:root {
  color-scheme: dark;
  --bg: #050605;
  --panel: #0a0c0a;
  --line: #262b23;
  --line-hi: #4b5244;
  --ink: #e9ebe5;
  --dim: #7d8476;
  --lime: #b3ff00;
  --lime-dim: #5d8000;
  --warn: #ffcf6b;
  --mono: "JetBrains Mono", Menlo, Consolas, monospace;
  --glow: 0;
  --top: 44px;
  --dock: 96px;
  --status: 24px;
}
* { box-sizing: border-box }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 13px/1.4 var(--mono) }
body {
  background:
    repeating-linear-gradient(0deg, transparent 0 2px, #ffffff04 2px 3px),
    radial-gradient(ellipse 70% 60% at 60% 45%, #12180d, var(--bg) 70%);
}
button { font: inherit; color: inherit; background: none; border: 1px solid var(--line-hi); padding: 8px 12px; cursor: pointer; letter-spacing: .06em }
button:hover:not(:disabled), button:focus-visible { border-color: var(--lime); color: var(--lime); outline: none }
button:disabled { opacity: .35; cursor: default }
.dim { color: var(--dim) }
.lime { color: var(--lime) }
code { color: var(--lime) }
.lbl { display: block; font-size: 10px; letter-spacing: .18em; color: var(--dim) }

/* ---------------------------------------------------------------- frame */
.app {
  height: 100svh; min-height: 560px;
  display: grid; grid-template-rows: var(--top) minmax(0, 1fr) var(--dock) var(--status);
  overflow: hidden;
}
.top { display: flex; align-items: center; gap: 16px; padding: 0 max(16px, 2vw); border-bottom: 1px solid var(--line); font-size: 11px; letter-spacing: .15em; z-index: 3; background: #050605cc }
.led { width: 8px; height: 8px; background: var(--lime); box-shadow: 0 0 8px var(--lime); animation: blink 1.6s steps(2) infinite }
@keyframes blink { 50% { opacity: .25 } }
.mode { margin-left: auto; border: 1px solid var(--lime-dim); color: var(--lime); padding: 4px 10px; font-size: 10px; letter-spacing: .14em; white-space: nowrap }
.mode.bonus { background: var(--lime); color: #0b1000; animation: blink .9s steps(2) infinite }
.icon-btn { padding: 5px 10px; font-size: 11px; min-width: 34px }
.sound[aria-pressed="true"] { color: var(--lime); border-color: var(--lime-dim) }

/* ---------------------------------------------------------------- stage */
.stage {
  position: relative; min-height: 0;
  display: grid; grid-template-columns: minmax(250px, 31vw) minmax(0, 1fr) minmax(150px, 12vw);
}

/* IRIS: big art that bleeds under the board */
.iris { position: relative; min-height: 0; margin-right: -8vw; z-index: 0 }
.portrait {
  position: absolute; inset: 0; overflow: hidden;
  -webkit-mask-image: linear-gradient(to right, #000 62%, transparent 97%);
  mask-image: linear-gradient(to right, #000 62%, transparent 97%);
}
.portrait img, .portrait video, #iris-ascii { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 22% }
.portrait img, .portrait video { filter: contrast(1.08) brightness(calc(.9 + var(--glow) * .12)) }
#iris-ascii { opacity: 0; transition: opacity .12s; pointer-events: none; mix-blend-mode: screen }
.scan { position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(0deg, transparent 0 2px, #0006 2px 3px) }
.eye { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, #d8ff6a 0, #b3ff00aa 30%, transparent 70%);
  opacity: calc(var(--glow) * .9); transform: scale(calc(1 + var(--glow) * 2.2)); mix-blend-mode: screen; transition: opacity .4s, transform .4s }
.iris.injecting #iris-ascii { opacity: .85 }
.iris.injecting .portrait img, .iris.injecting .portrait video { filter: contrast(1.4) brightness(.6) }
.iris.breach .portrait { animation: shake .35s steps(3) 3 }
.iris.breach #iris-ascii { opacity: .45 }
@keyframes shake { 33% { transform: translate(-4px, 2px) } 66% { transform: translate(3px, -2px) } }

.iris-tag { position: absolute; top: 14px; left: 16px; display: flex; gap: 10px; align-items: baseline; font-size: 11px; letter-spacing: .16em; padding: 4px 8px; background: #050605b0; border-left: 2px solid var(--lime) }
#iris-state { color: var(--dim); font-size: 10px }
.iris.breach .iris-tag { background: var(--lime); color: #0b1000 }
.iris.breach #iris-state { color: #0b1000 }

.term {
  position: absolute; left: 14px; bottom: 14px; width: calc(100% - 8vw - 28px); max-width: 380px;
  background: #050605c4; border: 1px solid var(--line-hi); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.term-head { display: flex; justify-content: space-between; padding: 4px 8px; border-bottom: 1px solid var(--line); font-size: 9px; letter-spacing: .18em; color: var(--dim) }
#say { height: calc(6 * 1.55em); overflow: hidden; padding: 4px 8px; color: var(--dim); font-size: 10.5px; line-height: 1.55; display: flex; flex-direction: column; justify-content: flex-end }
#say .ln { white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
#say .hit { color: var(--ink) }
#say .warn { color: var(--warn) }
#say .dim { color: #555b50 }
#say .iris-line { color: var(--lime); font-weight: 700; font-size: 12px; text-shadow: 0 0 8px #b3ff0060 }
#say .typing::after { content: "█"; color: var(--lime) }

/* center: logo + board */
.center { position: relative; z-index: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 12px 18px }
.logo { margin: 0; color: var(--ink); font: 700 clamp(4px, .62vw, 9px)/1.02 var(--mono); text-shadow: 0 0 14px #b3ff0040; white-space: pre; flex: none }
.board-frame {
  width: min(100%, calc((100svh - var(--top) - var(--dock) - var(--status) - 120px) * 1.45));
  border: 1px solid var(--line-hi); background: #050605;
  box-shadow: -40px 0 80px 10px #000, 0 0 0 1px #000;
}
.app.breach .board-frame { border-color: var(--lime); box-shadow: 0 0 0 1px var(--lime), 0 0 50px #b3ff0040 }
.hud { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 10px; letter-spacing: .12em; color: var(--dim) }
.hud.bonus { color: var(--lime); background: #0f1608 }
#board { display: block; width: 100%; aspect-ratio: 1.45 }

/* right rail */
.rail { position: relative; z-index: 1; display: flex; flex-direction: column; justify-content: center; gap: 12px; padding: 16px 18px 16px 0 }
.meter, .rail-card { border: 1px solid var(--line); background: #070907d0; padding: 10px 12px }
.meter b { display: block; font-size: clamp(26px, 2.6vw, 40px); font-weight: 800; color: var(--lime); line-height: 1.1; text-shadow: 0 0 16px #b3ff0050 }
#infect-bar { margin: 6px 0 0; color: var(--lime); font-size: 10px; overflow: hidden }
.rail-card b { display: block; font-size: 22px; font-weight: 800 }
.rail-card.hint span:last-child { font-size: 11px; color: var(--ink) }

/* ---------------------------------------------------------------- dock */
.dock {
  position: relative; z-index: 2;
  display: grid; grid-template-columns: 1fr auto 118px auto 1fr; align-items: center; gap: 28px;
  padding: 0 max(16px, 2vw);
  border-top: 1px solid var(--line-hi);
  background: linear-gradient(#0b0e0a, #060706);
}
.stat label { display: block; font-size: 10px; letter-spacing: .18em; color: var(--dim); margin-bottom: 3px }
.stat b { font-size: 22px; font-weight: 800; white-space: nowrap }
.balance { justify-self: end; text-align: right }
.stepper { display: flex; align-items: center; gap: 10px }
.stepper button { width: 32px; height: 32px; padding: 0; font-size: 17px }
.stepper b { min-width: 3.6em; text-align: center }
#win.bump { display: inline-block; transform: scale(1.12); color: #fff }
#win.hot { color: var(--lime); text-shadow: 0 0 10px #b3ff0080 }
.side-btns { justify-self: start; display: flex; gap: 8px }
.buy { color: var(--lime); border-color: var(--lime-dim); font-weight: 700; font-size: 11px }
#turbo { font-size: 11px }
#turbo[aria-pressed="true"] { color: var(--lime); border-color: var(--lime) }

.run {
  width: 118px; height: 118px; margin-top: -40px; border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #d8ff6a, var(--lime) 55%, #7fb800);
  color: #0b1000; border: 3px solid #0b1000; outline: 1px solid var(--lime);
  font-weight: 800; font-size: 20px; letter-spacing: .02em; white-space: nowrap;
  box-shadow: 0 0 0 6px #050605, 0 0 0 7px var(--lime-dim), 0 0 34px #b3ff0070;
  transition: transform .08s;
  animation: idle-pulse 2.4s ease-in-out infinite;
}
.run:hover:not(:disabled), .run:focus-visible { color: #0b1000; border-color: #0b1000; transform: scale(1.04) }
.run:active:not(:disabled) { transform: scale(.94) }
.run:disabled { animation: none; filter: saturate(.3) brightness(.6); opacity: 1 }
@keyframes idle-pulse { 50% { box-shadow: 0 0 0 6px #050605, 0 0 0 7px var(--lime), 0 0 54px #b3ff00a0 } }

.status { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 0 max(16px, 2vw); font-size: 10px; color: var(--ink); border-top: 1px solid var(--line) }

/* ---------------------------------------------------------------- dialogs */
dialog { width: min(560px, calc(100% - 32px)); color: var(--ink); background: var(--panel); border: 1px solid var(--lime-dim); padding: 22px; font-size: 12.5px; line-height: 1.55 }
dialog::backdrop { background: #000c }
dialog h2 { margin: 0 0 12px; color: var(--lime); font-size: 15px; letter-spacing: .06em }
dialog form { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px }
.cta { background: var(--lime); color: #0b1000; border: 2px solid #d6ff7a; font-weight: 800; padding: 8px 16px }
.cta:hover:not(:disabled), .cta:focus-visible { background: #d6ff7a; color: #0b1000 }
table { width: 100%; border-collapse: collapse; margin: 6px 0 10px }
caption { text-align: left; color: var(--dim); padding-bottom: 6px }
th, td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line) }
td:first-child { color: var(--lime) }
.warn { color: #ffb86b }

/* ---------------------------------------------------------------- board camera effects */
#board { transform-origin: 50% 50% }
#board.fx-punch { animation: punch .38s cubic-bezier(.2,.9,.3,1) }
#board.fx-glitch { animation: rgbsplit .45s steps(6) }
@keyframes punch { 30% { transform: scale(1.045) } 100% { transform: scale(1) } }
@keyframes rgbsplit {
  0%   { filter: drop-shadow(-4px 0 0 #ff2b6a) drop-shadow(4px 0 0 #2bf0ff); clip-path: inset(0 0 0 0); transform: translateX(-3px) }
  25%  { filter: drop-shadow(5px 0 0 #ff2b6a) drop-shadow(-5px 0 0 #2bf0ff); clip-path: inset(12% 0 30% 0); transform: translateX(4px) }
  50%  { filter: drop-shadow(-2px 0 0 #ff2b6a) drop-shadow(2px 0 0 #2bf0ff); clip-path: inset(0 0 0 0); transform: translateX(-1px) skewX(-2deg) }
  75%  { filter: drop-shadow(3px 0 0 #ff2b6a) drop-shadow(-3px 0 0 #2bf0ff); clip-path: inset(40% 0 8% 0) }
  100% { filter: none; clip-path: inset(0 0 0 0); transform: none }
}

/* ---------------------------------------------------------------- narrow screens */
@media (max-width: 980px) {
  .stage { grid-template-columns: minmax(200px, 34vw) minmax(0, 1fr) }
  .rail { grid-column: 1 / -1; flex-direction: row; padding: 0 16px 10px; justify-content: center }
  .rail-card.hint { display: none }
  .meter { display: flex; align-items: baseline; gap: 10px }
  .meter b { font-size: 22px }
  #infect-bar { margin: 0 }
}

@media (max-width: 720px) {
  :root { --top: 40px; --dock: auto; --status: auto }
  .app { height: auto; min-height: 100svh; overflow: visible; grid-template-rows: var(--top) auto auto auto }
  .top { gap: 10px; padding: 0 12px; position: sticky; top: 0 }
  .top > b { display: none }
  .icon-btn { white-space: nowrap }
  .hide-sm { display: none }
  .stage { grid-template-columns: 1fr; grid-template-rows: auto auto auto }
  .iris { height: 180px; margin: 0; display: grid; grid-template-columns: 48% 1fr; border-bottom: 1px solid var(--line) }
  .portrait { position: relative; inset: auto; -webkit-mask-image: none; mask-image: none; border-right: 1px solid var(--line) }
  .portrait img, .portrait video, #iris-ascii { object-position: 50% 6% }
  .term { position: static; width: auto; max-width: none; border: 0; background: #070907; backdrop-filter: none; display: flex; flex-direction: column }
  .term-head { padding: 6px 8px }
  #say { font-size: 9px; height: auto; flex: 1 }
  .iris-tag { top: 8px; left: 8px; font-size: 10px; padding: 3px 6px }
  .iris-tag #iris-state { display: none }
  .center { padding: 8px 8px 0; gap: 6px }
  .logo { font-size: clamp(3.4px, 1.15vw, 7px) }
  .board-frame { width: 100% }
  .rail { grid-column: auto; padding: 8px 8px 0; gap: 8px }
  .meter, .rail-card { padding: 6px 10px; flex: 1 }
  .rail-card b { font-size: 16px }
  #infect-bar { display: none }
  .dock {
    position: sticky; bottom: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    grid-template-columns: 1fr auto 1fr; grid-template-areas: "bal run win" "bet run side"; gap: 8px 12px;
  }
  .balance { grid-area: bal; justify-self: start; text-align: left }
  .bet { grid-area: bet }
  .run { grid-area: run; width: 92px; height: 92px; margin: 0; font-size: 16px }
  .win-stat { grid-area: win; justify-self: end; text-align: right }
  .side-btns { grid-area: side; justify-self: end; flex-direction: column; gap: 6px }
  .side-btns button { padding: 6px 8px; font-size: 10px }
  .stat b { font-size: 17px }
  .stepper { gap: 6px }
  .stepper button { width: 28px; height: 28px }
  .status { padding: 6px 12px 10px; flex-direction: column; align-items: flex-start; gap: 2px }
}

/* ---------------------------------------------------------------- intro / boot screen */
.intro { position: fixed; inset: 0; z-index: 50; background: #020302; display: grid; place-items: center; overflow: hidden; --k: 0; cursor: default }
.intro.running { cursor: pointer }
.intro-body { position: relative; z-index: 2; width: min(720px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 14px }
.intro-logo { margin: 0 auto; font: 700 clamp(4px, 1.05vw, 11px)/1.02 var(--mono); color: var(--ink); white-space: pre;
  text-shadow: 0 0 calc(10px + var(--k) * 30px) #b3ff0060; opacity: calc(.85 + var(--k) * .15) }
.intro-log { height: calc(14 * 1.5em); overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; font-size: 12px; line-height: 1.5; color: var(--dim);
  border-left: 2px solid var(--line-hi); padding-left: 12px }
.intro-log div { animation: type-in .25s steps(12) both; white-space: nowrap; overflow: hidden }
.intro-log .hi { color: var(--ink) }
.intro-log .warn { color: var(--warn) }
.intro-log .alarm { color: #ff4d6d; font-weight: 800; letter-spacing: .1em }
.intro-log .iris { color: var(--lime); font-weight: 800; font-size: 14px; text-shadow: 0 0 10px #b3ff0080 }
@keyframes type-in { from { max-width: 0 } to { max-width: 100% } }
.intro-bar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; font-size: 10px; letter-spacing: .16em; color: var(--dim) }
.intro-bar .track { height: 8px; border: 1px solid var(--line-hi); padding: 1px }
.intro-bar i { display: block; height: 100%; width: 0; background: var(--lime); box-shadow: 0 0 10px var(--lime); transition: width .2s }
.intro.running .intro-bar i { background: linear-gradient(90deg, #ff4d6d, var(--warn) 40%, var(--lime)); transition: none }
.intro-bar b { color: var(--ink); white-space: pre }
.intro-go { align-self: center; margin-top: 6px; padding: 14px 34px; font-size: 16px; font-weight: 800; letter-spacing: .14em;
  color: #0b1000; background: var(--lime); border: 2px solid #d6ff7a; box-shadow: 0 0 30px #b3ff0070; animation: idle-glow 1.6s ease-in-out infinite }
.intro-go:hover, .intro-go:focus-visible { color: #0b1000; border-color: #fff }
@keyframes idle-glow { 50% { box-shadow: 0 0 50px #b3ff00b0 } }
.intro-hint { margin: 0; text-align: center; font-size: 10px; color: #4d5348; letter-spacing: .08em }
/* IRIS's eye bleeds in behind the log as the quarantine fails */
.intro-eye { position: absolute; left: 50%; top: 50%; width: 92vmin; height: 92vmin; margin: -46vmin 0 0 -46vmin; z-index: 0;
  background: url(assets/iris.webp) no-repeat; background-size: 300% auto; background-position: 80% 17.6%;
  -webkit-mask-image: radial-gradient(circle, #000 30%, transparent 70%); mask-image: radial-gradient(circle, #000 30%, transparent 70%);
  opacity: calc(var(--k) * var(--k) * .6); filter: contrast(1.4) brightness(.85); transform: scale(calc(1.3 - var(--k) * .3)); mix-blend-mode: screen }
.intro-noise { position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent 0 2px, #00000080 2px 3px), radial-gradient(ellipse at center, transparent 40%, #000 95%);
  opacity: .9 }
.intro.hit .intro-body { transform: translateX(-6px); filter: drop-shadow(3px 0 0 #ff2b6a) drop-shadow(-3px 0 0 #2bf0ff) }
.intro.out { animation: intro-out .7s steps(7) forwards }
@keyframes intro-out {
  0% { background: #b3ff00 } 15% { background: #020302; clip-path: inset(0 0 0 0) }
  40% { clip-path: inset(20% 0 35% 0); filter: drop-shadow(6px 0 #ff2b6a) drop-shadow(-6px 0 #2bf0ff) }
  70% { clip-path: inset(46% 0 46% 0) } 100% { clip-path: inset(50% 0 50% 0); opacity: 0 }
}

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

.flyer { position: fixed; z-index: 40; pointer-events: none; font: 800 18px var(--mono); color: var(--lime); text-shadow: 0 0 10px #b3ff00, 0 2px 0 #000; white-space: nowrap; transform: translate(-50%,-50%) }

/* pointer parallax (--px / --py in -1..1, set from game.js) */
:root { --px: 0; --py: 0 }
.logo { transform: translate(calc(var(--px) * 3px), calc(var(--py) * 2px)); transition: transform .6s ease-out }
.iris { margin-left: -8px; transform: translate(calc(var(--px) * -6px), calc(var(--py) * -3px)); transition: transform .6s ease-out }
.board-frame { transform: translate(calc(var(--px) * 2px), calc(var(--py) * 1px)); transition: transform .6s ease-out }
.rail { transform: translate(calc(var(--px) * 3px), calc(var(--py) * 2px)); transition: transform .6s ease-out }
@media (max-width: 720px) { .iris, .board-frame, .rail { transform: none } }

/* equalizer graph in the right rail */
.eq-card .lbl i { font-style: normal; color: #4d5348 }
#eq { display: block; width: 100%; height: 64px; margin-top: 6px }
@media (max-width: 720px) { #eq { height: 34px; margin-top: 2px } }
