/* ==========================================================================
   The cabinet — the full-screen shell every game is played in
   --------------------------------------------------------------------------
   One layout for all ten games, built for a phone held in one hand first and
   scaled up to a desktop from there.

   The rule the whole file follows: THE GAME IS THE PAGE. While you are
   playing, the screen holds a slim bar, the score, the playfield and the
   controls under your thumbs — nothing else, and nothing scrolls. Anything
   that is not the game (the rules, the legend, the footer) sits below the
   first screen where it can be read before a run and is out of the way
   during one.

   The playfield keeps the proportions its game was written for and is fitted
   into whatever space is left, the way a video is fitted into a player:
   as large as it can go without cropping, on any screen, either way up.
   ========================================================================== */

/* Each game sits in one of the four brand worlds; the world only moves the
   accent and the backdrop, so the cabinet stays one family. */
.cab-body {
  --accent: var(--frimax-amber);
  --world: #145c33;
  --world-deep: #04150d;
  --bar-h: 46px;
  background: var(--world-deep);
  /* The body's own grain and vignette (brand.css) stay; the cabinet paints
     its backdrop on .cab so it never bleeds into the notes underneath. */
  overscroll-behavior: none;
}

.cab-body[data-world="frinax"] {
  --world: #10527f;
  --world-deep: #04121f;
}
.cab-body[data-world="snappers"] {
  --world: #8c1a1f;
  --world-deep: #1c0607;
}
.cab-body[data-world="thunder"] {
  --world: #3a2a8f;
  --world-deep: #0b0822;
}
.cab-body[data-world="gold"] {
  --world: #7a4a08;
  --world-deep: #160d02;
}

/* While a run is live the page must not move under a swipe. */
.cab-body.is-playing {
  overflow: hidden;
  touch-action: none;
}

/* ------------------------------------------------------------------ frame */

.cab {
  position: relative;
  /* dvh tracks the browser's collapsing toolbar, so the cabinet is exactly
     the visible screen on a phone; vh is the fallback and is only ever a
     toolbar's height too tall. */
  height: 100vh;
  height: 100dvh;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0
    env(safe-area-inset-left);
  background:
    radial-gradient(ellipse 110% 70% at 50% 0%, var(--world) 0%, transparent 72%),
    linear-gradient(180deg, var(--world-deep), #020a06);
  overflow: hidden;
}

/* Scan lines over the backdrop only — the faintest nod to a CRT, kept off the
   playfield itself where it would cost legibility. */
.cab::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.14) 0 1px,
    transparent 1px 3px
  );
  opacity: 0.5;
}

.cab > * {
  position: relative;
}

/* -------------------------------------------------------------------- bar */

.cab-bar {
  flex: 0 0 auto;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
}

.cab-brand {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

.cab-brand img {
  height: 26px;
  width: auto;
  display: block;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5));
}

.cab-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding-left: 4px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.86rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--frimax-cream);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* On a phone the bar cannot hold the logo, a twelve-letter title and four
   buttons at once. During a run the title is the thing to give up: the
   player knows what they are playing, and the pause button needs the room. */
@media (max-width: 480px) {
  .cab-title {
    font-size: 0.78rem;
    letter-spacing: 0.07em;
  }

  .cab-body.is-playing .cab-title {
    visibility: hidden;
  }
}

/* ------------------------------------------------------------------- main */

.cab-main {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

/* -------------------------------------------------------------------- HUD */

.cab .hud {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  gap: 5px;
  padding: 2px 8px 6px;
}

.cab .hud-item {
  flex: 1 1 0;
  min-width: 0;
  max-width: 150px;
  padding: 5px 4px 6px;
  border-radius: 10px;
  background-color: rgba(0, 0, 0, 0.42);
}

.cab .hud-label {
  font-size: 0.54rem;
  letter-spacing: 0.1em;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cab .hud-value {
  display: block;
  font-size: 1.02rem;
  color: var(--accent);
  white-space: nowrap;
  transform-origin: 50% 60%;
}

/* A value that just changed kicks, so the eye catches it without reading. */
.cab .hud-value.bump {
  animation: hud-bump 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.6);
}

@keyframes hud-bump {
  30% {
    transform: scale(1.32);
    color: var(--frimax-cream);
  }
}

/* The thin progress / timer rail some games run under the score. */
.cab .progress,
.cab .timer-bar {
  flex: 0 0 auto;
  width: auto;
  max-width: none;
  height: 6px;
  margin: 0 10px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}

/* ------------------------------------------------------------------ stage */

/* The box the playfield is fitted into. `container-type: size` lets the
   stage below measure this box in cqw/cqh, which is what makes "as large as
   fits, never cropped" a one-line rule instead of a script. */
.cab-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0 6px;
  container-type: size;
}

.cab .stage {
  /* --ar is the game's own width / height, set inline on the element. */
  width: min(100cqw, 100cqh * var(--ar), var(--stage-max, 760px));
  aspect-ratio: var(--ar);
  max-width: none;
  margin: 0;
  border-radius: 14px;
  border-width: 2px;
}

/* The playfield canvas only: a game may put other canvases inside its stage
   (Frimax Streets' minimap), and those size themselves. */
.cab .stage > canvas {
  width: 100%;
  height: 100%;
}

/* Browsers without container units get the width-led fit they had before. */
@supports not (width: 1cqw) {
  .cab .stage {
    width: min(100%, 560px);
  }
}

/* --------------------------------------------------------------- controls */

.cab-controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  min-height: calc(10px + env(safe-area-inset-bottom));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.cab-hint {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  text-align: center;
}

/* Keyboard hints are for a keyboard; touch hints for a touchscreen. */
.cab-hint.for-touch {
  display: none;
}
@media (pointer: coarse) {
  .cab-hint.for-keys {
    display: none;
  }
  .cab-hint.for-touch {
    display: block;
  }
}

/* The d-pad: one moulded cross rather than four loose keys. */
.cab .dpad {
  display: none;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 0;
  margin: 0;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.55));
}

.cab .dpad button {
  border: 0;
  border-radius: 0;
  background: linear-gradient(180deg, #2c3a31, #18211c);
  box-shadow: inset 0 1px 0 rgba(255, 253, 247, 0.18);
  color: var(--frimax-cream);
  font-size: 1rem;
  touch-action: none;
}

.cab .dpad .up {
  border-radius: 12px 12px 0 0;
}
.cab .dpad .down {
  border-radius: 0 0 12px 12px;
}
.cab .dpad .left {
  border-radius: 12px 0 0 12px;
}
.cab .dpad .right {
  border-radius: 0 12px 12px 0;
}

/* The hub of the cross, so the four arms read as one piece. */
.cab .dpad::before {
  content: "";
  grid-area: 2 / 2;
  background: #18211c;
}

.cab .dpad button:active,
.cab .dpad button.is-down {
  background: linear-gradient(180deg, var(--frimax-green), var(--frimax-green-dark));
}

/* Left / right only: two wide keys. */
.cab .dpad.dpad-lr {
  grid-template-columns: repeat(2, 84px);
  grid-template-rows: 46px;
  gap: 10px;
}
.cab .dpad.dpad-lr::before {
  display: none;
}
.cab .dpad.dpad-lr .left,
.cab .dpad.dpad-lr .right {
  grid-area: auto;
  border-radius: 12px;
}

@media (pointer: coarse) {
  .cab .dpad {
    display: grid;
  }
}

/* On a short screen the d-pad would take the playfield's space, and a swipe
   does the same job — so the playfield wins. */
@media (pointer: coarse) and (max-height: 610px) {
  .cab .dpad:not(.dpad-lr) {
    display: none;
  }
}

/* The one-button games: a proper arcade button, domed and lit. */
.arcade-btn {
  position: relative;
  width: 132px;
  height: 58px;
  border: 0;
  border-radius: 999px;
  background: radial-gradient(ellipse 80% 90% at 50% 20%, #ffd27a, var(--frimax-amber) 55%, #b9740a);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    inset 0 -6px 10px rgba(120, 70, 0, 0.5),
    0 6px 0 #7a4a08,
    0 12px 18px rgba(0, 0, 0, 0.55);
  color: #3a2200;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.05s ease,
    box-shadow 0.05s ease;
}

.arcade-btn:active,
.arcade-btn.is-down {
  transform: translateY(5px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.45),
    inset 0 -4px 8px rgba(120, 70, 0, 0.5),
    0 1px 0 #7a4a08,
    0 4px 8px rgba(0, 0, 0, 0.5);
}

/* A mouse has the whole playfield to click on and a keyboard beside it. */
@media (hover: hover) and (pointer: fine) {
  .arcade-btn {
    display: none;
  }
}

/* ---------------------------------------------------------------- overlay */

/* The start / game-over sheet covers the whole play area rather than only
   the playfield, so the results — score, level bar, leaderboard, share —
   have a full screen to work with however small the game's own canvas is. */
.cab .overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: block;
  padding: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background:
    radial-gradient(ellipse 80% 50% at 50% 30%, color-mix(in srgb, var(--world) 70%, transparent), transparent 75%),
    rgba(3, 10, 6, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.cab .overlay[hidden] {
  display: none;
}

.cab .overlay-inner {
  min-height: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 22px 18px 26px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.cab .overlay h2 {
  font-size: clamp(1.7rem, 7.4vw, 2.6rem);
  line-height: 1.05;
  margin: 0 0 10px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--frimax-cream);
  background: linear-gradient(180deg, #fffdf7 0%, #ffe6a8 40%, var(--frimax-amber) 66%, #b9740a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.55));
  text-shadow: none;
}

.cab .overlay-inner > p {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 0.98rem;
  line-height: 1.5;
}

.cab .overlay .btn-lg {
  min-width: 200px;
}

/* "Press start" pulse on the one button that matters. */
.cab .overlay #overlay-btn {
  animation: press-start 1.5s ease-in-out infinite;
}

@keyframes press-start {
  50% {
    transform: scale(1.045);
    filter: brightness(1.1);
  }
}

.cab .overlay .results {
  width: 100%;
}

/* The packs fanned above the title on the start sheet. */
.cab-fan {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 92px;
  margin-bottom: 14px;
  pointer-events: none;
}

.cab-fan img {
  height: 86px;
  width: auto;
  margin: 0 -9px;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.55));
}

.cab-fan img:nth-child(1) {
  transform: rotate(-12deg) translateY(6px);
}
.cab-fan img:nth-child(2) {
  height: 92px;
  z-index: 1;
}
.cab-fan img:nth-child(3) {
  transform: rotate(12deg) translateY(6px);
}

/* On a very short play area the fan is the first thing to go. */
@media (max-height: 560px) {
  .cab-fan {
    display: none;
  }
}

/* -------------------------------------------------------------- countdown */

.cab-count {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.cab-count span {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(5rem, 34vw, 11rem);
  line-height: 1;
  color: var(--frimax-cream);
  -webkit-text-stroke: 3px rgba(0, 0, 0, 0.55);
  paint-order: stroke fill;
  text-shadow:
    0 6px 0 rgba(0, 0, 0, 0.5),
    0 0 46px var(--accent);
  animation: count-beat 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.cab-count span.is-go {
  color: var(--accent);
  font-size: clamp(4rem, 26vw, 9rem);
  animation-duration: 0.6s;
}

@keyframes count-beat {
  0% {
    opacity: 0;
    transform: scale(2.2);
  }
  30% {
    opacity: 1;
    transform: scale(1);
  }
  80% {
    opacity: 1;
    transform: scale(0.96);
  }
  100% {
    opacity: 0;
    transform: scale(0.8);
  }
}

/* ------------------------------------------------------------ pause sheet */

.cab-pause {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 10, 6, 0.86);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  text-align: center;
}

.cab-pause[hidden] {
  display: none;
}

.cab-pause h2 {
  margin: 0 0 18px;
  font-size: 1.9rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--frimax-cream);
}

.cab-pause .stack {
  display: grid;
  gap: 10px;
  justify-items: center;
}

.cab-pause .btn {
  min-width: 200px;
}

/* ------------------------------------------------------------ the notes */

/* Everything that is not the game: the rules, the legend, the way home. */
.cab-info {
  padding: 30px 0 40px;
  background: var(--bg-deep);
  border-top: 1px solid var(--border);
}

.cab-info .wrap {
  max-width: 560px;
}

.cab-info h2 {
  font-size: 1.1rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--frimax-amber);
  margin: 0 0 8px;
}

.cab-info .game-tagline {
  text-align: left;
  margin-bottom: 18px;
}

.cab-info .legend {
  max-width: none;
  margin: 0 0 20px;
}

.cab-info .cab-home {
  display: flex;
  justify-content: center;
}

/* ============================================================== landscape */

/* A phone on its side: the bar and the score share one row, and the controls
   lift off the bottom edge to float over the corners of the play area, which
   the playfield's letterboxing leaves free. */
@media (orientation: landscape) and (max-height: 520px) {
  .cab-body {
    --bar-h: 40px;
  }

  /* The floor that stops the cabinet collapsing on a tiny window is taller
     than a phone on its side; here the screen is the only limit. */
  .cab {
    min-height: 0;
  }

  .cab-bar {
    position: absolute;
    top: env(safe-area-inset-top);
    left: env(safe-area-inset-left);
    right: env(safe-area-inset-right);
    z-index: 3;
    pointer-events: none;
  }

  .cab-bar > * {
    pointer-events: auto;
  }

  .cab-title,
  .cab-brand {
    display: none;
  }

  .cab-bar .cab-back {
    margin-right: auto;
  }

  .cab .hud {
    padding: 4px 150px 4px 56px;
    min-height: var(--bar-h);
    align-items: center;
  }

  .cab .hud-item {
    padding: 3px 4px 4px;
    display: flex;
    gap: 6px;
    justify-content: center;
    align-items: baseline;
  }

  .cab .hud-label {
    margin: 0;
  }

  .cab-stage {
    padding: 0 6px 6px;
  }

  .cab-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4;
    justify-content: space-between;
    padding: 0 calc(14px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom))
      calc(14px + env(safe-area-inset-left));
    pointer-events: none;
  }

  .cab-controls > * {
    pointer-events: auto;
  }

  .cab-controls .cab-hint {
    display: none;
  }

  .cab .dpad,
  .arcade-btn {
    opacity: 0.86;
  }

  /* One-button games: the button belongs under the right thumb. */
  .cab-controls .arcade-btn:only-child {
    margin-left: auto;
  }
}

/* ================================================================ desktop */

@media (min-width: 760px) and (min-height: 560px) {
  .cab-body {
    --bar-h: 58px;
  }

  .cab-bar {
    padding: 0 18px;
    gap: 10px;
  }

  .cab-brand img {
    height: 36px;
  }

  .cab-title {
    font-size: 1.05rem;
    padding-left: 10px;
  }

  .cab .hud {
    justify-content: center;
    gap: 10px;
    padding: 4px 16px 12px;
  }

  .cab .hud-item {
    flex: 0 1 132px;
    padding: 8px 10px 9px;
    border-radius: 14px;
  }

  .cab .hud-label {
    font-size: 0.62rem;
    margin-bottom: 3px;
  }

  .cab .hud-value {
    font-size: 1.35rem;
  }

  .cab .progress,
  .cab .timer-bar {
    width: min(100% - 32px, 560px);
    margin: 0 auto 12px;
  }

  .cab-stage {
    padding: 0 16px;
  }

  .cab .stage {
    border-radius: 20px;
  }

  .cab-controls {
    padding: 12px 16px 16px;
  }

  .cab-hint {
    font-size: 0.78rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cab .overlay #overlay-btn,
  .cab-count span,
  .cab .hud-value.bump {
    animation: none;
  }
}
