/* The cabinet's furniture.
   ===========================================================================
   Everything a player sees that is not the game itself: the loading bar, the
   score, the pause sheet and the death card. One stylesheet for every game in
   the catalogue, so two hundred games feel like one arcade.

   IT MATCHES THE PORTAL, on purpose. Same warm paper, same marquee amber, same
   rule that anything the machine reports about itself is set in mono. A player
   who came from games.cstsolution.com should not notice a seam.

   THE FURNITURE IS BRIGHT; the game behind it may be any time of day. That is
   house rule 9, and it is why these cards are paper over a scrim rather than
   another dark panel on a dark game.

   NOTHING HERE SCROLLS. The document cannot (html/body are fixed and
   overflow:hidden), and every card is capped at the viewport height with its
   own contents shrinking instead. That is AGENTS.md rule 1, enforced in one
   place for the whole catalogue.
   ======================================================================== */

:root {
  --cab-paper:   #FAF6EE;
  --cab-card:    #FFFFFF;
  --cab-hair:    #E3DACA;
  --cab-ink:     #1C1822;
  --cab-quiet:   #6B6376;
  --cab-lamp:    #E08A12;
  --cab-lamp-hot:#F2A62B;
  --cab-lamp-ink:#8F5300;
  --cab-on-lamp: #2A1B02;
  --cab-scrim:   rgba(14, 12, 18, .62);
  --cab-glow:    rgba(224, 138, 18, .3);

  --cab-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --cab-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

  /* Read back by fit.mjs, which cannot query env() directly. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  color-scheme: light;
}

* { box-sizing: border-box; }

/* The document is the window and nothing more. A game that can scroll is a
   game whose controls move under the player's thumb. */
html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #0E0C12;
  font-family: var(--cab-sans);
  color: var(--cab-ink);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
}

#stage {
  position: fixed; inset: 0;
  display: block;
  width: 100%; height: 100%;
  touch-action: none;
}

.cab-layer {
  position: fixed; inset: 0;
  display: grid;
  pointer-events: none;
  padding:
    calc(env(safe-area-inset-top, 0px) + .6rem)
    calc(env(safe-area-inset-right, 0px) + .6rem)
    calc(env(safe-area-inset-bottom, 0px) + .6rem)
    calc(env(safe-area-inset-left, 0px) + .6rem);
}
.cab-layer > * { pointer-events: auto; }

/* ── readouts ────────────────────────────────────────────────────────────
   Mono, because these are the machine reporting about itself — the same rule
   the portal follows. Tabular figures so a score does not jitter sideways as
   it counts up. */
.cab-readout {
  font-family: var(--cab-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
}

/* ── the HUD ─────────────────────────────────────────────────────────── */

.cab-hud {
  position: fixed; left: 0; right: 0;
  top: calc(env(safe-area-inset-top, 0px) + .5rem);
  display: flex; align-items: flex-start; gap: .5rem;
  padding-inline: calc(env(safe-area-inset-left, 0px) + .6rem) calc(env(safe-area-inset-right, 0px) + .6rem);
  pointer-events: none;
}

.cab-score {
  /* Centred by the two equal side clusters around it (below), not by auto
     margins: in a flex row every auto margin shares the free space, so
     `margin: 0 auto` here plus the right cluster's `margin-left: auto` put
     the score a third of the way across instead of in the middle. */
  flex: none;
  margin: 0;
  text-align: center;
  /* A pill, so the number is readable over a bright sky and a dark cave
     alike. This is the only thing between the player and knowing how they are
     doing, and it may not depend on what is behind it. */
  background: rgba(14, 12, 18, .42);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-radius: 999px;
  padding: .3rem .85rem .35rem;
  color: #FFF8EC;
  line-height: 1.15;
}
.cab-score b {
  display: block;
  font-family: var(--cab-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.2rem, 4.2vmin, 1.9rem);
  font-weight: 700;
  letter-spacing: -.01em;
}
.cab-score small {
  display: block;
  font-family: var(--cab-mono);
  font-size: clamp(.7rem, 1.9vmin, .78rem);
  letter-spacing: .1em; text-transform: uppercase;
  opacity: .72;
}

/* The two buttons that are always there. 44px, both directions, always. */
.cab-btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-width: 44px; min-height: 44px;
  padding: 0 .75rem;
  font: inherit; font-size: .95rem; font-weight: 650;
  color: var(--cab-ink); background: var(--cab-card);
  border: 1px solid var(--cab-hair); border-radius: 999px;
  /* The "More games" action is an <a>, and a browser underlines those. In a
     row of buttons one underlined label reads as broken, not as a link. */
  text-decoration: none;
  cursor: pointer;
  transition: transform 110ms cubic-bezier(.2,.7,.3,1), background 110ms, border-color 110ms;
}
.cab-btn:active { transform: translateY(1px); }
.cab-btn:focus-visible { outline: 2px solid var(--cab-lamp); outline-offset: 2px; }

.cab-btn--ghost {
  background: rgba(14, 12, 18, .42);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-color: rgba(255, 255, 255, .22);
  color: #FFF8EC;
  padding: 0; width: 44px;
}

.cab-btn--go {
  background: linear-gradient(180deg, var(--cab-lamp-hot), var(--cab-lamp));
  color: var(--cab-on-lamp); border-color: transparent;
  font-weight: 800; font-size: 1.05rem;
  padding: 0 1.6rem; min-height: 52px;
  box-shadow: 0 8px 26px -10px var(--cab-glow);
}

/* Equal flex basis on both sides, whatever each holds, so the score between
   them is in the middle of the window. */
.cab-hud__left, .cab-hud__right { flex: 1 1 0; min-width: 44px; display: flex; gap: .4rem; pointer-events: auto; }
.cab-hud__right { justify-content: flex-end; }

/* ── the one line of instruction ─────────────────────────────────────────
   House rule 8: nothing to read. One verb, near the bottom where the eye is
   during play, gone the moment the player does anything. */
.cab-hint {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12%);
  margin: 0; padding: .4rem 1rem;
  background: rgba(14, 12, 18, .42);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-radius: 999px;
  color: #FFF8EC; font-size: clamp(.82rem, 2.4vmin, .95rem);
  white-space: nowrap;
  transition: opacity 320ms ease;
  pointer-events: none;
}
.cab-hint[hidden] { display: none; }
.cab-hint.is-going { opacity: 0; }

/* ── overlays: loading, pause, death ─────────────────────────────────── */

.cab-sheet {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + .8rem) .8rem calc(env(safe-area-inset-bottom, 0px) + .8rem);
  background: var(--cab-scrim);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.cab-sheet[hidden] { display: none !important; }

.cab-card {
  width: min(24rem, 100%);
  /* THE CAP THAT KEEPS RULE 1. The card can never be taller than the window,
     and if its contents do not fit, they shrink — the card does not scroll and
     the page certainly does not. */
  max-height: 100%;
  display: flex; flex-direction: column; gap: .7rem;
  background: var(--cab-paper);
  border: 1px solid var(--cab-hair);
  border-radius: 16px;
  padding: clamp(.9rem, 3.5vmin, 1.5rem);
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, .7);
  text-align: center;
  overflow: hidden;
}
/* The marquee, lit, across the top of every card. The portal's signature. */
.cab-card::before {
  content: ''; display: block;
  height: 3px; margin: calc(-1 * clamp(.9rem, 3.5vmin, 1.5rem)) calc(-1 * clamp(.9rem, 3.5vmin, 1.5rem)) 0;
  background: linear-gradient(90deg, var(--cab-lamp-hot), var(--cab-lamp), var(--cab-lamp-hot));
  border-radius: 16px 16px 0 0;
  flex: none;
}

.cab-card h1, .cab-card h2 {
  margin: 0;
  font-size: clamp(1.15rem, 4.4vmin, 1.6rem);
  font-weight: 800; letter-spacing: -.02em; line-height: 1.12;
  text-wrap: balance;
}
.cab-card p { margin: 0; color: var(--cab-quiet); font-size: clamp(.86rem, 2.6vmin, .95rem); }

/* The two numbers a run ends on. Big, because they are the reason to press
   the button underneath them. */
.cab-figures { display: flex; gap: .6rem; justify-content: center; }
.cab-figure {
  flex: 1 1 0; min-width: 0;
  background: var(--cab-card); border: 1px solid var(--cab-hair); border-radius: 12px;
  padding: .55rem .4rem .6rem;
}
.cab-figure b {
  display: block;
  font-family: var(--cab-mono); font-variant-numeric: tabular-nums;
  font-size: clamp(1.5rem, 6vmin, 2.3rem); font-weight: 700; line-height: 1;
  letter-spacing: -.02em;
}
.cab-figure small {
  display: block; margin-top: .2rem;
  font-family: var(--cab-mono); font-size: clamp(.7rem, 1.9vmin, .74rem);
  letter-spacing: .12em; text-transform: uppercase; color: var(--cab-quiet);
}
.cab-figure.is-best b { color: var(--cab-lamp-ink); }

.cab-flag {
  font-family: var(--cab-mono); font-size: clamp(.7rem, 2vmin, .78rem);
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--cab-lamp-ink); font-weight: 700;
}

/* House rule 5: restart is one tap, in the same place, every time. It is the
   last element in the card and the biggest, so on a phone it lands under the
   thumb that was already playing. */
.cab-actions { display: flex; flex-direction: column; gap: .45rem; margin-top: .2rem; }
.cab-actions .cab-btn { width: 100%; }
.cab-actions__row { display: flex; gap: .45rem; }
.cab-actions__row .cab-btn { flex: 1 1 0; }

/* ── loading ─────────────────────────────────────────────────────────── */

.cab-loading { gap: .9rem; }
.cab-loading .cab-card { width: min(20rem, 100%); }

.cab-bar {
  height: .5rem; border-radius: 999px; overflow: hidden;
  background: var(--cab-hair);
  border: 1px solid var(--cab-hair);
}
.cab-bar i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--cab-lamp-hot), var(--cab-lamp));
  border-radius: inherit;
  transition: width 180ms ease-out;
}
/* Before a real number has arrived there is a sheen rather than a made-up
   percentage — the same rule the portal's cover follows. */
.cab-bar.is-waiting i {
  width: 38%;
  animation: cab-wait 1.1s ease-in-out infinite alternate;
}
@keyframes cab-wait { from { transform: translateX(-100%); } to { transform: translateX(270%); } }

.cab-pct { font-family: var(--cab-mono); font-size: clamp(.72rem, 2vmin, .8rem); color: var(--cab-quiet); min-height: 1.2em; margin: 0; }

/* ── a landscape phone is 375px tall; the card has to give ────────────── */
@media (max-height: 30rem) {
  .cab-card { width: min(28rem, 100%); gap: .45rem; padding: .7rem .9rem; }
  .cab-card h1, .cab-card h2 { font-size: 1.05rem; }
  .cab-card p { display: none; }              /* the flavour line is the first thing to go */
  .cab-figure b { font-size: 1.4rem; }
  .cab-actions { flex-direction: row; }
  .cab-actions__row { flex: 1 1 0; }
  .cab-hint { bottom: calc(env(safe-area-inset-bottom, 0px) + .6rem); }
}

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