:root {
  color-scheme: dark;
  --bg: #09090b;
  --panel: #0f0f13;
  --line: #27272a;
  --line-strong: #3f3f46;
  --ink: #f4f4f5;
  --ink-2: #d4d4d8;
  --muted: #71717a;
  --muted-2: #52525b;
  --amber: #fbbf24;
  --amber-bright: #fcd34d;
  --amber-dim: #b45309;
  --emerald: #34d399;
  --rose: #fb7185;
  --display: "VT323", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --body: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-family: var(--body);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
}

button, input { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }

/* CRT overlays */
.crt-scanlines, .crt-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
}

.crt-scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0,
    rgba(0,0,0,0) 2px,
    rgba(0,0,0,0.16) 3px,
    rgba(0,0,0,0) 4px
  );
  mix-blend-mode: multiply;
  opacity: 0.5;
}

.crt-vignette {
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.5) 100%);
}

.glow-amber {
  color: var(--amber-bright);
  text-shadow: 0 0 6px rgba(251,191,36,0.55), 0 0 18px rgba(251,191,36,0.22);
}

@keyframes crt-flicker {
  0%, 96%, 100% { opacity: 1; }
  97% { opacity: 0.95; }
  99% { opacity: 0.97; }
}

@keyframes blink {
  0%, 60%, 100% { opacity: 1; }
  70% { opacity: 0.35; }
}

/* App shell — single viewport, no scroll */
.app {
  height: 100dvh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0));
  background:
    radial-gradient(ellipse at top, rgba(251,191,36,0.05), transparent 60%),
    linear-gradient(90deg, rgba(251,191,36,0.022) 1px, transparent 1px) 0 0 / 56px 56px,
    linear-gradient(0deg, rgba(251,191,36,0.022) 1px, transparent 1px) 0 0 / 56px 56px,
    var(--bg);
  overflow: hidden;
  animation: crt-flicker 6s infinite;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 4px 6px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.35);
  text-transform: uppercase;
  flex-shrink: 0;
  height: 32px;
}

.wordmark {
  font-family: var(--display);
  font-size: 18px;
  letter-spacing: 0.06em;
}

.sep { color: var(--muted-2); }
.breadcrumb { color: var(--ink-2); }
.spacer { flex: 1; }

.topbar .dot {
  color: var(--emerald);
  text-shadow: 0 0 6px rgba(52,211,153,0.55);
  animation: blink 1.8s infinite;
  font-size: 10px;
}

.topbar .state { color: var(--amber); }
.topbar .clock { color: var(--amber-bright); min-width: 9ch; text-align: right; }

/* Account bar — math first, prominent */
.acctbar {
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr 1fr 1fr;
  gap: 4px;
  padding: 0;
  flex-shrink: 0;
  font-family: var(--display);
  letter-spacing: 0.05em;
}

.acctbar .cell {
  border: 1px solid rgba(251,191,36,0.32);
  background: linear-gradient(180deg, rgba(251,191,36,0.06), rgba(0,0,0,0.4));
  padding: 5px 8px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  overflow: hidden;
}

.acctbar .cell span {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
  margin-bottom: 2px;
}

.acctbar .cell b {
  color: var(--ink);
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.acctbar .cell.big b {
  font-size: 22px;
  color: var(--amber-bright);
}

.acctbar .cell .ok {
  color: var(--emerald);
}

.acctbar .cell.pnl b {
  color: var(--ink);
}
.acctbar .cell.pnl.up b { color: var(--emerald); }
.acctbar .cell.pnl.down b { color: var(--rose); }

/* HUD strip — score + brief */
.hudstrip {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
  font-family: var(--display);
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.hudstrip .stat,
.hudstrip .badge {
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.4);
  padding: 4px 6px;
  text-align: center;
  min-width: 0;
  overflow: hidden;
}

.hudstrip .stat b,
.hudstrip .badge b {
  display: block;
  color: var(--amber-bright);
  font-size: 16px;
  line-height: 1;
  font-weight: 400;
}

.hudstrip .stat span,
.hudstrip .badge span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 1px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.hudstrip .badge b {
  color: var(--ink);
  font-size: 14px;
}

.hudstrip .badge span {
  margin-top: 0;
  margin-bottom: 1px;
}

/* Status line */
.status-line {
  margin: 0;
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: 0.05em;
  color: var(--amber);
  text-transform: uppercase;
  padding: 0 4px;
  flex-shrink: 0;
  min-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-line.is-good { color: var(--emerald); }
.status-line.is-bad { color: var(--rose); }

/* Screen / canvas — fills remaining */
.screen {
  flex: 1;
  min-height: 0;
  position: relative;
  border: 1px solid rgba(251,191,36,0.25);
  background:
    radial-gradient(ellipse at center, rgba(251,191,36,0.04), transparent 65%),
    linear-gradient(180deg, rgba(8,8,11,0.6), rgba(0,0,0,0.85)),
    #050507;
  box-shadow:
    inset 0 0 60px rgba(0,0,0,0.7),
    inset 0 0 120px rgba(251,191,36,0.04),
    0 12px 28px -12px rgba(0,0,0,0.7),
    0 0 0 1px rgba(251,191,36,0.06);
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* Risk slider row */
.risk-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.4);
  padding: 4px 8px;
  font-family: var(--display);
  letter-spacing: 0.05em;
  flex-shrink: 0;
  font-size: 13px;
  height: 32px;
}

.risk-row label { color: var(--muted); text-transform: uppercase; }
.risk-row input[type="range"] {
  width: 100%;
  accent-color: var(--amber);
}
.risk-row .risk-readout { color: var(--amber-bright); white-space: nowrap; }

/* Action row */
.actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr)) 1.4fr;
  gap: 4px;
  flex-shrink: 0;
}

.act {
  font-family: var(--display);
  font-size: 16px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  color: var(--amber);
  background: rgba(0,0,0,0.4);
  min-height: 44px;
  transition: color 120ms, border-color 120ms, background 120ms, text-shadow 120ms;
  -webkit-tap-highlight-color: transparent;
}

.act:hover, .act:active {
  color: var(--amber-bright);
  border-color: var(--amber);
  text-shadow: 0 0 6px rgba(251,191,36,0.4);
}

.act.mark { border-color: rgba(251,191,36,0.6); }
.act.long {
  color: var(--emerald);
  border-color: rgba(52,211,153,0.55);
}
.act.short {
  color: var(--rose);
  border-color: rgba(251,113,133,0.55);
}
.act.wait { color: var(--ink-2); }

.act.commit {
  color: #111;
  background: var(--amber);
  border-color: var(--amber);
  font-weight: 400;
}
.act.commit:hover, .act.commit:active {
  background: var(--amber-bright);
  color: #111;
  text-shadow: none;
}

.act.is-armed {
  border-color: var(--amber-bright);
  background: rgba(251,191,36,0.18);
  color: var(--amber-bright);
}

.act:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Narrower phones */
@media (max-width: 540px) {
  .hudstrip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: auto;
  }
  .acctbar {
    grid-template-columns: 1.4fr 1fr 1fr;
    grid-auto-rows: auto;
  }
  .acctbar .cell.pnl {
    grid-column: 2 / span 2;
  }
  .acctbar .cell:nth-child(4) {
    grid-column: 1 / span 1;
  }
  .acctbar .cell.big b { font-size: 20px; }
  .acctbar .cell b { font-size: 15px; }
  .topbar { font-size: 13px; gap: 4px; }
  .topbar .breadcrumb { display: none; }
  .topbar .sep:first-of-type { display: none; }
  .actions {
    grid-template-columns: repeat(4, minmax(0,1fr));
  }
  .act.commit {
    grid-column: 1 / -1;
    min-height: 48px;
  }
  .status-line { font-size: 13px; }
}

/* Landscape phones — keep it tight */
@media (max-height: 480px) {
  .hudstrip .stat b,
  .hudstrip .badge b { font-size: 14px; }
  .hudstrip .stat span,
  .hudstrip .badge span { font-size: 10px; }
  .act { min-height: 36px; font-size: 14px; }
  .risk-row { height: 28px; font-size: 12px; }
}

/* Wider screens — center column */
@media (min-width: 900px) {
  .app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0));
    gap: 8px;
  }
  .topbar { height: 36px; font-size: 15px; }
  .wordmark { font-size: 20px; }
  .status-line { font-size: 16px; min-height: 22px; }
  .act { min-height: 48px; font-size: 18px; }
  .risk-row { height: 36px; font-size: 14px; }
}
