/* MathAns for MCQ — Quizlet-shaped study app.
   Light tokens on :root; dark tokens repeated twice — once for system dark
   (unless the viewer forced light) and once for the explicit
   [data-theme="dark"] toggle. Keep the two dark blocks identical. */

:root {
  --bg:        #f6f7fb;
  --bg-2:      #edeff7;
  --card:      #ffffff;
  --card-2:    #f8f9fd;
  --ink:       #282e3e;
  --muted:     #586380;
  --line:      #d9dde8;
  --line-soft: #e8ebf3;

  --accent:      #4255ff;
  --accent-2:    #3542d6;
  --accent-ink:  #ffffff;
  --accent-soft: #edefff;
  --accent-line: #c4caff;

  --good: #0f8a5f; --good-bg: #e3f7ee; --good-line: #a9e4c9;
  --warn: #8a5a00; --warn-bg: #fff3d6; --warn-line: #f5d98a;
  --bad:  #c2313f; --bad-bg:  #ffe9eb; --bad-line:  #f7b8bf;

  --shadow:    0 1px 2px rgba(40,46,62,.06), 0 8px 24px -14px rgba(40,46,62,.25);
  --shadow-lg: 0 12px 40px -12px rgba(40,46,62,.3), 0 2px 8px rgba(40,46,62,.06);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0a092d;
    --bg-2:      #13143a;
    --card:      #2e3856;
    --card-2:    #1f2a48;
    --ink:       #f6f7fb;
    --muted:     #a8b1cf;
    --line:      #3f4a6e;
    --line-soft: #35406a;

    --accent:      #7c89ff;
    --accent-2:    #98a3ff;
    --accent-ink:  #0a092d;
    --accent-soft: #232a5a;
    --accent-line: #3d4aa8;

    --good: #59e3a7; --good-bg: #123b2f; --good-line: #1e6a51;
    --warn: #ffd37a; --warn-bg: #3d2f0c; --warn-line: #6b5314;
    --bad:  #ff8c98; --bad-bg:  #46151d; --bad-line:  #7a2632;

    --shadow: none;
    --shadow-lg: 0 16px 50px -12px rgba(0,0,0,.7);
  }
}

:root[data-theme="dark"] {
  --bg:        #0a092d;
  --bg-2:      #13143a;
  --card:      #2e3856;
  --card-2:    #1f2a48;
  --ink:       #f6f7fb;
  --muted:     #a8b1cf;
  --line:      #3f4a6e;
  --line-soft: #35406a;

  --accent:      #7c89ff;
  --accent-2:    #98a3ff;
  --accent-ink:  #0a092d;
  --accent-soft: #232a5a;
  --accent-line: #3d4aa8;

  --good: #59e3a7; --good-bg: #123b2f; --good-line: #1e6a51;
  --warn: #ffd37a; --warn-bg: #3d2f0c; --warn-line: #6b5314;
  --bad:  #ff8c98; --bad-bg:  #46151d; --bad-line:  #7a2632;

  --shadow: none;
  --shadow-lg: 0 16px 50px -12px rgba(0,0,0,.7);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang HK", "Microsoft JhengHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── top bar ─────────────────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 12px; letter-spacing: .02em;
}
.brand b { font-size: 16px; font-weight: 700; }
.brand small { display: block; font-size: 11.5px; color: var(--muted); margin-top: -2px; }
.topbar .spacer { flex: 1; }
.dev-toggle { border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 999px; padding: 5px 11px; font-size: 12px; font-weight: 700; letter-spacing: .04em; margin-right: 8px; }
.dev-toggle[aria-pressed="true"] { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.dev-only { display: none; }
html.dev .dev-only { display: block; }
.callout.dev-only { border-style: dashed; border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn); }
.callout.dev-only .hint { color: var(--warn); opacity: .85; font-size: 13px; }
.topbar .theme-toggle { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.theme-toggle button {
  border: 0; background: transparent; padding: 4px 10px; border-radius: 999px; font-size: 12px; color: var(--muted);
}
.theme-toggle button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.wrap { max-width: 960px; margin: 0 auto; padding: 28px 18px 80px; }
.wrap.narrow { max-width: 760px; }

/* ── generic bits ────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; font-size: 14.5px; text-decoration: none;
  transition: transform .08s, background .12s, border-color .12s;
}
.btn:hover { border-color: var(--accent-line); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.big { padding: 15px 24px; font-size: 16px; border-radius: 14px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--bg-2); color: var(--ink); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); border-color: var(--bad-line); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn .ico { font-size: 18px; line-height: 1; }

.kicker { font-size: 11.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.lede { color: var(--muted); font-size: 15px; max-width: 60ch; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--line); background: var(--card-2); color: var(--muted);
}
.pill.good { color: var(--good); background: var(--good-bg); border-color: var(--good-line); }
.pill.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.pill.bad  { color: var(--bad);  background: var(--bad-bg);  border-color: var(--bad-line); }
.pill.src { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 500; font-size: 11.5px; }
.pill.accent { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }

.callout {
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card-2); font-size: 14px;
}
.callout.good { background: var(--good-bg); border-color: var(--good-line); color: var(--good); }
.callout.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.callout.bad  { background: var(--bad-bg);  border-color: var(--bad-line);  color: var(--bad); }
.callout ul { margin: 6px 0 0; padding-left: 18px; }
.callout ul.notes { color: var(--muted); font-size: 13px; }
.callout.ocr-offer { border-style: dashed; }
.callout.ocr-offer .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: 5px; padding: 0 4px; }
.q-edit .stem-text { white-space: pre-line; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; }
.field .hint { font-size: 12.5px; color: var(--muted); }
.input, textarea.input, select.input {
  width: 100%; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
}
textarea.input { min-height: 120px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13.5px; line-height: 1.5; }
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

/* ── library ─────────────────────────────────────────────────────────── */

.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; flex-wrap: wrap; margin-bottom: 22px; }
.hero h1 { font-size: 30px; }
.hero p { margin-top: 6px; }

.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.set-card {
  display: block; text-decoration: none; color: inherit; text-align: left; width: 100%;
  padding: 18px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card);
  box-shadow: var(--shadow); border-bottom-width: 4px; transition: border-color .12s, transform .1s;
}
.set-card:hover { border-bottom-color: var(--accent); transform: translateY(-1px); }
.set-card h3 { font-size: 17px; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-card .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 12.5px; color: var(--muted); }
.set-card .bar { height: 6px; border-radius: 999px; background: var(--line-soft); margin-top: 12px; overflow: hidden; }
.set-card .bar i { display: block; height: 100%; background: var(--good); border-radius: 999px; }

.empty {
  text-align: center; padding: 56px 20px; border: 1.5px dashed var(--line); border-radius: var(--radius); background: var(--card-2);
}
.empty .big { font-size: 42px; margin-bottom: 8px; }
.empty h2 { font-size: 20px; margin-bottom: 6px; }
.empty p { color: var(--muted); margin-bottom: 18px; }

.how { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-top: 34px; }
.how div { padding: 14px 16px; border-radius: 12px; background: var(--card); border: 1px solid var(--line-soft); font-size: 13.5px; color: var(--muted); }
.how b { display: block; color: var(--ink); margin-bottom: 4px; font-size: 14px; }
.how .n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; margin-right: 6px; }

/* ── wizard ──────────────────────────────────────────────────────────── */

.steps { display: flex; gap: 6px; align-items: center; margin: 0 0 22px; padding: 0; list-style: none; flex-wrap: wrap; }
.steps li { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.steps li .n { width: 24px; height: 24px; border-radius: 999px; display: grid; place-items: center; background: var(--bg-2); border: 1px solid var(--line); font-size: 12px; }
.steps li.active { color: var(--ink); }
.steps li.active .n { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.steps li.done .n { background: var(--good-bg); color: var(--good); border-color: var(--good-line); }
.steps li + li::before { content: ""; width: 26px; height: 1px; background: var(--line); margin: 0 4px; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; display: flex; flex-direction: column; gap: 18px; }
.panel h2 { font-size: 22px; }
.panel .row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.panel .actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; padding-top: 6px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }

.drop {
  border: 2px dashed var(--line); border-radius: 14px; padding: 34px 18px; text-align: center; background: var(--card-2);
  cursor: pointer; transition: border-color .12s, background .12s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .big { font-size: 34px; }
.drop b { display: block; margin-top: 6px; }
.drop span { font-size: 13px; color: var(--muted); }
.drop.small { padding: 16px; }

.progress { height: 8px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .2s; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card-2); }
.stat .v { font-size: 26px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.stat .l { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.stat.good { border-color: var(--good-line); background: var(--good-bg); }
.stat.good .v { color: var(--good); }
.stat.bad { border-color: var(--bad-line); background: var(--bad-bg); }
.stat.bad .v { color: var(--bad); }

.preview { display: flex; flex-direction: column; gap: 10px; }
.q-edit {
  border: 1px solid var(--line); border-radius: 12px; background: var(--card-2); padding: 12px 14px; display: grid; gap: 8px;
}
.q-edit.flag { border-color: var(--warn-line); background: var(--warn-bg); }
.q-edit .head { display: flex; align-items: center; gap: 8px; }
.q-edit .head .lab { font-weight: 700; font-size: 13px; }
.q-edit .head .spacer { flex: 1; }
.q-edit textarea { min-height: 54px; font-family: inherit; font-size: 14px; }
.q-edit .opts { display: grid; gap: 6px; }
.q-edit .opt { display: flex; gap: 8px; align-items: center; }
.q-edit .opt .letter { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-weight: 700; font-size: 12px; background: var(--bg-2); border: 1px solid var(--line); flex: none; }
.q-edit .opt .letter.ans { background: var(--good-bg); color: var(--good); border-color: var(--good-line); }
.q-edit .opt input { flex: 1; padding: 7px 10px; }
.q-edit .foot { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.q-edit .foot select { padding: 6px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); }
.mini { padding: 5px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); font-size: 12.5px; font-weight: 600; }
.mini:hover { border-color: var(--accent-line); }
.mini.danger { color: var(--bad); }

/* ── structure step ──────────────────────────────────────────────────── */

.field label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13.5px; }
.heading-list { display: grid; gap: 6px; }
.heading-row { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; padding: 8px 12px; border: 1px solid var(--line-soft); border-radius: 10px; background: var(--card); }
.heading-row .pg { font-size: 11.5px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.heading-row .txt { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.heading-row.off .txt { color: var(--muted); text-decoration: line-through; }
.heading-row select { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 13px; }
.heading-results { display: grid; gap: 4px; margin-top: 8px; max-height: 240px; overflow: auto; }
.heading-results button { text-align: left; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line-soft); background: var(--card); font-size: 13px; }
.heading-results button:hover { border-color: var(--accent-line); }
.heading-results button .pg { color: var(--muted); font-size: 11.5px; margin-right: 6px; }
@media (max-width: 600px) { .heading-row { grid-template-columns: 1fr auto; } .heading-row .pg { grid-column: 1 / -1; } }

/* ── set page ────────────────────────────────────────────────────────── */

.set-head { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 20px; }
.set-head h1 { font-size: 28px; flex: 1; min-width: 200px; }
.set-head .meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 22px; }
.mode {
  display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); text-decoration: none; color: inherit; font-weight: 700; box-shadow: var(--shadow); transition: border-color .12s, transform .1s;
}
.mode:hover { border-color: var(--accent); transform: translateY(-1px); }
.mode .ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 20px; background: var(--accent-soft); color: var(--accent); }
.mode small { display: block; font-weight: 500; color: var(--muted); font-size: 12.5px; }
.mode.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.mode.primary .ico { background: rgba(255,255,255,.18); color: inherit; }
.mode.primary small { color: inherit; opacity: .85; }

.mastery { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; padding: 18px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); margin-bottom: 22px; }
.ring { position: relative; width: 84px; height: 84px; }
.ring svg { transform: rotate(-90deg); }
.ring .track { stroke: var(--line-soft); }
.ring .fill { stroke: var(--good); transition: stroke-dashoffset .4s; }
.ring .pct { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 17px; }
.mastery .legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); }
.mastery .legend b { color: var(--ink); font-size: 18px; display: block; }
.mastery .legend i { display: inline-block; width: 8px; height: 8px; border-radius: 999px; margin-right: 6px; }

.terms { display: flex; flex-direction: column; gap: 8px; }
.terms h2 { font-size: 18px; margin: 8px 0 4px; }
.term { display: grid; grid-template-columns: minmax(56px, auto) 1fr auto; gap: 12px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line-soft); background: var(--card); align-items: start; }
.term .lab { font-weight: 700; color: var(--muted); font-size: 13px; padding-top: 2px; white-space: nowrap; }
.term .stem { font-size: 14.5px; white-space: pre-line; }
.term .chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.term .set-answer { display: inline-flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--warn); font-weight: 600; }
.term .set-answer select { padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.term .opts { display: flex; gap: 6px 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 4px; }
.term .opts .ans { color: var(--good); font-weight: 700; }
.term .state { display: flex; gap: 6px; align-items: center; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 8px; height: 8px; border-radius: 999px; background: var(--line); }
.dots i.on { background: var(--good); }
@media (max-width: 600px) { .term { grid-template-columns: 1fr; gap: 6px; } }

/* ── other questions folder ──────────────────────────────────────────── */

.pill.t-mcq   { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }
.pill.t-short { color: var(--good); background: var(--good-bg); border-color: var(--good-line); }
.pill.t-long  { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.pill.t-fill  { color: var(--bad); background: var(--bad-bg); border-color: var(--bad-line); }

.folder { margin-top: 26px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card-2); padding: 16px 18px; }
details.folder { padding: 0; }
details.folder summary { list-style: none; cursor: pointer; padding: 14px 18px; display: flex; flex-direction: column; gap: 2px; font-weight: 700; }
details.folder summary::-webkit-details-marker { display: none; }
details.folder summary::before { content: "📁 "; }
details.folder[open] summary::before { content: "📂 "; }
details.folder summary .hint { font-weight: 500; font-size: 12.5px; color: var(--muted); }
details.folder .folder-body { padding: 0 18px 16px; }
.folder-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.folder-head h2 { font-size: 18px; }
.folder-head h2 a { color: inherit; text-decoration: none; }
.folder-head h2 a:hover { color: var(--accent); }
.folder-count { font-size: 13px; color: var(--muted); }
.folder > .hint { font-size: 13px; color: var(--muted); margin: 4px 0 10px; }
.folder-group { margin-top: 12px; }
.folder-group h3 { font-size: 13px; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.folder-group h3 span { color: var(--muted); font-weight: 600; }
.other-item { border: 1px solid var(--line-soft); border-radius: 12px; background: var(--card); padding: 10px 14px; display: grid; gap: 6px; margin-bottom: 8px; }
.other-item .head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.other-item .head .lab { font-weight: 700; font-size: 13px; }
.other-item .head .spacer { flex: 1; }
.other-item .stem-text { font-size: 14.5px; white-space: pre-line; }

/* ── study (learn + flashcards) ──────────────────────────────────────── */

.study { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.study-top { display: flex; align-items: center; gap: 14px; padding: 12px 18px; }
.study-top .x { width: 38px; height: 38px; border-radius: 999px; border: 0; background: transparent; font-size: 20px; color: var(--muted); display: grid; place-items: center; }
.study-top .x:hover { background: var(--bg-2); color: var(--ink); }
.study-top .bar { flex: 1; height: 10px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.study-top .bar i { display: block; height: 100%; width: 0; background: var(--good); border-radius: 999px; transition: width .35s; }
.study-top .bar i.learn { background: var(--accent); }
.study-top .count { font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap; min-width: 6ch; text-align: right; }

.study-body { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 8px 18px 150px; }
.qcard {
  width: 100%; max-width: 720px; background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: var(--shadow-lg); padding: 28px; margin-top: 10px; animation: card-in .22s ease-out;
}
@keyframes card-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.qcard .tags { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.qcard .tags .spacer { flex: 1; }
.qcard .streak { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.qcard .stem { font-size: 21px; font-weight: 600; line-height: 1.4; margin-bottom: 22px; overflow-wrap: anywhere; white-space: pre-line; }
.qcard .prompt { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.opts-list { display: grid; gap: 10px; }
.opt-btn {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--card);
  font-size: 16px; line-height: 1.4; transition: border-color .1s, background .1s, transform .08s; overflow-wrap: anywhere;
}
.opt-btn:hover:not(:disabled) { border-color: var(--accent-line); background: var(--card-2); }
.opt-btn:active:not(:disabled) { transform: scale(.995); }
.opt-btn .letter {
  flex: none; width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  font-weight: 800; font-size: 13px; background: var(--bg-2); border: 1px solid var(--line); color: var(--muted);
}
.opt-btn .key { flex: none; margin-left: auto; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
.opt-btn:disabled { cursor: default; }
.opt-btn.correct { border-color: var(--good); background: var(--good-bg); }
.opt-btn.correct .letter { background: var(--good); color: #fff; border-color: var(--good); }
.opt-btn.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt-btn.wrong .letter { background: var(--bad); color: #fff; border-color: var(--bad); }
.opt-btn.dim { opacity: .55; }

.feedback {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  padding: 18px; border-top: 1px solid var(--line); background: var(--card);
  transform: translateY(100%); transition: transform .2s ease-out;
}
.feedback.show { transform: none; }
.feedback.good { background: var(--good-bg); border-color: var(--good-line); }
.feedback.bad  { background: var(--bad-bg);  border-color: var(--bad-line); }
.feedback.ask  { background: var(--accent-soft); border-color: var(--accent-line); }
.feedback.ask .mark { background: var(--accent); color: var(--accent-ink); }
.feedback.ask .txt b { color: var(--accent); }
.ask-btns { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; width: 100%; }
.ask-btns .ask-no { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }
.ask-btns .ask-letters { display: inline-flex; gap: 4px; }
.ask-btns .ask-letters .btn { padding: 8px 12px; min-width: 40px; }
.opt-btn.picked { border-color: var(--accent); background: var(--accent-soft); }
.opt-btn.picked .letter { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.feedback .in { max-width: 720px; margin: 0 auto; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.feedback .mark { width: 44px; height: 44px; border-radius: 999px; display: grid; place-items: center; font-size: 22px; font-weight: 800; flex: none; }
.feedback.good .mark { background: var(--good); color: #fff; }
.feedback.bad .mark { background: var(--bad); color: #fff; }
.feedback .txt { flex: 1; min-width: 200px; }
.feedback .txt b { display: block; font-size: 16px; }
.feedback.good .txt b { color: var(--good); }
.feedback.bad .txt b { color: var(--bad); }
.feedback .txt span { font-size: 13.5px; color: var(--muted); }
.feedback .btn { min-width: 150px; }
.feedback.good .btn.primary { background: var(--good); border-color: var(--good); color: #fff; }
.feedback.bad .btn.primary { background: var(--bad); border-color: var(--bad); color: #fff; }

.finish { text-align: center; max-width: 560px; margin: 30px auto 0; padding: 36px 24px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-lg); }
.finish .big { font-size: 56px; line-height: 1; margin-bottom: 12px; }
.finish h2 { font-size: 26px; margin-bottom: 8px; }
.finish p { color: var(--muted); margin-bottom: 18px; }
.finish .stats { margin: 18px 0 22px; text-align: left; }
.finish .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* the paper beside the cards */
.study-split { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.study-split.with-paper { display: grid; grid-template-columns: minmax(280px, 46%) minmax(0, 1fr); gap: 0; align-items: start; }
.study-split.with-paper .study-body { padding-top: 8px; }
.paper-pane { position: sticky; top: 62px; height: calc(100vh - 62px); display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--card-2); }
.paper-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.paper-bar .check { display: flex; align-items: center; gap: 6px; font-weight: 600; cursor: pointer; }
.paper-bar .spacer { flex: 1; }
.paper-bar .paper-pageno { font-weight: 700; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.paper-scroll { position: relative; flex: 1; overflow: auto; background: #1a1a1a; }
.paper-page { position: relative; }
.paper-page canvas { display: block; }
.paper-mask { position: absolute; inset: 0; background: #000; pointer-events: none; }
.paper-hole { position: absolute; pointer-events: none; box-shadow: 0 0 0 9999px #000; border-radius: 6px; outline: 2px solid var(--accent); }
.paper-pane.masked .paper-mask { display: none; }      /* the hole's shadow is the mask */
.paper-pane:not(.masked) .paper-hole { box-shadow: none; outline: 2px dashed var(--accent); }
.paper-note { padding: 6px 12px; font-size: 12.5px; color: var(--muted); min-height: 1.6em; }
/* figures and tables cut out of the paper, in place of their tag */
.fig-slot { display: block; margin: 10px 0; max-width: 100%; border: 2px solid var(--accent); border-radius: 8px; overflow: hidden; background: #fff; }
.fig-slot canvas { display: block; width: 100%; height: auto; }
.fig-slot .fig-label { display: block; padding: 8px 10px; font-size: 13px; font-weight: 500; color: var(--muted); text-transform: capitalize; }
.fig-slot.shown .fig-label { display: none; }
.fig-slot.missing { border-style: dashed; background: transparent; }
.opt-btn .fig-slot, .face .opts .fig-slot { margin: 6px 0 0; }
.fig-pill { text-transform: capitalize; }
.paper-toggle[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
@media (max-width: 900px) {
  .study-split.with-paper { grid-template-columns: 1fr; }
  .paper-pane { position: relative; top: 0; height: 46vh; border-right: 0; border-bottom: 1px solid var(--line); }
}

/* flashcards */
.flip-wrap { width: 100%; max-width: 720px; perspective: 1400px; margin-top: 10px; }
.flip { position: relative; width: 100%; min-height: 380px; transition: transform .45s cubic-bezier(.2,.7,.2,1); transform-style: preserve-3d; cursor: pointer; }
.flip.flipped { transform: rotateX(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-lg);
  padding: 28px; display: flex; flex-direction: column; overflow: auto;
}
.face.front { position: relative; min-height: 380px; }   /* in flow, so a card with a figure grows */
.face.back { transform: rotateX(180deg); }
.face .fig-slot canvas { width: auto; max-width: 100%; max-height: 280px; margin: 0 auto; }
.face .lab { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 14px; }
.face .stem { font-size: 21px; font-weight: 600; line-height: 1.4; overflow-wrap: anywhere; white-space: pre-line; }
.face .opts { display: grid; gap: 6px; margin-top: 18px; font-size: 15.5px; }
.face .opts div { display: flex; gap: 10px; }
.face .opts b { color: var(--muted); font-weight: 700; min-width: 20px; }
.face .answer { margin-top: auto; padding-top: 18px; font-size: 26px; font-weight: 750; color: var(--good); }
.face .answer small { display: block; font-size: 15px; font-weight: 500; color: var(--ink); margin-top: 4px; }
.face .answer.none { color: var(--muted); font-size: 20px; }
.face .hint { margin-top: auto; padding-top: 16px; font-size: 12.5px; color: var(--muted); text-align: center; }
.fc-nav { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 20px; }
.fc-nav .arrow { width: 52px; height: 52px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 20px; }
.fc-nav .arrow:hover { border-color: var(--accent); color: var(--accent); }
.fc-nav .n { font-weight: 700; color: var(--muted); min-width: 8ch; text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 40;
  transition: opacity .18s, transform .18s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .topbar .brand { flex: 1 0 100%; }
  .topbar .spacer { display: none; }
  .topbar > .btn { padding: 7px 10px; font-size: 12px; }
  .topbar .dev-toggle { margin-right: 0; }
  .topbar .theme-toggle { margin-left: auto; }
  .topbar .theme-toggle button { padding: 4px 7px; }
  .wrap { padding: 20px 14px 70px; }
  .panel { padding: 18px; }
  .qcard { padding: 20px; }
  .qcard .stem { font-size: 18px; }
  .opt-btn { font-size: 15px; padding: 12px 13px; }
  .opt-btn .key { display: none; }
  .face { padding: 20px; }
  .face .stem { font-size: 18px; }
  .hero h1 { font-size: 26px; }
}
