/* =====================================================================
   Ambulance — fixed "daylight city" theme.
   Same page frame as Flappy / Timberman (full-height app shell, frosted
   top bar, chunky arcade buttons, hard-shadow stage, card overlays,
   colored rules modal) but with this game's own palette taken straight
   from its 3D scene: emergency red, ambulance white, asphalt grey, beacon
   green, sky blue, warm gold trim. The stage is a 16:9 landscape board
   because this is a driving game. Deliberately ignores the center's
   light/dark mode; no glass.css loaded. The c-* chrome lives HERE on
   purpose — it is not inherited from the shared stylesheets.
   ===================================================================== */
:root {
  --am-sky:    #8fc7e8;   /* page gradient top */
  --am-sky2:   #bfe0f2;   /* page gradient middle */
  --am-haze:   #eaf3ea;   /* page gradient bottom */
  --am-red:    #e23b4e;   /* ambulance livery / primary */
  --am-reddk:  #8f1d2b;
  --am-white:  #f4f6fb;
  --am-asphalt:#4a5463;   /* roads */
  --am-asphdk: #2b3242;   /* outline ink — main text colour */
  --am-green:  #35b46a;   /* patient beacon */
  --am-gold:   #f4b731;   /* trim / highlights */
  --am-line:   rgba(43, 50, 66, .82);
  --am-cream:  #fbfdff;
}

html, body { height: 100%; }
body.am-page {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, var(--am-sky) 0%, var(--am-sky2) 52%, var(--am-haze) 100%);
  color: var(--am-asphdk);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.am-page *,
body.am-page *::before,
body.am-page *::after { box-sizing: border-box; }

/* ---------- App frame ---------- */
.c-app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.c-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px 18px;
  flex-wrap: wrap;
  padding: 12px clamp(12px, 3vw, 28px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(255, 255, 255, .4);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--am-red);
  z-index: 20;
}
.c-bar__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.c-bar__brand svg { filter: drop-shadow(0 2px 0 rgba(43, 50, 66, .18)); }
.c-bar__title {
  margin: 0;
  font-size: clamp(19px, 3.4vw, 26px);
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--am-asphdk);
  text-shadow: 2px 2px 0 rgba(255, 255, 255, .55);
}
.c-bar__stats { display: flex; align-items: center; gap: 8px 18px; margin-left: auto; }
.c-bar__controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stat { font-size: 14px; font-weight: 700; letter-spacing: .03em; white-space: nowrap; color: rgba(43, 50, 66, .72); }
.stat b { color: var(--am-reddk); font-size: 16px; }

/* ---------- Buttons (chunky arcade style, matches the shared frame) ------ */
.c-btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-block;
  padding: 9px 16px;
  border-radius: 12px;
  border: 2px solid var(--am-line);
  background: #fff;
  color: var(--am-asphdk);
  box-shadow: 0 3px 0 rgba(43, 50, 66, .35);
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
}
.c-btn:hover { background: #fdeef0; border-color: var(--am-red); }
.c-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(43, 50, 66, .35); }
.c-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(226, 59, 78, .5); }
/* Primary = ambulance emergency red. */
.c-btn--primary {
  background: linear-gradient(140deg, #ef5566, var(--am-red));
  border-color: var(--am-line);
  color: #fff;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, .2);
}
.c-btn--primary:hover { background: linear-gradient(140deg, #f4697a, var(--am-red)); }

/* ---------- Table / stage column ---------- */
.c-table {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 2.4vh, 22px);
}
.am-board {
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* 16:9 landscape; capped by both viewport width and remaining height. */
  width: min(96vw, calc((100vh - 210px) * 1.7778), 1040px);
  width: min(96vw, calc((100dvh - 210px) * 1.7778), 1040px);
}
.am-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(#bfe0f2, #dbe7df);
  border: 3px solid var(--am-line);
  box-shadow: 0 10px 0 rgba(43, 50, 66, .22), 0 22px 48px rgba(43, 50, 66, .35);
  touch-action: manipulation;
}
#scene {
  display: block;
  width: 100%; height: 100%;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
}

/* ---------- Timer (shift clock) bar ---------- */
.timerbar {
  position: relative;
  flex: none;
  height: 20px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .6);
  border: 2px solid var(--am-line);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(43, 50, 66, .18);
}
.timerbar__fill {
  height: 100%; width: 100%;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd15a, var(--am-gold));
  transition: width .12s linear, background-color .3s ease;
}
.timerbar__fill.warn { background: linear-gradient(180deg, #ffa24d, #ef7a2a); }
.timerbar__fill.low  { background: linear-gradient(180deg, #ff6a72, var(--am-red)); }
.timerbar__label {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; letter-spacing: .04em;
  color: var(--am-asphdk);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .6);
  pointer-events: none;
}

/* ---------- HUD overlay (objective + compass) ---------- */
.am-hud { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.am-hud[hidden] { display: none; }
.am-objective {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(43, 50, 66, .72);
  color: #fff;
  font-size: 14px; font-weight: 800; letter-spacing: .03em;
  text-transform: uppercase;
  border: 2px solid rgba(255, 255, 255, .5);
  box-shadow: 0 4px 12px rgba(43, 50, 66, .35);
  white-space: nowrap;
}
.am-objective.pick { background: rgba(30, 120, 68, .82); }
.am-objective.drop { background: rgba(180, 40, 55, .85); }

/* Frameless 3D navigation readout pinned to the top-centre of the stage: a
   perspective-tilted extruded arrow (JS yaws #arrow) over an extruded
   distance number. No dial box / backdrop — it floats on the scene. */
.am-nav {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 0;
  perspective: 420px;
}
.am-arrow3d {
  width: 66px; height: 66px;
  transform: rotateX(30deg);
  transform-style: preserve-3d;
  filter: drop-shadow(0 8px 7px rgba(43, 50, 66, .45));
}
.am-arrow {
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .09s linear;
}
.am-arrow svg { width: 100%; height: 100%; display: block; overflow: visible; }
.am-arrow__face { fill: var(--am-green); stroke: #0f5a30; stroke-width: 1.3; stroke-linejoin: round; }
/* Underside offset down-right behind the face fakes solid thickness. */
.am-arrow__side { fill: #157a44; stroke: none; transform: translate(1.8px, 3.4px); }
.am-arrow.drop .am-arrow__face { fill: #ff6472; stroke: #7a1420; }
.am-arrow.drop .am-arrow__side { fill: #8f1420; }
.am-dist {
  font-size: 23px; font-weight: 800; letter-spacing: .03em;
  color: #fff;
  text-shadow:
    0 1px 0 #b6791f, 0 2px 0 #9c6716, 0 3px 0 #7f5311,
    0 4px 0 #613f0b, 0 6px 8px rgba(0, 0, 0, .45);
}

/* ---------- Penalty toast (hitting a car / pedestrian) ---------- */
.am-toast {
  position: absolute; bottom: 64px; left: 50%; transform: translateX(-50%);
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(205, 40, 55, .92);
  color: #fff;
  font-size: 15px; font-weight: 800; letter-spacing: .03em;
  border: 2px solid rgba(255, 255, 255, .6);
  box-shadow: 0 6px 16px rgba(43, 50, 66, .4);
  white-space: nowrap;
  pointer-events: none;
}
.am-toast[hidden] { display: none; }
.am-toast.show { animation: amToast 1.2s ease forwards; }
@keyframes amToast {
  0%   { opacity: 0; transform: translateX(-50%) translateY(8px) scale(.9); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-14px) scale(1); }
}
/* Timer bar shakes + flashes when the clock loses time to a hit. */
.timerbar.hit { animation: amHit .4s ease; }
@keyframes amHit {
  0%, 100% { box-shadow: inset 0 1px 3px rgba(43, 50, 66, .18); }
  20%, 60% { box-shadow: 0 0 0 3px rgba(255, 60, 72, .8), inset 0 1px 3px rgba(43, 50, 66, .18); }
  30%, 70% { transform: translateX(-4px); }
  50%      { transform: translateX(4px); }
}

/* ---------- Caption under the stage ---------- */
.am-caption {
  flex: none;
  margin: 0;
  text-align: center;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.9;
  color: rgba(43, 50, 66, .72);
}
.am-card kbd, .c-modal kbd, .am-caption kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin: 0 1px;
  font: 700 12px/1.5 ui-monospace, "Segoe UI", monospace;
  text-align: center;
  color: var(--am-asphdk);
  background: #fff;
  border: 1px solid var(--am-line);
  border-radius: 6px;
  box-shadow: 0 2px 0 rgba(43, 50, 66, .3);
}

/* ---------- Ready / game-over overlays ---------- */
.am-overlay {
  touch-action: manipulation;
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(43, 50, 66, .34);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.am-overlay[hidden] { display: none; }
.am-card {
  touch-action: manipulation;
  max-width: 340px;
  text-align: center;
  padding: 22px 24px 20px;
  border-radius: 16px;
  background: linear-gradient(160deg, #ffffff, var(--am-cream));
  border: 2px solid var(--am-line);
  box-shadow: 0 8px 0 rgba(43, 50, 66, .25), 0 22px 50px rgba(43, 50, 66, .4);
  color: var(--am-asphdk);
  animation: amPop .3s ease;
}
@keyframes amPop { from { transform: scale(.88); opacity: 0; } }
.am-card__big { font-size: 42px; line-height: 1.1; }
.am-card__big svg { display: block; margin: 0 auto; }
.am-card h2 {
  margin: 6px 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--am-asphdk);
  text-shadow: 2px 2px 0 rgba(255, 255, 255, .5);
}
.am-card p { margin: 0 0 14px; color: #4a5463; font-size: 13.5px; line-height: 1.55; }
.am-card p b { color: var(--am-reddk); }
.am-card .c-btn { font-size: 14px; }

/* ---------- Rules modal ---------- */
.c-modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; padding: 16px;
  overflow-y: auto;            /* the overlay itself scrolls; the card never has an inner scrollbar */
  overscroll-behavior: contain;
}
.c-modal[hidden] { display: none; }
.c-modal__backdrop {
  position: fixed; inset: 0;   /* stays put while the overlay scrolls */
  background: rgba(43, 50, 66, .5);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
/* Panel is "inside the rig": deep ambulance-white with red trim + asphalt ink.
   margin:auto centres it and — unlike align-items:center — lets a too-tall card
   scroll into view from the top instead of clipping. */
.c-modal__panel {
  position: relative; z-index: 1;
  margin: auto;
  width: min(92vw, 490px);
  background: linear-gradient(160deg, #ffffff, #e7edf3);
  color: var(--am-asphdk);
  border-radius: 16px;
  border: 2px solid var(--am-line);
  box-shadow: 0 8px 0 rgba(43, 50, 66, .3), 0 24px 60px rgba(43, 50, 66, .55);
}
.c-modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 2px solid var(--am-red);
  background: linear-gradient(140deg, #ef5566, var(--am-red));
  border-radius: 14px 14px 0 0;
}
.c-modal__head h2 {
  margin: 0; font-size: 18px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .04em;
  color: #fff; text-shadow: 2px 2px 0 rgba(0, 0, 0, .2);
}
.c-modal__x {
  appearance: none; border: 0; background: none;
  color: #fff; font-size: 26px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.c-modal__x:hover { color: var(--am-gold); }
.c-modal__body { padding: 8px 20px 4px; font-size: 14px; line-height: 1.55; }
.c-modal__body h3 {
  margin: 16px 0 6px; font-size: 13px;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--am-reddk);
}
.c-modal__body ul { margin: 0; padding-left: 20px; }
.c-modal__body li { margin: 4px 0; }
.c-modal__body b { color: var(--am-reddk); }
.c-modal__lead { margin: 12px 0; }
.c-modal__note {
  margin: 14px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(74, 84, 99, .1);
  border: 1px solid rgba(74, 84, 99, .28);
  font-size: 13px;
  color: #3d4757;
}
.c-modal__foot { display: flex; justify-content: flex-end; padding: 12px 20px 16px; }
.c-modal .c-btn--primary { border-color: var(--am-line); }

/* ---------- Responsive ---------- */
@media (max-width: 700px), (max-height: 620px) {
  .c-bar { gap: 5px 12px; padding: 7px clamp(10px, 3vw, 18px); padding-top: max(7px, env(safe-area-inset-top)); }
  .c-bar__brand { gap: 8px; }
  .c-bar__title { font-size: 16px; }
  .c-bar__stats { gap: 4px 12px; margin-left: auto; }
  .stat { font-size: 12px; }
  .stat b { font-size: 13px; }
  .c-btn { padding: 8px 10px; font-size: 12px; }
  .c-bar__controls { gap: 6px; }
  .c-bar__controls .c-btn { padding: 9px 10px; white-space: nowrap; }
  .am-board { width: min(97vw, calc((100vh - 185px) * 1.7778), 1040px); width: min(97vw, calc((100dvh - 185px) * 1.7778), 1040px); }
}
@media (max-width: 700px) {
  .c-bar__controls { flex: 1 1 100%; flex-wrap: nowrap; }
  .c-bar__controls .c-btn { flex: 1 1 auto; min-width: 0; padding: 9px 6px; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 420px) {
  .am-objective { font-size: 11.5px; padding: 5px 11px; }
  .am-arrow3d { width: 52px; height: 52px; }
  .am-dist { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  .c-btn, .am-card, .am-arrow, .timerbar__fill { transition: none; animation: none; }
}
