/* ============================================================
   Rerouted — frame styles.
   Palette + type LOCKED to art-direction.md. This is the frame
   Kian dresses further; it stands as designed work, not grey.
   ============================================================ */

/* ------------------------------------------------------------
   SELF-HOSTED TYPE (offline-complete law).
   Fredoka (display) + Rubik (UI) are bundled as local woff2 in
   /fonts/ — no Google Fonts request, no network dependency. The
   game renders in its true cartoon type on a plane, a locked-down
   office, or a captive-portal wifi.
   Both families are open source under the SIL Open Font License
   v1.1 (Fredoka: Milena Brãndao, Hafontia; Rubik: Hubert & Fischer),
   so bundling is clean. font-display:swap keeps first paint instant.
   ------------------------------------------------------------ */
@font-face {
  font-family: 'Fredoka'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('../fonts/fredoka-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Fredoka'; font-style: normal; font-weight: 500; font-display: swap;
  src: url('../fonts/fredoka-latin-500-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Fredoka'; font-style: normal; font-weight: 600; font-display: swap;
  src: url('../fonts/fredoka-latin-600-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Fredoka'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('../fonts/fredoka-latin-700-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Rubik'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('../fonts/rubik-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Rubik'; font-style: normal; font-weight: 500; font-display: swap;
  src: url('../fonts/rubik-latin-500-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Rubik'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('../fonts/rubik-latin-700-normal.woff2') format('woff2');
}

:root {
  /* ground & structure */
  --asphalt:        #2B2D42;
  --asphalt-deep:   #1F2138;
  --block:          #3A3D5C;
  --block-top:      #4A4E73;
  --lane:           #F2F3F7;

  /* actors */
  --red:            #FF3B4E;
  --red-shade:      #D31E36;
  --windshield:     #8CE0FF;
  --tyre:           #16172A;

  /* cargo & goals */
  --kraft:          #F4A03C;
  --kraft-shade:    #D97E1E;
  --tape:           #FFE7C2;
  --pickup:         #22C776;
  --dropoff:        #FF4FB8;

  /* road-state */
  --amber:          #FFC43D;
  --closed:         #E23145;
  --flash:          #FFFFFF;

  /* ui */
  --panel-ink:      #20223A;
  --panel-raise:    #2E3154;
  --ui-white:       #FFFFFF;
  --ui-dim:         #9AA0C7;
  --timer-cool:     #22C776;
  --timer-warn:     #FFC43D;
  --timer-panic:    #FF3B4E;
  --cta:            #FFD23F;
  --cta-ink:        #20223A;

  --r-chip: 8px;
  --r-card: 14px;
  --r-big: 22px;

  --sans: 'Rubik', system-ui, sans-serif;
  --display: 'Fredoka', 'Rubik', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--asphalt-deep);
  color: var(--ui-white);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.tnum { font-variant-numeric: tabular-nums; }

/* ============================================================
   APP FRAME — desktop spends the width: city + rail.
   ============================================================ */

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 340px;
  background:
    radial-gradient(120% 120% at 30% 0%, #262842 0%, var(--asphalt-deep) 70%);
}

#stage {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

/* ---- HUD (desktop: floating top bar over the canvas) ---- */
.hud {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(32, 34, 58, 0.82);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(154, 160, 199, 0.18);
  border-radius: var(--r-card);
  box-shadow: 0 6px 0 rgba(0,0,0,0.18);
  z-index: 5;
}
.hud-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 74px;
  padding: 2px 10px;
}
.hud-cell + .hud-cell { border-left: 1px solid rgba(154,160,199,0.15); }
.hud-label {
  font: 500 12px/1 var(--sans);
  letter-spacing: 0.12em;
  color: var(--ui-dim);
  margin-bottom: 4px;
}
.hud-value {
  font: 700 24px/1 var(--sans);
  color: var(--ui-white);
}
.hud-timer .hud-value { font-size: 30px; }
.hud-timer .hud-value.warn  { color: var(--timer-warn); }
.hud-timer .hud-value.panic { color: var(--timer-panic); animation: pulse 0.5s steps(2) infinite; }
.hud-timer .hud-value.cool  { color: var(--timer-cool); }
@keyframes pulse { 50% { opacity: 0.45; } }

/* ============================================================
   RIGHT RAIL — the persistent leaderboard on desktop.
   ============================================================ */

#rail {
  background: var(--panel-ink);
  border-left: 2px solid rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  padding: 22px 20px;
  gap: 18px;
  z-index: 4;
}
.rail-brand { display: flex; justify-content: center; padding: 4px 0 2px; }
.rail-brand img { width: 78%; max-width: 240px; height: auto; }

.rail-board {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: rgba(0,0,0,0.16);
  border-radius: var(--r-card);
  padding: 14px 12px;
  min-height: 0;
}
.board-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 2px 4px 12px;
  border-bottom: 1px solid rgba(154,160,199,0.16);
  margin-bottom: 8px;
}
.board-title { font: 700 15px/1 var(--display); letter-spacing: 0.06em; color: var(--ui-white); }
.board-sub   { font: 400 11px/1 var(--sans); color: var(--ui-dim); }

.board-list { list-style: none; overflow-y: auto; flex: 1; }
.board-row {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  border-radius: var(--r-chip);
  font: 500 15px/1 var(--sans);
}
.board-row + .board-row { margin-top: 2px; }
.board-row .r-rank { font: 700 15px/1 var(--sans); color: var(--ui-dim); }
.board-row .r-name { color: var(--ui-white); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: 0.02em; }
.board-row .r-score { font: 700 15px/1 var(--sans); color: var(--ui-white); }
.board-row.rank-1 { background: rgba(255,210,63,0.14); }
.board-row.rank-1 .r-rank { font-family: var(--display); font-size: 18px; color: var(--cta); }
.board-row.rank-2 .r-rank { color: #C9CEEC; }
.board-row.rank-3 .r-rank { color: var(--kraft); }
.board-row.is-you {
  background: rgba(255,79,184,0.18);
  outline: 1px solid rgba(255,79,184,0.5);
}
.board-row.is-you .r-name { color: var(--dropoff); font-weight: 700; }

.rail-foot { text-align: center; color: var(--ui-dim); font-size: 12px; }
.rail-foot b { color: var(--ui-white); font-weight: 700; letter-spacing: 0.04em; }

/* ============================================================
   TOUCH CONTROLS — hidden on desktop, shown on phone.
   ============================================================ */
.touch-controls { display: none; }
.dpad {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(3, 66px);
  grid-template-rows: repeat(3, 66px);
  gap: 8px;
  z-index: 6;
}
.dbtn {
  border: none;
  border-radius: 16px;
  background: var(--panel-raise);
  color: var(--ui-white);
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 4px 0 rgba(0,0,0,0.35);
  touch-action: none;
  user-select: none;
  transition: transform 0.05s, background 0.05s;
}
.dbtn:active, .dbtn.pressed {
  background: var(--red);
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.35);
}
.dbtn-up    { grid-column: 2; grid-row: 1; }
.dbtn-left  { grid-column: 1; grid-row: 2; }
.dbtn-right { grid-column: 3; grid-row: 2; }
.dbtn-down  { grid-column: 2; grid-row: 3; }

/* ============================================================
   OVERLAY SCREENS
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 16, 30, 0.62);
  backdrop-filter: blur(6px);
}
.overlay[data-screen="none"] { display: none; }
.overlay[data-screen="delivered"] {
  background: transparent;
  backdrop-filter: none;
  pointer-events: none;
}

.screen { display: none; width: 100%; height: 100%; align-items: center; justify-content: center; padding: 24px; }
.overlay[data-screen="title"]     .screen-title,
.overlay[data-screen="level"]     .screen-level,
.overlay[data-screen="delivered"] .screen-delivered,
.overlay[data-screen="fail"]      .screen-fail,
.overlay[data-screen="paused"]    .screen-paused { display: flex; }

/* shared card */
.title-card, .level-card, .fail-card, .paused-card, .delivered-card {
  background: var(--panel-ink);
  border: 1px solid rgba(154,160,199,0.16);
  border-radius: var(--r-big);
  box-shadow: 0 14px 0 rgba(0,0,0,0.30), 0 30px 60px rgba(0,0,0,0.45);
  padding: 40px 44px;
  text-align: center;
  max-width: 520px;
  width: 100%;
  animation: cardIn 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(16px) scale(0.96); } }

/* ---- TITLE ---- */
.title-wordmark { width: 100%; max-width: 400px; height: auto; margin: 0 auto 6px; display: block; }
.title-tag {
  font: 500 18px/1.4 var(--sans);
  color: var(--ui-dim);
  margin: 8px 0 28px;
}
.title-hint { margin-top: 18px; font: 400 13px/1.4 var(--sans); color: var(--ui-dim); }
.hint-phone { display: none; }

/* ---- LEVEL / TAUNT ---- */
.level-kicker {
  display: inline-block;
  font: 700 14px/1 var(--display);
  letter-spacing: 0.14em;
  color: var(--cta);
  background: rgba(255,210,63,0.12);
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 18px;
}
.level-title { font: 700 40px/1.05 var(--display); letter-spacing: 0.01em; margin-bottom: 12px; }
.level-taunt { font: 400 18px/1.4 var(--sans); color: var(--ui-dim); margin-bottom: 30px; }

/* ---- DELIVERED (juice flash) ---- */
.delivered-card {
  background: var(--pickup);
  border: none;
  padding: 26px 40px;
  animation: deliveredPop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes deliveredPop {
  0%   { opacity: 0; transform: scale(0.5) rotate(-6deg); }
  60%  { opacity: 1; transform: scale(1.08) rotate(1deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
.delivered-big { display: block; font: 700 48px/1 var(--display); letter-spacing: 0.04em; color: var(--panel-ink); }
.delivered-stats { display: flex; justify-content: center; gap: 26px; margin: 16px 0 8px; }
.delivered-stats div { display: flex; flex-direction: column; }
.ds-num   { font: 700 26px/1 var(--sans); color: var(--panel-ink); }
.ds-label { font: 500 11px/1 var(--sans); letter-spacing: 0.1em; color: rgba(32,34,58,0.7); margin-top: 3px; }
.delivered-total { display: block; font: 700 34px/1 var(--display); color: var(--panel-ink); margin-top: 4px; }

/* ---- FAIL ---- */
.fail-title { font: 700 44px/1.02 var(--display); color: var(--red); margin-bottom: 8px; }
.fail-line { font: 400 18px/1.4 var(--sans); color: var(--ui-dim); margin-bottom: 26px; }
.fail-score {
  display: flex; flex-direction: column; align-items: center;
  background: rgba(0,0,0,0.2); border-radius: var(--r-card); padding: 16px; margin-bottom: 22px;
}
.fs-label { font: 500 12px/1 var(--sans); letter-spacing: 0.12em; color: var(--ui-dim); }
.fs-value { font: 700 52px/1 var(--sans); color: var(--ui-white); margin: 4px 0; }
.fs-meta  { font: 400 13px/1 var(--sans); color: var(--ui-dim); }

.name-entry { display: flex; flex-direction: column; gap: 12px; }
.name-label { font: 500 13px/1 var(--sans); letter-spacing: 0.06em; color: var(--ui-dim); }
.name-input {
  font: 700 26px/1 var(--sans);
  text-align: center;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ui-white);
  background: var(--panel-raise);
  border: 2px solid rgba(154,160,199,0.25);
  border-radius: var(--r-chip);
  padding: 14px;
  outline: none;
}
.name-input:focus { border-color: var(--dropoff); }

.fail-board-head {
  display: flex; align-items: baseline; justify-content: space-between;
  font: 700 15px/1 var(--display); letter-spacing: 0.06em; margin-bottom: 10px;
}
.fail-board-rank { font: 500 13px/1 var(--sans); color: var(--dropoff); letter-spacing: 0.02em; }
.board-list-fail { max-height: 240px; }
.fail-board .btn { margin-top: 18px; width: 100%; }

/* ---- PAUSED ---- */
.paused-title { font: 700 40px/1 var(--display); letter-spacing: 0.06em; margin-bottom: 8px; }
.paused-sub { font: 400 16px/1.4 var(--sans); color: var(--ui-dim); margin-bottom: 26px; }
.paused-card .btn + .btn { margin-top: 12px; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-block;
  font: 600 18px/1 var(--display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: none;
  border-radius: var(--r-chip);
  padding: 16px 34px;
  cursor: pointer;
  transition: transform 0.06s, filter 0.1s;
}
.btn-cta { background: var(--cta); color: var(--cta-ink); box-shadow: 0 5px 0 #C9A423; }
.btn-cta:hover { filter: brightness(1.04); }
.btn-cta:active { transform: translateY(4px); box-shadow: 0 1px 0 #C9A423; }
.btn-ghost {
  background: transparent; color: var(--ui-dim);
  border: 1px solid rgba(154,160,199,0.3);
}
.btn-ghost:hover { color: var(--ui-white); border-color: var(--ui-white); }
.btn-block { width: 100%; }

/* ============================================================
   PHONE FACE — portrait single column, native (not a squish).
   Toggled by JS via #app[data-face="phone"] AND by media query.
   ============================================================ */
#app[data-face="phone"] {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}
#app[data-face="phone"] #rail { display: none; }
#app[data-face="phone"] .touch-controls { display: block; }
#app[data-face="phone"] .hud {
  top: auto;
  bottom: calc(22px + 3 * 66px + 2 * 8px + 16px); /* clear of dpad */
  padding: 8px 10px;
  gap: 6px;
}
#app[data-face="phone"] .hud-cell { min-width: 58px; padding: 2px 6px; }
#app[data-face="phone"] .hud-value { font-size: 20px; }
#app[data-face="phone"] .hud-timer .hud-value { font-size: 26px; }
#app[data-face="phone"] .hint-desktop { display: none; }
#app[data-face="phone"] .hint-phone { display: inline; }
#app[data-face="phone"] .level-title { font-size: 30px; }
#app[data-face="phone"] .fail-title { font-size: 34px; }
#app[data-face="phone"] .title-card,
#app[data-face="phone"] .level-card,
#app[data-face="phone"] .fail-card,
#app[data-face="phone"] .paused-card { padding: 30px 24px; }

/* Safety net: very narrow viewports force phone face even if JS hasn't. */
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #rail { display: none; }
  .touch-controls { display: block; }
  .hint-desktop { display: none; }
  .hint-phone { display: inline; }
}
