/* Kemu One — styles. System fonts only (no external hosts). */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --ink: #141a22;
  --ink-2: #3a4351;
  --muted: #667080;
  --line: #e2e6ec;
  --brand: #1f5fbf;
  --brand-ink: #ffffff;
  --brand-soft: #e7effb;
  --good: #16865a;
  --good-soft: #e3f4ec;
  --bad: #cf3434;
  --bad-soft: #fbe9e9;
  --warn: #c98a00;
  --warn-soft: #fdf3dc;
  --new: #a3acb9;
  --learning: #e2a21a;
  --mastered: #1fa36b;
  --shadow: 0 1px 2px rgba(20, 26, 34, .05), 0 4px 16px rgba(20, 26, 34, .06);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1d222b;
    --ink: #e9ecf1;
    --ink-2: #c3c9d3;
    --muted: #8f99a8;
    --line: #272d37;
    --brand: #5b95ec;
    --brand-ink: #0b1220;
    --brand-soft: #18263d;
    --good: #3cc486;
    --good-soft: #13291f;
    --bad: #f06a6a;
    --bad-soft: #2e1717;
    --warn: #f0b93a;
    --warn-soft: #2c2412;
    --new: #566070;
    --learning: #e8ac2c;
    --mastered: #34b97c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
@media (min-width: 760px) { body { padding-bottom: 40px; } }
a { color: var(--brand); text-decoration: none; }
button { font: inherit; color: inherit; }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.tiny { font-size: .78rem; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- chrome ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; font-size: 1.05rem; }
.brand img { border-radius: 7px; }
.nav { display: none; gap: 4px; margin-left: 12px; }
.nav a { color: var(--muted); padding: 6px 12px; border-radius: 999px; font-weight: 550; font-size: .95rem; }
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a.active { color: var(--brand); background: var(--brand-soft); }
.icon-btn { margin-left: auto; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; color: var(--muted); }
.icon-btn:hover, .icon-btn.active { color: var(--ink); background: var(--surface-2); }
@media (min-width: 760px) { .nav { display: flex; } }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .7rem; font-weight: 600; color: var(--muted); padding: 4px 0; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--brand); }
@media (min-width: 760px) { .tabbar { display: none; } }
body.focus .tabbar { display: none; }
body.focus { padding-bottom: 24px; }

main { max-width: 980px; margin: 0 auto; padding: 20px 16px 24px; outline: none; }
main.narrow { max-width: 720px; }

/* ---------- building blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: 1fr; }
.grid.three { grid-template-columns: 1fr; }
@media (min-width: 640px) {
  .grid.two { grid-template-columns: 1fr 1fr; }
  .grid.three { grid-template-columns: repeat(3, 1fr); }
}
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 28px 0 12px; }
.section-title h2 { font-size: 1.05rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; cursor: pointer; text-align: center;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.lg { min-height: 54px; font-size: 1.05rem; border-radius: 14px; }
.btn[disabled] { opacity: .45; cursor: default; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.chip.new { background: var(--surface-2); color: var(--muted); }
.chip.learning { background: var(--warn-soft); color: var(--warn); }
.chip.mastered { background: var(--good-soft); color: var(--good); }
.chip.due { background: var(--brand-soft); color: var(--brand); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.new { background: var(--new); }
.dot.learning { background: var(--learning); }
.dot.mastered { background: var(--mastered); }

.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: .85rem; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.filters button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* stacked mastery bar */
.mbar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.mbar span { display: block; height: 100%; }
.mbar .m { background: var(--mastered); }
.mbar .l { background: var(--learning); }
.mbar.thin { height: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .82rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- home ---------- */
.hero { display: grid; gap: 20px; grid-template-columns: 1fr; align-items: center; }
@media (min-width: 640px) { .hero { grid-template-columns: auto 1fr; } }
.ring { position: relative; width: 148px; height: 148px; margin: 0 auto; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--surface-2); }
.ring .val { stroke: var(--brand); transition: stroke-dashoffset .8s ease; }
.ring .pass { stroke: var(--ink); }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-label b { font-size: 2.4rem; line-height: 1; font-weight: 750; letter-spacing: -.03em; }
.ring-label span { font-size: .72rem; line-height: 1.2; color: var(--muted); font-weight: 600; margin-top: 6px; text-transform: uppercase; letter-spacing: .06em; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.kpi b { display: block; font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi span { font-size: .75rem; color: var(--muted); font-weight: 600; }

.actions { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.action { display: flex; flex-direction: column; gap: 4px; padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--ink); cursor: pointer; text-align: left; }
.action:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.action b { font-size: 1rem; }
.action span { font-size: .82rem; color: var(--muted); }
.action.primary { grid-column: 1 / -1; background: var(--brand); border-color: var(--brand); color: var(--brand-ink); flex-direction: row; align-items: center; padding: 18px 20px; }
.action.primary span { color: color-mix(in srgb, var(--brand-ink) 80%, transparent); }
.action.primary .go { margin-left: auto; font-size: 1.4rem; }
@media (min-width: 640px) { .actions { grid-template-columns: repeat(4, 1fr); } }

.topic { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); color: var(--ink); cursor: pointer; text-align: left; }
.topic:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.topic .row { justify-content: space-between; }
.topic b { font-size: .95rem; font-weight: 650; }

/* ---------- question ---------- */
.session-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.progress { flex: 1; height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .3s ease; }
.qcard { padding: 22px; }
.qmeta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.qtext { font-size: 1.2rem; line-height: 1.45; font-weight: 600; }
.qimg { margin: 16px 0 4px; display: flex; justify-content: center; background: var(--surface-2); border-radius: 12px; padding: 10px; }
.qimg img { max-height: 280px; border-radius: 6px; object-fit: contain; background: #fff; }
.options { display: grid; gap: 10px; margin-top: 18px; }
.options.tf { grid-template-columns: 1fr 1fr; }
.opt {
  display: flex; align-items: flex-start; gap: 12px; width: 100%;
  padding: 14px 16px; border-radius: 12px; min-height: 52px;
  border: 1.5px solid var(--line); background: var(--surface); text-align: left; cursor: pointer;
  font-size: 1rem; line-height: 1.4;
  transition: border-color .12s ease, background .12s ease;
}
.opt:hover:not([disabled]) { border-color: var(--brand); }
.opt .k { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: var(--surface-2); font-size: .8rem; font-weight: 700; color: var(--muted); }
.options.tf .opt { justify-content: center; align-items: center; font-weight: 650; font-size: 1.05rem; }
.opt.sel { border-color: var(--brand); background: var(--brand-soft); }
.opt.sel .k { background: var(--brand); color: var(--brand-ink); }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.right .k { background: var(--good); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .k { background: var(--bad); color: #fff; }
.opt[disabled] { cursor: default; }
.opt.dim { opacity: .55; }

.feedback { margin-top: 16px; padding: 14px 16px; border-radius: 12px; display: flex; gap: 12px; align-items: flex-start; }
.feedback.ok { background: var(--good-soft); color: var(--good); }
.feedback.no { background: var(--bad-soft); color: var(--bad); }
.feedback b { display: block; }
.feedback p { color: var(--ink-2); font-size: .9rem; margin-top: 2px; }
.history { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.history i { width: 10px; height: 10px; border-radius: 3px; background: var(--good); display: inline-block; }
.history i.x { background: var(--bad); }
.history i.e { outline: 2px solid color-mix(in srgb, var(--ink) 30%, transparent); outline-offset: 1px; }
.steps { display: inline-flex; gap: 3px; vertical-align: middle; }
.steps i { width: 16px; height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--muted) 30%, transparent); display: inline-block; }
.steps i.on { background: var(--mastered); }

.nextbar { position: sticky; bottom: 12px; margin-top: 16px; }
@media (max-width: 759px) { body.focus .nextbar { bottom: calc(12px + env(safe-area-inset-bottom)); } }

/* flashcards */
.flip { cursor: pointer; }
.reveal { margin-top: 18px; padding: 16px; border-radius: 12px; background: var(--good-soft); }
.reveal .lbl { font-size: .75rem; font-weight: 700; color: var(--good); text-transform: uppercase; letter-spacing: .06em; }
.reveal .ans { font-size: 1.1rem; font-weight: 650; margin-top: 4px; }
.grade { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grade .btn.no { color: var(--bad); }
.grade .btn.yes { color: var(--good); }
.kbd { font-size: .72rem; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; margin-left: 6px; font-weight: 600; }
.btn.primary .kbd { color: inherit; border-color: currentColor; opacity: .6; }
@media (hover: none) { .kbd { display: none; } }

/* ---------- exam ---------- */
.exam-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.1rem; padding: 6px 12px; border-radius: 10px; background: var(--surface-2); }
.timer.low { background: var(--bad-soft); color: var(--bad); }
.navgrid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
.navgrid button { aspect-ratio: 1; border: 1px solid var(--line); background: var(--surface); border-radius: 7px; font-size: .72rem; font-weight: 600; color: var(--muted); cursor: pointer; padding: 0; font-variant-numeric: tabular-nums; }
.navgrid button.done { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.navgrid button.cur { outline: 2px solid var(--brand); outline-offset: 1px; }
.navgrid button.right { background: var(--good-soft); color: var(--good); border-color: transparent; }
.navgrid button.wrong { background: var(--bad); color: #fff; border-color: transparent; }
.exam-layout { display: grid; gap: 16px; }
@media (min-width: 900px) { .exam-layout { grid-template-columns: 1fr 300px; align-items: start; } .exam-side { position: sticky; top: 76px; } }
.result-hero { text-align: center; padding: 28px 18px; }
.result-hero .score { font-size: 4rem; font-weight: 800; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.result-hero.pass .score { color: var(--good); }
.result-hero.fail .score { color: var(--bad); }
.badge { display: inline-block; margin-top: 10px; padding: 4px 14px; border-radius: 999px; font-weight: 700; font-size: .85rem; }
.pass .badge { background: var(--good-soft); color: var(--good); }
.fail .badge { background: var(--bad-soft); color: var(--bad); }

/* ---------- lists ---------- */
.search { width: 100%; min-height: 46px; padding: 10px 14px 10px 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23889' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-4-4'/%3E%3C/svg%3E") no-repeat 12px center / 18px; color: var(--ink); font: inherit; }
.search:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.qlist { display: grid; gap: 8px; }
.qitem { display: flex; gap: 12px; align-items: center; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: var(--ink); }
.qitem:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.qitem .thumb { width: 52px; height: 40px; flex: none; border-radius: 6px; object-fit: contain; background: #fff; border: 1px solid var(--line); }
.qitem .t { flex: 1; min-width: 0; font-size: .92rem; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.qitem .n { color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; width: 34px; flex: none; }

.timeline { display: grid; gap: 0; }
.timeline .ev { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.timeline .ev:last-child { border-bottom: 0; }
.mark { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: .75rem; font-weight: 800; color: #fff; background: var(--good); }
.mark.x { background: var(--bad); }

/* charts */
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid-line { stroke: var(--line); }
.chart .pass-line { stroke: var(--good); stroke-dasharray: 4 4; }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 2.5; stroke-linejoin: round; }
.chart .pt { fill: var(--surface); stroke: var(--brand); stroke-width: 2.5; }
.chart .pt.fail { stroke: var(--bad); }
.chart .bar { fill: var(--brand); }
.chart .bar.empty { fill: var(--surface-2); }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }

.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: .92rem; }
.field input { min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; }
.toast { position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: .9rem; z-index: 50; box-shadow: var(--shadow); }
@media (min-width: 760px) { .toast { bottom: 28px; } }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
