:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --card: #ffffff;
  --soft: #eef1f8;
  --text: #1b2033;
  --muted: #667085;
  --line: #dfe3ee;
  --accent: #4f7cff;
  --accent-soft: #e6edff;
  --good: #16a37f;
  --warn: #d9822b;
  --bad: #e0485a;
  --M: #4f7cff; --R: #16a37f; --C: #d9822b; --E: #b35fd6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1220; --card: #171b2d; --soft: #1f2439; --text: #e7e9f2; --muted: #98a0b8;
    --line: #2a3050; --accent: #7c9cff; --accent-soft: #232c4d; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1220; --card: #171b2d; --soft: #1f2439; --text: #e7e9f2; --muted: #98a0b8;
  --line: #2a3050; --accent: #7c9cff; --accent-soft: #232c4d; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 150px;
}
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: .3em 0 .7em; }
a { color: var(--accent); }
small, .muted { color: var(--muted); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; max-width: 1100px; margin: 0 auto;
}
.brand { display: flex; gap: 12px; align-items: center; }
.sync { font-size: .78rem; color: var(--muted); }
.sync[data-s="synced"] { color: var(--good); }
.sync[data-s="error"] { color: var(--bad); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.brand h1 { font-size: 1.15rem; margin: 0; }
.brand .sub { margin: 0; color: var(--muted); font-size: .85rem; }
.logo {
  width: 40px; height: 40px; border-radius: 10px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800;
}

.tabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 0 16px 10px; max-width: 1100px; margin: 0 auto;
  scrollbar-width: none; position: sticky; top: env(safe-area-inset-top, 0px); background: var(--bg); z-index: 5; padding-top: 6px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 7px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap; font: inherit; font-size: .9rem;
}
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

main { max-width: 1100px; margin: 0 auto; padding: 4px 16px 24px; }

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.card + .card { margin-top: 14px; }
.grid > .card + .card { margin-top: 0; }
.card.soft { background: var(--soft); box-shadow: none; }
.card h2, .card h3 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 1.6rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: .85rem; }

.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 8px;
  padding: 7px 12px; font: inherit; font-size: .9rem; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 3px 8px; font-size: .8rem; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 8px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; max-width: 100%;
}
textarea { width: 100%; min-height: 90px; resize: vertical; }
input[type="number"] { width: 70px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { color: var(--text); }
.form { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.badge {
  display: inline-block; font-size: .72rem; padding: 2px 7px; border-radius: 999px;
  background: var(--soft); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; font-weight: 600;
}
.badge.d1 { color: var(--good); }
.badge.d2 { color: var(--warn); }
.badge.d3 { color: var(--bad); }
.badge.w { color: var(--accent); }
.badge.phase { color: #fff; border: none; white-space: normal; }

.bar { height: 8px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.chapter { border: 1px solid var(--line); border-radius: 10px; background: var(--card); margin-bottom: 10px; }
.chapter > summary { cursor: pointer; padding: 11px 14px; list-style: none; display: flex; gap: 10px; align-items: center; }
.chapter > summary::-webkit-details-marker { display: none; }
.chapter > summary .name { flex: 1; font-weight: 600; min-width: 0; }
.chapter .body { padding: 0 14px 12px; }
.chapter .topic { margin: 12px 0 6px; font-weight: 600; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; }
.meta { font-size: .85rem; color: var(--muted); }
.meta b { color: var(--text); font-weight: 600; }

.leaf { border-top: 1px solid var(--line); padding: 8px 0; }
.leaf-head { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.leaf-head .nm { flex: 1; min-width: 0; }
.leaf-detail { margin: 8px 0 4px; padding: 12px; background: var(--soft); border-radius: 10px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--line); }
.dot.doing { background: var(--warn); }
.dot.done { background: var(--good); }
.dot.mastered { background: var(--accent); }
.star { cursor: pointer; font-size: 1.1rem; background: none; border: none; color: var(--muted); padding: 0 2px; }
.star.on { color: #f5b301; }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.block { border-left: 4px solid var(--accent); padding: 8px 12px; background: var(--soft); border-radius: 8px; margin-bottom: 10px; }
.block .bt { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.task { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px dashed var(--line); }
.task:first-of-type { border-top: none; }
.task input[type="checkbox"] { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--good); }
.task .tx { flex: 1; min-width: 0; }
.task.done .tx { opacity: .6; }
.task ul { margin: 4px 0 0; padding-left: 18px; font-size: .9rem; }

.rate { display: flex; gap: 4px; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.scroll-x { overflow-x: auto; }

pre.prompt {
  white-space: pre-wrap; background: var(--soft); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; font-size: .82rem; max-height: 360px; overflow: auto;
}

.warnbox { border: 1px solid var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); border-radius: 10px; padding: 10px 12px; }
.infobox { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; }

.hbar { display: grid; grid-template-columns: 150px 1fr 40px; gap: 8px; align-items: center; font-size: .85rem; margin: 4px 0; }
.hbar .bar { height: 10px; }

.pomo {
  position: fixed; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); width: 230px; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  padding: 10px 12px; z-index: 20;
}
.pomo-head { display: flex; gap: 6px; align-items: center; }
.pomo-head select { flex: 1; padding: 4px 6px; }
.pomo-count { font-size: .8rem; color: var(--muted); }
.pomo-time { font-size: 2.2rem; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.pomo-cue { font-size: .8rem; color: var(--muted); text-align: center; min-height: 1em; }
.pomo-btns { display: flex; gap: 6px; justify-content: center; margin-top: 6px; }
.pomo.collapsed .pomo-body { display: none; }
.pomo.running { border-color: var(--good); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(80px);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; transition: transform .2s; z-index: 30;
  max-width: 90vw; font-size: .9rem; opacity: 0; visibility: hidden;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }

.pager { display: flex; justify-content: space-between; align-items: center; margin: 10px 0; }
.day { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: var(--card); }
.day h4 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.day .ln { font-size: .88rem; margin: 3px 0; }
.day.today { border-color: var(--accent); }

ol.steps, ul.clean { margin: 6px 0; padding-left: 20px; }
ul.clean { list-style: none; padding-left: 0; }
ul.clean li { padding: 3px 0; }
.chart svg { width: 100%; height: auto; display: block; }

@media (max-width: 600px) {
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: 6px; }
  .hbar { grid-template-columns: 100px 1fr 34px; }
  .pomo { width: calc(100% - 24px); right: 12px; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); padding: 6px 10px; }
  .pomo-body { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 10px; }
  .pomo-time { font-size: 1.5rem; text-align: left; }
  .pomo-btns { margin: 0; justify-content: flex-end; }
  .pomo-cue { grid-column: 1 / -1; text-align: left; order: 3; }
  .stat .v { font-size: 1.3rem; }
  body { padding-bottom: 150px; }
}

/* ---------- practice questions ---------- */
.qcard { display: flex; flex-direction: column; gap: 12px; }
.qimg { max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; align-self: flex-start; }
.qtimer { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted); }
.opts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; max-width: 520px; }
.opt { display: flex; gap: 8px; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 10px; padding: 12px; cursor: pointer; font-size: 1.05rem; background: var(--card); }
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt-ok, .opt-ok:has(input:checked) { border-color: var(--good); background: color-mix(in srgb, var(--good) 15%, var(--card)); }
.opt-bad, .opt-bad:has(input:checked) { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 15%, var(--card)); }
.qres { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.qres.good { border-color: var(--good); }
.qres.bad { border-color: var(--bad); }
.qres ul { margin: 4px 0 8px; padding-left: 20px; }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center; margin-top: 12px; }
.drop.over, .drop:focus { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.upls { display: grid; gap: 10px; margin-top: 12px; }
.upl { display: grid; grid-template-columns: minmax(0, 260px) 1fr; gap: 12px; align-items: start; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.upl img { max-width: 100%; border-radius: 8px; background: #fff; border: 1px solid var(--line); }
img.thumb { width: 110px; max-height: 70px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
@media (max-width: 600px) { .upl { grid-template-columns: 1fr; } .opts { max-width: none; } }
