/* ============================================================
   因數分數魔法城堡 — 元件樣式
   ============================================================ */

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 20px;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.1;
  text-align: center;
  touch-action: manipulation;
  user-select: none;
  transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.16); }
.btn:active { transform: scale(0.95); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }

.btn--primary {
  background: linear-gradient(180deg, var(--gold) 0%, var(--gold-d) 100%);
  color: #3a2200;
  box-shadow: 0 6px 0 #a96a0c, 0 12px 24px rgba(0, 0, 0, 0.35);
}
.btn--primary:hover { background: linear-gradient(180deg, #ffe08c 0%, #ffb43a 100%); }
.btn--primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #a96a0c, 0 6px 14px rgba(0, 0, 0, 0.3); }
.btn--soft { background: rgba(255, 255, 255, 0.14); border-color: var(--line); }
.btn--ghost { background: transparent; border-color: var(--line); }
.btn--danger { background: rgba(255, 111, 134, 0.18); border-color: var(--coral); color: #ffd3da; }
.btn--danger:hover { background: rgba(255, 111, 134, 0.32); }
.btn--xl { min-height: 60px; padding: 0 40px; font-size: 1.3rem; }
.btn--sm { min-height: 44px; padding: 0 14px; font-size: 0.92rem; }
.btn--block { width: 100%; }
.btn--icon {
  width: 46px;
  min-width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--line);
}
.btn--icon.btn--sm { width: 44px; min-width: 44px; height: 44px; min-height: 44px; }
.btn--icon[aria-pressed="true"] { background: var(--gold); color: #3a2200; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  font-weight: 800;
}
.pill__sub { font-weight: 500; color: var(--muted); font-size: 0.85rem; }

.badge {
  display: inline-block;
  padding: 2px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: #2a1700;
  font-weight: 800;
  font-size: 0.9rem;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips li, .chips > span {
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--line);
  font-size: 0.9rem;
}

/* ---------- 分數、循環小數顯示 ---------- */
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 1.12;
  margin: 0 0.14em;
  font-variant-numeric: tabular-nums;
}
.frac__n { padding: 0 0.22em 0.04em; border-bottom: 0.09em solid currentColor; }
.frac__d { padding: 0.04em 0.22em 0; }
.mixed { display: inline-flex; align-items: center; gap: 0.08em; vertical-align: middle; }
.mixed__w { font-weight: 800; }
.rep { white-space: nowrap; }
.rd { position: relative; display: inline-block; }
.rd::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -0.1em;
  width: 0.15em;
  height: 0.15em;
  border-radius: 50%;
  background: currentColor;
  transform: translateX(-50%);
}

/* ---------- 主畫面 ---------- */
.home {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding-top: 0;
}
.home__mascot {
  width: clamp(130px, 28vh, 240px);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  background: none;
  filter: drop-shadow(0 12px 22px rgba(0, 0, 0, 0.5));
  animation: float 3.6s ease-in-out infinite;
}
.home__mascot img { width: 100%; height: 100%; object-fit: contain; }
.home__mascot:active { transform: scale(0.94); }
.home__kicker {
  color: #ffe9b5;
  font-weight: 700;
  font-size: clamp(0.85rem, 2.6vw, 1.05rem);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}
.home__title {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
  font-size: clamp(2.4rem, 11vw, 4.6rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: 0 4px 0 #6d3fc0, 0 8px 18px rgba(0, 0, 0, 0.55);
}
.home__title span:last-child { color: var(--gold); text-shadow: 0 4px 0 #a96a0c, 0 8px 18px rgba(0, 0, 0, 0.55); }
.home__tagline { max-width: 34em; color: #f5eeff; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7); font-size: clamp(0.95rem, 2.8vw, 1.1rem); }
.home__cta { margin-top: 8px; }
.home__stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 6px; }
.home__stats span {
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line);
  font-size: 0.92rem;
}

/* ---------- 城堡地圖 ---------- */
.map__title { text-align: center; color: var(--muted); margin-bottom: 12px; font-size: 0.95rem; }
.map__areas {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr));
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
}
.area {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.area__banner {
  position: relative;
  min-height: 92px;
  padding: 12px 16px;
  background: center / cover no-repeat;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.area__banner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(20, 13, 51, 0.1), rgba(20, 13, 51, 0.88));
}
.area__banner > * { position: relative; z-index: 1; }
.area__name { font-size: 1.25rem; font-weight: 900; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7); }
.area__theme { font-size: 0.85rem; color: #f0e8ff; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7); }
.area__levels {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px;
}
.lv {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 108px;
  padding: 8px 4px 6px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  text-align: center;
  transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease;
}
.lv:hover { transform: translateY(-3px); border-color: var(--accent); background: rgba(255, 255, 255, 0.13); }
.lv__no {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #2a1700;
  font-weight: 900;
}
.lv__emoji { font-size: 1.9rem; line-height: 1.1; }
.lv__name { font-size: 0.76rem; line-height: 1.2; color: #f1eaff; min-height: 2.4em; display: flex; align-items: center; }
.lv__stars { display: flex; gap: 1px; height: 14px; }
.lv__stars .ico { width: 14px; height: 14px; fill: rgba(255, 255, 255, 0.22); }
.lv__stars .on { fill: var(--gold); }
.lv.is-locked { opacity: 0.6; background: rgba(0, 0, 0, 0.3); }
.lv.is-locked .lv__no { background: #5a4d96; color: #ddd; }
.lv.is-locked .lv__emoji { filter: grayscale(1) brightness(0.7); }
.lv__lock { position: absolute; top: 5px; right: 6px; width: 16px; height: 16px; fill: #cfc4ff; }
.lv.is-current { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.35); }
.lv.is-boss .lv__emoji { font-size: 2.1rem; }

/* ---------- 關卡介紹 ---------- */
.intro { display: flex; justify-content: center; align-items: flex-start; }
.intro__card {
  width: min(100%, 860px);
  display: grid;
  grid-template-columns: minmax(130px, 220px) 1fr;
  gap: 20px;
  align-items: center;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
}
.intro__guardian {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 24px;
  background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.04));
  border: 2px solid var(--accent);
  font-size: clamp(4rem, 14vw, 6.5rem);
  animation: float 3.2s ease-in-out infinite;
}
.intro__guardian img { width: 92%; height: 92%; object-fit: contain; }
.intro__text { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.intro__concept { font-size: clamp(1.15rem, 3.4vw, 1.5rem); font-weight: 800; color: var(--gold); }
.intro__story { color: #f1eaff; }
.intro__tips { padding: 12px 14px; border-radius: var(--radius-sm); background: rgba(0, 0, 0, 0.28); border-left: 5px solid var(--accent); }
.intro__tips h2 { font-size: 0.95rem; color: var(--accent); margin-bottom: 4px; }
.intro__tips li { padding-left: 1.3em; position: relative; margin: 4px 0; font-size: 1.02rem; }
.intro__tips li::before { content: "✦"; position: absolute; left: 0; color: var(--gold); }
.intro__actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: flex-end; margin-top: 4px; }

/* ---------- 答題畫面 ---------- */
.topbar--play { padding-bottom: 2px; }
.statusbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px var(--gutter);
  min-height: 40px;
}
.hearts { display: flex; gap: 3px; }
.hearts .ico { width: 24px; height: 24px; fill: var(--coral); transition: transform 0.2s ease; }
.hearts .lost { fill: rgba(255, 255, 255, 0.2); }
.score { display: flex; align-items: baseline; gap: 6px; }
.score__label { font-size: 0.8rem; color: var(--muted); }
.score strong { font-size: 1.45rem; color: var(--gold); font-variant-numeric: tabular-nums; }
.combo { flex: 1; min-height: 28px; }
.combo__badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff7a3d, #ffb703);
  color: #3a1500;
  font-weight: 900;
  font-size: 0.95rem;
}
.qcount { color: var(--muted); font-size: 0.95rem; font-weight: 700; white-space: nowrap; }

.timerbar {
  position: relative;
  height: 14px;
  margin: 2px var(--gutter) 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--line);
  overflow: hidden;
}
.timerbar__fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--mint), #9be15d);
  transition: background 0.3s ease;
}
.timerbar.is-mid .timerbar__fill { background: linear-gradient(90deg, #ffd166, #ffb703); }
.timerbar.is-low .timerbar__fill { background: linear-gradient(90deg, #ff6f86, #ff3d5a); }
.timerbar__text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.play {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-content: start;
}
.guardian {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: 1px solid var(--line);
}
.guardian__face {
  position: relative;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  font-size: 2.2rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  flex: none;
}
.guardian__face img { width: 100%; height: 100%; object-fit: contain; }
.guardian__info { flex: 1; min-width: 0; }
.guardian__name { font-weight: 800; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hpbar { height: 12px; border-radius: 999px; background: rgba(0, 0, 0, 0.45); border: 1px solid var(--line); overflow: hidden; margin-top: 4px; }
.hpbar__fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff6f86, #ff9a5c); transition: width 0.45s ease; }

.qpanel { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.qcard {
  position: relative;
  padding: 14px 16px 16px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow);
}
.qcard__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.tag { padding: 2px 12px; border-radius: 999px; background: var(--accent); color: #2a1700; font-weight: 800; font-size: 0.85rem; }
.qcard__prompt {
  font-size: clamp(1.2rem, 3.2vw + 0.4rem, 1.75rem);
  font-weight: 700;
  line-height: 1.7;
  word-break: break-word;
}
.qcard__prompt .frac { font-size: 1.12em; }
.qcard.is-hidden .qcard__prompt, .qcard.is-hidden .tag { visibility: hidden; }

.hintbox {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 209, 102, 0.16);
  border: 1px solid var(--gold);
  color: #fff3d0;
  font-size: 1.02rem;
  line-height: 1.6;
}
.hintbox strong { color: var(--gold); }
.hintbox--warn { background: rgba(255, 111, 134, 0.14); border-color: var(--coral); color: #ffe2e7; }
.hintbox--near { background: rgba(92, 200, 255, 0.14); border-color: var(--sky); color: #e1f4ff; }

.visual {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--line);
  overflow-x: auto;
  text-align: center;
}
.visual__caption { margin-top: 6px; font-size: 0.9rem; color: var(--muted); }

.apanel { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.answer-area { min-width: 0; }
.play-actions { display: flex; gap: 10px; }
.play-actions .btn { flex: 1; }

/* 選擇題 */
.choice { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.choice__btn {
  position: relative;
  min-height: 64px;
  padding: 10px 14px 10px 36px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.1);
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease;
}
.choice__btn:hover { border-color: var(--gold); background: rgba(255, 255, 255, 0.18); }
.choice__btn:active { transform: scale(0.96); }
.choice__key {
  position: absolute;
  left: 8px;
  top: 8px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  font-size: 0.78rem;
  color: var(--muted);
}
.choice--long { grid-template-columns: 1fr; }
.choice--long .choice__btn { font-size: 1.05rem; text-align: left; justify-content: flex-start; font-weight: 600; }
.choice--sym .choice__btn { font-size: 2.2rem; grid-column: auto; }
.choice--yn .choice__btn { font-size: 1.5rem; }
.choice__btn.is-wrong { background: rgba(255, 111, 134, 0.3); border-color: var(--coral); }
.choice__btn.is-right { background: rgba(62, 224, 169, 0.3); border-color: var(--mint); }
.choice__btn[disabled] { opacity: 0.55; pointer-events: none; }

/* 數字輸入 */
.entry { display: flex; flex-direction: column; gap: 10px; }
.entry__fields { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; }
.field {
  position: relative;
  min-width: 96px;
  min-height: 62px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--line);
  background: rgba(0, 0, 0, 0.4);
  color: var(--text);
  font-size: 1.9rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
}
.field__label { font-size: 0.72rem; font-weight: 600; color: var(--muted); line-height: 1.2; }
.field__value { min-height: 1.3em; min-width: 1.5em; }
.field.is-active { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.35); }
.field.is-active .field__value::after { content: "▏"; color: var(--gold); animation: blink 1s steps(2) infinite; }
.field__unit { font-size: 1rem; color: var(--muted); font-weight: 600; margin-left: 6px; }
.entry__row { display: flex; align-items: center; gap: 8px; }
.field--frac { min-width: 84px; font-size: 1.7rem; }
.fracbox { display: flex; flex-direction: column; align-items: stretch; gap: 6px; min-width: 96px; }
.fracbox .field { min-height: 54px; }
.fracbar { height: 5px; border-radius: 3px; background: var(--text); }
.fracword { font-size: 1.2rem; color: var(--muted); font-weight: 700; }

.pad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; max-width: 420px; width: 100%; margin: 0 auto; }
.pad__key {
  min-height: 54px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.12);
  font-size: 1.5rem;
  font-weight: 800;
  touch-action: manipulation;
  transition: transform 0.1s ease, background 0.15s ease;
}
.pad__key:hover { background: rgba(255, 255, 255, 0.2); }
.pad__key:active { transform: scale(0.92); background: rgba(255, 209, 102, 0.35); }
.pad__key--fn { font-size: 1rem; background: rgba(255, 255, 255, 0.07); }
.pad__key--go {
  grid-column: span 2;
  background: linear-gradient(180deg, var(--gold), var(--gold-d));
  color: #3a2200;
  border-color: transparent;
  font-size: 1.25rem;
}
.pad__key--go:active { background: var(--gold-d); }
.pad__key[disabled] { opacity: 0.4; pointer-events: none; }

/* 多選 */
.pick { display: flex; flex-direction: column; gap: 10px; }
.pick__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 8px; }
.pick__chip {
  min-height: 54px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.1);
  font-size: 1.4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
.pick__chip:active { transform: scale(0.92); }
.pick__chip[aria-pressed="true"] { background: linear-gradient(180deg, var(--gold), var(--gold-d)); color: #3a2200; border-color: transparent; transform: translateY(-2px); }
.pick__bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pick__count { flex: 1; color: var(--muted); font-weight: 700; }

/* 排序 */
.order { display: flex; flex-direction: column; gap: 12px; }
.order__slots { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
.order__slot {
  min-width: 70px;
  min-height: 70px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 2px dashed var(--line);
  background: rgba(0, 0, 0, 0.3);
  font-size: 1.4rem;
  font-weight: 800;
  position: relative;
}
.order__slot.is-filled { border-style: solid; border-color: var(--gold); background: rgba(255, 209, 102, 0.12); }
.order__slot small { position: absolute; top: 2px; left: 6px; font-size: 0.7rem; color: var(--muted); }
.order__lt { color: var(--muted); font-weight: 900; font-size: 1.3rem; }
.order__items { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.order__item {
  min-width: 78px;
  min-height: 70px;
  padding: 6px 14px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.12);
  font-size: 1.45rem;
  font-weight: 800;
  transition: transform 0.12s ease, opacity 0.15s ease;
}
.order__item:active { transform: scale(0.93); }
.order__item[disabled] { opacity: 0.25; pointer-events: none; }
.order__bar { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- 教具 ---------- */
.v-pairs { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.v-pair { padding: 6px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.1); font-weight: 800; }
.v-pair__grid { display: grid; gap: 2px; margin: 6px auto 0; justify-content: center; }
.v-pair__grid i { width: 9px; height: 9px; border-radius: 2px; background: var(--accent); display: block; }
.v-array { display: inline-grid; gap: 4px; }
.v-array i { width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff1b8, var(--accent)); display: block; }
.v-venn { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; text-align: center; align-items: stretch; }
.v-venn__col { padding: 8px 6px; border-radius: 12px; border: 2px solid var(--line); background: rgba(255, 255, 255, 0.06); }
.v-venn__col--both { border-color: var(--gold); background: rgba(255, 209, 102, 0.16); }
.v-venn__title { font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; }
.v-venn__nums { font-size: 1.15rem; font-weight: 800; word-spacing: 0.2em; line-height: 1.5; }
.v-sd { display: inline-grid; justify-content: center; font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; }
.v-sd__row { display: grid; grid-template-columns: 2.2em 3.4em 3.4em; align-items: stretch; }
.v-sd__d { text-align: right; padding-right: 0.3em; color: var(--gold); }
.v-sd__n { padding: 0.05em 0.5em; }
.v-sd__n--first { border-left: 3px solid var(--text); }
.v-sd__row.has-line .v-sd__n { border-bottom: 3px solid var(--text); }
.v-sd__row.is-last .v-sd__n--first { border-left-color: transparent; }
.v-sd__q { display: inline-block; min-width: 1.4em; border-radius: 6px; background: rgba(255, 209, 102, 0.25); color: var(--gold); text-align: center; }
.v-bars { display: flex; flex-direction: column; gap: 8px; }
.v-bar { display: grid; grid-template-columns: 3.4em 1fr; align-items: center; gap: 8px; font-weight: 800; }
.v-bar svg { width: 100%; height: 30px; display: block; }
.v-area svg, .v-dec svg { width: min(100%, 240px); height: auto; }
.legend { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; font-size: 0.82rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* ---------- 回饋層 ---------- */
.feedback {
  position: fixed;
  left: 50%;
  bottom: calc(var(--footer-h) + 18px);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 22px 10px 12px;
  border-radius: 999px;
  background: rgba(255, 248, 234, 0.97);
  color: #2a1b63;
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  font-weight: 900;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -20px) scale(0.8);
  opacity: 0;
  pointer-events: none;
  max-width: 92vw;
}
.feedback img { width: 54px; height: 54px; object-fit: contain; flex: none; }
.feedback.is-on { animation: pop-in 1.5s ease both; }
.feedback.is-good { background: #e9fff5; color: #0b5c3e; border: 3px solid var(--mint); }
.feedback.is-bad { background: #fff2f4; color: #7a1b2c; border: 3px solid var(--coral); }
.feedback.is-near { background: #eaf7ff; color: #124a6e; border: 3px solid var(--sky); }

.float-score {
  position: fixed;
  z-index: 75;
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 2px 0 #7a4a00, 0 4px 12px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  animation: float-up 1.2s ease-out forwards;
}

/* ---------- 結算 ---------- */
.result, .ending { display: flex; justify-content: center; align-items: flex-start; }
.result__card, .ending__card {
  width: min(100%, 640px);
  padding: 22px 20px;
  border-radius: 24px;
  background: var(--panel);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.result__kicker { color: var(--accent); font-weight: 800; letter-spacing: 0.1em; }
.result__card h1, .ending__card h1 { font-size: clamp(1.7rem, 7vw, 2.6rem); line-height: 1.2; }
.result__sub { color: #f1eaff; }
.result__stars { display: flex; gap: 8px; justify-content: center; }
.result__stars .ico { width: 64px; height: 64px; fill: rgba(255, 255, 255, 0.18); }
.result__stars .ico.on { fill: var(--gold); filter: drop-shadow(0 0 10px rgba(255, 209, 102, 0.8)); animation: star-pop 0.6s ease both; }
.result__rows { width: 100%; max-width: 420px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; text-align: left; padding: 10px 14px; border-radius: 14px; background: rgba(0, 0, 0, 0.28); }
.result__rows dt { color: var(--muted); }
.result__rows dd { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.result__rows .total { color: var(--gold); font-size: 1.3em; }
.result__mascot img, .ending__mascot { width: 110px; height: 110px; object-fit: contain; animation: float 3s ease-in-out infinite; }
.ending__mascot { width: 160px; height: 160px; }
.result__actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }

/* ---------- 對話框 ---------- */
.dialog {
  width: min(94vw, 520px);
  max-height: 88vh;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 22px;
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
.dialog--small { width: min(92vw, 420px); }
.dialog::backdrop { background: rgba(8, 4, 30, 0.72); backdrop-filter: blur(3px); }
.dialog[open] { animation: dialog-in 0.25s ease both; display: flex; flex-direction: column; }
.dialog__panel { display: flex; flex-direction: column; min-height: 0; max-height: 88vh; }
.dialog__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 8px 20px; }
.dialog__head h2 { font-size: 1.25rem; display: flex; align-items: center; gap: 8px; }
.dialog__body { padding: 8px 20px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.dialog__hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
.dialog__note { font-size: 0.85rem; color: var(--muted); }
.dialog__version { font-size: 0.8rem; color: var(--muted); text-align: right; }
.dialog__actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.setting { display: grid; grid-template-columns: 6.5em 1fr auto; align-items: center; gap: 12px; min-height: 46px; }
.setting--simple { grid-template-columns: 1fr auto; }
.setting__label { font-weight: 700; }
.setting input[type="range"] { width: 100%; height: 36px; accent-color: var(--gold); }
.switch {
  position: relative;
  width: 58px;
  height: 34px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.15);
  padding: 0;
  transition: background 0.2s ease;
}
.switch span { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform 0.2s ease; }
.switch[aria-checked="true"] { background: var(--mint); }
.switch[aria-checked="true"] span { transform: translateX(24px); }
.switch { min-height: 44px; height: 44px; width: 68px; }
.switch span { top: 7px; left: 5px; }
.switch[aria-checked="true"] span { transform: translateX(28px); }

.steps__q { padding: 10px 14px; border-radius: 12px; background: rgba(0, 0, 0, 0.3); font-size: 1.1rem; line-height: 1.7; }
.steps__list { counter-reset: s; display: flex; flex-direction: column; gap: 8px; }
.steps__list li {
  counter-increment: s;
  position: relative;
  padding: 10px 14px 10px 48px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 1.05rem;
  line-height: 1.7;
  animation: step-in 0.35s ease both;
}
.steps__list li::before {
  content: counter(s);
  position: absolute;
  left: 12px;
  top: 10px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--gold);
  color: #3a2200;
  font-weight: 900;
  font-size: 0.9rem;
}
.steps__answer { padding: 12px 14px; border-radius: 12px; background: rgba(62, 224, 169, 0.18); border: 2px solid var(--mint); font-size: 1.2rem; font-weight: 800; }
.install__steps { display: flex; flex-direction: column; gap: 8px; counter-reset: i; }
.install__steps li { counter-increment: i; position: relative; padding-left: 34px; line-height: 1.7; }
.install__steps li::before { content: counter(i); position: absolute; left: 0; top: 2px; width: 24px; height: 24px; border-radius: 50%; background: var(--gold); color: #3a2200; font-weight: 900; display: grid; place-items: center; font-size: 0.85rem; }

/* ---------- 計算紙 ---------- */
.scratch { position: fixed; inset: 0; z-index: 60; background: rgba(8, 4, 30, 0.7); display: grid; place-items: center; padding: 12px; }
.scratch__sheet { width: min(100%, 900px); height: min(92%, 640px); display: flex; flex-direction: column; border-radius: 18px; overflow: hidden; background: #fff8e8; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6); }
.scratch__bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; background: #2d2070; color: var(--text); }
.scratch__tip { flex: 1; color: var(--muted); font-size: 0.85rem; min-width: 8em; }
.scratch__tools { display: flex; gap: 8px; }
.scratch__canvas { flex: 1; width: 100%; min-height: 0; touch-action: none; cursor: crosshair; background-color: #fff8e8; background-image: linear-gradient(rgba(60, 40, 120, 0.12) 1px, transparent 1px); background-size: 100% 36px; }

/* ---------- 版面：寬螢幕 ---------- */
@media (min-width: 760px) {
  .play { grid-template-columns: minmax(0, 1.4fr) minmax(300px, 1fr); max-width: 1180px; margin: 0 auto; }
  .guardian { grid-column: 1 / -1; }
  .choice { gap: 12px; }
}
@media (min-width: 1100px) {
  .play { grid-template-columns: 190px minmax(0, 1.5fr) minmax(330px, 1fr); }
  .guardian { grid-column: auto; flex-direction: column; text-align: center; align-self: start; padding: 16px 10px; }
  .guardian__face { width: 96px; height: 96px; font-size: 3.8rem; }
  .guardian__name { white-space: normal; }
  .guardian__info { width: 100%; flex: none; }
}

/* ---------- 版面：手機 ---------- */
@media (max-width: 640px) {
  .intro__card { grid-template-columns: 1fr; padding: 16px; }
  .intro__guardian { max-width: 150px; margin: 0 auto; }
  .area__levels { gap: 6px; padding: 10px; }
  .lv__name { font-size: 0.7rem; }
  .qcard__prompt { line-height: 1.65; }
  .choice__btn { padding-left: 30px; font-size: 1.15rem; }
  .field { min-width: 84px; font-size: 1.7rem; }
  .pad__key { min-height: 50px; }
  .dialog__body { padding-inline: 16px; }
  .setting { grid-template-columns: 5.5em 1fr auto; gap: 8px; }
  .result__stars .ico { width: 52px; height: 52px; }
  .v-venn { grid-template-columns: 1fr; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .home__mascot { width: 110px; }
  .home__title { font-size: 2.2rem; flex-direction: row; gap: 0.3em; }
}

.area[data-a="1"] { --accent: #f6b73c; }
.area[data-a="2"] { --accent: #35c7d9; }
.area[data-a="3"] { --accent: #ff8a4c; }
.area[data-a="4"] { --accent: #a78bfa; }

@media (max-width: 520px) {
  .topbar--play .topbar__kicker { display: none; }
  .topbar--play .topbar__title h1 { white-space: normal; font-size: 0.95rem; line-height: 1.2; }
}

.score, .score__label, .qcount { white-space: nowrap; }
.combo { min-width: 0; }
.combo__badge { white-space: nowrap; flex: none; }
@media (max-width: 640px) {
  .statusbar { gap: 8px; padding-block: 2px; min-height: 34px; }
  .hearts { gap: 1px; }
  .hearts .ico { width: 20px; height: 20px; }
  .score strong { font-size: 1.25rem; }
  .combo__badge { font-size: 0.8rem; padding: 1px 8px; }
  .qcount { font-size: 0.85rem; }
  .guardian { padding: 4px 10px; gap: 8px; }
  .guardian__face { width: 34px; height: 34px; font-size: 1.4rem; }
  .guardian__name { font-size: 0.85rem; }
  .hpbar { height: 9px; margin-top: 2px; }
  .play { gap: 8px; }
  .qcard { padding: 8px 14px 12px; }
  .qcard__head { margin-bottom: 2px; }
  .field { min-height: 52px; }
  .fracbox .field { min-height: 44px; }
  .pad { gap: 6px; }
  .pad__key { min-height: 46px; font-size: 1.3rem; }
  .entry { gap: 6px; }
  .hide-sm { display: none; }
}

.pad__key--go:hover { background: linear-gradient(180deg, #ffe08c, #ffb43a); }

@media (max-width: 520px) {
  .pill--hide-sm { display: none; }
}
