:root {
  --brand: #008078;
  --brand-soft: rgba(0, 128, 120, .10);
  --bg: #ffffff;
  --bg2: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --text2: #6e6e73;
  --line: #d9d9de;
  --gray5: #e5e5ea;
  --gray6: #f2f2f7;
  --red: #e5484d;
  --yellow: #e8b100;
  --green: #30a46c;
  --blue: #2f7de1;
  --orange: #f08a24;
  --gold: #fbbf3c;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #4dccb8; --brand-soft: rgba(77,204,184,.16);
    --bg: #000; --bg2: #1c1c1e; --card: #1c1c1e; --text: #f2f2f7; --text2: #a1a1a6;
    --line: #38383a; --gray5: #2c2c2e; --gray6: #1c1c1e; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #4dccb8; --brand-soft: rgba(77,204,184,.16);
  --bg: #000; --bg2: #1c1c1e; --card: #1c1c1e; --text: #f2f2f7; --text2: #a1a1a6;
  --line: #38383a; --gray5: #2c2c2e; --gray6: #1c1c1e; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; opacity: .45; }
input[type=text], input[type=password], input[type=number], input:not([type]), select, textarea {
  background: var(--gray6); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%;
  font-size: 16px; /* 避免 iOS 自動放大 */
}
textarea { resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
a { color: var(--brand); }

#app { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
.topbar {
  display: grid; grid-template-columns: 64px 1fr 64px; align-items: center;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { display: block; font-size: 12px; font-weight: 400; color: var(--text2); text-align: center; }
.topbar .left, .topbar .right { display: flex; gap: 4px; }
.topbar .right { justify-content: flex-end; }
.iconbtn { width: 40px; height: 40px; border-radius: 20px; display: grid; place-items: center; color: var(--brand); font-size: 20px; }
.iconbtn:hover { background: var(--brand-soft); }
.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: 16px; }
.tabbar {
  display: flex; justify-content: center; gap: 48px; border-top: 1px solid var(--line); background: var(--bg);
  padding: 6px 0 calc(env(safe-area-inset-bottom) + 6px);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--text2); min-width: 64px; gap: 2px; }
.tabbar button.on { color: var(--brand); }
.tabbar svg { width: 24px; height: 24px; }

.section-title { font-size: 13px; color: var(--text2); padding: 16px 16px 6px; margin: 0; font-weight: 500; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--line);
  width: 100%; text-align: left; min-height: 48px;
}
button.row:hover, .row.click:hover { background: var(--gray6); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-size: 16px; }
.row .meta { font-size: 12px; color: var(--text2); }
.row .num { font-variant-numeric: tabular-nums; color: var(--text2); font-size: 13px; min-width: 30px; text-align: right; }
.trunc { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deck-icon { color: var(--brand); font-size: 22px; width: 26px; text-align: center; }

.actionbar { display: flex; justify-content: center; gap: 56px; padding: 8px 0; border-top: 1px solid var(--line); background: var(--bg2); }
.actionbar button { display: flex; flex-direction: column; align-items: center; color: var(--brand); font-size: 12px; gap: 2px; }
.actionbar svg { width: 26px; height: 26px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--brand); color: var(--brand); border-radius: 999px; padding: 5px 13px; font-size: 13px; white-space: nowrap;
}
.chip.on { background: var(--brand); color: #fff; }
:root[data-theme="dark"] .chip.on { color: #000; }

.btn {
  display: block; width: 100%; padding: 12px; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 600; font-size: 15px; text-align: center;
}
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.gray { background: #8e8e93; }
.btn.red { background: var(--red); }
.btn.orange { background: var(--orange); }
.btn.small { display: inline-block; width: auto; padding: 7px 14px; font-size: 14px; }
.btn:disabled { background: var(--gray5); color: var(--text2); opacity: 1; }
.btnrow { display: flex; gap: 8px; }
.btnrow .btn { flex: 1; }
.link { color: var(--brand); font-size: 14px; }
.danger { color: var(--red); }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.f0 { background: var(--red); } .f1 { background: var(--yellow); } .f2 { background: var(--green); } .f3 { background: var(--blue); }
.star { font-size: 20px; color: var(--text2); width: 32px; height: 32px; display: grid; place-items: center; }
.star.on { color: var(--gold); }
.accent { font-size: 11px; border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; color: var(--text2); }
.accent:hover { border-color: var(--brand); color: var(--brand); }
.accent.big { font-size: 14px; padding: 6px 12px; }

/* 單字卡 */
.wordcard { display: flex; flex-direction: column; gap: 10px; }
.wordcard .head { display: flex; align-items: center; gap: 8px; }
.wordcard .head .w { font-size: 26px; font-weight: 500; flex: 1; word-break: break-word; }
.kk { color: var(--text2); font-size: 15px; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--gray5); color: var(--text2); }
.pill.brand { background: var(--brand); color: #fff; }
.pill.note { background: var(--brand-soft); color: var(--brand); min-width: 52px; text-align: center; }
.pill.anti { background: rgba(48,164,108,.16); color: var(--green); }
.sense-head { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.bullet { display: flex; gap: 8px; font-size: 15px; }
.bullet::before { content: "•"; }
.sent { display: flex; gap: 8px; align-items: flex-start; font-size: 15px; }
.sent::before { content: "•"; }
.sent span { flex: 1; }
.sent.zh { color: var(--text2); }
mark { background: none; color: var(--brand); font-weight: 600; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2px 0; width: 100%; }
.speak { color: var(--text2); font-size: 16px; }
.speak:hover { color: var(--brand); }

.progressbar { height: 4px; background: var(--gray5); }
.progressbar > div { height: 100%; background: var(--brand); transition: width .25s; }
.pager-nav { display: flex; justify-content: space-between; padding: 8px 16px calc(env(safe-area-inset-bottom) + 8px); }
.circle { width: 44px; height: 44px; border-radius: 22px; background: var(--gray6); display: grid; place-items: center; font-size: 18px; }

/* 表單區塊 */
.group { background: var(--card); border-radius: 12px; margin: 0 16px; overflow: hidden; border: 1px solid var(--line); }
.group .row:last-child { border-bottom: 0; }
.formrow { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.formrow:last-child { border-bottom: 0; }
.formrow label { flex: 1; }
.check { width: 22px; height: 22px; border: 2px solid var(--brand); border-radius: 5px; flex: none; display: grid; place-items: center; color: #fff; font-size: 14px; }
.check.on { background: var(--brand); }
.numfield { width: 64px !important; text-align: center; padding: 5px 4px !important; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--gray5); border-radius: 15px; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 26px; height: 26px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(20px); }

.modes { display: flex; gap: 10px; overflow-x: auto; padding: 12px 16px; }
.mode { flex: none; width: 78px; height: 70px; border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 12px; color: var(--text2); }
.mode .ic { font-size: 22px; }
.mode.on { border: 2px solid var(--brand); color: var(--brand); }
.seg { display: flex; background: var(--gray5); border-radius: 9px; padding: 2px; margin: 0 16px 8px; }
.seg button { flex: 1; padding: 6px; border-radius: 7px; font-size: 14px; }
.seg button.on { background: var(--card); box-shadow: var(--shadow); font-weight: 600; }

/* 複習 */
.session { display: flex; flex-direction: column; height: 100%; }
.session .cardbox { flex: 1; margin: 0 16px; border: 1px solid var(--line); border-radius: 10px; overflow-y: auto; padding: 20px 16px; position: relative; }
.session .cardbox.revealed::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 5px; background: var(--brand); border-radius: 10px 10px 0 0; }
.center { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding-top: 70px; }
.big-word { font-size: 32px; font-weight: 500; }
.blank { width: 200px !important; text-align: center; }
.ok { color: var(--green); } .bad { color: var(--red); }
.speakbig { width: 72px; height: 72px; border-radius: 36px; background: var(--brand); color: #fff; font-size: 30px; display: grid; place-items: center; }

/* 測驗 */
.option { display: flex; align-items: center; gap: 14px; padding: 12px; border: 1.2px solid var(--line); border-radius: 10px; width: 100%; text-align: left; }
.option .letter { width: 30px; height: 30px; border-radius: 15px; background: var(--gray6); display: grid; place-items: center; flex: none; }
.option.picked { border-color: var(--brand); background: var(--brand-soft); }
.option.picked .letter { background: var(--brand); color: #fff; }
.option.right { border-color: var(--green); background: rgba(48,164,108,.12); }
.option.wrong { border-color: var(--red); background: rgba(229,72,77,.12); }
.option.crossed .txt { text-decoration: line-through; color: var(--text2); }
.option .txt { flex: 1; }
.bubbles { display: flex; gap: 10px; overflow-x: auto; padding: 10px 12px; }
.bubble { flex: none; width: 40px; height: 40px; border-radius: 20px; background: var(--gray5); position: relative; font-variant-numeric: tabular-nums; }
.bubble.done { background: var(--brand); color: #fff; }
.bubble.cur { outline: 2px solid var(--text); outline-offset: 3px; }
.bubble.r { background: rgba(48,164,108,.3); color: var(--text); }
.bubble.w { background: rgba(229,72,77,.3); color: var(--text); }
.bubble .flag { position: absolute; top: -4px; right: -4px; font-size: 11px; }
.qprompt { font-size: 20px; line-height: 1.8; letter-spacing: .3px; }
.examfoot { border-top: 1px solid var(--line); padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px); display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; }
.examfoot .submit { justify-self: center; padding: 10px 30px; border-radius: 999px; background: var(--brand); color: #fff; font-weight: 600; }
.examfoot .submit:disabled { background: var(--gray5); color: var(--text2); opacity: 1; }
.starq { display: inline-flex; gap: 6px; align-items: center; font-size: 15px; color: var(--brand); padding: 6px 0; }
.starq.on { color: var(--orange); }

.mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; white-space: pre-wrap; background: var(--gray6); border-radius: 8px; padding: 10px; word-break: break-word; }
.hint { font-size: 14px; color: var(--text2); }
.warn { font-size: 12px; color: var(--orange); }

/* 進度 */
.welcome { font-size: 28px; font-weight: 700; margin: 8px 16px 4px; }
.cardx { background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin: 12px 16px; padding: 16px; }
.cardx h3 { margin: 0 0 12px; font-size: 17px; display: flex; justify-content: space-between; align-items: center; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { background: var(--gray6); border-radius: 10px; padding: 12px 8px; text-align: center; }
.tile .n { font-size: 24px; font-weight: 700; color: var(--brand); }
.tile .l { font-size: 12px; color: var(--text2); }
.week { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; gap: 4px; }
.week .d { font-size: 12px; color: var(--text2); }
.week .b { font-size: 22px; filter: grayscale(1); opacity: .3; }
.week .b.on { filter: none; opacity: 1; }
.chart svg { width: 100%; height: 170px; display: block; }
.chart .legend { font-size: 12px; color: var(--text2); display: flex; justify-content: space-between; margin-bottom: 6px; }

/* 登入 */
.login { max-width: 360px; margin: 0 auto; padding: 14vh 24px 24px; display: flex; flex-direction: column; gap: 14px; }
.login img { width: 84px; height: 84px; border-radius: 20px; align-self: center; }
.login h1 { text-align: center; margin: 0 0 10px; font-size: 24px; }
.err { color: var(--red); font-size: 14px; min-height: 20px; }

#toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 60px); transform: translateX(-50%) translateY(-20px);
  background: var(--card); color: var(--text); border-left: 4px solid var(--brand); box-shadow: 0 4px 16px rgba(0,0,0,.18);
  padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; max-width: calc(100vw - 32px); z-index: 10;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { border-left-color: var(--red); }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 9; padding: 16px; }
.modal { background: var(--card); border-radius: 14px; padding: 18px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.modal h3 { margin: 0; text-align: center; font-size: 17px; }
.modal p { margin: 0; text-align: center; color: var(--text2); font-size: 14px; }
.empty { text-align: center; color: var(--text2); padding: 48px 16px; }
.small { font-size: 12px; }
.muted { color: var(--text2); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.spacer { flex: 1; }
@media (max-width: 380px) { .tabbar { gap: 24px; } }
