:root {
  --navy: #070b1f;
  --ink: #0e1433;
  --red: #e23b4a;
  --green: #2fbf71;
  --gold: #ffd166;
  --cream: #fff4dc;
  --glass: rgba(14, 20, 51, 0.72);
  --font: ui-rounded, "Arial Rounded MT Bold", "Nunito", "Trebuchet MS", system-ui, sans-serif;
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; width: 100%;
  position: fixed; inset: 0; overflow: hidden;
  background: var(--navy); color: var(--cream);
  font-family: var(--font);
  overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}

canvas#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }
button { font-family: inherit; color: inherit; border: 0; cursor: pointer; touch-action: none; }
kbd { font-family: inherit; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; inset: 0; pointer-events: none;
  padding: calc(8px + var(--st)) calc(10px + var(--sr)) 0 calc(10px + var(--sl));
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 8px;
}
#hud > * { pointer-events: auto; }
.hud-left { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; min-width: 0; }
.hud-mid { display: flex; gap: 8px; justify-self: center; }
.hud-right { display: flex; gap: 8px; justify-self: end; }

.gas {
  display: flex; align-items: center; gap: 8px;
  background: var(--glass); border: 2px solid rgba(255, 244, 220, 0.25);
  border-radius: 999px; padding: 5px 8px 5px 12px;
  width: min(38vw, 250px);
}
.gas-label { font-weight: 800; font-size: 13px; letter-spacing: 0.08em; }
.gas-track { flex: 1; height: 14px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.gas-fill {
  display: block; height: 100%; width: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #7be495, #c9f27b);
  transition: width 0.12s linear;
}
.gas.low .gas-fill { background: linear-gradient(90deg, #ffb347, var(--gold)); }
.gas.empty { border-color: var(--red); animation: pulse-red 0.6s infinite alternate; }
.gas.empty .gas-fill { background: var(--red); }
@keyframes pulse-red { to { box-shadow: 0 0 0 4px rgba(226, 59, 74, 0.45); } }

.chip {
  font-size: 12px; font-weight: 800; letter-spacing: 0.04em;
  padding: 3px 10px; border-radius: 999px; background: var(--glass);
  border: 2px solid var(--gold); color: var(--gold);
}
.chip.gentle { border-color: #9be3c0; color: #9be3c0; }

.stat {
  background: var(--glass); border-radius: 999px; padding: 5px 12px;
  font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap;
}

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--glass); border: 2px solid rgba(255, 244, 220, 0.25);
  display: grid; place-items: center; padding: 0;
}
.icon-btn svg { width: 22px; height: 22px; fill: var(--cream); stroke: var(--cream); }
.icon-btn:active { transform: scale(0.92); }

/* ---------- Tutorial tip ---------- */
.tip {
  position: absolute; left: 50%; top: calc(62px + var(--st)); transform: translateX(-50%);
  max-width: min(86vw, 520px); text-align: center; pointer-events: none;
  background: var(--cream); color: var(--ink); font-weight: 800; font-size: 15px; line-height: 1.3;
  padding: 8px 16px; border-radius: 16px; border: 3px solid var(--red);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}

/* ---------- Touch controls ---------- */
#controls { position: absolute; inset: 0; pointer-events: none; }
.pad { position: absolute; bottom: calc(14px + var(--sb)); display: flex; align-items: flex-end; gap: 14px; }
.pad-left { left: calc(16px + var(--sl)); }
.pad-right { right: calc(16px + var(--sr)); }
.ctl {
  pointer-events: auto; position: relative;
  display: grid; place-items: center; border-radius: 50%;
  background: rgba(255, 244, 220, 0.14); border: 3px solid rgba(255, 244, 220, 0.5);
  color: var(--cream); font-weight: 900;
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.ctl svg { width: 34px; height: 34px; fill: var(--cream); }
.ctl.down { transform: scale(0.93); background: rgba(255, 244, 220, 0.32); }
.ctl-rot { width: 76px; height: 76px; }
.ctl-toot {
  width: 112px; height: 112px; font-size: 24px; letter-spacing: 0.06em;
  background: radial-gradient(circle at 35% 30%, #ff7a86, var(--red) 70%);
  border-color: var(--cream); box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}
.ctl-toot.down { background: radial-gradient(circle at 35% 30%, #ff9aa3, #c92b3a 70%); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); }
.ctl-toot.empty { filter: saturate(0.35); }
.ctl-pack { width: 64px; height: 64px; margin-bottom: 70px; margin-right: -8px; border-color: #ffb347; }
.ctl-pack .frond { fill: #5fd38d; }
.ctl-pack .root { fill: #ff9838; }
.ctl-pack span {
  position: absolute; right: -6px; top: -6px; min-width: 24px; height: 24px; padding: 0 4px;
  border-radius: 12px; background: var(--cream); color: var(--ink); font-size: 14px; line-height: 24px;
}
.ctl-pack.none { opacity: 0.4; }
.ctl-pack.urgent { animation: pack-pulse 0.5s infinite alternate; }
@keyframes pack-pulse { to { transform: scale(1.14); box-shadow: 0 0 0 6px rgba(255, 179, 71, 0.4); } }

.ctl kbd {
  display: none; position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%);
  font-size: 11px; font-weight: 800; opacity: 0.75; letter-spacing: 0.06em; white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) {
  .ctl kbd { display: block; }
  .pad { bottom: calc(30px + var(--sb)); }
  .ctl-rot { width: 60px; height: 60px; }
  .ctl-toot { width: 92px; height: 92px; font-size: 20px; }
  .ctl-pack { width: 56px; height: 56px; margin-bottom: 56px; }
}
@media (max-height: 380px) {
  .ctl-rot { width: 68px; height: 68px; }
  .ctl-toot { width: 96px; height: 96px; font-size: 21px; }
  .ctl-pack { width: 58px; height: 58px; margin-bottom: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  .gas.empty, .ctl-pack.urgent { animation: none; }
  .gas-fill { transition: none; }
}

/* ---------- Overlay screens ---------- */
#overlay { position: absolute; inset: 0; display: none; }
#overlay.open {
  display: grid; place-items: center; overflow-y: auto; touch-action: pan-y;
  padding: calc(12px + var(--st)) calc(14px + var(--sr)) calc(12px + var(--sb)) calc(14px + var(--sl));
}
#overlay.dim { background: rgba(7, 11, 31, 0.72); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.card {
  width: min(100%, 460px); background: linear-gradient(180deg, #19214f, #0e1433);
  border: 3px solid rgba(255, 244, 220, 0.28); border-radius: 24px; padding: 18px 20px 20px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55); text-align: center;
}
.card.wide { width: min(100%, 720px); }
.card h2 { margin: 0 0 2px; font-size: clamp(24px, 5vw, 34px); color: var(--gold); letter-spacing: 0.02em; }
.card .sub { margin: 0 0 12px; opacity: 0.8; font-size: 15px; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.btn {
  min-height: 48px; min-width: 110px; padding: 10px 20px; border-radius: 999px;
  background: rgba(255, 244, 220, 0.12); border: 2px solid rgba(255, 244, 220, 0.45);
  font-size: 17px; font-weight: 800; touch-action: manipulation;
}
.btn.primary { background: var(--red); border-color: var(--cream); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35); }
.btn:active { transform: translateY(2px); }
.btn:focus-visible, .toggle:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.settings { display: grid; gap: 8px; text-align: left; }
.toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 52px; padding: 8px 12px 8px 14px; border-radius: 16px;
  background: rgba(255, 255, 255, 0.07); border: 2px solid transparent; touch-action: manipulation;
}
.toggle-text { display: grid; text-align: left; }
.toggle-text b { font-size: 16px; }
.toggle-text small { opacity: 0.7; font-size: 12.5px; }
.toggle-knob { flex: none; width: 52px; height: 30px; border-radius: 999px; background: rgba(255, 255, 255, 0.2); position: relative; transition: background 0.15s; }
.toggle-knob::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--cream); transition: transform 0.15s;
}
.toggle[aria-checked="true"] .toggle-knob { background: var(--green); }
.toggle[aria-checked="true"] .toggle-knob::after { transform: translateX(22px); }
@media (prefers-reduced-motion: reduce) { .toggle-knob, .toggle-knob::after { transition: none; } }

.tip.pop { animation: tip-pop 0.35s ease-out; }
@keyframes tip-pop { from { transform: translateX(-50%) scale(0.8); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

/* ---------- Title ---------- */
#overlay.clear { place-items: stretch; }
.title { display: flex; flex-direction: column; justify-content: space-between; align-items: center; text-align: center; min-height: 100%; gap: 12px; }
.logo { position: relative; margin-top: clamp(4px, 4vh, 40px); }
.logo h1 {
  margin: 0; font-size: clamp(38px, 10.5vw, 96px); line-height: 0.95; letter-spacing: 0.03em; font-weight: 900;
  color: var(--gold); text-shadow: 0 4px 0 #c0392b, 0 8px 0 rgba(0, 0, 0, 0.45), 0 0 34px rgba(255, 209, 102, 0.45);
  transform: rotate(-3deg);
}
.logo h1 span { display: inline-block; }
.logo h1 span:last-child { color: var(--cream); }
.logo-star {
  position: absolute; right: -4%; top: -30%; font-size: clamp(30px, 7vw, 64px); color: var(--gold);
  text-shadow: 0 0 24px rgba(255, 209, 102, 0.9); animation: star-spin 6s linear infinite;
}
@keyframes star-spin { to { transform: rotate(360deg); } }
.tagline { margin: 12px 0 0; font-style: italic; font-weight: 700; font-size: clamp(13px, 2.4vw, 18px); opacity: 0.92; text-shadow: 0 2px 6px #000; }
.title-actions { display: grid; gap: 10px; justify-items: center; margin-bottom: clamp(4px, 3vh, 30px); }
.btn.big { min-width: 190px; min-height: 58px; font-size: 22px; letter-spacing: 0.04em; }
.row.tight { margin-top: 0; }

/* ---------- Intro comic ---------- */
.comic { width: min(100%, 620px); display: grid; gap: 10px; justify-items: center; }
.panel {
  position: relative; width: min(100%, calc((100vh - 190px) * 16 / 9)); min-width: 240px;
  border: 5px solid var(--cream); border-radius: 10px; overflow: hidden;
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.5); transform: rotate(-1deg); background: var(--navy);
}
.panel canvas { display: block; width: 100%; height: auto; }
.panel-no { position: absolute; top: 6px; left: 8px; background: var(--cream); color: var(--ink); font-weight: 900; font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.caption {
  margin: 0; background: #fff6c9; color: var(--ink); font-weight: 800; font-size: clamp(14px, 2.4vw, 18px); line-height: 1.3;
  padding: 8px 14px; border: 3px solid var(--ink); border-radius: 6px; box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45); text-align: center; max-width: 560px;
}
.comic .row { margin-top: 2px; }

/* ---------- Course select + briefing ---------- */
.courses { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; text-align: left; }
.course {
  display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 8px 12px; border-radius: 16px;
  background: rgba(255, 255, 255, 0.08); border: 2px solid rgba(255, 244, 220, 0.3); touch-action: manipulation; text-align: left;
}
.course:not(.locked):active { transform: scale(0.98); }
.course-no { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--red); font-weight: 900; font-size: 18px; }
.course-text { display: grid; min-width: 0; }
.course-text b { font-size: 16px; }
.course-text small { opacity: 0.75; font-size: 12.5px; }
.course.locked { opacity: 0.45; cursor: default; }
.course.locked .course-no { background: rgba(255, 255, 255, 0.2); }
.eyebrow { margin: 0 0 2px; font-size: 12.5px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: #9be3c0; }
.idea { margin: 0 0 10px; font-weight: 800; color: var(--cream); }
.fact { display: grid; gap: 2px; text-align: left; background: rgba(47, 191, 113, 0.14); border: 2px dashed rgba(155, 227, 192, 0.6); border-radius: 14px; padding: 8px 12px; font-size: 14px; line-height: 1.35; }
.fact b { color: #9be3c0; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; }
.keys { margin: 10px 0 0; font-size: 12.5px; opacity: 0.75; }

/* ---------- Results ---------- */
.results .pun { font-size: clamp(28px, 6.5vw, 46px); transform: rotate(-2deg); text-shadow: 0 3px 0 #c0392b; margin: 2px 0 8px; }
.ladder { display: flex; flex-wrap: wrap; gap: 4px 6px; justify-content: center; align-items: center; font-size: 13px; font-weight: 800; margin-bottom: 10px; }
.ladder span { padding: 3px 9px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); opacity: 0.55; }
.ladder span.past { opacity: 0.8; }
.ladder span.on { background: var(--gold); color: var(--ink); opacity: 1; transform: scale(1.12); box-shadow: 0 0 16px rgba(255, 209, 102, 0.6); }
.ladder i { opacity: 0.4; font-style: normal; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat-cell { background: rgba(255, 255, 255, 0.07); border-radius: 12px; padding: 6px 4px; display: grid; }
.stat-cell small { font-size: 11.5px; opacity: 0.75; }
.stat-cell b { font-size: 19px; font-variant-numeric: tabular-nums; }
.eff { margin: 10px 0 0; font-weight: 800; font-size: 15px; }
.eff small { opacity: 0.7; font-weight: 600; }
.stars { color: var(--gold); letter-spacing: 2px; font-size: 18px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; }
.badges span { font-size: 12px; font-weight: 800; padding: 3px 10px; border-radius: 999px; border: 2px solid #9be3c0; color: #9be3c0; }
.best { margin: 8px 0 0; font-weight: 800; color: var(--gold); font-size: 14px; }
.results .tagline { font-size: 12.5px; opacity: 0.7; margin-top: 10px; }
.more { margin: 10px 0 0 !important; font-size: 12.5px !important; }

@media (max-height: 420px) {
  .card { padding: 10px 16px 12px; }
  .card h2 { font-size: 22px; }
  .card .sub { margin-bottom: 6px; font-size: 13px; }
  .row { margin-top: 8px; }
  .toggle { min-height: 46px; padding: 4px 12px; }
  .settings { grid-template-columns: repeat(3, 1fr); }
  .toggle-text small { display: none; }
  .results .pun { font-size: 26px; margin-bottom: 4px; }
  .stats { grid-template-columns: repeat(6, 1fr); }
  .stat-cell b { font-size: 16px; }
  .results .tagline, .keys { display: none; }
  .ladder { margin-bottom: 6px; }
  .btn.big { min-height: 50px; font-size: 19px; }
  .logo h1 { font-size: clamp(34px, 9vw, 60px); }
  .tagline { margin-top: 6px; }
  .tip { top: calc(54px + var(--st)); font-size: 13px; padding: 5px 12px; }
}
@media (prefers-reduced-motion: reduce) { .logo-star, .tip.pop { animation: none; } }

/* Narrow (portrait) screens: stats drop to a second HUD row so the gas meter stays readable. */
@media (max-width: 520px) {
  #hud { grid-template-columns: 1fr auto; }
  .hud-mid { grid-row: 2; grid-column: 1 / -1; justify-self: start; }
  .hud-right { grid-row: 1; grid-column: 2; }
  .gas { width: min(56vw, 250px); }
  .tip { top: calc(104px + var(--st)); }
}

/* ---------- Burp brake button ---------- */
.ctl-brake {
  width: 76px; height: 76px; font-size: 17px; line-height: 1; letter-spacing: 0.04em;
  background: radial-gradient(circle at 35% 30%, #a8e4ff, #3f8fd6 72%); border-color: var(--cream);
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.ctl-brake small { font-size: 11px; font-weight: 800; opacity: 0.85; text-transform: uppercase; letter-spacing: 0.08em; }
.ctl-brake.down { background: radial-gradient(circle at 35% 30%, #c8efff, #2f78bd 72%); }
@media (hover: hover) and (pointer: fine) { .ctl-brake { width: 62px; height: 62px; font-size: 14px; } }
@media (max-height: 380px) { .ctl-brake { width: 66px; height: 66px; font-size: 15px; } }

/* ---------- Hidden tuning panel ---------- */
.tune {
  position: fixed; z-index: 50; top: calc(60px + var(--st)); left: calc(10px + var(--sl));
  width: min(320px, calc(100vw - 20px)); max-height: calc(100vh - 80px); overflow-y: auto; touch-action: pan-y;
  background: rgba(8, 12, 34, 0.94); border: 2px solid var(--gold); border-radius: 16px; padding: 10px 12px 12px;
  font-size: 13px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.tune-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; color: var(--gold); font-size: 15px; }
.tune-x { width: 36px; height: 36px; border-radius: 50%; background: rgba(255, 255, 255, 0.1); font-size: 20px; line-height: 1; }
.tune-row { display: grid; gap: 2px; margin: 8px 0; }
.tune-row span { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.tune-row output { color: var(--gold); font-variant-numeric: tabular-nums; }
.tune-row input { width: 100%; accent-color: var(--red); touch-action: pan-x; height: 28px; }
.tune-btns { display: flex; gap: 8px; margin-top: 10px; }
.tune-btns button { flex: 1; min-height: 40px; border-radius: 999px; background: var(--red); font-weight: 800; touch-action: manipulation; }
.tune-btns button + button { background: rgba(255, 255, 255, 0.12); }
.tune-copy { width: 100%; height: 150px; margin-top: 8px; font: 12px ui-monospace, Consolas, monospace; background: #000; color: #9be3c0; border-radius: 8px; border: 0; padding: 6px; user-select: text; -webkit-user-select: text; }
.tune-note { margin: 8px 0 0; opacity: 0.6; font-size: 11.5px; }
.tune-toggle {
  position: fixed; z-index: 51; left: 50%; transform: translateX(-50%); bottom: calc(6px + var(--sb));
  min-height: 36px; padding: 4px 14px; border-radius: 999px; background: rgba(8, 12, 34, 0.85); border: 2px solid var(--gold);
  color: var(--gold); font-weight: 900; font-size: 13px; letter-spacing: 0.08em; touch-action: manipulation;
}

/* ---------- Flow additions ---------- */
.stat.hits { color: #ffb3b3; }
.btn .count {
  display: inline-grid; place-items: center; min-width: 26px; height: 26px; margin-left: 10px; padding: 0 6px;
  border-radius: 999px; background: rgba(255, 244, 220, 0.25); font-size: 15px; vertical-align: middle;
}
.finale { margin: 0 0 10px; font-weight: 800; font-size: 16px; color: #9be3c0; }
.results.failed .finale { color: #ffb3b3; }
.results.failed .pun { text-shadow: 0 3px 0 #5a3496; }

/* ---------- Splash ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.title { justify-content: flex-end; }
.btn.huge {
  min-width: min(300px, 80vw); min-height: 76px; padding: 10px 34px; font-size: clamp(26px, 5vw, 34px); letter-spacing: 0.05em;
  border: 4px solid var(--cream); line-height: 1.05; display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(circle at 35% 25%, #ff7a86, var(--red) 65%);
  box-shadow: 0 7px 0 #8f1f2b, 0 0 0 6px rgba(255, 209, 102, 0.25), 0 12px 30px rgba(0, 0, 0, 0.5);
  animation: play-glow 1.6s ease-in-out infinite alternate;
}
.btn.huge small { font-size: 0.48em; letter-spacing: 0.03em; opacity: 0.9; font-weight: 800; }
.btn.huge:active { transform: translateY(4px); box-shadow: 0 3px 0 #8f1f2b, 0 0 0 6px rgba(255, 209, 102, 0.25); }
@keyframes play-glow { to { box-shadow: 0 7px 0 #8f1f2b, 0 0 0 10px rgba(255, 209, 102, 0.4), 0 12px 34px rgba(0, 0, 0, 0.5); } }
.btn.sec {
  min-height: 52px; min-width: 120px; font-size: 17px; padding: 8px 18px;
  background: rgba(14, 20, 51, 0.78); border: 2px solid rgba(255, 244, 220, 0.6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.title-actions { gap: 12px; }
.title .secondary { gap: 8px; }
@media (max-height: 480px) and (orientation: landscape) {
  .title { align-items: flex-end; }
  .title-actions { width: min(58vw, 460px); margin-right: 2vw; }
  .btn.huge { min-height: 60px; font-size: 26px; }
  .btn.sec { min-height: 46px; min-width: 0; font-size: 15px; padding: 6px 12px; }
}
@media (max-width: 520px) {
  .title .secondary { display: grid; grid-template-columns: 1fr 1fr; width: min(100%, 360px); }
  .btn.sec { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) { .btn.huge { animation: none; } }

/* ---------- Tootorial tip ---------- */
.tip-step { display: block; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--red); margin-bottom: 1px; }

/* ---------- How to Play ---------- */
.card.howto { width: min(100%, 820px); text-align: left; }
.howto h2 { text-align: center; font-size: clamp(22px, 4.4vw, 32px); }
.howto .eyebrow { text-align: center; }
.goal-line { text-align: center; margin: 4px 0 12px; font-size: 15px; }
.goal-line b { color: var(--gold); }
.howto-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.howto-grid section { background: rgba(255, 255, 255, 0.05); border-radius: 18px; padding: 10px 12px; }
.howto-grid h3 { margin: 0 0 6px; font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: #9be3c0; }
.ctl-row, .thing { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.ctl-row b, .thing b { display: block; font-size: 15.5px; }
.ctl-row small, .thing small, .gas-note { display: block; font-size: 12.5px; opacity: 0.8; line-height: 1.3; }
.ctl-keys { flex: none; width: 128px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; justify-content: center; }
.ctl-keys i { font-size: 11px; opacity: 0.6; font-style: normal; }
.key {
  display: inline-grid; place-items: center; min-width: 34px; height: 34px; padding: 0 6px; border-radius: 8px;
  background: linear-gradient(#f4ecdc, #d9ccb3); color: var(--ink); font-weight: 900; font-size: 15px;
  box-shadow: 0 3px 0 #8f8573, inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}
.key.wide { min-width: 74px; font-size: 12px; letter-spacing: 0.06em; }
.pad-icon {
  display: inline-grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; font-weight: 900; font-size: 12px;
  border: 2px solid var(--cream); background: rgba(255, 244, 220, 0.16);
}
.pad-icon.rot { font-size: 18px; }
.pad-icon.toot { width: 58px; height: 58px; background: radial-gradient(circle at 35% 30%, #ff7a86, var(--red) 70%); }
.pad-icon.burp { width: 52px; height: 52px; background: radial-gradient(circle at 35% 30%, #a8e4ff, #3f8fd6 72%); }
.pad-icon.pack { border-color: #ffb347; font-size: 20px; }
.gas-demo { display: flex; align-items: center; gap: 8px; margin: 10px 0 4px; background: var(--glass); border: 2px solid rgba(255, 244, 220, 0.25); border-radius: 999px; padding: 4px 10px; }
.thing canvas { flex: none; width: 52px; height: 52px; }
@media (max-width: 640px) { .howto-grid { grid-template-columns: 1fr; } }
@media (max-height: 420px) {
  .howto h2 { font-size: 20px; }
  .ctl-row, .thing { margin: 3px 0; }
  .thing canvas { width: 40px; height: 40px; }
  .ctl-row small, .thing small { font-size: 11.5px; }
}
.ctl-keys .br { flex-basis: 100%; height: 0; }

/* ---------- Reindeer fact corner panel ---------- */
#overlay.open { grid-auto-rows: auto; align-content: center; gap: 10px; }
.fact-corner {
  justify-self: center; width: min(100%, 460px); display: grid; gap: 1px;
  background: rgba(14, 20, 51, 0.82); border: 2px dashed rgba(155, 227, 192, 0.55); border-radius: 14px;
  padding: 6px 12px; font-size: 12.5px; line-height: 1.35; opacity: 0.9;
}
.fact-corner b { color: #9be3c0; font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; }
@media (min-width: 1000px) and (min-height: 560px) {
  .fact-corner { position: fixed; left: calc(16px + var(--sl)); bottom: calc(16px + var(--sb)); width: 260px; }
}

/* ---------- Course card ---------- */
.card.course-card {
  width: min(100%, 860px); display: grid; grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr); gap: 18px;
  align-items: center; text-align: left; padding: 18px;
}
.cc-art canvas, .res-art canvas {
  display: block; width: 100%; height: auto; border-radius: 18px; border: 4px solid var(--cream);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.45); transform: rotate(-1.2deg); background: var(--navy);
}
.course-card.boss .cc-art canvas { border-color: var(--gold); }
.cc-info h2 { font-size: clamp(28px, 5vw, 42px); margin-bottom: 4px; }
.cc-goal { margin: 0 0 10px; font-size: 16px; font-weight: 700; line-height: 1.35; }
.objectives { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.objectives li { display: flex; align-items: center; gap: 10px; background: rgba(255, 255, 255, 0.06); border-radius: 12px; padding: 3px 10px 3px 4px; font-weight: 700; font-size: 14.5px; }
.objectives canvas { flex: none; width: 40px; height: 40px; }
.cc-meta { margin: 10px 0 0; font-size: 13.5px; font-weight: 800; color: var(--gold); }
.course-card .row { justify-content: flex-start; }

/* ---------- End card ---------- */
.card.results.with-art { width: min(100%, 880px); display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); gap: 18px; align-items: center; }
.res-art canvas { transform: rotate(1.5deg); }
.results.failed .res-art canvas { border-color: #ffb3b3; }

@media (max-width: 700px) {
  .card.course-card, .card.results.with-art { grid-template-columns: 1fr; gap: 10px; }
  .cc-art, .res-art { max-width: 360px; justify-self: center; width: 100%; }
  .course-card .row { justify-content: center; }
}
@media (max-height: 480px) and (min-width: 701px) {
  .card.course-card, .card.results.with-art { padding: 12px 14px; gap: 12px; }
  .cc-info h2 { font-size: 26px; }
  .cc-goal { font-size: 13.5px; margin-bottom: 6px; }
  .objectives li { font-size: 12.5px; padding: 1px 8px 1px 2px; }
  .objectives canvas { width: 30px; height: 30px; }
  .cc-meta { margin-top: 6px; }
}
@media (max-height: 480px) and (max-width: 700px) { .cc-art, .res-art { display: none; } }

/* Short landscape phones: keep course and end cards on one screen. */
@media (max-height: 480px) and (min-width: 701px) {
  #overlay.open { padding-top: calc(6px + var(--st)); padding-bottom: calc(6px + var(--sb)); }
  .card.course-card { grid-template-columns: minmax(0, 0.72fr) minmax(0, 1.28fr); }
  .card.results.with-art { grid-template-columns: minmax(0, 0.55fr) minmax(0, 1.45fr); padding: 10px 14px; }
  .course-card .cc-goal { display: none; }
  .course-card .eyebrow, .results .eyebrow { margin-bottom: 0; font-size: 11px; }
  .cc-info h2 { font-size: 24px; }
  .course-card .row, .results .row { flex-wrap: nowrap; margin-top: 8px; gap: 8px; }
  .course-card .btn, .results .btn { min-height: 44px; min-width: 0; padding: 6px 14px; font-size: 15px; }
  .course-card .btn.big, .results .btn.big { font-size: 17px; min-width: 0; }
  .results .pun { font-size: 24px; margin: 0 0 4px; }
  .results .finale { font-size: 13px; margin-bottom: 4px; }
  .results .ladder { margin-bottom: 4px; font-size: 11.5px; }
  .results .eff { margin-top: 4px; font-size: 13px; }
  .results .badges { margin-top: 4px; }
  .results .best { margin-top: 4px; font-size: 12.5px; }
  .results .tagline { display: none; }
  .stats { grid-template-columns: repeat(6, 1fr); }
  .stat-cell small { font-size: 10px; }
  .stat-cell b { font-size: 15px; }
  .fact-corner { display: none; }
}

/* Centre overlay screens when they fit, but scroll from the very top when they don't (grid centring clipped tall cards). */
#overlay.open { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#overlay.open > :first-child { margin-top: auto; }
#overlay.open > :last-child { margin-bottom: auto; }
#overlay.open > .card, #overlay.open > .comic { flex: none; }
#overlay.clear > .title { flex: 1 0 auto; width: 100%; align-self: stretch; }
.results .btn { white-space: nowrap; }
@media (max-height: 480px) and (min-width: 701px) {
  .results .btn { padding: 6px 11px; font-size: 14px; }
}

/* ---------- In-game sound quick toggles ---------- */
.quick {
  position: absolute; right: calc(10px + var(--sr)); top: calc(60px + var(--st));
  display: flex; flex-direction: column; gap: 8px;
}
.quick-btn {
  position: relative; width: 64px; height: 58px; border-radius: 18px; padding: 2px 0 0;
  display: grid; place-items: center; align-content: center; gap: 0;
  background: var(--glass); border: 2px solid rgba(255, 244, 220, 0.55); touch-action: manipulation;
}
.quick-btn span { font-size: 24px; line-height: 1; }
.quick-btn small { font-size: 11px; font-weight: 900; letter-spacing: 0.04em; }
.quick-btn:active { transform: scale(0.94); }
.quick-btn.off { opacity: 0.6; border-color: rgba(255, 244, 220, 0.25); }
.quick-btn.off::after {
  content: ""; position: absolute; left: 10px; right: 10px; top: 50%; height: 4px; border-radius: 2px;
  background: var(--red); transform: rotate(-35deg); box-shadow: 0 0 0 2px rgba(7, 11, 31, 0.7);
}
.quick-btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
@media (max-width: 520px) {
  .quick { top: calc(104px + var(--st)); }
  .tip { max-width: calc(100vw - 110px); left: calc(50% - 38px); }
}
@media (max-height: 380px) { .quick-btn { width: 56px; height: 50px; } .quick-btn span { font-size: 20px; } }

/* ---------- Full tooting experience ---------- */
.experience { width: min(100%, 760px); display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; }
.experience canvas { width: min(100%, 440px); height: auto; }
.experience h2 { margin: 0; font-size: clamp(28px, 6vw, 48px); color: var(--gold); text-shadow: 0 4px 0 #c0392b, 0 8px 18px rgba(0, 0, 0, 0.5); line-height: 1.1; }
.experience .sub { margin: 4px 0 10px; font-size: clamp(14px, 2.4vw, 18px); opacity: 0.85; max-width: 560px; }
.exp-choices { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; align-items: center; }
.btn.exp-polite {
  min-height: 76px; min-width: min(280px, 80vw); padding: 10px 26px; font-size: clamp(19px, 3.6vw, 24px);
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1;
  background: rgba(14, 20, 51, 0.8); border: 3px solid rgba(255, 244, 220, 0.7);
}
.exp-choices small { font-size: 0.55em; font-weight: 800; opacity: 0.85; letter-spacing: 0.02em; }
@media (max-height: 480px) {
  .experience canvas { width: min(60%, 300px); }
  .experience h2 { font-size: 26px; }
  .btn.exp-polite, .exp-choices .btn.huge { min-height: 58px; }
}
.nowrap { white-space: nowrap; }

/* ---------- Display font for big titles ---------- */
.experience h2, .cc-info h2, .results .pun, .howto h2 {
  font-family: "Luckiest Guy", var(--font); font-weight: 400; letter-spacing: 0.03em;
}
.experience h2, .cc-info h2, .results .pun { line-height: 1.05; }

/* ---------- Full-size course cards (refinement 2) ---------- */
.card.course-card {
  --u: clamp(16px, 0.9vw + 1.2vh, 28px);
  font-size: var(--u);
  width: min(88vw, 1500px); min-height: min(84vh, 1000px);
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: clamp(18px, 3.5vw, 56px);
  padding: clamp(18px, 3vw, 48px); align-content: center; align-items: center;
}
.cc-art { display: flex; flex-direction: column; gap: 1.1em; align-self: center; }
.cc-info .eyebrow { font-size: 0.85em; margin-bottom: 0.2em; }
.cc-info h2 { font-size: 3.2em; margin: 0 0 0.25em; }
.course-card .cc-goal { font-size: 1.15em; margin: 0 0 0.9em; line-height: 1.35; }
.course-card .objectives { gap: 0.45em; }
.course-card .objectives li { font-size: 1em; padding: 0.35em 0.9em 0.35em 0.35em; gap: 0.7em; border-radius: 0.8em; }
.course-card .objectives canvas { width: 2.6em; height: 2.6em; }
.course-card .cc-meta { font-size: 0.95em; margin-top: 0.9em; }
.course-card .row { margin-top: 1.2em; gap: 0.7em; justify-content: flex-start; }
.course-card .btn { min-height: 2.9em; font-size: 1em; padding: 0 1.3em; }
.course-card .btn.big { font-size: 1.35em; min-height: 2.5em; min-width: 7em; }
.course-card .fact-corner { position: static; width: auto; justify-self: auto; font-size: 0.78em; transform: rotate(-1deg); }
/* Results: the fixed fact panel no longer drags the card to the bottom on big screens. */
@media (min-width: 1000px) and (min-height: 560px) { #overlay.open > .card { margin-bottom: auto; } }

@media (max-width: 700px) { /* phones held upright: the card is the whole screen */
  .card.course-card {
    --u: clamp(15px, 4.1vw, 19px);
    width: 100%; min-height: calc(100vh - 24px); min-height: calc(100dvh - 24px);
    grid-template-columns: 1fr; align-content: start; gap: 12px; padding: 16px;
  }
  .cc-art { max-width: 480px; width: 100%; justify-self: center; }
  .cc-info h2 { font-size: 2.3em; }
  .course-card .row { justify-content: stretch; }
  .course-card .btn { flex: 1 1 auto; }
  .course-card .btn.big { flex-basis: 100%; }
}
@media (max-height: 480px) and (min-width: 701px) { /* phones held sideways */
  .card.course-card {
    --u: clamp(12px, 3.3vh, 16px);
    width: 96vw; min-height: 90vh; padding: 12px 18px; gap: 18px;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  }
  .cc-info h2 { font-size: 2.3em; }
  .course-card .cc-goal, .course-card .fact-corner { display: none; }
  .course-card .objectives li { padding: 0.15em 0.7em 0.15em 0.2em; }
  .course-card .objectives canvas { width: 2.2em; height: 2.2em; }
  .course-card .row { margin-top: 0.7em; }
  .course-card .btn { min-height: 44px; font-size: 1.05em; }
  .course-card .btn.big { min-height: 48px; font-size: 1.3em; min-width: 0; }
}
@media (max-width: 700px) {
  .course-card .cc-art { display: contents; } /* picture first, then the info, fact at the very bottom */
  .course-card .cc-art canvas { width: min(100%, calc(25vh * 1.45), 460px); justify-self: center; }
  .course-card .cc-info { order: 1; }
  .course-card .fact-corner { order: 2; }
  .course-card .cc-goal { font-size: 1em; margin-bottom: 0.6em; }
  .course-card .objectives li { padding: 0.25em 0.7em 0.25em 0.25em; }
  .course-card .objectives canvas { width: 2.3em; height: 2.3em; }
}
