/* ============================================================
   元件：按鈕、關卡節點、題目卡、選項、數字鍵盤、提示、分步引導、
   回饋、對話框、設定、計算紙、結算
   ============================================================ */

/* ---------- 按鈕 ---------- */
.btn {
  position: relative;
  overflow: hidden;
  min-height: 48px;
  padding: 10px 20px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s, background 0.2s, box-shadow 0.2s;
  -webkit-user-select: none;
  user-select: none;
}
.btn:hover { background: rgba(255, 255, 255, 0.18); }
.btn:active { transform: scale(0.95); }
.btn[disabled], .btn.is-disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: var(--accent-ink); border-color: transparent; box-shadow: 0 6px 22px rgba(56, 232, 255, 0.28); }
.btn--primary:hover { background: linear-gradient(135deg, var(--accent), var(--accent2)); filter: brightness(1.1); }
.btn--ghost { background: transparent; }
.btn--soft { background: rgba(255, 255, 255, 0.12); }
.btn--danger { background: #ff5f7a; color: #260610; border-color: transparent; }
.btn--danger:hover { background: #ff7b92; }
.btn--xl { min-height: 60px; padding: 14px 40px; font-size: 22px; border-radius: 18px; }
.btn--sm { min-height: 44px; padding: 6px 14px; font-size: 15px; }
.btn--icon { width: 48px; min-width: 48px; padding: 0; display: inline-grid; place-items: center; font-size: 20px; border-radius: 50%; }
.btn .ripple { position: absolute; border-radius: 50%; background: rgba(255, 255, 255, 0.5); transform: scale(0); animation: ripple 0.6s ease-out forwards; pointer-events: none; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 14px; font-weight: 700; white-space: nowrap; }
.badge { display: inline-block; padding: 2px 12px; border-radius: 999px; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: var(--accent-ink); font-weight: 900; font-size: 14px; }

/* ---------- 關卡節點 ---------- */
.level-node {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  align-items: center;
  text-align: left;
  min-height: 92px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s;
}
.level-node:hover { transform: translateY(-3px); border-color: var(--c1); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35); }
.level-node:active { transform: scale(0.97); }
.level-node__no { grid-row: span 2; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; font-weight: 900; background: var(--c1); color: #04122b; }
.level-node__icon { position: absolute; right: 10px; top: 6px; font-size: 20px; opacity: 0.85; }
.level-node__name { font-weight: 900; font-size: 16px; line-height: 1.25; padding-right: 22px; }
.level-node__stars { font-size: 15px; letter-spacing: 2px; color: #ffd166; }
.level-node__stars .off { color: rgba(255, 255, 255, 0.25); }
.level-node.is-done { border-color: rgba(125, 255, 178, 0.55); }
.level-node.is-current { border-color: var(--warn); box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.4), 0 0 22px rgba(255, 209, 102, 0.3); animation: pulseNode 2s ease-in-out infinite; }
.level-node.is-locked { filter: grayscale(0.7); opacity: 0.6; }
.level-node.is-locked .level-node__no { background: #4a5688; color: #cfd8ff; }
.level-node .lock { position: absolute; right: 10px; bottom: 8px; font-size: 18px; }

/* ---------- 題目卡 ---------- */
.question-card { background: var(--card-strong); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 8px; }
.question-card__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.question-card__tag { display: inline-block; padding: 2px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); font-size: 13px; font-weight: 800; color: var(--accent); }
.question-card__prompt { margin: 0; font-size: 20px; line-height: 1.6; font-weight: 700; }
.btn--sm.btn--icon { width: 44px; min-width: 44px; min-height: 44px; }

.hint-box { padding: 10px 14px; border-radius: 14px; background: rgba(255, 209, 102, 0.16); border: 1px dashed var(--warn); color: #ffe9a8; font-weight: 700; animation: slideDown 0.35s ease both; }

/* ---------- 選擇題 ---------- */
.answer-area { display: grid; gap: 10px; }
.choices { display: grid; gap: 10px; grid-template-columns: 1fr; }
.choice {
  display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; text-align: left;
  min-height: 58px; padding: 10px 14px; border-radius: 16px; border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.08); color: var(--text); font-weight: 800; font-size: 18px; cursor: pointer;
  transition: transform 0.12s, border-color 0.2s, background 0.2s;
}
.choice__key { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, 0.16); font-weight: 900; }
.choice:hover { border-color: var(--accent); background: rgba(255, 255, 255, 0.14); }
.choice:active { transform: scale(0.97); }
.choice.is-wrong { border-color: var(--bad); background: rgba(255, 90, 110, 0.18); opacity: 0.7; pointer-events: none; }
.choice.is-right { border-color: var(--good); background: rgba(93, 242, 168, 0.22); }
.choice[disabled] { cursor: default; }

/* ---------- 數字鍵盤 ---------- */
.numpad { display: grid; gap: 10px; }
.numpad__display { display: flex; align-items: baseline; justify-content: center; gap: 8px; min-height: 64px; padding: 8px 14px; border-radius: 16px; background: rgba(0, 0, 0, 0.35); border: 2px solid var(--accent); font-variant-numeric: tabular-nums; }
.numpad__value { font-size: 36px; font-weight: 900; letter-spacing: 0.04em; word-break: break-all; }
.numpad__display.is-empty .numpad__value { color: rgba(255, 255, 255, 0.35); }
.numpad__unit { font-size: 18px; font-weight: 800; color: var(--accent); }
.numpad__grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key { min-height: 54px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.12); color: var(--text); font-size: 24px; font-weight: 900; cursor: pointer; transition: transform 0.1s, background 0.15s; }
.key:hover { background: rgba(255, 255, 255, 0.2); }
.key:active { transform: scale(0.9); background: var(--accent); color: var(--accent-ink); }
.key--fn { font-size: 18px; background: rgba(255, 255, 255, 0.07); }
.key--submit { grid-column: span 2; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: var(--accent-ink); font-size: 20px; border: none; }
.key--wide { font-size: 18px; }
.numpad.is-disabled { opacity: 0.5; pointer-events: none; }
.numpad.is-done .numpad__grid { display: none; }
.numpad.is-done .numpad__display { border-color: var(--good); }

.play-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.play-actions .btn { flex: 1; min-width: 120px; }

.explain-card { scroll-margin-bottom: calc(var(--footer-h) + 20px); padding: 14px 16px; border-radius: var(--radius); background: rgba(93, 242, 168, 0.12); border: 1px solid rgba(93, 242, 168, 0.5); display: grid; gap: 10px; animation: slideDown 0.4s ease both; }
.explain-card.is-help { background: rgba(255, 209, 102, 0.12); border-color: rgba(255, 209, 102, 0.55); }
.explain-card__result { margin: 0; font-weight: 900; font-size: 20px; }
.explain-card__text { margin: 0; color: #e6f2ff; }

/* ---------- 回饋氣泡 ---------- */
.feedback { position: fixed; left: 50%; top: 36%; transform: translateX(-50%); z-index: 80; pointer-events: none; display: grid; justify-items: center; gap: 4px; }
.feedback__bubble { padding: 14px 26px; border-radius: 22px; font-size: 26px; font-weight: 900; text-align: center; color: #04122b; box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5); animation: popBubble 1.5s ease both; max-width: 86vw; }
.feedback__bubble.good { background: linear-gradient(135deg, #5df2a8, #38e8ff); }
.feedback__bubble.bad { background: linear-gradient(135deg, #ffd166, #ff9f6b); }
.feedback__bubble.info { background: linear-gradient(135deg, #d58bff, #8b7bff); color: #fff; }
.feedback__pts { font-size: 20px; font-weight: 900; color: #ffe9a8; text-shadow: 0 2px 6px #000; animation: floatPts 1.5s ease both; }

/* ---------- 分步引導 ---------- */
.steps-panel { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px 16px calc(var(--footer-h) + 16px); background: rgba(3, 6, 22, 0.78); backdrop-filter: blur(4px); }
.steps-card { width: min(560px, 100%); max-height: 100%; overflow: auto; background: var(--card-strong); border: 1px solid var(--line); border-radius: 22px; padding: 18px; display: grid; gap: 12px; animation: popIn 0.35s ease both; }
.steps-card__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.steps-card__head h3 { font-size: 20px; }
.steps-dots { display: flex; gap: 6px; }
.steps-dots i { width: 26px; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.2); }
.steps-dots i.is-done { background: var(--good); }
.steps-dots i.is-now { background: var(--accent); }
.steps-card__q { margin: 0; font-size: 19px; font-weight: 800; }
.steps-card__orig { margin: 0; font-size: 14px; color: var(--muted); }
.steps-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.steps-options .choice { grid-template-columns: 1fr; text-align: center; justify-items: center; }
.steps-note { margin: 0; min-height: 1.5em; font-weight: 800; color: var(--warn); }

/* ---------- 結算 ---------- */
.result__stars { display: flex; justify-content: center; gap: 10px; font-size: 56px; line-height: 1; min-height: 62px; }
.result__stars .star-big { color: rgba(255, 255, 255, 0.2); filter: grayscale(1); transform: scale(0.6); }
.result__stars .star-big.is-on { color: #ffd166; filter: none; animation: starPop 0.7s cubic-bezier(.2, 1.6, .4, 1) both; text-shadow: 0 0 22px rgba(255, 209, 102, 0.8); }
.result__stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.stat { padding: 8px 10px; border-radius: 14px; background: rgba(255, 255, 255, 0.09); }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.result__guardian { display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-radius: 18px; background: rgba(255, 255, 255, 0.09); text-align: left; animation: slideDown 0.6s ease both; }
.result__guardian img { width: 96px; height: 96px; object-fit: contain; flex: none; }

/* ---------- 對話框 ---------- */
.dialog { border: 1px solid var(--line); border-radius: 22px; padding: 0; background: #111a4a; color: var(--text); width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - var(--footer-h) - 24px); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6); margin: auto; margin-bottom: calc(var(--footer-h) + 8px); }
/* 背景遮罩不蓋住底部的固定頁尾，開著對話框時版權頁尾仍清楚可見（::backdrop 舊瀏覽器不繼承變數，故附預設值） */
.dialog::backdrop { background: rgba(3, 6, 22, 0.7); backdrop-filter: blur(3px); bottom: calc(var(--footer-h, 46px) + env(safe-area-inset-bottom, 0px)); }
.dialog[open] { animation: popIn 0.3s ease both; }
.dialog--small { width: min(420px, calc(100vw - 24px)); }
.dialog__form { display: grid; }
.dialog__head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.dialog__head h2 { font-size: 22px; }
.dialog__body { padding: 8px 16px 18px; display: grid; gap: 12px; overflow: auto; }
.dialog__hr { border: 0; border-top: 1px solid var(--line); margin: 2px 0; width: 100%; }
.dialog__note { margin: 0; font-size: 13px; color: var(--muted); }
.dialog__version { margin: 0; font-size: 12px; color: var(--muted); text-align: right; }
.setting { display: grid; gap: 6px; padding: 8px 10px; border-radius: 14px; background: rgba(255, 255, 255, 0.06); }
.setting__toggle { display: flex; align-items: center; justify-content: space-between; min-height: 46px; width: 100%; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); font-weight: 800; font-size: 17px; cursor: pointer; }
.setting__toggle b { padding: 2px 12px; border-radius: 999px; background: var(--good); color: #04281a; }
.setting__toggle[aria-pressed="false"] b { background: #6a739e; color: #fff; }
.setting__toggle--danger b { background: #ff7b92; color: #2b0610; }
.setting input[type="range"] { width: 100%; height: 44px; accent-color: var(--accent); }
.reset-confirm { padding: 12px; border-radius: 14px; background: rgba(255, 90, 110, 0.14); border: 1px solid #ff8d8d; display: grid; gap: 10px; margin-top: 8px; }
.reset-confirm p { margin: 0; font-weight: 700; }
.reset-confirm__actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.install-steps { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; }
.install-block { padding: 10px 12px; border-radius: 14px; background: rgba(255, 255, 255, 0.07); display: grid; gap: 6px; }
.install-block h3 { font-size: 17px; color: var(--accent); }

/* ---------- 提示訊息 ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--footer-h) + 16px); transform: translate(-50%, 20px); z-index: 120; max-width: min(92vw, 520px); padding: 12px 20px; border-radius: 16px; background: rgba(22, 32, 92, 0.97); border: 1px solid var(--accent); font-weight: 800; text-align: center; opacity: 0; pointer-events: none; transition: opacity 0.3s, transform 0.3s; }
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }
.toast.is-cheat { background: linear-gradient(135deg, #ff6bd6, #8b7bff, #38e8ff); color: #04122b; font-size: 20px; border: none; }
.confetti-layer { position: fixed; inset: 0; z-index: 110; pointer-events: none; overflow: hidden; }
.confetti { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; animation: confettiFall 2.4s ease-in forwards; }

/* ---------- 計算紙 ---------- */
.scratchpad-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 12px 12px calc(var(--footer-h) + 12px); background: rgba(3, 6, 22, 0.8); }
.scratchpad { width: min(900px, 100%); height: min(560px, 100%); display: grid; grid-template-rows: auto 1fr; background: #0d1546; border: 1px solid var(--line); border-radius: 20px; overflow: hidden; }
.scratchpad__bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.scratchpad__tip { color: var(--muted); font-size: 13px; flex: 1; min-width: 140px; }
.scratchpad__tools { display: flex; gap: 8px; }
.scratchpad__canvas { width: 100%; height: 100%; touch-action: none; cursor: crosshair; background-color: #101a55; background-image: linear-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.07) 1px, transparent 1px); background-size: 32px 32px; }
#scratchpad-eraser.is-on { background: var(--warn); color: #2a2005; }

/* ---------- 教具容器 ---------- */
.vis-svg { width: 100%; height: auto; max-height: 36vh; display: block; }
.vis-cap { margin-top: 4px; font-size: 14px; font-weight: 800; color: var(--muted); text-align: center; }
.vis-mascot { display: grid; place-items: center; padding: 6px; }
.vis-mascot img { width: 120px; height: 120px; object-fit: contain; animation: bob 3s ease-in-out infinite; }
.vis-table { border-collapse: separate; border-spacing: 0; width: min(380px, 100%); border-radius: 14px; overflow: hidden; border: 1px solid var(--line); font-size: 18px; }
.vis-table th, .vis-table td { padding: 10px 14px; text-align: center; border-bottom: 1px solid var(--line); }
.vis-table th { background: rgba(56, 232, 255, 0.25); }
.vis-table tr:last-child td { border-bottom: 0; }
.noscript { position: fixed; inset: auto 16px 60px; z-index: 99; background: #fff; color: #111; padding: 16px; border-radius: 12px; }

@media (min-width: 560px) {
  .choices { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .question-card__prompt { font-size: 18px; }
  .vis-svg { max-height: 30vh; }
  .feedback__bubble { font-size: 22px; padding: 12px 18px; }
}
