:root {
  --bg: #f6f5f1; --surface: #ffffff; --surface-2: #efede7; --ink: #1d1d1b; --muted: #6b6a64; --line: #e2dfd6;
  --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #d6efec;
  --good: #1f8a4c; --good-soft: #dcf2e4; --bad: #c2402f; --bad-soft: #fbe3df;
  --hard: #b7791f; --easy: #2f6fb7;
  --radius: 14px; --maxw: 640px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121412; --surface: #1c1f1d; --surface-2: #262a27; --ink: #ecebe6; --muted: #a09f98; --line: #2f3330;
    --accent: #2bb3a4; --accent-ink: #0b1513; --accent-soft: #173532;
    --good: #4cc27d; --good-soft: #17301f; --bad: #ef7765; --bad-soft: #3a1c17;
    --hard: #e0a84a; --easy: #6aa5e8;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
code { font: 0.92em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.top { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
.top h1 { margin: 0; font-size: 17px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .brand { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.back, .gear { font-size: 28px; line-height: 1; text-decoration: none; color: var(--ink); justify-self: start; padding: 4px 8px; }
.gear { font-size: 20px; justify-self: end; }
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 40px); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.lede { font-size: 18px; color: var(--muted); }
.big { font-size: 44px; margin: 0; }
.ok { color: var(--good); font-weight: 700; margin: 0; }
.bad { color: var(--bad); font-weight: 600; }
h2 { font-size: 18px; margin: 0; }
h2.area { margin: 24px 0 0; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h3 { margin: 0; font-size: 18px; }
p { margin: 0; }

button, .button { appearance: none; font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  border-radius: 12px; padding: 12px 16px; min-height: 46px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button:disabled { opacity: .55; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.danger { color: var(--bad); }
.wide { width: 100%; }
.button.disabled { background: var(--surface-2); color: var(--muted); border-color: var(--line); }
button.link { background: none; border: 0; color: var(--accent); min-height: 0; padding: 4px; font-weight: 500; }
button.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
button.icon { min-height: 44px; min-width: 44px; padding: 8px; font-size: 20px; background: var(--accent-soft); border-color: transparent; }

input, textarea, select { font: inherit; font-size: 16px; width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
.row > input[type=search] { flex: 1; width: auto; }
.form label { display: block; flex: 1; }
.form label > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; }
.stats > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; }
.stats b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }

.course-head { display: block; text-decoration: none; color: inherit; margin-bottom: 12px; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill.due { background: var(--accent-soft); color: var(--accent); }
.pill.new { background: var(--good-soft); color: var(--good); }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0 6px; }
.bar .fill { height: 100%; background: var(--accent); }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin: 0 -4px 4px; }
.tabs a { padding: 8px 14px; border-radius: 99px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; white-space: nowrap; }
.tabs a.on { background: var(--ink); color: var(--bg); }

.list { display: flex; flex-direction: column; gap: 6px; }
.item { justify-content: flex-start; text-align: left; font-weight: 500; background: var(--surface); }
details summary { cursor: pointer; font-weight: 600; }
.note { white-space: pre-wrap; font-size: 14px; line-height: 1.55; margin: 12px 0; max-height: 60vh; overflow: auto; }

.stage { margin-top: 4px; padding-bottom: 96px; }
.flash { min-height: 280px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.flash .pic { max-width: 220px; width: 60%; border-radius: 12px; }
.front { font-size: 30px; font-weight: 700; letter-spacing: -.01em; }
.hidden-text { filter: blur(9px); user-select: none; }
.back { font-size: 20px; }
.example { background: var(--surface-2); border-radius: 12px; padding: 12px; width: 100%; }
.example p:first-child { font-size: 18px; font-weight: 600; }
.notes { font-size: 14px; color: var(--muted); }
.audio { display: inline-flex; gap: 6px; }

.question { font-size: 18px; font-weight: 600; }
.option { width: 100%; justify-content: flex-start; text-align: left; flex-direction: column; align-items: flex-start; font-weight: 500; background: var(--surface); }
.option small { font-weight: 400; font-size: 13px; color: var(--muted); margin-top: 4px; }
.option.picked { border-color: var(--accent); background: var(--accent-soft); }
.option.right { border-color: var(--good); background: var(--good-soft); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.dim { opacity: .55; }
.option:disabled { opacity: 1; }
.option.dim:disabled { opacity: .5; }

.rates { position: sticky; bottom: calc(env(safe-area-inset-bottom) + 8px); display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.rate { flex-direction: column; gap: 0; padding: 8px 4px; background: var(--surface); }
.rate span { font-size: 12px; font-weight: 500; color: var(--muted); }
.rate.again b { color: var(--bad); } .rate.hard b { color: var(--hard); } .rate.good b { color: var(--good); } .rate.easy b { color: var(--easy); }
.rate.suggest { outline: 2px solid var(--accent); outline-offset: 1px; }

.card > b { display: block; }
.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 64px); transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; max-width: calc(100vw - 32px); font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.bad { background: var(--bad); color: #fff; }

.spark-box { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; }
.spark-box > * + * { margin-top: 8px; }
.spark-link { text-decoration: none; color: inherit; }
.spark .note { margin: 0; font-size: 15px; }
.spark.processed, .spark.dismissed { opacity: .75; }
.button.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }

.tile { text-decoration: none; color: inherit; margin: 8px 0; }
.tile-icon { font-size: 24px; width: 36px; text-align: center; }
.block { display: block; }
.stack-sm { flex-direction: column; align-items: flex-start; gap: 2px; }
.editor .doc-title { font-size: 22px; font-weight: 700; border: 0; background: transparent; padding: 6px 0; }
.editor .doc-title:focus { outline: none; }
.editor .doc-body { min-height: 55vh; font-size: 17px; line-height: 1.6; resize: vertical; }
label.check input { width: auto; }
