/* Prep — mobile-first study app. No frameworks, no external assets. */

:root {
  --bg: #0f1216;
  --bg-soft: #161b22;
  --bg-card: #1a2029;
  --line: #262d38;
  --fg: #e6edf3;
  --fg-dim: #9aa7b4;
  --fg-faint: #6b7784;
  --accent: #4cc2ff;
  --accent-dim: #1d3f52;
  --good: #56d364;
  --warn: #e3b341;
  --bad: #f85149;
  --radius: 14px;
  --tap: 48px;
  --pad: 16px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa; --bg-soft: #fff; --bg-card: #fff; --line: #d8dee4;
    --fg: #1f2328; --fg-dim: #57606a; --fg-faint: #8c959f;
    --accent: #0969da; --accent-dim: #ddf0ff;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--fg);
  font-family: var(--sans);
  font-size: 16px; line-height: 1.55;
  overscroll-behavior-y: none;
}

body { padding-bottom: env(safe-area-inset-bottom); }

.app { max-width: 720px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.boot { padding: 40px; color: var(--fg-dim); text-align: center; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--pad) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .sub { font-size: 12px; color: var(--fg-faint); font-weight: 400; }

.iconbtn {
  min-width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--fg);
  font-size: 18px; display: grid; place-items: center; cursor: pointer; padding: 0 10px;
}
.iconbtn:active { background: var(--bg-card); }

/* ---------- layout ---------- */
main { flex: 1; padding: var(--pad); padding-bottom: 24px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.spacer { flex: 1; }
.muted { color: var(--fg-dim); }
.faint { color: var(--fg-faint); font-size: 13px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 4px; }
.stat {
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; text-align: center;
}
.stat b { display: block; font-size: 22px; line-height: 1.2; }
.stat span { font-size: 11px; color: var(--fg-faint); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- buttons ---------- */
.btn {
  min-height: var(--tap); padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--fg);
  font-size: 15px; font-weight: 600; font-family: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; width: 100%;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04121c; }
@media (prefers-color-scheme: light) { .btn.primary { color: #fff; } }
.btn.ghost { background: transparent; }
.btn[disabled] { opacity: .45; }
.btn.sm { min-height: 38px; font-size: 13px; padding: 0 12px; width: auto; }

/* ---------- deck list ---------- */
.group-title {
  font-size: 12px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--fg-faint); margin: 18px 2px 6px;
}
.deck {
  display: block; text-decoration: none; color: inherit;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px;
}
.deck + .deck { margin-top: 8px; }
.deck-top { display: flex; align-items: baseline; gap: 8px; }
.deck-title { font-weight: 600; font-size: 15px; flex: 1; }
.pill {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-dim); color: var(--accent); white-space: nowrap;
}
.pill.zero { background: var(--bg-card); color: var(--fg-faint); }
.progress { height: 4px; border-radius: 999px; background: var(--line); margin-top: 9px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--good); border-radius: inherit; }

/* ---------- study card ---------- */
.study { display: flex; flex-direction: column; min-height: calc(100dvh - 60px); }
.sessionbar { padding: 0 var(--pad); }
.sessionbar .progress { margin: 10px 0 0; }

.card {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin: var(--pad); flex: 1;
  display: flex; flex-direction: column; gap: 10px;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.card-meta { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--fg-faint); }
.tag { border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.card h2 { font-size: 16px; margin: 0; line-height: 1.35; }

.prompt { font-size: 15px; }
.answer { border-top: 1px dashed var(--line); padding-top: 12px; }

.actions {
  position: sticky; bottom: 0;
  display: grid; gap: 8px; padding: 10px var(--pad) calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); border-top: 1px solid var(--line);
}
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.grades .btn { flex-direction: column; gap: 0; padding: 0 4px; font-size: 13px; }
.grades .btn small { font-size: 10px; color: var(--fg-faint); font-weight: 500; }
.g1 { border-color: var(--bad); } .g2 { border-color: var(--warn); }
.g3 { border-color: var(--good); } .g4 { border-color: var(--accent); }

/* ---------- mcq ---------- */
.opts { display: grid; gap: 8px; }
.opt {
  text-align: left; min-height: var(--tap); padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--fg);
  font: inherit; font-size: 14px; cursor: pointer; display: flex; gap: 10px; align-items: flex-start;
}
.opt b { color: var(--fg-faint); }
.opt.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.opt[disabled] { opacity: 1; cursor: default; }

/* ---------- markdown / code ---------- */
.md { font-size: 15px; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3, .md h4 { font-size: 15px; margin: 14px 0 6px; line-height: 1.3; }
.md h1 { font-size: 17px; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0; padding-left: 20px; }
.md li { margin: 3px 0; }
.md blockquote {
  margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--accent);
  background: var(--bg-soft); border-radius: 0 8px 8px 0; color: var(--fg-dim);
}
.md code { font-family: var(--mono); font-size: .88em; background: var(--bg-soft); padding: 1px 5px; border-radius: 5px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md table { border-collapse: collapse; font-size: 13px; min-width: 100%; }
.md .tablewrap { overflow-x: auto; margin: 10px 0; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; }
.md th { background: var(--bg-soft); }
.md strong { font-weight: 650; }

pre {
  margin: 10px 0; padding: 12px; border-radius: 10px;
  background: var(--bg-soft); border: 1px solid var(--line);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
pre code { background: none; padding: 0; font-size: 12.5px; line-height: 1.5; }
pre.wrap code { white-space: pre-wrap; overflow-wrap: anywhere; }

.tok-com { color: var(--fg-faint); font-style: italic; }
.tok-str { color: #7ee787; }
.tok-kw  { color: #ff7b72; font-weight: 600; }
.tok-num { color: #d2a8ff; }
.tok-fn  { color: #d2a8ff; }
@media (prefers-color-scheme: light) {
  .tok-str { color: #0a7c2f; } .tok-kw { color: #cf222e; }
  .tok-num, .tok-fn { color: #8250df; }
}

/* ---------- read mode ---------- */
.reader details {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px;
}
.reader details + details { margin-top: 8px; }
.reader summary { cursor: pointer; font-weight: 600; font-size: 15px; list-style: none; }
.reader summary::-webkit-details-marker { display: none; }
.reader summary::before { content: "▸ "; color: var(--fg-faint); }
.reader details[open] summary::before { content: "▾ "; }
.reader details[open] summary { margin-bottom: 8px; }

/* ---------- search ---------- */
.search {
  width: 100%; min-height: var(--tap); padding: 0 14px; font: inherit; font-size: 15px;
  background: var(--bg-soft); color: var(--fg);
  border: 1px solid var(--line); border-radius: 12px;
}
.hit { display: block; text-decoration: none; color: inherit; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg-soft); }
.hit + .hit { margin-top: 8px; }
.hit .t { font-weight: 600; font-size: 14px; }

.empty { text-align: center; color: var(--fg-faint); padding: 40px 20px; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 50;
  background: var(--bg-card); border: 1px solid var(--line); color: var(--fg);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; box-shadow: 0 8px 24px #0006;
}
