/* ==========================================================================
   SWITCH 'N SPELL -- bright, modern "sunny rail yard" theme
   ========================================================================== */

:root {
  --ink: #2B2320;
  --cream: #FFF8E9;
  --cream-dim: #F3E6C8;
  --paper: #FFFFFF;
  --red: #E0453A;
  --red-dark: #B5352C;
  --gold: #FFC94A;
  --gold-dark: #E8A72C;
  --green: #3FAE68;
  --green-dark: #2C8A50;
  --blue: #4A90E2;
  --blue-dark: #366FB8;
  --purple: #6C63C6;
  --pink: #EF6FA7;
  --sky-top: #5EC9F2;
  --sky-bot: #DFF4FF;
  --shadow: rgba(30, 25, 15, 0.22);
  --shadow-strong: rgba(30, 25, 15, 0.35);
  --font-display: "Baloo 2", ui-rounded, "Segoe UI", sans-serif;
  --font-body: "Nunito", "Segoe UI", sans-serif;
  --radius-lg: 26px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background:
    radial-gradient(ellipse 60% 40% at 15% 12%, rgba(255,255,255,0.85), transparent 60%),
    radial-gradient(ellipse 50% 30% at 85% 8%, rgba(255,255,255,0.7), transparent 60%),
    linear-gradient(to bottom, var(--sky-top) 0%, var(--sky-bot) 55%, #CDEFC9 100%);
  background-attachment: fixed;
}

button { font-family: inherit; }

/* ---------------------------------------------------------------------- */
/* Screen panels                                                          */
/* ---------------------------------------------------------------------- */

#app {
  position: relative;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* The game and how-to-play screens hold the canvas-drawn track, and the
   whole track always has to fit on screen at once (no scrolling) -- so
   unlike the text screens, they benefit from every extra pixel of width
   the viewport can offer. Letting #app grow well past the normal 960px
   card width on these two screens gives fitGridToViewport() a much
   bigger box to scale the canvas into, which is what actually makes the
   letters on the cars legible. min()/vw keep it self-limiting: it never
   gets wider than the viewport, and the canvas itself only ever grows to
   whichever of width/height is the tighter fit, so this can't push the
   canvas off-screen or introduce scrollbars. */
body[data-screen="gameScreen"] #app,
body[data-screen="howtoScreen"] #app {
  max-width: min(1700px, 98vw);
}

.screen-panel {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 12px;
}
.screen-panel.active { display: block; }
#gameScreen.screen-panel, #howtoScreen.screen-panel { padding: 4px; }

.panel-card {
  position: relative;
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: 0 18px 40px var(--shadow), 0 2px 0 rgba(255,255,255,0.6) inset;
  padding: 22px;
  overflow: hidden;
  min-height: calc(100vh - 24px);
  min-height: calc(100dvh - 24px);
  display: flex;
  flex-direction: column;
}
.panel-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 10px;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--green), var(--blue), var(--purple), var(--pink));
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                */
/* ---------------------------------------------------------------------- */

.btn {
  background: var(--cream);
  border: none;
  color: var(--ink);
  padding: 13px 22px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.01em;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--cream-dim), 0 6px 14px var(--shadow);
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 5px 0 var(--cream-dim), 0 10px 18px var(--shadow); }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--cream-dim), 0 3px 8px var(--shadow); }
.btn-primary {
  background: linear-gradient(180deg, var(--red) 0%, var(--red-dark) 100%);
  color: var(--cream);
  box-shadow: 0 3px 0 #8A241D, 0 8px 18px rgba(224,69,58,0.4);
}
.btn-primary:hover { box-shadow: 0 5px 0 #8A241D, 0 12px 22px rgba(224,69,58,0.45); }
.btn-primary:active { box-shadow: 0 1px 0 #8A241D, 0 4px 10px rgba(224,69,58,0.4); }
.btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* ---------------------------------------------------------------------- */
/* Persistent audio controls (upper-right, on top of every screen)        */
/* ---------------------------------------------------------------------- */

.audio-controls {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  z-index: 1000;
  display: flex;
  gap: 8px;
}

.mute-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  border-radius: 50%;
  background: var(--paper);
  border: none;
  color: var(--blue-dark);
  cursor: pointer;
  box-shadow: 0 4px 10px var(--shadow);
  transition: transform 120ms ease, box-shadow 120ms ease, color 120ms ease;
}
[data-audio-btn="sfx"] { font-size: 0.65rem; font-weight: 800; letter-spacing: 0.02em; }
.mute-btn:hover { transform: translateY(-1px) scale(1.05); box-shadow: 0 6px 14px var(--shadow); }
.mute-btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.mute-btn.is-muted { color: #A9A398; }
.mute-btn.is-muted span { position: relative; }
.mute-btn.is-muted span::after {
  content: "";
  position: absolute;
  left: -6px;
  right: -6px;
  top: 50%;
  border-top: 3px solid var(--red);
  transform: rotate(-45deg);
}

body[data-screen="gameScreen"] .audio-controls { display: none; }

.in-game-audio-controls {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 3;
  display: flex;
  gap: 6px;
}
.mute-btn-compact { width: 28px; height: 28px; font-size: 0.85rem; box-shadow: 0 2px 6px var(--shadow); }
[data-audio-btn="sfx"].mute-btn-compact { font-size: 0.6rem; }

@media (max-width: 480px) {
  .audio-controls { top: calc(env(safe-area-inset-top, 0px) + 8px); right: calc(env(safe-area-inset-right, 0px) + 8px); gap: 6px; }
  .mute-btn { width: 36px; height: 36px; font-size: 1rem; }
  [data-audio-btn="sfx"] { font-size: 0.55rem; }
}

.title-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}

/* ---------------------------------------------------------------------- */
/* Title screen                                                           */
/* ---------------------------------------------------------------------- */

.title-frame { justify-content: center; align-items: center; text-align: center; }
.title-content { position: relative; z-index: 2; max-width: 680px; width: 100%; }

.hero-train {
  width: 100%;
  height: clamp(70px, 16vw, 130px);
  margin-bottom: 10px;
}
.hero-canvas { display: block; width: 100%; height: 100%; }

.tagline { font-family: var(--font-display); font-size: 1.15rem; color: var(--blue-dark); margin: 4px 0; font-weight: 700; }
.credit { font-size: 0.85rem; color: #8A8072; line-height: 1.6; margin-top: 10px; }
.footnote { font-size: 0.75rem; color: #8A8072; margin-top: 24px; }

/* ---------------------------------------------------------------------- */
/* How-to / word entry text screens                                       */
/* ---------------------------------------------------------------------- */

.wordentry-content { max-width: 680px; margin: 0 auto; position: relative; z-index: 2; width: 100%; }
/* .howto-content itself is NOT width-capped -- it's allowed to use the
   whole (now-widened) card so .tutorial-demo can stretch full width.
   The reading column (heading + .howto-scroll) gets its own 680px cap
   below so the paragraphs stay a comfortable line length. */
.howto-content { margin: 0 auto; position: relative; z-index: 2; width: 100%; }

.howto-frame {
  height: calc(100vh - 24px);
  height: calc(100dvh - 24px);
  --game-pad: 6px;
  padding: var(--game-pad);
}
.howto-frame .howto-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.howto-frame .tutorial-demo {
  /* The instructions below are independently scrollable at their own
     min-height, so they don't need a big share of the vertical budget --
     nearly all of it should go to the demo, so its canvas reads at
     roughly the same size as the real game's (see .howto-scroll's much
     smaller flex-grow just below). */
  flex: 20 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.howto-content > h1 { max-width: 680px; margin-left: auto; margin-right: auto; width: 100%; flex-shrink: 0; }
.howto-scroll {
  flex: 1 1 0;
  min-height: 92px;
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  overflow-y: auto;
  padding-right: 6px;
  -webkit-overflow-scrolling: touch;
}
.howto-footer { flex-shrink: 0; margin-top: 10px; padding-top: 10px; border-top: 2px solid var(--cream-dim); }

.howto-content h1, .wordentry-content h1, .end-content h1 {
  font-family: var(--font-display);
  letter-spacing: 0.01em;
  font-size: 1.6rem;
  color: var(--red);
  margin: 0 0 10px;
}
.howto-content p, .wordentry-content p { line-height: 1.6; color: var(--ink); }
.howto-content .example { margin: 14px 0; }
.inverse-sample {
  display: inline-block;
  background: var(--gold);
  color: var(--ink);
  padding: 4px 10px;
  font-weight: 800;
  font-family: var(--font-display);
  border-radius: var(--radius-sm);
  letter-spacing: 0.08em;
}
.key-list { line-height: 2; padding-left: 1.2em; }
.key-list b { color: var(--red); font-family: var(--font-display); }

/* ---------------------------------------------------------------------- */
/* Animated How-To-Play tutorial demo                                     */
/* ---------------------------------------------------------------------- */

.tutorial-demo {
  margin: 8px 0 18px;
  padding: 8px 0;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #EAF7FF, #F7FBEE);
  box-shadow: inset 0 0 0 2px rgba(74,144,226,0.15);
}
.tutorial-viewport {
  display: flex;
  justify-content: center;
  overflow: hidden;
  padding: 2px 0;
  /* .tutorial-demo is now itself a flex column (see .howto-frame
     .tutorial-demo above), so this grows to fill whatever room is
     genuinely left over after the caption/keycaps/heading/footer take
     their natural size -- computed live by the browser instead of a
     guessed vh number, so it can never overflow its card and force a
     scrollbar or get clipped on shorter screens. min-height is just a
     "never fully vanish" floor. */
  flex: 1 1 auto;
  min-height: 90px;
}
.tutorial-caption {
  flex-shrink: 0;
  text-align: center;
  min-height: 2.6em;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue-dark);
  font-weight: 700;
  font-size: clamp(0.9rem, 2.6vw, 1.05rem);
  line-height: 1.4;
  margin: 6px auto 8px;
  max-width: 560px;
}
/* The keycaps reuse the real game's .btn.ctl button styling (see "Game
   screen" section below) so they look identical to the actual on-screen
   controls -- .keycap itself now only adds the bits that are specific to
   this legend: a disabled/inert look-but-don't-touch cursor (these are
   aria-hidden reference labels, not real buttons) and the "this is the
   key being simulated right now" glow while the tutorial plays. */
.key-row {
  display: flex;
  justify-content: center;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 6px;
  flex-shrink: 0;
}
.key-row.digits {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  max-width: 420px;
  margin: 0 auto;
}
.keycap {
  cursor: default;
  pointer-events: none;
}
.key-row .keycap.active {
  color: var(--cream);
  background: linear-gradient(180deg, var(--green), var(--green-dark));
  box-shadow: 0 4px 12px rgba(63,174,104,0.5);
  transform: translateY(-2px) scale(1.06);
}
.hint { color: #8A8072; font-size: 0.9rem; }

.word-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 8px;
}
#wordInput {
  flex: 1;
  background: var(--cream);
  border: 3px solid var(--cream-dim);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  text-transform: uppercase;
  text-align: center;
}
#wordInput:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 4px rgba(74,144,226,0.2); }
.word-error { color: var(--red); min-height: 1.4em; font-size: 0.9rem; font-weight: 700; }

/* ---------------------------------------------------------------------- */
/* Game screen                                                            */
/* ---------------------------------------------------------------------- */

.game-frame { --game-pad: 6px; padding: var(--game-pad); }
.canvas-viewport {
  position: relative;
  z-index: 2;
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  padding: 2px 0;
  /* Bleed past the card's own side padding so the track canvas gets to
     use the full card width, not just the width inside the padding. */
  margin-left: calc(-1 * var(--game-pad, 0px));
  margin-right: calc(-1 * var(--game-pad, 0px));
}
.canvas-host {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}
.game-canvas, .hero-canvas {
  display: block;
  border-radius: var(--radius-md);
}
.game-canvas.shake { animation: canvasShake 400ms ease; }
@keyframes canvasShake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-6px, 2px) rotate(-0.6deg); }
  40% { transform: translate(5px, -2px) rotate(0.6deg); }
  60% { transform: translate(-4px, 1px) rotate(-0.4deg); }
  80% { transform: translate(3px, -1px) rotate(0.4deg); }
}

.game-banner {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%) scale(0.7);
  z-index: 5;
  padding: 14px 28px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1rem, 4vw, 1.6rem);
  letter-spacing: 0.02em;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 12px 30px var(--shadow-strong);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
}
.game-banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); animation: bannerPop 500ms ease; }
.game-banner.banner-derail { background: var(--red); color: var(--cream); }
.game-banner.banner-success { background: var(--gold); color: var(--ink); }
@keyframes bannerPop {
  0% { transform: translate(-50%, -50%) scale(0.6); }
  60% { transform: translate(-50%, -50%) scale(1.12); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

.console {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  margin-top: 4px;
  padding-top: 4px;
}
.status-line {
  text-align: center;
  min-height: 2.6em;
  font-weight: 700;
  font-size: clamp(0.85rem, 2.4vw, 1rem);
  color: var(--blue-dark);
  margin: 2px 0 6px;
}

/* All three button rows live stacked in the SAME grid cell at all times
   (never display:none'd), so #touchControls is always sized to the
   TALLEST of the three -- constant, regardless of which mode is active,
   which keeps the track above it from ever shifting size. */
.touch-controls {
  display: grid;
}
.touch-controls .row-command,
.touch-controls .row-switch,
.touch-controls .row-couple {
  grid-row: 1;
  grid-column: 1;
  visibility: hidden;
  pointer-events: none;
}
.touch-controls.mode-command .row-command,
.touch-controls.mode-switchSelect .row-switch,
.touch-controls.mode-coupleEntry .row-couple,
.touch-controls.mode-decoupleEntry .row-couple {
  visibility: visible;
  pointer-events: auto;
}

.row-command {
  display: flex;
  gap: 7px;
  justify-content: center;
  flex-wrap: wrap;
}
.row-switch { display: flex; gap: 7px; justify-content: center; flex-wrap: wrap; }
.row-couple {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  max-width: 420px;
  margin: 0 auto;
}
.row-couple .ctl.wide { grid-column: 1 / -1; }

.ctl {
  min-width: 58px;
  padding: 8px 10px;
  line-height: 1.15;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 3px 0 var(--cream-dim), 0 5px 10px var(--shadow);
}
.ctl span { display: block; font-size: 0.7rem; letter-spacing: 0.05em; color: var(--blue-dark); opacity: 0.8; }
.ctl.small { min-width: 42px; padding: 7px 6px; }
.ctl.wide { min-width: 100px; }
.ctl[data-action="forward"], .ctl[data-action="reverse"] { background: linear-gradient(180deg, var(--blue), var(--blue-dark)); color: var(--cream); box-shadow: 0 3px 0 #2A578F, 0 6px 12px rgba(74,144,226,0.35); }
.ctl[data-action="forward"] span, .ctl[data-action="reverse"] span { color: var(--cream); opacity: 0.85; }
.ctl[data-action="stop"] { background: linear-gradient(180deg, var(--red), var(--red-dark)); color: var(--cream); box-shadow: 0 3px 0 #8A241D, 0 6px 12px rgba(224,69,58,0.35); }
.ctl[data-action="stop"] span { color: var(--cream); opacity: 0.85; }

.quit-btn {
  display: block;
  margin: 10px auto 0;
  font-size: 0.8rem;
  padding: 6px 14px;
  opacity: 0.75;
}

/* ---------------------------------------------------------------------- */
/* End screen                                                             */
/* ---------------------------------------------------------------------- */

.end-content { max-width: 560px; margin: 0 auto; text-align: center; position: relative; z-index: 2; width: 100%; }
#endTitle { font-family: var(--font-display); font-size: 1.7rem; margin: 6px 0 14px; }
#endTitle.derail-title { color: var(--red); }
#endTitle.success-title { color: var(--gold-dark); }
.end-message { color: var(--ink); line-height: 1.5; font-size: 1.05rem; }
.end-time-block { margin: 18px 0; font-size: 1.2rem; font-weight: 700; }
.record-banner {
  color: var(--gold-dark);
  font-weight: 800;
  font-family: var(--font-display);
  animation: recordPulse 0.9s ease infinite;
}
@keyframes recordPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* ---------------------------------------------------------------------- */
/* New Game: mode select (Campaign vs Single Word)                        */
/* ---------------------------------------------------------------------- */

.mode-cards {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 20px 0;
}
.mode-card-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 18px 20px;
  text-align: left;
}
.mode-card-sub {
  font-family: var(--font-body);
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.82rem;
  font-weight: 600;
  opacity: 0.8;
}

/* ---------------------------------------------------------------------- */
/* Modal overlay (resume-campaign prompt, tamper warning)                 */
/* ---------------------------------------------------------------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(43, 35, 32, 0.55);
  backdrop-filter: blur(3px);
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  width: 100%;
  max-width: 440px;
  min-height: 0;
  padding: 26px;
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}
.modal-content { position: relative; z-index: 2; text-align: center; }
.modal-content h2 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--red);
}
.modal-content p { line-height: 1.6; color: var(--ink); margin: 0 0 6px; }
.modal-content .title-buttons { margin-top: 18px; }

.ios-install-steps { text-align: left; }
.ios-install-steps ol { margin: 10px 0 0; padding-left: 22px; line-height: 1.7; }
.ios-install-steps .share-icon {
  display: inline-flex;
  vertical-align: middle;
  margin-left: 4px;
  color: var(--blue-dark);
}

/* ---------------------------------------------------------------------- */
/* Campaign level badge (game screen)                                     */
/* ---------------------------------------------------------------------- */

.level-badge {
  position: relative;
  z-index: 2;
  text-align: center;
  letter-spacing: 0.04em;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--cream);
  background: linear-gradient(180deg, var(--green), var(--green-dark));
  border-radius: 999px;
  padding: 5px 14px;
  margin: 0 auto 8px;
  width: fit-content;
  box-shadow: 0 3px 8px rgba(63,174,104,0.35);
}
.level-badge #levelBadgeSpeed { font-weight: 600; opacity: 0.9; }

.switch4-hint {
  position: relative;
  z-index: 2;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--blue-dark);
  max-width: 420px;
  margin: 0 auto 8px;
}
.switch4-hint[hidden] { display: none; }

/* ---------------------------------------------------------------------- */
/* Campaign level-progress strip (end screen)                             */
/* ---------------------------------------------------------------------- */

.level-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 16px 0;
}
.level-strip[hidden] { display: none; }
.level-pip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border-radius: 50%;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--cream);
  color: #A9A398;
}
.level-pip.completed {
  color: var(--cream);
  background: linear-gradient(180deg, var(--green), var(--green-dark));
  box-shadow: 0 3px 8px rgba(63,174,104,0.35);
}
.level-pip.current {
  color: var(--ink);
  background: var(--gold);
  box-shadow: 0 3px 10px rgba(255,201,74,0.55);
  animation: recordPulse 0.9s ease infinite;
}

/* ---------------------------------------------------------------------- */
/* Balloons -- mission accomplished celebration                          */
/* ---------------------------------------------------------------------- */

.balloon-layer {
  position: fixed;
  inset: 0;
  z-index: 4000;
  pointer-events: none;
  overflow: hidden;
}
.balloon {
  position: absolute;
  bottom: -140px;
  width: 44px;
  height: 56px;
  background: var(--balloon-color, var(--red));
  border-radius: 50% 50% 50% 50% / 58% 58% 42% 42%;
  box-shadow: inset -6px -6px 0 rgba(0,0,0,0.08), 0 6px 16px rgba(0,0,0,0.18);
  animation-name: balloonRise;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}
.balloon::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -34px;
  width: 2px;
  height: 34px;
  background: rgba(80, 65, 50, 0.55);
  transform: translateX(-50%);
}
.balloon::after {
  content: "";
  position: absolute;
  top: 10px;
  left: 12px;
  width: 12px;
  height: 16px;
  background: rgba(255,255,255,0.35);
  border-radius: 50%;
  transform: rotate(-20deg);
}
@keyframes balloonRise {
  0% { transform: translateY(0) translateX(0) rotate(0deg); opacity: 0; }
  8% { opacity: 1; }
  100% { transform: translateY(-115vh) translateX(var(--drift, 20px)) rotate(var(--spin, 4deg)); opacity: 1; }
}

/* ---------------------------------------------------------------------- */
/* Responsive tweaks                                                      */
/* ---------------------------------------------------------------------- */

@media (max-width: 480px) {
  .panel-card { padding: 14px; border-radius: 18px; }
  /* .game-frame/.howto-frame need to stay tighter than the general
     .panel-card padding above (same specificity, so without this they'd
     win by source order alone) -- small phones are exactly where every
     extra pixel of canvas space matters most for legibility. */
  .game-frame { --game-pad: 4px; padding: var(--game-pad); }
  .howto-frame { --game-pad: 4px; padding: var(--game-pad); }
  .ctl { min-width: 48px; padding: 7px 6px; font-size: 0.95rem; }
  .ctl span { font-size: 0.62rem; }
}

@media (prefers-reduced-motion: reduce) {
  .keycap.active, .record-banner, .level-pip.current, .game-banner.show,
  .balloon, .game-canvas.shake { animation: none; }
}
