/* ==========================================================================
   Trái Cây Nối Nối: screens and layout
   ========================================================================== */

html,
body { height: 100%; }
body {
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--muc-tim-900);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
#app { position: fixed; inset: 0; overflow: hidden; }
#fx { position: fixed; inset: 0; z-index: 70; pointer-events: none; }

.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.is-active { display: flex; animation: screen-in var(--dur-slow) var(--ease-out); }
@keyframes screen-in { from { opacity: 0; transform: scale(1.015); } to { opacity: 1; transform: none; } }

/* gạch bông floor behind every menu screen */
.tiles-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(110% 70% at 50% -10%, rgb(255 246 214 / 0.95), rgb(255 246 214 / 0) 60%),
    linear-gradient(rgb(240 251 248 / 0.5), rgb(240 251 248 / 0.5)),
    var(--gach-bong-image, none) center / 184px 184px,
    var(--ngoc-gach-bong-100);
}

/* ---------- top bar (menus) ---------- */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) var(--space-3) max(16px, env(safe-area-inset-left));
}
.topbar__title { flex: 1; min-width: 0; margin: 0; font: 400 clamp(1.5rem, 5vw, 2rem)/1.1 var(--font-display); color: var(--color-ink); }
.topbar__stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px 8px 10px;
  border-radius: var(--radius-pill);
  font: var(--weight-black) var(--text-md)/1 var(--font-ui);
  background: #fff;
  box-shadow: 0 4px 0 var(--muc-tim-200);
}
.topbar__stat .star { width: 22px; height: 22px; }
.scroller {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-2) max(16px, env(safe-area-inset-right)) var(--space-9) max(16px, env(safe-area-inset-left));
}
.scroller__lead { max-width: 1180px; margin: 0 auto var(--space-5); color: var(--color-ink-soft); font-weight: var(--weight-medium); }

/* ---------- home ---------- */
.home { align-items: center; justify-content: center; overflow: hidden; }
.home__floaters { position: absolute; inset: 0; pointer-events: none; }
.home__floaters .fruit { position: absolute; width: var(--s, 72px); height: var(--s, 72px); animation: bob var(--d, 4s) ease-in-out var(--delay, 0s) infinite; filter: drop-shadow(0 8px 8px rgb(42 22 64 / 0.18)); }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(var(--r, 0deg)); } 50% { transform: translateY(-12px) rotate(calc(var(--r, 0deg) * -1)); } }
.home__stack {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  width: min(92vw, 540px);
  padding: var(--space-4) 0 var(--space-9);
}
.home__brand { position: relative; width: min(100%, 480px); animation: brand-in 0.8s var(--ease-spring) both; }
.home__brand .logo { display: block; width: 100%; height: auto; filter: drop-shadow(0 14px 14px rgb(42 22 64 / 0.22)); }
.home__mascot { position: relative; width: clamp(110px, 30vw, 150px); margin: -18px 0 -14px; animation: mascot-in 0.9s var(--ease-spring) 0.25s both; }
.home__mascot .mascot { width: 100%; height: auto; animation: bob 3.2s ease-in-out 1.2s infinite; }
@keyframes brand-in { from { transform: translateY(-30px) scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes mascot-in { from { transform: translateY(40px) scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }
.home__tagline {
  margin: var(--space-2) 0 0;
  padding: 6px 16px;
  border-radius: var(--radius-pill);
  font: var(--weight-semibold) var(--text-md)/1.4 var(--font-ui);
  color: var(--color-ink-soft);
  background: rgb(255 255 255 / 0.75);
}
.home__actions { display: flex; flex-direction: column; gap: var(--space-4); width: min(100%, 320px); }
.home__row { display: flex; gap: var(--space-4); justify-content: center; }
.home__foot {
  position: absolute;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-ink-soft);
}

/* ---------- journey ---------- */
.journey__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
  gap: var(--space-5);
  max-width: 1180px;
  margin: 0 auto;
}
.level-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 0;
  background: none;
  border-radius: var(--radius-lg);
  text-align: left;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-spring);
}
.level-card > .postcard { flex: 1; }
@media (hover: hover) { .level-card:hover { transform: translateY(-4px) rotate(-0.6deg); } }
.level-card:active { transform: translateY(1px) scale(0.99); }
.level-card.is-next .postcard { box-shadow: 0 0 0 4px var(--vang-xoai-500), 0 6px 0 var(--sua-dua-200), var(--shadow-soft); }
.level-card.is-next .postcard__num { animation: next-ping 1.6s ease-in-out infinite; }
@keyframes next-ping { 50% { box-shadow: 0 0 0 4px #fff, 0 0 0 10px rgb(255 197 46 / 0.45), 0 6px 10px rgb(42 22 64 / 0.3); } }
.level-card.is-locked { cursor: not-allowed; }
.level-card.is-locked .postcard__view { filter: grayscale(0.85) brightness(0.92); }
.level-card.is-locked .postcard__num { background: var(--muc-tim-200); }
.level-card__lock {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
}
.level-card__lock .icon { width: 40px; height: 40px; filter: drop-shadow(0 3px 6px rgb(42 22 64 / 0.5)); }

/* ---------- fruit notebook ---------- */
.book__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-4);
  max-width: 1180px;
  margin: 0 auto;
}
.fruit-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--space-4) var(--space-3);
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: 0 5px 0 var(--sua-dua-200), var(--shadow-soft);
  text-align: center;
}
.fruit-card .fruit { width: 96px; height: 96px; transition: transform var(--dur-base) var(--ease-spring); }
@media (hover: hover) { .fruit-card:hover .fruit { transform: translateY(-6px) rotate(-6deg); } }
.fruit-card h3 { margin: 2px 0 0; font: 400 var(--text-lg)/1.15 var(--font-display); color: var(--color-ink); }
.fruit-card p { margin: 0 0 6px; font-size: var(--text-sm); line-height: 1.35; color: var(--color-ink-soft); }
.fruit-card.is-extra { background: var(--sua-dua-100); }

/* ---------- game: scene ---------- */
.scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky-1), var(--sky-2) 55%, var(--sky-3));
}
.scene__sky { position: absolute; inset: 0; background: radial-gradient(90% 60% at 50% 40%, rgb(255 255 255 / 0.18), rgb(255 255 255 / 0) 70%); }
.scene__top { position: absolute; top: 0; left: 0; width: 100%; height: min(32vh, 280px); }
.scene__bottom { position: absolute; left: 0; bottom: 0; width: 100%; height: min(48vh, 460px); }
.scene__particles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.scene__particles i { position: absolute; top: 0; display: block; will-change: transform, opacity; }
.scene__particles[data-kind="leaves"] i { width: 16px; height: 9px; border-radius: 100% 0; background: #6CC95A; opacity: 0.85; animation: drift-down linear infinite; }
.scene__particles[data-kind="leaves"] i:nth-child(3n) { background: #A6E875; }
.scene__particles[data-kind="petals"] i { width: 12px; height: 11px; border-radius: 70% 70% 70% 0; background: #FFB3C9; animation: drift-down linear infinite; }
.scene__particles[data-kind="petals"] i:nth-child(2n) { background: #FFD233; }
.scene__particles[data-kind="fireflies"] i { width: 6px; height: 6px; border-radius: 50%; background: #FFE27A; box-shadow: 0 0 12px 4px rgb(255 214 107 / 0.65); animation: float-up linear infinite; }
.scene__particles[data-kind="mist"] i { width: 70vw; height: 90px; border-radius: 50%; background: rgb(255 255 255 / 0.4); filter: blur(22px); animation: mist-drift linear infinite; }
.scene__particles[data-kind="sparkle"] i { width: 12px; height: 12px; background: #fff; clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); animation: twinkle ease-in-out infinite; }
@keyframes drift-down { from { transform: translate3d(0, -12vh, 0) rotate(0deg); } to { transform: translate3d(16vw, 112vh, 0) rotate(560deg); } }
@keyframes float-up { 0% { transform: translate3d(0, 105vh, 0); opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } 100% { transform: translate3d(6vw, 30vh, 0); opacity: 0; } }
@keyframes mist-drift { from { transform: translate3d(-80vw, 0, 0); } to { transform: translate3d(110vw, 0, 0); } }
@keyframes twinkle { 0%, 100% { transform: scale(0.2); opacity: 0; } 50% { transform: scale(1); opacity: 0.95; } }

/* ---------- game: layout ---------- */
.screen.game.is-active { display: grid; }
.game {
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "hud" "board" "tools";
}
.game.is-frozen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  box-shadow: inset 0 0 0 5px rgb(169 228 255 / 0.85), inset 0 0 80px rgb(169 228 255 / 0.7);
  animation: fade-in var(--dur-base) var(--ease-out);
}

.hud {
  grid-area: hud;
  position: relative;
  z-index: var(--z-hud);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) var(--space-1) max(12px, env(safe-area-inset-left));
}
.hud__panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 9px 14px 11px;
  border-radius: 22px;
  background: rgb(255 253 247 / 0.95);
  box-shadow: 0 5px 0 rgb(42 22 64 / 0.12), var(--shadow-soft);
}
.hud__row { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.hud__lv {
  flex: none;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  font: var(--weight-black) var(--text-xs)/1 var(--font-ui);
  color: var(--color-ink);
  background: var(--vang-xoai-500);
}
.hud__title { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font: 400 var(--text-lg)/1.2 var(--font-display); color: var(--color-ink); }
.hud__title .is-short { display: none; }
.hud__mode { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 10px; color: var(--ngoc-gach-bong-800); background: var(--ngoc-gach-bong-100); }
.hud__mode .icon { width: 18px; height: 18px; }
.hud__pairs { flex: none; font: var(--weight-bold) var(--text-xs)/1 var(--font-ui); color: var(--color-ink-soft); white-space: nowrap; }
.hud__score {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 78px;
  height: 64px;
  padding: 0 var(--space-3);
  border-radius: 20px;
  background: rgb(255 253 247 / 0.95);
  box-shadow: 0 5px 0 rgb(42 22 64 / 0.12), var(--shadow-soft);
}
.hud__score small { font: var(--weight-bold) 0.6875rem/1 var(--font-ui); color: var(--color-ink-soft); }
.hud__score b { font: 400 var(--text-xl)/1.15 var(--font-display); font-variant-numeric: tabular-nums; color: var(--hong-thanh-long-600); }
.hud__score.is-bump b { animation: bump 0.32s var(--ease-spring); }
@keyframes bump { 50% { transform: scale(1.25); } }

.board-wrap { grid-area: board; position: relative; z-index: var(--z-board); min-height: 0; }
.board {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 30px;
  background: var(--board-mat, rgb(255 255 255 / 0.4));
  box-shadow: inset 0 0 0 3px rgb(255 255 255 / 0.6), 0 24px 44px -26px rgb(42 22 64 / 0.55);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}
.board__lake {
  position: absolute;
  z-index: 1;
  display: grid;
  place-items: center;
  border-radius: 38%;
  background: radial-gradient(ellipse at 50% 38%, #B4EADF, #6CC0B0 62%, #4E9F92);
  box-shadow: inset 0 6px 14px rgb(15 70 64 / 0.28);
  overflow: hidden;
}
.board__lake svg { width: 52%; max-width: 150px; height: auto; }
.board.is-shuffling .tile__body { animation: shuffle-spin 0.5s var(--ease-out); }
@keyframes shuffle-spin { 40% { transform: scale(0.82) rotate(-10deg); } }
.board__links { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 400; }
.board__links .link-glow { fill: none; stroke-linecap: round; stroke-linejoin: round; opacity: 0.45; }
.board__links .link-core { fill: none; stroke: #fff; stroke-linecap: round; stroke-linejoin: round; }
.board__links .link-dot { fill: #fff; }
.board__links g { animation: link-out 0.42s var(--ease-in) 0.18s forwards; }
@keyframes link-out { to { opacity: 0; } }

.tools {
  grid-area: tools;
  position: relative;
  z-index: var(--z-hud);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: var(--space-6);
  padding: var(--space-2) var(--space-4) max(14px, env(safe-area-inset-bottom));
}

/* floating feedback over the board */
.pop {
  position: absolute;
  z-index: 450;
  pointer-events: none;
  font: 400 1.35rem/1 var(--font-display);
  color: var(--vang-xoai-500);
  text-shadow: 0 2px 0 var(--muc-tim-800), 2px 0 0 var(--muc-tim-800), -2px 0 0 var(--muc-tim-800), 0 -2px 0 var(--muc-tim-800), 2px 2px 0 var(--muc-tim-800), -2px 2px 0 var(--muc-tim-800), 0 5px 0 rgb(42 22 64 / 0.3);
  transform: translate(-50%, -50%);
  animation: pop-up 0.9s var(--ease-out) forwards;
}
@keyframes pop-up { 0% { transform: translate(-50%, -30%) scale(0.6); opacity: 0; } 20% { transform: translate(-50%, -60%) scale(1.15); opacity: 1; } 100% { transform: translate(-50%, -190%) scale(1); opacity: 0; } }
.combo {
  position: absolute;
  left: 50%;
  top: 4%;
  z-index: 460;
  pointer-events: none;
  white-space: nowrap;
  font: 400 clamp(1.9rem, 7vw, 3rem)/1 var(--font-display);
  color: #fff;
  text-shadow: 0 3px 0 var(--hong-thanh-long-600), 3px 0 0 var(--hong-thanh-long-600), -3px 0 0 var(--hong-thanh-long-600), 0 -3px 0 var(--hong-thanh-long-600), 3px 3px 0 var(--hong-thanh-long-600), -3px 3px 0 var(--hong-thanh-long-600), 0 8px 0 var(--muc-tim-800);
  animation: combo-in 1.2s var(--ease-out) forwards;
}
.combo small { display: block; margin-top: 4px; font-size: 0.5em; text-align: center; color: var(--vang-xoai-300); }
@keyframes combo-in {
  0% { transform: translateX(-50%) scale(0.3) rotate(-8deg); opacity: 0; }
  18% { transform: translateX(-50%) scale(1.15) rotate(3deg); opacity: 1; }
  30% { transform: translateX(-50%) scale(1) rotate(0); }
  80% { opacity: 1; }
  100% { transform: translateX(-50%) translateY(-24px) scale(0.95); opacity: 0; }
}

/* tutorial coach */
.coach {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 470;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  width: max-content;
  max-width: min(92vw, 380px);
  transform: translateX(var(--coach-x, -50%));
  pointer-events: none;
  animation: coach-in var(--dur-slow) var(--ease-spring);
}
@keyframes coach-in {
  from { transform: translateX(var(--coach-x, -50%)) translateY(20px) scale(0.9); opacity: 0; }
  to { transform: translateX(var(--coach-x, -50%)); opacity: 1; }
}
.coach .mascot { flex: none; width: 70px; height: auto; }
.coach__bubble {
  position: relative;
  margin-bottom: 26px;
  padding: 10px 14px;
  border-radius: 18px 18px 18px 4px;
  font: var(--weight-bold) var(--text-sm)/1.4 var(--font-ui);
  background: #fff;
  box-shadow: var(--shadow-float);
}

/* ---------- landscape / desktop: tools move to a right-hand column ---------- */
@media (min-aspect-ratio: 1/1) and (min-width: 700px) {
  .game {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "hud hud" "board tools";
  }
  .tools { flex-direction: column; justify-content: center; align-items: center; gap: var(--space-5); padding: 0 max(24px, env(safe-area-inset-right)) var(--space-6) var(--space-2); }
}
/* ---------- landscape phones: the HUD becomes a left rail and the tools a right rail,
   so the board gets the whole height of the screen ---------- */
@media (min-aspect-ratio: 1/1) and (max-height: 540px) {
  .game {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "hud board tools";
  }
  .hud {
    flex-direction: column;
    align-items: stretch;
    width: calc(94px + env(safe-area-inset-left));
    max-width: none;
    height: 100%;
    margin: 0;
    padding: max(8px, env(safe-area-inset-top)) 4px max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    gap: 6px;
  }
  .hud > .icon-btn { flex: none; width: 44px; height: 44px; border-radius: 15px; align-self: center; }
  .hud__panel { flex: 1; min-height: 0; align-items: center; padding: 8px 6px; gap: 6px; border-radius: 18px; }
  .hud__row { flex: none; flex-direction: column; gap: 3px; width: 100%; }
  .hud__title { flex: none; width: 100%; white-space: normal; text-align: center; font-size: 0.8125rem; line-height: 1.15; }
  .hud__title .is-full { display: none; }
  .hud__title .is-short { display: inline; }
  .hud__pairs { display: block; }
  .hud__mode { display: none; }
  .hud .timer { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
  .hud .timer > .icon { flex: none; }
  .hud .timer__track { flex: 1; min-height: 40px; width: 12px; height: auto; }
  .hud .timer__fill { transform-origin: center bottom; transform: scaleY(var(--p, 1)); background: linear-gradient(90deg, #5FE0B0, var(--la-chuoi-500)); }
  .hud .timer.is-mid .timer__fill { background: linear-gradient(90deg, #FFDB5C, var(--vang-xoai-600)); }
  .hud .timer.is-low .timer__fill { background: linear-gradient(90deg, #FF8A7A, var(--do-den-long-500)); }
  .hud .timer.is-frozen .timer__fill { background: linear-gradient(90deg, #A9E4FF, var(--tra-da-500)); }
  .hud .timer__mark { left: 2px; right: 2px; top: auto; bottom: var(--m); width: auto; height: 2px; }
  .hud .timer__text { flex: none; min-width: 0; text-align: center; font-size: 0.875rem; }
  .hud__score { flex: none; width: 100%; min-width: 0; height: 50px; padding: 0 4px; border-radius: 16px; }
  .hud__score b { font-size: 1.1rem; }
  .tools {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) 4px;
  }
  .tool__face { width: 52px; height: 52px; border-radius: 17px; }
  .tool .pu-art { width: 34px; height: 34px; }
  .tool .badge { min-width: 22px; height: 22px; padding: 0 6px; font-size: 0.75rem; top: -6px; right: -6px; }
  .tool--mini .tool__face { width: 40px; height: 40px; border-radius: 14px; }
  .tool__label { display: none; }
}
@media (min-aspect-ratio: 1/1) and (max-height: 360px) {
  .hud__pairs { display: none; }
  .tools { gap: 6px; }
}
/* ---------- portrait phones: slimmer HUD and tool bar, more room for the board ---------- */
@media (max-width: 600px) and (orientation: portrait) {
  .hud { gap: var(--space-2); padding: max(8px, env(safe-area-inset-top)) 10px 2px; }
  .hud > .icon-btn { width: 44px; height: 44px; border-radius: 15px; }
  .hud__panel { padding: 7px 11px 8px; gap: 5px; border-radius: 18px; }
  .hud__score { min-width: 64px; height: 52px; padding: 0 8px; border-radius: 16px; }
  .hud__score b { font-size: 1.15rem; }
  .tools { gap: var(--space-4); padding: 2px 10px max(8px, env(safe-area-inset-bottom)); }
  .tool { gap: 4px; }
  .tool__face { width: 54px; height: 54px; border-radius: 18px; }
  .tool .pu-art { width: 36px; height: 36px; }
  .tool .badge { min-width: 22px; height: 22px; padding: 0 6px; font-size: 0.75rem; top: -6px; right: -6px; }
  .tool__label { font-size: 0.6875rem; padding: 1px 8px; }
  .tool--mini .tool__face { width: 44px; height: 44px; border-radius: 15px; }
}
@media (max-width: 560px) {
  .hud__title { font-size: var(--text-md); }
  .hud__title .is-full { display: none; }
  .hud__title .is-short { display: inline; }
  .hud__mode,
  .hud__pairs { display: none; }
}
/* small phones */
@media (max-width: 380px) {
  .hud { gap: var(--space-2); }
  .hud__score { min-width: 64px; }
  .tools { gap: var(--space-4); }
}

@media (prefers-reduced-motion: reduce) {
  .scene__particles { display: none; }
  .home__floaters .fruit,
  .home__mascot .mascot { animation: none; }
}

/* ---------- level intro (postcard dialog) ---------- */
.intro__view {
  position: relative;
  height: 150px;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky-1), var(--sky-2) 60%, var(--sky-3));
}
.intro__view .scene__bottom { position: absolute; inset: 0; width: 100%; height: 100%; }
.intro__view .scene__top { position: absolute; left: 0; top: 0; width: 100%; height: 60%; }
.intro__num {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  margin: -30px auto 0;
  border-radius: 50%;
  font: 400 1.9rem/1 var(--font-display);
  color: var(--color-ink);
  background: var(--vang-xoai-500);
  box-shadow: 0 0 0 5px #fff, 0 8px 14px rgb(42 22 64 / 0.3);
}
.intro__body { padding: var(--space-3) var(--space-6) 0; }
/* the start button stays in reach while the card scrolls on short screens */
.modal__card--postcard .modal__actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin: 0 calc(var(--space-6) * -1);
  padding: var(--space-4) var(--space-6) var(--space-5);
  background: linear-gradient(rgb(255 253 247 / 0), var(--color-surface) 32%);
}
.modal__card--postcard { padding-bottom: 0; }
/* shorter portrait phones: the mascot sits inside the card and everything tightens */
@media (max-height: 760px) and (orientation: portrait) {
  .modal__card:has(.modal__art) { margin-top: 0; overflow: auto; padding-top: var(--space-4); }
  .modal__art { width: 96px; margin: 0 auto var(--space-1); }
  .modal__art .mascot { width: 96px; }
  .modal__title { font-size: var(--text-2xl); }
  .stars--lg .star { width: 50px; height: 50px; }
  .stars--lg .star:nth-child(2) { width: 62px; height: 62px; transform: translateY(-10px); }
  @keyframes star-in-mid { 0% { transform: translateY(-10px) scale(0); } 100% { transform: translateY(-10px) scale(1); } }
  .score-table { margin: var(--space-3) 0; gap: 4px; }
  .score-table > div { padding: 6px 12px; }
  .score-table .is-total dd { font-size: var(--text-xl); }
  .settings-row { margin: var(--space-3) 0; }
  .toggle { min-height: 48px; }
}
/* short screens (phones held sideways): wider, lower dialogs */
@media (max-height: 480px) {
  .modal { padding: 8px; }
  .modal__card { width: min(100%, 640px); max-height: calc(100dvh - 16px); padding: var(--space-4) var(--space-5); }
  .modal__card:has(.modal__art) { margin-top: 0; overflow: auto; }
  .modal__art { width: 64px; margin: 0 auto; }
  .modal__art .mascot { width: 64px; }
  .modal__title { font-size: var(--text-2xl); margin-bottom: var(--space-1); }
  .modal__text { margin-bottom: var(--space-3); }
  .stars--lg .star { width: 42px; height: 42px; }
  .stars--lg .star:nth-child(2) { width: 52px; height: 52px; transform: translateY(-8px); }
  @keyframes star-in-mid { 0% { transform: translateY(-8px) scale(0); } 100% { transform: translateY(-8px) scale(1); } }
  .score-table { grid-template-columns: 1fr 1fr; margin: var(--space-3) 0; }
  .settings-row { margin: var(--space-2) 0 var(--space-3); }
  .toggle { min-height: 46px; }
  .modal__actions .btn { min-height: 48px; font-size: 1rem; }
  .modal__card--postcard { padding: 0; }
  .intro__view { display: none; }
  .intro__num { margin: 14px auto 0; width: 44px; height: 44px; font-size: 1.4rem; box-shadow: 0 0 0 4px #fff, 0 6px 10px rgb(42 22 64 / 0.25); }
  .intro__body { padding: var(--space-1) var(--space-5) 0; }
  .intro__body .modal__title { font-size: 1.5rem; }
  .intro__facts { grid-template-columns: 1fr 1fr; }
  .intro__new > p { display: none; }
  .intro__fruits figure { width: 52px; }
  .intro__fruits .fruit { width: 36px; height: 36px; }
  .modal__card--postcard .modal__actions { margin: 0 calc(var(--space-5) * -1); padding: var(--space-3) var(--space-5) var(--space-4); }
  .intro__num { display: none; }
  .intro__body { padding-top: var(--space-4); }
  /* win: mascot, title and stars on the left; score and buttons on the right */
  .modal__card:has(.score-table) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
    grid-template-areas: "art table" "eyebrow table" "title table" "stars actions";
    column-gap: var(--space-5);
    align-items: center;
  }
  .modal__card:has(.score-table) .modal__art { grid-area: art; }
  .modal__card:has(.score-table) .modal__eyebrow { grid-area: eyebrow; }
  .modal__card:has(.score-table) .modal__title { grid-area: title; }
  .modal__card:has(.score-table) .stars { grid-area: stars; justify-content: center; }
  .modal__card:has(.score-table) .score-table { grid-area: table; grid-template-columns: 1fr; margin: 0; }
  .modal__card:has(.score-table) .modal__actions { grid-area: actions; }
  /* pause: same idea with the sound switches */
  .modal__card:has(.modal__art):has(.settings-row) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
    grid-template-areas: "art settings" "eyebrow settings" "title actions" "text actions";
    column-gap: var(--space-5);
    align-items: center;
  }
  .modal__card:has(.modal__art):has(.settings-row) .modal__art { grid-area: art; }
  .modal__card:has(.modal__art):has(.settings-row) .modal__eyebrow { grid-area: eyebrow; }
  .modal__card:has(.modal__art):has(.settings-row) .modal__title { grid-area: title; }
  .modal__card:has(.modal__art):has(.settings-row) .modal__text { grid-area: text; margin: 0; }
  .modal__card:has(.modal__art):has(.settings-row) .settings-row { grid-area: settings; margin: 0; }
  .modal__card:has(.modal__art):has(.settings-row) .modal__actions { grid-area: actions; }
}
@media (max-height: 760px) {
  .intro__view { height: 104px; }
  .intro__num { width: 52px; height: 52px; margin-top: -26px; font-size: 1.6rem; }
  .intro__body .modal__title { font-size: 1.6rem; }
  .intro__body .modal__text { font-size: 0.9375rem; margin-bottom: var(--space-3); }
  .intro__facts { gap: 6px; margin-bottom: var(--space-3); }
  .intro__facts li { padding: 8px 10px; }
  .intro__facts li > .icon { width: 30px; height: 30px; padding: 6px; }
  .intro__fruits .fruit { width: 42px; height: 42px; }
}
.intro__body .modal__title { font-size: var(--text-2xl); }
.intro__body .modal__text { margin-bottom: var(--space-4); }
.intro__facts { display: grid; gap: var(--space-2); margin: 0 0 var(--space-5); padding: 0; list-style: none; text-align: left; }
.intro__facts li {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-surface-sunken);
  font-size: var(--text-sm);
  line-height: 1.4;
  color: var(--color-ink-soft);
}
.intro__facts li > .icon { flex: none; width: 34px; height: 34px; padding: 7px; border-radius: 12px; color: var(--ngoc-gach-bong-800); background: #fff; }
.intro__facts b { display: block; font-size: var(--text-md); color: var(--color-ink); }
.intro__new { margin: 0 0 var(--space-5); }
.intro__new > p { margin: 0 0 var(--space-2); font: var(--weight-bold) var(--text-sm)/1.2 var(--font-ui); color: var(--color-ink-soft); }
.intro__fruits { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); }
.intro__fruits figure { display: flex; flex-direction: column; align-items: center; width: 64px; margin: 0; }
.intro__fruits .fruit { width: 50px; height: 50px; }
.intro__fruits figcaption { font: var(--weight-bold) var(--text-xs)/1.2 var(--font-ui); color: var(--color-ink); text-align: center; }

/* ---------- win score table ---------- */
.score-table { display: grid; gap: 6px; margin: var(--space-5) 0; text-align: left; }
.score-table > div { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: 8px 14px; border-radius: 14px; background: var(--color-surface-sunken); }
.score-table dt { display: flex; align-items: center; gap: 8px; font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-ink-soft); }
.score-table dd { margin: 0; font: 400 var(--text-lg)/1 var(--font-display); font-variant-numeric: tabular-nums; color: var(--color-ink); }
.score-table .is-total { background: var(--vang-xoai-100); }
.score-table .is-total dt { color: var(--color-ink); font-weight: var(--weight-black); }
.score-table .is-total dd { font-size: var(--text-2xl); color: var(--hong-thanh-long-600); }
.settings-row { margin: var(--space-4) 0 var(--space-5); }


/* ---------- coach position ---------- */
.game > .coach { left: 50%; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 104px); }
@media (min-aspect-ratio: 1/1) and (min-width: 700px) {
  .game > .coach { left: 20px; bottom: 20px; --coach-x: 0; flex-direction: column; align-items: flex-start; max-width: 200px; }
  .game > .coach .coach__bubble { margin: 0; border-radius: 4px 18px 18px 18px; }
}
@media (min-aspect-ratio: 1/1) and (max-height: 540px) {
  .game > .coach { left: calc(104px + env(safe-area-inset-left)); bottom: 6px; --coach-x: 0; max-width: 42vw; }
  .game > .coach .mascot { display: none; }
  .game > .coach .coach__bubble { margin: 0; padding: 7px 12px; font-size: 0.8125rem; border-radius: 14px; }
}
