:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --soft: #f1efea;
  --line: #e7e4dd;
  --ink: #141413;
  --ink2: #4a4843;
  --mute: #8d8a82;
  --hl: #fff0a6;
  --accent: #141413;
  --good: #2f7d4f;
  --good-bg: #e6f3ea;
  --bad: #b3412e;
  --bad-bg: #f9e7e3;
  --warn: #c98a12;
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans Devanagari", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413; --card: #1d1d1b; --soft: #252522; --line: #33322e;
    --ink: #f3f1ea; --ink2: #c9c6bd; --mute: #8f8c84; --hl: #5c4e12; --accent: #f3f1ea;
    --good: #6cc48f; --good-bg: #1e3326; --bad: #ee8a76; --bad-bg: #3a221d;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.45; }
body { min-height: 100dvh; overscroll-behavior-y: none; overflow-x: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- chrome ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 10px) 20px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.brand { font-family: var(--serif); font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.brand-dot { color: var(--warn); }
.sync { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--mute); padding: 6px 10px; border: 1px solid var(--line); border-radius: 99px; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--mute); }
.sync.ok .sync-dot { background: var(--good); }
.sync.err .sync-dot { background: var(--bad); }
.sync.busy .sync-dot { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.view { padding: 6px 18px calc(96px + var(--safe-b)); max-width: 680px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 6px 8px calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; color: var(--mute); font-size: 11px; font-weight: 500; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.on { color: var(--ink); }

/* ---------- type ---------- */
.label { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--mute); }
.h1 { font-family: var(--serif); font-size: 34px; line-height: 1.08; letter-spacing: -0.02em; margin: 10px 0 6px; font-weight: 500; }
.h1 em { font-style: italic; }
.h2 { font-family: var(--serif); font-size: 22px; margin: 0; font-weight: 500; letter-spacing: -0.01em; }
.muted { color: var(--mute); }
.small { font-size: 13px; }
.hi { font-family: var(--sans); }
mark { background: var(--hl); color: inherit; padding: 0 4px; border-radius: 4px; }

/* ---------- cards & buttons ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 14px; font-weight: 600; background: var(--accent); color: var(--bg); width: 100%; }
.btn:active { transform: scale(.98); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.soft { background: var(--soft); color: var(--ink); }
.btn.sm { min-height: 38px; padding: 0 14px; font-size: 14px; width: auto; border-radius: 11px; }
.btn[disabled] { opacity: .4; pointer-events: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; flex: none; background: var(--card); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.icon-btn.on svg { fill: currentColor; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; margin: 0 -18px; padding-left: 18px; padding-right: 18px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); font-size: 14px; white-space: nowrap; }
.chip b { font-family: var(--mono); font-weight: 400; font-size: 11px; color: var(--mute); margin-left: 4px; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.on b { color: inherit; opacity: .7; }
.tag { display: inline-block; font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; background: var(--soft); padding: 5px 9px; border-radius: 7px; color: var(--ink2); }
.pill { font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; padding: 3px 7px; border-radius: 6px; }
.pill.new { background: var(--soft); color: var(--mute); }
.pill.learning { background: #fdf0d5; color: #8a5a00; }
.pill.review { background: #e4eefb; color: #2b5797; }
.pill.mastered { background: var(--good-bg); color: var(--good); }
@media (prefers-color-scheme: dark) {
  .pill.learning { background: #3b2e10; color: #f0c46a; }
  .pill.review { background: #1b2a40; color: #8fb6ee; }
}

/* ---------- today ---------- */
.hero { padding: 14px 0 6px; }
.stats3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.stat .n { font-family: var(--serif); font-size: 30px; line-height: 1; }
.stat .l { margin-top: 6px; }
.note { font-size: 13px; color: var(--ink2); background: var(--soft); border-radius: 12px; padding: 10px 12px; }

/* ---------- session ---------- */
.progress { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ink); border-radius: 4px; transition: width .3s; }
.sess-top { display: flex; align-items: center; gap: 12px; margin: 6px 0 14px; }
.sess-top .progress { flex: 1; }
.fc { min-height: 300px; display: flex; flex-direction: column; }
.fc .prompt { font-family: var(--serif); font-size: 23px; line-height: 1.38; margin: 14px 0; letter-spacing: -0.005em; }
.fc .prompt.hi { font-family: var(--sans); font-size: 19px; line-height: 1.55; }
.blank { display: inline-block; min-width: 72px; border-bottom: 2px solid var(--ink); color: var(--mute); text-align: center; font-family: var(--mono); font-size: .75em; line-height: 1.2; padding: 0 4px; }
.blank.fill { color: var(--good); border-color: var(--good); font-family: var(--serif); font-size: 1em; font-weight: 600; }
.hint { font-size: 15px; color: var(--ink2); border-left: 3px solid var(--hl); padding: 4px 0 4px 10px; }
.answer-word { font-family: var(--serif); font-size: 40px; line-height: 1.05; letter-spacing: -0.02em; font-weight: 500; }
.meta { font-size: 14px; color: var(--mute); }
.meta i { font-family: var(--serif); }
.mean { background: var(--soft); border-radius: 14px; padding: 12px 14px; font-size: 17px; }
.grades { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.grade { border-radius: 14px; padding: 10px 4px; border: 1px solid var(--line); background: var(--card); text-align: center; }
.grade b { display: block; font-size: 15px; }
.grade span { font-family: var(--mono); font-size: 11px; color: var(--mute); }
.grade.g0 b { color: var(--bad); }
.grade.g3 b { color: var(--good); }
.grade.rec { outline: 2px solid var(--ink); outline-offset: -1px; }
.opts { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.opt { text-align: left; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-family: var(--serif); font-size: 19px; }
.opt.right { background: var(--good-bg); border-color: var(--good); }
.opt.wrong { background: var(--bad-bg); border-color: var(--bad); }
.opt[disabled] { cursor: default; }
.type-in { display: flex; gap: 8px; }
.type-in input { flex: 1; min-width: 0; min-height: 50px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); padding: 0 14px; font-size: 18px; outline: none; }
.type-in input:focus { border-color: var(--ink); }
.verdict { font-weight: 600; padding: 10px 14px; border-radius: 12px; }
.verdict.ok { background: var(--good-bg); color: var(--good); }
.verdict.no { background: var(--bad-bg); color: var(--bad); }
.verdict.meh { background: #fdf0d5; color: #8a5a00; }
.linkish { color: var(--ink2); text-decoration: underline; text-underline-offset: 3px; font-size: 14px; }

/* ---------- words ---------- */
.search { width: 100%; min-height: 46px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); padding: 0 14px; font-size: 16px; outline: none; }
.wlist { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.wrow { display: flex; align-items: center; gap: 12px; text-align: left; width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.wrow .w { font-family: var(--serif); font-size: 20px; }
.wrow .m { font-size: 13.5px; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wrow .txt { flex: 1; min-width: 0; }

/* ---------- sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.35); animation: fade .2s; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92dvh; overflow-y: auto; background: var(--bg); border-radius: 22px 22px 0 0; padding: 10px 18px calc(24px + var(--safe-b)); animation: up .25s cubic-bezier(.2,.8,.2,1); max-width: 680px; margin: 0 auto; }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 12px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.sec { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.sec .label { margin-bottom: 8px; display: block; }
.sec .label.warm { color: var(--warn); }
.ex { border-left: 2px solid var(--line); padding-left: 12px; }
.ex p { margin: 0 0 8px; }
.ex .lng { font-family: var(--mono); font-size: 10px; background: var(--soft); padding: 2px 5px; border-radius: 4px; color: var(--mute); margin-right: 6px; }
.usage { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 15px; }
.usage dt { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--mute); padding-top: 3px; }
.usage dd { margin: 0; }
.kv { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; text-align: center; }
.kv div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 4px; }
.kv b { display: block; font-family: var(--serif); font-size: 18px; font-weight: 500; }
.kv span { font-size: 11px; color: var(--mute); }
.field { display: grid; gap: 6px; }
.field input, .field textarea, .field select { width: 100%; border-radius: 12px; border: 1px solid var(--line); background: var(--card); padding: 12px; font-size: 16px; outline: none; }
.field textarea { min-height: 70px; resize: vertical; }

/* ---------- progress ---------- */
.bars { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; align-items: end; height: 110px; }
.bars div { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; }
.bars i { display: block; width: 100%; background: var(--ink); border-radius: 6px 6px 3px 3px; min-height: 3px; }
.bars span { font-family: var(--mono); font-size: 10px; color: var(--mute); }
.bars em { font-style: normal; font-size: 11px; color: var(--ink2); }
.catbar { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 14px; }
.catbar .track { grid-column: 1 / -1; height: 6px; background: var(--soft); border-radius: 6px; overflow: hidden; display: flex; }
.catbar .track i { display: block; height: 100%; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper b { min-width: 34px; text-align: center; font-family: var(--serif); font-size: 20px; font-weight: 500; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.setting:first-of-type { border-top: 0; }
.switch { width: 50px; height: 30px; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s; }
.switch.on { background: var(--good); }
.switch.on::after { transform: translateX(20px); }

.toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30; max-width: 90vw; animation: up .2s; }
.empty { text-align: center; padding: 30px 10px; }
.empty .big { font-family: var(--serif); font-size: 26px; }
.speak svg { width: 16px; height: 16px; }

/* ---------- course ---------- */
.unit-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px 0; border-top: 1px solid var(--line); }
.unit-row:first-of-type { border-top: 0; }
.unit-row .unum { width: 34px; height: 34px; flex: none; border-radius: 10px; background: var(--soft); display: inline-flex; align-items: center; justify-content: center; font-family: var(--serif); font-size: 17px; }
.unit-row .grow { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.unit-row b { font-weight: 500; }
.unit-row .track { height: 5px; background: var(--soft); border-radius: 5px; overflow: hidden; display: flex; }
.unit-row .track i { display: block; height: 100%; background: var(--good); }
.unit-row .track i.g { background: var(--ink2); opacity: .5; }
.unit-row.locked { opacity: .55; }
.unit-row.locked .unum { font-size: 14px; }
