/* =====================================================================
   Neon Rush, split view.
   Left: a monitor showing the game. Right: a printout of the code on
   green-bar paper, marked up with highlighter and pen while it runs.
   Below 980px wide the printout moves underneath the monitor.
   ===================================================================== */
:root {
  --slab: #1c1e22;        /* monitor plastic / desk */
  --slab-2: #26292e;
  --slab-line: #34373d;
  --slab-ink: #e6e3da;
  --slab-muted: #9a978f;
  --bezel: #0f1012;
  --game-cyan: #37e5ff;   /* from the game's own art */
  --game-gold: #ffd36a;

  --paper: #fdfdf8;
  --bar: #e2eedc;         /* green-bar stripe */
  --perf: #e4e3da;
  --ink: #24272c;
  --ink-soft: #6a6e75;
  --pen: #2347a8;         /* ballpoint blue */
  --red-pen: #c4332a;
  --marker: #fff06a;      /* highlighter */
  --lit: #8a3b12;         /* strings and numbers on the printout */

  --serif: 'Literata', Georgia, 'Times New Roman', serif;
  --mono: 'Courier Prime', 'Courier New', Courier, monospace;
  --pixel: 'Silkscreen', 'Courier New', monospace;

  --line: 20px;           /* one printed line of code */
  --holes: 34px;          /* tractor-feed margin */
  --sticky-h: 150px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--slab);
  color: var(--slab-ink);
  font: 400 15px/1.6 var(--serif);
  -webkit-font-smoothing: antialiased;
}
body.split {
  display: grid;
  grid-template-columns: minmax(0, var(--left, 56%)) 12px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}
body.dragging { cursor: col-resize; user-select: none; }
body.dragging * { pointer-events: none; }
body.dragging .gutter { pointer-events: auto; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

/* ===================== Left: the monitor ===================== */
.screen-side {
  overflow-y: auto;
  padding: 18px 26px 32px;
  container-type: inline-size;
  scrollbar-width: thin; scrollbar-color: var(--slab-line) transparent;
}
.screen-top { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.logo { margin: 0; font: 700 22px/1 var(--pixel); color: var(--slab-ink); letter-spacing: 0; }
.best { margin: 0; color: var(--slab-muted); font-size: 14px; text-align: right; }
.best b { font: 700 16px var(--mono); color: var(--game-gold); margin-left: 6px; }

.game-shell {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 12px solid var(--bezel);
  border-radius: 14px;
  box-shadow: 0 0 0 1px var(--slab-line), 0 24px 40px -24px #000;
  background: #050916;
  container-type: inline-size;
}
.game-shell canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }

.game-hud {
  position: absolute; top: 14px; left: 18px; right: 18px;
  display: flex; justify-content: space-between; pointer-events: none;
  font-family: var(--pixel);
}
.game-hud div { display: flex; flex-direction: column; gap: 2px; }
.game-hud span { font-size: 10px; color: #8ea5c4; }
.game-hud strong { font-size: 20px; font-weight: 400; color: #f3f8ff; }
.hud-score { align-items: center; }
.hud-score strong { color: var(--game-cyan); }
.hud-combo { min-height: 14px; font-style: normal; font-size: 12px; color: var(--game-gold); }
.game-hud .hud-score strong { font-size: 44px; line-height: 1; text-shadow: 0 2px 0 #000; }
.hud-best { align-items: flex-end; }
.hud-best strong { color: var(--game-gold); }
.tap-hint {
  position: absolute; left: 50%; bottom: 16%; transform: translateX(-50%);
  margin: 0; padding: 6px 14px; border-radius: 20px;
  background: rgba(8, 10, 16, .7); color: #fff; font-size: 15px; white-space: nowrap;
  pointer-events: none;
}
.tap-hint kbd { color: #fff; }

/* Top 5 inside the game screen, beside the form and the results */
.overlay.with-board { flex-direction: row; gap: 30px; }
.overlay-main { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.player-form.overlay-main { display: block; width: min(420px, 100%); }
.board-panel {
  flex: none; width: 236px; align-self: center;
  padding-left: 24px; border-left: 1px solid #ffffff24; text-align: left;
}
.board-panel h3 { margin: 0 0 8px; font: 700 16px var(--pixel); color: #fff; }
.board-panel .score-list { list-style: none; margin: 0; padding: 0; }
.board-panel .leader-row { grid-template-columns: 20px minmax(0, 1fr) auto; gap: 8px; padding: 6px 0; border-bottom: 1px solid #ffffff14; }
.board-panel .leader-row.is-you { padding-left: 6px; }
.board-panel .rank-badge { font-size: 13px; }
.board-panel .player-info { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.board-panel .player-info small { display: block; margin: 1px 0 0; font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
.board-panel .player-score { font-size: 15px; }
.board-panel .open-spot .player-info small { display: none; }
/* Narrower game screen: keep the Top 5 beside the result, just more compact */
@container (max-width: 680px) {
  .overlay.with-board { gap: 18px; padding: 12px 16px; }
  .board-panel { width: 180px; padding-left: 16px; }
  .board-panel h3 { font-size: 14px; margin-bottom: 4px; }
  .board-panel .leader-row { padding: 4px 0; gap: 6px; grid-template-columns: 16px minmax(0, 1fr) auto; }
  .board-panel .player-info { font-size: 13px; }
  .board-panel .player-info small { font-size: 10px; }
  .board-panel .player-score { font-size: 14px; }
  .end .btn { width: 190px; }
}
/* Only on very small screens (phones) is there no room: the Top 5 moves below the game */
@container (max-width: 440px) {
  .board-panel { display: none; }
  .overlay.with-board { flex-direction: column; gap: 0; }
}

/* Photo picker on the start screen */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.fields .photo-field { grid-row: span 2; display: flex; align-items: center; justify-content: center; }
.fields .photo-pick { align-items: center; gap: 6px; cursor: pointer; font-size: 12px; text-align: center; }
.photo-preview {
  position: relative; display: block; width: 68px; height: 68px; border-radius: 50%;
  border: 2px dashed #5a5d64; background: #ffffff08 center / cover no-repeat;
}
.photo-preview::after { content: '+'; position: absolute; inset: 0; display: grid; place-items: center; font: 400 28px var(--serif); color: var(--slab-muted); }
.photo-preview[style*="url"] { border: 2px solid var(--game-cyan); }
.photo-preview[style*="url"]::after { content: none; }
.photo-pick:hover .photo-preview { border-color: var(--game-cyan); }
.photo-pick:hover { color: var(--slab-ink); }
.sr-only:focus-visible + .photo-pick .photo-preview { outline: 2px solid #fff; outline-offset: 3px; }
.hud-lives { align-items: flex-end; }
.hud-lives strong { color: #ff4fd8; font-size: 16px; letter-spacing: 3px; }

.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px; text-align: center;
  background: rgba(8, 10, 16, .84);
  overflow-y: auto;
}
.player-form { width: min(460px, 100%); text-align: left; }
.form-title { margin: 0 0 16px; font: 700 26px/1.1 var(--pixel); color: #fff; text-align: center; }
.fields { display: grid; grid-template-columns: 92px 1fr 1fr; gap: 14px 18px; margin-bottom: 20px; }
.field-name { grid-column: 2 / -1; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--slab-muted); }
.fields input, .fields select {
  width: 100%; height: 34px; padding: 0 2px;
  border: 0; border-bottom: 2px solid #5a5d64; border-radius: 0;
  background: transparent; color: #fff; font: 400 17px var(--serif);
  outline: none;
}
.fields select { cursor: pointer; }
.fields select option { background: var(--slab-2); color: var(--slab-ink); }
.fields input:focus, .fields select:focus { border-bottom-color: var(--game-cyan); }
.btn {
  display: block; width: 100%; height: 44px; border: 0; border-radius: 4px;
  background: var(--game-cyan); color: var(--bezel);
  font: 700 16px var(--pixel); cursor: pointer;
}
.btn:hover { background: #7ff0ff; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .fields input:focus-visible, .fields select:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.form-message { min-height: 22px; margin: 8px 0 0; font-size: 13px; color: #ff9b93; text-align: center; }

.countdown { background: rgba(8, 10, 16, .6); }
.countdown strong { font: 700 clamp(80px, 18cqw, 150px)/1 var(--pixel); color: var(--game-cyan); }

.end p { margin: 0; }
.end-kicker { font-style: italic; color: var(--slab-muted); font-size: 15px; }
.end h2 { margin: 2px 0 0; font: 700 30px/1.15 var(--pixel); color: #fff; }
.final-score { font: 700 clamp(40px, 9cqw, 64px)/1.1 var(--pixel); color: var(--game-gold); margin: 6px 0 4px; }
.end-message { color: var(--slab-muted); font-size: 14px; max-width: 40ch; }
.result-rank { color: var(--slab-ink); font-size: 16px; margin: 4px 0 18px !important; }
.end .btn { width: 220px; }
.again-hint { margin-top: 10px !important; font-size: 13px; color: var(--slab-muted); }
.again-hint kbd { font-size: 11px; line-height: 18px; }
.again-hint .link-button { font-size: 13px; }
.again-hint .link-button:hover { color: var(--slab-ink); }

.mobile-controls { position: absolute; bottom: 10px; left: 12px; right: 12px; display: flex; justify-content: space-between; pointer-events: none; }
.mobile-controls button { pointer-events: auto; width: 58px; height: 50px; border-radius: 8px; border: 1px solid #ffffff40; background: #0008; color: #fff; font-size: 30px; }
@media (hover: hover) and (pointer: fine) { .mobile-controls { display: none !important; } }

.how-to { margin: 16px 0 26px; max-width: 68ch; color: var(--slab-muted); font-size: 14px; }
kbd {
  display: inline-block; min-width: 22px; padding: 0 5px; text-align: center;
  font: 700 12px/20px var(--mono); color: var(--slab-ink);
  border: 1px solid #55585f; border-bottom-width: 2px; border-radius: 3px;
}

/* When the Top 5 fits inside the game screen, don't repeat it below */
/* When the Top 5 fits inside the game screen, don't repeat it below (keep "Clear scores") */
@container (min-width: 465px) {   /* = the game screen is wider than 440px, so its own Top 5 is showing */
  .scores { display: none; }   /* the Top 5 is inside the game screen instead */
}
.scores-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--slab-line); padding-bottom: 8px; }
.scores h2 { margin: 0; font: 600 17px var(--serif); color: var(--slab-ink); }
.link-button { border: 0; background: none; padding: 0; color: var(--slab-muted); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link-button:hover { color: #ff9b93; }
.score-list { list-style: none; margin: 0; padding: 0; }
.leader-row { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 10px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--slab-2); }
.rank-badge { font: 700 14px var(--mono); color: var(--slab-muted); }
.player-info b { font-weight: 600; color: var(--slab-ink); }
.player-info small { margin-left: 8px; font-size: 13px; color: var(--slab-muted); }
.player-score { font: 700 16px var(--mono); color: var(--slab-ink); }
.leader-row:first-child .player-score, .leader-row:first-child .rank-badge { color: var(--game-gold); }
.leader-row.is-you { background: linear-gradient(90deg, #37e5ff1f, transparent 80%); box-shadow: inset 3px 0 0 var(--game-cyan); padding-left: 8px; }
.leader-row.is-you .player-info b::after { content: ' (you)'; font-weight: 400; color: var(--game-cyan); }
.leader-row.open-spot .player-info b, .leader-row.open-spot .player-score { color: #55585f; font-weight: 400; font-style: italic; }
.empty-board { padding: 14px 0; color: var(--slab-muted); font-style: italic; }

/* Smaller monitor: tighten the overlays */
@container (max-width: 600px) {
  .form-title { font-size: 20px; margin-bottom: 10px; }
  .fields { gap: 8px 14px; margin-bottom: 12px; }
  .fields input, .fields select { height: 30px; font-size: 15px; }
  .btn { height: 38px; font-size: 14px; }
  .end h2 { font-size: 22px; }
  .result-rank { margin-bottom: 10px !important; }
  .game-hud { top: 8px; left: 10px; right: 10px; }
  .game-hud strong { font-size: 15px; }
}
@container (max-width: 440px) {
  .overlay { padding: 8px 14px; }
  .form-title, .end-message, .end-kicker, .again-hint kbd { display: none; }
  .again-hint { margin-top: 4px !important; font-size: 11px; }
  .fields { grid-template-columns: 48px 1.3fr 1fr 1fr; gap: 8px; }
  .field-name { grid-column: auto; }
  .fields .photo-field { grid-row: auto; }
  .photo-preview { width: 42px; height: 42px; }
  #photoText, .tap-hint kbd { display: none; }
  .game-hud .hud-score strong { font-size: 30px; }
  .tap-hint { font-size: 12px; }
  .fields label { font-size: 11px; }
  .fields input, .fields select { font-size: 14px; height: 28px; }
  .form-message { min-height: 0; }
  .end h2 { font-size: 16px; }
  .final-score { font-size: 32px; }
  .result-rank { font-size: 13px; }
  .end .btn { height: 34px; }
}

/* ===================== Divider ===================== */
.gutter { position: relative; cursor: col-resize; background: var(--slab); outline: none; }
.gutter::after {
  content: ''; position: absolute; top: 50%; left: 4px; width: 4px; height: 48px; transform: translateY(-50%);
  border-radius: 2px; background: var(--slab-line);
}
.gutter:hover::after, .gutter:focus-visible::after, body.dragging .gutter::after { background: var(--slab-ink); }

/* ===================== Right: the code listing ===================== */
/* Day = printout on green-bar paper. Night (default) = the same printout, dark. */
.paper {
  --p-bg: var(--paper);
  --p-bar: var(--bar);
  --p-ink: var(--ink);
  --p-soft: var(--ink-soft);
  --p-com: #7a7d74;
  --p-lit: var(--lit);
  --p-link: var(--pen);
  --p-lnum: #9a9d93;
  --p-hot: rgba(255, 236, 80, .75);     /* highlighter over running code */
  --p-hot-edge: #d9a800;
  --p-warm: rgba(255, 236, 80, .28);
  --p-warm-edge: rgba(217, 168, 0, .4);
  --p-idle: .5;
  --p-hole: var(--slab);
  --p-perf: var(--perf);
  --p-head-line: #c4c3ba;
}
body.night .paper {
  --p-bg: #131518;
  --p-bar: #181d1b;
  --p-ink: #d9d6cc;
  --p-soft: #8d9088;
  --p-com: #6f746d;
  --p-lit: #e2ab73;
  --p-link: #93b4ff;
  --p-lnum: #4a4f56;
  --p-hot: rgba(255, 206, 84, .2);
  --p-hot-edge: #ffce54;
  --p-warm: rgba(255, 206, 84, .07);
  --p-warm-edge: rgba(255, 206, 84, .35);
  --p-idle: .42;
  --p-hole: #08090a;
  --p-perf: #24272b;
  --p-head-line: #2c3035;
}

.paper {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 var(--holes);
  color: var(--p-ink);
  /* tractor-feed holes down both edges, the perforation lines, then the paper */
  background:
    radial-gradient(circle at 17px 12px, var(--p-hole) 5px, transparent 5.5px) left top / var(--holes) 24px repeat-y,
    radial-gradient(circle at 17px 12px, var(--p-hole) 5px, transparent 5.5px) right top / var(--holes) 24px repeat-y,
    linear-gradient(to right,
      transparent calc(var(--holes) - 1px), var(--p-perf) calc(var(--holes) - 1px), var(--p-perf) var(--holes), transparent var(--holes),
      transparent calc(100% - var(--holes)), var(--p-perf) calc(100% - var(--holes)), var(--p-perf) calc(100% - var(--holes) + 1px), transparent calc(100% - var(--holes) + 1px)),
    var(--p-bg);
  background-attachment: local, local, local, local;
  scrollbar-width: thin; scrollbar-color: var(--p-perf) transparent;
  transition: background-color .2s, color .2s;
}
.paper ::selection { background: var(--p-hot-edge); color: #111; }

.paper-head {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px 10px 0;
  background: var(--p-bg);
  border-bottom: 1px dashed var(--p-head-line);
}
.file-name { margin: 0; font: 400 13px var(--mono); color: var(--p-soft); }
.head-buttons { display: flex; gap: 6px; }
.head-btn {
  border: 1px solid var(--p-head-line); border-radius: 3px; background: none;
  padding: 2px 10px; font: 400 13px var(--mono); color: var(--p-ink); cursor: pointer;
}
.head-btn:hover { border-color: var(--p-soft); }
.head-btn:focus-visible { outline: 2px solid var(--p-link); outline-offset: 2px; }
.theme-toggle::before { content: '☾ '; }
.theme-toggle[aria-pressed="false"]::before { content: '☀ '; }
.follow-toggle::before { content: '○ '; }
.follow-toggle[aria-pressed="true"]::before { content: '● '; color: var(--p-hot-edge); }
.follow-toggle[aria-pressed="false"] { color: var(--p-soft); }
@media (max-width: 980px) { .follow-toggle { display: none; } }

pre.code {
  margin: 0; padding: 12px 0 48px;
  overflow-x: auto;              /* long lines scroll sideways inside the listing */
  scrollbar-width: thin; scrollbar-color: var(--p-perf) transparent;
  font: 400 13px/var(--line) var(--mono);
  color: var(--p-ink);
  font-variant-ligatures: none;
  counter-reset: ln;
  /* green-bar paper: three lines striped, three lines plain */
  background: repeating-linear-gradient(to bottom, var(--p-bar) 0 calc(var(--line) * 3), transparent calc(var(--line) * 3) calc(var(--line) * 6))
              0 12px / 100% calc(100% - 60px) no-repeat;
}
pre.code code { display: block; min-width: max-content; font: inherit; }
pre.code .ln { display: block; white-space: pre; padding-right: 14px; }
pre.code .ln::before {
  counter-increment: ln; content: counter(ln);
  display: inline-block; width: 36px; margin-right: 14px; padding-right: 8px; text-align: right;
  color: var(--p-lnum); user-select: none;
  border-right: 3px solid transparent;
}
/* Lines that just ran: "hot" = in the last ~0.2 s, "warm" = fading out */
pre.code .ln.hot { background: var(--p-hot); }
pre.code .ln.hot::before { border-right-color: var(--p-hot-edge); color: var(--p-ink); }
pre.code .ln.warm { background: var(--p-warm); }
pre.code .ln.warm::before { border-right-color: var(--p-warm-edge); }
/* During a run, code that isn't running steps back so the live lines stand out */
pre.code.running .ln:not(.hot):not(.warm) { opacity: var(--p-idle); }
pre.code .ln.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 30% { box-shadow: inset 0 0 0 999px rgba(147, 180, 255, .22); } 100% { box-shadow: none; } }

/* Syntax colours: mostly ink, a little colour where it helps reading */
.t-com { color: var(--p-com); font-style: italic; }
.t-kw { font-weight: 700; }
.t-str, .t-num { color: var(--p-lit); }
.t-lit { color: var(--p-lit); font-weight: 700; }
.t-game, .t-const { font-weight: 700; }
.t-link { color: var(--p-link); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--p-link) 40%, transparent); text-underline-offset: 3px; cursor: pointer; }
.t-link:hover { text-decoration-color: var(--p-link); }
.t-link:focus-visible { outline: 2px solid var(--p-link); outline-offset: 1px; }

/* ===================== Narrow screens: code under the monitor ===================== */
@media (max-width: 980px) {
  body.split { display: block; height: auto; overflow: auto; }
  .screen-side { overflow: visible; }
  .paper { overflow: visible; }
  .paper-head { position: static; }
  .gutter { display: none; }
}
@media (max-width: 560px) {
  :root { --holes: 22px; }
  .paper { background:
      radial-gradient(circle at 11px 12px, var(--p-hole) 3.5px, transparent 4px) left top / var(--holes) 24px repeat-y,
      radial-gradient(circle at 11px 12px, var(--p-hole) 3.5px, transparent 4px) right top / var(--holes) 24px repeat-y,
      var(--p-bg); }
  .screen-side { padding: 14px 14px 26px; }
  .game-shell { border-width: 7px; border-radius: 10px; }
  pre.code { font-size: 12px; }
  pre.code .ln::before { width: 30px; margin-right: 8px; padding-right: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  .paper { transition: none; }
  pre.code .ln.flash { animation: none; }
}

/* "Live for everyone" / "Offline" note under each Top 5 */
.board-note { margin: 8px 0 0; font-size: 12px; font-style: italic; color: var(--slab-muted); }
.board-panel .board-note { font-size: 11px; margin-top: 6px; }
