:root {
  --bg-cream: #FFF8EE;
  --bg-sky-top: #DFF4FF;
  --bg-sky-bot: #FFF6E8;
  --ink-navy: #24304B;
  --ink-soft: #596785;
  --coral: #FF6B8B;
  --sunny: #FFB703;
  --mint: #2EC4B6;
  --sky: #3A86FF;
  --lavender: #8338EC;
  --card-white: #FFFFFF;
  --shadow-soft: 0 8px 22px rgba(36, 48, 75, 0.10);
  --safe-top: max(10px, env(safe-area-inset-top));
  --safe-bot: max(12px, env(safe-area-inset-bottom));
  --safe-left: max(12px, env(safe-area-inset-left));
  --safe-right: max(12px, env(safe-area-inset-right));
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg-cream);
  color: var(--ink-navy);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "PingFang HK", "Noto Sans TC", sans-serif;
  /* Panning only: no pinch-zoom and no double-tap-zoom. `manipulation` still allows pinch. */
  touch-action: pan-x pan-y;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* iOS Safari/WebKit resets the inherited touch-action at every scroll container (overflow
   auto/scroll/hidden). Mounted games (.shark, .starship), their overlays, #screen-home and the
   dialogs are such containers and used to declare nothing, so controls inside them fell back to
   `auto` and kept pinch / double-tap zoom. Give EVERY element the panning-only default at zero
   specificity: any element that declares its own touch-action (canvas `none`, dialogs `pan-y`)
   still wins, while nothing is left on `auto`. No selector here may grant pinch-zoom. */
:where(html) * {
  touch-action: pan-x pan-y;
}
/* A native slider needs horizontal drags for itself. */
input[type="range"] {
  touch-action: pan-y;
}
/* shark.css asked for `manipulation` (which allows pinch) on its two floating buttons; they live
   inside the touch-action:none stage already, this keeps that true even if they are moved. */
html .shark .shark-mission-btn,
html .shark .shark-dash-fab {
  touch-action: pan-x pan-y;
}

.app-shell {
  width: 100%;
  max-width: 520px;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: var(--safe-top) var(--safe-right) var(--safe-bot) var(--safe-left);
  gap: 8px;
}

/* The third game owns its canvas and lifecycle; these rules only place its host. */
#screen-math {
  position: relative;
  padding: var(--safe-top) 0 var(--safe-bot);
  background: #080f35;
  color: #fff;
}
#math-mount { flex: 1; min-height: 0; width: 100%; }
/* Sync notices float over the stage: appearing/disappearing must never resize the canvas
   (every save after a correct answer used to shrink the stage and nudge Safari's page). */
#math-sync-status { position: absolute; left: 12px; right: 12px; bottom: calc(var(--safe-bot) + 10px); z-index: 45; margin: 0; padding: 6px 14px; border-radius: 12px; background: rgba(8, 15, 53, .92); border: 1px solid rgba(255, 228, 166, .35); font-size: .82rem; color: #ffe4a6; pointer-events: none; }
#math-sync-status button { pointer-events: auto; min-height: 56px; margin: 8px 12px 4px 0; border-radius: 12px; padding: 8px 12px; font: inherit; }
#math-loading { display: none; text-align: center; padding: 24px; }
#screen-math[aria-busy="true"] #math-loading { display: block; }
#screen-math[aria-busy="true"] #math-mount { visibility: hidden; }
#math-loading button { min-width: 56px; min-height: 56px; border-radius: 16px; font: inherit; }
.math-launch-icon { font-size: 3.3rem; }
.math-profile-button { font-size: .85rem !important; }
#screen-shark { padding: var(--safe-top) 0 var(--safe-bot); background: #031d35; color: white; }
#shark-mount { flex: 1; min-height: 0; width: 100%; }
#shark-sync-status { margin: 0; padding: 4px 14px; font-size: .82rem; color: #ffe4a6; }

/* Kid-first poster grid: 4 giant toy-box cards come first; calm parent/theme dock sits below. */
#screen-home {
  font-size: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-top: max(6px, env(safe-area-inset-top));
  gap: 6px;
  justify-content: flex-start;
}
#screen-home .game-cards {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(156px, 1fr);
  max-height: 556px;
  gap: 10px;
  min-height: min-content;
  align-items: stretch;
  justify-content: stretch;
}
#screen-home .game-launch-card { min-height: 100px; max-height: none; height: 100%; flex: none; }

/* ---------------- HOME SCREEN ---------------- */

.home-header {
  background: rgba(255, 255, 255, 0.88);
  border-radius: 999px;
  padding: 3px 12px;
  box-shadow: 0 3px 10px rgba(36, 48, 75, 0.06);
  border: 1.5px solid #FFE2EC;
  flex-shrink: 0;
}

.hero-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.hero-mascot {
  display: block;
  width: 32px;
  height: 32px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  flex-shrink: 0;
}

.hero-copy {
  min-width: 0;
}

.hero-copy h1 {
  margin: 0;
  font-size: clamp(16px, 4.2vw, 19px);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--ink-navy);
}

.hero-copy p {
  display: none;
}

#games-loading-status {
  margin: 0;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  text-align: center;
  flex-shrink: 0;
}

/* The French hub hides #app until its entry module runs (#games-entry-pending). The inline guard in
   index.html puts the status line in the visitor's language into --games-wait; the Cantonese text is only
   the fallback. Jugue builds drop that style element and guard, so this never matches there; the desktop QR
   page keeps the element but sets .phone-qr-gate. */
html:has(#games-entry-pending) body:not(.phone-qr-gate)::before {
  content: var(--games-wait, "正在準備遊戲…");
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--ink-soft);
  font-size: 16px;
  font-weight: 800;
  text-align: center;
}

.home-parent-dock {
  margin-top: auto;
  padding-top: 5px;
  border-top: 1px solid rgba(36, 48, 75, 0.09);
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
  flex-shrink: 0;
}

.home-dock-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
}

.app-pill {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.2;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid #E5ECF6;
  color: #5B6B88;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46%;
  flex-shrink: 0;
}

/* Learning Record Bar & Accessible Switch Control */
.learning-bar {
  margin: 0;
  padding: 0;
  border: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.learning-status-btn {
  appearance: none;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1.5px solid #E5ECF6;
  background: rgba(255, 255, 255, 0.72);
  color: #4A5A78;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}

.learning-status-btn:active {
  transform: scale(0.97);
}

.learning-status-btn.is-child-mode {
  background: rgba(236, 252, 249, 0.85);
  border-color: #9BE7DC;
  color: var(--ink-navy);
}

.learning-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid #E2E8F4;
}

.learning-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.learning-status-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
}

.asset-wait-dialog {
  width: min(90vw, 370px);
  max-height: min(90dvh, var(--vvh, 90dvh));
  overflow-y: auto;
  padding: 22px;
  border: 3px solid var(--sunny);
  border-radius: 24px;
  color: var(--ink-navy);
  background: var(--bg-cream);
  text-align: center;
  touch-action: pan-y;
}

.asset-wait-dialog::backdrop { background: rgba(36, 48, 75, 0.45); }
.asset-wait-dialog p { line-height: 1.6; }
.asset-wait-dialog button { width: 100%; min-height: 44px; margin-top: 8px; }

.learning-sync-status {
  font-size: 10.5px;
  line-height: 1.2;
  color: #805400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.learning-summary {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.login-switch-wrap {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  min-height: 44px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1.5px solid #E5ECF6;
  cursor: pointer;
}

.login-switch-text {
  font-size: 11.5px;
  font-weight: 700;
  color: #596785;
  white-space: nowrap;
}

.login-switch-wrap.is-on {
  border-color: #8DE0D6;
  background: rgba(242, 255, 253, 0.88);
}

.login-switch-wrap.is-on .login-switch-text {
  color: #0E7C71;
}

input[type="checkbox"][switch] {
  accent-color: var(--mint, #2EC4B6);
  margin: 0;
  cursor: pointer;
}

input[type="checkbox"][switch]:focus-visible {
  outline: 3px solid #FF8C00;
  outline-offset: 4px;
}

/* Fallback switch styling ONLY applied when `!(switch in HTMLInputElement.prototype)` */
input[type="checkbox"].switch-fallback {
  appearance: none;
  -webkit-appearance: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #CBD5E1;
  position: relative;
  transition: background-color 0.16s ease;
  flex-shrink: 0;
}

input[type="checkbox"].switch-fallback::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  transition: transform 0.16s ease;
}

input[type="checkbox"].switch-fallback:checked {
  background: var(--mint, #2EC4B6);
}

input[type="checkbox"].switch-fallback:checked::after {
  transform: translateX(16px);
}

.world-bar-caption {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  color: #6B7A99;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.world-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  max-width: 100%;
  flex-shrink: 0;
  align-self: center;
}

.world-chip {
  appearance: none;
  width: 100%;
  min-width: 0;
  border: 1.5px solid #E5ECF6;
  background: rgba(255, 255, 255, 0.78);
  color: #4A5A78;
  border-radius: 14px;
  padding: 3px 3px;
  min-height: 44px;
  font-size: clamp(11px, 2.85vw, 13px);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  white-space: normal;
  text-align: center;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}

.world-chip:active {
  transform: scale(0.95);
}

.world-chip.is-review {
  border-color: #F3D999;
  background: rgba(255, 252, 240, 0.85);
  color: #8A5200;
  white-space: normal;
}

.world-chip.is-selected {
  background: #DDF3FF;
  color: #0B3954;
  border-color: #38BDF8;
  font-weight: 800;
}

.world-chip.is-review.is-selected {
  background: #FFECC2;
  border-color: #F59E0B;
  color: #6B3700;
  font-weight: 800;
}

.game-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.game-launch-card {
  appearance: none;
  width: 100%;
  border-radius: 24px;
  border: 2.5px solid transparent;
  border-bottom-width: 5px;
  padding: 12px 10px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(36, 48, 75, 0.10);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.game-launch-card:disabled {
  opacity: 0.72;
  cursor: wait;
}

.game-launch-card:active {
  transform: scale(0.97);
}

.card-bubble {
  background: linear-gradient(165deg, #E6F7FF 0%, #C3E7FF 100%);
  border-color: #6CC2FF;
  border-bottom-color: #3698E6;
}

.card-tetris {
  background: linear-gradient(165deg, #FFF1F7 0%, #FFDCEB 100%);
  border-color: #FF9BC0;
  border-bottom-color: #E86496;
}

.card-math {
  background: linear-gradient(165deg, #F4EEFF 0%, #E2D2FF 100%);
  border-color: #B48EFF;
  border-bottom-color: #8A5CF0;
}

.card-shark {
  background: linear-gradient(165deg, #E2FCF7 0%, #BEF2EA 100%);
  border-color: #5CD6C6;
  border-bottom-color: #24AD9D;
}

.launch-icon-wrap {
  width: clamp(56px, 11dvh, 92px);
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: inset 0 2px 0 #FFFFFF, 0 4px 10px rgba(36, 48, 75, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.launch-icon-wrap img {
  display: block;
  width: 86%;
  height: 86%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
}

@keyframes game-card-float {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -3px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  #screen-home:not([hidden]) .game-card-icon {
    animation: game-card-float 3.2s ease-in-out infinite;
  }
  #screen-home:not([hidden]) .card-tetris .game-card-icon {
    animation-delay: -0.8s;
  }
  #screen-home:not([hidden]) .card-math .game-card-icon {
    animation-delay: -1.6s;
  }
  #screen-home:not([hidden]) .card-shark .game-card-icon {
    animation-delay: -2.4s;
  }
}

.launch-text {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.launch-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  min-width: 0;
}

.launch-text strong {
  font-size: clamp(14.5px, 3.8vw, 18px);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--ink-navy);
}

.launch-text .launch-desc {
  display: none;
}

.launch-text .game-age-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  max-width: 100%;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}

.launch-text .game-age-badge.is-preschool {
  background: linear-gradient(135deg, #FFE8B3 0%, #FFC9A9 100%);
  color: #7C2D12;
  border: 1.5px solid #FFA96B;
  box-shadow: 0 2px 6px rgba(255, 138, 91, 0.18);
}

.launch-text .game-age-badge.is-six-plus {
  background: rgba(255, 255, 255, 0.88);
  color: #24304B;
  border: 1.5px solid rgba(36, 48, 75, 0.14);
}

.launch-go {
  min-width: 56px;
  height: 30px;
  padding: 0 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, #2596FF 0%, #0EA5E9 100%);
  box-shadow: 0 3px 0 rgba(24, 34, 58, 0.20);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
  flex-shrink: 0;
}

.card-tetris .launch-go {
  background: linear-gradient(135deg, #FF5C8D 0%, #EC4899 100%);
}

.card-math .launch-go {
  background: linear-gradient(135deg, #8B5CF6 0%, #6D28D9 100%);
}

.card-shark .launch-go {
  background: linear-gradient(135deg, #14B8A6 0%, #0284C7 100%);
}

/* ---------------- HUD & GAME STAGES ---------------- */

.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-shrink: 0;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.hud-btn {
  appearance: none;
  border: 2px solid #E2E8F4;
  background: #FFFFFF;
  color: var(--ink-navy);
  min-height: 46px;
  padding: 0 12px;
  border-radius: 16px;
  font-size: 0.96rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(36, 48, 75, 0.07);
}

.hud-btn:active {
  transform: scale(0.94);
}

.hud-back {
  min-width: 44px;
  padding: 0 10px;
  font-size: 1.15rem;
}

.hud-pause {
  min-width: 44px;
  padding: 0 9px;
  font-size: 1.05rem;
  background: #F5F7FC;
}

.hud-speaker {
  background: linear-gradient(135deg, #FFD166 0%, #FFB703 100%);
  border-color: #F4A200;
  color: #24304B;
  min-width: 74px;
  padding: 0 10px;
  font-size: 0.92rem;
}

#screen-bubble:not([data-terminal]):has(#bubble-overlay:not([hidden])) :is(#bubble-pause, #bubble-replay),
#screen-tetris:not([data-terminal]):has(#tetris-overlay:not([hidden])) :is(#tetris-pause, #tetris-replay) {
  opacity: 0.45;
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

#screen-bubble > .hud-bar {
  flex-wrap: wrap;
  container-type: inline-size;
}

#screen-bubble .hud-actions,
#screen-bubble .hud-stats {
  flex-wrap: wrap;
}

/* Enlarged text on a wide, short screen: the one-row header no longer holds the full replay label and every
   counter, and wrapping would take a third of the stage. The replay button keeps its icon and accessible name. */
@media (min-width: 520px) and (max-height: 520px) {
  @container (max-width: 31rem) {
    #screen-bubble .hud-speaker {
      min-width: 44px;
    }

    #screen-bubble .hud-speaker span {
      display: none;
    }
  }
}

.stat-pill {
  background: #FFFFFF;
  border: 2px solid #ECEFF7;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: clamp(0.76rem, 3.2vw, 0.86rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.wave-pill {
  background: #EDF8FF;
  border-color: #BDE3FF;
  color: #165B96;
}

.stage-wrap {
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  border-radius: 26px;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  container-type: size;
}

.bubble-stage-wrap {
  background: linear-gradient(180deg, #CBEFFF 0%, #EAF9FF 62%, #FFF7E8 100%);
  border: 3px solid #A8DFFF;
}

.tetris-stage-wrap {
  background: linear-gradient(180deg, #FFFDF9 0%, #FFF3F8 100%);
  border: 3px solid #FFD0E3;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.word-toast {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 12px;
  margin-inline: auto;
  width: fit-content;
  max-width: calc(100% - 24px);
  background: rgba(255, 255, 255, 0.96);
  border: 3px solid #FFD166;
  border-radius: 999px;
  padding: 7px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 4px 10px;
  text-align: center;
  box-shadow: 0 8px 20px rgba(36, 48, 75, 0.14);
  pointer-events: none;
  z-index: 4;
}

.word-toast strong {
  font-size: clamp(1.05rem, 4.4cqi, 1.2rem);
  color: var(--ink-navy);
}

.word-toast span {
  font-size: clamp(0.84rem, 3.6cqi, 0.92rem);
  font-weight: 700;
  color: var(--coral);
}

@keyframes badge-pop-in {
  0% {
    opacity: 0;
    transform: translateY(6px) scale(0.94);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.event-badge-pill {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: clamp(104px, 19cqh, 132px);
  margin-inline: auto;
  width: fit-content;
  max-width: calc(100% - 24px);
  background: rgba(36, 48, 75, 0.90);
  border: 2px solid #FFD166;
  border-radius: 999px;
  padding: 6px 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: 0 6px 18px rgba(24, 34, 58, 0.22);
  pointer-events: none;
  z-index: 4;
  animation: badge-pop-in 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.12);
}

.event-badge-text {
  color: #FFF8EE;
  font-size: clamp(0.74rem, 3.3cqi, 0.86rem);
  font-weight: 800;
  line-height: 1.28;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}

.ship-hud-bar {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 7px;
  margin-inline: auto;
  max-width: 21.375rem;
  min-height: 28px;
  padding: 0 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.90);
  border: 1.5px solid rgba(147, 213, 255, 0.95);
  display: grid;
  grid-template-columns: minmax(32px, 1fr) minmax(0, max-content) 42px;
  align-items: center;
  gap: 6px;
  box-shadow: 0 3px 10px rgba(36, 48, 75, 0.08);
  pointer-events: none;
  z-index: 3;
  contain: layout style;
}

.ship-hud-bar.is-invincible {
  background: rgba(255, 240, 194, 0.96);
  border-color: #FFB703;
  grid-template-columns: minmax(32px, 1fr) minmax(0, max-content);
}

.ship-hud-info {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.ship-hud-icon {
  width: 19px;
  height: 19px;
  object-fit: contain;
  flex-shrink: 0;
}

.ship-hud-label {
  font-size: clamp(0.7rem, 3.1cqi, 0.78rem);
  font-weight: 800;
  color: var(--ink-navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ship-hud-bar.is-invincible .ship-hud-label {
  color: #B85D00;
}

.ship-hud-meter {
  grid-column: 3;
  grid-row: 1;
  width: 42px;
  height: 8px;
  border-radius: 999px;
  background: #E2ECF7;
  overflow: hidden;
  flex-shrink: 0;
}

.ship-hud-fill {
  height: 100%;
  width: 12%;
  border-radius: 999px;
  background: #2EC4B6;
  transition: width 0.18s ease;
}

.ship-hud-goal {
  grid-column: 2;
  grid-row: 1;
  color: var(--ink-navy);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.3;
  text-align: center;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* A large text setting must not turn the HUD into a tall card over the plane.
   The stage's rem-relative width detects when the goal needs the full row. */
@container (width < 15rem) {
  .ship-hud-bar,
  .ship-hud-bar.is-invincible {
    grid-template-columns: minmax(0, 1fr);
  }
  .ship-hud-info,
  .ship-hud-meter {
    display: none;
  }
  .ship-hud-goal {
    grid-column: 1;
  }
}

.start-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 250, 242, 0.95);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  align-items: safe center;
  justify-content: center;
  justify-content: safe center;
  padding: 18px 18px;
  text-align: center;
  gap: 9px;
  z-index: 8;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
}

.start-overlay.is-gameover {
  background: rgba(255, 249, 242, 0.80);
  backdrop-filter: blur(2.5px);
  -webkit-backdrop-filter: blur(2.5px);
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  gap: 7px;
  transition:
    opacity 280ms ease-out,
    display 280ms allow-discrete;
}

@starting-style {
  .start-overlay.is-gameover:not([hidden]) {
    opacity: 0;
  }
}

.start-overlay.is-gameover.is-instant-reveal {
  transition: none;
}

.overlay-art {
  width: 84px;
  height: 84px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  flex-shrink: 0;
}

.start-overlay.is-gameover .overlay-art {
  width: 58px;
  height: 58px;
}

.start-overlay h2 {
  margin: 0;
  font-size: clamp(1.26rem, 1.05rem + 1.3vw, 1.66rem);
  max-width: 100%;
  overflow-wrap: anywhere;
}

.start-overlay.is-gameover h2 {
  font-size: clamp(1.42rem, 1.18rem + 1.4vw, 1.88rem);
  letter-spacing: 0.04em;
  font-weight: 900;
  color: #D9385A;
  line-height: 1.08;
}

.overlay-subtitle {
  margin: -3px 0 0;
  font-size: clamp(0.94rem, 0.86rem + 0.35vw, 1.08rem);
  font-weight: 900;
  color: var(--ink-navy) !important;
  line-height: 1.2;
}

.start-overlay p {
  margin: 0;
  max-width: min(336px, 100%);
  font-size: clamp(0.86rem, 0.8rem + 0.35vw, 0.98rem);
  line-height: 1.4;
  color: var(--ink-soft);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.gameover-stats-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: 100%;
  max-width: 348px;
}

.gameover-stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid #FFE2EC;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--ink-navy);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* Checkpoint / Varied Start Mode Selector Pills */
.start-mode-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: 100%;
  max-width: 348px;
}

.mode-pill {
  appearance: none;
  border: 2px solid #DCE5F2;
  background: #FFFFFF;
  color: var(--ink-navy);
  border-radius: 999px;
  padding: 6px 12px;
  min-height: 36px;
  min-width: 0;
  max-width: 100%;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  overflow-wrap: anywhere;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.mode-pill:disabled {
  opacity: 0.62;
  cursor: wait;
}

.mode-pill:active:not(:disabled) {
  transform: scale(0.96);
}

.mode-pill.is-selected {
  background: #24304B;
  border-color: #24304B;
  color: #FFFFFF;
}

.mode-pill.is-checkpoint.is-selected {
  background: linear-gradient(135deg, #FF8E53 0%, #FF5E7E 100%);
  border-color: #FF5E7E;
  color: #FFFFFF;
}

/* Post-Run Interactive Word Review Box */
.post-review-box {
  width: 100%;
  max-width: 344px;
  background: rgba(255, 255, 255, 0.96);
  border: 2px solid #FFE2EC;
  border-radius: 18px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.post-review-label {
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--ink-soft);
  max-width: 100%;
  overflow-wrap: anywhere;
}

.post-review-empty {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-soft);
  line-height: 1.35;
}

.post-review-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
  width: 100%;
  min-width: 0;
}

.review-word-chip {
  appearance: none;
  border: 1.5px solid #CFE8FF;
  background: #F4FAFF;
  color: var(--ink-navy);
  border-radius: 18px;
  padding: 5px 10px;
  min-height: 34px;
  min-width: 0;
  max-width: 100%;
  font-size: 0.77rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  gap: 4px;
  cursor: pointer;
}

.review-word-chip:disabled {
  opacity: 0.62;
  cursor: wait;
}

.review-word-chip.is-missed {
  border-color: #FFB3C6;
  background: #FFF0F4;
  color: #9E1946;
}

.review-word-chip:active:not(:disabled) {
  transform: scale(0.95);
}

.review-word-chip.is-speaking {
  outline: 2px solid #8446B0;
  outline-offset: 2px;
  background: #EDE2FF;
  animation: review-speaking-pulse 700ms ease-in-out 2;
}

@keyframes review-speaking-pulse {
  50% { box-shadow: 0 0 0 4px rgba(132, 70, 176, 0.2); }
}

.review-word-pair {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 3px;
  border-radius: 16px;
  background: #F4FAFF;
}

.review-word-pair .review-word-chip {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  min-height: 40px;
}

.review-word-chip.is-comparison {
  border-color: #CDB8ED;
  color: #60358A;
}

@media (prefers-reduced-motion: reduce) {
  .review-word-chip.is-speaking { animation: none; }
  .start-overlay.is-gameover { transition: none; }
  .event-badge-pill { animation: none; }
  .ship-hud-fill { transition: none; }
}

.primary-start-btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #FF6B8B 0%, #FF8E53 100%);
  color: #FFFFFF;
  min-block-size: 56px;
  min-inline-size: 56px;
  min-height: 56px;
  min-width: 56px;
  max-width: 100%;
  padding: 8px 28px;
  font-size: 1.16rem;
  font-weight: 900;
  line-height: 1.2;
  box-shadow: 0 10px 22px rgba(255, 107, 139, 0.35);
  cursor: pointer;
  margin-top: 2px;
  flex-shrink: 0;
  overflow-wrap: anywhere;
  touch-action: pan-x pan-y;
}

.primary-start-btn:disabled {
  opacity: 0.72;
  cursor: wait;
}

.primary-start-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.gameover-actions-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 348px;
  flex-shrink: 0;
}

.gameover-action-btn {
  appearance: none;
  flex: 1 1 132px;
  min-block-size: 56px;
  min-inline-size: 56px;
  min-height: 56px;
  min-width: 56px;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 20px;
  border: 2px solid #DCE5F2;
  background: #FFFFFF;
  color: var(--ink-navy);
  font-size: 0.90rem;
  font-weight: 900;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 5px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(36, 48, 75, 0.08);
  overflow-wrap: anywhere;
  touch-action: pan-x pan-y;
}

.gameover-action-btn.is-review {
  background: #F2FAFF;
  border-color: #BAE0FF;
  color: #165B96;
}

.gameover-action-btn.is-home {
  background: #FFFFFF;
  border-color: #DCE5F2;
  color: var(--ink-navy);
}

.gameover-action-btn:disabled {
  opacity: 0.62;
  cursor: wait;
}

.gameover-action-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.gameover-action-btn:focus-visible,
.primary-start-btn:focus-visible,
.mode-pill:focus-visible,
.review-word-chip:focus-visible {
  outline: 3px solid #FFB703;
  outline-offset: 2px;
}

/* result-hierarchy:start */
/* Bubble game-over only. Size and weight; each theme keeps its own fill and ink. */
#screen-bubble .start-overlay.is-gameover .primary-start-btn {
  width: min(100%, 348px);
  min-width: 44px;
  min-height: 56px;
  height: auto;
  max-height: none;
  padding-inline: 16px;
  font-weight: 900;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
}

#screen-bubble .start-overlay.is-gameover .gameover-actions-row,
#screen-bubble .start-overlay.is-gameover .start-mode-group {
  flex-direction: column;
  align-items: stretch;
  width: min(100%, 348px);
  max-width: 100%;
}

#screen-bubble .start-overlay.is-gameover .gameover-action-btn.is-home,
#screen-bubble .start-overlay.is-gameover .start-mode-group .mode-pill {
  flex: 1 1 auto;
  width: 100%;
  min-width: 44px;
  min-height: 44px;
  height: auto;
  max-height: none;
  padding-inline: 12px;
  font-weight: 700;
  font-size: 0.92rem;
  box-shadow: none;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
}

#screen-bubble .start-overlay.is-gameover .gameover-action-btn.is-review {
  flex: 1 1 auto;
  width: 100%;
  min-width: 44px;
  height: auto;
  max-height: none;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
}

#screen-bubble .start-overlay.is-gameover .post-review-chips {
  gap: 8px;
}

#screen-bubble .start-overlay.is-gameover .review-word-chip {
  flex: 0 1 auto;
  width: auto;
  min-width: 44px;
  min-height: 44px;
  height: auto;
  max-width: 100%;
  border-radius: 12px;
  padding: 6px 10px;
  font-weight: 800;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
}

#screen-bubble .start-overlay.is-gameover .gameover-stat-chip {
  cursor: default;
  pointer-events: none;
  font-weight: 700;
  font-size: 0.78rem;
  border-radius: 8px;
  box-shadow: none;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
}

@media (max-width: 430px), (max-height: 520px) {
  #screen-bubble .start-overlay.is-gameover .primary-start-btn,
  #screen-bubble .start-overlay.is-gameover .gameover-action-btn,
  #screen-bubble .start-overlay.is-gameover .mode-pill,
  #screen-bubble .start-overlay.is-gameover .review-word-chip {
    padding-inline: 10px;
    height: auto;
    max-height: none;
    overflow: visible;
  }
}
/* result-hierarchy:end */

/* ---------------- TETRIS CONTROLS ---------------- */

.tetris-status-strip {
  background: #FFFFFF;
  border: 2px solid #FFE0EC;
  border-radius: 14px;
  padding: 5px 10px;
  text-align: center;
  font-size: clamp(0.78rem, 0.72rem + 0.35vw, 0.92rem);
  line-height: 1.25;
  font-weight: 800;
  color: var(--ink-navy);
  flex-shrink: 0;
  contain: layout style;
}

.tetris-controls {
  display: grid;
  grid-template-columns: 1fr 1.15fr 0.9fr 1fr 1fr;
  gap: 8px;
  flex-shrink: 0;
  transition: opacity 0.18s ease;
  touch-action: none;
}

.tetris-controls.is-cards-phase {
  opacity: 0.42;
}

.ctrl-btn {
  appearance: none;
  border: 2px solid #DCE4F2;
  background: #FFFFFF;
  color: var(--ink-navy);
  min-height: 56px;
  border-radius: 20px;
  font-size: 1.42rem;
  font-weight: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  gap: 2px;
  box-shadow: 0 5px 0 #D5DFEE;
  cursor: pointer;
  touch-action: none;
}

.ctrl-btn span {
  font-size: 0.72rem;
  font-weight: 800;
}

.ctrl-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #D5DFEE;
}

.ctrl-rotate {
  background: linear-gradient(180deg, #EDE3FF 0%, #DFCFFF 100%);
  border-color: #C7AEFF;
  box-shadow: 0 5px 0 #BFA3FF;
}

.ctrl-drop {
  background: linear-gradient(180deg, #FFE8EC 0%, #FFD5DF 100%);
  border-color: #FFB6C7;
  box-shadow: 0 5px 0 #F4A3B8;
}

/* ---------------- UNIFIED 3-MINUTE PAUSE MODAL ---------------- */

.pause-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(36, 48, 75, 0.46);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  align-items: safe center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 40;
}

.pause-modal-card {
  width: 100%;
  max-width: 348px;
  background: linear-gradient(180deg, #FFFFFF 0%, #FFF7EE 100%);
  border: 3px solid #FFD166;
  border-radius: 30px;
  padding: 22px 22px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 11px;
  box-shadow: 0 18px 42px rgba(24, 34, 58, 0.28);
}

.pause-mascot {
  width: 82px;
  height: 82px;
  object-fit: contain;
}

.pause-modal-card h2 {
  margin: 0;
  font-size: 1.48rem;
  color: var(--ink-navy);
}

.pause-timer-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #EEF9FF;
  border: 2px solid #A8DFFF;
  border-radius: 999px;
  padding: 7px 18px;
}

.pause-timer-badge span {
  font-size: 0.84rem;
  font-weight: 800;
  color: #165B96;
}

.pause-timer-badge strong {
  font-size: 1.42rem;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  color: var(--ink-navy);
}

.pause-timer-badge.is-urgent {
  background: #FFF0F3;
  border-color: #FFB3C6;
}

.pause-timer-badge.is-urgent strong {
  color: #D90429;
}

.pause-modal-card p {
  margin: 0;
  font-size: 0.94rem;
  line-height: 1.42;
  color: var(--ink-soft);
  font-weight: 600;
}

.pause-resume-btn {
  appearance: none;
  width: 100%;
  min-height: 64px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #2EC4B6 0%, #20A4F3 100%);
  color: #FFFFFF;
  font-size: 1.32rem;
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(32, 164, 243, 0.34);
  cursor: pointer;
  margin-top: 4px;
}

.pause-resume-btn:active {
  transform: scale(0.96);
}

.pause-secondary-btn {
  appearance: none;
  width: 100%;
  min-height: 46px;
  border: 2px solid #E2E8F4;
  border-radius: 999px;
  background: #FFFFFF;
  color: var(--ink-soft);
  font-size: 0.96rem;
  font-weight: 800;
  cursor: pointer;
}

.pause-secondary-btn:active {
  transform: scale(0.97);
}

/* ---------------- LEARNING & ORIGINAL LOGIN DIALOG ---------------- */

dialog.learning-dialog {
  padding: 0;
  border: 3px solid #FFD166;
  border-radius: 28px;
  width: min(92vw, 430px);
  max-height: min(86vh, 86dvh, calc(var(--vvh, 100dvh) * 0.86));
  background: linear-gradient(180deg, #FFFFFF 0%, #FFF9F2 100%);
  color: var(--ink-navy);
  box-shadow: 0 20px 46px rgba(24, 34, 58, 0.30);
  overflow: hidden;
}

dialog.learning-dialog::backdrop {
  background-color: rgba(24, 34, 58, 0.48);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.learning-dialog-inner {
  padding: 18px;
  max-height: min(85vh, 85dvh, calc(var(--vvh, 100dvh) * 0.85));
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.learning-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.learning-dialog-head h2 {
  margin: 0;
  font-size: 1.18rem;
}

.dialog-close-btn {
  appearance: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid #E2E8F4;
  background: #FFFFFF;
  color: var(--ink-soft);
  font-size: 0.96rem;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
}

.modal-switch-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  border-radius: 18px;
  background: #F6FAFF;
  border: 2px solid #DCE7F7;
  cursor: pointer;
}

.modal-switch-card.is-on {
  background: #EEFCF9;
  border-color: #92E4D9;
}

.modal-switch-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.modal-switch-copy strong {
  font-size: 0.88rem;
  color: var(--ink-navy);
}

.modal-switch-copy span {
  font-size: 0.76rem;
  line-height: 1.32;
  color: var(--ink-soft);
  font-weight: 600;
}

.learning-auth-panel {
  background: #FFFFFF;
  border: 2px solid #FFE2EC;
  border-radius: 20px;
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.learning-auth-panel h3 {
  margin: 0;
  font-size: 1rem;
}

.auth-hint {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--ink-soft);
  font-weight: 600;
}

.parent-login-form {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.login-field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.login-field-group label {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--ink-navy);
}

.login-field-group input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 2px solid #D8E2F1;
  background: #FFFFFF;
  color: var(--ink-navy);
  font-size: 16px; /* Prevents iOS Safari auto-zoom on input focus */
  font-weight: 600;
}

.login-field-group input:focus {
  outline: none;
  border-color: var(--sky);
}

.login-submit-btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  min-height: 46px;
  background: linear-gradient(135deg, #2EC4B6 0%, #20A4F3 100%);
  color: #FFFFFF;
  font-size: 0.98rem;
  font-weight: 900;
  cursor: pointer;
}

.login-submit-btn:disabled {
  opacity: 0.65;
}

.login-alt-actions {
  display: flex;
  gap: 8px;
}

.login-secondary-btn {
  appearance: none;
  flex: 1 1 0;
  min-height: 38px;
  border-radius: 999px;
  border: 1.5px solid #DCE4F2;
  background: #F8FAFE;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
}

.login-status-msg {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  color: #0E7C71;
}

.login-status-msg.is-error {
  color: #D90429;
}

.learning-children-panel {
  background: #FFFFFF;
  border: 2px solid #CDECE7;
  border-radius: 20px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.children-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.84rem;
  font-weight: 800;
}

.logout-mini-btn {
  appearance: none;
  border: 1.5px solid #E2E8F4;
  background: #FFFFFF;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

.child-picker-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.child-card-btn {
  appearance: none;
  border: 2px solid #DCE6F5;
  background: #F9FBFF;
  color: var(--ink-navy);
  border-radius: 16px;
  padding: 7px 12px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
}

.child-card-btn.is-selected {
  background: #E9FBF8;
  border-color: #2EC4B6;
  box-shadow: 0 4px 12px rgba(46, 196, 182, 0.18);
}

.learning-stats-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-mini-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.stat-mini-card {
  border-radius: 16px;
  padding: 8px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 1.5px solid #E5ECF6;
  background: #FFFFFF;
}

.stat-mini-card span {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--ink-soft);
}

.stat-mini-card strong {
  font-size: 1.15rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.stat-mini-card.is-weak {
  background: #FFF5F7;
  border-color: #FFD0DC;
}

.stat-mini-card.is-mastered {
  background: #F2FCF9;
  border-color: #C2EFE4;
}

.stat-mini-card.is-stage {
  background: #F2F9FF;
  border-color: #C7E4FF;
}

.weak-section-hint {
  margin: 0;
  font-size: 0.76rem;
  line-height: 1.34;
  color: var(--ink-soft);
  font-weight: 700;
}

.weak-words-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.weak-empty-note {
  font-size: 0.8rem;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 6px 2px;
}

.dialog-action-btn {
  appearance: none;
  width: 100%;
  min-height: 46px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #FF6B8B 0%, #FF8E53 100%);
  color: #FFFFFF;
  font-size: 0.94rem;
  font-weight: 900;
  cursor: pointer;
}

.dialog-action-btn:active {
  transform: scale(0.97);
}

@container (max-height: 430px) {
  .overlay-art {
    width: 64px;
    height: 64px;
  }
}

/* ---------------- VIEWPORT / ZOOM POLICY ---------------- */

/* Focus-zoom guard: every text-entry control stays >= 16px (iOS Safari zooms smaller ones on focus). */
html input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="button"]):not([type="submit"]),
html textarea,
html select {
  font-size: max(16px, 1em);
}

/* Narrow phones (320px class): keep the HUD on one row without clipping. */
@media (max-width: 359px) {
  .hud-bar,
  .hud-actions {
    gap: 4px;
  }

  .hud-btn {
    padding: 0 9px;
  }

  .hud-speaker {
    min-width: 44px;
  }

  .hud-speaker span {
    display: none;
  }

  .stat-pill {
    padding: 4px 6px;
    font-size: 0.74rem;
  }

  .hud-stats {
    gap: 3px;
  }

  .tetris-controls {
    gap: 5px;
  }
}

@media (max-height: 700px) {
  #screen-home {
    gap: 6px;
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  #screen-home .home-header {
    padding: 3px 10px;
  }

  #screen-home .hero-mascot {
    width: 32px;
    height: 32px;
  }

  #screen-home .hero-copy h1 {
    font-size: 16px;
  }

  #screen-home .game-cards {
    grid-auto-rows: minmax(148px, 1fr);
    gap: 8px;
  }

  #screen-home .game-launch-card {
    padding: 9px 8px 8px;
    gap: 4px;
    border-radius: 22px;
  }

  #screen-home .launch-icon-wrap {
    width: clamp(56px, 10.5dvh, 72px);
    border-radius: 18px;
  }

  #screen-home .launch-go {
    min-width: 50px;
    height: 28px;
    font-size: 12px;
  }
}

@media (max-height: 600px) {
  #screen-home {
    gap: 5px;
    padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  #screen-home .home-header {
    padding: 3px 10px;
  }

  #screen-home .hero-mascot {
    width: 28px;
    height: 28px;
  }

  #screen-home .hero-copy h1 {
    font-size: 15px;
  }

  #screen-home .home-parent-dock {
    padding-top: 4px;
    gap: 4px;
  }

  #screen-home .learning-avatar {
    width: 22px;
    height: 22px;
  }

  #screen-home .game-cards {
    grid-auto-rows: minmax(140px, 1fr);
    gap: 7px;
  }

  #screen-home .game-launch-card {
    min-height: 100px;
    gap: 3px;
    padding: 7px 6px 6px;
    border-radius: 20px;
  }

  #screen-home .launch-icon-wrap {
    width: 56px;
    border-radius: 16px;
  }

  #screen-home .launch-text strong {
    font-size: 14.5px;
  }

  #screen-home .launch-text .game-age-badge {
    font-size: 10.5px;
    padding: 2px 7px;
  }

  #screen-home .launch-go {
    min-width: 46px;
    height: 25px;
    font-size: 11.5px;
  }
}

@media (orientation: landscape) and (min-width: 560px) and (max-height: 500px) {
  #screen-home .game-cards {
    flex: 0 0 auto;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: minmax(146px, auto);
    max-height: none;
    gap: 6px;
  }

  #screen-home .game-launch-card {
    padding: 6px 5px 5px;
    gap: 3px;
  }

  #screen-home .launch-icon-wrap {
    width: 52px;
    border-radius: 15px;
  }

  #screen-home .launch-text strong {
    font-size: clamp(13.5px, 1.9vw, 16px);
  }

  #screen-home .launch-text .game-age-badge {
    font-size: 10px;
    padding: 2px 6px;
  }

  #screen-home .launch-go {
    min-width: 44px;
    height: 24px;
    font-size: 11px;
  }
}

@media (orientation: landscape) and (min-width: 680px) and (max-height: 500px) {
  #screen-home .game-cards {
    flex: 1 1 auto;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: minmax(165px, 1fr);
    max-height: 186px;
    gap: 8px;
  }

  #screen-home .game-launch-card {
    padding: 8px 8px 7px;
    gap: 4px;
  }

  #screen-home .launch-icon-wrap {
    width: clamp(60px, 17dvh, 72px);
    border-radius: 18px;
  }

  #screen-home .launch-go {
    min-width: 50px;
    height: 26px;
    font-size: 12px;
  }

  #screen-home .world-bar {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 4px;
  }

  #screen-home .world-chip {
    font-size: clamp(11px, 1.4vw, 12.5px);
  }
}

@media (max-height: 440px) and (orientation: landscape) {
  #screen-home .home-dock-meta {
    display: none;
  }
}

/* Short viewports (landscape phones, keyboard-shrunk windows): compact overlays and dialogs. */
@container (max-height: 320px) {
  .overlay-art {
    width: 44px;
    height: 44px;
  }

  .start-overlay {
    padding: 10px 14px;
    gap: 6px;
  }
}

@media (max-height: 520px) {
  .pause-modal-backdrop {
    padding: 10px;
  }

  .pause-modal-card {
    padding: 12px 18px 12px;
    gap: 7px;
  }

  .pause-mascot {
    width: 44px;
    height: 44px;
  }

  .pause-resume-btn {
    min-height: 52px;
  }
}

/* Short landscape phones: the stacked pause card is ~334px tall and pushes Home below the fold. Put the
   status text and the two actions side by side; both buttons keep their 52px / 46px targets. Narrower
   than 480px keeps the stacked card; enlarged text keeps both columns and scrolls inside the backdrop. */
@media (orientation: landscape) and (max-height: 380px) and (min-width: 480px) {
  .pause-modal-backdrop {
    padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .pause-modal-card {
    max-width: min(560px, 100%);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: repeat(4, auto);
    column-gap: 16px;
    row-gap: 6px;
    align-items: center;
    justify-items: center;
    padding: 12px 16px;
  }

  .pause-mascot,
  .pause-modal-card h2,
  .pause-timer-badge,
  .pause-modal-card p {
    grid-column: 1;
  }

  .pause-mascot {
    width: 36px;
    height: 36px;
  }

  .pause-modal-card h2 {
    font-size: 1.2rem;
  }

  .pause-modal-card p {
    font-size: 0.86rem;
    line-height: 1.3;
  }

  .pause-resume-btn,
  .pause-secondary-btn {
    grid-column: 2;
    margin-top: 0;
  }

  .pause-resume-btn {
    grid-row: 1 / span 2;
    align-self: end;
  }

  .pause-secondary-btn {
    grid-row: 3 / span 2;
    align-self: start;
  }
}

/* Short landscape: widen the shell and stage wrap (the bubble engine supports down to 0.55 h/w
   aspect), and move the Tetris controls beside the board. */
@media (orientation: landscape) and (max-height: 520px) {
  .app-shell {
    max-width: 960px;
  }

  .game-launch-card {
    max-height: none;
  }

  .bubble-stage-wrap {
    align-self: center;
    width: min(100%, calc((100dvh - 96px) * 1.48));
    height: min(100%, calc(100dvh - 96px));
  }

  #screen-tetris {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(150px, 28vw, 230px);
    grid-template-rows: auto auto minmax(0, 1fr);
    column-gap: 10px;
    row-gap: 8px;
  }

  #screen-tetris > .hud-bar {
    grid-column: 1 / -1;
  }

  #screen-tetris > .tetris-status-strip {
    grid-column: 1;
    grid-row: 2;
  }

  #screen-tetris > .tetris-stage-wrap {
    grid-column: 1;
    grid-row: 3;
  }

  #screen-tetris > .tetris-controls {
    grid-column: 2;
    grid-row: 2 / 4;
    grid-template-columns: 1fr 1fr;
    align-content: center;
  }

  #ctrl-left { grid-area: 1 / 1; }
  #ctrl-right { grid-area: 1 / 2; }
  #ctrl-rotate { grid-area: 2 / 1 / 3 / 3; }
  #ctrl-down { grid-area: 3 / 1; }
  #ctrl-drop { grid-area: 3 / 2; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .bubble-stage-wrap {
    align-self: center;
    width: min(100%, calc((100dvh - 96px) * 1.48));
    height: min(100%, calc(100dvh - 96px));
  }

  #screen-tetris {
    row-gap: 4px;
  }

  #screen-tetris > .hud-bar,
  #screen-tetris .game-topbar {
    padding-block: 2px;
  }

  #screen-tetris > .tetris-status-strip,
  #screen-tetris .target-strip {
    padding-block: 2px;
    min-height: 30px;
  }

  #screen-tetris > .tetris-controls,
  #screen-tetris .tetris-controls {
    padding-block: 2px;
    gap: 6px;
  }
}

/* Recovery follows the visual viewport after an escaped pinch. Only this independent nav is
   counter-scaled by JS; game layout, canvas coordinates and pointer capture remain untouched. */
.viewport-recovery {
  position: fixed;
  z-index: 80;
  transform-origin: top left;
  display: flex;
  gap: 6px;
  padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) 6px max(6px, env(safe-area-inset-left));
  border-radius: 16px;
  background: #24304B;
  box-shadow: 0 3px 14px #0005;
  touch-action: pan-x pan-y;
}
.viewport-recovery button {
  appearance: none;
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 8px 6px;
  border: 0;
  border-radius: 10px;
  background: white;
  color: #24304B;
  font: 700 16px/1.25 -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
}
.viewport-recovery button:disabled { opacity: 0.55; cursor: wait; }
.viewport-recovery button:focus-visible { outline: 3px solid #FFB703; outline-offset: 2px; }

/* Keep the existing pause UI scrollable inside the visible rectangle; the recovery nav also
   forwards its original home/resume controls when the card is below the current pan position. */
html[data-visual-viewport] .pause-modal-backdrop {
  inset: auto;
  left: var(--vv-left);
  top: var(--vv-top);
  width: var(--vv-width);
  height: var(--vv-height);
  padding: 16px 8px;
  touch-action: pan-y;
}

/* Keep the GAME OVER result card inside the visible visualViewport after zoom/pan, starting
   cleanly below `.viewport-recovery` so all three >=56x56px actions remain scrollable & reachable. */
html[data-visual-viewport-zoomed] .start-overlay.is-gameover {
  position: fixed;
  inset: auto;
  left: var(--vv-left);
  top: var(--vv-top);
  width: var(--vv-width);
  height: var(--vv-height);
  z-index: 45;
  justify-content: flex-start;
  padding: calc((72px + env(safe-area-inset-top)) / var(--vv-scale, 1)) 8px
    max(12px, calc(env(safe-area-inset-bottom) / var(--vv-scale, 1))) 8px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
}

html[data-visual-viewport-zoomed] .start-overlay.is-gameover .primary-start-btn,
html[data-visual-viewport-zoomed] .start-overlay.is-gameover .gameover-action-btn {
  max-width: 100%;
  padding-inline: 10px;
  font-size: clamp(0.78rem, 4vw, 1rem);
}

@media (max-height: 520px) {
  .start-overlay.is-gameover {
    padding-block: 8px;
    gap: 5px;
  }

  .start-overlay.is-gameover .overlay-art {
    width: 38px;
    height: 38px;
  }
}

/* Shark / Math overlays (pause, role choice, victory, result) are `position: fixed; inset: 0`, i.e.
   the LAYOUT viewport. After an escaped pinch the visible rectangle is smaller and panned, so
   keep the whole card scrollable inside what the child can actually see; the recovery toolbar
   above it forwards the same home / continue buttons. */
html[data-visual-viewport-zoomed] .shark-overlay,
html[data-visual-viewport-zoomed] .starship-overlay {
  inset: auto;
  left: var(--vv-left);
  top: var(--vv-top);
  width: var(--vv-width);
  height: var(--vv-height);
  padding-top: calc((72px + env(safe-area-inset-top)) / var(--vv-scale, 1));
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
}

/* Native dialogs stay in their original DOM/top layer. Fixed CSS bounds leave close/retry,
   form focus, paste, scrolling and modal inertness with the native dialog implementation. */
html[data-visual-viewport] dialog.learning-dialog,
html[data-visual-viewport] dialog.asset-wait-dialog {
  position: fixed;
  inset: auto;
  left: calc(var(--vv-left) + 8px);
  right: calc(100% - var(--vv-left) - var(--vv-width) + 8px);
  top: calc(var(--vv-top) + max(8px, env(safe-area-inset-top)));
  margin: 0 auto;
  max-width: calc(var(--vv-width) - 16px);
  max-height: calc(var(--vv-height) - max(8px, env(safe-area-inset-top)) - 8px);
}
html[data-visual-viewport] .learning-dialog-inner {
  max-height: calc(var(--vv-height) - max(8px, env(safe-area-inset-top)) - 16px);
}
.learning-dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #FFF9F2;
}
.learning-dialog-head h2 { min-width: 0; overflow-wrap: anywhere; }
.dialog-close-btn { flex-shrink: 0; }

/* Child-facing home targets stay usable on short phones; Shark is last in DOM. */
#screen-home .learning-status-btn,
#screen-home .login-switch-wrap,
#screen-home .world-chip { min-height: 44px; }
