/* 黑金配色：跟上課投影片同一個感覺。排版、按鈕、開關、語音面板都是從 π 挑戰搬過來的 */
:root {
  --bg: #12100c;
  --bg-2: #1e1a12;
  --card: #2b261a;
  --text: #f7f1e3;
  --muted: #b3a88f;
  --accent: #e8b84a;
  --accent-2: #ff8a3d;
  --good: #5ee0a0;
  --warn: #f2c94c;
  --bad: #ff5c7a;
  --key: #3a3324;
  --key-press: #4d4430;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
body { background: radial-gradient(circle at 50% 0%, var(--bg-2), var(--bg) 70%); }
/* 整頁 user-select: none 的話，有些 iPhone 會打不進字 */
input { user-select: text; -webkit-user-select: text; }

button { font: inherit; color: inherit; border: 0; cursor: pointer; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico, .mic-ico { flex: none; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.ico { width: 16px; height: 16px; stroke-width: 1.9; }
.mic-ico { width: 52px; height: 52px; stroke-width: 1.5; }

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 24px) 20px calc(env(safe-area-inset-bottom) + 20px);
}
.screen.active { display: flex; animation: screen-in .28s cubic-bezier(.2, .8, .2, 1); }
.screen.active.back { animation-name: screen-in-back; }
@keyframes screen-in { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }
@keyframes screen-in-back { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }

/* ---------- 主選單 ---------- */
#screen-menu { position: relative; justify-content: center; text-align: center; gap: 8px; }
.btn-round {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 16px);
  right: 16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--key-press);
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-round .ico { width: 20px; height: 20px; }
.btn-round:active { background: var(--key-press); }
.btn-sound.off { opacity: .5; }
.logo svg {
  width: 120px;
  height: 60px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  filter: drop-shadow(0 6px 20px rgba(232, 184, 74, .35));
}
h1 { margin: 4px 0 0; font-size: 34px; letter-spacing: 4px; }
.subtitle { margin: 0; color: var(--muted); }
.best-box {
  width: 100%;
  max-width: 340px;
  margin: 18px 0 4px;
  padding: 10px 18px;
  background: var(--card);
  border-radius: 18px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.best-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.best-row span { display: inline-flex; align-items: center; gap: 6px; }
.best-row b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.best-row b.has { color: var(--accent); }
.menu-buttons { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.menu-btn {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  border-radius: 18px;
  background: var(--card);
  text-align: left;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .35);
  transition: transform .05s, background .1s;
}
.menu-btn:active { transform: translateY(2px); box-shadow: none; background: var(--key-press); }
.menu-icon { display: flex; align-items: center; }
.menu-icon .ico { width: 30px; height: 30px; stroke-width: 1.6; }
.menu-icon.test { color: var(--accent); }
.menu-icon.practice { color: var(--good); }
.menu-icon.list { color: var(--accent-2); }
.menu-text { display: flex; flex-direction: column; gap: 4px; }
.menu-text b { font-size: 20px; }
.menu-text small { color: var(--muted); font-size: 13px; }

/* ---------- 設定畫面 ---------- */
.setup { gap: 10px; }
.setup h2 { margin-top: 4px; }
.setup-desc { margin: 0 0 4px; color: var(--muted); font-size: 14px; text-align: center; }
.setup-note { margin: 4px 0; color: var(--muted); font-size: 14px; line-height: 1.7; text-align: center; }
.setup-actions { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: auto; padding-top: 12px; }
.tiers { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 6px; }
.tier {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 6px 12px;
  border-radius: 16px;
  background: var(--bg-2);
  box-shadow: inset 0 0 0 1px rgba(232, 184, 74, .35);
}
.tier small { color: var(--accent); font-size: 14px; font-weight: 700; letter-spacing: 2px; }
.tier b { font-size: 40px; line-height: 1.1; font-family: Georgia, "Times New Roman", serif; color: var(--text); }
.tier span { color: var(--muted); font-size: 13px; }
.p-range { color: var(--muted); font-size: 14px; }
.p-range b { color: var(--accent); font-size: 18px; margin: 0 2px; }

.toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-2);
  border-radius: 18px;
  cursor: pointer;
}
.toggle[hidden] { display: none; }
.toggle-text { color: var(--muted); font-size: 15px; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch { position: relative; flex: none; width: 48px; height: 28px; border-radius: 999px; background: var(--key); transition: background .2s; }
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text);
  transition: transform .2s;
}
.toggle input:checked + .switch { background: var(--accent); }
.toggle input:checked + .switch::after { transform: translateX(20px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

.stepper { width: 100%; padding: 12px; background: var(--bg-2); border-radius: 18px; }
.stepper-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.stepper-label { color: var(--muted); font-size: 14px; }
.stepper-reset { padding: 3px 10px; border-radius: 999px; background: transparent; border: 1px solid var(--key-press); color: var(--muted); font-size: 12px; }
.stepper-reset:active { background: var(--key-press); }
.stepper-reset:disabled { opacity: .3; cursor: default; }
.stepper-value { margin-left: auto; font-size: 30px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.stepper-value small { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.stepper-row { display: grid; grid-template-columns: 1fr 1fr 1px 1fr 1fr; gap: 6px; align-items: center; }
.stepper-divider { align-self: stretch; background: var(--key-press); }
.stepper-row button { height: 40px; border-radius: 10px; background: var(--key); font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stepper-row button:active { background: var(--key-press); }
.stepper-row button:disabled { opacity: .3; cursor: default; }
.stepper-row .minus { color: var(--muted); }

.btn-primary {
  width: 100%;
  max-width: 320px;
  padding: 16px;
  border-radius: 16px;
  font-size: 20px;
  font-weight: 700;
  color: #2a1a00;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 20px rgba(255, 138, 61, .3);
  transition: transform .08s;
}
.btn-primary:active { transform: scale(.97); }
.btn-ghost {
  width: 100%;
  max-width: 320px;
  padding: 14px;
  border-radius: 16px;
  font-size: 17px;
  background: transparent;
  border: 1px solid var(--key-press);
  color: var(--muted);
}
.btn-ghost:active { background: var(--key-press); }
.btn-ghost[hidden] { display: none; }

/* ---------- 看清單 ---------- */
#screen-list.active { height: 100dvh; min-height: 0; }
.list-head { width: 100%; display: flex; align-items: center; gap: 12px; }
.list-tip { color: var(--muted); font-size: 13px; }
.btn-back {
  flex: none;
  min-width: 72px;
  height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--key-press);
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}
.btn-back:active { background: var(--key-press); }
/* 兩欄、每欄 10 個，由上到下再換欄（跟投影片一樣的讀法） */
.list-grid {
  flex: 1;
  min-height: 0;
  width: 100%;
  margin-top: 12px;
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(10, 1fr);
  gap: 6px 10px;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 0;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--bg-2);
  font-size: min(20px, 5.2vw);
  text-align: left;
  overflow: hidden;
  white-space: nowrap;
}
.list-item:active { background: var(--key-press); }
.list-item .no { flex: none; color: var(--accent); font-size: .75em; font-weight: 700; font-variant-numeric: tabular-nums; }
.list-pager { width: 100%; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-top: 12px; }
.list-info { text-align: center; color: var(--muted); font-size: 14px; }
.list-info b { color: var(--accent); font-size: 18px; }
.btn-page { padding: 14px 8px; border-radius: 16px; background: var(--card); font-size: 16px; font-weight: 600; box-shadow: 0 3px 0 rgba(0, 0, 0, .3); }
.btn-page:active { background: var(--key-press); transform: translateY(2px); box-shadow: none; }
.btn-page:disabled { opacity: .3; cursor: default; }

/* ---------- 遊戲畫面 ---------- */
/* 固定一個「看得到的」高度：手機鍵盤打開時 --vvh 會變小（game.js 用 visualViewport 量），
   整個畫面跟著縮，輸入框才不會被鍵盤蓋住 */
#screen-game.active {
  height: var(--vvh, 100dvh);
  min-height: 0;
  overflow: hidden;
  padding-top: calc(env(safe-area-inset-top) + 16px);
  padding-bottom: calc(env(safe-area-inset-bottom) + 14px);
}
body.kb #screen-game.active { padding-top: 8px; padding-bottom: 8px; }

.hud { width: 100%; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.hud-left { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.mode-tag { padding: 3px 10px; border-radius: 999px; background: var(--card); color: var(--accent); font-size: 13px; }
.mode-tag.practice { color: var(--good); }
.miss-count { color: var(--muted); font-size: 12px; min-height: 15px; }
.score { text-align: center; line-height: 1.1; }
.score-num { font-size: 34px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.score-total { font-size: 16px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.btn-quit { position: relative; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--key-press); background: transparent; color: var(--muted); font-size: 13px; }
.btn-quit::after { content: ''; position: absolute; inset: -11px -8px; }
.btn-quit:active { background: var(--key-press); }
.btn-quit[hidden] { display: none; }
.clock { display: flex; align-items: center; gap: 5px; font-size: 18px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.clock .ico { width: 17px; height: 17px; }
body.kb .score-num { font-size: 26px; }
body.kb .hud-left .miss-count { display: none; }

.pace { width: 100%; margin-top: 8px; }
.progress { height: 5px; border-radius: 999px; background: rgba(255, 255, 255, .07); overflow: hidden; }
.progress i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 8px rgba(232, 184, 74, .7);
  transition: width .25s ease-out;
}
.pace-text { min-height: 18px; margin-top: 4px; color: var(--muted); font-size: 13px; text-align: center; font-variant-numeric: tabular-nums; }
.pace-text b { color: var(--accent); }
.pace-text .over { color: var(--bad); }
body.kb .pace-text { display: none; }

/* 鎖鏈：由上往下排，最新的貼著下面那一格；放不下的舊卡片從上面淡出 */
.chain {
  flex: 1;
  min-height: 0;
  width: 100%;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 0;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 40px);
  mask-image: linear-gradient(to bottom, transparent, #000 40px);
}
.chain[hidden] { display: none; }   /* 跟 π 一樣的坑：display: flex 會蓋過 [hidden] */
.link {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 52%;
  max-width: 100%;
  padding: 6px 16px;
  border-radius: 14px;
  background: var(--bg-2);
  font-size: 22px;
  line-height: 1.3;
}
.link .no { color: var(--muted); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.link .w { flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 卡片之間的那一節鎖鏈 */
.chain .link { position: relative; margin-top: 14px; }
.chain .link::before {
  content: '';
  position: absolute;
  top: -14px;
  left: 50%;
  width: 2px;
  height: 14px;
  margin-left: -1px;
  background: var(--key-press);
}
.chain .link:first-child::before { display: none; }
.link.ctx { opacity: .45; }
.link.fresh { animation: pop .25s ease; box-shadow: inset 0 0 0 1px rgba(232, 184, 74, .5); }
.link.skip .w { color: var(--bad); }
.link.skip { box-shadow: inset 0 0 0 2px var(--bad); }
.link.hint .w { color: var(--accent-2); }
.link.unclear .w { color: #7fd1c7; }   /* 沒聽清楚、靠後面接上才算對的 */
.link.start { opacity: .45; font-size: 15px; color: var(--muted); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* 現在要答的這一格（發光的金框）；練習時提示會出現在這裡 */
.slot {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 70%;
  max-width: 100%;
  margin-top: 14px;
  padding: 10px 18px;
  border-radius: 16px;
  background: var(--bg-2);
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 22px rgba(232, 184, 74, .25);
  font-size: 30px;
  line-height: 1.25;
}
.slot::before {
  content: '';
  position: absolute;
  top: -14px;
  left: 50%;
  width: 2px;
  height: 14px;
  margin-left: -1px;
  background: var(--accent);
}
.slot.first::before { display: none; }
.slot-no { color: var(--accent); font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.slot-word { flex: 1; min-height: 1.25em; text-align: center; letter-spacing: 2px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.slot-word .q { color: var(--accent); animation: blink 1s steps(1) infinite; }
.slot-word.hint { color: var(--accent-2); }
.slot.wrong { animation: shake .35s; box-shadow: inset 0 0 0 2px var(--bad), 0 0 22px rgba(255, 92, 122, .3); }
.slot[hidden] { display: none; }
body.kb .slot { margin-top: 10px; padding: 6px 16px; font-size: 24px; }
@keyframes blink { 50% { opacity: 0; } }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.feedback { min-height: 22px; margin-top: 6px; color: var(--muted); font-size: 14px; text-align: center; }
.feedback.bad { color: var(--bad); }
.feedback.good { color: var(--good); }
.feedback[hidden] { display: none; }

/* 提示／跳過（左）＋ 切換打字／語音（右） */
.input-switch { width: 100%; display: flex; gap: 8px; margin-top: 6px; }
.input-switch[hidden] { display: none; }
.input-switch .spacer { flex: 1; }
.btn-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--key-press);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
}
.btn-switch::after { content: ''; position: absolute; inset: -10px -4px 0; }
.btn-switch:active { background: var(--key-press); }
.btn-switch[hidden] { display: none; }   /* 跟 π 一樣的坑：inline-flex 會蓋過 [hidden] */

.type-form { width: 100%; display: flex; gap: 8px; margin-top: 10px; }
.type-form[hidden] { display: none; }
.type-input {
  flex: 1;
  min-width: 0;
  height: 54px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--key-press);
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  font-size: 22px;   /* 16px 以上，iPhone 點進去才不會自動放大 */
}
.type-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.type-input::placeholder { color: var(--muted); opacity: .6; font-size: 17px; }
.btn-send {
  flex: none;
  width: 72px;
  height: 54px;
  border-radius: 14px;
  background: var(--accent);
  color: #2a1a00;
  font-size: 17px;
  font-weight: 700;
}
.btn-send:active { transform: scale(.96); }

/* 語音模式：整塊取代輸入框 */
.voice-panel {
  flex: none;
  width: 100%;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  animation: panel-in .3s ease;
}
.voice-panel[hidden] { display: none; }
.mic {
  position: relative;
  flex: none;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: var(--card);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .35);
  transition: background .15s, color .15s, transform .05s;
  touch-action: none;
  -webkit-touch-callout: none;
}
.mic:active { transform: translateY(2px); box-shadow: none; }
.mic.on { background: rgba(255, 92, 122, .2); color: var(--bad); box-shadow: inset 0 0 0 3px var(--bad); }
.mic.on::before, .mic.on::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--bad);
  animation: ripple 2s ease-out infinite;
}
.mic.on::after { animation-delay: 1s; }
/* 按下去但麥克風還沒開好：淡淡的紅框閃，這時候唸的聽不到 */
.mic.wait { color: var(--muted); box-shadow: inset 0 0 0 3px rgba(255, 92, 122, .35); animation: mic-wait .6s ease-in-out infinite alternate; }
@keyframes mic-wait { to { box-shadow: inset 0 0 0 3px rgba(255, 92, 122, .1); } }
@keyframes ripple { to { transform: scale(1.55); opacity: 0; } }
.voice-words { min-height: 34px; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 100%; }
.voice-words span { padding: 3px 10px; border-radius: 10px; background: var(--bg-2); font-size: 17px; }
.voice-words .hit { color: var(--accent); }
.voice-words .miss { color: var(--bad); box-shadow: inset 0 0 0 2px var(--bad); }
.voice-words .skip { color: var(--muted); opacity: .6; }
.voice-words .unclear { color: #7fd1c7; box-shadow: inset 0 0 0 1px rgba(127, 209, 199, .6); }
.voice-text { max-width: 340px; min-height: 24px; color: var(--muted); font-size: 15px; line-height: 1.6; }
.voice-text b { color: var(--text); font-weight: 600; }
.voice-panel.error .voice-text { color: var(--bad); }
.btn-claim {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--card);
  color: var(--good);
  font-size: 15px;
  box-shadow: inset 0 0 0 1px rgba(94, 224, 160, .5);
  animation: panel-in .2s ease;
}
.btn-claim[hidden] { display: none; }

/* ---------- 結果區 ---------- */
.result-panel {
  flex: 1;
  min-height: 0;
  width: 100%;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  overflow-y: auto;
  animation: panel-in .3s ease;
}
.result-panel[hidden] { display: none; }
@keyframes panel-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
h2 { margin: 0; font-size: 26px; }
.grade { display: inline-flex; align-items: center; gap: 8px; padding: 6px 18px; border-radius: 999px; font-size: 18px; font-weight: 800; letter-spacing: 2px; }
.grade:empty { display: none; }
.grade.g3 { color: #2a1a00; background: linear-gradient(135deg, #ffe08a, var(--accent)); box-shadow: 0 0 24px rgba(232, 184, 74, .6); }
.grade.g2 { color: #2a1a00; background: var(--accent); }
.grade.g1 { color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.grade.g0 { color: var(--muted); font-weight: 600; letter-spacing: 0; font-size: 15px; box-shadow: inset 0 0 0 1px var(--key-press); }
.new-record { display: inline-flex; align-items: center; gap: 6px; font-size: 17px; color: var(--good); font-weight: 700; }
.new-record .ico { width: 18px; height: 18px; fill: currentColor; }
.new-record[hidden] { display: none; }
.stats { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { padding: 10px 4px; background: var(--bg-2); border-radius: 14px; }
.stat-num { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { margin-top: 2px; color: var(--muted); font-size: 12px; }
/* 10×10 鎖鏈格：每一格一環 */
.grid { width: 100%; max-width: 340px; display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }
.grid[hidden] { display: none; }
.grid button {
  aspect-ratio: 1;
  border-radius: 5px;
  background: var(--key);
  color: rgba(0, 0, 0, .55);
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 0;
}
.grid .ok { background: var(--good); }
.grid .slow { background: var(--warn); }
.grid .wrong, .grid .hint { background: var(--accent-2); }
.grid .claim, .grid .unclear { background: #7fd1c7; }
.grid .skip { background: var(--bad); color: #fff; }
.grid .none { background: var(--key); color: var(--muted); opacity: .5; }
.grid .sel { outline: 2px solid var(--text); outline-offset: 1px; }
.grid-info { min-height: 20px; color: var(--muted); font-size: 13px; }
.grid-info b { color: var(--text); }
.grid-info[hidden] { display: none; }
.over-actions { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: auto; }
.over-actions .btn-primary { padding: 14px; font-size: 18px; }
.over-actions .btn-ghost { padding: 11px; font-size: 16px; }

/* 答錯：整個畫面閃一下紅 */
.flash { position: fixed; inset: 0; z-index: 8; pointer-events: none; background: var(--bad); opacity: 0; }
.flash.on { animation: flash .28s ease-out; }
@keyframes flash { from { opacity: .25; } to { opacity: 0; } }

/* ---------- 確認視窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 7, 4, .72);
  animation: fade-in .15s ease;
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 340px;
  padding: 24px 20px 20px;
  border-radius: 22px;
  background: var(--card);
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
  animation: pop-in .18s ease;
}
.modal-card h3 { margin: 0 0 8px; font-size: 21px; }
.modal-card p { margin: 0 0 20px; color: var(--muted); font-size: 15px; line-height: 1.5; }
.modal-card p b { color: var(--accent); }
.modal-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { transform: scale(.92); opacity: 0; } }

/* 畫面上方的小提示，幾秒後自己消失 */
.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 14px);
  left: 50%;
  z-index: 12;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast[hidden] { display: none; }
.toast.show { animation: toast-in .25s ease; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -10px); } }

/* ---------- 矮螢幕（iPhone SE 667、舊機 640／568） ---------- */
@media (max-height: 740px) {
  .logo svg { width: 90px; height: 45px; }
  h1 { font-size: 28px; }
  .best-box { margin: 10px 0 2px; padding: 8px 16px; }
  .menu-buttons { gap: 10px; margin-top: 10px; }
  .menu-btn { padding: 13px 18px; }

  .setup { gap: 8px; padding-top: calc(env(safe-area-inset-top) + 14px); padding-bottom: calc(env(safe-area-inset-bottom) + 12px); }
  .setup h2 { margin-top: 0; font-size: 22px; }
  .tier { padding: 10px 6px 8px; }
  .tier b { font-size: 32px; }
  .stepper { padding: 9px 12px; }
  .stepper-head { margin-bottom: 6px; }
  .stepper-value { font-size: 24px; }
  .stepper-row button { height: 34px; }
  .setup-actions .btn-primary { padding: 12px; font-size: 18px; }
  .setup-actions .btn-ghost { padding: 10px; font-size: 16px; }

  .result-panel { gap: 7px; }
  .result-panel h2 { font-size: 22px; }
  .grade { padding: 4px 16px; font-size: 16px; }
  .stat { padding: 6px 4px; }
  .stat-num { font-size: 18px; }
  .grid { max-width: 250px; gap: 2px; }
  .over-actions .btn-primary { padding: 11px; font-size: 17px; }
  .over-actions .btn-ghost { padding: 8px; font-size: 15px; }

  .mic { width: 96px; height: 96px; }
  .mic-ico { width: 44px; height: 44px; }
  .slot { font-size: 26px; padding: 8px 16px; }
  .link { font-size: 19px; padding: 5px 14px; }
}
@media (max-height: 620px) {
  .subtitle { display: none; }
  .menu-btn { padding: 10px 16px; }
  .menu-icon .ico { width: 26px; height: 26px; }
  .setup-note { font-size: 13px; line-height: 1.5; }
  .stepper-row button { height: 30px; }
  .result-panel { gap: 5px; }
  .result-panel h2 { font-size: 20px; }
  .stat-num { font-size: 16px; }
  .over-actions { gap: 6px; }
  .grid { max-width: 200px; }
  .new-record { font-size: 15px; }
  .grid-info { min-height: 0; font-size: 12px; }
  .grid-info:not(:has(b)) { display: none; }   /* 「點格子看是哪一個詞」這句說明放不下就收起來，點了格子才出現 */
}

@media (prefers-reduced-motion: reduce) {
  .screen.active, .link.fresh, .slot.wrong { animation: none; }
}
