/* ============ 色彩與基本設定 ============ */
:root {
  --bg: #f4f3fb;
  --bg-grad: radial-gradient(1200px 500px at 10% -10%, #e6e2ff 0%, transparent 60%),
             radial-gradient(900px 400px at 110% 0%, #ffe3f1 0%, transparent 55%);
  --card: #ffffff;
  --card-2: #f8f7fd;
  --text: #1c1a33;
  --muted: #6e6b87;
  --line: #e6e4f2;
  --primary: #5b4bdb;
  --primary-2: #8b5cf6;
  --primary-soft: #ece9ff;
  --on-primary: #ffffff;
  --good: #16a36a;
  --good-soft: #e2f6ec;
  --bad: #e5484d;
  --bad-soft: #fde8e8;
  --warn: #d9850b;
  --warn-soft: #fdf1dc;
  --pink: #db2777;
  --pink-soft: rgba(219,39,119,.14);
  --shadow-sm: 0 1px 2px rgba(28,26,51,.06), 0 1px 3px rgba(28,26,51,.05);
  --shadow: 0 6px 20px -6px rgba(60,45,160,.18), 0 2px 6px rgba(28,26,51,.05);
  --shadow-lg: 0 20px 50px -12px rgba(60,45,160,.35);
  --radius: 18px;
  --radius-sm: 12px;
  /* 圖表色（dataviz 參考色票，已用 validate_palette.js 對本站卡片底色驗證） */
  --series-1: #2a78d6;        /* 復習 */
  --series-2: #eb6834;        /* 測驗 */
  --stage-1: #86b6ef;         /* 待學習 */
  --stage-2: #2a78d6;         /* 學習中 */
  --stage-3: #104281;         /* 已熟記 */
  --grid: #ebe9f3;
  --axis: #c9c6d9;
  --font: "Inter", "Noto Sans TC", system-ui, -apple-system, "Microsoft JhengHei", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0e1a;
    --bg-grad: radial-gradient(1200px 500px at 10% -10%, #231d52 0%, transparent 60%),
               radial-gradient(900px 400px at 110% 0%, #3a1430 0%, transparent 55%);
    --card: #1a1928; --card-2: #222134; --text: #ecebf7; --muted: #9c99b8; --line: #2d2b44;
    --primary: #8b7bff; --primary-2: #b18cff; --primary-soft: #2a2550; --on-primary: #ffffff;
    --good: #3ccf8e; --good-soft: #15302a; --bad: #ff6b6f; --bad-soft: #3a1a20;
    --warn: #f0b048; --warn-soft: #3a2c14;
    --pink: #ff7eb9; --pink-soft: rgba(255,126,185,.18);
    --series-1: #3987e5; --series-2: #d95926;
    --stage-1: #184f95; --stage-2: #3987e5; --stage-3: #9ec5f4;
    --grid: #26253a; --axis: #3a3852;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow: 0 8px 24px -8px rgba(0,0,0,.6);
    --shadow-lg: 0 24px 60px -12px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px));
}
button, input, select, textarea { font-family: inherit; }
.ico { width: 1.2em; height: 1.2em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.2em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ============ 頂部 ============ */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 18px 12px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.brand {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-2) 60%, #ec4899);
  color: #fff; font-weight: 800; font-size: 1rem; letter-spacing: -.5px; box-shadow: var(--shadow);
}
.titles { flex: 1; min-width: 0; }
.topbar h1 { font-size: 1.15rem; margin: 0; line-height: 1.2; font-weight: 700; letter-spacing: -.2px; }
.subtitle { font-size: .72rem; color: var(--muted); letter-spacing: .5px; }
.badge {
  background: linear-gradient(135deg, #f43f5e, #ec4899); color: #fff; border-radius: 999px;
  padding: 4px 12px; font-size: .78rem; font-weight: 600; box-shadow: 0 4px 12px -4px rgba(236,72,153,.6);
}

main { padding: 16px 18px; max-width: 720px; margin: 0 auto; }
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ============ 按鈕與輸入框 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: var(--radius-sm); padding: 12px 16px; font-size: 1rem; font-weight: 500; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: transform .12s ease, box-shadow .2s ease, background .2s ease;
  -webkit-tap-highlight-color: transparent; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); border-color: transparent; color: var(--on-primary);
  box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--primary) 80%, transparent);
}
.btn.accent { background: var(--primary-soft); border-color: transparent; color: var(--primary); box-shadow: none; }
.btn.ghost { background: color-mix(in srgb, var(--card) 70%, transparent); }
.btn.ghost-plain { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); box-shadow: none; }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--bad) 80%, transparent); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.sm { padding: 8px 12px; font-size: .88rem; border-radius: 10px; }
.icon-btn {
  border: 0; background: var(--card-2); width: 40px; height: 40px; border-radius: 12px; display: inline-grid; place-items: center;
  font-size: 1.15rem; cursor: pointer; color: var(--text); flex: none;
}
.icon-btn:active { transform: scale(.94); }

.manual input, .search, .field textarea, .quiz-input, .tag-input {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 1rem; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.manual input:focus, .search:focus, .field textarea:focus, .quiz-input:focus, .tag-input:focus, .note-input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent);
}
.input-icon { position: relative; flex: 1; min-width: 0; }
.input-icon .ico { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon input { padding-left: 40px; }

.check { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }

/* ============ 掃描 ============ */
.hero {
  position: relative; overflow: hidden; border-radius: 24px; padding: 22px 18px 18px;
  background: linear-gradient(140deg, var(--primary) 0%, var(--primary-2) 55%, #ec4899 120%);
  color: #fff; box-shadow: var(--shadow-lg);
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; border-radius: 50%;
  background: rgba(255,255,255,.12);
}
.hero-text { position: relative; z-index: 1; margin-bottom: 16px; }
.hero h2 { margin: 0 0 4px; font-size: 1.35rem; letter-spacing: -.3px; }
.hero p { margin: 0; opacity: .85; font-size: .92rem; }
.scan-actions { position: relative; z-index: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.big-btn { padding: 16px; font-size: 1.05rem; font-weight: 600; border-radius: 14px; }
.hero .btn.primary { background: #fff; color: var(--primary); box-shadow: 0 10px 24px -10px rgba(0,0,0,.35); }
.hero .btn.ghost { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.35); color: #fff; box-shadow: none; }
.hero .scan-opt { position: relative; z-index: 1; margin-top: 14px; font-size: .85rem; opacity: .95; }
.hero .check input { accent-color: #fff; }

.manual { display: flex; gap: 8px; margin-top: 16px; }
.status { color: var(--muted); font-size: .92rem; margin: 12px 2px; min-height: 1em; }
.status:empty { margin: 4px 0; }

.ocr-tools { display: grid; gap: 10px; margin: 4px 0 8px; }
.tools-row { display: flex; gap: 8px; align-items: stretch; }
.tools-row .seg { flex: 1; }

.crop-stage { display: grid; gap: 10px; }
.crop-wrap {
  position: relative; border-radius: var(--radius); overflow: hidden; background: #000; box-shadow: var(--shadow);
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: crosshair;
}
.crop-wrap canvas { display: block; width: 100%; height: auto; }
.crop-sel {
  position: absolute; border: 2px solid #fff; border-radius: 4px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.5), 0 0 0 1px rgba(0,0,0,.4) inset; pointer-events: none;
}
.crop-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.crop-actions #cropGo { margin-left: auto; padding-inline: 22px; }
.seg {
  display: grid; grid-template-columns: 1fr 1fr; padding: 4px; gap: 4px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 14px;
}
.seg button { border: 0; background: transparent; color: var(--muted); padding: 9px; font-weight: 600; border-radius: 10px; cursor: pointer; }
.seg button.on { background: var(--card); color: var(--primary); box-shadow: var(--shadow-sm); }
.multi-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.level-select { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: .88rem; }

.ocr-stage { position: relative; margin-top: 8px; border-radius: var(--radius); overflow: hidden; background: #000; box-shadow: var(--shadow); }
.ocr-stage img { display: block; width: 100%; height: auto; }
.ocr-box {
  position: absolute; border: 2px solid rgba(91,75,219,.9); background: rgba(91,75,219,.12);
  border-radius: 5px; cursor: pointer; padding: 0; transition: background .15s ease;
}
/* 片語：雙線框，和單字區分 */
.ocr-box.phrase { border-style: double; border-width: 3px; }
.ocr-box.saved { border-color: rgba(22,163,106,.95); background: rgba(22,163,106,.2); }
.ocr-box.low { border-style: dashed; opacity: .6; }
.ocr-box.active { background: rgba(255,196,0,.35); border-color: #f0b400; }
.ocr-box.picked { border-color: #f0b400; background: rgba(255,196,0,.45); box-shadow: 0 0 0 2px rgba(240,180,0,.35); }
.ocr-zh { position: absolute; border: 2px solid var(--pink); background: var(--pink-soft); border-radius: 5px; pointer-events: none; }
.ocr { color: var(--pink) !important; }

#view-scan, #view-words { padding-bottom: 72px; }
.action-bar {
  position: fixed; z-index: 9; left: 12px; right: 12px; max-width: 696px; margin: 0 auto;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg);
  animation: rise .2s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.action-bar > span { flex: 1; font-weight: 700; min-width: 5em; }

/* ============ 面板（bottom sheet）============ */
.backdrop { position: fixed; inset: 0; background: rgba(12,10,30,.45); z-index: 20; backdrop-filter: blur(2px); animation: fadein .2s ease; }
@keyframes fadein { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 24px 24px 0 0; padding: 8px 18px calc(18px + env(safe-area-inset-bottom, 0px));
  max-width: 720px; margin: 0 auto; box-shadow: 0 -12px 40px rgba(12,10,30,.25);
  animation: sheetup .25s cubic-bezier(.2,.8,.2,1);
}
@keyframes sheetup { from { transform: translateY(40px); opacity: .6; } }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.sheet-title { flex: 1; margin: 0; font-size: 1.2rem; }
.sheet-word { flex: 1; font-size: 1.8rem; font-weight: 800; letter-spacing: -.5px; border: 0; background: transparent; color: var(--text); padding: 2px 0; min-width: 0; outline: none; }
.phonetic { color: var(--muted); margin-bottom: 10px; min-height: 1.2em; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; font-size: .78rem; }
.meta:empty { display: none; }
.tag { background: var(--primary-soft); color: var(--primary); border-radius: 999px; padding: 3px 10px; font-weight: 500; }
.stars { color: var(--warn); letter-spacing: 1px; align-self: center; }
.forms { width: 100%; color: var(--muted); }
.link-btn { border: 0; background: none; color: var(--primary); font: inherit; font-weight: 600; padding: 0 4px; cursor: pointer; text-decoration: underline; }
.lemma-btn { border: 1px solid var(--primary); color: var(--primary); background: transparent; border-radius: 999px; padding: 3px 10px; font: inherit; font-weight: 600; cursor: pointer; }
.field { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 12px; letter-spacing: .3px; }
.field textarea, .field .tag-input { margin-top: 6px; resize: vertical; font-weight: 400; letter-spacing: 0; }
.field textarea { background: var(--card-2); }
.source { margin-bottom: 12px; font-style: italic; }
.sheet-actions { display: flex; gap: 8px; position: sticky; bottom: 0; padding-top: 8px; background: var(--card); }
.sheet-actions .primary { flex: 1; }

.sheet.confirm { text-align: center; }
.sheet.confirm .sheet-title { margin: 6px 0; }
.sheet.confirm .sheet-actions > .btn { flex: 1; }
.confirm-icon {
  width: 52px; height: 52px; border-radius: 50%; margin: 6px auto 4px; display: grid; place-items: center;
  background: var(--bad-soft); color: var(--bad); font-size: 1.6rem; font-weight: 800;
}

.batch-list { list-style: none; padding: 0; margin: 12px 0; }
.batch-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.batch-row > input[type=checkbox] { width: 20px; height: 20px; margin-top: 6px; flex: none; accent-color: var(--primary); }
.batch-row .main { flex: 1; min-width: 0; }
.batch-row .w { font-weight: 700; font-size: 1.05rem; }
.batch-row .m { color: var(--muted); font-size: .86rem; white-space: pre-line; margin-top: 2px; }
.batch-row.off .main { opacity: .45; }
.w-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.note-input {
  flex: 1; min-width: 8em; padding: 7px 11px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text); font-size: .92rem; outline: none;
}
.note-input.ocr { border-color: var(--pink); background: var(--pink-soft); }
.note { font-size: .72rem; color: var(--warn); background: var(--warn-soft); border-radius: 6px; padding: 1px 6px; margin-left: 4px; font-weight: 600; }

/* ============ 標籤 ============ */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px;
  padding: 8px 14px; cursor: pointer; font-size: .92rem; font-weight: 500; box-shadow: var(--shadow-sm);
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); box-shadow: 0 6px 14px -6px color-mix(in srgb, var(--primary) 80%, transparent); }
.tag-filter {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; margin: 0 -18px 8px; padding-inline: 18px;
  scrollbar-width: none; -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 24px), transparent);
          mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 24px), transparent);
}
.tag-filter::-webkit-scrollbar { display: none; }
.tag-filter:empty { display: none; }
.tag-filter .chip { flex: none; white-space: nowrap; padding: 6px 13px; font-size: .84rem; }
.tag-filter .chip small { opacity: .65; margin-left: 4px; font-weight: 600; }
.tag-filter .multi { border-style: dashed; background: transparent; box-shadow: none; }
.tag-filter .multi.on { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); box-shadow: none; }
.tag-quick { margin: -4px 0 12px; }
.tag-quick .chip { padding: 5px 11px; font-size: .8rem; box-shadow: none; background: var(--card-2); }
.wtag {
  display: inline-block; font-size: .68rem; font-weight: 600; color: var(--primary); background: var(--primary-soft);
  border-radius: 999px; padding: 1px 8px; margin-right: 4px; vertical-align: 2px;
}

/* ============ 單字本 ============ */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.stat {
  background: var(--card); border-radius: 16px; padding: 12px 6px; text-align: center; box-shadow: var(--shadow-sm);
  border: 1px solid var(--line); position: relative; overflow: hidden;
}
.stat::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: var(--c, var(--primary)); }
.stat:nth-child(1) { --c: var(--primary); }
.stat:nth-child(2) { --c: var(--bad); }
.stat:nth-child(3) { --c: var(--good); }
.stat:nth-child(4) { --c: var(--warn); }
.stat b { display: block; font-size: 1.45rem; font-weight: 800; letter-spacing: -.5px; color: var(--c); }
.stat span { font-size: .72rem; color: var(--muted); font-weight: 500; }

.list-tools { display: flex; gap: 8px; }
.list-tools .btn { flex: none; }
#selectBtn.on { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

.word-list { list-style: none; padding: 0; margin: 14px 0 0; }
.word-item {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-sm);
  padding: 13px 16px; margin-bottom: 9px; display: flex; gap: 12px; align-items: center; cursor: pointer;
  transition: transform .12s ease, box-shadow .2s ease, border-color .15s ease;
}
.word-item:active { transform: scale(.985); }
.word-item .main { flex: 1; min-width: 0; }
.word-item .w { font-weight: 700; font-size: 1.08rem; letter-spacing: -.2px; }
.word-item .w .muted { font-weight: 400; letter-spacing: 0; }
.word-item .m { color: var(--muted); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.wnote {
  margin-top: 6px; padding: 4px 10px; border-radius: 8px; font-size: .84rem;
  background: var(--pink-soft); color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wnote span { color: var(--pink); font-weight: 700; font-size: .72rem; margin-right: 6px; }
.wnote.full-note { white-space: pre-line; text-align: left; font-size: .92rem; padding: 8px 12px; margin-top: 10px; }
.word-item .due {
  font-size: .72rem; color: var(--muted); white-space: nowrap; background: var(--card-2);
  border-radius: 999px; padding: 3px 9px; font-weight: 600;
}
.word-item .due.now { color: var(--bad); background: var(--bad-soft); }
.word-item .tick {
  width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line); flex: none;
  display: grid; place-items: center; color: transparent; transition: all .15s ease;
}
.word-item .tick .ico { width: 14px; height: 14px; stroke-width: 3; }
.word-item.sel { border-color: var(--primary); background: color-mix(in srgb, var(--primary-soft) 55%, var(--card)); }
.word-item.sel .tick { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ============ 復習卡 ============ */
.progress { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .84rem; font-weight: 600; margin-bottom: 10px; }
.card {
  position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 24px;
  padding: 30px 22px; text-align: center; min-height: 280px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; justify-content: center; gap: 10px; overflow: hidden;
}
.card::before {
  content: ""; position: absolute; inset: 0 0 auto; height: 6px;
  background: linear-gradient(90deg, var(--primary), var(--primary-2), #ec4899);
}
.card .big { font-size: 2.4rem; font-weight: 800; letter-spacing: -1px; word-break: break-word; }
.card .zh { font-size: 1.12rem; font-weight: 500; white-space: pre-line; line-height: 1.6; }
.card .en { color: var(--muted); font-size: .88rem; white-space: pre-line; text-align: left; background: var(--card-2); border-radius: 12px; padding: 10px 12px; }
.card .ex { font-style: italic; color: var(--muted); font-size: .9rem; }
.card .icon-btn { vertical-align: middle; margin-left: 4px; }
#rvBack { display: grid; gap: 10px; margin-top: 6px; padding-top: 14px; border-top: 1px dashed var(--line); }
.grade { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.grade .btn { flex-direction: column; gap: 2px; padding: 12px 4px; font-size: .95rem; font-weight: 700; box-shadow: none; }
.grade .btn small { opacity: .75; font-size: .7rem; font-weight: 500; }
.grade .again { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.grade .hard { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.grade .good { background: var(--good-soft); border-color: transparent; color: var(--good); }
.grade .easy { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.full { width: 100%; margin-top: 14px; padding: 14px; font-size: 1.02rem; }

/* ============ 測驗 ============ */
.setup { display: grid; gap: 16px; background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 18px; box-shadow: var(--shadow-sm); }
.setup .full { margin-top: 0; }
.listen-btn { width: 76px; height: 76px; border-radius: 50%; margin: 0 auto 6px; font-size: 2rem; background: var(--primary-soft); color: var(--primary); }
.options { display: grid; gap: 9px; margin-top: 14px; }
.options .btn { justify-content: flex-start; text-align: left; padding: 15px 18px; white-space: normal; border-radius: 14px; }
.options .btn.correct { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.options .btn.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.quiz-input { margin-top: 14px; text-align: center; font-size: 1.35rem; font-weight: 600; letter-spacing: .5px; }
.quiz-input.correct { border-color: var(--good); background: var(--good-soft); }
.quiz-input.wrong { border-color: var(--bad); background: var(--bad-soft); }
.feedback { margin-top: 12px; font-weight: 700; min-height: 1.4em; text-align: center; }
.feedback.ok { color: var(--good); }
.feedback.no { color: var(--bad); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .big { font-size: 3.2rem; margin-bottom: 6px; }
h3 { font-size: 1rem; margin: 22px 2px 10px; }

/* ============ 統計 ============ */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; box-shadow: var(--shadow-sm); }
.kpi .label { font-size: .8rem; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 1.9rem; font-weight: 700; letter-spacing: -.5px; line-height: 1.15; margin-top: 2px; }
.kpi .value small { font-size: .9rem; font-weight: 500; color: var(--muted); margin-left: 3px; letter-spacing: 0; }
.kpi .sub { font-size: .75rem; color: var(--muted); }

.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 16px 16px 12px; box-shadow: var(--shadow-sm); margin-bottom: 14px; }
.chart-card h3 { margin: 0; font-size: 1rem; }
.chart-card > p, .chart-head p { margin: 2px 0 0; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.seg-sm { grid-template-columns: repeat(3, auto); padding: 3px; border-radius: 11px; }
.seg-sm button { padding: 5px 10px; font-size: .78rem; border-radius: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 12px 0 2px; font-size: .8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart { position: relative; margin-top: 8px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font-family: var(--font); font-size: 10px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover, .chart .hit.on { fill: color-mix(in srgb, var(--primary) 8%, transparent); }
.chart .val { fill: var(--text); font-weight: 600; }
.chart-tip {
  position: fixed; z-index: 40; pointer-events: none; background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 11px; box-shadow: var(--shadow-lg); font-size: .8rem; min-width: 110px;
}
.chart-tip .t { color: var(--muted); font-size: .72rem; margin-bottom: 3px; }
.chart-tip .row { display: flex; align-items: center; gap: 7px; }
.chart-tip .row b { font-size: .92rem; min-width: 1.5em; }
.chart-tip .key { width: 12px; height: 2px; border-radius: 1px; }
.table-view { margin-top: 8px; font-size: .8rem; }
.table-view summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.table-view table { width: 100%; border-collapse: collapse; margin-top: 6px; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { padding: 4px 6px; text-align: right; border-bottom: 1px solid var(--line); }
.table-view th:first-child, .table-view td:first-child { text-align: left; }
.table-view .scroll { max-height: 220px; overflow: auto; }
.tag-bars { display: grid; gap: 14px; margin-top: 12px; }
.tag-row .top { display: flex; justify-content: space-between; gap: 8px; font-size: .86rem; margin-bottom: 5px; }
.tag-row .top b { font-weight: 600; }
.tag-row .top span { color: var(--muted); font-size: .76rem; }
.stack { display: flex; gap: 2px; height: 14px; }
.stack i { display: block; height: 100%; min-width: 3px; cursor: pointer; }
.stack i:last-child { border-radius: 0 4px 4px 0; }
.stack i:hover { filter: brightness(1.12); }

/* ============ 設定 ============ */
.set-section { padding: 14px 0 16px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.set-section:first-of-type { border-top: 0; padding-top: 4px; }
.set-section h3 { margin: 0; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.set-section h3 .ico { color: var(--primary); }
.set-section p { margin: 0; }
.set-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.set-grid .btn { padding: 11px 6px; font-size: .9rem; white-space: normal; }
.set-section .full { margin-top: 0; }
.file-btn { cursor: pointer; }
.pin-form { display: grid; gap: 8px; }
.pin-form input, .login-card input {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--card-2); color: var(--text); font-size: 1rem; outline: none;
}
.pin-form input:focus, .login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent); }
.backup-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 260px; overflow-y: auto; }
.backup-list li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px; background: var(--card-2); }
.backup-list .info { flex: 1; min-width: 0; }
.backup-list .name { font-size: .82rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.backup-list .sub { font-size: .74rem; color: var(--muted); }
.backup-list .kind { font-size: .68rem; font-weight: 700; border-radius: 6px; padding: 1px 6px; background: var(--primary-soft); color: var(--primary); margin-right: 4px; }

/* ============ 登入 ============ */
.login {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px;
  background: var(--bg-grad), var(--bg);
}
.login-card {
  width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 26px;
  padding: 28px 22px 22px; box-shadow: var(--shadow-lg); display: grid; gap: 12px; text-align: center;
}
.login-card h2 { margin: 4px 0 0; font-size: 1.3rem; }
.login-card p { margin: 0; }
.login-card input { text-align: center; font-size: 1.3rem; letter-spacing: 6px; }
.login-card input::placeholder { letter-spacing: normal; font-size: 1rem; }
.login-card .full { margin-top: 4px; }
.brand.big { width: 64px; height: 64px; border-radius: 20px; font-size: 1.6rem; margin: 0 auto; }
.login-error { color: var(--bad); font-weight: 600; font-size: .9rem; min-height: 1.3em; }

/* ============ 底部分頁列 ============ */
.tabbar {
  position: fixed; z-index: 10; left: 12px; right: 12px; max-width: 520px; margin: 0 auto;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  display: grid; grid-template-columns: repeat(5, 1fr); padding: 6px;
  background: color-mix(in srgb, var(--card) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow-lg);
}
.tabbar button {
  border: 0; background: transparent; padding: 7px 0 6px; cursor: pointer; border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted);
  transition: color .15s ease, background .2s ease; -webkit-tap-highlight-color: transparent;
}
.tabbar .ico { width: 22px; height: 22px; }
.tabbar button span { font-size: .7rem; font-weight: 600; }
.tabbar button.active { color: var(--primary); background: var(--primary-soft); }

.toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: #1c1a33; color: #fff; padding: 11px 18px; border-radius: 16px; z-index: 30; font-size: .9rem;
  width: max-content; max-width: min(90vw, 480px); text-align: center; word-break: break-all;
  box-shadow: var(--shadow-lg); animation: rise .2s ease;
}
