/* ══ FLOPPY · CRT ═════════════════════════════════════════════════════════
   The screen itself and everything rendered inside it: boot sequence,
   info panels, game canvas, leaderboards.
   ════════════════════════════════════════════════════════════════════════ */

.screen {
  position: relative;
  aspect-ratio: 4 / 3;
  max-height: 72dvh;
  margin: 0 auto;
  width: 100%;
  background:
    radial-gradient(115% 105% at 50% 45%, #0e1c10 0%, var(--screen-bg) 62%, #050a06 100%);
  border-radius: 14px / 10px;
  overflow: hidden;
  box-shadow:
    inset 0 0 60px 12px rgba(0,0,0,.85),
    inset 0 0 140px 30px rgba(0,0,0,.5),
    0 0 34px -6px rgba(124,252,155,.14);
  isolation: isolate;
}
.screen:focus-visible { outline: none; }

/* Scrollable content plane */
.crt {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: clamp(1rem, 2.4vw, 1.9rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--p-green);
  font-size: clamp(.76rem, 1.15vw, .92rem);
  line-height: 1.62;
  text-shadow: 0 0 6px rgba(124,252,155,.42);
  scrollbar-width: thin;
  scrollbar-color: #2c6b3d transparent;
}
.crt::-webkit-scrollbar { width: 9px; }
.crt::-webkit-scrollbar-thumb { background: #2c6b3d; border-radius: 4px; }
.crt::-webkit-scrollbar-track { background: rgba(0,0,0,.3); }

/* When a game is loaded the plane must not scroll or pad.
   Deliberately `block`, not a centring grid: as a centred grid item the stage
   is sized to its content rather than stretched, so on touch layouts the
   on-screen controls pushed past the bottom of the tube and were clipped. */
.crt[data-mode="game"] {
  padding: 0;
  overflow: hidden;
  display: block;
}

/* ── Glass, scanlines, flicker ───────────────────────────────────────── */

.crt-glass {
  position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background:
    linear-gradient(125deg, rgba(255,255,255,.055) 0%, rgba(255,255,255,0) 42%),
    radial-gradient(120% 110% at 50% 48%, rgba(0,0,0,0) 55%, rgba(0,0,0,.55) 100%);
}

.crt-scan {
  position: absolute; inset: -2px; z-index: 2; pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,.26) 0px,
    rgba(0,0,0,.26) 1px,
    rgba(0,0,0,0) 1px,
    rgba(0,0,0,0) 3px
  );
  mix-blend-mode: multiply;
  opacity: .85;
}

/* A slow bright band rolling down the tube */
.crt-flicker {
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(124,252,155,0) 0%,
    rgba(124,252,155,.035) 48%,
    rgba(124,252,155,0) 100%);
  height: 34%;
  animation: roll 9s linear infinite;
}
@keyframes roll {
  0%   { transform: translateY(-40%); }
  100% { transform: translateY(330%); }
}

/* CRT chrome off */
.screen[data-crt="off"] .crt-scan,
.screen[data-crt="off"] .crt-flicker { display: none; }
.screen[data-crt="off"] .crt { text-shadow: none; }
.screen[data-crt="off"] .crt-glass { opacity: .35; }

/* Channel-change flash when a disk is loaded */
.screen[data-loading="true"]::after {
  content: '';
  position: absolute; inset: 0; z-index: 5;
  background: #cfeed8;
  animation: flash .28s ease-out forwards;
  pointer-events: none;
}
@keyframes flash {
  0%   { opacity: .5; transform: scaleY(.004); }
  35%  { opacity: .35; transform: scaleY(1); }
  100% { opacity: 0;   transform: scaleY(1); }
}

/* ══ Screen content ══════════════════════════════════════════════════ */

.crt h1, .crt h2, .crt h3 { margin: 0 0 .6rem; font-weight: 700; letter-spacing: .1em; }
.crt h1 { font-size: 1.5em; }
.crt h2 { font-size: 1.1em; color: var(--p-amber); text-shadow: 0 0 7px rgba(255,180,84,.4); }
.crt h3 { font-size: .95em; color: #b6ffca; }
.crt p  { margin: 0 0 .85rem; max-width: 68ch; }
.crt ul, .crt ol { margin: 0 0 .9rem; padding-left: 1.15rem; max-width: 68ch; }
.crt li { margin-bottom: .3rem; }
.crt a  { color: var(--p-amber); text-underline-offset: 3px; }
.crt strong { color: #ddffe6; }
.crt hr {
  border: none;
  border-top: 1px dashed rgba(124,252,155,.3);
  margin: 1.1rem 0;
}

/* Panel header line, e.g.  ┌─ CONTRACT ─────────┐ */
.panel-head {
  display: flex; align-items: baseline; gap: .75rem;
  margin-bottom: 1rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid rgba(124,252,155,.28);
}
.panel-head h1 { margin: 0; }
.panel-head .panel-tag {
  margin-left: auto;
  font-size: .68em;
  letter-spacing: .16em;
  color: var(--p-dim);
}

.dim { color: var(--p-dim); }
.amber { color: var(--p-amber); }

/* Key/value rows */
.kv { display: grid; grid-template-columns: minmax(9rem, auto) 1fr; gap: .3rem 1rem; margin: 0 0 1rem; }
.kv dt { color: var(--p-dim); letter-spacing: .08em; }
.kv dd { margin: 0; color: #ddffe6; }

/* Contract address block */
.ca-block {
  border: 1px solid rgba(124,252,155,.35);
  background: rgba(124,252,155,.05);
  padding: .85rem 1rem;
  margin: 0 0 1.1rem;
  border-radius: 3px;
}
.ca-label { font-size: .7em; letter-spacing: .2em; color: var(--p-dim); display: block; margin-bottom: .35rem; }
.ca-value {
  display: block;
  font-size: clamp(.72rem, 1.5vw, .95rem);
  word-break: break-all;
  color: #eaffef;
  letter-spacing: .02em;
}
.ca-pending {
  display: block;
  color: var(--p-amber);
  letter-spacing: .1em;
}
.ca-actions { display: flex; gap: .5rem; margin-top: .75rem; flex-wrap: wrap; }

/* Buttons inside the screen */
.btn {
  font: inherit;
  font-size: .8em;
  letter-spacing: .14em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .45rem .85rem;
  color: var(--p-green);
  background: rgba(124,252,155,.08);
  border: 1px solid var(--p-dim);
  border-radius: 2px;
  transition: background .13s, color .13s, box-shadow .13s;
}
.btn:hover, .btn:focus-visible {
  background: var(--p-green);
  color: #04170b;
  text-shadow: none;
  box-shadow: 0 0 16px -2px var(--p-glow);
  outline: none;
}
.btn[data-variant="amber"] { color: var(--p-amber); border-color: rgba(255,180,84,.55); background: rgba(255,180,84,.08); }
.btn[data-variant="amber"]:hover, .btn[data-variant="amber"]:focus-visible { background: var(--p-amber); color: #21150a; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* Notice / warning box */
.notice {
  border-left: 3px solid var(--p-amber);
  background: rgba(255,180,84,.07);
  padding: .7rem .9rem;
  margin: 0 0 1rem;
  color: #ffe0b8;
  font-size: .92em;
}
.notice strong { color: #fff1de; }

/* ── Boot sequence ───────────────────────────────────────────────────── */

.boot { font-size: .95em; white-space: pre-wrap; }
.boot-line { opacity: 0; animation: bootin .01s forwards; }
@keyframes bootin { to { opacity: 1; } }

.cursor::after {
  content: '\2588';
  animation: blink 1.05s steps(1) infinite;
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Idle / attract screen ───────────────────────────────────────────── */

.attract {
  height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  gap: .9rem;
}
.attract-logo {
  font-size: clamp(2rem, 7vw, 4rem);
  font-weight: 700;
  letter-spacing: .3em;
  margin-left: .3em;
  color: var(--p-green);
  text-shadow: 0 0 24px var(--p-glow), 0 0 3px #fff;
}
.attract-sub { letter-spacing: .28em; font-size: .8em; color: var(--p-dim); }
.attract-cta {
  margin-top: .6rem;
  letter-spacing: .2em;
  color: var(--p-amber);
  animation: pulse 1.7s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .32; } }

/* ── Game stage ──────────────────────────────────────────────────────── */

.stage {
  position: relative;
  width: 100%; height: 100%;
  display: grid;
  /* hud · canvas · footer hint · touch controls. The canvas row is the only
     flexible one, so the controls always get the height they need. */
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}

.stage-hud {
  display: flex; align-items: center; gap: 1rem;
  padding: .5rem clamp(.7rem, 1.6vw, 1.1rem);
  font-size: .78em;
  letter-spacing: .12em;
  border-bottom: 1px solid rgba(124,252,155,.2);
  background: rgba(0,0,0,.35);
  flex-wrap: wrap;
}
.hud-item { display: flex; gap: .4rem; align-items: baseline; }
.hud-key { color: var(--p-dim); font-size: .85em; }
.hud-val { color: #eaffef; font-variant-numeric: tabular-nums; min-width: 2ch; }
.hud-spacer { flex: 1; }
.hud-title { color: var(--p-amber); font-weight: 700; }

.stage-canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: .4rem;
}
.stage-canvas-wrap canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
  background: #04080a;
  box-shadow: 0 0 0 1px rgba(124,252,155,.18), 0 0 28px -8px var(--p-glow);
}

.stage-foot {
  padding: .45rem clamp(.7rem, 1.6vw, 1.1rem);
  font-size: .7em;
  letter-spacing: .1em;
  color: var(--p-dim);
  border-top: 1px solid rgba(124,252,155,.14);
  background: rgba(0,0,0,.35);
  display: flex; gap: .9rem; flex-wrap: wrap; align-items: center;
}

/* Overlay shown for start / pause / game-over */
.overlay {
  position: absolute; inset: 0;
  z-index: 4;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  gap: .7rem;
  padding: 1.2rem;
  background: rgba(4, 12, 7, .86);
  backdrop-filter: blur(1.5px);
}
.overlay[hidden] { display: none; }
.overlay-title {
  font-size: clamp(1.1rem, 3.4vw, 1.9rem);
  letter-spacing: .22em;
  font-weight: 700;
  color: var(--p-amber);
  text-shadow: 0 0 18px rgba(255,180,84,.45);
}
.overlay-sub { font-size: .85em; color: var(--p-green); letter-spacing: .1em; max-width: 42ch; }
.overlay-score { font-size: 1.15em; color: #eaffef; letter-spacing: .12em; }
.overlay-actions { display: flex; gap: .55rem; flex-wrap: wrap; justify-content: center; margin-top: .3rem; }

/* Initials entry.
   A single real <input> sits transparently over three display cells: one input
   means no cross-field focus race, while the cells keep the arcade look. */
.initials {
  position: relative;
  display: flex;
  gap: .45rem;
  justify-content: center;
  margin: .3rem 0;
}
/* The real input sits transparently over the cells, so a native selection
   would paint a highlight band across them with no visible text inside it —
   it reads as a rendering glitch. The select-all behaviour is still wanted
   (typing replaces the remembered initials), just not its default painting. */
.ini-input::selection { background: transparent; color: transparent; }
.ini-input::-moz-selection { background: transparent; color: transparent; }

.ini-input {
  position: absolute;
  inset: 0;
  width: 100%;
  font: inherit;
  font-size: clamp(1.4rem, 4vw, 2.1rem);
  text-align: center;
  letter-spacing: 1.35em;
  text-indent: 1.35em;
  color: transparent;
  caret-color: transparent;
  background: transparent;
  border: none;
  outline: none;
  z-index: 2;
  cursor: text;
}
.ini-cell {
  display: grid;
  place-items: center;
  width: 2.4em;
  font-size: clamp(1.4rem, 4vw, 2.1rem);
  line-height: 1.35;
  color: var(--p-dim);
  background: rgba(124,252,155,.06);
  border: 1px solid var(--p-dim);
  border-radius: 2px;
  transition: border-color .12s, box-shadow .12s, color .12s, background .12s;
}
.ini-cell[data-filled="true"] { color: var(--p-green); }
.ini-cell[data-active="true"] {
  border-color: var(--p-green);
  background: rgba(124,252,155,.16);
  box-shadow: 0 0 14px -2px var(--p-glow);
  animation: inicaret 1.05s steps(1) infinite;
}
@keyframes inicaret { 50% { border-color: var(--p-dim); } }

.submit-state { font-size: .8em; letter-spacing: .1em; min-height: 1.4em; }
.submit-state[data-tone="ok"]   { color: var(--p-green); }
.submit-state[data-tone="err"]  { color: #ff9a8a; }
.submit-state[data-tone="wait"] { color: var(--p-dim); }

/* ── Leaderboard tables ──────────────────────────────────────────────── */

.lb-tabs { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: 1rem; }
.lb-tab {
  font: inherit; font-size: .72em; letter-spacing: .1em;
  cursor: pointer;
  padding: .32rem .6rem;
  color: var(--p-dim);
  background: transparent;
  border: 1px solid rgba(124,252,155,.22);
  border-radius: 2px;
}
.lb-tab[aria-selected="true"] { color: #04170b; background: var(--p-green); text-shadow: none; }
.lb-tab:focus-visible { outline: 2px solid var(--p-amber); outline-offset: 1px; }

.lb-wrap { width: min(30rem, 100%); }
.lb-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.lb-table th {
  text-align: left;
  font-size: .68em; letter-spacing: .18em;
  color: var(--p-dim);
  font-weight: 400;
  padding: .3rem .5rem;
  border-bottom: 1px solid rgba(124,252,155,.25);
}
.lb-table td { padding: .32rem .5rem; border-bottom: 1px dotted rgba(124,252,155,.13); }
.lb-table tr[data-rank="1"] td { color: var(--p-amber); }
.lb-table .rank { width: 3.5ch; color: var(--p-dim); }
.lb-table .who  { letter-spacing: .28em; color: #eaffef; }
.lb-table .score { text-align: right; color: #eaffef; }
.lb-table .when { text-align: right; color: var(--p-dim); font-size: .82em; white-space: nowrap; }
.lb-table tr[data-you="true"] td { background: rgba(124,252,155,.09); }

.lb-empty { color: var(--p-dim); padding: 1.2rem 0; }

/* ── Touch controls (mobile only) ────────────────────────────────────── */

.touchpad { display: none; }

@media (pointer: coarse) {
  .touchpad {
    display: grid;
    gap: .4rem;
    padding: .5rem clamp(.7rem, 1.6vw, 1.1rem) .7rem;
    background: rgba(0,0,0,.35);
    border-top: 1px solid rgba(124,252,155,.14);
  }
  .touchpad[data-layout="dpad"]  { grid-template-columns: repeat(3, 1fr); max-width: 260px; margin: 0 auto; }
  .touchpad[data-layout="lr"]    { grid-template-columns: repeat(4, 1fr); }
  .touchpad[data-layout="tap"]   { grid-template-columns: 1fr; }
  .tbtn {
    font: inherit; font-size: 1.05rem;
    -webkit-user-select: none; user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    padding: .85rem 0;
    color: var(--p-green);
    background: rgba(124,252,155,.1);
    border: 1px solid var(--p-dim);
    border-radius: 4px;
  }
  .tbtn:active { background: var(--p-green); color: #04170b; }
  .tbtn[data-slot="blank"] { visibility: hidden; }
  .stage-foot { display: none; }
}

/* Small screens: switch the tube to portrait. Every game canvas is taller than
   it is wide, so a 4:3 landscape screen on a phone letterboxes the playfield
   down to a stamp with dead space above and below it. */
@media (max-width: 620px) {
  .screen { aspect-ratio: 3 / 4; max-height: 74dvh; }
}

/* ── Market panel ────────────────────────────────────────────────────── */

.live-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--p-green);
  box-shadow: 0 0 8px 1px var(--p-glow);
  margin-right: .45rem;
  vertical-align: middle;
  animation: livepulse 2s ease-in-out infinite;
}
@keyframes livepulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.price-hero {
  display: flex;
  align-items: baseline;
  gap: .9rem;
  flex-wrap: wrap;
  margin: 0 0 1.1rem;
  padding: .85rem 1rem;
  border: 1px solid rgba(124,252,155,.35);
  background: rgba(124,252,155,.05);
  border-radius: 3px;
}
.price-now {
  font-size: clamp(1.5rem, 4.5vw, 2.3rem);
  font-weight: 700;
  letter-spacing: .04em;
  color: #eaffef;
  font-variant-numeric: tabular-nums;
}
.price-chg { font-size: .9em; letter-spacing: .1em; color: var(--p-dim); }

.up   { color: #7cfc9b; }
.down { color: #ff8f8f; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: .5rem;
  margin: 0 0 1.2rem;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  padding: .55rem .7rem;
  border: 1px solid rgba(124,252,155,.18);
  background: rgba(0,0,0,.28);
  border-radius: 2px;
}
.stat-k { font-size: .62em; letter-spacing: .18em; color: var(--p-dim); }
.stat-v {
  font-size: 1.02em;
  color: #eaffef;
  font-variant-numeric: tabular-nums;
  letter-spacing: .03em;
}

/* Compact live readout on the CONTRACT disk */
.live-strip {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  font-size: .84em;
  letter-spacing: .06em;
  padding: .5rem .75rem;
  margin: 0 0 1.1rem;
  border-left: 2px solid var(--p-dim);
  background: rgba(0,0,0,.25);
}
.live-strip strong { color: #eaffef; font-variant-numeric: tabular-nums; }
