/* ============================================================
 * 多益互動單字卡 — Design System
 * 依 DESIGN.md「技術報告式排版」：
 *  低飽和海軍藍主調、1px 細線、等寬字當標籤、白色紙張放灰底、
 *  圓角 ≤ 4px、不用陰影（對話框／提示除外）、全站只有一個暖色 accent。
 * ============================================================ */
:root {
  --font-sans: 'IBM Plex Sans', 'Noto Sans TC', 'Microsoft JhengHei', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --radius-md: 4px;
  --radius-sm: 3px;

  --kb-surface: #FFFFFF;
  --kb-surface-2: #F2F4F7;
  --kb-navy: #1E3050;
  --kb-navy-2: #2C4E7A;
  --kb-blue: #3E6392;
  --kb-olive: #6E7F58;
  --kb-brick: #9C5B52;
  --kb-gold: #A8873F;
  --kb-accent: #C4693C;

  --color-bg: #EAEDF1;
  --color-bg-side: #E5EAF0;
  --color-border: #D2D9E2;
  --color-border-light: #E2E7ED;
  --color-text: #1B2735;
  --color-text-muted: #52667A;
  --color-text-subtle: #8493A5;

  --on-navy: #FFFFFF;
  --mark-bg: rgba(168, 135, 63, 0.24);
  --overlay: rgba(14, 23, 35, 0.45);
  color-scheme: light;
}
[data-theme='dark'] {
  --kb-surface: #16202F;
  --kb-surface-2: #1C2839;
  --kb-navy: #405A85;
  --kb-navy-2: #7FA9D9;
  --kb-blue: #6E9BCB;
  --kb-olive: #93A87A;
  --kb-brick: #C87F72;
  --kb-gold: #C7A55A;
  --kb-accent: #E08B52;

  --color-bg: #0E1723;
  --color-bg-side: #111C29;
  --color-border: #2B3B4F;
  --color-border-light: #22303F;
  --color-text: #C9D4E0;
  --color-text-muted: #93A3B5;
  --color-text-subtle: #6B7C90;

  --on-navy: #FFFFFF;
  --mark-bg: rgba(199, 165, 90, 0.28);
  --overlay: rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; overscroll-behavior-y: none;
  font-family: var(--font-sans); font-size: 15px; line-height: 1.6;
  color: var(--color-text); background: var(--color-bg);
  text-wrap: pretty;
}
main { flex: 1; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
.card, .vrow, .tab, .rate { touch-action: manipulation; }
input, select { font: inherit; color: inherit; }
svg { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
img { display: block; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--color-text-muted); font-size: 0.93rem; }
.muted.mono { font-size: 12px; letter-spacing: 0.06em; }

kbd {
  font-family: var(--font-mono); font-size: 11.5px; line-height: 1;
  padding: 3px 6px; border-radius: var(--radius-sm);
  background: var(--kb-surface-2); border: 1px solid var(--color-border); border-bottom-width: 2px;
  color: var(--color-text-muted);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--color-border); border: 2px solid transparent; background-clip: padding-box; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-subtle); background-clip: padding-box; border: 2px solid transparent; }
:focus-visible { outline: 2px solid var(--kb-navy-2); outline-offset: 2px; border-radius: var(--radius-sm); }

/* ---------- 載入中 ---------- */
.loader { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: var(--color-bg); transition: opacity 0.4s ease, visibility 0.4s; }
.loader.is-done { opacity: 0; visibility: hidden; pointer-events: none; display: none !important; }
.loader-card { text-align: center; width: min(280px, 80vw); }
.loader-logo { margin: 0 auto 20px; }
.loader-title { font-weight: 600; }
.loader-sub { color: var(--color-text-subtle); font-size: 12px; letter-spacing: 0.14em; margin-top: 4px; }
.loader-bar { height: 2px; margin-top: 18px; background: var(--color-border); overflow: hidden; }
.loader-bar i { display: block; width: 40%; height: 100%; background: var(--kb-accent); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

/* ---------- 頂部列（56px、sticky、白底、下方 1px 線） ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: 56px;
  display: flex; align-items: center; gap: 16px; padding: 0 clamp(12px, 3vw, 28px);
  background: var(--kb-surface); border-bottom: 1px solid var(--color-border);
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: inherit; flex: none; }
.brand-logo { width: 36px; height: 36px; border-radius: 50%; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 15.5px; font-weight: 600; letter-spacing: 0.01em; }
.brand-text em { font-style: normal; font-size: 10.5px; letter-spacing: 0.14em; color: var(--color-text-subtle); }

.tabs { display: flex; align-self: stretch; margin: 0 auto; gap: 4px; }
.tab {
  position: relative; display: flex; align-items: center; gap: 8px; padding: 0 16px;
  color: var(--color-text-muted); font-weight: 500; transition: color 0.15s, background 0.15s;
}
.tab i { font-style: normal; font-size: 11.5px; color: var(--color-text-subtle); letter-spacing: 0.04em; }
.tab:hover { color: var(--color-text); background: var(--kb-surface-2); }
.tab.is-active { color: var(--kb-navy-2); }
.tab.is-active i { color: var(--kb-accent); }
.tab.is-active::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; background: var(--kb-navy-2); }

.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--radius-sm);
  font-size: 12.5px; color: var(--color-text-muted); background: var(--kb-surface-2); border: 1px solid var(--color-border-light); white-space: nowrap;
}
.chip.mono { font-size: 12px; letter-spacing: 0.04em; }
.chip.streak { padding: 5px 12px; font-weight: 500; }
.chip.streak b { color: var(--kb-navy-2); font-family: var(--font-mono); font-size: 14px; }

.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-md);
  color: var(--color-text-muted); border: 1px solid var(--color-border); background: var(--kb-surface);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.icon-btn:hover { color: var(--color-text); background: var(--kb-surface-2); }
.ic-sun { display: none; }
[data-theme='dark'] .ic-sun { display: block; }
[data-theme='dark'] .ic-moon { display: none; }

/* ---------- 版面 ---------- */
main { width: min(1100px, 100%); margin: 0 auto; padding: clamp(14px, 3vw, 28px); }
.view { display: none; }
.view.is-active { display: block; animation: viewIn 0.3s ease; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel-head { position: relative; display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 18px; margin: 10px 0 20px; padding-top: 14px; }
.panel-head::before { content: ''; position: absolute; left: 0; top: 0; width: 22px; height: 2px; background: var(--kb-accent); }
.panel-head h2 { font-size: 23px; font-weight: 600; letter-spacing: -0.01em; }

/* ---------- 學習：進度列 ---------- */
.session-bar { display: flex; align-items: center; gap: 18px; margin: 0 auto 16px; max-width: 760px; }
.counts { display: flex; gap: 16px; }
.count { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--color-text-muted); padding-bottom: 2px; border-bottom: 2px solid transparent; }
.count i { width: 8px; height: 8px; border-radius: 2px; }
.count b { font-family: var(--font-mono); font-size: 15px; font-weight: 500; color: var(--color-text); font-variant-numeric: tabular-nums; }
.count em { font-style: normal; }
.c-new i { background: var(--kb-blue); }
.c-learn i { background: var(--kb-brick); }
.c-review i { background: var(--kb-olive); }
.count.is-current { border-bottom-color: var(--kb-accent); }

.progress { flex: 1; height: 4px; background: var(--color-border); overflow: hidden; border-radius: 2px; }
.progress-fill { height: 100%; width: 0; background: var(--kb-navy-2); transition: width 0.4s ease; }

.mini-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius-md);
  font-size: 13px; color: var(--color-text-muted); background: var(--kb-surface); border: 1px solid var(--color-border);
  transition: color 0.15s, background 0.15s, opacity 0.15s;
}
.mini-btn:hover:not(:disabled) { color: var(--color-text); background: var(--kb-surface-2); }
.mini-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- 單字卡 ---------- */
.stage { max-width: 760px; margin: 0 auto; }
.card-scene { perspective: 1800px; }
.card-scene.swap { animation: cardIn 0.28s ease; }
@keyframes cardIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

.card { display: grid; position: relative; cursor: pointer; outline: none; transform-style: preserve-3d; transition: transform 0.55s cubic-bezier(0.2, 0.85, 0.25, 1); -webkit-tap-highlight-color: transparent; }
.card.no-anim { transition: none; }
.card[data-flipped='true'] { transform: rotateY(180deg); }

.face {
  --st: var(--kb-blue);
  grid-area: 1 / 1; display: flex; flex-direction: column; gap: 18px;
  min-height: min(440px, 58vh); max-height: 74vh; overflow: auto;
  padding: clamp(20px, 4vw, 34px);
  background: var(--kb-surface); border: 1px solid var(--color-border); border-left: 3px solid var(--st); border-radius: var(--radius-md);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  transition: visibility 0s 0.28s;
}
.card[data-state='learn'] .face { --st: var(--kb-brick); }
.card[data-state='master'] .face { --st: var(--kb-olive); }
.card.no-anim .face { transition: none; }
.face.back { transform: rotateY(180deg); }
.card[data-flipped='false'] .face.back { visibility: hidden; }
.card[data-flipped='true'] .face.front { visibility: hidden; }

.face-top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stars { color: var(--kb-gold); letter-spacing: 1px; font-size: 12px; }
.chip.cat { color: var(--kb-navy-2); }
.state-badge { margin-left: auto; font-size: 12.5px; font-weight: 500; padding: 3px 10px; border-radius: var(--radius-sm); border: 1px solid currentColor; letter-spacing: 0.04em; }
.state-badge.new { color: var(--kb-blue); }
.state-badge.learn { color: var(--kb-brick); }
.state-badge.master { color: var(--kb-olive); }

.face-main { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 10px 0; }
.face-main::before { content: ''; width: 22px; height: 2px; background: var(--kb-accent); margin-bottom: 4px; }
.pos { color: var(--color-text-subtle); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; }
.word {
  font-size: clamp(2.3rem, 9vw, 4.4rem); font-weight: 600; line-height: 1.14; letter-spacing: -0.02em;
  color: var(--color-text); overflow-wrap: anywhere; word-break: break-word;
}
.word.zh-front { font-size: clamp(1.9rem, 6.5vw, 3rem); line-height: 1.3; letter-spacing: 0; }
.speak {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: var(--radius-md);
  color: var(--on-navy); background: var(--kb-navy); transition: filter 0.15s, transform 0.15s;
}
.speak svg { width: 22px; height: 22px; }
.speak:hover { filter: brightness(1.15); }
.speak:active { transform: scale(0.95); }
.speak.sm { width: 34px; height: 34px; }
.speak.sm svg { width: 17px; height: 17px; }
.speak.playing { animation: ping 0.8s ease-out; }
@keyframes ping { 0% { box-shadow: 0 0 0 0 var(--kb-navy-2); } 100% { box-shadow: 0 0 0 12px transparent; } }
.face-foot { text-align: center; color: var(--color-text-subtle); font-size: 12.5px; }

/* 背面 */
.back-head { display: flex; flex-direction: column; gap: 8px; }
.back-word { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 12px; }
.back-word h3 { font-size: clamp(1.35rem, 4vw, 1.7rem); font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.zh { font-size: clamp(1.5rem, 5vw, 2.1rem); font-weight: 600; line-height: 1.4; color: var(--kb-navy-2); }
.forms { color: var(--color-text-muted); font-size: 13.5px; }
.forms b { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.08em; color: var(--color-text-subtle); font-weight: 500; margin-right: 8px; }

.examples { display: flex; flex-direction: column; gap: 10px; }
.ex {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: start;
  padding: 12px 16px; background: var(--kb-surface); border: 1px solid var(--color-border); border-left: 3px solid var(--kb-blue); border-radius: var(--radius-md);
}
.ex-en { font-size: 15.5px; line-height: 1.6; }
.ex-zh { grid-column: 1; color: var(--color-text-muted); font-size: 14px; }
.ex-play {
  grid-row: 1 / span 2; grid-column: 2; display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-md);
  color: var(--color-text-muted); background: var(--kb-surface-2); border: 1px solid var(--color-border); transition: color 0.15s, background 0.15s;
}
.ex-play:hover { color: var(--kb-navy-2); background: var(--color-border-light); }
.ex-play svg { width: 15px; height: 15px; }
mark { color: inherit; background: var(--mark-bg); padding: 0 3px; border-radius: 2px; font-weight: 600; }

.tips-toggle {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--radius-md);
  background: var(--kb-surface-2); border: 1px solid var(--color-border); font-size: 13.5px; font-weight: 500; text-align: left;
  transition: background 0.15s;
}
.tips-toggle .mono { font-size: 12px; letter-spacing: 0.12em; color: var(--kb-gold); }
.tips-toggle kbd { margin-left: auto; }
.tips-toggle:hover { background: var(--color-border-light); }
.tips-list { list-style: none; display: none; flex-direction: column; gap: 8px; margin-top: 10px; }
.tips.open .tips-list { display: flex; animation: viewIn 0.25s ease; }
.tips-list li {
  padding: 11px 16px; font-size: 14px; color: var(--color-text); line-height: 1.7;
  background: var(--kb-surface); border: 1px solid var(--color-border); border-left: 3px solid var(--kb-gold); border-radius: var(--radius-md);
}

/* ---------- 作答區 ---------- */
.answer-bar { margin-top: 16px; min-height: 68px; }
.show-btn {
  width: 100%; height: 56px; border-radius: var(--radius-md); font-size: 16px; font-weight: 600; color: var(--on-navy); background: var(--kb-navy);
  display: flex; align-items: center; justify-content: center; gap: 12px; transition: filter 0.15s, transform 0.1s;
}
.show-btn:hover { filter: brightness(1.18); }
.show-btn:active { transform: translateY(1px); }
.show-btn kbd { background: rgba(255, 255, 255, 0.16); color: var(--on-navy); border-color: rgba(255, 255, 255, 0.25); }

.rate-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; animation: viewIn 0.2s ease; }
.rate {
  --rc: var(--kb-navy-2);
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: 68px; border-radius: var(--radius-md); background: var(--kb-surface); border: 1px solid var(--color-border); border-top: 3px solid var(--rc);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.rate:hover { background: var(--kb-surface-2); border-color: var(--rc); }
.rate:active { transform: translateY(1px); }
.r-label { font-weight: 600; font-size: 15.5px; color: var(--rc); }
.r-int { font-size: 12px; color: var(--color-text-muted); letter-spacing: 0.02em; }
.rate kbd { position: absolute; top: 6px; right: 7px; font-size: 10.5px; padding: 2px 5px; border-bottom-width: 1px; }
.r1 { --rc: var(--kb-brick); }
.r2 { --rc: var(--kb-gold); }
.r3 { --rc: var(--kb-olive); }
.r4 { --rc: var(--kb-navy-2); }

.hotkeys { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 20px; margin-top: 18px; color: var(--color-text-subtle); font-size: 12.5px; }

/* ---------- 完成畫面 ---------- */
.done { text-align: center; padding: 44px 20px; background: var(--kb-surface); border: 1px solid var(--color-border); border-left: 3px solid var(--kb-olive); border-radius: var(--radius-md); animation: viewIn 0.35s ease; }
.done-logo { margin: 0 auto 14px; }
.done h2 { position: relative; font-size: 23px; font-weight: 600; padding-top: 14px; margin-bottom: 6px; }
.done h2::before { content: ''; position: absolute; left: 50%; top: 0; margin-left: -11px; width: 22px; height: 2px; background: var(--kb-accent); }
.done p { color: var(--color-text-muted); }
.done-stats { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; margin: 24px 0; }
.done-stat { min-width: 108px; padding: 12px 18px; background: var(--kb-surface-2); border: 1px solid var(--color-border-light); border-radius: var(--radius-md); }
.done-stat b { display: block; font-family: var(--font-mono); font-size: 24px; font-weight: 500; color: var(--kb-navy-2); }
.done-stat span { color: var(--color-text-muted); font-size: 12.5px; }
.done-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; }

.btn { padding: 10px 22px; border-radius: var(--radius-md); font-weight: 500; border: 1px solid var(--color-border); background: var(--kb-surface); transition: background 0.15s, filter 0.15s; }
.btn:hover { background: var(--kb-surface-2); }
.btn.primary { color: var(--on-navy); border-color: var(--kb-navy); background: var(--kb-navy); }
.btn.primary:hover { filter: brightness(1.18); background: var(--kb-navy); }
.btn.danger { color: var(--kb-brick); border-color: var(--kb-brick); }
.btn.sm { padding: 7px 14px; font-size: 14px; }

/* ---------- 字庫 ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.search { flex: 1 1 260px; display: flex; align-items: center; gap: 10px; padding: 0 14px; height: 42px; border-radius: var(--radius-md); background: var(--kb-surface); border: 1px solid var(--color-border); color: var(--color-text-subtle); transition: border-color 0.15s; }
.search:focus-within { border-color: var(--kb-navy-2); color: var(--color-text); }
.search input { flex: 1; background: none; border: 0; outline: none; min-width: 0; }
.search input::placeholder { color: var(--color-text-subtle); }
.seg { display: flex; border-radius: var(--radius-md); background: var(--kb-surface); border: 1px solid var(--color-border); overflow: hidden; }
.seg button { padding: 0 14px; height: 40px; color: var(--color-text-muted); font-size: 14px; border-right: 1px solid var(--color-border-light); transition: color 0.15s, background 0.15s; }
.seg button:last-child { border-right: 0; }
.seg button:hover { color: var(--color-text); background: var(--kb-surface-2); }
.seg button.is-active { color: var(--on-navy); background: var(--kb-navy); }
.select { height: 42px; padding: 0 12px; border-radius: var(--radius-md); background: var(--kb-surface); border: 1px solid var(--color-border); outline: none; cursor: pointer; }
.select option { background: var(--kb-surface); color: var(--color-text); }

.vlist { position: relative; height: calc(100vh - 330px); min-height: 360px; overflow-y: auto; border-radius: var(--radius-md); background: var(--kb-surface); border: 1px solid var(--color-border); outline: none; }
.vlist-spacer { position: relative; width: 100%; }
.vlist-rows { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }
.vrow {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; height: 68px; padding: 0 18px;
  border-bottom: 1px solid var(--color-border-light); cursor: pointer; transition: background 0.12s; width: 100%; text-align: left;
}
.vrow:hover { background: var(--kb-surface-2); }
.vrow-main { min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.vrow-w { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vrow-z { color: var(--color-text-muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vrow-meta { display: flex; align-items: center; gap: 12px; }
.vrow-star { color: var(--kb-gold); font-size: 12px; letter-spacing: 1px; }
.vrow .state-badge { margin: 0; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--color-text-subtle); }

/* ---------- 統計 ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 12px; }
.kpi { padding: 16px 18px; background: var(--kb-surface); border: 1px solid var(--color-border); border-left: 3px solid var(--kc, var(--kb-navy-2)); border-radius: var(--radius-md); }
.kpi span { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.1em; color: var(--color-text-subtle); }
.kpi b { display: block; font-size: 32px; font-weight: 600; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.kpi small { color: var(--color-text-muted); font-size: 12.5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.block { padding: 20px 22px; background: var(--kb-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); }
.block h3 { position: relative; padding-left: 12px; font-size: 17px; font-weight: 600; margin-bottom: 18px; }
.block h3::before { content: ''; position: absolute; left: 0; top: 3px; width: 3px; height: 16px; background: var(--kb-blue); }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 170px; border-bottom: 1px solid var(--color-border); }
.bar { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; position: relative; }
.bar-stack { width: 100%; max-width: 28px; display: flex; flex-direction: column; justify-content: flex-end; flex: none; height: 120px; gap: 1px; }
.bar-stack i { display: block; width: 100%; height: 0; min-height: 0; border-radius: 1px; transition: height 0.5s ease; }
.bar-n { background: var(--kb-navy-2); }
.bar-r { background: var(--kb-olive); }
.bar-f { background: var(--kb-blue); }
.bar label { position: absolute; bottom: -22px; font-family: var(--font-mono); font-size: 11px; color: var(--color-text-subtle); white-space: nowrap; }
.bar.today label { color: var(--kb-accent); font-weight: 500; }
.bar-v { font-family: var(--font-mono); font-size: 11px; color: var(--color-text-muted); height: 14px; }
.bars { margin-bottom: 26px; }
.legend { display: flex; gap: 16px; margin-top: 4px; font-size: 12.5px; color: var(--color-text-muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
.lg-new { background: var(--kb-navy-2); } .lg-rev { background: var(--kb-olive); }

.ring-block { display: flex; flex-direction: column; }
.ring-wrap { display: flex; align-items: center; justify-content: center; gap: 26px; flex-wrap: wrap; flex: 1; }
.ring { position: relative; width: 168px; height: 168px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; }
.ring .bg { stroke: var(--color-border-light); }
.ring .fg { transition: stroke-dashoffset 0.9s ease; }
.ring .fg-l { stroke: var(--kb-navy-2); }
.ring .fg-m { stroke: var(--kb-olive); }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-center b { font-size: 30px; font-weight: 600; line-height: 1; letter-spacing: -0.02em; }
.ring-center span { font-size: 12.5px; color: var(--color-text-muted); margin-top: 4px; }
.ring-legend { display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.ring-legend div { display: flex; align-items: center; gap: 10px; color: var(--color-text-muted); }
.ring-legend i { width: 10px; height: 10px; border-radius: 2px; }
.ring-legend b { color: var(--color-text); margin-left: auto; padding-left: 14px; font-family: var(--font-mono); font-weight: 500; font-variant-numeric: tabular-nums; }

.score-bars { display: flex; flex-direction: column; gap: 16px; }
.sb-top { display: flex; justify-content: space-between; font-size: 13.5px; color: var(--color-text-muted); margin-bottom: 6px; }
.sb-top b { color: var(--color-text); font-family: var(--font-mono); font-weight: 500; }
.sb-top span:last-child { font-family: var(--font-mono); font-size: 12.5px; }
.sb-track { height: 8px; border-radius: 2px; background: var(--color-border-light); overflow: hidden; display: flex; }
.sb-track i { display: block; height: 100%; width: 0; transition: width 0.7s ease; }
.sb-m { background: var(--kb-olive); }
.sb-l { background: var(--kb-navy-2); }

/* ---------- 對話框（可使用陰影） ---------- */
.dialog {
  margin: auto; width: min(640px, calc(100vw - 24px)); max-height: min(86vh, 860px);
  border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 0; color: var(--color-text);
  background: var(--kb-surface); box-shadow: 0 24px 64px -16px rgba(14, 23, 35, 0.4); overflow: hidden;
}
.dialog[open] { animation: dlgIn 0.22s ease; display: block; }
.dialog::backdrop { background: var(--overlay); }
@keyframes dlgIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.dlg-inner { display: flex; flex-direction: column; max-height: min(86vh, 860px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; background: var(--kb-surface-2); border-bottom: 1px solid var(--color-border); }
.dlg-head h2 { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.dlg-body { padding: 20px 22px 26px; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; }

.sec-title { font-family: var(--font-mono); font-size: 12px; font-weight: 500; letter-spacing: 0.12em; color: var(--color-text-subtle); padding-bottom: 6px; border-bottom: 1px solid var(--color-border-light); text-transform: uppercase; }
.field { display: flex; flex-direction: column; gap: 10px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.field label, .field-row > span:first-child { font-weight: 500; }
.field small { color: var(--color-text-subtle); font-size: 12.5px; font-weight: 400; display: block; }
.field-val { color: var(--kb-navy-2); font-family: var(--font-mono); font-weight: 500; font-variant-numeric: tabular-nums; }
input[type='range'] { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 2px; background: var(--color-border); outline: none; }
input[type='range']::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 20px; border-radius: var(--radius-sm); background: var(--kb-navy); border: 2px solid var(--kb-surface); outline: 1px solid var(--kb-navy); cursor: pointer; }
input[type='range']::-moz-range-thumb { width: 12px; height: 18px; border-radius: var(--radius-sm); background: var(--kb-navy); border: 2px solid var(--kb-surface); cursor: pointer; }

.switch { position: relative; width: 44px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: var(--radius-md); background: var(--color-border); transition: background 0.2s; }
.switch i::after { content: ''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 2px; background: var(--kb-surface); transition: transform 0.2s; }
.switch input:checked + i { background: var(--kb-navy); }
.switch input:checked + i::after { transform: translateX(20px); background: #fff; }
.switch input:focus-visible + i { outline: 2px solid var(--kb-navy-2); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { padding: 6px 13px; border-radius: var(--radius-sm); font-size: 13.5px; color: var(--color-text-muted); background: var(--kb-surface); border: 1px solid var(--color-border); transition: all 0.15s; }
.chip-btn:hover { color: var(--color-text); background: var(--kb-surface-2); }
.chip-btn.on { color: var(--on-navy); background: var(--kb-navy); border-color: var(--kb-navy); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.filter-info { padding: 11px 16px; background: var(--kb-surface); border: 1px solid var(--color-border); border-left: 3px solid var(--kb-blue); border-radius: var(--radius-md); font-size: 14px; }

.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.detail-meta { color: var(--color-text-subtle); font-family: var(--font-mono); font-size: 12px; }

/* ---------- 頁尾 ---------- */
.footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 18px; padding: 18px 16px; background: var(--color-bg-side); border-top: 1px solid var(--color-border); color: var(--color-text-subtle); font-size: 12.5px; }
.footer img { border-radius: 50%; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 200; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 11px 20px; border-radius: var(--radius-md); background: var(--kb-navy); color: var(--on-navy); font-size: 14px;
  box-shadow: 0 12px 32px -10px rgba(14, 23, 35, 0.5); transition: opacity 0.25s, transform 0.25s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 響應式 ---------- */
@media (max-width: 1024px) { main { padding-top: 18px; } }
@media (max-width: 760px) {
  .brand-text { display: none; }
  .brand-logo { width: 30px; height: 30px; }
  .topbar { gap: 6px; padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)); }
  .tabs { margin: 0; flex: 1; min-width: 0; justify-content: space-around; gap: 0; }
  .tab { padding: 0 6px; flex: 1; justify-content: center; gap: 5px; white-space: nowrap; font-size: 15px; }
  .tab i { display: none; }
  .tab.is-active::after { left: 6px; right: 6px; height: 3px; }
  .top-actions { gap: 6px; }
  .icon-btn { width: 40px; height: 40px; }
  .chip.streak { padding: 4px 8px; font-size: 12px; }
  main { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }

  /* 認字頁：進度列、卡片 */
  .session-bar { flex-wrap: wrap; gap: 8px 10px; margin-bottom: 12px; }
  .session-bar .progress { order: 3; flex-basis: 100%; }
  .counts { gap: 12px; }
  .session-actions { margin-left: auto; }
  .mini-btn { min-height: 40px; padding: 6px 14px; }
  .face { min-height: min(380px, 52dvh); max-height: none; overflow: visible; gap: 14px; padding: 18px 16px; }
  .face-main { gap: 12px; }
  .speak.sm { width: 44px; height: 44px; }
  .ex { padding: 12px 12px 12px 14px; }
  .ex-play { width: 44px; height: 44px; }
  .tips-toggle { min-height: 48px; }

  /* 作答區：黏在螢幕底部，單手拇指即可評分 */
  .answer-bar {
    position: sticky; bottom: 0; z-index: 20; min-height: 0;
    margin: 12px -14px 0; padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--color-bg) 78%, transparent);
  }
  .show-btn { height: 60px; font-size: 17px; }
  .rate-grid { gap: 8px; }
  .rate { height: 68px; }
  .r-label { font-size: 16px; }
  .rate kbd, .hotkeys, .show-btn kbd, .tips-toggle kbd, .kbd-only { display: none; }

  /* 字庫 */
  .panel-head { margin: 4px 0 14px; }
  .panel-head h2 { font-size: 21px; }
  .toolbar { gap: 8px; }
  .search { flex: 1 1 100%; height: 46px; }
  .search input, .select, #sync-input, #sync-code { font-size: 16px; }
  .seg { flex: 1 1 auto; }
  .seg button { flex: 1; height: 44px; padding: 0 6px; }
  .select { height: 46px; }
  .vlist { height: calc(100vh - 360px); height: calc(100dvh - 360px); min-height: 320px; }
  .vrow { padding: 0 12px; gap: 8px; }
  .vrow-meta { gap: 8px; }

  /* 統計 */
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 12px 14px; }
  .kpi b { font-size: 26px; }
  .grid-2 { grid-template-columns: 1fr; gap: 8px; }
  .block { padding: 16px 14px; }
  .ring { width: 140px; height: 140px; }
  .ring-wrap { gap: 18px; }
  #bars-14 .bar:nth-child(even) label { display: none; }

  /* 對話框：底部彈出式 */
  .dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 14px 14px 0 0; max-height: 92vh; max-height: 92dvh; border-bottom: 0; }
  .dialog[open] { animation: sheetIn 0.26s cubic-bezier(0.2, 0.85, 0.25, 1); }
  .dlg-inner { max-height: 92vh; max-height: 92dvh; }
  .dlg-head { padding: 12px 16px 12px 18px; }
  .dlg-body { padding: 16px 18px calc(24px + env(safe-area-inset-bottom)); gap: 18px; }
  .btn.sm { min-height: 44px; padding: 8px 16px; }
  .btn { min-height: 46px; }
  .chip-btn { min-height: 40px; padding: 8px 14px; }
  .btn-row { gap: 8px; }
  input[type='range'] { height: 6px; }
  input[type='range']::-webkit-slider-thumb { width: 24px; height: 30px; }
  input[type='range']::-moz-range-thumb { width: 22px; height: 28px; }
  .switch { width: 52px; height: 30px; }
  .switch i::after { width: 24px; height: 24px; }
  .switch input:checked + i::after { transform: translateX(22px); }

  .toast { bottom: calc(100px + env(safe-area-inset-bottom)); }
  .footer { flex-direction: column; gap: 4px; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
}
@keyframes sheetIn { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }
@media (hover: none) {
  .rate kbd, .hotkeys, .show-btn kbd, .tips-toggle kbd, .kbd-only { display: none; }
}
@media (max-width: 360px) {
  .r-label { font-size: 14.5px; }
  .chip.streak { display: none; }
  .word { font-size: clamp(2rem, 11vw, 2.6rem); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
