/* ============================================================
   數學星球大冒險 — components.css
   按鈕、卡片、星球插畫、星圖、答題元件與各種覆蓋層
   ============================================================ */

/* ------------------------------------------------------------
   1. 按鈕：厚實、圓潤、有實體按鍵感
   ------------------------------------------------------------ */
.btn {
  --btn-bg: rgba(255, 255, 255, 0.085);
  --btn-bg-hover: rgba(255, 255, 255, 0.14);
  --btn-fg: var(--text);
  --btn-border: var(--line);
  --btn-edge: rgba(0, 0, 0, 0.42);
  --btn-drop: rgba(0, 0, 0, 0.24);

  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: 52px;
  padding: 0.65em 1.3em;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 2px solid var(--btn-border);
  border-radius: 18px;
  box-shadow: 0 5px 0 var(--btn-edge), 0 12px 22px var(--btn-drop), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  font-family: var(--font-ui);
  font-size: clamp(0.92rem, 1.5vw, 1.03rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 0.02em;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  transition:
    transform 0.14s ease,
    box-shadow 0.14s ease,
    background-color 0.2s ease,
    border-color 0.2s ease,
    filter 0.2s ease;
}

.btn:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--btn-bg-hover);
  border-color: var(--line-strong);
  transform: translateY(-2px);
  filter: brightness(1.04);
}

.btn:active:not(:disabled):not([aria-disabled="true"]) {
  box-shadow: 0 2px 0 var(--btn-edge), 0 5px 10px var(--btn-drop);
  transform: translateY(3px);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.46;
  filter: grayscale(0.35) saturate(0.55);
  box-shadow: 0 3px 0 var(--btn-edge);
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  --btn-bg: linear-gradient(180deg, var(--accent-hi) 0%, var(--accent) 58%, var(--accent) 100%);
  --btn-bg-hover: linear-gradient(180deg, #fff3c9 0%, var(--accent-hi) 52%, var(--accent) 100%);
  --btn-fg: var(--accent-ink);
  --btn-border: rgba(255, 255, 255, 0.58);
  --btn-edge: var(--accent-shadow);
  --btn-drop: var(--glow);

  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  box-shadow:
    0 6px 0 var(--accent-shadow),
    0 14px 26px var(--glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.62),
    inset 0 -3px 0 rgba(0, 0, 0, 0.08);
}

.btn--primary::before {
  content: "";
  position: absolute;
  inset: 3px 8px auto;
  height: 38%;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.36), transparent);
  border-radius: calc(18px - 4px) calc(18px - 4px) 50% 50%;
  opacity: 0.7;
}

.btn--primary:hover:not(:disabled) {
  box-shadow:
    0 8px 0 var(--accent-shadow),
    0 18px 34px var(--glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.btn--glow {
  animation: pulse-glow 2.8s ease-in-out infinite;
}

.btn--ghost {
  --btn-bg: rgba(9, 10, 28, 0.32);
  --btn-bg-hover: rgba(255, 255, 255, 0.12);
  --btn-fg: var(--text);
  --btn-border: rgba(255, 255, 255, 0.19);
  --btn-edge: rgba(0, 0, 0, 0.35);
}

.btn--soft {
  --btn-bg: linear-gradient(180deg, #fffdf7, var(--paper-warm));
  --btn-bg-hover: linear-gradient(180deg, #fff, #ffedc8);
  --btn-fg: var(--paper-ink);
  --btn-border: var(--paper-line);
  --btn-edge: #c8b085;
  --btn-drop: rgba(0, 0, 0, 0.22);

  box-shadow:
    0 5px 0 #c8b085,
    0 11px 20px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 #fff;
}

.btn--soft:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn--icon {
  width: 52px;
  min-width: 52px;
  height: 52px;
  min-height: 52px;
  padding: 0;
  border-radius: 17px;
  font-size: 1.22rem;
  line-height: 1;
}

.btn--sm {
  min-height: 48px;
  padding: 0.45em 1em;
  border-radius: 14px;
  font-size: 0.86rem;
}

.btn--sm.btn--icon {
  width: 48px;
  min-width: 48px;
  height: 48px;
  min-height: 48px;
}

.btn--xl {
  min-height: clamp(60px, 7.4vh, 70px);
  padding: 0.8em 2.1em;
  border-radius: 24px;
  font-size: clamp(1.08rem, 2vw, 1.36rem);
  letter-spacing: 0.05em;
}

.btn--xl.btn--icon {
  width: clamp(60px, 7.4vh, 70px);
  padding: 0;
}

.btn__spark {
  margin-left: 0.15em;
  font-size: 0.85em;
  opacity: 0.9;
  animation: twinkle 1.9s ease-in-out infinite alternate;
}

.btn--audio {
  color: var(--accent-hi);
}

.btn--audio.is-off,
.btn--audio.is-muted,
.btn--audio[aria-pressed="false"] {
  color: var(--text-muted);
  opacity: 0.68;
  filter: grayscale(0.5);
}

.btn--audio.is-off::after,
.btn--audio.is-muted::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 62%;
  height: 2px;
  background: currentColor;
  border-radius: var(--r-pill);
  transform: translate(-50%, -50%) rotate(-42deg);
  opacity: 0.8;
}

/* 奶油卡片上的透明按鈕改為淺色系 */
.intro__card .btn--ghost,
.result__card .btn--ghost {
  --btn-bg: rgba(255, 255, 255, 0.55);
  --btn-bg-hover: #fffdf7;
  --btn-fg: var(--paper-ink);
  --btn-border: var(--paper-line);
  --btn-edge: #cdb68c;
  --btn-drop: rgba(71, 48, 12, 0.16);
}

.intro__card .btn--primary,
.result__card .btn--primary {
  text-shadow: none;
}

/* ------------------------------------------------------------
   2. 狀態列、膠囊、徽章、進度點
   ------------------------------------------------------------ */
.topbar,
.playbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.4vw, 16px);
  width: 100%;
  min-height: var(--topbar-h);
  color: var(--text);
}

.topbar {
  padding-bottom: clamp(7px, 1.2vh, 12px);
  border-bottom: 1px solid var(--line);
}

.topbar::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-2), transparent);
  opacity: 0.6;
  pointer-events: none;
}

.playbar {
  padding:
    var(--safe-top)
    var(--safe-right)
    clamp(6px, 1.1vh, 10px)
    var(--safe-left);
  background: linear-gradient(180deg, rgba(9, 10, 30, 0.72), rgba(9, 10, 30, 0.24));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.topbar__title {
  flex: 1 1 auto;
  min-width: 0;
}

.topbar__kicker {
  display: block;
  margin-bottom: 1px;
  color: var(--accent-hi);
  font-size: clamp(0.64rem, 1.1vw, 0.76rem);
  font-weight: 800;
  line-height: 1.4;
  letter-spacing: 0.11em;
}

.topbar__title h1 {
  overflow: hidden;
  color: var(--text);
  font-size: clamp(1.12rem, 2.3vw, 1.72rem);
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__stats,
.playbar__tools {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: clamp(5px, 0.8vw, 9px);
}

.playbar__info {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.playbar__level {
  overflow: hidden;
  color: var(--text);
  font-size: clamp(0.8rem, 1.25vw, 0.94rem);
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.36em;
  min-height: 38px;
  padding: 0.28em 0.78em;
  color: var(--text);
  background: rgba(10, 11, 31, 0.46);
  border: 1.5px solid var(--line);
  border-radius: var(--r-pill);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  font-size: clamp(0.78rem, 1.25vw, 0.9rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

.pill__icon {
  font-size: 1.05em;
  line-height: 1;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
}

.pill--coins {
  color: #ffe9a8;
  background: rgba(255, 209, 102, 0.12);
  border-color: rgba(255, 209, 102, 0.4);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 0 16px rgba(255, 209, 102, 0.12);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  min-height: 30px;
  padding: 0.25em 0.8em;
  color: var(--accent-hi);
  background: var(--accent-soft);
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--r-pill);
  font-size: clamp(0.7rem, 1.2vw, 0.8rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1;
}

.intro__card .badge {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: rgba(255, 255, 255, 0.36);
  box-shadow: 0 3px 0 var(--accent-shadow);
}

.dots {
  display: flex;
  align-items: center;
  gap: clamp(5px, 0.8vw, 8px);
  min-height: 16px;
}

.dot,
.dots__dot,
.dots > span,
.dots > i {
  display: block;
  flex: 0 0 auto;
  width: clamp(10px, 1.4vh, 14px);
  height: clamp(10px, 1.4vh, 14px);
  background: rgba(255, 255, 255, 0.15);
  border: 1.5px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
  transition:
    background-color 0.25s ease,
    border-color 0.25s ease,
    box-shadow 0.25s ease,
    transform 0.25s ease,
    border-radius 0.25s ease;
}

.dots__dot.is-done,
.dot.is-done,
.dot--done,
.dots > .is-done,
.dots > .is-correct {
  background: var(--accent);
  border-color: var(--accent-hi);
  box-shadow: 0 0 10px var(--glow);
}

.dots__dot.is-correct,
.dot.is-correct,
.dot--correct {
  background: var(--mint);
  border-color: #b8f7dd;
}

.dots__dot.is-helped,
.dot.is-helped,
.dot--helped {
  background: var(--sky);
  border-color: #c8f3ff;
  border-radius: 3px;
  box-shadow: 0 0 9px rgba(56, 189, 248, 0.55);
  transform: rotate(45deg) scale(0.82);
}

.dots__dot.is-current,
.dot.is-current,
.dot--current,
.dots > .is-current,
.dots > .is-active {
  background: var(--accent-2);
  border-color: #fff;
  box-shadow: 0 0 0 3px var(--accent-soft), 0 0 12px var(--accent-2);
  transform: scale(1.16);
}

.dots__dot.is-wrong,
.dot.is-wrong,
.dot--wrong,
.dots > .is-wrong {
  background: var(--coral-deep);
  border-color: var(--coral);
}

.progress-chip,
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  min-height: 32px;
  padding: 0.25em 0.72em;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  font-size: 0.82em;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.progress-chip strong,
.chip strong {
  color: var(--accent-hi);
  font-variant-numeric: tabular-nums;
}

.home__progress > span,
.home__progress > .progress-chip,
.home__progress > .chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  min-height: 34px;
  padding: 0.28em 0.85em;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  font-weight: 800;
  line-height: 1;
}

.home__progress strong {
  color: var(--accent-hi);
  font-size: 1.1em;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------
   3. 主畫面：標誌、星球、奇奇、飛船
   ------------------------------------------------------------ */
.logo {
  display: inline-flex;
  flex-direction: column;
  align-items: inherit;
  font-family: var(--font-display);
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 0.98;
}

/* 星球本體：用多層漸層畫出光澤、大氣與表面 */
.planet {
  --planet-size: clamp(170px, 23vw, 290px);
  --planet-color: var(--accent);
  --planet-hi: var(--accent-hi);
  --planet-deep: var(--accent-shadow);

  position: relative;
  width: var(--planet-size);
  max-width: 88vw;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 24%, rgba(255, 255, 255, 0.94) 0 3.5%, rgba(255, 255, 255, 0.22) 11%, transparent 20%),
    radial-gradient(circle at 37% 30%, var(--planet-hi) 0%, var(--planet-color) 44%, var(--planet-deep) 100%);
  box-shadow:
    inset -22px -26px 0 rgba(16, 6, 35, 0.18),
    inset 14px 16px 30px rgba(255, 255, 255, 0.2),
    0 0 0 2px rgba(255, 255, 255, 0.16),
    0 0 64px var(--glow),
    0 28px 52px rgba(0, 0, 0, 0.36);
  animation: float 7.2s ease-in-out infinite;
}

.planet::before {
  content: "";
  position: absolute;
  inset: 18% -4%;
  z-index: 1;
  border-radius: 50%;
  background: linear-gradient(
    180deg,
    transparent 34%,
    rgba(255, 255, 255, 0.15) 44%,
    rgba(255, 255, 255, 0.05) 51%,
    transparent 61%
  );
  transform: rotate(-15deg);
  opacity: 0.8;
  pointer-events: none;
}

.planet::after {
  content: "";
  position: absolute;
  top: 8%;
  left: 18%;
  width: 26%;
  height: 17%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255, 255, 255, 0.68), transparent 70%);
  filter: blur(2px);
  transform: rotate(-24deg);
  pointer-events: none;
}

.planet__ring {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: 154%;
  height: 40%;
  border: clamp(7px, 1vw, 13px) solid var(--accent-2);
  border-top-color: rgba(255, 255, 255, 0.7);
  border-right-color: var(--accent-2);
  border-bottom-color: rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  box-shadow:
    0 0 18px rgba(255, 255, 255, 0.2),
    inset 0 0 14px rgba(255, 255, 255, 0.16);
  transform: translate(-50%, -50%) rotate(-17deg);
  transform-origin: center;
  opacity: 0.78;
  pointer-events: none;
  animation: ring-sway 10s ease-in-out infinite;
}

.planet__crater {
  position: absolute;
  z-index: 3;
  aspect-ratio: 1;
  background: rgba(44, 17, 62, 0.16);
  border-radius: 50%;
  box-shadow:
    inset -3px -4px 0 rgba(255, 255, 255, 0.15),
    inset 2px 3px 0 rgba(23, 8, 38, 0.22);
  pointer-events: none;
}

.planet__crater--1 {
  top: 31%;
  left: 20%;
  width: 17%;
}

.planet__crater--2 {
  right: 20%;
  bottom: 27%;
  width: 23%;
}

.planet__crater--3 {
  right: 27%;
  top: 23%;
  width: 10%;
  opacity: 0.72;
}

.planet__emoji {
  position: relative;
  z-index: 4;
  display: block;
  font-size: calc(var(--planet-size, 240px) * 0.3);
  line-height: 1;
  filter: drop-shadow(0 8px 10px rgba(25, 8, 45, 0.32));
  transform: translateY(-2%);
}

.planet--hero {
  --planet-size: clamp(190px, 25vw, 340px);
}

.planet--intro {
  --planet-size: clamp(180px, 23vw, 300px);
}

.home__planet::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(430px, 102%);
  aspect-ratio: 1.28;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  transform: translate(-50%, -50%) rotate(-13deg);
  pointer-events: none;
}

.home__planet::after {
  content: "✦";
  position: absolute;
  top: 9%;
  right: 12%;
  color: var(--accent-2);
  font-size: clamp(1.1rem, 2.2vw, 1.8rem);
  text-shadow: 0 0 14px var(--accent-2);
  animation: twinkle 2.6s ease-in-out infinite alternate;
}

/* 飛船：尾焰 emoji 向左，船身微微上下漂浮 */
.ship {
  --ship-size: clamp(120px, 17vw, 190px);
  --ship-color: var(--sky);
  --trail-color: #fef3c7;

  position: relative;
  display: grid;
  place-items: center;
  width: var(--ship-size);
  aspect-ratio: 1.42;
  isolation: isolate;
}

.ship__emoji {
  position: relative;
  z-index: 2;
  font-size: calc(var(--ship-size) * 0.56);
  line-height: 1;
  filter:
    drop-shadow(0 12px 16px rgba(0, 0, 0, 0.38))
    drop-shadow(0 0 18px var(--ship-color));
  animation: bob 4.4s ease-in-out infinite;
}

.ship__trail {
  position: absolute;
  top: 54%;
  right: 55%;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 62%;
  min-height: 50%;
  color: var(--trail-color);
  font-size: calc(var(--ship-size) * 0.34);
  line-height: 1;
  text-align: center;
  filter:
    blur(0.3px)
    drop-shadow(0 0 10px var(--trail-color))
    drop-shadow(0 0 20px var(--ship-color));
  transform: translateY(-50%);
  opacity: 0.92;
  animation: trail-flicker 1.1s ease-in-out infinite alternate;
  pointer-events: none;
}

.ship__trail::before,
.ship__trail::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: 50%;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, transparent, var(--trail-color));
  opacity: 0.34;
  transform: translateY(-50%);
}

.ship__trail::before {
  right: 48%;
  width: 120%;
  height: 26%;
  filter: blur(4px);
}

.ship__trail::after {
  right: 58%;
  width: 75%;
  height: 10%;
  filter: blur(1.5px);
  opacity: 0.55;
}

.ship--big {
  --ship-size: clamp(190px, 30vh, 300px);
}

.ship--preview {
  --ship-size: clamp(190px, 30vh, 290px);
}

/* 奇奇機器人：即使只有一個 emoji 也能自成可愛徽章 */
.mascot {
  --mascot-size: clamp(92px, 12vw, 138px);

  position: relative;
  display: grid;
  place-items: center;
  width: var(--mascot-size);
  aspect-ratio: 1;
  color: #063a2b;
  background:
    radial-gradient(circle at 31% 25%, #f6fffc 0 8%, #c9f8e6 38%, #70dcb8 72%, #3bc397 100%);
  border: clamp(3px, 0.5vw, 5px) solid rgba(255, 255, 255, 0.82);
  border-radius: 50%;
  box-shadow:
    inset -8px -10px 0 rgba(5, 82, 60, 0.16),
    0 0 32px rgba(52, 211, 153, 0.32),
    0 14px 26px rgba(0, 0, 0, 0.3);
  font-size: calc(var(--mascot-size) * 0.36);
  line-height: 1;
  animation: bob 5.2s ease-in-out infinite;
}

.mascot::before {
  content: "";
  position: absolute;
  inset: 12%;
  border: 2px dashed rgba(6, 58, 43, 0.16);
  border-radius: 50%;
  pointer-events: none;
}

.mascot__emoji,
.mascot__face {
  position: relative;
  z-index: 1;
  display: block;
  font-size: 1em;
  line-height: 1;
}

.mascot__eye {
  display: inline-block;
  transform-origin: center;
  animation: mascot-blink 5.2s ease-in-out infinite;
}

.mascot__eyes {
  animation: mascot-blink 5.2s ease-in-out infinite;
  transform-origin: center;
}

.mascot-placeholder {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(130px, 22vw, 210px);
  aspect-ratio: 1;
  color: #063a2b;
  background:
    radial-gradient(circle at 32% 26%, #f6fffc 0 7%, #c9f8e6 38%, #70dcb8 72%, #3bc397 100%);
  border: 4px solid rgba(255, 255, 255, 0.82);
  border-radius: 50%;
  box-shadow:
    inset -10px -12px 0 rgba(5, 82, 60, 0.15),
    0 0 34px rgba(52, 211, 153, 0.34),
    0 16px 30px rgba(0, 0, 0, 0.3);
  font-size: clamp(3rem, 8vw, 4.6rem);
  line-height: 1;
  animation: bob 5.2s ease-in-out infinite;
}

.mascot-placeholder::after {
  content: "奇奇";
  position: absolute;
  bottom: 9%;
  left: 50%;
  padding: 0.18em 0.55em;
  color: #064d39;
  background: rgba(255, 255, 255, 0.72);
  border-radius: var(--r-pill);
  font-family: var(--font-ui);
  font-size: 0.18em;
  font-weight: 900;
  letter-spacing: 0.08em;
  transform: translateX(-50%);
  white-space: nowrap;
}

.play-visual .mascot {
  --mascot-size: clamp(150px, 23vw, 250px);
}

.home__ship .ship {
  --ship-size: clamp(150px, 22vw, 230px);
}

/* ------------------------------------------------------------
   4. 星圖：星系、關卡卡、星星、鎖
   ------------------------------------------------------------ */
.galaxy {
  --galaxy-color: #34d399;
  --galaxy-ink: #032b1f;
  --galaxy-soft: rgba(52, 211, 153, 0.16);
  --galaxy-glow: rgba(52, 211, 153, 0.34);

  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: clamp(9px, 1.4vh, 15px);
  overflow: hidden;
  background:
    radial-gradient(ellipse 62% 54% at 92% -8%, var(--galaxy-soft), transparent 68%),
    linear-gradient(155deg, rgba(255, 255, 255, 0.075), rgba(7, 8, 24, 0.28));
  border: 2px solid rgba(255, 255, 255, 0.11);
  border-radius: var(--r-lg);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 16px 34px rgba(0, 0, 0, 0.22);
}

.galaxy::before {
  content: "";
  position: absolute;
  top: 0;
  right: 18%;
  left: 18%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--galaxy-color), transparent);
  opacity: 0.78;
  pointer-events: none;
}

.galaxy:nth-child(4n + 1),
.galaxy--1,
.galaxy[data-galaxy="1"] {
  --galaxy-color: #34d399;
  --galaxy-ink: #032b1f;
  --galaxy-soft: rgba(52, 211, 153, 0.16);
  --galaxy-glow: rgba(52, 211, 153, 0.34);
}

.galaxy:nth-child(4n + 2),
.galaxy--2,
.galaxy[data-galaxy="2"] {
  --galaxy-color: #fbbf24;
  --galaxy-ink: #2e1a00;
  --galaxy-soft: rgba(251, 191, 36, 0.16);
  --galaxy-glow: rgba(251, 191, 36, 0.34);
}

.galaxy:nth-child(4n + 3),
.galaxy--3,
.galaxy[data-galaxy="3"] {
  --galaxy-color: #a78bfa;
  --galaxy-ink: #1d0f49;
  --galaxy-soft: rgba(167, 139, 250, 0.17);
  --galaxy-glow: rgba(167, 139, 250, 0.36);
}

.galaxy:nth-child(4n + 4),
.galaxy--4,
.galaxy[data-galaxy="4"] {
  --galaxy-color: #38bdf8;
  --galaxy-ink: #04263a;
  --galaxy-soft: rgba(56, 189, 248, 0.17);
  --galaxy-glow: rgba(56, 189, 248, 0.36);
}

.galaxy__head {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: clamp(7px, 1vw, 11px);
  min-width: 0;
  margin-bottom: clamp(6px, 1vh, 10px);
}

.galaxy__head > div {
  min-width: 0;
}

.galaxy__heading {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.galaxy__badge {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: clamp(32px, 4.4vh, 44px);
  aspect-ratio: 1;
  color: var(--galaxy-ink);
  background: linear-gradient(180deg, #fff 0%, var(--galaxy-color) 26%, var(--galaxy-color) 100%);
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  border-radius: 14px;
  box-shadow:
    0 3px 0 rgba(0, 0, 0, 0.28),
    0 0 18px var(--galaxy-glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  font-size: clamp(1rem, 2vh, 1.3rem);
  line-height: 1;
}

.galaxy__title {
  overflow: hidden;
  margin: 0;
  color: var(--text);
  font-size: clamp(0.9rem, 1.4vw, 1.15rem);
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.galaxy__tagline {
  overflow: hidden;
  margin-top: 1px;
  color: var(--text-muted);
  font-size: clamp(0.62rem, 0.95vw, 0.76rem);
  font-weight: 600;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.galaxy__progress,
.galaxy__count,
.galaxy__stars {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.3em;
  min-height: 28px;
  margin-left: auto;
  padding: 0.2em 0.62em;
  color: var(--galaxy-color);
  background: var(--galaxy-soft);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--r-pill);
  font-size: clamp(0.62rem, 0.95vw, 0.74rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

.galaxy__progress strong,
.galaxy__count strong {
  color: #fff;
  font-size: 1.12em;
  text-shadow: 0 0 10px var(--galaxy-glow);
}

.level-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  flex: 1 1 auto;
  gap: clamp(6px, 0.9vw, 10px);
  min-height: 0;
}

.level-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
  min-height: 0;
  padding: clamp(7px, 1.1vh, 12px) clamp(8px, 0.9vw, 13px);
  overflow: hidden;
  color: var(--text);
  text-align: left;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
  border: 2px solid rgba(255, 255, 255, 0.13);
  border-radius: 17px;
  box-shadow:
    0 4px 0 rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition:
    transform 0.16s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    background-color 0.18s ease,
    opacity 0.18s ease;
}

.level-card > * {
  flex-shrink: 0;
}

.level-card::before {
  content: "";
  position: absolute;
  top: -42%;
  right: -18%;
  width: 85%;
  aspect-ratio: 1;
  pointer-events: none;
  background: radial-gradient(circle, var(--galaxy-color) 0%, transparent 68%);
  opacity: 0.17;
}

.level-card::after {
  content: "";
  position: absolute;
  right: 9px;
  bottom: 8px;
  left: 9px;
  height: 2px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--galaxy-color), transparent);
  opacity: 0.35;
}

.level-card:hover:not(:disabled):not(.is-locked):not(.level-card--locked) {
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.17), rgba(255, 255, 255, 0.06));
  border-color: var(--galaxy-color);
  box-shadow:
    0 7px 0 rgba(0, 0, 0, 0.26),
    0 0 22px var(--galaxy-glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
  transform: translateY(-3px);
}

.level-card:active:not(:disabled):not(.is-locked) {
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
  transform: translateY(2px);
}

.level-card__number,
.level-card__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  min-height: 22px;
  padding: 0 0.34em;
  color: var(--galaxy-ink);
  background: var(--galaxy-color);
  border-radius: 8px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
  font-family: var(--font-num);
  font-size: 0.72rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.level-card__icon {
  position: absolute;
  top: 7px;
  right: 9px;
  font-size: clamp(1rem, 2.1vh, 1.45rem);
  line-height: 1;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.28));
}

.level-card__title {
  display: -webkit-box;
  overflow: hidden;
  width: 100%;
  margin-top: 1px;
  color: var(--text);
  font-size: clamp(0.73rem, 1.02vw, 0.9rem);
  font-weight: 800;
  line-height: 1.32;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.level-card__meta,
.level-card__concept {
  display: block;
  overflow: hidden;
  width: 100%;
  color: var(--text-muted);
  font-size: clamp(0.58rem, 0.8vw, 0.68rem);
  font-weight: 600;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-card__foot {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  width: 100%;
  margin-top: auto;
  padding-top: 2px;
}

.level-card__stars,
.level-card .stars {
  display: inline-flex;
  gap: 1px;
  margin-top: auto;
  padding-top: 2px;
  font-size: clamp(0.7rem, 1.2vh, 0.88rem);
  line-height: 1;
}

.level-card__foot .level-card__stars,
.level-card__foot .stars {
  margin: 0;
  padding: 0;
}

.level-card__lock {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 20px;
  padding: 0.12em 0.5em;
  overflow: hidden;
  color: var(--text-muted);
  background: rgba(7, 8, 22, 0.46);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  font-size: clamp(0.52rem, 0.72vw, 0.6rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-card .lock {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  color: var(--text-dim);
  background: rgba(7, 8, 22, 0.64);
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 0.78rem;
  line-height: 1;
}

.level-card--locked,
.level-card.is-locked {
  opacity: 0.56;
  cursor: not-allowed;
  filter: saturate(0.38);
  border-style: dashed;
}

.level-card--locked::after,
.level-card.is-locked::after {
  opacity: 0.15;
}

.level-card--locked .level-card__title,
.level-card.is-locked .level-card__title {
  color: var(--text-dim);
}

.level-card--completed,
.level-card--done,
.level-card.is-completed,
.level-card.is-done {
  border-color: rgba(52, 211, 153, 0.44);
  background:
    radial-gradient(ellipse at 90% 0%, rgba(52, 211, 153, 0.14), transparent 58%),
    linear-gradient(155deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.045));
}

.level-card--completed::after,
.level-card--done::after,
.level-card.is-completed::after,
.level-card.is-done::after {
  background: linear-gradient(90deg, transparent, var(--mint), transparent);
  opacity: 0.7;
}

.level-card--current {
  background:
    radial-gradient(ellipse at 90% 0%, var(--galaxy-soft), transparent 62%),
    linear-gradient(155deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.07));
  border-color: var(--galaxy-color);
  box-shadow:
    0 5px 0 rgba(0, 0, 0, 0.28),
    0 0 0 3px var(--galaxy-soft),
    0 0 26px var(--galaxy-glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.level-card--current .level-card__number {
  box-shadow:
    0 2px 0 rgba(0, 0, 0, 0.22),
    0 0 14px var(--galaxy-glow);
}

.level-card__goal,
.level-card__hint {
  color: var(--galaxy-color);
  font-size: 0.64rem;
  font-weight: 800;
  line-height: 1;
}

/* 星星：預設是暗星，亮起後由 animations.css 接手 */
.stars {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  line-height: 1;
}

.star {
  display: inline-block;
  color: rgba(255, 255, 255, 0.18);
  font-size: 1em;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  transition:
    color 0.2s ease,
    transform 0.2s ease,
    text-shadow 0.2s ease;
}

.star--on,
.star.is-on,
.star--filled {
  color: var(--gold);
  text-shadow:
    0 0 8px rgba(255, 209, 102, 0.8),
    0 2px 0 rgba(122, 76, 0, 0.25);
}

.level-card--locked .star {
  color: rgba(255, 255, 255, 0.12);
}

/* ------------------------------------------------------------
   5. 關卡介紹的資訊膠囊
   ------------------------------------------------------------ */
.intro__meta > *,
.intro__chip,
.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.34em;
  min-height: 34px;
  padding: 0.28em 0.78em;
  color: #5a3c08;
  background: linear-gradient(180deg, #fff8e7, #ffedc9);
  border: 1.5px solid #e2c98f;
  border-radius: var(--r-pill);
  box-shadow: inset 0 1px 0 #fff;
  font-size: clamp(0.68rem, 1.2vw, 0.79rem);
  font-weight: 800;
  line-height: 1;
}

.intro__meta strong,
.intro__chip strong,
.meta-chip strong {
  color: #8a4b00;
  font-weight: 900;
}

/* ------------------------------------------------------------
   6. 題目卡、直式計算、教具舞台
   ------------------------------------------------------------ */
.question-card {
  position: relative;
  flex: 0 0 auto;
  padding: clamp(12px, 2vh, 20px) clamp(14px, 2vw, 22px);
  overflow: hidden;
  color: var(--paper-ink);
  background:
    radial-gradient(rgba(37, 27, 61, 0.035) 1px, transparent 1.4px) 0 0 / 16px 16px,
    linear-gradient(170deg, #fffdf7, var(--paper) 58%, #fff1d8);
  border: 2px solid var(--paper-line);
  border-radius: var(--r-md);
  box-shadow:
    0 20px 40px rgba(4, 4, 18, 0.32),
    0 4px 0 var(--paper-line-strong),
    inset 0 1px 0 #fff;
}

.question-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 7px;
  height: 100%;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  opacity: 0.9;
}

.question-card__tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  min-height: 26px;
  padding: 0.2em 0.7em;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: var(--r-pill);
  box-shadow: 0 2px 0 var(--accent-shadow);
  font-size: clamp(0.62rem, 1.15vw, 0.72rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.08em;
}

.question-card__prompt {
  margin-top: 0.55em;
  color: var(--paper-ink);
  font-size: clamp(1rem, 1.7vw, 1.32rem);
  font-weight: 800;
  line-height: 1.68;
  letter-spacing: 0.012em;
}

.question-card__prompt strong,
.question-card__prompt mark {
  color: #8a4b00;
  background: linear-gradient(transparent 58%, rgba(255, 209, 102, 0.52) 58%);
  border-radius: 4px;
  font-weight: 900;
}

.question-card__note {
  margin-top: 0.65em;
  padding-top: 0.55em;
  color: var(--paper-muted);
  border-top: 1px dashed var(--paper-line-strong);
  font-size: clamp(0.75rem, 1.2vw, 0.86rem);
  font-weight: 600;
  line-height: 1.55;
}

.question-card__unit {
  display: inline-flex;
  margin-left: 0.3em;
  padding: 0.1em 0.55em;
  color: #6c4700;
  background: #fff0c6;
  border: 1px solid #e6ca83;
  border-radius: var(--r-pill);
  font-size: 0.78em;
  font-weight: 900;
  vertical-align: 0.1em;
}

/* SVG sizes are owned by each manipulative class (e.g. .mp-block-icon,
   .mp-fraction__svg); a broad `svg` rule here overrides their width. */
.play-visual .mp-block-icon {
  width: 1.9rem;
  height: 1.9rem;
  max-width: 1.9rem;
  max-height: 1.9rem;
}

.play-visual > .manipulative,
.play-visual > .visual,
.play-visual > [class*="manipulative"] {
  display: grid;
  place-items: center;
  width: 100%;
  max-width: 760px;
  min-height: 0;
}

.play-visual > .mascot {
  margin: auto;
}

.play-visual__label,
.visual-label {
  position: absolute;
  top: 10px;
  left: 14px;
  color: var(--paper-muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

/* 直式計算：讓 JS 以一般 div／table 輸出時都能維持數字對齊 */
.vertical-math {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  gap: 0.2em;
  padding: clamp(10px, 1.8vh, 18px) clamp(14px, 2vw, 24px);
  overflow-x: auto;
  overflow-y: hidden;
  color: var(--paper-ink);
  background:
    radial-gradient(rgba(37, 27, 61, 0.04) 1px, transparent 1.4px) 0 0 / 14px 14px,
    linear-gradient(170deg, #fffdf7, var(--paper-warm));
  border: 2px solid var(--paper-line);
  border-radius: var(--r-md);
  box-shadow:
    0 12px 28px rgba(4, 4, 18, 0.26),
    0 4px 0 var(--paper-line-strong),
    inset 0 1px 0 #fff;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  -webkit-overflow-scrolling: touch;
}

.vertical-math__problem,
.vertical-math__grid,
.vertical-math__rows {
  display: grid;
  justify-content: center;
  width: max-content;
  min-width: 8ch;
  margin: 0 auto;
  font-family: var(--font-num);
  font-size: clamp(1.25rem, 2.7vh, 1.85rem);
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: 0.14em;
}

.vertical-math__row,
.vertical-math .row {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.3em;
  min-height: 1.25em;
  text-align: right;
  white-space: nowrap;
}

/* app.js 的直式輸出：vm-row / vm-line / vm-op */
.vm-row {
  display: grid;
  grid-template-columns: 1.45em minmax(5ch, auto);
  justify-content: end;
  align-items: baseline;
  width: max-content;
  min-width: 8ch;
  margin: 0 auto;
  color: var(--paper-ink);
  font-family: var(--font-num);
  font-size: clamp(1.4rem, 3.1vh, 2.05rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
  letter-spacing: 0.13em;
  white-space: nowrap;
}

.vm-row > span:last-child {
  text-align: right;
}

.vm-op {
  display: inline-block;
  color: var(--coral-deep);
  font-weight: 900;
  text-align: left;
  letter-spacing: 0;
}

.vm-line {
  width: 8ch;
  height: 3px;
  margin: 0.12em auto;
  background: var(--paper-ink);
  border-radius: var(--r-pill);
}

.vertical-math__division {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.12em;
  width: max-content;
  margin: 0 auto;
  color: var(--paper-ink);
  font-family: var(--font-num);
  font-size: clamp(1.6rem, 3.7vh, 2.4rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  letter-spacing: 0.06em;
}

.vm-divisor {
  color: var(--coral-deep);
  font-size: 0.82em;
  letter-spacing: 0.01em;
}

.vm-bracket {
  color: var(--paper-ink);
  font-size: 1.22em;
  font-weight: 900;
  line-height: 1;
}

.vm-dividend {
  padding: 0 0.14em 0 0.06em;
  color: var(--paper-ink);
  letter-spacing: 0.12em;
}

.vertical-math__op {
  display: inline-block;
  min-width: 1.15em;
  color: var(--coral-deep);
  font-weight: 900;
  text-align: left;
}

.vertical-math__line,
.vertical-math .line {
  display: block;
  height: 3px;
  margin: 0.18em 0;
  background: var(--paper-ink);
  border-radius: var(--r-pill);
}

.vertical-math__answer,
.vertical-math .answer-line {
  color: #0b6f4f;
  font-weight: 900;
}

.vertical-math__carry {
  color: var(--coral-deep);
  font-size: 0.62em;
  font-weight: 900;
  vertical-align: super;
}

.vertical-math table {
  margin: 0 auto;
  font-family: var(--font-num);
  font-size: clamp(1.2rem, 2.6vh, 1.8rem);
  font-variant-numeric: tabular-nums;
}

.vertical-math th,
.vertical-math td {
  padding: 0.08em 0.36em;
  text-align: right;
  white-space: nowrap;
}

.vertical-math .muted,
.vertical-math__hint {
  max-width: 32em;
  margin: 0.25em auto 0;
  color: var(--paper-muted);
  font-family: var(--font-ui);
  font-size: clamp(0.66rem, 1.1vw, 0.74rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.45;
  text-align: center;
}

/* ------------------------------------------------------------
   7. 選擇題
   ------------------------------------------------------------ */
.choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(8px, 1.2vh, 12px);
  min-width: 0;
}

.choice-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: clamp(58px, 8.4vh, 76px);
  padding: 0.7em 1em;
  overflow: hidden;
  color: var(--paper-ink);
  text-align: center;
  background: linear-gradient(180deg, #fffdf7 0%, var(--paper) 58%, var(--paper-warm) 100%);
  border: 2px solid var(--paper-line);
  border-radius: 18px;
  box-shadow:
    0 5px 0 var(--paper-line-strong),
    0 12px 22px rgba(0, 0, 0, 0.26),
    inset 0 1px 0 #fff;
  font-family: var(--font-num);
  font-size: clamp(1.12rem, 2.3vw, 1.62rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  letter-spacing: 0.02em;
  word-break: break-word;
  transition:
    transform 0.14s ease,
    box-shadow 0.14s ease,
    border-color 0.18s ease,
    background-color 0.18s ease,
    opacity 0.18s ease;
}

.choice-btn::before {
  content: "";
  position: absolute;
  top: 3px;
  right: 9px;
  left: 9px;
  height: 32%;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.72), transparent);
  border-radius: 12px 12px 50% 50%;
  opacity: 0.62;
}

.choice-btn:hover:not(:disabled):not(.is-selected) {
  border-color: var(--accent);
  box-shadow:
    0 8px 0 var(--paper-line-strong),
    0 16px 26px rgba(0, 0, 0, 0.23),
    0 0 0 3px var(--accent-soft);
  transform: translateY(-2px);
}

.choice-btn:active:not(:disabled) {
  box-shadow: 0 2px 0 var(--paper-line-strong);
  transform: translateY(3px);
}

.choice-btn.is-selected,
.choice-btn[aria-pressed="true"],
.choice-btn--selected {
  background: linear-gradient(180deg, #fffdf7, #fff0cb);
  border-color: var(--accent-2);
  box-shadow:
    0 5px 0 var(--paper-line-strong),
    0 0 0 4px rgba(251, 113, 133, 0.16),
    0 0 22px rgba(251, 113, 133, 0.18);
}

.choice-btn.is-correct,
.choice-btn--correct,
.choice-btn[data-state="correct"] {
  padding-right: 2.7rem;
  color: #064e38;
  background: linear-gradient(180deg, #f4fff9 0%, #d9fbec 60%, #bff5de 100%);
  border-color: var(--mint-deep);
  box-shadow:
    0 5px 0 #0b7a55,
    0 0 0 4px rgba(52, 211, 153, 0.18),
    0 0 28px rgba(52, 211, 153, 0.24);
}

.choice-btn.is-correct::after,
.choice-btn--correct::after,
.choice-btn[data-state="correct"]::after {
  content: "✓";
  position: absolute;
  top: 50%;
  right: 0.65rem;
  display: grid;
  place-items: center;
  width: 1.6em;
  height: 1.6em;
  color: #fff;
  background: var(--mint-deep);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.22);
  font-family: var(--font-ui);
  font-size: 0.68em;
  font-weight: 900;
  transform: translateY(-50%);
  animation: correct-burst 0.45s ease-out;
}

.choice-btn.is-wrong,
.choice-btn--wrong,
.choice-btn[data-state="wrong"] {
  padding-right: 2.7rem;
  color: #6e1427;
  background: linear-gradient(180deg, #fff8f9 0%, #ffe3e8 60%, #ffd0d8 100%);
  border-color: var(--coral-deep);
  box-shadow:
    0 5px 0 #8c1f36,
    0 0 0 4px rgba(251, 113, 133, 0.15);
  animation: shake 0.42s ease-in-out;
}

.choice-btn.is-wrong::after,
.choice-btn--wrong::after,
.choice-btn[data-state="wrong"]::after {
  content: "✕";
  position: absolute;
  top: 50%;
  right: 0.65rem;
  display: grid;
  place-items: center;
  width: 1.6em;
  height: 1.6em;
  color: #fff;
  background: var(--coral-deep);
  border: 2px solid #fff;
  border-radius: 50%;
  font-family: var(--font-ui);
  font-size: 0.68em;
  font-weight: 900;
  transform: translateY(-50%);
}

.choice-btn:disabled {
  opacity: 1;
  cursor: default;
}

.choices.is-locked .choice-btn:not(.is-correct):not(.is-wrong):not(.choice-btn--correct):not(.choice-btn--wrong) {
  opacity: 0.48;
  filter: saturate(0.45);
}

.choice-btn__key {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 1.5em;
  height: 1.5em;
  margin-right: 0.5em;
  color: var(--paper-muted);
  background: rgba(37, 27, 61, 0.07);
  border: 1px solid rgba(37, 27, 61, 0.09);
  border-radius: 50%;
  font-family: var(--font-ui);
  font-size: 0.58em;
  font-weight: 900;
  line-height: 1;
}

.choice-btn__text {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------
   8. 數字鍵盤與雙欄輸入
   ------------------------------------------------------------ */
.numpad {
  display: grid;
  gap: clamp(7px, 1.1vh, 11px);
  min-width: 0;
  padding: clamp(8px, 1.3vh, 13px);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.075), rgba(7, 8, 22, 0.24));
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 22px;
  box-shadow:
    var(--shadow-card),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.numpad__display {
  position: relative;
  min-width: 0;
  padding: clamp(7px, 1.1vh, 11px) clamp(10px, 1.4vw, 16px);
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(56, 189, 248, 0.12), transparent 72%),
    linear-gradient(180deg, #080a1c, #10132e);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  box-shadow:
    inset 0 6px 22px rgba(0, 0, 0, 0.48),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.numpad__display::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.022) 0,
    rgba(255, 255, 255, 0.022) 1px,
    transparent 1px,
    transparent 4px
  );
  opacity: 0.8;
}

.numpad__fields {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.numpad__field {
  display: flex;
  flex: 1 1 110px;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  padding: 3px 10px 5px;
  color: var(--text);
  font-family: var(--font-ui);
  text-align: left;
  background: transparent;
  border: 2px dashed rgba(255, 255, 255, 0.13);
  border-radius: 12px;
  cursor: pointer;
  transition:
    border-color 0.18s ease,
    background-color 0.18s ease,
    box-shadow 0.18s ease;
}

.numpad__field:hover {
  border-color: rgba(255, 255, 255, 0.28);
}

.numpad__field--active,
.numpad__field.is-active,
.numpad__field[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  border-style: solid;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.035);
}

.numpad__field-label,
.numpad__label {
  color: var(--accent-hi);
  font-size: clamp(0.6rem, 1vw, 0.7rem);
  font-weight: 900;
  line-height: 1.2;
  letter-spacing: 0.09em;
}

.numpad__value {
  display: block;
  min-height: 1.12em;
  max-width: 100%;
  overflow: hidden;
  color: var(--text);
  font-family: var(--font-num);
  font-size: clamp(1.8rem, 4.1vh, 2.9rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1.12;
  letter-spacing: 0.08em;
  text-overflow: ellipsis;
  text-shadow: 0 0 18px var(--glow);
  white-space: nowrap;
}

.numpad__field--active .numpad__value::after,
.numpad__field.is-active .numpad__value::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 0.86em;
  margin-left: 2px;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 8px var(--accent);
  vertical-align: -0.06em;
  animation: caret-blink 1.05s steps(1, end) infinite;
}

.numpad__unit {
  flex: 0 0 auto;
  align-self: flex-end;
  margin-bottom: 0.3em;
  color: var(--text-muted);
  font-size: clamp(0.7rem, 1.2vw, 0.82rem);
  font-weight: 800;
  line-height: 1;
}

.numpad__keys {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(6px, 0.9vh, 9px);
  min-width: 0;
}

.numpad__key,
.numpad__clear,
.numpad__submit {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 52px;
  padding: 0.35em;
  color: var(--paper-ink);
  background: linear-gradient(180deg, #fffdf7 0%, var(--paper) 55%, var(--paper-warm) 100%);
  border: 2px solid var(--paper-line);
  border-radius: 15px;
  box-shadow:
    0 4px 0 var(--paper-line-strong),
    0 8px 14px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 #fff;
  font-family: var(--font-num);
  font-size: clamp(1.18rem, 2.6vw, 1.6rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  user-select: none;
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease,
    border-color 0.16s ease,
    filter 0.16s ease;
}

.numpad__key:hover:not(:disabled),
.numpad__clear:hover:not(:disabled),
.numpad__submit:hover:not(:disabled) {
  border-color: var(--accent);
  filter: brightness(1.03);
}

.numpad__key:active:not(:disabled),
.numpad__clear:active:not(:disabled),
.numpad__submit:active:not(:disabled) {
  box-shadow: 0 1px 0 var(--paper-line-strong), 0 3px 8px rgba(0, 0, 0, 0.18);
  transform: translateY(3px);
}

.numpad__key:disabled,
.numpad__clear:disabled,
.numpad__submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.45);
}

.numpad__key--wide {
  grid-column: span 2;
}

.numpad__decimal,
.numpad__key--decimal {
  color: #0b6f9e;
}

.numpad__backspace {
  color: #7a2c0a;
  background: linear-gradient(180deg, #fffaf0, #ffe7c2);
  border-color: #e8c995;
  font-size: clamp(1.05rem, 2.2vw, 1.35rem);
}

.numpad__clear {
  color: #7a2c0a;
  background: linear-gradient(180deg, #fffaf0, #ffe7c2);
  border-color: #e8c995;
  font-family: var(--font-ui);
  font-size: clamp(0.78rem, 1.6vw, 0.94rem);
  letter-spacing: 0.05em;
}

.numpad__submit {
  grid-column: span 2;
  min-height: clamp(54px, 7.3vh, 64px);
  color: var(--accent-ink);
  background: linear-gradient(180deg, var(--accent-hi) 0%, var(--accent) 60%, var(--accent) 100%);
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow:
    0 5px 0 var(--accent-shadow),
    0 12px 24px var(--glow),
    inset 0 1px 0 rgba(255, 255, 255, 0.56);
  font-family: var(--font-ui);
  font-size: clamp(0.95rem, 1.9vw, 1.14rem);
  letter-spacing: 0.07em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.28);
}

.numpad__submit.numpad__key--wide {
  grid-column: span 2;
}

.numpad__submit:active:not(:disabled) {
  box-shadow: 0 2px 0 var(--accent-shadow), 0 5px 12px var(--glow);
}

.numpad__hint,
.numpad__note {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.45;
  text-align: center;
}

.dual-input {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(8px, 1.2vw, 12px);
  min-width: 0;
}

.dual-input .numpad__field,
.dual-input .numpad__display {
  min-width: 0;
}

.numpad-fallback {
  display: grid;
  gap: 10px;
  padding: clamp(10px, 1.6vh, 15px);
  color: var(--paper-ink);
  background:
    radial-gradient(rgba(37, 27, 61, 0.03) 1px, transparent 1.4px) 0 0 / 16px 16px,
    linear-gradient(170deg, #fffdf7, var(--paper-warm));
  border: 2px solid var(--paper-line);
  border-radius: 18px;
  box-shadow: 0 4px 0 var(--paper-line-strong), inset 0 1px 0 #fff;
}

.numpad-fallback label {
  display: grid;
  gap: 4px;
  color: var(--paper-muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.numpad-fallback input {
  width: 100%;
  min-height: 56px;
  padding: 0.45em 0.8em;
  color: var(--paper-ink);
  background: #fff;
  border: 2px solid var(--paper-line-strong);
  border-radius: 13px;
  font-family: var(--font-num);
  font-size: clamp(1.2rem, 2.5vw, 1.5rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.numpad-fallback input:focus-visible {
  border-color: var(--accent);
}

.numpad-fallback .btn {
  width: 100%;
  margin-top: 2px;
}

/* ------------------------------------------------------------
   9. 回饋訊息（答對／再想想／提示）
   ------------------------------------------------------------ */
.feedback {
  position: fixed;
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 12px));
  left: 50%;
  z-index: var(--z-feedback);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55em 0.7em;
  width: min(680px, calc(100vw - 28px));
  padding: clamp(10px, 1.5vh, 14px) clamp(13px, 2vw, 20px);
  color: var(--paper-ink);
  background: #fff9ec;
  border: 3px solid var(--paper-line);
  border-radius: 19px;
  box-shadow:
    0 16px 38px rgba(3, 3, 16, 0.42),
    0 5px 0 rgba(0, 0, 0, 0.18);
  font-size: clamp(0.9rem, 1.8vw, 1.04rem);
  font-weight: 800;
  line-height: 1.5;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, 22px);
}

.feedback.is-visible {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.feedback--correct,
.feedback.is-correct {
  background: linear-gradient(180deg, #f7fffb, #ddfff1);
  border-color: var(--mint-deep);
  box-shadow:
    0 16px 38px rgba(3, 3, 16, 0.42),
    0 0 0 5px rgba(52, 211, 153, 0.16),
    0 5px 0 #0b7a55;
}

.feedback--wrong,
.feedback.is-wrong {
  background: linear-gradient(180deg, #fffafa, #ffe8ec);
  border-color: var(--coral-deep);
  box-shadow:
    0 16px 38px rgba(3, 3, 16, 0.42),
    0 0 0 5px rgba(251, 113, 133, 0.14),
    0 5px 0 #8c1f36;
}

.feedback--hint,
.feedback.is-hint {
  background: linear-gradient(180deg, #fffdf4, #fff2cd);
  border-color: #c48a0a;
  box-shadow:
    0 16px 38px rgba(3, 3, 16, 0.42),
    0 0 0 5px rgba(255, 209, 102, 0.16),
    0 5px 0 #a86e08;
}

.feedback__icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 2em;
  height: 2em;
  color: #fff;
  background: var(--coral-deep);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
  font-family: var(--font-ui);
  font-size: 1em;
  font-weight: 900;
  line-height: 1;
}

.feedback--correct .feedback__icon,
.feedback.is-correct .feedback__icon {
  background: var(--mint-deep);
}

.feedback--hint .feedback__icon,
.feedback.is-hint .feedback__icon {
  width: auto;
  height: auto;
  background: none;
  border: 0;
  box-shadow: none;
  font-size: 1.5em;
}

.feedback__body {
  display: flex;
  flex: 1 1 240px;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.feedback__body strong {
  color: var(--paper-ink);
  font-size: 1.02em;
  font-weight: 900;
  line-height: 1.35;
}

.feedback__body p {
  margin: 0;
  color: var(--paper-muted);
  font-size: clamp(0.78rem, 1.35vw, 0.9rem);
  font-weight: 650;
  line-height: 1.55;
}

.feedback__small {
  color: var(--paper-muted) !important;
  font-size: clamp(0.7rem, 1.15vw, 0.8rem) !important;
  opacity: 0.9;
}

.feedback__streak {
  display: inline-flex;
  align-self: flex-start;
  margin-top: 2px !important;
  padding: 0.2em 0.65em;
  color: #7a4100 !important;
  background: linear-gradient(180deg, #fff4ce, #ffe4a0);
  border: 1px solid #e6c273;
  border-radius: var(--r-pill);
  font-size: 0.76rem !important;
  font-weight: 900 !important;
  line-height: 1.4 !important;
}

.feedback__next {
  flex: 0 0 auto;
  min-height: 48px;
  margin-left: auto;
  padding: 0.5em 1.1em;
  font-size: clamp(0.82rem, 1.4vw, 0.94rem);
}

/* ------------------------------------------------------------
   10. 三階鷹架：底部步驟面板
   ------------------------------------------------------------ */
.steps-panel {
  position: fixed;
  right: 12px;
  bottom: 0;
  left: 12px;
  z-index: var(--z-sheet);
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.4vh, 14px);
  width: min(760px, calc(100vw - 24px));
  max-height: min(84dvh, 720px);
  margin: 0 auto;
  padding: clamp(12px, 2vh, 22px) clamp(14px, 3vw, 30px)
    max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  color: var(--text);
  background:
    radial-gradient(ellipse 60% 36% at 50% 0%, var(--accent-soft), transparent 70%),
    linear-gradient(170deg, #292a5e 0%, #181936 54%, #101127 100%);
  border: 2px solid var(--line-strong);
  border-bottom: 0;
  border-radius: 28px 28px 0 0;
  box-shadow:
    0 -18px 60px rgba(0, 0, 0, 0.52),
    0 0 0 100vmax rgba(5, 4, 18, 0.64);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.steps-panel::before {
  content: "";
  flex: 0 0 auto;
  width: 48px;
  height: 5px;
  margin: 0 auto 2px;
  background: rgba(255, 255, 255, 0.26);
  border-radius: var(--r-pill);
}

.steps-panel h2,
.steps-panel h3,
.steps-panel__title {
  color: var(--text);
  font-size: clamp(1.05rem, 2.2vw, 1.35rem);
  text-align: center;
}

.steps-panel__subtitle {
  margin-top: -0.4em;
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
}

/* app.js 實際輸出的面板結構 */
.steps__sheet {
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.3vh, 13px);
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
}

.steps__head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: center;
}

.steps__kicker {
  color: var(--accent-hi);
  font-size: clamp(0.72rem, 1.3vw, 0.82rem);
  font-weight: 900;
  letter-spacing: 0.09em;
}

.steps__head h2 {
  color: var(--text);
  font-size: clamp(1.06rem, 2.2vw, 1.32rem);
}

.steps__progress {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  gap: 0.35em;
  min-height: 30px;
  padding: 0.24em 0.85em;
  color: var(--accent-hi);
  background: rgba(255, 255, 255, 0.075);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  font-size: clamp(0.68rem, 1.2vw, 0.78rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.steps__body {
  display: grid;
  gap: clamp(7px, 1.2vh, 11px);
  padding: clamp(11px, 1.8vh, 16px) clamp(11px, 2.4vw, 18px);
  color: var(--paper-ink);
  background:
    radial-gradient(rgba(37, 27, 61, 0.03) 1px, transparent 1.4px) 0 0 / 16px 16px,
    linear-gradient(170deg, #fffdf7, var(--paper) 54%, var(--paper-warm));
  border: 2px solid var(--paper-line);
  border-radius: 18px;
  box-shadow:
    0 4px 0 var(--paper-line-strong),
    inset 0 1px 0 #fff;
}

.steps__body .step__prompt {
  font-size: clamp(0.92rem, 1.6vw, 1.04rem);
  line-height: 1.62;
}

.step__answer-box {
  display: grid;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.step__feedback {
  min-height: 1.4em;
  color: var(--paper-muted);
  font-size: clamp(0.76rem, 1.3vw, 0.86rem);
  font-weight: 800;
  line-height: 1.45;
}

.step__feedback.is-correct {
  color: var(--mint-deep);
}

.step__feedback.is-wrong {
  color: var(--coral-deep);
}

.step__feedback::before {
  margin-right: 0.35em;
  font-weight: 900;
}

.step__feedback.is-correct::before {
  content: "✓";
  color: var(--mint-deep);
}

.step__feedback.is-wrong::before {
  content: "↻";
  color: var(--coral-deep);
}

.step__input {
  width: 100%;
  min-height: 56px;
  padding: 0.5em 0.8em;
  color: var(--paper-ink);
  background: #fffdf7;
  border: 2px solid var(--paper-line-strong);
  border-radius: 14px;
  font-family: var(--font-num);
  font-size: clamp(1.15rem, 2.3vw, 1.45rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.step__input:focus-visible {
  border-color: var(--accent);
}

.steps__done {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: clamp(6px, 1.2vh, 12px) 4px clamp(2px, 0.8vh, 8px);
  text-align: center;
}

.steps__done-icon {
  display: grid;
  place-items: center;
  width: clamp(56px, 9vh, 76px);
  aspect-ratio: 1;
  background:
    radial-gradient(circle at 36% 28%, #fff9d9, #ffd166 62%, #e3a21a 100%);
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow:
    0 0 26px rgba(255, 209, 102, 0.5),
    0 6px 14px rgba(0, 0, 0, 0.16);
  font-size: clamp(1.8rem, 4.5vh, 2.6rem);
  line-height: 1;
  animation: pop-in 0.45s cubic-bezier(0.2, 0.84, 0.34, 1.2) both;
}

.steps__done h3 {
  color: var(--paper-ink);
  font-size: clamp(1rem, 2vw, 1.18rem);
  text-align: center;
}

.steps__done p {
  max-width: 36em;
  color: var(--paper-muted);
  font-size: clamp(0.8rem, 1.35vw, 0.9rem);
  font-weight: 600;
  line-height: 1.65;
}

.steps__done .btn {
  margin-top: 3px;
}

.steps__foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.steps__foot .btn {
  min-height: 44px;
}

.steps-panel .steps__body .numpad {
  margin-top: 0;
}

.steps {
  display: grid;
  gap: clamp(8px, 1.2vh, 12px);
  width: 100%;
}

.step {
  position: relative;
  display: grid;
  gap: 4px;
  padding: clamp(10px, 1.6vh, 15px) clamp(12px, 2vw, 18px);
  color: var(--paper-ink);
  background: linear-gradient(170deg, #fffdf7, var(--paper-warm));
  border: 2px solid var(--paper-line);
  border-radius: 17px;
  box-shadow:
    0 3px 0 var(--paper-line-strong),
    inset 0 1px 0 #fff;
}

.step::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 5px;
  height: 100%;
  background: var(--accent);
  border-radius: 5px 0 0 5px;
  opacity: 0.9;
}

.step.is-active,
.step--active {
  border-color: var(--accent);
  box-shadow:
    0 3px 0 var(--accent-shadow),
    0 0 0 3px var(--accent-soft);
}

.step.is-done,
.step--done {
  background: linear-gradient(170deg, #f7fffb, #dcfbee);
  border-color: #8fdcbf;
}

.step.is-done::before,
.step--done::before {
  background: var(--mint-deep);
}

.step__prompt {
  color: var(--paper-ink);
  font-size: clamp(0.9rem, 1.5vw, 1rem);
  font-weight: 800;
  line-height: 1.6;
}

.step__progress {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  width: fit-content;
  min-height: 26px;
  padding: 0.2em 0.65em;
  color: #6c4700;
  background: #fff0c6;
  border: 1px solid #e6ca83;
  border-radius: var(--r-pill);
  font-size: 0.72rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.step .numpad {
  margin-top: 6px;
}

.step .numpad__display {
  padding-top: 5px;
  padding-bottom: 5px;
}

.step .numpad__key,
.step .numpad__clear,
.step .numpad__submit {
  min-height: 48px;
}

.steps-panel__footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* ------------------------------------------------------------
   11. 過關結算
   ------------------------------------------------------------ */
.result__stars .star,
.result__stars .result-star,
.result__stars > * {
  color: #dfd1b5;
  font-size: clamp(2.7rem, 6.6vw, 4.6rem);
  line-height: 1;
  text-shadow: 0 3px 0 rgba(130, 102, 52, 0.18);
}

.result__stars .star--on,
.result__stars .is-on,
.result__stars .result-star--on {
  color: var(--gold);
  text-shadow:
    0 0 16px rgba(255, 209, 102, 0.7),
    0 4px 0 #b27a08,
    0 10px 24px rgba(160, 100, 0, 0.26);
}

.result__rewards > *,
.reward,
.reward-chip,
.result-reward {
  display: inline-flex;
  align-items: center;
  gap: 0.38em;
  min-height: 38px;
  padding: 0.3em 0.85em;
  color: #5c3d06;
  background: linear-gradient(180deg, #fff8e4, #ffe9b5);
  border: 2px solid #e0c17a;
  border-radius: var(--r-pill);
  box-shadow:
    0 3px 0 #c4a45f,
    inset 0 1px 0 #fff;
  font-size: clamp(0.78rem, 1.4vw, 0.9rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

.reward--monster,
.reward-chip--monster {
  color: #5b2a75;
  background: linear-gradient(180deg, #fbf1ff, #ecd8ff);
  border-color: #c9a8e6;
  box-shadow: 0 3px 0 #a987c4;
}

.reward--coins,
.reward-chip--coins {
  color: #6b4500;
}

.result__monster {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2vw, 18px);
  padding: clamp(12px, 2vh, 18px) clamp(14px, 2.4vw, 24px);
  color: var(--text);
  text-align: left;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(167, 139, 250, 0.22), transparent 62%),
    linear-gradient(155deg, #242557, #11122a);
  border: 2px solid var(--line-strong);
  border-radius: 22px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 6px 0 rgba(0, 0, 0, 0.2);
}

.result__monster .monster-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: clamp(10px, 2vw, 16px);
  width: 100%;
  padding: 0;
  color: var(--text);
  text-align: left;
  background: none;
  border: 0;
  box-shadow: none;
  transform: none;
}

.result__monster .monster-card__art,
.result__monster .monster-card__emoji {
  flex: 0 0 auto;
  width: clamp(56px, 8vh, 78px);
  height: clamp(56px, 8vh, 78px);
  font-size: clamp(2rem, 5vh, 3rem);
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid var(--line);
  border-radius: 50%;
}

.result__monster .monster-card__name {
  color: var(--text);
}

.result__monster .monster-card__fact,
.result__monster .fact {
  margin-top: 3px;
  padding-top: 5px;
  color: var(--text-dim);
  border-top-color: var(--line);
  font-size: 0.78rem;
}

.monster-card__body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
}

.monster-card__body .badge {
  align-self: flex-start;
  margin-bottom: 2px;
  color: var(--accent-hi);
  background: var(--accent-soft);
  border-color: var(--line);
}

.monster-card__body h3 {
  color: var(--text);
  font-size: clamp(0.98rem, 1.8vw, 1.16rem);
  text-align: left;
}

.monster-card__body p {
  margin: 0;
  color: var(--text-dim);
  font-size: clamp(0.72rem, 1.2vw, 0.82rem);
  font-weight: 600;
  line-height: 1.55;
}

.monster-card--result .monster-card__emoji {
  display: grid;
  place-items: center;
}

.reward-chip--coin,
.reward-chip--star,
.reward-chip--level {
  max-width: 100%;
}

.reward-chip small {
  margin-left: 0.2em;
  color: #8a6020;
  font-size: 0.8em;
  font-weight: 800;
  white-space: normal;
}

.result__monster__emoji {
  flex: 0 0 auto;
  font-size: clamp(2.4rem, 6vh, 3.6rem);
  line-height: 1;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.35));
}

.result__monster__text {
  min-width: 0;
}

.result__monster__name {
  font-size: clamp(0.95rem, 1.8vw, 1.15rem);
  font-weight: 900;
}

.result__monster__fact {
  margin-top: 3px;
  color: var(--text-dim);
  font-size: clamp(0.72rem, 1.2vw, 0.82rem);
  line-height: 1.55;
}

/* ------------------------------------------------------------
   12. 飛船工坊
   ------------------------------------------------------------ */
.shop-preview {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: clamp(190px, 30vh, 280px);
  padding: clamp(14px, 2.4vh, 24px);
  overflow: hidden;
  text-align: center;
  background:
    radial-gradient(ellipse 42% 52% at 50% 46%, var(--accent-soft), transparent 70%),
    radial-gradient(ellipse 70% 46% at 50% 100%, rgba(56, 189, 248, 0.16), transparent 72%),
    linear-gradient(180deg, #1d1e44 0%, #13142f 58%, #0c0d22 100%);
  border: 2px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow:
    var(--shadow-card),
    inset 0 0 60px rgba(56, 189, 248, 0.06);
  isolation: isolate;
}

.shop-preview > * {
  position: relative;
  z-index: 1;
}

.shop-preview::before {
  content: "";
  position: absolute;
  right: -18%;
  bottom: -62%;
  left: -18%;
  z-index: 0;
  height: 100%;
  background-image:
    linear-gradient(rgba(56, 189, 248, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 189, 248, 0.16) 1px, transparent 1px);
  background-size: 42px 42px;
  transform: perspective(420px) rotateX(62deg);
  transform-origin: center top;
  opacity: 0.5;
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 52%);
  mask-image: linear-gradient(180deg, transparent, #000 52%);
}

.shop-preview::after {
  content: "";
  position: absolute;
  top: 8%;
  left: 50%;
  z-index: 0;
  width: 44%;
  height: 84%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 76%);
  clip-path: polygon(42% 0, 58% 0, 100% 100%, 0 100%);
  transform: translateX(-50%);
  opacity: 0.35;
  pointer-events: none;
}

.shop-preview__scene {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: clamp(130px, 23vh, 220px);
}

.shop-preview__meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
}

.shop-preview__meta h2 {
  color: var(--text);
  font-size: clamp(1rem, 2vw, 1.3rem);
  text-align: center;
}

.shop-preview__meta p {
  max-width: 38em;
  color: var(--text-muted);
  font-size: clamp(0.74rem, 1.2vw, 0.84rem);
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
}

.shop-preview__meta .badge {
  margin-bottom: 2px;
}

.shop-preview .ship {
  --ship-size: clamp(180px, 30vh, 280px);
  filter: drop-shadow(0 24px 22px rgba(0, 0, 0, 0.34));
}

.shop-preview__label {
  margin-top: 4px;
  color: var(--accent-hi);
  font-size: clamp(0.72rem, 1.2vw, 0.82rem);
  font-weight: 900;
  letter-spacing: 0.12em;
}

.shop-preview__name {
  margin-top: 2px;
  color: var(--text);
  font-size: clamp(1rem, 2vw, 1.3rem);
  font-weight: 900;
}

.shop-preview__hint {
  max-width: 36em;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.shop-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: clamp(10px, 1.8vh, 15px);
  overflow: hidden;
  color: var(--paper-ink);
  text-align: center;
  background:
    radial-gradient(rgba(37, 27, 61, 0.028) 1px, transparent 1.4px) 0 0 / 15px 15px,
    linear-gradient(170deg, #fffdf7, var(--paper) 56%, var(--paper-warm));
  border: 2px solid var(--paper-line);
  border-radius: 21px;
  box-shadow:
    0 5px 0 var(--paper-line-strong),
    0 13px 24px rgba(0, 0, 0, 0.26),
    inset 0 1px 0 #fff;
  font-family: var(--font-ui);
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.18s ease,
    filter 0.18s ease;
}

.shop-card:hover:not(:disabled):not(.is-locked) {
  border-color: var(--accent);
  box-shadow:
    0 8px 0 var(--paper-line-strong),
    0 18px 30px rgba(0, 0, 0, 0.24),
    0 0 0 3px var(--accent-soft);
  transform: translateY(-3px);
}

.shop-card:active:not(:disabled):not(.is-locked) {
  box-shadow: 0 2px 0 var(--paper-line-strong);
  transform: translateY(3px);
}

.shop-card:disabled,
.shop-card[aria-disabled="true"] {
  cursor: not-allowed;
  filter: saturate(0.55);
}

.shop-card__art,
.shop-card__emoji {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: clamp(78px, 13vh, 118px);
  font-size: clamp(2.5rem, 6vw, 3.7rem);
  line-height: 1;
  background:
    radial-gradient(circle at 50% 68%, var(--accent-soft), transparent 68%),
    linear-gradient(160deg, rgba(56, 189, 248, 0.07), rgba(37, 27, 61, 0.055));
  border: 1.5px solid rgba(37, 27, 61, 0.09);
  border-radius: 16px;
  filter: drop-shadow(0 7px 8px rgba(53, 33, 0, 0.12));
}

.shop-card__name {
  color: var(--paper-ink);
  font-size: clamp(0.92rem, 1.5vw, 1.04rem);
  font-weight: 900;
  line-height: 1.35;
}

.shop-card__desc {
  color: var(--paper-muted);
  font-size: clamp(0.68rem, 1.1vw, 0.78rem);
  font-weight: 600;
  line-height: 1.45;
}

.shop-card__price,
.price {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  min-height: 32px;
  margin-top: auto;
  padding: 0.25em 0.75em;
  color: #6b4500;
  background: linear-gradient(180deg, #fff7db, #ffe8ad);
  border: 1.5px solid #e0bf6f;
  border-radius: var(--r-pill);
  font-size: clamp(0.78rem, 1.3vw, 0.88rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.shop-card__type {
  position: absolute;
  top: 8px;
  left: 9px;
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0.18em 0.55em;
  color: #6a4d12;
  background: rgba(255, 248, 229, 0.86);
  border: 1px solid rgba(37, 27, 61, 0.1);
  border-radius: var(--r-pill);
  font-size: 0.62rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.02em;
}

.shop-card__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: auto;
  padding-top: 4px;
}

.shop-card__foot .shop-card__price {
  margin-top: 0;
}

.shop-card__foot .btn {
  min-height: 44px;
  padding: 0.45em 0.9em;
  font-size: 0.8rem;
}

.shop-card__tag,
.shop-card__badge,
.shop-card__status {
  display: inline-flex;
  align-items: center;
  gap: 0.25em;
  min-height: 27px;
  padding: 0.2em 0.62em;
  color: #5b2a75;
  background: #f3e5ff;
  border: 1px solid #d4b6ec;
  border-radius: var(--r-pill);
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
}

.shop-card--owned,
.shop-card.is-owned {
  border-color: #8ed8bc;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(52, 211, 153, 0.14), transparent 62%),
    linear-gradient(170deg, #fbfffd, #edfbf4 58%, #ddf7eb);
}

.shop-card--equipped,
.shop-card.is-equipped {
  border-color: var(--accent);
  box-shadow:
    0 5px 0 var(--accent-shadow),
    0 0 0 4px var(--accent-soft),
    0 0 24px var(--glow);
}

.shop-card--owned::after,
.shop-card.is-owned::after {
  content: "✓";
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  color: #fff;
  background: var(--mint-deep);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 3px 7px rgba(0, 0, 0, 0.16);
  font-size: 0.72rem;
  font-weight: 900;
}

.shop-card--equipped::after,
.shop-card.is-equipped::after {
  content: "★";
  color: var(--accent-ink);
  background: var(--accent);
  border-color: #fff;
}

.shop-card--locked,
.shop-card.is-locked {
  opacity: 0.6;
  border-style: dashed;
}

/* ------------------------------------------------------------
   13. 星際圖鑑
   ------------------------------------------------------------ */
.monster-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
  min-width: 0;
  padding: clamp(10px, 1.7vh, 15px);
  overflow: hidden;
  color: var(--paper-ink);
  font-family: var(--font-ui);
  text-align: left;
  background:
    radial-gradient(rgba(37, 27, 61, 0.028) 1px, transparent 1.4px) 0 0 / 15px 15px,
    linear-gradient(170deg, #fffdf7, var(--paper) 58%, var(--paper-warm));
  border: 2px solid var(--paper-line);
  border-radius: 21px;
  box-shadow:
    0 5px 0 var(--paper-line-strong),
    0 13px 24px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 #fff;
  cursor: pointer;
  transition:
    transform 0.16s ease,
    box-shadow 0.16s ease,
    border-color 0.18s ease;
}

.monster-card__level {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  min-height: 22px;
  padding: 0.15em 0.55em;
  color: #7a5a16;
  background: rgba(255, 247, 224, 0.9);
  border: 1px solid rgba(37, 27, 61, 0.09);
  border-radius: var(--r-pill);
  font-size: 0.62rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.04em;
}

.monster-card:hover:not(.monster-card--locked) {
  border-color: var(--accent);
  box-shadow:
    0 8px 0 var(--paper-line-strong),
    0 0 0 3px var(--accent-soft),
    0 18px 30px rgba(0, 0, 0, 0.22);
  transform: translateY(-3px);
}

.monster-card__art,
.monster-card__emoji {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: clamp(78px, 13vh, 116px);
  font-size: clamp(2.5rem, 6vw, 3.8rem);
  line-height: 1;
  background:
    radial-gradient(circle at 50% 64%, var(--accent-soft), transparent 66%),
    linear-gradient(155deg, rgba(167, 139, 250, 0.1), rgba(56, 189, 248, 0.06));
  border: 1.5px solid rgba(37, 27, 61, 0.09);
  border-radius: 16px;
  filter: drop-shadow(0 8px 9px rgba(53, 33, 0, 0.14));
}

.monster-card__name {
  color: var(--paper-ink);
  font-size: clamp(0.9rem, 1.5vw, 1.04rem);
  font-weight: 900;
  line-height: 1.35;
}

.monster-card__id {
  color: #9a7b3d;
  font-family: var(--font-num);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  line-height: 1;
}

.monster-card__fact,
.fact {
  color: var(--paper-muted);
  font-size: clamp(0.68rem, 1.1vw, 0.78rem);
  font-weight: 600;
  line-height: 1.55;
}

.monster-card__fact {
  margin-top: 2px;
  padding-top: 6px;
  border-top: 1px dashed var(--paper-line-strong);
}

.monster-card--locked,
.monster-card.is-locked {
  color: var(--text-dim);
  cursor: default;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.08), rgba(10, 10, 28, 0.24));
  border-color: var(--line-strong);
  border-style: dashed;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 14px 28px rgba(0, 0, 0, 0.18);
}

.monster-card--locked .monster-card__art,
.monster-card--locked .monster-card__emoji,
.monster-card.is-locked .monster-card__art,
.monster-card.is-locked .monster-card__emoji {
  color: var(--text-muted);
  background:
    radial-gradient(circle at 50% 64%, rgba(255, 255, 255, 0.09), transparent 68%),
    rgba(255, 255, 255, 0.04);
  border-color: var(--line);
  filter: grayscale(1) brightness(0.52);
}

.monster-card--locked .monster-card__name,
.monster-card.is-locked .monster-card__name {
  color: var(--text-muted);
}

.monster-card--locked .monster-card__fact,
.monster-card.is-locked .monster-card__fact {
  color: var(--text-muted);
  border-top-color: var(--line);
}

.monster-card--locked::after {
  content: "🔒";
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 1.15rem;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

/* ------------------------------------------------------------
   14. 設定 Dialog
   ------------------------------------------------------------ */
.dialog {
  width: min(560px, calc(100vw - 26px));
  max-width: none;
  max-height: min(86dvh, 720px);
  padding: 0;
  overflow: visible;
  color: var(--text);
  background: transparent;
  border: 0;
}

.dialog::backdrop {
  background: rgba(4, 4, 15, 0.72);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
}

.dialog__form {
  display: flex;
  flex-direction: column;
  max-height: min(86dvh, 720px);
  overflow: hidden;
  background:
    radial-gradient(ellipse 60% 32% at 50% 0%, var(--accent-soft), transparent 70%),
    linear-gradient(170deg, #292a5e 0%, #181936 52%, #101127 100%);
  border: 2px solid var(--line-strong);
  border-radius: 28px;
  box-shadow:
    0 28px 80px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.13);
}

.dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.dialog__head h2 {
  color: var(--text);
  font-size: clamp(1.12rem, 2.4vw, 1.35rem);
}

.dialog__body {
  display: grid;
  gap: 9px;
  padding: 16px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 0.55em 0.9em;
  color: var(--text);
  background: rgba(255, 255, 255, 0.065);
  border: 1.5px solid var(--line);
  border-radius: 15px;
  font-weight: 800;
  text-align: left;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    transform 0.14s ease;
}

.setting-row:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.setting-row:active {
  transform: translateY(1px);
}

.setting-row__state {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0.2em 0.7em;
  color: var(--accent-hi);
  background: var(--accent-soft);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--r-pill);
  font-size: 0.74rem;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.setting-row[aria-pressed="true"] .setting-row__state {
  color: var(--accent-ink);
  background: var(--accent);
}

.setting-row--teacher {
  background: rgba(56, 189, 248, 0.08);
  border-color: rgba(56, 189, 248, 0.24);
}

.setting-row--teacher .setting-row__state {
  color: #bfefff;
  background: rgba(56, 189, 248, 0.13);
}

.setting-row--danger {
  background: rgba(251, 113, 133, 0.075);
  border-color: rgba(251, 113, 133, 0.24);
}

.setting-row--danger .setting-row__state {
  color: #ffd2d9;
  background: rgba(251, 113, 133, 0.16);
}

.dialog__hr {
  margin: 5px 0;
  border-top: 1px dashed var(--line);
}

.dialog__note {
  margin-top: 3px;
  padding: 0.7em 0.85em;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.14);
  border-radius: 12px;
  font-size: 0.76rem;
  line-height: 1.6;
}

.dialog__version {
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.08em;
}

.dialog__foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

/* ------------------------------------------------------------
   15. 計算紙
   ------------------------------------------------------------ */
.scratchpad-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-scratchpad);
  display: grid;
  place-items: center;
  padding:
    max(10px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  background: rgba(4, 4, 16, 0.74);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.scratchpad {
  display: flex;
  flex-direction: column;
  width: min(1120px, 100%);
  height: min(78dvh, 760px);
  min-height: 300px;
  overflow: hidden;
  background: var(--paper);
  border: 4px solid #f3e1bd;
  border-radius: 24px;
  box-shadow:
    0 34px 90px rgba(0, 0, 0, 0.58),
    0 0 0 1px rgba(255, 255, 255, 0.2);
}

.scratchpad__bar {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 9px 14px;
  color: var(--text);
  background:
    linear-gradient(180deg, #26275a, #171834);
  border-bottom: 1px solid var(--line);
}

.scratchpad__bar strong {
  font-size: 0.94rem;
  font-weight: 900;
  white-space: nowrap;
}

.scratchpad__tip {
  flex: 1 1 150px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.35;
}

.scratchpad__tools {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-left: auto;
}

.scratchpad__tools .btn {
  min-height: 44px;
}

.scratchpad__tools .btn[aria-pressed="true"] {
  color: #fff;
  background: linear-gradient(180deg, #a83a54, var(--coral-deep));
  border-color: #ffc0ca;
  box-shadow: 0 4px 0 #71172c;
}

.scratchpad__canvas {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  background-color: #fffdf7;
  background-image: radial-gradient(rgba(37, 27, 61, 0.085) 1px, transparent 1.3px);
  background-size: 22px 22px;
  cursor: crosshair;
  touch-action: none;
}

.scratchpad-overlay:not([hidden]) .scratchpad {
  animation: scratchpad-in 0.25s ease-out;
}

/* ------------------------------------------------------------
   16. Toast 與彩紙
   ------------------------------------------------------------ */
.toast {
  position: fixed;
  right: auto;
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 12px));
  left: 50%;
  z-index: var(--z-toast);
  max-width: min(560px, calc(100vw - 28px));
  padding: 0.72em 1.2em;
  color: var(--paper-ink);
  background: linear-gradient(180deg, #fffdf6, #fff0cf);
  border: 2px solid var(--paper-line);
  border-radius: var(--r-pill);
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.38),
    0 4px 0 #cbb58d;
  font-size: clamp(0.84rem, 1.5vw, 0.94rem);
  font-weight: 800;
  line-height: 1.45;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, 16px);
}

.toast.is-visible {
  visibility: visible;
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast--success {
  color: #064e38;
  background: linear-gradient(180deg, #f7fffb, #d9fbec);
  border-color: #8ed8bc;
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.38),
    0 0 0 4px rgba(52, 211, 153, 0.12),
    0 4px 0 #0b7a55;
}

.toast--warn {
  color: #6b4300;
  background: linear-gradient(180deg, #fffdf5, #fff1c9);
  border-color: #e0bd6b;
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.38),
    0 0 0 4px rgba(255, 209, 102, 0.13),
    0 4px 0 #a86e08;
}

.toast--info {
  color: #07415c;
  background: linear-gradient(180deg, #f7fdff, #dcf5ff);
  border-color: #93d8f4;
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.38),
    0 0 0 4px rgba(56, 189, 248, 0.12),
    0 4px 0 #0b6f9e;
}

.toast--success::before,
.toast--warn::before,
.toast--info::before {
  margin-right: 0.38em;
  font-weight: 900;
}

.toast--success::before {
  content: "✓";
  color: var(--mint-deep);
}

.toast--warn::before {
  content: "!";
  color: #a86e08;
}

.toast--info::before {
  content: "✦";
  color: #0b6f9e;
}

.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: var(--z-confetti);
  overflow: hidden;
  pointer-events: none;
}

.confetti__piece {
  position: absolute;
  top: -6vh;
  left: 50%;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0;
  animation: confetti-fall var(--d, 2.8s) cubic-bezier(0.2, 0.62, 0.42, 1) var(--delay, 0s) forwards;
}

.confetti__piece:nth-child(3n) {
  border-radius: 50%;
}

.confetti__piece:nth-child(4n) {
  width: 8px;
  height: 21px;
}

.confetti__piece:nth-child(5n) {
  width: 12px;
  height: 8px;
  border-radius: 1px;
}

/* ------------------------------------------------------------
   17. 零星動態元件的結構樣式
   ------------------------------------------------------------ */
.answer-value,
.answer-unit {
  font-variant-numeric: tabular-nums;
}

.answer-value {
  color: var(--paper-ink);
  font-family: var(--font-num);
  font-size: clamp(1.6rem, 3.6vh, 2.4rem);
  font-weight: 900;
}

.answer-unit {
  color: var(--paper-muted);
  font-size: 0.9rem;
  font-weight: 800;
}

/* 提示／解說區塊（JS 可在題目卡或結算中使用） */
.hint-box,
.explanation {
  padding: 0.8em 1em;
  color: var(--paper-ink);
  background: linear-gradient(170deg, #fffdf5, #fff0cd);
  border: 2px solid #e7ce98;
  border-left: 6px solid var(--accent);
  border-radius: 14px;
  font-size: clamp(0.82rem, 1.3vw, 0.92rem);
  font-weight: 600;
  line-height: 1.6;
}

.hint-box__title,
.explanation__title {
  display: block;
  margin-bottom: 0.25em;
  color: #7a5200;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.06em;
}

/* 進度條（若 JS 使用原生元素） */
progress {
  width: 100%;
  height: 10px;
  overflow: hidden;
  appearance: none;
  background: rgba(255, 255, 255, 0.12);
  border: 0;
  border-radius: var(--r-pill);
}

progress::-webkit-progress-bar {
  background: rgba(255, 255, 255, 0.12);
  border-radius: var(--r-pill);
}

progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: var(--r-pill);
}

progress::-moz-progress-bar {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: var(--r-pill);
}

/* ------------------------------------------------------------
   18. 元件響應式微調
   ------------------------------------------------------------ */
@media (max-width: 919px) {
  .level-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .level-card {
    padding: 8px 9px;
  }

  .galaxy {
    padding: 10px 11px;
  }

  .galaxy__head {
    margin-bottom: 7px;
  }

  .steps-panel {
    right: 0;
    left: 0;
    width: 100%;
    border-right: 0;
    border-left: 0;
    border-radius: 24px 24px 0 0;
  }
}

@media (max-width: 720px) {
  .btn {
    min-height: 50px;
    padding: 0.58em 1em;
    border-radius: 16px;
  }

  .btn--icon {
    width: 48px;
    min-width: 48px;
    height: 48px;
    min-height: 48px;
    border-radius: 15px;
    font-size: 1.1rem;
  }

  .btn--xl {
    min-height: 58px;
    padding: 0.7em 1.4em;
    font-size: 1.06rem;
  }

  .topbar,
  .playbar {
    gap: 7px;
  }

  .topbar__kicker {
    font-size: 0.62rem;
    letter-spacing: 0.07em;
  }

  .topbar__title h1 {
    font-size: 1.12rem;
  }

  .topbar__stats,
  .playbar__tools {
    gap: 5px;
  }

  .pill {
    min-height: 34px;
    padding: 0.22em 0.58em;
    font-size: 0.76rem;
  }

  .playbar__level {
    font-size: 0.78rem;
  }

  .dot,
  .dots > span,
  .dots > i {
    width: 10px;
    height: 10px;
  }

  .galaxy-list {
    gap: 10px;
  }

  .level-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .level-card {
    min-height: 92px;
  }

  .level-card__title {
    font-size: 0.78rem;
  }

  .galaxy__badge {
    width: 34px;
    border-radius: 12px;
  }

  .galaxy__title {
    font-size: 0.94rem;
  }

  .galaxy__tagline {
    font-size: 0.66rem;
  }

  .question-card {
    padding: 12px 14px;
  }

  .question-card__prompt {
    font-size: 1rem;
    line-height: 1.62;
  }

  .play-visual {
    padding: 10px;
  }

  .choices {
    gap: 8px;
  }

  .choice-btn {
    min-height: 56px;
    font-size: 1.16rem;
  }

  .numpad__value {
    font-size: clamp(1.65rem, 6.4vw, 2.3rem);
  }

  .numpad__keys {
    gap: 7px;
  }

  .numpad__key,
  .numpad__clear,
  .numpad__submit {
    min-height: 52px;
  }

  .feedback {
    max-width: calc(100vw - 20px);
    font-size: 0.86rem;
  }

  .shop-card__art,
  .shop-card__emoji,
  .monster-card__art,
  .monster-card__emoji {
    min-height: 82px;
  }

  .scratchpad {
    width: 100%;
    height: min(84dvh, 760px);
    border-width: 3px;
    border-radius: 20px;
  }

  .scratchpad__bar {
    padding: 8px 10px;
  }

  .scratchpad__tip {
    display: none;
  }

  .scratchpad__tools {
    width: 100%;
    margin-left: 0;
  }

  .scratchpad__tools .btn {
    flex: 1 1 auto;
  }

  .dialog__head,
  .dialog__body {
    padding-right: 14px;
    padding-left: 14px;
  }

  .dialog__foot {
    padding-right: 14px;
    padding-left: 14px;
  }

  .setting-row {
    min-height: 52px;
  }

  .result__card::before,
  .result__card::after {
    font-size: 1rem;
  }
}

@media (max-width: 480px) {
  .choices {
    grid-template-columns: minmax(0, 1fr);
  }

  .choice-btn {
    min-height: 54px;
  }

  .topbar__kicker {
    display: none;
  }

  .topbar__title h1 {
    font-size: 1.04rem;
  }

  .playbar__tools .pill {
    min-width: 0;
    padding-inline: 0.45em;
  }

  .galaxy__progress,
  .galaxy__count,
  .galaxy__stars {
    font-size: 0.62rem;
  }

  .galaxy__badge {
    width: 30px;
  }

  .level-card {
    min-height: 88px;
    padding: 7px 8px;
  }

  .level-card__title {
    font-size: 0.73rem;
  }

  .level-card__meta {
    display: none;
  }

  .numpad__key,
  .numpad__clear,
  .numpad__submit {
    border-radius: 13px;
  }

  .feedback {
    align-items: flex-start;
  }

  .monster-card__art,
  .monster-card__emoji,
  .shop-card__art,
  .shop-card__emoji {
    min-height: 76px;
    font-size: 2.4rem;
  }
}

/* 橫向手機：壓低元件高度但維持 52px 觸控目標 */
@media (orientation: landscape) and (max-height: 560px) {
  .btn {
    min-height: 48px;
    font-size: 0.84rem;
  }

  .btn--icon {
    width: 46px;
    min-width: 46px;
    height: 46px;
    min-height: 46px;
  }

  .btn--xl {
    min-height: 52px;
    padding: 0.55em 1.2em;
    font-size: 0.95rem;
  }

  .topbar,
  .playbar {
    min-height: 50px;
  }

  .playbar {
    padding-top: 5px;
    padding-bottom: 4px;
  }

  .topbar {
    padding-bottom: 4px;
  }

  .topbar__kicker {
    display: none;
  }

  .topbar__title h1 {
    font-size: 1.08rem;
  }

  .pill {
    min-height: 32px;
    font-size: 0.74rem;
  }

  .galaxy {
    padding: 7px 8px;
    border-radius: 18px;
  }

  .galaxy__head {
    gap: 6px;
    margin-bottom: 5px;
  }

  .galaxy__badge {
    width: 27px;
    border-radius: 9px;
    font-size: 0.86rem;
  }

  .galaxy__title {
    font-size: 0.78rem;
  }

  .galaxy__tagline {
    font-size: 0.58rem;
  }

  .level-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .level-card {
    min-height: 0;
    padding: 5px 6px;
    border-radius: 12px;
  }

  .level-card__number {
    min-width: 18px;
    min-height: 18px;
    font-size: 0.6rem;
  }

  .level-card__icon {
    top: 5px;
    right: 6px;
    font-size: 0.95rem;
  }

  .level-card__title {
    font-size: 0.62rem;
    line-height: 1.25;
  }

  .level-card__meta {
    display: none;
  }

  .level-card__stars,
  .level-card .stars {
    font-size: 0.58rem;
  }

  .question-card {
    padding: 9px 12px;
  }

  .question-card__tag {
    min-height: 22px;
    font-size: 0.58rem;
  }

  .question-card__prompt {
    margin-top: 0.35em;
    font-size: 0.88rem;
    line-height: 1.5;
  }

  .play-visual {
    padding: 8px;
  }

  .play-stage {
    gap: 8px;
  }

  .play-panel {
    gap: 7px;
  }

  .choice-btn {
    min-height: 48px;
    font-size: 1.02rem;
    border-radius: 14px;
  }

  .numpad {
    gap: 6px;
    padding: 7px;
  }

  .numpad__display {
    padding: 5px 10px;
  }

  .numpad__value {
    font-size: clamp(1.3rem, 4.8vh, 1.8rem);
  }

  .numpad__keys {
    gap: 5px;
  }

  .numpad__key,
  .numpad__clear {
    min-height: 48px;
    border-radius: 12px;
    font-size: 1.08rem;
  }

  .numpad__submit {
    min-height: 48px;
    border-radius: 12px;
  }

  .play-actions .btn {
    min-height: 44px;
  }

  .feedback {
    bottom: 8px;
    padding: 7px 12px;
    font-size: 0.8rem;
    border-width: 2px;
  }

  .steps-panel {
    max-height: 92dvh;
    padding-top: 8px;
  }

  .shop-preview {
    min-height: 150px;
    padding: 10px;
  }

  .shop-preview .ship {
    --ship-size: 130px;
  }

  .shop-grid,
  .collection-grid {
    gap: 8px;
    padding-top: 8px;
  }

  .shop-card,
  .monster-card {
    padding: 8px;
  }

  .shop-card__art,
  .shop-card__emoji,
  .monster-card__art,
  .monster-card__emoji {
    min-height: 62px;
    font-size: 2.1rem;
  }

  .result__monster {
    padding: 8px 12px;
  }

  .result__stars .star,
  .result__stars .result-star,
  .result__stars > * {
    font-size: clamp(2rem, 7vh, 3rem);
  }
}

/* 極窄視窗：讓雙欄輸入仍可讀 */
@media (max-width: 360px) {
  .dual-input {
    grid-template-columns: 1fr;
  }

  .numpad__value {
    font-size: 1.55rem;
  }

  .playbar__tools .pill {
    display: none;
  }
}
