:root {
  --bg: #f6f3ec;
  --card: #fffdf8;
  --ink: #1c2629;
  --muted: #5f6b6d;
  --line: #e3ddd0;
  --accent: #0f6e6e;
  --accent-ink: #ffffff;
  --accent-soft: #dcefeb;
  --good: #2b8a4b;
  --good-soft: #def2e3;
  --bad: #c0412b;
  --bad-soft: #fbe3dc;
  --warn-soft: #fbf0d4;
  --shadow: 0 1px 2px rgba(28, 38, 41, .06), 0 4px 16px rgba(28, 38, 41, .06);
  --radius: 14px;
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111617;
    --card: #192022;
    --ink: #e6ecea;
    --muted: #9aa7a6;
    --line: #2b3436;
    --accent: #4fb3a6;
    --accent-ink: #0b1414;
    --accent-soft: #1d3633;
    --good: #5cc27e;
    --good-soft: #1b3324;
    --bad: #ef7d63;
    --bad-soft: #3a211b;
    --warn-soft: #3a3220;
    --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(--sans);
  min-height: 100vh;
}
main {
  max-width: 780px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: var(--serif); font-weight: 650; line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.05rem; font-family: var(--sans); font-weight: 650; letter-spacing: 0; }
p { margin: 0 0 .8em; }
a { color: var(--accent); }
img { max-width: 100%; display: block; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; min-height: 44px; }
.topbar .title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand { display: flex; align-items: center; gap: 10px; margin: 8px 0 4px; }
.brand svg { width: 38px; height: 38px; flex: none; }
.brand h1 { margin: 0; }

/* Buttons */
button, .btn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 18px;
  min-height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
}
button:active, .btn:active { transform: scale(.98); }
button:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn-big { padding: 14px 22px; font-size: 1.05rem; min-height: 54px; border-radius: 16px; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--bad); }
.icon-btn { width: 44px; height: 44px; padding: 0; border-radius: 50%; flex: none; }
.link-btn { background: none; border: none; padding: 0; min-height: 0; color: var(--accent); text-decoration: underline; border-radius: 0; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.nb-card { display: block; color: inherit; text-decoration: none; }
.nb-card h2 { margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { background: var(--accent-soft); color: var(--ink); border-radius: 999px; padding: 3px 10px; font-size: .85rem; }
.chip-plain { background: transparent; border: 1px solid var(--line); }
.stat { font-variant-numeric: tabular-nums; }
.notice { background: var(--warn-soft); border-radius: 12px; padding: 10px 14px; font-size: .92rem; }
.empty { text-align: center; padding: 28px 16px; }

/* Forms */
label { display: block; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=search], textarea, select {
  font: inherit;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }
.topic-row { position: relative; }
.topic-row .row { flex-wrap: nowrap; }
.match { display: flex; gap: 10px; align-items: center; margin-top: 8px; padding: 8px; border-radius: 10px; background: var(--accent-soft); }
.match img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; flex: none; }
.match .t { font-weight: 600; }
.match.none { background: var(--bad-soft); }
.match select { margin-top: 6px; padding: 6px 10px; font-size: .9rem; }

/* Progress */
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .3s ease; }
.build-list li { margin: 8px 0; }
.build-list .ok { color: var(--good); }
.build-list .err { color: var(--bad); }

/* Notebook topic list */
.topic-list { list-style: none; padding: 0; margin: 0; }
.topic-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.topic-list li:first-child { border-top: none; }
.topic-list img, .topic-list .ph { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex: none; background: var(--line); }
.topic-list .grow { flex: 1; min-width: 0; }
.topic-list .name { font-weight: 600; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 6px; max-width: 220px; }
.bar > div { height: 100%; background: var(--good); }

.actions-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }

/* Learn cards */
.teach-photo { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; cursor: zoom-in; }
.teach-photo img { width: 100%; max-height: 60vh; object-fit: contain; margin: 0 auto; }
.credit { font-size: .78rem; color: var(--muted); margin-top: 6px; overflow-wrap: anywhere; }
.credit a { color: var(--muted); }
.section-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin: 18px 0 6px; }
.bullets { margin: 0; padding-left: 1.2em; }
.bullets li { margin: 5px 0; }
.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.strip button { padding: 0; border: none; border-radius: 10px; overflow: hidden; flex: none; width: 92px; height: 92px; scroll-snap-align: start; background: var(--line); }
.strip img { width: 100%; height: 100%; object-fit: cover; }
.pager { display: flex; justify-content: space-between; gap: 10px; margin-top: 20px; }
.dots { display: flex; gap: 6px; justify-content: center; margin: 10px 0 0; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots span.on { background: var(--accent); }
.compare { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x mandatory; }
.compare .card { margin: 0; scroll-snap-align: start; }
.compare img { width: 100%; height: 180px; object-fit: cover; border-radius: 10px; cursor: zoom-in; }
.notes-saved { font-size: .8rem; color: var(--good); margin-left: 8px; }

/* Quiz */
.quiz-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.quiz-head .progress { flex: 1; }
.quiz-photo { background: #000; border-radius: var(--radius); overflow: hidden; display: flex; align-items: center; justify-content: center; min-height: 220px; cursor: zoom-in; position: relative; }
.quiz-photo img { max-height: 58vh; width: 100%; object-fit: contain; }
.quiz-photo .zoom-hint { position: absolute; right: 10px; bottom: 10px; background: rgba(0,0,0,.55); color: #fff; font-size: .75rem; padding: 3px 8px; border-radius: 99px; pointer-events: none; }
.quiz-photo .loading { color: #bbb; padding: 40px; }
.choices { display: grid; gap: 10px; margin-top: 14px; }
.choice { justify-content: flex-start; text-align: left; border-radius: 14px; padding: 12px 16px; min-height: 52px; font-weight: 500; }
.choice .key { display: inline-flex; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); align-items: center; justify-content: center; font-size: .8rem; color: var(--muted); flex: none; }
.choice.right { background: var(--good-soft); border-color: var(--good); }
.choice.wrong { background: var(--bad-soft); border-color: var(--bad); }
.feedback { margin-top: 14px; border-radius: var(--radius); padding: 14px 16px; }
.feedback.right { background: var(--good-soft); }
.feedback.wrong { background: var(--bad-soft); }
.feedback h3 { margin-bottom: 6px; }
.score-big { font-family: var(--serif); font-size: 3rem; font-weight: 650; line-height: 1; }
.missed-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.missed-grid figure { margin: 0; }
.missed-grid img { width: 100%; height: 130px; object-fit: cover; border-radius: 10px; cursor: zoom-in; }
.missed-grid figcaption { font-size: .8rem; margin-top: 4px; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.check { display: flex; gap: 10px; align-items: center; font-weight: 500; padding: 6px 0; margin: 0; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* Photo manager */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; }
.tabs button { white-space: nowrap; }
.tabs button[aria-selected=true] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.grid button { padding: 0; border: none; border-radius: 10px; overflow: hidden; aspect-ratio: 1; background: var(--line); position: relative; min-height: 0; }
.grid img { width: 100%; height: 100%; object-fit: cover; }
.grid .badge { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: .7rem; padding: 2px 6px; border-radius: 99px; }
.grid.dim img { opacity: .55; }
details { margin-top: 18px; }
summary { cursor: pointer; font-weight: 600; padding: 8px 0; }

/* Viewer (full-screen photo) */
.viewer { position: fixed; inset: 0; background: #0b0b0b; z-index: 50; display: flex; flex-direction: column; color: #eee; }
.viewer[hidden] { display: none; }
.viewer .v-top { display: flex; justify-content: space-between; align-items: center; padding: max(10px, env(safe-area-inset-top)) 10px 6px; gap: 8px; }
.viewer .v-img { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: auto; touch-action: pan-x pan-y pinch-zoom; }
.viewer .v-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .v-img img.zoomed { max-width: none; max-height: none; width: 200%; cursor: zoom-out; }
.viewer .v-bottom { padding: 10px 14px calc(14px + env(safe-area-inset-bottom)); max-height: 40vh; overflow: auto; }
.viewer .v-bottom p { margin: 0 0 6px; font-size: .9rem; color: #ccc; }
.viewer button { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.2); }
.viewer .v-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.viewer select { background: #222; color: #fff; border-color: #444; width: auto; padding: 8px 12px; }
.viewer a { color: #9fd9d1; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; z-index: 60; font-size: .92rem; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
.toast[hidden] { display: none; }

.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: 48px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); min-width: 210px; z-index: 20; padding: 6px; }
.menu-list button { width: 100%; justify-content: flex-start; border: none; border-radius: 8px; background: transparent; }
.menu-list button:hover { background: var(--accent-soft); }

footer.site { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); font-size: .88rem; color: var(--muted); }
footer.site .row { gap: 6px 16px; }

@media (min-width: 640px) {
  .choices.two-col { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 2.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
