:root {
  --ink: #2a241c;
  --muted: #6f6256;
  --paper: #f4ecdc;
  --paper-2: #efe4d0;
  --line: #e0d2bc;
  --accent: #b5522e;
  --shadow: 0 18px 50px rgba(60, 40, 20, 0.28);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #c9bda8;
  overflow: hidden;
}

#view {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
  background: #1c1814;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.score, .out, .turn, .hint {
  position: absolute;
  background: rgba(244, 236, 220, 0.52);  /* punch31-merge11: less opaque cream */
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  box-shadow: 0 8px 24px rgba(50, 36, 18, 0.16);
}

.score {
  top: 72px;
  left: 14px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.win-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.ticket-line {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.ticket-line.hot { color: #7a2e16; }
.car-meter { top: 156px; }
.car-meter b { background: #6f8f5a; }
.out {
  top: 14px;
  right: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  border-radius: 16px;
}
.score b, .out b { font-variant-numeric: tabular-nums; }

.clock-panel {
  position: absolute;
  top: 14px;
  left: 14px;
  background: rgba(244, 236, 220, 0.52);
  border-radius: 16px;
  padding: 8px 14px;
  box-shadow: 0 8px 24px rgba(50, 36, 18, 0.16);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 180px;
}

.clock-panel b {
  font-variant-numeric: tabular-nums;
  font-size: 18px;
}

#gateNote {
  color: var(--muted);
  font-size: 12px;
}

.meter {
  position: absolute;
  top: 116px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(244, 236, 220, 0.48);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
  box-shadow: 0 8px 24px rgba(50, 36, 18, 0.12);
}

.meter i, .thank-cue i {
  display: block;
  width: 92px;
  height: 8px;
  border-radius: 999px;
  background: #e4d8c4;
  overflow: hidden;
}

.meter b, .thank-cue b#thankBar {
  display: block;
  height: 100%;
  width: 0%;
  background: #c47a32;
  border-radius: inherit;
}

.blink-badge {
  position: absolute;
  top: 46%;
  width: 54px;
  height: 58px;
  margin-top: -29px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  font-size: 20px;
  line-height: 1;
  color: rgba(42, 36, 28, 0.35);
  background: rgba(244, 236, 220, 0.55);
  border: 2px solid transparent;
  pointer-events: none;
  padding: 0;
  font: inherit;
  cursor: default;
  -webkit-appearance: none;
  appearance: none;
}

/* Big hazard thank — touch/no-keyboard only (shown via body.touch-chrome) */
.hazard-btn {
  display: none;
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  min-width: min(220px, calc(100vw - 120px));
  min-height: 56px;
  padding: 10px 22px;
  border-radius: 18px;
  border: 2px solid rgba(138, 61, 18, 0.35);
  background: #ffb03a;
  color: #5a2a0c;
  font: 700 18px/1.1 "Avenir Next", "Segoe UI", sans-serif;
  letter-spacing: 0.04em;
  box-shadow: 0 10px 28px rgba(80, 40, 10, 0.28);
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.hazard-btn span { font-size: 15px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.hazard-btn.held,
.hazard-btn:active {
  filter: brightness(0.92);
  transform: translateX(-50%) scale(0.97);
  background: #ff9a18;
}

.blink-badge small {
  font-size: 11px;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.lights-chip {
  position: absolute;
  top: 196px;
  left: 14px;
  background: rgba(244, 236, 220, 0.52);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(50, 36, 18, 0.12);
}

.lights-chip.on {
  color: var(--ink);
  background: #f3e2b0;
}

.lights-chip.warn {
  color: #7a2e16;
  background: #f0d0b0;
}

.score.bump {
  animation: scoreBump 0.45s ease;
}

@keyframes scoreBump {
  0% { transform: scale(1); }
  40% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

.point-pop {
  position: fixed;
  left: 16px;
  z-index: 7;
  pointer-events: none;
  background: rgba(244, 236, 220, 0.62);
  border-radius: 18px;
  padding: 8px 22px 10px;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 68px;
  line-height: 1.02;
  box-shadow: 0 16px 40px rgba(40, 24, 10, 0.32);
  animation: pointDrop 2.4s ease forwards;
  max-width: min(420px, calc(100vw - 28px));
}

.point-pop b {
  display: block;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.point-pop small {
  display: block;
  margin-top: 2px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.01em;
  opacity: 0.92;
}

.point-pop.up { color: #1f6b3a; }
.point-pop.down { color: #9d2218; }

.point-pop.quiet {
  animation: none;
  opacity: 1;
  font-size: 42px;
  top: 140px;
}

.ticket-show {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  z-index: 6;
  width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}

.ticket-card {
  background: rgba(244, 236, 220, 0.95);
  color: #2a241c;
  border-radius: 18px;
  padding: 14px 16px 12px;
  box-shadow: 0 16px 40px rgba(40, 24, 10, 0.28);
}

.ticket-card h2 {
  margin: 2px 0 6px;
  font-size: 28px;
  line-height: 1.05;
}

.ticket-card p {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.ticket-bar {
  display: block;
  height: 8px;
  margin: 10px 0 6px;
  border-radius: 99px;
  background: rgba(42, 36, 28, 0.12);
  overflow: hidden;
}

.ticket-bar b {
  display: block;
  height: 100%;
  width: 0%;
  background: #b5522e;
}

.ticket-meta {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  letter-spacing: 0.02em;
}

#radioBtn {
  min-width: 9.5em;
}

.toast.score-toast {
  font-size: 17px;
  font-weight: 600;
  padding: 12px 14px;
  border-left: 5px solid #c45a2d;
}

@keyframes pointDrop {
  0% { opacity: 0; transform: translateY(-36px) scale(1.35); }
  14% { opacity: 1; transform: translateY(0) scale(1); }
  72% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(16px) scale(0.96); }
}

.blink-badge.left { left: 12px; }
.blink-badge.right { right: 12px; }
.blink-badge.want { border-color: rgba(181, 82, 46, 0.45); }
.blink-badge.on {
  color: #8a3d12;
  background: #ffd27a;
  box-shadow: 0 0 0 4px rgba(255, 176, 64, 0.35);
}

.thank-cue {
  position: absolute;
  left: 50%;
  bottom: 62px;
  transform: translateX(-50%);
  background: rgba(255, 214, 140, 0.62);
  color: var(--ink);
  border-radius: 16px;
  padding: 10px 14px 8px;
  text-align: center;
  min-width: 220px;
  box-shadow: 0 10px 28px rgba(80, 40, 10, 0.2);
}

.thank-cue b { display: block; font-size: 18px; }
.thank-cue span { display: block; font-size: 14px; margin: 2px 0 6px; font-variant-numeric: tabular-nums; }
.thank-cue.bonus { background: #ffb03a; }
.thank-cue i { margin: 0 auto; }

.turn {
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 16px;
  text-align: center;
  min-width: 180px;
}

#turn {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 28px;
  letter-spacing: 0.02em;
  line-height: 1;
}

#body {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 4px;
}

.hint {
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  white-space: nowrap;
}

#toasts {
  position: fixed;
  left: 16px;
  bottom: 64px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: min(360px, calc(100vw - 32px));
}

.toast {
  background: rgba(244, 236, 220, 0.62);  /* punch31-merge11: match transparent HUD */
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  font-size: 14px;
}

#bulletin {
  position: fixed;
  top: 78px;
  right: 16px;
  width: min(260px, calc(100vw - 32px));
  background: var(--paper);
  color: var(--ink);
  padding: 16px 16px 14px;
  border-radius: 6px;
  box-shadow: var(--shadow);
  transform: rotate(-1.4deg);
}

#bulletin h2 {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 22px;
  margin: 8px 0 4px;
}

#bulletin p { margin: 0 0 6px; }

#plate {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  font-size: 20px;
}

.stamp {
  display: inline-block;
  border: 2px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.small { color: var(--muted); font-size: 12px; }

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Opaque enough that the lit canvas cannot glare through menus on phone */
  background: rgba(36, 30, 24, 0.92);
  padding: 16px;
}

.card {
  width: min(460px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  min-width: 0;
  background: var(--paper);
  color: var(--ink);
  border-radius: 18px;
  padding: 26px 26px 22px;
  box-shadow: var(--shadow);
  overflow-wrap: break-word;
}

.kicker {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--accent);
}

h1 {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-weight: 500;
  font-size: 40px;
  line-height: 0.95;
  margin: 6px 0 12px;
}

.card p { margin: 0 0 12px; line-height: 1.45; }

.keys {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  background: var(--paper-2);
  border-radius: 12px;
  padding: 12px;
  margin: 8px 0 16px;
  font-size: 14px;
}

kbd {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background: white;
  border-radius: 6px;
  padding: 2px 6px;
  border: 1px solid var(--line);
}

button {
  font: inherit;
  background: var(--accent);
  color: #fff8ef;
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  cursor: pointer;
}

/* Launch Start: solid green CTA under the two title paras (not buried after keys). */
#startBtn {
  display: block;
  width: 100%;
  min-height: 48px;
  margin: 4px 0 16px;
  padding: 14px 18px;
  background: #1f6b3a;
  color: #fff8ef;
  font-weight: 650;
  box-shadow: 0 8px 22px rgba(31, 107, 58, 0.35);
}
#startBtn:hover,
#startBtn:focus-visible {
  background: #258448;
  outline: 2px solid rgba(255, 248, 239, 0.55);
  outline-offset: 2px;
}
#startBtn:active {
  background: #175530;
  transform: scale(0.985);
}

/* Keyboard legend: tablet/desktop only — hide on phone / narrow portrait. */
@media (max-width: 640px), (max-width: 700px) and (orientation: portrait) {
  #overlay .card > .keys {
    display: none;
  }
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.actions button {
  width: 100%;
  min-height: 44px;
}

.booked-actions {
  width: min(380px, calc(100vw - 32px));
}

#menuBtn {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 5;
  min-height: 44px;
  padding: 10px 16px;
  box-shadow: 0 8px 24px rgba(50, 36, 18, 0.16);
}

#pause {
  z-index: 8;
  /* Scrim only. The card is solid. The canvas stays up so a phone does not go blank. */
  background: rgba(36, 30, 24, 0.38);
}

.results {
  list-style: none;
  margin: 8px 0 14px;
  padding: 10px 12px;
  background: rgba(255, 248, 236, 0.72);
  border-radius: 12px;
  text-align: left;
}

.results li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  font-size: 14px;
}

.results b { font-variant-numeric: tabular-nums; }

#booked .results {
  background: rgba(255, 255, 255, 0.9);
  color: #1c1e21;
}

#pause .card {
  background: #f4ecdc;
  color: #2a241c;
}

/* Keep the last WebGL frame visible under opaque pause/menus.
   Hiding #view made mobile app-switcher / resume look blank. */
body.sim-paused #view,
body.app-hidden #view {
  /* intentionally visible — render loop is frozen instead */
}

#audioBar {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  pointer-events: auto;
  max-width: calc(100vw - 108px);
  background: rgba(244, 236, 220, 0.92);
  border-radius: 999px;
  padding: 6px 8px 6px 6px;
  box-shadow: 0 8px 24px rgba(50, 36, 18, 0.16);
}

#audioBar button {
  padding: 8px 12px;
  font-size: 13px;
}

#gatePaintBtn {
  background: #f3d4e8;
}

#audioBar label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

#vol { width: 88px; accent-color: var(--accent); }

.booked {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(8, 10, 16, 0.42);
  padding: 16px;
}

.wasted {
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: clamp(42px, 8vw, 84px);
  letter-spacing: 0.08em;
  color: #e8e6ea;
  text-shadow: 0 6px 0 #1a0a0c, 0 0 24px rgba(0, 0, 0, 0.45);
  margin: 0;
}

.fb-card {
  width: min(380px, calc(100vw - 32px));
  background: rgba(255, 255, 255, 0.55);
  color: #1c1e21;
  border-radius: 10px;
  padding: 12px 12px 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.fb-logo {
  color: #1877f2;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.04em;
  margin-bottom: 8px;
}

.fb-user {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.fb-user i {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #d8dde6;
  display: block;
}

.fb-user b { display: block; font-size: 14px; }
.fb-user small { color: #65676b; font-size: 12px; }
.fb-text { margin: 0 0 8px; font-size: 15px; }

.fb-card img {
  display: block;
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 6px;
  background: #d0d4dc;
}

.fb-plate {
  margin: 8px 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  font-size: 18px;
}

.fb-bar {
  border-top: 1px solid rgba(0, 0, 0, 0.12);
  padding-top: 8px;
  color: #65676b;
  font-size: 13px;
}

.booked button { pointer-events: auto; }
.booked button.ghost {
  background: rgba(244, 236, 220, 0.94);
  color: var(--ink);
}

.foot { color: var(--muted); font-size: 12px; margin-top: 12px; }

.art {
  height: 46px;
  margin-bottom: 8px;
  background:
    linear-gradient(#2a241c, #2a241c) 8px 30px / 92px 8px no-repeat,
    repeating-linear-gradient(90deg, #e0b33a 0 10px, #2a241c 10px 20px) 8px 26px / 92px 10px no-repeat,
    radial-gradient(circle at 120px 16px, #f0d78a 0 7px, #2a241c 8px 10px, transparent 11px);
}

#fail:not(.backup) .art { display: none; }

#selftest {
  position: fixed;
  left: 8px;
  bottom: 8px;
  max-height: 45vh;
  overflow: auto;
  background: rgba(255, 255, 255, 0.92);
  color: #1b1b1b;
  font: 12px/1.4 ui-monospace, monospace;
  padding: 8px;
  z-index: 5;
}

[hidden] { display: none !important; }

@media (max-width: 640px) {
  h1 { font-size: 32px; }
  .card { padding: 20px 16px 16px; }
  /* Compact top HUD so street/map dominates the viewport */
  .score, .out, .turn, .hint {
    padding: 4px 9px;
    box-shadow: 0 4px 14px rgba(50, 36, 18, 0.12);
    font-size: 12px;
  }
  .clock-panel {
    top: 6px;
    left: 6px;
    min-width: 0;
    max-width: calc(100vw - 132px);
    padding: 4px 8px;
    border-radius: 12px;
    gap: 0;
  }
  .clock-panel b { font-size: 13px; }
  #gateNote { font-size: 10px; line-height: 1.2; }
  .turn {
    top: 6px;
    left: auto;
    right: 6px;
    transform: none;
    min-width: 0;
    padding: 4px 8px;
    border-radius: 12px;
  }
  #turn { font-size: 16px; }
  #body { font-size: 10px; margin-top: 1px; letter-spacing: 0.06em; }
  .score {
    top: 52px;
    left: 6px;
    border-radius: 12px;
    gap: 0;
    padding: 4px 8px;
  }
  .win-hint, .ticket-line { font-size: 10px; }
  .out {
    top: 52px;
    right: 6px;
    border-radius: 12px;
    gap: 0;
    padding: 4px 8px;
    font-size: 11px;
  }
  .meter {
    top: 96px;
    left: 6px;
    padding: 3px 7px;
    gap: 5px;
    font-size: 10px;
  }
  .meter i, .thank-cue i { width: 64px; height: 6px; }
  .car-meter { top: 120px; }
  .lights-chip {
    top: 144px;
    left: 6px;
    font-size: 10px;
    padding: 3px 8px;
  }
  .point-pop { font-size: 36px; left: 6px; padding: 6px 14px 8px; border-radius: 14px; }
  .point-pop small { font-size: 13px; }
  .point-pop.quiet { font-size: 28px; top: 110px; }
  .hint {
    white-space: normal;
    text-align: center;
    max-width: calc(100vw - 20px);
    bottom: 48px;
    font-size: 12px;
    padding: 4px 10px;
  }
  .thank-cue {
    bottom: 88px;
    min-width: 0;
    max-width: calc(100vw - 20px);
    padding: 6px 10px 5px;
    border-radius: 12px;
  }
  .thank-cue b { font-size: 14px; }
  .thank-cue span { font-size: 12px; }
  .blink-badge { width: 36px; height: 36px; font-size: 14px; border-radius: 12px; }
  .blink-badge small { font-size: 9px; }
  /* Patrol / ticket card: compact overlay, less map crush */
  .ticket-show {
    bottom: 72px;
    width: min(340px, calc(100vw - 20px));
  }
  .ticket-card {
    padding: 8px 10px 7px;
    border-radius: 12px;
  }
  .ticket-card h2 { font-size: 18px; margin: 0 0 3px; }
  .ticket-card p { font-size: 12px; line-height: 1.25; }
  .ticket-bar { height: 5px; margin: 6px 0 4px; }
  .ticket-meta { font-size: 11px; }
  /* Bottom chrome: compact audio + menu so map grows */
  #audioBar {
    left: 6px;
    bottom: 6px;
    max-width: calc(100vw - 88px);
    gap: 4px;
    padding: 3px 5px 3px 3px;
    border-radius: 999px;
  }
  #audioBar button {
    padding: 5px 8px;
    font-size: 11px;
    min-height: 32px;
  }
  #audioBar label { font-size: 11px; gap: 4px; }
  #vol { width: 56px; }
  #radioBtn { min-width: 0; }
  #menuBtn {
    right: 6px;
    bottom: 6px;
    min-height: 40px;
    padding: 8px 12px;
    font-size: 13px;
  }
  /* Touch stick BR + slim H/L + Pause/Exit above audio (punch31-merge6 layout; merge11 shrink) */
  #touchNav {
    left: 6px;
    bottom: 48px;
    gap: 4px;
  }
  #touchNav button {
    min-width: 56px;
    min-height: 32px;
    padding: 4px 8px;
    font-size: 11px;
  }
  #stickBase {
    width: 72px;
    height: 72px;
    right: 6px;
    left: auto;
    bottom: 40px;
  }
  #stickKnob {
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
  }
  #touchActions {
    right: 84px;
    bottom: 40px;
    gap: 4px;
    grid-template-columns: 1fr;
  }
  #touchActions button {
    min-width: 36px;
    min-height: 32px;
    padding: 3px 2px;
    font-size: 10px;
  }
  .hazard-btn {
    top: 6px;
    min-width: min(140px, calc(100vw - 100px));
    min-height: 40px;
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 12px;
  }
  .hazard-btn span { font-size: 11px; }
  body.touch-chrome .blink-badge {
    width: 42px;
    height: 46px;
    margin-top: -23px;
    font-size: 15px;
  }
  body.touch-chrome .meter {
    top: 96px;
    right: 6px;
    left: auto;
  }
  body.touch-chrome .car-meter {
    top: 120px;
    right: 6px;
    left: auto;
  }

  /* Portrait phones: title card taller than viewport — scroll + sticky Join */
  .overlay {
    align-items: flex-start;
    justify-content: center;
    padding: 12px 12px 16px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .card {
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    margin: auto 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  h1 {
    font-size: 28px;
    margin: 4px 0 8px;
  }

  .keys {
    /* Hidden on phone/narrow portrait via earlier media rule; keep compact if shown */
    margin: 4px 0 12px;
  }

  #fail .card .actions,
  #pause .card .actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: var(--paper);
    padding-top: 8px;
    box-shadow: 0 -10px 18px var(--paper);
  }

  /* Start is in-flow under the two paras; keys hidden — keep green CTA, no sticky bottom */
  #overlay .card #startBtn {
    position: static;
    display: block;
    width: 100%;
    min-height: 48px;
    margin: 4px 0 12px;
    padding: 14px 16px;
    z-index: auto;
    background: #1f6b3a;
    color: #fff8ef;
    box-shadow: 0 8px 22px rgba(31, 107, 58, 0.35);
  }

  #overlay .card {
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
  }

  /* During title overlay, tuck audio bar under the dimmer so Join wins taps */
  body:has(#overlay:not([hidden])) #audioBar {
    z-index: 1;
  }
  #overlay {
    z-index: 5;
  }

  .foot {
    font-size: 11px;
    margin-top: 8px;
    line-height: 1.3;
  }
}



/* Title overlay: leave game → site home */
.home-close {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 9;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(244, 236, 220, 0.94);
  color: var(--ink);
  text-decoration: none;
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 8px 24px rgba(50, 36, 18, 0.16);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.home-close:hover,
.home-close:focus-visible {
  background: #fff8ef;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.home-close:active {
  transform: scale(0.96);
}

/* Short phone-landscape / short viewports: keep title Join tappable */
@media (max-height: 430px) {
  .overlay {
    align-items: flex-start;
    justify-content: center;
    padding: 8px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .home-close {
    top: 6px;
    right: 6px;
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  .card {
    width: min(560px, calc(100vw - 16px));
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    margin: auto 0;
    padding: 10px 14px 10px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .kicker { font-size: 10px; letter-spacing: 0.12em; }

  h1 {
    font-size: 22px;
    line-height: 1;
    margin: 2px 0 6px;
  }

  .card > p {
    margin: 0 0 6px;
    font-size: 13px;
    line-height: 1.3;
  }

  .keys {
    gap: 2px 8px;
    padding: 8px;
    margin: 2px 0 8px;
    font-size: 12px;
    line-height: 1.25;
  }

  kbd { padding: 1px 5px; }

  #fail .card .actions,
  #pause .card .actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: var(--paper);
    padding-top: 6px;
    box-shadow: 0 -10px 18px var(--paper);
  }

  #overlay .card #startBtn {
    position: static;
    display: block;
    width: 100%;
    min-height: 44px;
    margin: 2px 0 8px;
    padding: 10px 16px;
    z-index: auto;
    background: #1f6b3a;
    color: #fff8ef;
    box-shadow: 0 8px 22px rgba(31, 107, 58, 0.35);
  }

  .actions { gap: 6px; }
  .actions button { min-height: 40px; padding: 10px 14px; }

  .foot {
    font-size: 11px;
    margin-top: 6px;
    line-height: 1.3;
  }

  .art { height: 28px; margin-bottom: 4px; }

  .wasted { font-size: clamp(28px, 7vw, 48px); }
  .fb-card img { height: 100px; }
  .booked { gap: 10px; padding: 8px; }
}

@media (max-height: 360px) {
  h1 { font-size: 18px; margin: 0 0 4px; }
  .card { padding: 8px 12px; }
  .card > p { font-size: 12px; margin: 0 0 4px; }
  .keys {
    max-height: 28vh;
    overflow-y: auto;
    margin: 0 0 6px;
    font-size: 11px;
  }
  .foot { display: none; }
}


/* punch31-merge14: remove in-game footer help banner (desktop + touch) */
.hint,
#hint {
  display: none !important;
}

/* punch31-merge14: desktop/tablet — Line | Turn chip | Car meters across the top */
body:not(.touch-chrome) .meter {
  top: 22px;
  left: auto;
  right: calc(50% + 102px);
}
body:not(.touch-chrome) .car-meter {
  top: 22px;
  left: calc(50% + 102px);
  right: auto;
}



/* Touch / mobile play chrome */
#touchPad {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#touchNav {
  pointer-events: auto;
  position: absolute;
  left: 12px;
  bottom: 64px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 4;
  touch-action: none;
}
#touchNav button {
  min-width: 70px;
  min-height: 36px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 650;
  box-shadow: 0 8px 20px rgba(50, 36, 18, 0.18);
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
#touchNav button.ghost {
  background: rgba(244, 236, 220, 0.5);
}

#stickBase {
  pointer-events: auto;
  position: absolute;
  right: 12px;
  left: auto;
  bottom: 52px;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(244, 236, 220, 0.28);
  border: 2px solid rgba(42, 36, 28, 0.22);
  box-shadow: 0 8px 24px rgba(50, 36, 18, 0.14);
  touch-action: none;
}

#stickKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  background: rgba(181, 82, 46, 0.88);
  border: 2px solid rgba(255, 248, 239, 0.55);
  box-shadow: 0 4px 14px rgba(40, 24, 10, 0.28);
  will-change: transform;
}

#touchActions {
  pointer-events: auto;
  position: absolute;
  right: 112px;
  bottom: 52px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  touch-action: none;
}

#touchActions button {
  min-width: 44px;
  min-height: 38px;
  padding: 5px 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.1;
  box-shadow: 0 8px 20px rgba(50, 36, 18, 0.18);
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#touchActions button.ghost {
  background: rgba(244, 236, 220, 0.5);
}

#touchActions button:active,
#touchActions button.held {
  filter: brightness(0.92);
  transform: scale(0.97);
}

@media (pointer: coarse), (hover: none), (max-width: 820px), (max-height: 500px) {
  #touchPad:not([hidden]) {
    display: block;
  }
  /* Touch pad carries Menu; hide duplicate floating Menu */
  body.touch-chrome #menuBtn {
    display: none !important;
  }

  /* Phone / no-keyboard play chrome (punch31-merge6) */
  body.touch-chrome .turn {
    display: none !important;
  }
  body.touch-chrome .lights-chip {
    display: none !important;
  }
  body.touch-chrome .hazard-btn:not([hidden]) {
    display: flex;
  }
  body.touch-chrome .blink-badge {
    pointer-events: auto;
    cursor: pointer;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    width: 48px;
    height: 54px;
    margin-top: -27px;
    font-size: 18px;
    background: rgba(244, 236, 220, 0.48);
    border-color: rgba(42, 36, 28, 0.18);
    box-shadow: 0 8px 22px rgba(50, 36, 18, 0.18);
  }
  body.touch-chrome .blink-badge.held,
  body.touch-chrome .blink-badge:active {
    filter: brightness(0.94);
    transform: scale(0.97);
  }
  body.touch-chrome .meter {
    top: 96px;
    left: auto;
    right: 6px;
  }
  body.touch-chrome .car-meter {
    top: 120px;
    left: auto;
    right: 6px;
  }
  body.touch-chrome #audioBar {
    max-width: calc(100vw - 118px);
  }
}


@media (max-height: 430px) {
  #touchNav {
    left: 4px;
    bottom: 40px;
    gap: 3px;
  }
  #touchNav button {
    min-width: 52px;
    min-height: 28px;
    padding: 3px 6px;
    font-size: 10px;
  }
  #stickBase {
    width: 64px;
    height: 64px;
    right: 6px;
    left: auto;
    bottom: 32px;
  }
  #stickKnob {
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
  }
  #touchActions {
    right: 74px;
    bottom: 32px;
    gap: 3px;
    grid-template-columns: 1fr;
  }
  #touchActions button {
    min-width: 32px;
    min-height: 28px;
    padding: 2px 2px;
    font-size: 9px;
  }
  #audioBar {
    max-width: calc(100vw - 120px);
    padding: 2px 4px 2px 2px;
    gap: 3px;
  }
  #audioBar button { padding: 4px 7px; font-size: 10px; min-height: 28px; }
  #vol { width: 48px; }
  .thank-cue { bottom: 108px; }
  .hint { bottom: 108px; }
  .ticket-show { bottom: 118px; }
  .ticket-card { padding: 6px 8px 5px; }
  .ticket-card h2 { font-size: 15px; }
  .ticket-card p { font-size: 11px; }
  .clock-panel { padding: 3px 6px; }
  .clock-panel b { font-size: 12px; }
  .score, .out { top: 40px; padding: 3px 6px; }
  /* touch keeps stacked right; desktop keeps top flank (merge14) */
  body.touch-chrome .meter { top: 78px; right: 6px; left: auto; }
  body.touch-chrome .car-meter { top: 98px; right: 6px; left: auto; }
  body:not(.touch-chrome) .meter { top: 14px; right: calc(50% + 90px); left: auto; }
  body:not(.touch-chrome) .car-meter { top: 14px; left: calc(50% + 90px); right: auto; }
  .lights-chip { top: 118px; font-size: 9px; padding: 2px 6px; }
  .hazard-btn {
    top: 4px;
    min-height: 40px;
    min-width: min(140px, calc(100vw - 90px));
    padding: 6px 10px;
    font-size: 13px;
  }
  body.touch-chrome .blink-badge {
    width: 44px;
    height: 48px;
    margin-top: -24px;
    font-size: 16px;
  }
}


/* Win card — warm base commendation (punch31-merge5), Soft/Candy paper */
#win .win-card {
  background:
    linear-gradient(180deg, rgba(255, 250, 240, 0.95) 0%, var(--paper) 42%, var(--paper-2) 100%);
  border: 1.5px solid #d7c4a4;
  box-shadow:
    var(--shadow),
    inset 0 0 0 1px rgba(255, 248, 236, 0.85),
    inset 0 0 0 7px rgba(214, 180, 120, 0.14);
  text-align: center;
}

#win .win-kicker {
  color: #8a5a32;
  letter-spacing: 0.04em;
  font-size: 11px;
  font-weight: 650;
  text-transform: none;
}

#win #winTitle,
#win .win-card h1 {
  font-family: "Iowan Old Style", Palatino, Georgia, "Times New Roman", serif;
  font-weight: 600;
  font-size: clamp(28px, 5.2vw, 38px);
  line-height: 1.08;
  letter-spacing: 0.01em;
  color: #7a3f1c;
  margin: 8px 0 10px;
  text-shadow: 0 1px 0 rgba(255, 248, 236, 0.9);
}

#win .win-citation {
  margin: 0 auto 16px;
  max-width: 34em;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
  font-style: italic;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
}

#win .win-stats-label,
#win #winScore {
  margin: 0 0 6px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #8a5a32;
  font-style: normal;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

#win #winResults .results {
  margin-top: 0;
  background: rgba(255, 250, 240, 0.82);
  border: 1px solid rgba(215, 196, 164, 0.65);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

#win .actions button:not(.ghost) {
  background: #8a4a28;
  color: #fff8ef;
  box-shadow: 0 8px 20px rgba(122, 63, 28, 0.28);
}
#win .actions button:not(.ghost):hover,
#win .actions button:not(.ghost):focus-visible {
  background: #9b5630;
}
#win .actions button:not(.ghost):active {
  background: #6f3a1e;
  transform: scale(0.985);
}

@media (max-width: 640px), (max-width: 700px) and (orientation: portrait) {
  #win .card .actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: var(--paper);
    padding-top: 8px;
    box-shadow: 0 -10px 18px var(--paper);
  }
}

@media (max-height: 430px) {
  #win #winTitle,
  #win .win-card h1 { font-size: 22px; margin: 4px 0 6px; }
  #win .win-citation { font-size: 13px; margin-bottom: 8px; }
  #win .card .actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: var(--paper);
    padding-top: 6px;
    box-shadow: 0 -10px 18px var(--paper);
  }
}

/* Kawaii / good-event balloons + cheers (punch27) */
#fxLayer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  overflow: hidden;
}
.cheer-banner {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  font: 800 28px/1.1 system-ui, sans-serif;
  color: #fff7fb;
  text-shadow: 0 2px 0 #ff6eb4, 0 6px 18px rgba(40, 10, 40, 0.45);
  animation: cheer-pop 1.6s ease-out forwards;
  white-space: nowrap;
}
.dom-balloon {
  position: absolute;
  bottom: -40px;
  width: 28px;
  height: 36px;
  border-radius: 50% 50% 50% 50% / 42% 42% 58% 58%;
  animation: balloon-rise 2.1s ease-out forwards;
  box-shadow: inset -4px -6px 0 rgba(255, 255, 255, 0.35);
}
.dom-balloon::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 100%;
  width: 2px;
  height: 22px;
  margin-left: -1px;
  background: rgba(255, 246, 238, 0.65);
}
@keyframes cheer-pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.6) translateY(12px); }
  18% { opacity: 1; transform: translateX(-50%) scale(1.12) translateY(0); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) scale(1) translateY(-18px); }
}
@keyframes balloon-rise {
  0% { transform: translateY(0) rotate(-6deg); opacity: 0; }
  12% { opacity: 1; }
  100% { transform: translateY(-110vh) rotate(10deg); opacity: 0; }
}
