:root {
  --bg: #0e0f13;
  --surface: #171922;
  --surface-2: #20232f;
  --line: #2b2f3d;
  --text: #ece8e1;
  --muted: #9a9aa8;
  --accent: #f2b56b;
  --accent-ink: #1b1308;
  --teal: #7fc8c2;
  --good: #7bd88f;
  --bad: #ff8a80;
  --radius: 18px;
  --tabbar: calc(62px + env(safe-area-inset-bottom));
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); }
body { overscroll-behavior: none; }
a { color: var(--teal); }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 650; line-height: 1.2; margin: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#view { height: calc(100dvh - var(--tabbar)); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.page { padding: calc(18px + env(safe-area-inset-top)) 16px 32px; max-width: 640px; margin: 0 auto; }
.page > h1 { font-size: 30px; margin-bottom: 4px; }
.sub { color: var(--muted); margin: 0 0 18px; }

/* ---------- tab bar */
.tabbar {
  position: fixed; inset: auto 0 0 0; height: var(--tabbar); padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr); background: rgba(14, 15, 19, .94);
  backdrop-filter: blur(14px); border-top: 1px solid var(--line); z-index: 20;
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 500; }
.tabbar a.on { color: var(--accent); }

/* ---------- buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 500; cursor: pointer; text-decoration: none; color: var(--text); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--line); background: rgba(23, 25, 34, .8); cursor: pointer; }
input[type=text], input[type=url], input[type=password], input[type=date], input[type=number], textarea, select {
  width: 100%; min-height: 46px; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); outline: none;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus { border-color: var(--accent); }
label.field { display: block; margin: 0 0 14px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

/* ---------- feed */
.feed-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10; padding: calc(10px + env(safe-area-inset-top)) 12px 18px;
  display: flex; gap: 8px; align-items: center; background: linear-gradient(var(--bg) 30%, transparent);
  pointer-events: none;
}
.feed-top > * { pointer-events: auto; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.chip { flex: none; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: rgba(23, 25, 34, .85); font-size: 13px; font-weight: 500; cursor: pointer; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.feed { height: 100%; overflow-y: scroll; scroll-snap-type: y mandatory; scrollbar-width: none; }
.feed::-webkit-scrollbar { display: none; }
.card {
  height: 100%; scroll-snap-align: start; scroll-snap-stop: always; position: relative;
  display: flex; flex-direction: column; padding: calc(64px + env(safe-area-inset-top)) 18px 16px; overflow: hidden;
}
.card-inner { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; max-width: 620px; width: 100%; margin: 0 auto; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.pill { padding: 3px 10px; border-radius: 999px; background: hsla(var(--h, 35), 70%, 65%, .16); color: hsl(var(--h, 35), 75%, 74%); font-weight: 600; font-size: 12px; }
.seen-dot::before { content: "seen"; font-size: 11px; color: var(--muted); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; }

.card.art { background: radial-gradient(120% 70% at 100% 0%, hsla(var(--h), 60%, 45%, .22), transparent 60%), var(--bg); }
.art .title { font-size: clamp(22px, 6.2vw, 30px); margin-bottom: 10px; }
.art .authors { color: var(--muted); font-size: 13px; margin: 0 0 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.abstract { color: #d6d2cb; font-size: 15px; line-height: 1.6; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 9; -webkit-box-orient: vertical; }
.abstract.open { -webkit-line-clamp: unset; overflow-y: auto; display: block; max-height: 52vh; }
.linkish { background: none; border: 0; color: var(--teal); padding: 6px 0; cursor: pointer; font-weight: 500; text-align: left; }

.actions { display: flex; gap: 8px; justify-content: center; padding-top: 12px; max-width: 620px; width: 100%; margin: 0 auto; }
.actions .btn { flex: 1; min-width: 0; padding: 0 10px; font-size: 14px; }
.btn.saved { color: var(--accent); border-color: var(--accent); }

.card.vid { padding-left: 0; padding-right: 0; background: #000; }
.player { flex: 1; min-height: 0; display: grid; place-items: center; position: relative; }
.player iframe { border: 0; width: 100%; height: 100%; }
.player.r169 iframe { height: auto; aspect-ratio: 16 / 9; }
.player.portrait iframe { max-width: 420px; }
.thumb { width: 100%; height: 100%; object-fit: contain; opacity: .7; }
.vmeta { padding: 12px 18px 0; }
.vmeta h3 { font-family: var(--sans); font-size: 16px; font-weight: 600; }
.vmeta p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.vid .actions { padding-left: 18px; padding-right: 18px; }

.card.quiz { background: radial-gradient(100% 60% at 0% 100%, rgba(127, 200, 194, .16), transparent 60%), var(--bg); }
.quiz .q { font-family: var(--serif); font-size: clamp(20px, 5.6vw, 26px); margin-bottom: 18px; }
.opt { display: block; width: 100%; text-align: left; padding: 13px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); margin-bottom: 9px; cursor: pointer; line-height: 1.4; }
.opt.right { border-color: var(--good); background: rgba(123, 216, 143, .12); }
.opt.wrong { border-color: var(--bad); background: rgba(255, 138, 128, .1); }
.opt:disabled { cursor: default; color: var(--text); }
.explain-box { margin-top: 6px; padding: 14px 16px; border-radius: 14px; background: var(--surface-2); font-size: 14.5px; }
.verdict { font-weight: 600; margin-bottom: 4px; }
.verdict.good { color: var(--good); } .verdict.bad { color: var(--bad); }

.card.end { text-align: center; }
.end .moon { font-size: 54px; }
.end h2 { font-size: 28px; margin: 10px 0; }

/* ---------- lists & panels */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.panel h3 { font-size: 18px; margin-bottom: 10px; }
.section-title { font: 600 12px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 26px 0 10px; }
.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--text); }
.list-item:last-child { border-bottom: 0; }
.list-item .t { flex: 1; min-width: 0; }
.list-item .t b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.list-item .t small { color: var(--muted); }
.empty { color: var(--muted); padding: 10px 0; }

.course-card { display: block; text-decoration: none; color: var(--text); border-radius: var(--radius); padding: 18px; margin-bottom: 12px; border: 1px solid var(--line);
  background: linear-gradient(135deg, hsla(var(--h), 55%, 40%, .35), hsla(var(--h), 55%, 25%, .12)), var(--surface); }
.course-card h3 { font-size: 21px; }
.course-card .meta { margin: 6px 0 0; }
.progress { height: 5px; border-radius: 9px; background: rgba(255, 255, 255, .08); overflow: hidden; margin-top: 12px; }
.progress i { display: block; height: 100%; background: hsl(var(--h), 70%, 68%); }

.week { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; background: var(--surface); overflow: hidden; }
.week > summary { list-style: none; display: flex; gap: 12px; align-items: center; padding: 14px 16px; cursor: pointer; }
.week > summary::-webkit-details-marker { display: none; }
.wk-num { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-weight: 600; background: var(--surface-2); flex: none; }
.week.current { border-color: var(--accent); }
.week.current .wk-num { background: var(--accent); color: var(--accent-ink); }
.week .wk-body { padding: 0 16px 16px; }
.counts { color: var(--muted); font-size: 12.5px; }
.file { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.file a { flex: 1; min-width: 0; color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ext { font: 600 10px/1 var(--sans); padding: 5px 6px; border-radius: 6px; background: var(--surface-2); color: var(--teal); text-transform: uppercase; flex: none; }
.upload { position: relative; overflow: hidden; }
.upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.x { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; padding: 4px 8px; }

/* ---------- material */
.tldr { background: linear-gradient(135deg, rgba(242, 181, 107, .16), rgba(242, 181, 107, .04)); border: 1px solid rgba(242, 181, 107, .35); border-radius: var(--radius); padding: 16px; font-size: 16px; }
.mat h2 { font-size: 21px; margin: 26px 0 8px; }
.mat p { margin: 0 0 12px; color: #dcd8d0; line-height: 1.65; }
.analogy { border-left: 3px solid var(--teal); padding: 4px 0 4px 14px; color: #dcd8d0; font-style: italic; }
dl.terms dt { font-weight: 600; margin-top: 10px; color: var(--accent); }
dl.terms dd { margin: 2px 0 0; color: #d6d2cb; }
.flashcards { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 4px 16px 10px; margin: 0 -16px; scrollbar-width: none; }
.flash { flex: 0 0 82%; scroll-snap-align: center; min-height: 170px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-2); padding: 18px; display: flex; align-items: center; justify-content: center; text-align: center; cursor: pointer; font-size: 16px; position: relative; }
.flash.flipped { background: #233130; border-color: var(--teal); }
.flash small { position: absolute; top: 10px; left: 14px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
ul.mis { padding-left: 18px; color: #dcd8d0; }

/* ---------- sheet */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92dvh; overflow-y: auto; background: var(--surface); border-radius: 22px 22px 0 0; padding: 22px 16px calc(22px + env(safe-area-inset-bottom)); animation: up .22s ease-out; max-width: 640px; margin: 0 auto; }
.sheet.full .sheet-panel { top: 0; max-height: none; border-radius: 0; padding-top: calc(22px + env(safe-area-inset-top)); }
.sheet-panel h2 { font-size: 22px; margin: 0 40px 14px 0; }
.sheet-x { position: absolute; top: 12px; right: 12px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--surface-2); font-size: 22px; cursor: pointer; z-index: 2; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

.quiz-progress { display: flex; gap: 4px; margin: 6px 40px 18px 0; }
.quiz-progress i { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.quiz-progress i.done { background: var(--teal); }
.quiz-progress i.miss { background: var(--bad); }
.score { font-family: var(--serif); font-size: 56px; text-align: center; margin: 20px 0 4px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar) + 14px); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 999px; font-weight: 500; z-index: 60; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0, 0, 0, .4); cursor: pointer; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; margin: 30px auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { text-align: center; color: var(--muted); padding: 20px 0; }
.notice { padding: 12px 14px; border-radius: 12px; background: rgba(242, 181, 107, .1); border: 1px solid rgba(242, 181, 107, .3); font-size: 14px; margin-bottom: 14px; }
.qr { background: #fff; padding: 12px; border-radius: 12px; width: max-content; margin: 10px 0; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; word-break: break-all; }
.toggle-row { display: flex; gap: 10px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row input[type=checkbox] { width: 20px; height: 20px; margin-top: 12px; accent-color: var(--accent); flex: none; }

@media (min-width: 900px) {
  .card { padding-left: 10vw; padding-right: 10vw; }
}

/* ---------- drama */
.card.drama { background: radial-gradient(120% 70% at 0% 0%, hsla(var(--h), 70%, 50%, .22), transparent 60%), var(--bg); }
.drama .title { font-size: clamp(22px, 6.2vw, 30px); margin-bottom: 12px; }
.tea { color: hsl(var(--h), 80%, 76%); }
.spill h2 { font-size: 23px; margin: 4px 40px 10px 0; }
.spill h4 { font: 600 12px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 22px 0 8px; }
.spill ul { margin: 0; padding-left: 18px; }
.spill li { margin-bottom: 6px; color: #dcd8d0; }
.spice { letter-spacing: 2px; }
.players { display: flex; flex-wrap: wrap; gap: 8px; }
.player-chip { padding: 8px 12px; border-radius: 12px; background: var(--surface-2); font-size: 13.5px; line-height: 1.3; }
.player-chip small { display: block; color: var(--muted); }
.sides { display: grid; gap: 10px; }
.side { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.side b { display: block; margin-bottom: 6px; }
.fact-grid { display: grid; gap: 10px; }
.fact { border-radius: 14px; padding: 12px 14px; }
.fact.ok { background: rgba(123, 216, 143, .08); border: 1px solid rgba(123, 216, 143, .35); }
.fact.maybe { background: rgba(242, 181, 107, .08); border: 1px solid rgba(242, 181, 107, .35); }
.fact b { display: block; margin-bottom: 6px; font-size: 13px; }

/* ---------- math */
.card.mathcard { background: radial-gradient(120% 70% at 50% 100%, hsla(var(--h), 60%, 45%, .2), transparent 60%), var(--bg); }
.mflip { min-height: 46%; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px;
  border-radius: 22px; border: 1px solid var(--line); background: var(--surface); font-size: 19px; line-height: 1.5; cursor: pointer; }
.mflip.flipped { border-color: hsl(var(--h), 60%, 60%); background: hsla(var(--h), 40%, 20%, .5); }
.ring { --p: 0; width: 64px; height: 64px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 600; font-size: 14px;
  background: radial-gradient(closest-side, var(--surface) 78%, transparent 80%), conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0); }
.unit { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 10px; overflow: hidden; }
.unit > summary { list-style: none; display: flex; gap: 12px; align-items: center; padding: 14px 16px; cursor: pointer; }
.unit > summary::-webkit-details-marker { display: none; }
.unit-badge { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-weight: 650; font-family: var(--serif);
  background: hsla(var(--h), 60%, 55%, .2); color: hsl(var(--h), 75%, 75%); flex: none; }
.lesson-row { display: flex; gap: 12px; align-items: center; padding: 11px 16px; border-top: 1px solid var(--line); text-decoration: none; color: var(--text); }
.lesson-row .t { flex: 1; min-width: 0; }
.lesson-row .t small { display: block; color: var(--muted); font-size: 12.5px; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); flex: none; }
.dot.read { border-color: var(--accent); background: linear-gradient(90deg, var(--accent) 50%, transparent 50%); }
.dot.done { border-color: var(--good); background: var(--good); }
.dot.ready { border-color: var(--teal); }
.lesson h2 { font-size: 21px; margin: 28px 0 8px; }
.lesson p { margin: 0 0 12px; color: #dcd8d0; line-height: 1.65; }
.lesson .why { color: var(--muted); font-size: 15px; }
.formula { padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); margin-bottom: 10px; overflow-x: auto; }
.formula b { display: block; font-size: 13px; color: var(--accent); margin-bottom: 4px; }
.formula small { display: block; color: var(--muted); margin-top: 4px; font-size: 13.5px; }
.example { border-radius: var(--radius); background: linear-gradient(135deg, rgba(127, 200, 194, .1), rgba(127, 200, 194, .02)); border: 1px solid rgba(127, 200, 194, .3); padding: 16px; }
.example ol { padding-left: 20px; margin: 10px 0; }
.example li { margin-bottom: 8px; }
.app-box { border-left: 3px solid var(--accent); padding-left: 14px; }
pre.code { background: #0a0b0e; border: 1px solid var(--line); border-radius: 14px; padding: 14px; overflow-x: auto; font: 12.5px/1.55 ui-monospace, Consolas, monospace; color: #d7e3e0; }
.exercise { border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 10px; background: var(--surface); }
.exercise .reveal { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.katex { font-size: 1.05em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* ---------- exam questions */
.q-text { font-size: 18px; line-height: 1.5; margin-bottom: 16px; }
.q-text.long { font-size: 15.5px; }
.q-text .katex-display { margin: 8px 0; }
.exam-figs { margin: 0 0 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.exam-figs summary { padding: 10px 14px; cursor: pointer; color: var(--teal); font-size: 14px; }
.exam-figs img { display: block; width: 100%; background: #fff; border-top: 1px solid var(--line); }
.opt .letter { display: inline-block; width: 22px; color: var(--muted); }
.opt.skip { border-color: var(--muted); }
.quiz-progress i.skip { background: var(--muted); }
