/*
 * One arcade cabinet, four screens. The chassis, marquee and control strip
 * never move; only what sits behind the bezel changes.
 */

/*
 * Self-hosted so the cabinet works with no network: this is a game people
 * run on localhost. Latin subsets only, which is all the interface uses.
 * Both fall back to a monospace stack, whose fixed advance is the closest
 * match for a pixel font while the real one is still loading.
 */
@font-face {
  font-family: "Silkscreen";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/silkscreen-400.woff2") format("woff2");
}

@font-face {
  font-family: "Silkscreen";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/silkscreen-700.woff2") format("woff2");
}

@font-face {
  font-family: "VT323";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/vt323-400.woff2") format("woff2");
}

:root {
  color-scheme: dark;

  /* Cabinet */
  --chassis: #101014;
  --recess: #07070a;
  --edge: #2a2a32;
  --panel: #17171f;
  --red: #ff3355;
  --gold: #f5b942;
  --text: #e8e8ea;
  /* 6.45:1 on --panel, 7.28:1 on --recess, 6.87:1 on --chassis. */
  --dim: #9a9aad;

  /* Seat one of the player palette in app.js. Kept in step by hand so READY
     and the logo snake are the same green the board draws. */
  --green: #4ade80;

  /* Results podium only. */
  --silver: #b9bec9;
  --bronze: #c8823c;

  /* Machine lettering: labels, tags, the wordmark. */
  --font-display: "Silkscreen", ui-monospace, SFMono-Regular, Consolas, monospace;

  /* Numbers, and only numbers: room code, levels, the clock. */
  --font-mono: "VT323", ui-monospace, SFMono-Regular, Consolas, monospace;

  /* Anything a person wrote, or has to read at length. */
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 24px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom))
           max(16px, env(safe-area-inset-left));
  background: var(--recess);
  color: var(--text);
  font: 14px/1.5 var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

/* Focus is a white ring throughout, the same cue the board puts on your head. */
:where(a, button, input, [tabindex]):focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

#screen:focus-visible { outline-offset: -2px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 10;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
  transform: translateY(-72px);
  transition: transform 120ms ease;
}

.skip-link:focus-visible { transform: translateY(0); }

/* --- chassis ------------------------------------------------------------ */

.cabinet {
  max-width: 900px;
  margin: 0 auto;
  background: var(--chassis);
  border: 0.5px solid var(--edge);
  border-radius: 12px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.035),
    0 2px 6px rgba(0, 0, 0, 0.45),
    0 20px 50px rgba(0, 0, 0, 0.55);
}

/* --- marquee ------------------------------------------------------------ */

.marquee {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 0.5px solid var(--edge);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
}

.logo-mark {
  display: block;
  flex: none;
  width: 90px;
  height: 30px;
}

.logo-cell { fill: var(--green); }
.logo-cell--head { fill: #bbf7d0; }
.logo-dot { fill: var(--gold); }

.logo-word {
  display: flex;
  flex-direction: column;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 4px;
  /* Letter-spacing hangs off the last glyph; pull the block back to sit flush. */
  margin-right: -4px;
}

.logo-tanchi { color: var(--text); }
.logo-snake { color: var(--red); }

.marquee-right {
  flex: none;
  text-align: right;
}

.marquee-code {
  margin: 0 -4px 2px 0;
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: 4px;
  color: var(--gold);
}

.screen-name {
  margin: 0 -3px 0 0;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--dim);
}

/* --- banner ------------------------------------------------------------- */

.banner {
  margin: 18px 18px 0;
  padding: 10px 12px;
  background: rgba(255, 51, 85, 0.08);
  border: 1px solid var(--red);
  border-radius: 6px;
  color: var(--red);
  font-size: 13px;
}

/* --- screen recess ------------------------------------------------------ */

.recess {
  position: relative;
  margin: 18px;
  padding: 14px;
  min-height: 320px;
  background: var(--recess);
  border: 2px solid var(--edge);
  border-radius: 8px;
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.75);
}

/* Scanlines. 2px period at 3% white: visible on the flat panels, and at 12px
   cells it never eats a snake segment on the 48x48 board. */
.recess::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  border-radius: 6px;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.03) 0,
    rgba(255, 255, 255, 0.03) 1px,
    transparent 1px,
    transparent 2px
  );
}

.screen {
  position: relative;
  z-index: 1;
}

/* --- control strip ------------------------------------------------------ */

.controls {
  display: flex;
  align-items: center;
  min-height: 64px;
  padding: 13px 18px;
  border-top: 0.5px solid var(--edge);
}

.control-set {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  width: 100%;
}

.control-set--game { justify-content: space-between; }

.control-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* --- buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 18px;
  background: transparent;
  border: 1px solid var(--edge);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease,
              box-shadow 120ms ease, transform 80ms ease;
}

/* Leaving is never the thing you came here to do. */
.btn--quiet {
  border-color: transparent;
  color: var(--dim);
}

.btn--quiet:hover,
.btn--quiet:focus-visible {
  border-color: var(--edge);
  color: var(--text);
}

.btn--red {
  background: var(--red);
  border-color: var(--red);
  color: var(--chassis);
  font-weight: 600;
}

.btn--red:hover,
.btn--red:focus-visible {
  color: #06060a;
  box-shadow: 0 0 0 3px rgba(255, 51, 85, 0.24);
}

.btn--gold {
  border-color: var(--gold);
  color: var(--gold);
}

.btn--gold:hover,
.btn--gold:focus-visible { background: rgba(245, 185, 66, 0.14); }

.btn--green {
  border-color: var(--green);
  color: var(--green);
}

.btn--green:hover,
.btn--green:focus-visible { background: rgba(74, 222, 128, 0.14); }

/* You are ready: the fill is the second cue, the label change is the first. */
.btn--green.is-on {
  background: var(--green);
  border-color: var(--green);
  color: var(--chassis);
  font-weight: 600;
}

.btn--green.is-on:hover,
.btn--green.is-on:focus-visible {
  color: #06060a;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.24);
}

.btn:active { transform: translateY(1px); }

/* --- labels, hints, inputs ---------------------------------------------- */

.field-label {
  display: block;
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}

.hint {
  margin: 12px 0 0;
  color: var(--dim);
  font-size: 13px;
  text-wrap: balance;
}

input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-body);
  /* 16px keeps iOS from zooming the whole cabinet on focus. */
  font-size: 16px;
  transition: border-color 120ms ease;
}

input::placeholder { color: var(--dim); }

input:hover { border-color: #3a3a45; }

input:focus-visible { border-color: var(--text); }

/* An input is somewhere people type, so it keeps the body face. */
.room-input {
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 6px;
  text-transform: uppercase;
}

/* --- 1. menu ------------------------------------------------------------ */

.screen--menu {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 292px;
}

.menu-form {
  display: grid;
  gap: 18px;
  width: 100%;
  max-width: 340px;
}

/* --- 2. lobby ----------------------------------------------------------- */

.screen--lobby {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.room-code {
  display: block;
  margin: 0 0 0 -8px;
  padding: 2px 8px;
  background: transparent;
  border: 1px dashed transparent;
  border-radius: 6px;
  cursor: copy;
  touch-action: manipulation;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.room-code:hover,
.room-code:focus-visible {
  background: rgba(245, 185, 66, 0.07);
  border-color: var(--edge);
}

.room-code-value {
  display: block;
  margin-right: -5px;
  font-family: var(--font-mono);
  font-size: 39px;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: 5px;
  color: var(--gold);
}

.copy-status {
  margin: 8px 0 0;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}

.copy-status.is-done { color: var(--green); }

/* --- 3. game ------------------------------------------------------------ */

.screen--game {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.board-wrap { flex: none; }

/*
 * 576 CSS pixels at 48 cells of 12. app.js sizes the backing store to the
 * display so a cell is a whole number of device pixels; the CSS size never
 * changes, because a fractional cell renders blurry.
 */
#board {
  display: block;
  width: 576px;
  height: 576px;
  background: var(--recess);
  border: 1px solid var(--edge);
  border-radius: 2px;
}

.scorepanel {
  display: flex;
  flex: none;
  flex-direction: column;
  width: 236px;
  min-height: 576px;
}

.tickline {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 16px 0 0;
  padding-top: 10px;
  border-top: 0.5px solid var(--edge);
}

.tickline .field-label { margin: 0; }

.tick-value {
  font-family: var(--font-mono);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  color: var(--dim);
}

/* Direction read-out, not a control: five cells, the live one in white. */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 12px);
  grid-template-rows: repeat(3, 12px);
  gap: 3px;
}

.dpad-cell {
  background: var(--edge);
  border-radius: 2px;
  transition: background-color 120ms ease;
}

.dpad-up { grid-area: 1 / 2; }
.dpad-left { grid-area: 2 / 1; }
.dpad-mid { grid-area: 2 / 2; }
.dpad-right { grid-area: 2 / 3; }
.dpad-down { grid-area: 3 / 2; }

.dpad-cell.is-lit { background: var(--text); }

.keyhint {
  margin: 0 -3px 0 0;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--dim);
}

.lamp {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--red);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.2),
    inset 0 -3px 4px rgba(0, 0, 0, 0.4),
    0 0 14px rgba(255, 51, 85, 0.22);
}

/* --- 4. results --------------------------------------------------------- */

.rows--standings { gap: 5px; }

.standing-rank {
  flex: none;
  width: 26px;
  font-family: var(--font-display);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
  text-align: right;
}

.standing--1 {
  /* Warmer than --panel by a hair, so first place reads before you read it. */
  background: #1d1a17;
  background: color-mix(in srgb, var(--gold) 9%, var(--panel));
  border-left-color: var(--gold);
}

.standing--1 .row-name,
.standing--1 .row-value,
.standing--1 .standing-rank { color: var(--gold); }

.standing--2 { border-left-color: var(--silver); }
.standing--3 { border-left-color: var(--bronze); }

.standing--rest {
  min-height: 28px;
  padding-top: 3px;
  padding-bottom: 3px;
  opacity: 0.55;
}

.standing--rest .row-name { font-size: 13px; }

/*
 * The row is already held back by its opacity, which drags --dim under the
 * contrast floor. The rank is how you find yourself on this screen, so it
 * takes the brighter ink and lets the opacity do the de-emphasising.
 */
.standing--rest .standing-rank { color: var(--text); }

/* --- shared player rows ------------------------------------------------- */

.rows {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rows li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 8px;
  background: var(--panel);
  /* The only colour a row carries is the player's, on this edge. */
  border-left: 2px solid var(--edge);
  border-radius: 0 4px 4px 0;
}

.rows li.is-away { opacity: 0.5; }

.row-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  /* The panel is sized around this, not the other way round: the longest
     name the generator can make, "Restless Crimson Snake", clears the
     column at this size even on your own row at LV 10. */
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* READY, WAITING and the like. */
.row-value {
  flex: none;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--dim);
  text-align: right;
}

/* LV counts, which are numbers and belong in the number face. */
.row-value--number {
  /* Wide enough for LV 10, so the name column does not shrink when
     somebody levels into double digits. */
  min-width: 36px;
  /* A level is the score, not a label: it reads at full contrast. */
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  line-height: 1.1;
}

.row-value.is-ready { color: var(--green); }

.tag {
  flex: none;
  padding: 1px 5px;
  border: 1px solid currentColor;
  border-radius: 3px;
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--dim);
}

.tag--host,
.tag--winner { color: var(--gold); }

/* The same white ring the board draws on your own head. */
.you-ring {
  flex: none;
  width: 10px;
  height: 10px;
  border: 2px solid var(--text);
  border-radius: 2px;
}

.swatch {
  flex: none;
  width: 13px;
  height: 13px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.rows li.empty {
  min-height: 0;
  padding: 8px 0;
  background: transparent;
  border-left-color: transparent;
  color: var(--dim);
  font-size: 13px;
}

.colophon {
  max-width: 900px;
  margin: 16px auto 0;
  color: var(--dim);
  font-size: 13px;
  text-align: center;
}

/* --- responsive --------------------------------------------------------- */

@media (max-width: 940px) {
  .cabinet,
  .colophon { max-width: 660px; }

  /* The board is fixed at 512px; the panel moves under it rather than
     squeezing the canvas into fractional cells. */
  .screen--game { flex-direction: column; }

  .scorepanel {
    width: 100%;
    min-height: 0;
  }

  .screen--lobby {
    grid-template-columns: minmax(0, 1fr);
    gap: 22px;
  }
}

/* Narrower than the board itself: scroll the screen, never scale the canvas. */
@media (max-width: 680px) {
  .screen--game {
    overflow-x: auto;
    overscroll-behavior-x: contain;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }

  .btn:active { transform: none; }
}
