/* ---------- tokens ---------- */
:root {
  --desk: #ebe5d8;
  --page: #fffdf8;
  --page-2: #faf6ee;
  --ink: #24211c;
  --muted: #6d665b;
  --line: #e3dbcb;
  --accent: #0f6b5c;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0ec;
  --bad: #a3392b;
  --bad-soft: #f8e7e2;
  --good: #1f7a3a;
  --good-soft: #e3f2e7;
  --warn: #8a5a00;
  --warn-soft: #fbf0d6;
  --code-bg: #f5f0e6;
  --code-ink: #2b2720;
  --shadow: 0 1px 2px rgba(60, 40, 10, .08), 0 12px 40px rgba(60, 40, 10, .14);
  --spine: linear-gradient(90deg, rgba(60, 40, 10, .13), rgba(60, 40, 10, 0) 28px);
  --hl-kw: #8a2f6b; --hl-str: #2d6a1f; --hl-num: #9a4d00; --hl-com: #8b8374; --hl-type: #1f5a9a; --hl-fn: #6b4a00;

  --reader-size: 18px;
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --read: "Literata", Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --desk: #0f0f12; --page: #1b1a1f; --page-2: #211f25; --ink: #ebe6dc; --muted: #a49d91; --line: #2f2d34;
    --accent: #5fc4ae; --accent-ink: #0b1f1a; --accent-soft: #1a302b;
    --bad: #f19482; --bad-soft: #3a221e; --good: #85d59f; --good-soft: #1a2e21; --warn: #f0c46a; --warn-soft: #33291a;
    --code-bg: #131216; --code-ink: #e6e1d6;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 16px 48px rgba(0,0,0,.5);
    --spine: linear-gradient(90deg, rgba(0,0,0,.45), rgba(0,0,0,0) 28px);
    --hl-kw: #e89ad1; --hl-str: #9fd88a; --hl-num: #f3b36b; --hl-com: #7d776d; --hl-type: #8ec1f5; --hl-fn: #e8cf7a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --desk: #0f0f12; --page: #1b1a1f; --page-2: #211f25; --ink: #ebe6dc; --muted: #a49d91; --line: #2f2d34;
  --accent: #5fc4ae; --accent-ink: #0b1f1a; --accent-soft: #1a302b;
  --bad: #f19482; --bad-soft: #3a221e; --good: #85d59f; --good-soft: #1a2e21; --warn: #f0c46a; --warn-soft: #33291a;
  --code-bg: #131216; --code-ink: #e6e1d6;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 16px 48px rgba(0,0,0,.5);
  --spine: linear-gradient(90deg, rgba(0,0,0,.45), rgba(0,0,0,0) 28px);
  --hl-kw: #e89ad1; --hl-str: #9fd88a; --hl-num: #f3b36b; --hl-com: #7d776d; --hl-type: #8ec1f5; --hl-fn: #e8cf7a;
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--desk);
  color: var(--ink);
  font: 15px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.boot { display: grid; place-items: center; height: 100dvh; color: var(--muted); font-family: var(--read); font-style: italic; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--page); color: var(--ink);
  font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--page-2); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn { width: 42px; min-height: 42px; padding: 0; }
.icon { width: 20px; height: 20px; flex: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font: 600 12px/1 var(--ui); letter-spacing: .02em; white-space: nowrap;
}
.chip.muted { background: var(--page-2); color: var(--muted); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 10px;
  font-weight: 500; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(400px, 100%); background: var(--page); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 36px 28px; position: relative; overflow: hidden;
}
.login-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 28px; background: var(--spine); }
.login-card h1 { font: 700 28px/1.2 var(--read); margin: 0 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 13px; }
.field input {
  height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--page-2);
}
.field input:focus { border-color: var(--accent); outline: none; }
.error { color: var(--bad); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: color-mix(in srgb, var(--desk) 88%, transparent);
  backdrop-filter: blur(10px);
}
.topbar .title { flex: 1; min-width: 0; }
.topbar .title b { display: block; font: 600 15px/1.2 var(--ui); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .title span { font-size: 12px; color: var(--muted); }
.brand { display: flex; align-items: center; gap: 10px; font: 700 18px/1 var(--read); text-decoration: none; color: var(--ink); }
.brand svg { width: 28px; height: 28px; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 8px 16px 64px; }

/* ---------- dashboard ---------- */
.hero { display: grid; gap: 16px; grid-template-columns: 1.3fr 1fr; margin: 12px 0 28px; }
.panel { background: var(--page); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; position: relative; overflow: hidden; }
.panel.book::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 28px; background: var(--spine); pointer-events: none; }
.hero h1 { font: 700 clamp(24px, 4vw, 32px)/1.15 var(--read); margin: 0 0 8px; }
.hero p { margin: 0 0 18px; color: var(--muted); font-family: var(--read); font-size: 17px; }
.continue { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat { background: var(--page-2); border-radius: 12px; padding: 14px; }
.stat b { display: block; font: 700 26px/1.1 var(--read); font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--muted); }
.meter { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }

.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 12px 16px; margin: 8px 0 4px; font-weight: 500; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0 0 18px; }
.search { flex: 1; min-width: 200px; height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--page); }
.search:focus { outline: none; border-color: var(--accent); }

.week { margin: 0 0 28px; }
.week h2 { font: 600 13px/1 var(--ui); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; }
.days { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.day-tile {
  display: flex; flex-direction: column; gap: 8px; text-align: left; text-decoration: none; color: var(--ink);
  background: var(--page); border: 1px solid transparent; border-radius: 12px; padding: 16px; min-height: 132px;
  box-shadow: 0 1px 2px rgba(60,40,10,.06); transition: transform .15s, border-color .15s, box-shadow .15s; position: relative;
}
.day-tile:hover { transform: translateY(-2px); border-color: var(--line); box-shadow: var(--shadow); }
.day-tile .num { font: 600 12px/1 var(--ui); color: var(--accent); letter-spacing: .04em; }
.day-tile h3 { font: 600 17px/1.25 var(--read); margin: 0; flex: 1; }
.day-tile .meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.day-tile.done .num::after { content: " · complete"; color: var(--good); }
.day-tile.locked { opacity: .55; pointer-events: none; }
.results { display: grid; gap: 8px; margin-bottom: 24px; }
.result { display: flex; gap: 12px; align-items: center; padding: 12px 14px; background: var(--page); border-radius: 10px; text-decoration: none; color: var(--ink); }
.result:hover { outline: 1px solid var(--line); }
.result small { color: var(--muted); margin-left: auto; white-space: nowrap; }

/* ---------- reader / flipbook ---------- */
.reader { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; }
.progressline { height: 3px; background: var(--line); }
.progressline > i { display: block; height: 100%; background: var(--accent); transition: width .35s; }
.stage {
  position: relative; perspective: 2200px; perspective-origin: 0% 50%;
  width: min(820px, calc(100vw - 24px)); margin: 0 auto; padding: 6px 0 10px; min-height: 0;
  touch-action: pan-y;
}
.page {
  position: absolute; inset: 6px 0 10px; background: var(--page); border-radius: 6px var(--radius) var(--radius) 6px;
  box-shadow: var(--shadow); overflow: hidden; transform-origin: 0 50%; backface-visibility: hidden;
  will-change: transform;
}
.page::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 28px; background: var(--spine); pointer-events: none; z-index: 2; }
.page::after { /* page-stack edge on the right */
  content: ""; position: absolute; top: 8px; bottom: 8px; right: 0; width: 5px; pointer-events: none;
  background: repeating-linear-gradient(90deg, var(--line) 0 1px, transparent 1px 2.5px); opacity: .8;
}
.page .shade { position: absolute; inset: 0; pointer-events: none; opacity: 0; z-index: 3;
  background: linear-gradient(90deg, rgba(0,0,0,0), rgba(0,0,0,.28)); }
.page-scroll { height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 34px 44px 40px 56px; scroll-behavior: smooth; }
.page-foot { display: flex; justify-content: space-between; margin-top: 40px; padding-top: 14px; border-top: 1px solid var(--line);
  font: italic 13px/1 var(--read); color: var(--muted); }

.page.turn-next { animation: turnNext .62s cubic-bezier(.45,.05,.3,1) forwards; z-index: 5; }
.page.turn-next .shade { animation: shadeIn .62s forwards; }
.page.turn-prev { animation: turnPrev .62s cubic-bezier(.45,.05,.3,1) forwards; z-index: 5; }
.page.turn-prev .shade { animation: shadeOut .62s forwards; }
.page.under { z-index: 1; }
@keyframes turnNext { 0% { transform: rotateY(0); } 80% { opacity: 1; } 100% { transform: rotateY(-96deg); opacity: 0; } }
@keyframes turnPrev { 0% { transform: rotateY(-96deg); opacity: 0; } 20% { opacity: 1; } 100% { transform: rotateY(0); opacity: 1; } }
@keyframes shadeIn { to { opacity: 1; } }
@keyframes shadeOut { from { opacity: 1; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .page.turn-next, .page.turn-prev { animation-duration: .01s; }
}

.pager {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  width: min(820px, calc(100vw - 24px)); margin: 0 auto; padding: 4px 0 calc(10px + env(safe-area-inset-bottom));
}
.dots { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; flex: 1; min-width: 0; }
.dots button { width: 9px; height: 9px; border-radius: 50%; border: 0; padding: 0; background: var(--line); }
.dots button.on { background: var(--accent); transform: scale(1.3); }
.dots button.mastered { background: var(--good); }
.pager .count { font: 600 13px/1 var(--ui); color: var(--muted); font-variant-numeric: tabular-nums; }

/* reading typography */
.prose { font: 400 var(--reader-size)/1.68 var(--read); }
.prose p { margin: 0 0 .9em; }
.prose ul, .prose ol { margin: 0 0 .9em; padding-left: 1.3em; }
.prose li { margin: .25em 0; }
.prose strong { font-weight: 700; }
.prose h1, .prose h2, .prose h3, .prose h4 { font-family: var(--ui); line-height: 1.3; margin: 1.2em 0 .5em; }
.prose h3 { font-size: 1em; } .prose h4 { font-size: .95em; }
.prose blockquote { margin: 0 0 1em; padding: .2em 0 .2em 1em; border-left: 3px solid var(--accent); color: var(--ink); font-style: italic; }
.prose code { font: .84em var(--mono); background: var(--code-bg); padding: .1em .35em; border-radius: 5px; }
.prose pre { background: var(--code-bg); color: var(--code-ink); padding: 14px 16px; border-radius: 10px; overflow-x: auto; margin: 0 0 1em;
  font: 13.5px/1.55 var(--mono); border: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
.prose pre code { background: none; padding: 0; font: inherit; }
.prose table { border-collapse: collapse; width: 100%; font: 14.5px/1.45 var(--ui); margin: 0 0 1em; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--page-2); }
.prose > :last-child { margin-bottom: 0; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-literal { color: var(--hl-kw); }
.hljs-string, .hljs-attr + .hljs-string, .hljs-regexp { color: var(--hl-str); }
.hljs-number { color: var(--hl-num); }
.hljs-comment, .hljs-quote { color: var(--hl-com); font-style: italic; }
.hljs-type, .hljs-class .hljs-title, .hljs-title.class_, .hljs-meta { color: var(--hl-type); }
.hljs-title.function_, .hljs-attr, .hljs-attribute { color: var(--hl-fn); }

/* card page parts */
.card-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.card-title { font: 700 clamp(25px, 4.2vw, 34px)/1.15 var(--read); margin: 0 0 22px; letter-spacing: -.01em; }
.label { display: flex; align-items: center; gap: 8px; font: 700 12px/1 var(--ui); letter-spacing: .09em; text-transform: uppercase; color: var(--accent); margin: 30px 0 12px; }
.label::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.layman { background: var(--accent-soft); border-radius: 12px; padding: 18px 20px; }
.scenario-context { margin-bottom: 12px; }
.versus { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.versus > div { border-radius: 12px; padding: 14px 16px; font-size: calc(var(--reader-size) * .92); }
.versus h4 { font: 700 13px/1 var(--ui); margin: 0 0 8px !important; letter-spacing: .02em; }
.versus .without { background: var(--bad-soft); } .versus .without h4 { color: var(--bad); }
.versus .with { background: var(--good-soft); } .versus .with h4 { color: var(--good); }
.diagram { background: var(--page-2); border-radius: 12px; padding: 14px; overflow-x: auto; text-align: center; min-height: 60px; }
.diagram svg { max-width: 100%; height: auto; }
.diagram { cursor: zoom-in; position: relative; }
.diagram .zoom-hint { position: absolute; right: 10px; bottom: 8px; font: 600 11px/1 var(--ui); color: var(--muted); }
.diagram.zoomed { position: fixed; inset: 0; z-index: 40; border-radius: 0; padding: 48px 16px 16px; overflow: auto; cursor: zoom-out; background: var(--page); display: block; }
.diagram.zoomed svg { max-width: none !important; min-width: min(1100px, 240vw); }
.diagram.zoomed .zoom-hint { position: fixed; top: 16px; right: 16px; bottom: auto; font-size: 13px; }
.example { border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px 6px; margin-bottom: 14px; }
.example-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font: 600 15px/1.3 var(--ui); margin-bottom: 12px; }
.more-examples[hidden] { display: none; }
.say { position: relative; background: var(--page-2); border-radius: 12px; padding: 18px 20px; border-left: 4px solid var(--accent); }
.say-actions { display: flex; gap: 6px; margin-top: 10px; }

.quiz-q { margin: 0 0 18px; }
.quiz-q > p { font-weight: 600; margin: 0 0 10px; font-family: var(--ui); font-size: 15.5px; }
.opts { display: grid; gap: 8px; }
.opt { text-align: left; border: 1px solid var(--line); background: var(--page); border-radius: 10px; padding: 11px 14px; font: 15px/1.4 var(--ui); display: flex; gap: 10px; align-items: flex-start; }
.opt:hover { border-color: var(--muted); }
.opt .k { font-weight: 700; color: var(--muted); width: 18px; flex: none; }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt[disabled] { cursor: default; }
.why { margin-top: 10px; font-size: calc(var(--reader-size) * .88); padding: 12px 14px; background: var(--page-2); border-radius: 10px; }

.fu { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.fu-q { width: 100%; text-align: left; background: none; border: 0; padding: 14px 16px; display: flex; gap: 12px; align-items: flex-start; font: 600 15.5px/1.4 var(--ui); }
.fu-q .n { color: var(--accent); flex: none; }
.fu-q .st { margin-left: auto; flex: none; }
.fu-body { padding: 0 16px 14px; }
.fu-body[hidden] { display: none; }
.think { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.rate { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.rate .btn.on-again { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.rate .btn.on-good { background: var(--good-soft); border-color: var(--good); color: var(--good); }

.notes textarea { width: 100%; min-height: 110px; resize: vertical; border: 1px solid var(--line); background: var(--page-2);
  border-radius: 10px; padding: 12px; font: 15px/1.5 var(--ui); }
.notes textarea:focus { outline: none; border-color: var(--accent); }
.notes small { color: var(--muted); }
.card-end { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; margin-top: 30px; padding: 16px; border-radius: 12px; background: var(--page-2); }

/* cover + end pages */
.cover { display: flex; flex-direction: column; justify-content: center; min-height: 100%; }
.cover .kicker { font: 600 13px/1 var(--ui); letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.cover h1 { font: 700 clamp(32px, 6vw, 48px)/1.08 var(--read); margin: 14px 0 14px; letter-spacing: -.015em; }
.cover .goal { font: italic 400 20px/1.5 var(--read); color: var(--muted); margin: 0 0 26px; max-width: 34em; }
.toc { list-style: none; padding: 0; margin: 0 0 28px; counter-reset: toc; }
.toc li { display: flex; align-items: baseline; gap: 10px; padding: 9px 0; border-bottom: 1px dotted var(--line); font: 17px/1.35 var(--read); cursor: pointer; }
.toc li::before { counter-increment: toc; content: counter(toc, decimal-leading-zero); font: 600 12px var(--mono); color: var(--muted); }
.toc li > span:first-child { flex: 1; }
.toc li:hover > span:first-child { color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin-top: 16px; }

/* practice (flashcards) */
.flash-stage { perspective: 1600px; width: min(720px, 100%); margin: 0 auto; }
.flash { position: relative; min-height: 380px; transition: transform .6s cubic-bezier(.45,.05,.3,1); transform-style: preserve-3d; }
.flash.flipped { transform: rotateY(180deg); }
.flash > div { position: absolute; inset: 0; backface-visibility: hidden; background: var(--page); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; overflow-y: auto; }
.flash .back { transform: rotateY(180deg); }
.flash .front { display: flex; flex-direction: column; justify-content: center; }
.flash .front h2 { font: 700 clamp(22px, 4vw, 28px)/1.3 var(--read); margin: 10px 0 18px; }
.flash-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 18px 0; }
.segmented { display: inline-flex; background: var(--page); border-radius: 10px; padding: 3px; gap: 2px; border: 1px solid var(--line); flex-wrap: wrap; }
.segmented button { border: 0; background: none; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--muted); }
.segmented button.on { background: var(--accent); color: var(--accent-ink); }

.settings { display: grid; gap: 16px; max-width: 640px; }
.settings h2 { font: 600 17px/1.2 var(--ui); margin: 0 0 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; }
  .page-scroll { padding: 24px 18px 30px 30px; }
  .page::before { width: 18px; }
  .versus { grid-template-columns: 1fr; }
  .stage { width: calc(100vw - 16px); }
  .pager { width: calc(100vw - 16px); }
  .topbar { padding-left: 10px; padding-right: 10px; }
  .hide-sm { display: none !important; }
  .flash { min-height: 440px; }
}
@media (min-width: 1200px) { .stage, .pager { width: 860px; } }
@media print {
  .topbar, .pager { display: none; }
  .page { position: static; box-shadow: none; }
}

/* ---------- day overview infographic (fixed light poster palette) ---------- */
.ov-wrap { container-type: inline-size; }
.ov {
  --n1: #0f2a4a; --n2: #1d4270; --amber: #f5b83d; --ink2: #13233a; --mut2: #4b5b70;
  --blue-t: #eef4fc; --red-t: #fdeeee; --red: #b42318; --green-t: #edf7ee; --green: #15803d; --yellow-t: #fff8e1;
  background: #f3f6fb; color: var(--ink2); font-family: var(--ui); border-radius: 14px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(15, 42, 74, .12);
}
.ov-head { background: linear-gradient(135deg, var(--n1), var(--n2)); color: #fff; padding: 30px 32px 26px; display: flex; gap: 20px; align-items: flex-start; }
.ov-headtext { flex: 1; min-width: 0; }
.ov-head h2 { font: 800 42px/1.12 var(--ui); margin: 0 0 12px; letter-spacing: -.02em; }
.ov-head h2 em { font-style: normal; color: var(--amber); }
.ov-head p { margin: 0; font-size: 19px; color: #d6e2f3; line-height: 1.4; }
.ov-badge { border: 1px solid rgba(255,255,255,.35); border-radius: 12px; padding: 12px 16px; flex: none; }
.ov-badge b { display: block; font-size: 22px; margin-bottom: 6px; }
.ov-badge span { font-size: 13px; color: #d6e2f3; line-height: 1.3; }
.ov-grid { display: grid; grid-template-columns: 1fr 1.05fr 1.15fr; gap: 16px; padding: 18px; }
.ov-panel { background: var(--blue-t); border-radius: 12px; padding: 18px 20px; }
.ov-panel h3 { font: 800 19px/1.25 var(--ui); margin: 0 0 12px; display: flex; gap: 8px; align-items: center; color: var(--ink2); }
.ov-panel p { margin: 0 0 12px; font-size: 15.5px; line-height: 1.5; color: var(--mut2); }
.ov-panel b { font-weight: 700; color: var(--ink2); }
.ov-panel small { display: block; font-size: 13.5px; color: var(--mut2); line-height: 1.35; margin-top: 2px; }
.ov-i { display: inline-flex; width: 22px; height: 22px; flex: none; }
.ov-i svg { width: 100%; height: 100%; }
.ov-i.circle { width: 46px; height: 46px; border-radius: 50%; background: #dbe7f7; color: var(--n1); padding: 11px; }
.ov-i.big { width: 38px; height: 38px; color: #2563eb; }
.ov-flow ol, .ov-check ol, .ov-pit ul { list-style: none; margin: 0; padding: 0; }
.ov-flow li { display: flex; gap: 14px; align-items: center; }
.ov-flow li b { font-size: 16.5px; }
.ov-flow li.arrow { color: var(--mut2); padding-left: 16px; height: 22px; font-size: 16px; }
.ov-idea { display: flex; flex-direction: column; }
.ov-chips { margin-top: auto; background: var(--green-t); border-radius: 12px; padding: 18px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; }
.ov-chip { background: #fff; border: 1px solid #cfe3d3; color: var(--green); font-weight: 800; font-size: 16px; padding: 8px 14px; border-radius: 10px; }
.ov-chips .plus { font-size: 22px; color: var(--mut2); }
.ov-trap { background: var(--red-t); }
.ov-trap h3 { color: var(--red); }
.ov-trap h3 .ov-i { color: var(--red); }
.ov-vs { display: grid; gap: 10px; }
.ov-vs > div { display: flex; gap: 10px; align-items: flex-start; border-radius: 10px; padding: 11px 13px; font-size: 14.5px; line-height: 1.4; font-weight: 600; }
.ov-vs .bad { background: #fbd5d2; color: #7a1d14; }
.ov-vs .good { background: #d5eed9; color: #14532d; }
.ov-vs .ov-i { width: 20px; height: 20px; }
.ov-check { background: #fff; border: 1px solid #e3eaf4; }
.ov-check li { display: flex; gap: 12px; align-items: flex-start; padding: 7px 0; }
.ov-check .num { width: 30px; height: 30px; border-radius: 50%; color: #fff; font-weight: 800; display: grid; place-items: center; flex: none; font-size: 14.5px; }
.ov-check b { font-size: 15.5px; }
.ov-pit { background: #fff; border: 1px solid #e3eaf4; }
.ov-pit li { display: flex; gap: 14px; align-items: flex-start; padding: 9px 0; }
.ov-pit b { font-size: 15.5px; }
.ov-stack { display: grid; gap: 16px; align-content: start; }
.ov-take { background: var(--green-t); }
.ov-take h3 { color: var(--green); }
.ov-take blockquote { margin: 0 0 12px; background: var(--yellow-t); border: 1px solid #f1d98a; border-radius: 12px; padding: 14px 16px; display: flex; gap: 10px;
  font: italic 700 18px/1.4 var(--ui); color: var(--ink2); }
.ov-take blockquote .ov-i { color: #d49a00; width: 26px; height: 26px; }
.ov-next { display: flex; gap: 14px; align-items: flex-start; }
.ov-next h3 { margin-bottom: 6px; }
.ov-next p { margin: 0; }
.ov-foot { background: var(--n1); color: #fff; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 28px; font-size: 15px; flex-wrap: wrap; }
.ov-foot i { font-style: normal; opacity: .5; margin: 0 12px; }
.ov-foot .sig { font: italic 20px var(--read); color: #d6e2f3; }
.ov-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
.ov-export-host { position: fixed; left: -10000px; top: 0; width: 1200px; }
.ov-export-host .ov { border-radius: 0; box-shadow: none; }
@container (max-width: 820px) {
  .ov-grid { grid-template-columns: 1fr 1fr; }
  .ov-stack { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; }
}
@container (max-width: 560px) {
  .ov-head { flex-direction: column-reverse; padding: 22px 20px; }
  .ov-head h2 { font-size: 28px; }
  .ov-head p { font-size: 16px; }
  .ov-grid { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .ov-stack { grid-template-columns: 1fr; }
  .ov-foot { padding: 14px 18px; }
}
/* gallery */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.thumb { display: block; text-decoration: none; color: var(--ink); background: var(--page); border-radius: 12px; overflow: hidden; box-shadow: 0 1px 2px rgba(60,40,10,.08); transition: transform .15s, box-shadow .15s; }
.thumb:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.thumb .frame { position: relative; overflow: hidden; aspect-ratio: 1200 / 1000; background: #f3f6fb; }
.thumb .frame .ov-wrap { position: absolute; top: 0; left: 0; width: 1200px; transform-origin: 0 0; pointer-events: none; }
.thumb .cap { padding: 10px 14px; font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; gap: 10px; }
.thumb .cap span { color: var(--muted); font-weight: 500; }
.page-scroll .ov-wrap { margin: -8px -14px 0 -20px; }
@media (max-width: 760px) { .page-scroll .ov-wrap { margin: -6px 0 0 -6px; } }

/* course library */
.courses { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.course { background: var(--page); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 22px 20px 40px; position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 10px; }
.course::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 22px; background: var(--spine); }
.course h2 { font: 700 23px/1.2 var(--read); margin: 0; }
.course p { margin: 0; color: var(--muted); font: 16px/1.5 var(--read); flex: 1; }
.course-top { display: flex; gap: 6px; }
.course-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.course .row { margin-top: 6px; }

/* ---------- badges (separate module: badges-ui.js) ---------- */
.medal { display: inline-grid; place-items: center; border-radius: 50%; flex: none; color: #fff; position: relative;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.18), 0 2px 6px rgba(0,0,0,.15); }
.medal svg { width: 52%; height: 52%; }
.medal.md { width: 46px; height: 46px; } .medal.sm { width: 26px; height: 26px; vertical-align: middle; } .medal.lg { width: 64px; height: 64px; }
.medal.bronze { background: radial-gradient(circle at 35% 30%, #e7a36b, #a8622e); }
.medal.silver { background: radial-gradient(circle at 35% 30%, #e3e8ef, #8b95a5); color: #2b3440; }
.medal.gold { background: radial-gradient(circle at 35% 30%, #ffe082, #c9960c); color: #4a3500; }
.medal.special { background: radial-gradient(circle at 35% 30%, #7fe0cb, #0f6b5c); }
.medal.locked { background: var(--page-2); color: var(--muted); box-shadow: inset 0 0 0 2px var(--line); filter: grayscale(1); opacity: .7; }
.shelf { margin: 0 0 24px; }
.shelf-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.shelf-head h2 { font: 700 20px/1 var(--read); margin: 0; }
.shelf-head h2 span { font: 500 13px var(--ui); color: var(--muted); margin-left: 8px; }
.shelf-row { display: flex; gap: 10px; flex-wrap: wrap; }
.shelf-next { margin: 14px 0 0; font-size: 14px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.shelf-next b { color: var(--ink); }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.badge-card { display: flex; gap: 14px; align-items: flex-start; background: var(--page); border-radius: 12px; padding: 16px; }
.badge-card b { font: 700 17px/1.2 var(--read); }
.badge-card p { margin: 4px 0 10px; font-size: 14px; color: var(--muted); }
.badge-card small { color: var(--muted); font-size: 12px; }
.badge-card > div { flex: 1; min-width: 0; }
.badge-toast { position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top)); z-index: 60; transform: translate(-50%, -30px) scale(.96); opacity: 0;
  display: flex; gap: 14px; align-items: center; background: var(--page); color: var(--ink); border-radius: 16px; padding: 14px 20px 14px 14px;
  box-shadow: var(--shadow); border: 1px solid var(--line); transition: .35s cubic-bezier(.2,.9,.3,1.3); max-width: calc(100vw - 32px); }
.badge-toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.badge-toast small { display: block; font: 700 11px var(--ui); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.badge-toast b { display: block; font: 700 18px/1.2 var(--read); }
.badge-toast span { font-size: 13px; color: var(--muted); }

/* ---------- logo ---------- */
.brand img { display: block; border-radius: 7px; }
.login-logo { display: block; border-radius: 16px; margin: 0 0 16px; box-shadow: 0 6px 18px rgba(22, 38, 74, .25); }

/* ---------- full-screen reading ---------- */
.fs-exit { display: none; }
.reader.immersive { grid-template-rows: 0 1fr auto; }
.reader.immersive .reader-top { overflow: hidden; }
.reader.immersive .fs-exit {
  display: inline-flex; position: fixed; z-index: 20; top: calc(8px + env(safe-area-inset-top)); right: 10px;
  background: color-mix(in srgb, var(--page) 80%, transparent); backdrop-filter: blur(8px); opacity: .75;
}
.reader.immersive .fs-exit:hover { opacity: 1; }
.reader.immersive .stage { width: min(860px, 100vw); padding-top: env(safe-area-inset-top); }
.reader.immersive .page { inset: 0; }

/* ---------- mobile: use the whole width for reading ---------- */
@media (max-width: 760px) {
  .stage { width: 100vw; padding: 0; }
  .page { inset: 0; border-radius: 0; box-shadow: none; }
  .page::before { width: 5px; }
  .page::after { display: none; }
  .page-scroll { padding: 18px 16px 26px 18px; }
  .pager { width: 100vw; padding: 6px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--page); border-top: 1px solid var(--line); }
  .layman, .say { padding: 14px 14px; }
  .versus > div { padding: 12px 13px; }
  .example { padding: 12px 12px 4px; }
  .prose pre { margin-left: -4px; margin-right: -4px; padding: 12px; }
  .card-title { margin-bottom: 16px; }
  .label { margin: 24px 0 10px; }
  .page-scroll .ov-wrap { margin: -4px -6px 0 -8px; }
  .reader.immersive .fs-exit { top: calc(6px + env(safe-area-inset-top)); right: 6px; }
}

/* people (admin) */
.people { display: grid; gap: 8px; }
.person { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-radius: 10px; background: var(--page-2); }
.person small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
@media (max-width: 760px) { .badge-toast { width: min(380px, calc(100vw - 24px)); } }

/* ---------- dialogs (centered on desktop, bottom sheet on phones) ---------- */
dialog.sheet { border: 0; padding: 0; border-radius: 16px; background: var(--page); color: var(--ink); width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px); box-shadow: var(--shadow); }
dialog.sheet::backdrop { background: rgba(10, 12, 20, .45); backdrop-filter: blur(2px); }
dialog.sheet form { padding: 22px 22px 18px; display: grid; gap: 4px; overflow-y: auto; max-height: calc(100dvh - 32px); }
dialog.sheet h2 { font: 700 21px/1.25 var(--read); margin: 0 0 6px; }
.sheet-intro p { margin: 0 0 10px; color: var(--muted); font-size: 14.5px; line-height: 1.5; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input { flex: 1; min-width: 0; width: 100%; }
.input-wrap .btn { position: absolute; right: 4px; min-height: 36px; }
.input-wrap input[type="password"], .input-wrap input:has(+ .btn) { padding-right: 70px; }
.field small.hint { margin-top: 4px; font-size: 12.5px; }
pre.share { background: var(--page-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: 14px/1.5 var(--mono); white-space: pre-wrap; word-break: break-all; margin: 0 0 8px; }
.forgot { width: 100%; margin-top: 8px; color: var(--muted); }
.person-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.person .who { min-width: 0; }
.field input { width: 100%; min-width: 0; }
@media (max-width: 760px) {
  input, textarea, select { font-size: 16px !important; }   /* stops iOS zooming into fields */
  dialog.sheet { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 92dvh; }
  dialog.sheet form { padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 92dvh; }
  .sheet-actions { flex-direction: column-reverse; }
  .sheet-actions .btn { width: 100%; }
  .person { flex-direction: column; align-items: stretch; }
  .person-actions .btn { flex: 1; }
  .settings .row > .field { flex: 1 1 100% !important; }
}
