:root {
  color-scheme: dark;
  --ink: #17172b;
  --paper: #f2f0e9;
  --lime: #d9ff43;
  --mint: #42e6b1;
  --coral: #ff6a5f;
  --line: rgba(242, 240, 233, 0.18);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 12% 0%, rgba(84, 74, 168, 0.22), transparent 36rem),
    var(--ink);
  color: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.site-shell { width: min(1480px, calc(100% - 48px)); min-height: 100svh; margin: 0 auto; display: flex; flex-direction: column; }
.site-shell main { flex: 1; }

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  letter-spacing: 0.1em;
  font-size: 12px;
  font-weight: 800;
}

.brand { color: var(--paper); display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--ink);
  background: var(--lime);
  border-radius: 4px 13px 4px 4px;
  font-size: 20px;
  font-style: italic;
  font-weight: 950;
  transform: rotate(-3deg);
}
.build-tag { color: #8f8e9e; border-left: 1px solid var(--line); padding-left: 12px; font-size: 9px; }
.status-row { display: flex; align-items: center; gap: 10px; color: #aaa9b7; }
.status-dot { width: 7px; height: 7px; background: var(--mint); border-radius: 50%; box-shadow: 0 0 0 5px rgba(66,230,177,.1); }
.icon-button { margin-left: 18px; padding: 10px 13px; border: 1px solid var(--line); color: var(--paper); background: transparent; cursor: pointer; font-size: 9px; letter-spacing: .08em; }

.section-label { margin: 0 0 10px; color: #8f8e9e; font-size: 9px; font-weight: 900; letter-spacing: .22em; }

.game-frame { border: 1px solid rgba(242, 240, 233, .3); box-shadow: 0 28px 90px rgba(0,0,0,.3); }
.game-toolbar { height: 62px; padding: 0 24px; display: flex; align-items: center; gap: 46px; background: #111121; border-bottom: 1px solid rgba(242, 240, 233, .17); }
.hud-group { display: flex; flex-direction: column; gap: 3px; }
.hud-group strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 23px; letter-spacing: .06em; line-height: 1; font-variant-numeric: tabular-nums; }
.hud-group small { color: var(--lime); font-size: 10px; margin-left: 5px; }
.hud-label { color: #777687; font-size: 8px; letter-spacing: .2em; font-weight: 900; }
.hud-group.best { margin-left: auto; text-align: right; }
.level-chip { border: 1px solid var(--lime); color: var(--lime); padding: 10px 14px; font: 800 10px/1 ui-monospace, monospace; letter-spacing: .12em; }

.canvas-wrap { position: relative; height: min(calc((100vw - 48px) * .5625), calc(100svh - 340px)); min-height: 300px; max-height: 676px; overflow: hidden; background: #bfe4ff; isolation: isolate; }
canvas { display: block; width: 100%; height: 100%; image-rendering: auto; }
.scanline { position: absolute; inset: 0; z-index: 2; pointer-events: none; opacity: .055; background: repeating-linear-gradient(0deg, #000 0, #000 1px, transparent 1px, transparent 4px); }

.start-card {
  position: absolute;
  z-index: 4;
  top: 50%;
  left: 50%;
  width: min(430px, calc(100% - 36px));
  padding: 34px 36px 28px;
  transform: translate(-50%, -50%);
  color: var(--ink);
  background: rgba(242, 240, 233, .97);
  box-shadow: 12px 12px 0 rgba(23, 23, 43, .22);
  transition: opacity .2s, transform .2s;
}
.start-card::before { content: ""; position: absolute; top: 0; left: 0; width: 78px; height: 5px; background: var(--coral); }
.start-card.hidden { opacity: 0; pointer-events: none; transform: translate(-50%, -46%); }
.card-kicker { color: #7c7a83; font: 800 9px/1 ui-monospace, monospace; letter-spacing: .16em; }
.start-card h2 { margin: 12px 0 9px; font-size: clamp(26px, 3vw, 42px); letter-spacing: -.05em; font-style: italic; font-weight: 950; }
.start-card p { color: #62616a; font-size: 12px; line-height: 1.7; }
.mode-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 19px; }
.mode-option { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid #cac7c1; color: #727078; background: transparent; text-align: left; cursor: pointer; transition: border-color .15s, background .15s, color .15s; }
.mode-option:hover { border-color: var(--ink); color: var(--ink); }
.mode-option.active { border-color: var(--ink); color: var(--ink); background: #fff; box-shadow: inset 0 -3px var(--lime); }
.mode-number { color: #aaa7a1; font: 700 8px/1 ui-monospace, monospace; }
.mode-option b, .mode-option small { display: block; }
.mode-option b { font-size: 10px; letter-spacing: .12em; }
.mode-option small { margin-top: 3px; color: #96939a; font-size: 8px; }
.start-button { width: 100%; display: flex; align-items: center; justify-content: space-between; margin-top: 22px; padding: 15px 18px; border: 0; color: var(--ink); background: var(--lime); font-weight: 950; font-size: 12px; letter-spacing: .1em; cursor: pointer; box-shadow: 4px 4px 0 var(--ink); transition: transform .12s, box-shadow .12s; }
.start-button:hover { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.start-card .keyboard-hint { margin: 18px 0 0; text-align: center; color: #8e8c94; font: 700 8px/1.6 ui-monospace, monospace; letter-spacing: .07em; }
kbd { border: 1px solid #aaa8ad; padding: 2px 5px; box-shadow: 0 1px 0 #aaa8ad; }

.touch-controls { display: none; position: absolute; z-index: 5; left: 16px; right: 16px; bottom: 16px; justify-content: space-between; pointer-events: none; }
.touch-controls button { width: 92px; height: 50px; border: 1px solid rgba(255,255,255,.65); color: white; background: rgba(23,23,43,.72); font-size: 9px; font-weight: 900; letter-spacing: .1em; pointer-events: auto; }
.touch-controls span { font-size: 18px; margin-right: 6px; }

.lower-grid { display: grid; grid-template-columns: .48fr 1.52fr; gap: 1px; margin-top: 1px; background: var(--line); }
.how-to, .jev-panel { min-height: 174px; padding: 20px 24px; background: var(--ink); }
.control-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.control-list > div { display: flex; align-items: center; gap: 13px; }
.control-icon { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid #4e4d61; color: var(--lime); font: 800 16px/1 ui-monospace, monospace; }
.control-list b, .control-list small { display: block; }
.control-list b { font-size: 11px; letter-spacing: .1em; }
.control-list small { margin-top: 5px; color: #717080; font: 700 7px/1 ui-monospace, monospace; letter-spacing: .08em; }
.jev-panel { display: grid; grid-template-columns: 1fr .7fr 1.45fr; grid-template-rows: 1fr auto auto; gap: 0 20px; align-items: center; border-left: 1px solid var(--line); transition: background .2s; }
.jev-panel.thinking { background: linear-gradient(100deg, #17172b 30%, #1d2333 50%, #17172b 70%); background-size: 200% 100%; animation: data-scan 1.4s linear infinite; }
@keyframes data-scan { to { background-position: -200% 0; } }
.jev-title { font-size: 11px; letter-spacing: .12em; font-weight: 900; }
.jev-title span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #777687; margin-right: 8px; }
.jev-title span.live { background: var(--mint); box-shadow: 0 0 0 5px rgba(66,230,177,.1); }
.jev-title span.error { background: var(--coral); }
.observed-state { margin: 15px 0 0; color: #626171; font: 700 7px/1.3 ui-monospace, monospace; letter-spacing: .1em; }
.observed-state b { display: block; margin-top: 5px; color: #b8b6c0; font-size: 9px; }
.decision-readout { display: flex; align-items: center; gap: 13px; }
.action-orb { display: grid; place-items: center; align-content: center; width: 74px; height: 74px; border: 1px solid #3e3d50; border-radius: 50%; background: #111120; box-shadow: inset 0 0 0 6px rgba(255,255,255,.02); }
.action-orb.active { border-color: var(--lime); box-shadow: 0 0 0 5px rgba(217,255,67,.06), inset 0 0 0 6px rgba(217,255,67,.04); }
.action-orb span, .confidence-readout span { color: #656475; font: 700 6px/1 ui-monospace, monospace; letter-spacing: .12em; }
.action-orb b { margin-top: 5px; color: var(--lime); font: 900 12px/1 ui-monospace, monospace; letter-spacing: .07em; }
.confidence-readout b { display: block; margin-top: 5px; font: 800 15px/1 ui-monospace, monospace; }
.confidence-readout .timing-label { display: block; margin-top: 11px; }
.confidence-readout .timing-value { color: var(--mint); font-size: 10px; letter-spacing: .05em; }
.confidence-readout small { display: block; margin-top: 4px; color: #747383; font: 700 7px/1 ui-monospace, monospace; }
.probability-bars { display: grid; gap: 9px; }
.probability-bars > div { display: grid; gap: 5px; }
.probability-bars span { display: flex; justify-content: space-between; color: #858392; font: 700 7px/1 ui-monospace, monospace; letter-spacing: .1em; }
.probability-bars i { display: block; height: 3px; overflow: hidden; background: #343346; }
.probability-bars em { display: block; width: 0; height: 100%; background: #777687; transition: width .35s ease; }
.probability-bars > div:nth-child(1) em { background: var(--lime); }
.probability-bars > div:nth-child(2) em { background: var(--coral); }
.probability-bars > div:nth-child(3) em { background: var(--mint); }
.probability-bars > div:nth-child(4) em { background: #77a5ff; }
.jev-countdown { grid-column: 1 / 4; display: grid; grid-template-columns: 170px 1fr 54px; align-items: center; gap: 14px; margin-top: 12px; padding-top: 10px; border-top: 1px solid #323144; opacity: .5; transition: opacity .2s; }
.jev-countdown.active { opacity: 1; }
.countdown-copy span, .countdown-copy small { display: block; color: #676676; font: 700 6px/1 ui-monospace, monospace; letter-spacing: .12em; }
.countdown-copy b { display: block; margin: 5px 0 4px; color: var(--lime); font: 800 10px/1 ui-monospace, monospace; letter-spacing: .08em; }
.countdown-track { height: 5px; overflow: hidden; background: #343346; }
.countdown-track i { display: block; width: 0; height: 100%; background: var(--lime); transition: width .08s linear; }
.jev-countdown strong { color: var(--paper); text-align: right; font: 800 14px/1 ui-monospace, monospace; }
.jev-note { grid-column: 2 / 4; display: flex; justify-content: space-between; margin: 9px 0 0; color: #5f5e6e; font: 700 7px/1 ui-monospace, monospace; letter-spacing: .09em; }

footer { height: 38px; display: flex; align-items: center; justify-content: space-between; color: #696878; font: 700 8px/1 ui-monospace, monospace; letter-spacing: .14em; }
footer a { color: #aaa9b6; }

@media (max-width: 1100px) {
  .control-list > div { flex-direction: column; justify-content: center; gap: 7px; text-align: center; }
  .control-icon { width: 30px; height: 30px; font-size: 13px; }
  .control-list b { font-size: 8px; }
  .control-list small { display: none; }
}

@media (max-width: 800px) {
  .site-shell { width: calc(100% - 24px); }
  .topbar { min-height: 64px; }
  .status-row > span:not(.status-dot), .build-tag { display: none; }
  .icon-button { margin-left: 5px; }
  .game-toolbar { height: 62px; gap: 20px; padding: 0 14px; }
  .hud-group strong { font-size: 17px; }
  .hud-group.best { display: none; }
  .canvas-wrap { min-height: 430px; aspect-ratio: auto; }
  canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
  .touch-controls { display: flex; }
  .start-card { top: 43%; padding: 25px 25px 22px; }
  .keyboard-hint { display: none; }
  .lower-grid { grid-template-columns: 1fr; }
  .control-list { justify-content: space-between; gap: 8px; }
  .control-list > div { gap: 8px; }
  .control-list small { display: none; }
  .jev-panel { border: 0; grid-template-columns: 1fr .8fr; gap: 18px; }
  .probability-bars { grid-column: 1 / 3; }
  .jev-countdown { grid-column: 1 / 3; grid-template-columns: 135px 1fr 45px; }
  .jev-note { grid-column: 1 / 3; }
  footer { height: 70px; }
  footer span:last-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
