:root {
  color-scheme: light;
  --sky: #62c6e8;
  --navy: #14324a;
  --paper: #fffdf8;
  --ink: #173042;
  --muted: #637985;
  --line: rgba(23, 48, 66, 0.13);
  --coral: #ff7667;
  --coral-dark: #c9473c;
  --yellow: #ffd65a;
  --yellow-dark: #a96800;
  --mint: #4fd2a1;
  --mint-dark: #087352;
  --blue: #6aaefc;
  --blue-dark: #195ba9;
  --purple: #9a7cf6;
  --purple-dark: #5a3fba;
  --shadow: 0 10px 0 rgba(20, 50, 74, 0.12);
  --safe-top: max(14px, env(safe-area-inset-top));
  --safe-right: max(18px, env(safe-area-inset-right));
  --safe-bottom: max(14px, env(safe-area-inset-bottom));
  --safe-left: max(18px, env(safe-area-inset-left));
}

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

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  background: var(--sky);
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  letter-spacing: 0;
  user-select: none;
  -webkit-user-select: none;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 4px solid var(--yellow);
  outline-offset: 3px;
}

.game-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 620px;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  overflow: hidden;
}

.game-shell::before,
.game-shell::after {
  position: absolute;
  z-index: -1;
  border: 3px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
  content: "";
}

.game-shell::before {
  width: 240px;
  height: 240px;
  right: -80px;
  top: 70px;
}

.game-shell::after {
  width: 110px;
  height: 110px;
  left: 3%;
  bottom: -44px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(350px, 1fr) minmax(320px, 520px) auto;
  align-items: center;
  gap: 16px;
  height: 58px;
  max-width: 1360px;
  margin: 0 auto 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #0b405c;
  font-weight: 900;
  transition: opacity 220ms ease, transform 320ms ease;
}

.brand-title {
  position: relative;
  line-height: 1;
  white-space: nowrap;
  transform: rotate(-1deg);
}

.brand-title strong {
  color: var(--navy);
  font-size: clamp(29px, 4.1vh, 39px);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.55);
}

.brand-title em {
  position: absolute;
  left: calc(100% + 6px);
  bottom: 0;
  padding: 2px 5px;
  border: 1px solid rgba(20, 50, 74, 0.18);
  border-radius: 6px;
  color: #2e667e;
  background: rgba(255, 255, 255, 0.45);
  font-size: 9px;
  font-style: normal;
  white-space: nowrap;
}

.game-shell.is-mode-selecting .brand {
  opacity: 0;
  transform: translateY(10px);
}

.brand.is-settling {
  animation: title-settle 420ms ease-out both;
}

.brand-mark,
.modal-brand {
  display: grid;
  width: 38px;
  aspect-ratio: 1;
  place-items: center;
  border: 2px solid rgba(20, 50, 74, 0.15);
  border-radius: 50%;
  color: var(--yellow-dark);
  background: var(--yellow);
  box-shadow: 0 4px 0 rgba(20, 50, 74, 0.12);
}

.round-status {
  display: grid;
  grid-template-columns: auto auto minmax(90px, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 7px 12px;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 16px;
  color: #0b405c;
  background: rgba(255, 255, 255, 0.32);
}

.mode-chip {
  padding: 3px 8px;
  border-radius: 999px;
  color: #073d56;
  background: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
  font-size: 12px;
  font-weight: 900;
}

.timer {
  min-width: 58px;
  font-size: 19px;
  font-variant-numeric: tabular-nums;
}

.timer.is-urgent {
  color: var(--coral-dark);
  animation: timer-pulse 600ms ease infinite alternate;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border: 2px solid rgba(20, 50, 74, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--coral);
  transition: width 300ms ease;
}

.target-value {
  white-space: nowrap;
  font-size: 12px;
  font-weight: 900;
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

.icon-button,
.close-button {
  display: grid;
  width: 44px;
  aspect-ratio: 1;
  padding: 0;
  place-items: center;
  border: 2px solid rgba(20, 50, 74, 0.14);
  border-radius: 14px;
  color: #174f6a;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 5px 0 rgba(20, 50, 74, 0.12);
  cursor: pointer;
  font-size: 23px;
  font-weight: 900;
}

.icon-button:active,
.close-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(20, 50, 74, 0.12);
}

.icon-button.is-muted {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.45);
}

.game-stage {
  display: grid;
  grid-template-columns: minmax(560px, 1.3fr) minmax(310px, 0.7fr);
  grid-template-areas:
    "board stats"
    "board mission"
    "board feedback"
    "board actions";
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: clamp(22px, 3vw, 50px);
  align-items: center;
  width: min(1260px, 100%);
  height: calc(100% - 64px);
  margin: 0 auto;
}

.board-zone {
  grid-area: board;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  align-items: center;
  justify-items: center;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.equation-workbench {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 102px;
  overflow: hidden;
}

.operator-bank {
  display: flex;
  justify-content: center;
  gap: 12px;
  height: 32px;
}

.operator-token {
  display: grid;
  width: 34px;
  height: 28px;
  place-items: center;
  overflow: hidden;
  border: 2px solid rgba(20, 50, 74, 0.15);
  border-radius: 9px;
  color: var(--navy);
  background: rgba(255, 255, 255, 0.68);
  box-shadow: 0 3px 0 rgba(20, 50, 74, 0.1);
  font-size: 23px;
  font-weight: 900;
  line-height: 1;
}

.operator-token.is-launching {
  animation: operator-launch 300ms ease both;
}

.difficulty-badge {
  display: grid;
  min-width: 112px;
  height: 28px;
  padding: 0 10px;
  place-items: center;
  border: 2px solid rgba(20, 50, 74, 0.15);
  border-radius: 9px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.68);
  box-shadow: 0 3px 0 rgba(20, 50, 74, 0.1);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.difficulty-badge.has-bonus {
  border-color: var(--coral-dark);
  color: #692018;
  background: var(--coral);
}

.difficulty-badge.is-celebrating {
  animation: difficulty-badge-pop 430ms cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
}

.equation-display {
  --equation-display-gap: clamp(5px, 0.8vw, 10px);
  --equation-expression-gap: clamp(4px, 0.7vw, 9px);
  --equation-slot-size: clamp(46px, 6.5vh, 64px);
  --equation-operator-width: 30px;
  --equation-equals-size: clamp(42px, 5.5vh, 54px);
  --equation-font-size: clamp(23px, 3.2vh, 36px);
  position: relative;
  display: grid;
  min-width: 0;
  place-items: center;
  width: 100%;
  max-width: 100%;
  min-height: 68px;
  padding: 5px 8px;
  overflow: hidden;
  color: #12384e;
  font-size: var(--equation-font-size);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.equation-content {
  position: absolute;
  display: flex;
  width: max-content;
  max-width: none;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: var(--equation-display-gap);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(var(--equation-scale, 1));
  transform-origin: center;
}

.equation-display[data-density="medium"] {
  --equation-display-gap: 6px;
  --equation-expression-gap: 5px;
  --equation-slot-size: clamp(42px, 5.8vh, 56px);
  --equation-operator-width: 26px;
  --equation-equals-size: 46px;
  --equation-font-size: clamp(22px, 2.9vh, 32px);
}

.equation-display[data-density="compact"] {
  --equation-display-gap: 4px;
  --equation-expression-gap: 3px;
  --equation-slot-size: clamp(38px, 5vh, 48px);
  --equation-operator-width: 22px;
  --equation-equals-size: 40px;
  --equation-font-size: clamp(20px, 2.6vh, 29px);
}

.equation-display[data-density="dense"] {
  --equation-display-gap: 3px;
  --equation-expression-gap: 2px;
  --equation-slot-size: 36px;
  --equation-operator-width: 22px;
  --equation-equals-size: 34px;
  --equation-font-size: 21px;
}

.operand-expression {
  display: flex;
  width: max-content;
  max-width: none;
  min-width: 0;
  flex: 0 0 auto;
  gap: var(--equation-expression-gap);
  align-items: center;
  justify-content: center;
  padding: 5px 3px 9px;
  overflow: visible;
}

.expression-placeholder {
  color: rgba(20, 50, 74, 0.55);
  font-size: 15px;
  text-align: center;
  white-space: nowrap;
}

.equation-slot {
  display: grid;
  width: var(--equation-slot-size);
  min-width: 0;
  flex: 0 0 auto;
  aspect-ratio: 1;
  place-items: center;
  overflow: hidden;
  border: 3px solid rgba(20, 50, 74, 0.16);
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 5px 0 rgba(20, 50, 74, 0.12);
  font-size: var(--equation-font-size);
  line-height: 1;
}

.equation-slot.is-digraph {
  font-size: calc(var(--equation-font-size) * 0.78);
}

.equation-slot.is-filled {
  border-color: var(--yellow-dark);
  color: #533900;
  background: var(--yellow);
}

.equation-slot.is-correct {
  border-color: var(--mint-dark);
  color: #053f2f;
  background: var(--mint);
}

.result-slot.is-awaiting {
  border-color: var(--purple-dark);
  background: #e8e0ff;
  animation: result-awaiting 650ms ease infinite alternate;
}

.operator-gap {
  display: grid;
  width: var(--equation-operator-width);
  height: var(--equation-slot-size);
  flex: 0 0 var(--equation-operator-width);
  place-items: center;
  overflow: hidden;
  color: rgba(20, 50, 74, 0.35);
  font-size: var(--equation-font-size);
  line-height: 1;
}

.operator-gap.is-filled {
  color: var(--navy);
  animation: operator-land 300ms cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.equation-equals {
  display: grid;
  width: var(--equation-equals-size);
  flex: 0 0 auto;
  aspect-ratio: 1;
  place-items: center;
  color: rgba(20, 50, 74, 0.32);
  overflow: hidden;
  font-size: calc(var(--equation-font-size) * 1.2);
  font-weight: 900;
  transition: color 180ms ease, transform 180ms ease;
}

.equation-equals.is-confirmed {
  color: var(--purple-dark);
  transform: scale(1.14);
  animation: operator-land 300ms cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.equation-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-height: 62px;
  align-items: center;
  gap: 10px;
}

.side-equation-actions {
  grid-area: actions;
}

.equation-action {
  display: flex;
  width: 100%;
  min-width: 0;
  height: 58px;
  padding: 0 10px;
  gap: 8px;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(20, 50, 74, 0.15);
  border-radius: 12px;
  box-shadow: 0 4px 0 rgba(20, 50, 74, 0.14);
  cursor: pointer;
  font-weight: 900;
}

.equation-action > span {
  font-size: 28px;
  line-height: 1;
}

.equation-action small {
  font-size: 15px;
  font-weight: 900;
}

.equation-action b {
  display: inline-grid;
  min-width: 18px;
  height: 18px;
  margin-left: 2px;
  padding: 0 4px;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: var(--navy);
  font-size: 11px;
}

.confirm-equation-button {
  border-color: var(--blue-dark);
  color: #103b70;
  background: var(--blue);
}

.clear-equation-button {
  border-color: var(--coral-dark);
  color: #6b1f18;
  background: var(--coral);
}

.refresh-board-button {
  border-color: var(--mint-dark);
  color: #064c38;
  background: var(--mint);
}

.equation-action:disabled {
  border-color: rgba(20, 50, 74, 0.15);
  color: rgba(20, 50, 74, 0.35);
  background: rgba(255, 255, 255, 0.5);
  box-shadow: 0 4px 0 rgba(20, 50, 74, 0.1);
  cursor: default;
}

.equation-action:disabled b {
  background: rgba(20, 50, 74, 0.25);
}

.equation-action:not(:disabled):active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(20, 50, 74, 0.14);
}

.board-frame {
  position: relative;
  width: min(100%, 63vh);
  min-width: 0;
  max-width: 620px;
  aspect-ratio: 1;
  padding: clamp(10px, 1.4vh, 15px);
  border: 4px solid rgba(20, 50, 74, 0.16);
  border-radius: 26px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.board {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: clamp(6px, 0.85vh, 9px);
  width: 100%;
  height: 100%;
}

.number-tile {
  position: relative;
  display: grid;
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  place-items: center;
  border: 3px solid rgba(20, 50, 74, 0.13);
  border-radius: 18px;
  color: var(--tile-ink);
  background: var(--tile-color);
  box-shadow: inset 0 -6px 0 rgba(20, 50, 74, 0.12), 0 2px 0 rgba(20, 50, 74, 0.08);
  cursor: pointer;
  font-size: clamp(21px, 4.1vh, 39px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  overflow: hidden;
  touch-action: manipulation;
}

.game-shell.is-word-mode .number-tile {
  font-size: clamp(20px, 3.7vh, 35px);
  text-transform: lowercase;
}

.game-shell.is-word-mode .operator-token {
  position: relative;
  overflow: visible;
  font-size: 16px;
  text-transform: lowercase;
}

.game-shell.is-word-mode #minusToken::before {
  position: absolute;
  top: 5px;
  width: 12px;
  left: -12px;
  color: var(--navy);
  content: "＋";
  font-size: 13px;
  text-align: center;
}

.game-shell.is-word-mode .mission-copy h1 {
  max-width: none;
  font-size: 28px;
  white-space: nowrap;
}

.game-shell.is-word-mode .equation-content {
  gap: 0;
}

.game-shell.is-word-mode .operand-expression {
  gap: clamp(3px, 0.55vw, 7px);
}

.game-shell.is-word-mode .equation-equals,
.game-shell.is-word-mode .result-slot {
  display: none;
}

.number-tile::after {
  position: absolute;
  width: 14%;
  aspect-ratio: 1;
  left: 13%;
  top: 12%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.42);
  content: "";
}

.number-tile[data-color="coral"] {
  --tile-color: var(--coral);
  --tile-ink: #5f1712;
}

.number-tile[data-color="yellow"] {
  --tile-color: var(--yellow);
  --tile-ink: #5a3b00;
}

.number-tile[data-color="mint"] {
  --tile-color: var(--mint);
  --tile-ink: #084b38;
}

.number-tile[data-color="blue"] {
  --tile-color: var(--blue);
  --tile-ink: #123f75;
}

.number-tile[data-color="purple"] {
  --tile-color: var(--purple);
  --tile-ink: #372272;
}

.number-tile.is-selected {
  z-index: 2;
  border-color: #fff;
  outline: 4px solid var(--navy);
  outline-offset: -1px;
  transform: translateY(-5px) scale(1.04);
  box-shadow: inset 0 -4px 0 rgba(20, 50, 74, 0.12), 0 9px 0 rgba(20, 50, 74, 0.2);
}

.number-tile.is-result {
  outline-color: var(--purple-dark);
}

.number-tile.is-removing {
  pointer-events: none;
  animation: tile-remove 300ms ease-in both;
}

.number-tile.is-wrong {
  border-color: var(--coral-dark);
  animation: tile-shake 320ms ease both;
}

.number-tile.is-dropping {
  animation: tile-drop 280ms cubic-bezier(0.2, 0.9, 0.3, 1.12) both;
}

.burst-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.burst-star {
  position: absolute;
  z-index: 5;
  color: var(--yellow-dark);
  font-size: 26px;
  font-weight: 900;
  animation: star-burst 620ms ease-out both;
}

.input-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 24px;
  color: rgba(20, 50, 74, 0.55);
  font-size: 12px;
  font-weight: 900;
}

.input-steps i {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: rgba(20, 50, 74, 0.2);
}

.input-steps span {
  padding: 3px 8px;
  border-radius: 999px;
}

.input-steps span.is-active {
  color: var(--navy);
  background: var(--yellow);
}

.side-zone {
  display: contents;
}

.mission-panel {
  grid-area: mission;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(140px, 0.82fr);
  align-items: center;
  min-height: 250px;
  padding: 22px 6px 16px 26px;
  border: 4px solid rgba(20, 50, 74, 0.14);
  border-radius: 26px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.eyebrow {
  color: var(--coral-dark);
  font-size: 14px;
  font-weight: 900;
}

.mission-copy h1 {
  max-width: 245px;
  margin: 8px 0 18px;
  color: var(--navy);
  font-size: clamp(25px, 2.8vw, 36px);
  line-height: 1.18;
  letter-spacing: 0;
}

.score-pop {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  padding: 5px 12px;
  border: 2px solid var(--yellow-dark);
  border-radius: 999px;
  color: #5a3b00;
  background: var(--yellow);
  font-size: 14px;
  font-weight: 900;
}

.score-pop.is-bumping {
  animation: score-bump 320ms ease both;
}

.mascot {
  min-width: 0;
  align-self: end;
}

.mascot svg {
  display: block;
  width: 100%;
  max-width: 220px;
  overflow: visible;
}

.planet-body {
  fill: var(--purple);
  stroke: var(--purple-dark);
  stroke-width: 5;
}

.planet-spot {
  fill: #c4b2ff;
}

.planet-ring-back,
.planet-ring-front {
  fill: none;
  stroke: var(--coral);
  stroke-linecap: round;
  stroke-width: 14;
}

.planet-ring-front {
  stroke: var(--yellow);
}

.face-eye,
.face-mouth {
  fill: none;
  stroke: #382274;
  stroke-linecap: round;
  stroke-width: 7;
}

.satellite {
  fill: var(--yellow);
  stroke: var(--yellow-dark);
  stroke-width: 4;
}

.spark {
  fill: none;
  stroke: var(--coral-dark);
  stroke-linecap: round;
  stroke-width: 6;
}

.mascot.is-happy {
  animation: mascot-hop 520ms ease both;
}

.mascot.is-super-happy {
  animation: mascot-super-hop 720ms cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}

.equation-display.is-difficulty-win {
  animation: difficulty-win 620ms ease both;
}

.stats-strip {
  grid-area: stats;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
  border: 3px solid rgba(20, 50, 74, 0.14);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 7px 0 rgba(20, 50, 74, 0.1);
}

.stats-strip > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  padding: 12px 7px;
}

.stats-strip > div + div {
  border-left: 2px solid var(--line);
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stats-strip strong {
  color: var(--navy);
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.stats-strip small {
  margin-left: 2px;
  color: var(--coral-dark);
  font-size: 13px;
}

.feedback {
  grid-area: feedback;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 56px;
  padding: 11px 16px;
  border: 3px solid rgba(20, 50, 74, 0.14);
  border-radius: 18px;
  color: var(--navy);
  background: rgba(255, 255, 255, 0.82);
  font-size: 17px;
  font-weight: 900;
}

.feedback-icon {
  color: var(--yellow-dark);
  font-size: 22px;
}

.feedback.is-success {
  border-color: var(--mint-dark);
  color: var(--mint-dark);
}

.feedback.is-error {
  border-color: var(--coral-dark);
  color: var(--coral-dark);
}

.modal {
  position: fixed;
  z-index: 30;
  width: min(460px, calc(100vw - 40px));
  left: 50%;
  top: 50%;
  padding: 28px;
  border: 4px solid var(--navy);
  border-radius: 26px;
  text-align: center;
  background: var(--paper);
  box-shadow: 0 14px 0 rgba(20, 50, 74, 0.25);
  transform: translate(-50%, -50%);
}

.modal[hidden],
.dialog-backdrop[hidden],
.icon-button[hidden] {
  display: none;
}

.modal-brand {
  width: 48px;
  margin: 0 auto;
  font-size: 25px;
}

.modal h2 {
  margin: 14px 0 18px;
  color: var(--navy);
  font-size: 32px;
}

.mode-modal {
  width: min(860px, calc(100vw - 40px));
  max-height: min(94dvh, 900px);
  overflow-y: auto;
}

.mode-game-title {
  display: flex;
  margin: 0 0 8px;
  align-items: flex-end;
  justify-content: center;
  color: var(--navy);
  font-size: clamp(34px, 6vw, 54px);
  line-height: 1.15;
  letter-spacing: 0;
  white-space: nowrap;
}

.mode-game-title span {
  display: inline-block;
  text-shadow: 0 4px 0 var(--yellow), 0 7px 0 rgba(20, 50, 74, 0.12);
  animation: title-character-hop 900ms ease-in-out infinite;
  animation-delay: calc(var(--char-index) * 90ms);
}

.mode-game-title span:nth-child(3n + 1) {
  color: var(--coral-dark);
}

.mode-game-title span:nth-child(3n + 2) {
  color: var(--navy);
}

.mode-game-title span:nth-child(3n) {
  color: var(--purple-dark);
}

.mode-modal h2 {
  margin: 10px 0 16px;
  font-size: 24px;
}

.home-summary {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(220px, 0.55fr);
  gap: 18px;
  padding: 14px 0 18px;
  border-top: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
}

.daily-panel {
  min-width: 0;
  text-align: left;
}

.daily-heading,
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.daily-heading h2,
.modal-head h2 {
  margin: 2px 0 10px;
  font-size: 23px;
}

.daily-date {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

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

.daily-mission {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  min-height: 50px;
  padding: 7px 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #f3f6f7;
}

.daily-mission > span {
  grid-row: 1 / 3;
  color: var(--muted);
  font-size: 20px;
  font-weight: 900;
}

.daily-mission strong {
  color: var(--navy);
  font-size: 13px;
}

.daily-mission small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.daily-mission.is-done {
  border-color: var(--mint-dark);
  background: #e1f8ef;
}

.daily-mission.is-done > span {
  color: var(--mint-dark);
}

.chest-button {
  display: grid;
  grid-template-columns: 42px 1fr;
  width: 100%;
  min-height: 58px;
  margin-top: 8px;
  padding: 7px 12px;
  align-items: center;
  border: 2px solid rgba(169, 104, 0, 0.35);
  border-radius: 8px;
  color: var(--navy);
  background: #fff2bd;
  cursor: pointer;
  text-align: left;
}

.chest-button > span {
  grid-row: 1 / 3;
  color: var(--yellow-dark);
  font-size: 30px;
  text-align: center;
}

.chest-button strong {
  font-size: 15px;
}

.chest-button small {
  color: #7d5a13;
  font-size: 11px;
  font-weight: 800;
}

.chest-button:disabled {
  cursor: default;
  filter: grayscale(0.65);
  opacity: 0.65;
}

.chest-button.is-ready {
  border-color: var(--yellow-dark);
  box-shadow: 0 4px 0 rgba(169, 104, 0, 0.3);
  animation: chest-ready 750ms ease-in-out infinite alternate;
}

.home-album-preview {
  display: grid;
  grid-template-columns: 82px 1fr 18px;
  gap: 10px;
  min-width: 0;
  padding: 10px;
  align-items: center;
  border: 0;
  border-left: 2px solid var(--line);
  color: var(--navy);
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.home-puzzle-thumb {
  width: 82px;
  aspect-ratio: 1;
  border: 3px solid var(--navy);
  border-radius: 8px;
  background-position: center;
  background-size: cover;
}

.home-album-preview > span:nth-child(2) {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.home-album-preview small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.home-album-preview strong {
  font-size: 15px;
}

.home-album-preview em {
  color: var(--coral-dark);
  font-size: 13px;
  font-style: normal;
  font-weight: 900;
}

.home-album-preview b {
  font-size: 30px;
}

.mode-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.mode-option {
  display: flex;
  min-height: 118px;
  padding: 18px 12px;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--line);
  border-radius: 18px;
  background: #f3f6f7;
  cursor: pointer;
}

.mode-option:first-child {
  border-color: var(--blue-dark);
}

.mode-option:last-child {
  border-color: var(--purple-dark);
}

.mode-option:active {
  transform: translateY(3px);
}

.mode-icon {
  display: grid;
  min-width: 72px;
  min-height: 52px;
  padding: 7px 10px;
  place-items: center;
  border-radius: 15px;
  color: var(--navy);
  background: var(--yellow);
  font-size: 20px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.mode-option strong {
  color: var(--navy);
  font-size: 20px;
}

.mode-option small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.dialog-art {
  display: flex;
  justify-content: center;
  gap: 8px;
  color: var(--yellow-dark);
  font-size: 38px;
}

.dialog-art span:nth-child(2) {
  transform: translateY(-10px);
}

.result-modal h2 {
  margin-bottom: 6px;
}

.result-modal {
  width: min(520px, calc(100vw - 40px));
  max-height: min(90dvh, 760px);
  overflow-y: auto;
}

.result-score {
  margin: 0;
  color: var(--coral-dark);
  font-size: 18px;
  font-weight: 900;
}

.result-score strong {
  font-size: 44px;
  font-variant-numeric: tabular-nums;
}

.result-modal > p:last-of-type {
  margin: 8px 0 22px;
  color: var(--muted);
  font-weight: 700;
}

.result-ranking {
  margin: 0 0 20px;
  text-align: left;
}

.result-ranking[hidden] {
  display: none;
}

.compact-ranking-list {
  max-height: 232px;
  margin-top: 7px;
}

.dialog-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.primary-button,
.secondary-button {
  min-width: 142px;
  min-height: 50px;
  padding: 9px 18px;
  border-radius: 15px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 900;
}

.primary-button {
  border: 3px solid var(--mint-dark);
  color: #053f2f;
  background: var(--mint);
  box-shadow: 0 5px 0 var(--mint-dark);
}

.secondary-button {
  border: 3px solid rgba(20, 50, 74, 0.2);
  color: var(--navy);
  background: #edf2f4;
  box-shadow: 0 5px 0 rgba(20, 50, 74, 0.15);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(20, 50, 74, 0.15);
}

.ranking-modal {
  width: min(500px, calc(100vw - 40px));
  text-align: left;
}

.album-modal {
  width: min(620px, calc(100vw - 40px));
  max-height: 94dvh;
  overflow-y: auto;
  text-align: left;
}

.album-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.album-tabs button {
  display: flex;
  min-height: 48px;
  padding: 7px 10px;
  align-items: center;
  justify-content: space-between;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--navy);
  background: #edf2f4;
  cursor: pointer;
}

.album-tabs button.is-active {
  border-color: var(--blue-dark);
  background: #ddecff;
}

.album-tabs small {
  color: var(--muted);
  font-weight: 900;
}

.puzzle-board {
  display: grid;
  width: min(100%, 470px);
  aspect-ratio: 1;
  margin: 0 auto;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 4px solid var(--navy);
  border-radius: 8px;
  background: var(--navy);
}

.puzzle-piece {
  display: grid;
  min-width: 0;
  place-items: center;
  color: #5d7180;
  background: #dfe7e9;
  font-size: 34px;
  font-weight: 900;
}

.puzzle-piece.is-revealed,
.reward-piece {
  background-image: var(--puzzle-image);
  background-position: var(--puzzle-x) var(--puzzle-y);
  background-size: 300% 300%;
}

.album-progress {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
  justify-content: space-between;
}

.album-progress strong {
  color: var(--coral-dark);
}

.album-progress span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}

.surprise-modal p,
.reward-modal p {
  margin: 6px 0 20px;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.6;
}

.rescue-target {
  display: flex;
  gap: 12px;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 8px;
  padding: 8px 12px 8px 8px;
  align-items: center;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--navy);
  background: #edf2f4;
  text-align: left;
}

.rescue-target > span {
  width: 54px;
  flex: 0 0 54px;
  aspect-ratio: 1;
  border: 2px solid var(--navy);
  border-radius: 6px;
  background-position: center;
  background-size: cover;
}

.rescue-target strong {
  font-size: 15px;
}

.surprise-symbol {
  display: grid;
  width: 76px;
  aspect-ratio: 1;
  margin: 0 auto 10px;
  place-items: center;
  border: 4px solid var(--coral-dark);
  border-radius: 50%;
  color: var(--coral-dark);
  background: var(--yellow);
  font-size: 48px;
  font-weight: 900;
  transform: rotate(6deg);
}

.reward-piece {
  width: 190px;
  aspect-ratio: 1;
  margin: 8px auto 14px;
  border: 5px solid var(--navy);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.reward-piece.is-complete {
  display: grid;
  place-items: center;
  color: var(--yellow-dark);
  background: var(--yellow);
  font-size: 90px;
}

.ranking-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.ranking-head h2 {
  margin: 4px 0 14px;
}

.close-button {
  width: 40px;
  font-size: 24px;
}

.ranking-list {
  display: grid;
  gap: 7px;
  max-height: 430px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  counter-reset: ranking;
}

.ranking-list li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 6px 10px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #f3f6f7;
  counter-increment: ranking;
}

.ranking-list li::before {
  content: counter(ranking);
  color: var(--muted);
  font-weight: 900;
  text-align: center;
}

.ranking-list li:nth-child(-n + 3)::before {
  color: var(--coral-dark);
}

.ranking-score {
  color: var(--navy);
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.ranking-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ranking-empty {
  display: block !important;
  padding: 28px !important;
  color: var(--muted);
  text-align: center;
}

.ranking-empty::before {
  content: "" !important;
}

.dialog-backdrop {
  position: fixed;
  z-index: 29;
  inset: 0;
  background: rgba(20, 50, 74, 0.5);
}

@keyframes tile-drop {
  from {
    opacity: 0;
    transform: translateY(-80%);
  }
}

@keyframes tile-remove {
  to {
    opacity: 0;
    transform: scale(0.2) rotate(14deg);
  }
}

@keyframes tile-shake {
  25% {
    transform: translateX(-7px);
  }
  50% {
    transform: translateX(7px);
  }
  75% {
    transform: translateX(-4px);
  }
}

@keyframes star-burst {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.6);
  }
  to {
    opacity: 0;
    transform: translate(var(--burst-x), var(--burst-y)) scale(1.5) rotate(80deg);
  }
}

@keyframes mascot-hop {
  35% {
    transform: translateY(-16px) rotate(-3deg);
  }
  70% {
    transform: translateY(3px) rotate(2deg);
  }
}

@keyframes mascot-super-hop {
  28% {
    transform: translateY(-24px) rotate(-7deg) scale(1.08);
  }
  55% {
    transform: translateY(4px) rotate(5deg) scale(0.98);
  }
  78% {
    transform: translateY(-9px) rotate(-2deg) scale(1.04);
  }
}

@keyframes difficulty-win {
  35% {
    filter: drop-shadow(0 0 12px rgba(255, 214, 90, 0.95));
    transform: scale(1.045);
  }
}

@keyframes difficulty-badge-pop {
  45% {
    transform: translateY(-5px) scale(1.16) rotate(-2deg);
  }
}

@keyframes operator-land {
  from {
    opacity: 0.2;
    transform: scale(1.8) translateY(-12px);
  }
}

@keyframes operator-launch {
  45% {
    transform: translateY(-7px) scale(1.22);
    background: var(--yellow);
  }
}

@keyframes result-awaiting {
  to {
    transform: translateY(-3px);
    box-shadow: 0 8px 0 rgba(90, 63, 186, 0.25);
  }
}

@keyframes score-bump {
  50% {
    transform: scale(1.14) rotate(-2deg);
  }
}

@keyframes timer-pulse {
  to {
    transform: scale(1.08);
  }
}

@keyframes title-character-hop {
  0%,
  45%,
  100% {
    transform: translateY(0) rotate(0);
  }
  22% {
    transform: translateY(-14px) rotate(-3deg) scale(1.06);
  }
}

@keyframes title-settle {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

@keyframes chest-ready {
  to {
    transform: translateY(-2px);
  }
}

@media (max-aspect-ratio: 4/3) {
  body {
    overflow: auto;
  }

  .game-shell {
    height: auto;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: visible;
  }

  .game-stage {
    grid-template-columns: 1fr;
    grid-template-areas:
      "stats"
      "board"
      "actions"
      "feedback"
      "mission";
    grid-template-rows: auto auto auto auto auto;
    gap: 12px;
    height: auto;
  }

  .board-zone {
    height: auto;
  }

  .board-frame {
    width: min(82vw, 600px);
  }

  .side-zone {
    display: contents;
  }

  .stats-strip,
  .side-equation-actions,
  .feedback,
  .mission-panel {
    width: min(82vw, 600px);
    margin-right: auto;
    margin-left: auto;
  }

  .side-equation-actions {
    grid-area: actions;
  }

  .mission-panel {
    min-height: 210px;
  }
}

@media (max-width: 900px) {
  .game-shell {
    min-height: 100dvh;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    height: auto;
    margin-bottom: 10px;
  }

  .brand {
    white-space: nowrap;
  }

  .brand-mark {
    width: 34px;
  }

  .round-status {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }

  .toolbar {
    grid-column: 2;
    grid-row: 1;
  }

  .game-stage {
    gap: 10px;
  }

  .equation-display {
    --equation-display-gap: 4px;
    --equation-operator-width: 23px;
  }

  .board-frame {
    width: min(100%, 580px);
    border-radius: 20px;
  }

  .number-tile {
    border-width: 2px;
    border-radius: 13px;
  }

  .stats-strip,
  .side-equation-actions,
  .feedback,
  .mission-panel {
    width: min(100%, 580px);
  }

  .mission-panel {
    grid-template-columns: 1fr 140px;
    min-height: 190px;
    padding: 18px 6px 12px 22px;
  }

  .mission-copy h1 {
    font-size: 27px;
  }
}

@media (max-width: 560px) {
  :root {
    --safe-top: max(8px, env(safe-area-inset-top));
    --safe-right: max(10px, env(safe-area-inset-right));
    --safe-bottom: max(10px, env(safe-area-inset-bottom));
    --safe-left: max(10px, env(safe-area-inset-left));
  }

  .topbar {
    gap: 6px 8px;
    margin-bottom: 6px;
  }

  .modal {
    width: calc(100vw - 20px);
    padding: 18px;
    border-width: 3px;
    border-radius: 16px;
  }

  .mode-modal {
    max-height: 96dvh;
  }

  .home-summary {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px 0;
  }

  .daily-heading h2,
  .modal-head h2 {
    font-size: 20px;
  }

  .daily-missions {
    gap: 4px;
  }

  .daily-mission {
    grid-template-columns: 19px 1fr;
    min-height: 46px;
    padding: 5px;
  }

  .daily-mission strong {
    font-size: 11px;
  }

  .daily-mission small {
    font-size: 9px;
  }

  .home-album-preview {
    grid-template-columns: 62px 1fr 18px;
    padding: 4px 8px;
    border-top: 2px solid var(--line);
    border-left: 0;
  }

  .home-puzzle-thumb {
    width: 62px;
  }

  .album-tabs button {
    min-width: 0;
    padding: 6px;
    font-size: 12px;
  }

  .puzzle-board {
    width: min(100%, 54dvh);
  }

  .album-progress {
    display: grid;
  }

  .album-progress span {
    text-align: left;
  }

  .reward-piece {
    width: min(190px, 52vw);
  }

  .brand {
    gap: 5px;
    min-width: 0;
  }

  .brand-mark {
    display: none;
  }

  .brand-title strong {
    font-size: 20px;
  }

  .brand-title em {
    left: auto;
    right: 0;
    bottom: -11px;
    padding: 1px 3px;
    font-size: 7px;
  }

  .toolbar {
    gap: 5px;
  }

  .icon-button {
    width: 36px;
    border-radius: 11px;
    font-size: 20px;
  }

  .round-status {
    grid-template-columns: auto auto minmax(55px, 1fr);
    gap: 6px;
    padding: 5px 8px;
    border-radius: 12px;
  }

  .target-value {
    display: none;
  }

  .game-stage {
    gap: 7px;
  }

  .stats-strip {
    border-width: 2px;
    border-radius: 13px;
    box-shadow: 0 4px 0 rgba(20, 50, 74, 0.1);
  }

  .stats-strip > div {
    padding: 5px;
  }

  .stats-strip strong {
    font-size: 19px;
  }

  .board-zone {
    gap: 4px;
  }

  .equation-workbench {
    min-height: 76px;
  }

  .operator-bank {
    height: 25px;
    gap: 7px;
  }

  .operator-token,
  .difficulty-badge {
    height: 23px;
  }

  .operator-token {
    width: 29px;
    font-size: 19px;
  }

  .difficulty-badge {
    min-width: 102px;
    font-size: 11px;
  }

  .equation-display {
    --equation-display-gap: 3px;
    --equation-expression-gap: 3px;
    --equation-slot-size: 39px;
    --equation-operator-width: 18px;
    --equation-equals-size: 35px;
    --equation-font-size: 25px;
    min-height: 50px;
    padding: 2px 4px;
  }

  .equation-display[data-density="medium"] {
    --equation-display-gap: 3px;
    --equation-expression-gap: 2px;
    --equation-slot-size: 36px;
    --equation-operator-width: 16px;
    --equation-equals-size: 33px;
    --equation-font-size: 23px;
  }

  .equation-display[data-density="compact"] {
    --equation-display-gap: 2px;
    --equation-expression-gap: 1px;
    --equation-slot-size: 32px;
    --equation-operator-width: 14px;
    --equation-equals-size: 30px;
    --equation-font-size: 21px;
  }

  .equation-display[data-density="dense"] {
    --equation-display-gap: 1px;
    --equation-expression-gap: 1px;
    --equation-slot-size: 29px;
    --equation-operator-width: 20px;
    --equation-equals-size: 28px;
    --equation-font-size: 19px;
  }

  .mode-options {
    grid-template-columns: 1fr;
  }

  .mode-option {
    min-height: 130px;
  }

  .dialog-actions {
    flex-direction: column;
  }

  .equation-slot {
    border-radius: 12px;
  }

  .mode-game-title {
    font-size: 31px;
  }

  .equation-action {
    height: 54px;
    padding: 0 7px;
  }

  .equation-actions {
    min-height: 58px;
    gap: 7px;
  }

  .equation-action > span {
    font-size: 25px;
  }

  .equation-action small {
    font-size: 13px;
  }

  .board-frame {
    padding: 8px;
    border-width: 3px;
    border-radius: 17px;
  }

  .board {
    gap: 5px;
  }

  .number-tile {
    border-radius: 11px;
    font-size: 26px;
  }

  .game-shell.is-word-mode .number-tile {
    font-size: 23px;
  }

  .input-steps {
    min-height: 20px;
  }

  .feedback {
    min-height: 46px;
    padding: 7px 12px;
    border-width: 2px;
    border-radius: 13px;
    font-size: 15px;
  }

}

@media (max-height: 720px) and (min-aspect-ratio: 4/3) {
  .game-shell {
    min-height: 570px;
  }

  .topbar {
    height: 48px;
    margin-bottom: 2px;
  }

  .brand {
    font-size: 18px;
  }

  .brand-mark {
    width: 33px;
  }

  .icon-button {
    width: 39px;
  }

  .game-stage {
    height: calc(100% - 50px);
  }

  .equation-workbench {
    min-height: 88px;
  }

  .operator-bank {
    height: 26px;
  }

  .operator-token {
    width: 30px;
    height: 24px;
    font-size: 20px;
  }

  .equation-display {
    min-height: 58px;
  }

  .board-frame {
    width: min(100%, 61vh);
  }

  .mission-panel {
    min-height: 210px;
  }
}

@media (min-width: 900px) and (min-height: 560px) and (orientation: landscape) {
  body { overflow: hidden; }
  .game-shell { height: 100dvh; min-height: 0; overflow: hidden; }
  .game-stage {
    grid-template-columns: minmax(0, 1.35fr) minmax(0, .9fr);
    grid-template-areas: "board stats" "board mission" "board feedback" "board actions";
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    height: calc(100% - 64px); gap: 16px;
  }
  .board-zone { height: 100%; }
  .board-frame { width: min(100%, calc(100dvh - 220px), 600px); }
  .stats-strip, .side-equation-actions, .feedback, .mission-panel { width: 100%; margin: 0; }
  .mission-panel { min-height: 180px; grid-template-columns: minmax(0, 1fr) minmax(0, .7fr); padding: 16px; }
  .mission-copy h1 { font-size: 26px; }
  .mode-modal { padding: 20px; }
  .mode-game-title { font-size: 42px; }
  .home-summary { padding: 10px 0; }
  .album-modal {
    width: min(880px, calc(100vw - 40px)); max-height: calc(100dvh - 32px);
    display: grid; grid-template-columns: minmax(240px, .8fr) minmax(0, 1.2fr);
    gap: 12px 24px; padding: 20px; overflow: visible;
  }
  .album-modal .modal-head { grid-column: 1 / -1; }
  .album-modal .album-tabs { grid-column: 1; grid-row: 2; grid-template-columns: 1fr; align-self: start; margin: 0; }
  .album-modal .puzzle-board { grid-column: 2; grid-row: 2 / 4; width: min(100%, calc(100dvh - 160px), 470px); }
  .album-modal .album-progress { grid-column: 1; grid-row: 3; display: grid; align-self: end; margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
