/* Tulika — built on the "Syllabus" design system tokens */

:root {
    --surface-000: #ffffff; --surface-100: #f7f5f0; --surface-200: #efebe2;
    --line: #e2ddd1; --line-control: #8f887a;
    --ink: #1b1e21; --ink-muted: #5a605c;
    --primary: #1d6b58; --on-primary: #ffffff; --primary-soft: #e2f0ea; --primary-text: #175a4a;
    --accent: #f0b12f; --on-accent: #2b1d00; --highlight: #fcefcc;
    --danger: #b23a1e; --info: #2453a3; --focus: #2453a3;
    --subj-math: #3a4db0; --subj-science: #0d7480; --subj-language: #b84a30;
    --subj-social: #946313; --subj-arts: #9c3a6f; --subj-tech: #4c6a26;
    --shadow-card: 0 1px 2px rgba(27,30,33,.05), 0 6px 20px -6px rgba(27,30,33,.08), 0 0 0 1px rgba(27,30,33,.06);
    --shadow-pop: 0 12px 32px rgba(27,30,33,.14), 0 0 0 1px rgba(27,30,33,.08);
    --well: #faf8f4;          /* topic lists inside white cards (light): paler than surface-200 so cards don't look muddy */

    --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
    --font-sans: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

    --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
    --space-5: 24px; --space-6: 32px; --space-7: 48px; --space-8: 64px;
    --radius-sm: 6px; --radius-md: 10px; --radius-lg: 16px; --radius-pill: 999px;
}
:root { color-scheme: light; }

/* Dark theme: follows the system unless the header switch set data-theme on <html> */
:root[data-theme="dark"] {
    color-scheme: dark;
    --surface-000: #1a1e21; --surface-100: #121517; --surface-200: #0d0f11;
    --line: #2a3035; --line-control: #6b757c;
    --ink: #eceeec; --ink-muted: #a2aaa5;
    --primary: #5cc4a5; --on-primary: #0a1f19; --primary-soft: #16302a; --primary-text: #7fd6bb;
    --highlight: #3a2f12; --danger: #ff8b70; --info: #8fb2ff; --focus: #8fb2ff;
    --subj-math: #93a3ff; --subj-science: #4fc3cf; --subj-language: #ff9a7f;
    --subj-social: #e0b25c; --subj-arts: #f08cc0; --subj-tech: #a6cf6f;
    --shadow-card: 0 0 0 1px rgba(236,238,236,.08);
    --shadow-pop: 0 12px 32px rgba(0,0,0,.5), 0 0 0 1px rgba(236,238,236,.1);
    --well: var(--surface-200);
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --surface-000: #1a1e21; --surface-100: #121517; --surface-200: #0d0f11;
        --line: #2a3035; --line-control: #6b757c;
        --ink: #eceeec; --ink-muted: #a2aaa5;
        --primary: #5cc4a5; --on-primary: #0a1f19; --primary-soft: #16302a; --primary-text: #7fd6bb;
        --highlight: #3a2f12; --danger: #ff8b70; --info: #8fb2ff; --focus: #8fb2ff;
        --subj-math: #93a3ff; --subj-science: #4fc3cf; --subj-language: #ff9a7f;
        --subj-social: #e0b25c; --subj-arts: #f08cc0; --subj-tech: #a6cf6f;
        --shadow-card: 0 0 0 1px rgba(236,238,236,.08);
        --shadow-pop: 0 12px 32px rgba(0,0,0,.5), 0 0 0 1px rgba(236,238,236,.1);
        --well: var(--surface-200);
    }
}

[x-cloak] { display: none !important; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--surface-100); color: var(--ink); font: 400 16px/24px var(--font-sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
:where(a, button, input, select):focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.icon { width: 20px; height: 20px; flex: none; display: block; }
.icon-sm { width: 16px; height: 16px; }

/* Type */
.t-display { font: 700 48px/52px var(--font-display); letter-spacing: -.02em; margin: 0; }
.t-h1 { font: 650 32px/38px var(--font-display); letter-spacing: -.015em; margin: 0; }
.t-h2 { font: 600 22px/28px var(--font-display); letter-spacing: -.01em; margin: 0; }
.t-h3 { font: 600 17px/24px var(--font-display); margin: 0; }
.t-label { font: 700 13px/16px var(--font-sans); letter-spacing: .04em; text-transform: uppercase; color: var(--ink-muted); }
.t-sm { font-size: 14px; line-height: 20px; }
.t-muted { color: var(--ink-muted); }
.num { font: 500 13px/16px var(--font-mono); font-variant-numeric: tabular-nums; color: var(--ink-muted); }
mark { background: var(--highlight); color: var(--ink); border-radius: 3px; padding: 0 1px; }

/* Layout */
.page { max-width: 1120px; margin: 0 auto; padding: 0 var(--space-4); }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface-100) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar .page { display: flex; align-items: center; gap: var(--space-4); height: 64px; }
.brand { font: 600 22px/1 var(--font-display); letter-spacing: -.01em; }
.grow { flex: 1; min-width: 0; }

/* Course switcher */
.switch { position: relative; }
.switch-btn { display: inline-flex; align-items: center; gap: var(--space-2); padding: 6px 10px 6px 6px; border: 0; border-radius: var(--radius-pill); background: var(--surface-200); cursor: pointer; white-space: nowrap; }
.switch-btn:hover { background: var(--line); }
.board-tag { font: 700 12px/16px var(--font-sans); letter-spacing: .04em; background: var(--primary); color: var(--on-primary); padding: 3px 8px; border-radius: var(--radius-pill); }
.switch-level { font: 600 15px/1 var(--font-display); }
.menu { position: absolute; top: calc(100% + 8px); left: 0; min-width: 260px; background: var(--surface-000); border-radius: var(--radius-md); box-shadow: var(--shadow-pop); padding: var(--space-2); z-index: 30; max-height: min(60vh, 440px); overflow-y: auto; }
.menu-item { display: flex; align-items: center; gap: var(--space-3); width: 100%; padding: var(--space-2) var(--space-3); border: 0; background: none; border-radius: var(--radius-md); text-align: left; cursor: pointer; }
.menu-item:hover { background: var(--surface-200); }
.menu-item.is-active { background: var(--primary-soft); }

/* Search */
.search { display: flex; align-items: center; gap: var(--space-2); height: 44px; padding: 0 var(--space-3); background: var(--surface-000); border: 1px solid var(--line-control); border-radius: var(--radius-md); color: var(--ink-muted); }
.search:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font: inherit; color: var(--ink); }
.kbd { font: 500 12px/1 var(--font-mono); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 3px 6px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); padding: var(--space-3) var(--space-4); border: 0; border-radius: var(--radius-md); font-weight: 700; cursor: pointer; text-align: left; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--primary-soft); color: var(--primary-text); }
.btn-ghost { background: none; color: var(--ink-muted); padding: var(--space-2) var(--space-3); }
.btn-ghost:hover { background: var(--surface-200); color: var(--ink); }

/* Hero */
.hero { display: flex; align-items: center; gap: var(--space-6); padding: var(--space-7) 0; flex-wrap: wrap; }
.ring { position: relative; flex: none; }
.ring svg { transform: rotate(-90deg); display: block; }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-value { font: 600 22px/1 var(--font-mono); color: var(--ink); }
.ring-caption { font-size: 12px; line-height: 16px; color: var(--ink-muted); }

/* Subject cards */
/* masonry columns so short subject cards don't leave holes under them */
.grid { columns: 340px; column-gap: var(--space-5); padding-bottom: var(--space-8); }
.grid > .card { break-inside: avoid; margin-bottom: var(--space-5); }
.card { background: var(--surface-000); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: var(--space-5); }
.card-head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.glyph { width: 36px; height: 36px; border-radius: var(--radius-md); display: grid; place-items: center; font: 600 15px/1 var(--font-display); color: #fff; flex: none; }
:root[data-theme="dark"] .glyph { color: var(--surface-100); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .glyph { color: var(--surface-100); } }

/* Theme switch */
.theme-btn { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border: 0; border-radius: var(--radius-md); background: none; color: var(--ink-muted); cursor: pointer; }
.theme-btn:hover { background: var(--surface-200); color: var(--ink); }
.bar { height: 6px; border-radius: var(--radius-pill); background: var(--surface-200); overflow: hidden; }
.bar-sm { height: 4px; }
.bar > i { display: block; height: 100%; border-radius: inherit; transition: width .18s ease-out; }
.bar-row { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); }

/* Chapter checklist */
.chapter { border-top: 1px solid var(--line); }
.chapter-head { display: flex; align-items: center; gap: var(--space-3); width: 100%; padding: var(--space-3) 0; border: 0; background: none; text-align: left; cursor: pointer; border-radius: var(--radius-sm); }
.chapter-head:hover { background: var(--surface-200); }
.chapter-head .t-h3 { flex: 1; }
.chev { transition: transform .15s ease-out; color: var(--ink-muted); }
.chev.is-open { transform: rotate(180deg); }
.pill { display: inline-flex; align-items: center; gap: 2px; padding: 2px 8px; border-radius: var(--radius-pill); }
.pill.is-done { background: var(--primary-soft); }
.pill.is-done .num { color: var(--primary-text); }
.topics { list-style: none; margin: 0 0 var(--space-3); padding: var(--space-2); background: var(--well); box-shadow: inset 0 0 0 1px var(--line); border-radius: var(--radius-md); }
.topic-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2); border-radius: var(--radius-sm); }
.topic-row:hover { background: var(--surface-000); }
.topic-row.is-next { box-shadow: inset 3px 0 0 var(--accent); }
.topic-title { flex: 1; min-width: 0; }
.topic-title:hover { color: var(--primary-text); text-decoration: underline; text-underline-offset: 3px; }
.topic-row.is-done .topic-title { color: var(--ink-muted); }
.next-tag { font: 700 11px/16px var(--font-sans); background: var(--accent); color: var(--on-accent); border-radius: var(--radius-pill); padding: 0 6px; white-space: nowrap; }

/* Checkbox */
.check { appearance: none; -webkit-appearance: none; margin: 0; width: 20px; height: 20px; flex: none; border: 1.5px solid var(--line-control); border-radius: var(--radius-sm); background: var(--surface-000); display: grid; place-items: center; cursor: pointer; transition: background .12s ease-out; }
.check::after { content: ""; width: 10px; height: 6px; border: 2px solid var(--on-primary); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); opacity: 0; }
.check:checked { background: var(--primary); border-color: var(--primary); }
.check:checked::after { opacity: 1; }

/* Topic page */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); padding: var(--space-6) 0 var(--space-4); }
.crumbs a:hover { color: var(--primary-text); }
.topic-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--space-6); align-items: start; padding-bottom: var(--space-8); }
.done-toggle { display: inline-flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); background: var(--surface-000); box-shadow: var(--shadow-card); cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-5) 0 var(--space-4); }
.chip { display: inline-flex; align-items: center; gap: var(--space-1); padding: 6px 12px; border: 1px solid var(--line-control); border-radius: var(--radius-sm); background: var(--surface-000); cursor: pointer; font-size: 14px; line-height: 20px; }
.chip.is-selected { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-text); font-weight: 700; }
.res-list { display: grid; gap: var(--space-3); }
.res { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-4); background: var(--surface-000); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); }
.res:hover { box-shadow: var(--shadow-pop); }
.res:hover .res-title { color: var(--primary-text); }
.res-icon { width: 44px; height: 44px; border-radius: var(--radius-md); display: grid; place-items: center; background: color-mix(in srgb, currentColor 11%, var(--surface-000)); flex: none; }
.res-title { font-weight: 700; }
.tag { font: 700 11px/16px var(--font-sans); letter-spacing: .04em; text-transform: uppercase; padding: 1px 6px; border-radius: var(--radius-sm); background: var(--surface-200); color: var(--ink-muted); }
.tag.is-curated { background: var(--primary-soft); color: var(--primary-text); }
.aside { position: sticky; top: 88px; }
.aside .topic-row.is-current { background: var(--primary-soft); }
.aside .topics { box-shadow: none; }
.pager { display: flex; gap: var(--space-3); margin-top: var(--space-6); flex-wrap: wrap; }
.pager .btn-primary { margin-left: auto; }

/* Search results */
.results { padding: var(--space-6) 0 var(--space-8); }
.result { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); background: var(--surface-000); border-radius: var(--radius-md); box-shadow: var(--shadow-card); margin-bottom: var(--space-2); }
.result:hover { box-shadow: var(--shadow-pop); }
.glyph-sm { width: 28px; height: 28px; font-size: 12px; border-radius: var(--radius-sm); }

/* Landing */
.home-nav { display: flex; align-items: center; gap: var(--space-1); }
.l-hero-bg { background: radial-gradient(60% 90% at 85% 0%, color-mix(in srgb, var(--primary-soft) 80%, transparent), transparent 70%), radial-gradient(40% 60% at 0% 100%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 70%); }
.l-hero { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: var(--space-7); align-items: center; padding-top: var(--space-8); padding-bottom: var(--space-8); }
.l-title { font: 700 52px/56px var(--font-display); letter-spacing: -.025em; margin: var(--space-3) 0 var(--space-4); }
.l-lead { font-size: 18px; line-height: 28px; color: var(--ink-muted); margin: 0; max-width: 34em; }
.l-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-6); }
.l-cover { width: 100%; height: auto; display: block; }
.l-cover .c-primary { fill: var(--primary); }
.l-cover .c-math { fill: var(--subj-math); }
.l-cover .c-accent { fill: var(--accent); }
.l-cover .c-science { fill: var(--subj-science); }
.l-cover .c-social { fill: var(--subj-social); }
.l-cover .c-soft { fill: var(--primary-soft); }
.l-cover .c-on { fill: var(--primary); }
.l-cover .c-off { fill: var(--surface-000); stroke: var(--line-control); stroke-width: 1.5; }
.l-cover .c-tick { fill: none; stroke: var(--on-primary); stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }

.l-stats { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface-000); }
.l-stats-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-5); padding-top: var(--space-5); padding-bottom: var(--space-5); }
.l-stats-row > div { display: flex; align-items: baseline; gap: var(--space-2); }
.l-stat { font: 600 28px/1 var(--font-mono); color: var(--ink); }

.l-section { padding-top: var(--space-8); padding-bottom: var(--space-8); }
.l-section .t-h1 { margin-top: var(--space-2); }
.l-sub { color: var(--ink-muted); margin: var(--space-2) 0 0; max-width: 40em; }
.l-courses { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-5); margin-top: var(--space-6); }
.l-course { display: flex; flex-direction: column; gap: var(--space-3); }
a.l-course:hover { box-shadow: var(--shadow-pop); }
.l-course-title { font: 700 36px/40px var(--font-display); letter-spacing: -.02em; margin: 0; }
.l-all { display: flex; justify-content: center; margin-top: var(--space-6); }
.l-catalog { padding-bottom: var(--space-8); }
.l-catalog .t-display { margin: var(--space-1) 0 0; }
.btn-ghost.is-active { background: var(--surface-200); color: var(--ink); }
.l-boards { margin: var(--space-5) 0 0; }
.l-stage { margin-top: var(--space-6); }
.l-stage-head { display: flex; align-items: baseline; gap: var(--space-3); padding-bottom: var(--space-2); border-bottom: 1px solid var(--line); }
.l-stage-head .t-h3 { margin: 0; }
.l-classes { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--space-4); margin-top: var(--space-4); }
.l-class { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-4); transition: box-shadow .15s ease-out; }
.l-class:hover { box-shadow: var(--shadow-pop); }
.l-class:hover .l-class-go { background: var(--primary); color: var(--on-primary); }
.l-class-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-2); }
.l-class-num { font: 700 36px/40px var(--font-display); letter-spacing: -.02em; color: var(--ink); }
.l-class-go { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-text); flex: none; transition: background .15s ease-out, color .15s ease-out; }
.l-glyphs { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.l-open { display: inline-flex; align-items: center; gap: var(--space-2); font-weight: 700; color: var(--primary-text); margin-top: auto; }
.l-soon { margin: var(--space-6) 0 0; }

.l-band { background: linear-gradient(180deg, var(--surface-100), color-mix(in srgb, var(--primary-soft) 70%, var(--surface-100))); }
.l-steps { list-style: none; padding: 0; margin: var(--space-6) 0 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-5); }
.l-steps p { margin: var(--space-2) 0 0; }
.l-step-num { display: block; font: 600 15px/1 var(--font-mono); color: var(--primary-text); margin-bottom: var(--space-4); }

.l-show { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-7); align-items: center; }
.l-mock { padding: var(--space-5); }
.l-mock-res { box-shadow: none; background: var(--surface-100); padding: var(--space-3); }

.l-cta { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-5); padding: var(--space-6); border-radius: var(--radius-lg); background: var(--primary-soft); }

@media (max-width: 900px) {
    .l-hero, .l-show { grid-template-columns: 1fr; gap: var(--space-6); }
    .l-hero { padding-top: var(--space-6); padding-bottom: var(--space-6); }
    .l-cover { max-width: 420px; }
    .l-steps { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
    .l-title { font-size: 36px; line-height: 40px; }
    .l-section { padding-top: var(--space-7); padding-bottom: var(--space-7); }
    .l-stats-row { justify-content: flex-start; gap: var(--space-3) var(--space-5); }
    .l-stat { font-size: 22px; }
    .l-actions .btn { width: 100%; justify-content: center; }
    .hide-sm { display: none; }
    .l-cta { padding: var(--space-5); }
    .l-classes { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
    .l-class { padding: var(--space-3); }
    .l-class-num { font-size: 28px; line-height: 32px; }
}

/* Loading screen: open book with pages turning */
body.is-loading { overflow: hidden; }
.loader { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-2); background: var(--surface-100); transition: opacity .4s ease-out, visibility .4s; animation: loader-fallback 0s 8s forwards; }
body:not(.is-loading) .loader { opacity: 0; visibility: hidden; pointer-events: none; }
@keyframes loader-fallback { to { opacity: 0; visibility: hidden; } }   /* never block the page if JS fails */
.loader-name { font: 700 30px/1 var(--font-display); letter-spacing: -.02em; margin-top: var(--space-5); }

.book { position: relative; width: 168px; height: 112px; perspective: 700px; transform-style: preserve-3d; }
.book-cover { position: absolute; inset: -8px -10px -10px; border-radius: 10px; background: var(--primary); }
.book-page, .book-flip {
    position: absolute; top: 0; width: 50%; height: 100%;
    background-color: var(--surface-000);
    background-image: repeating-linear-gradient(to bottom, transparent 0 9px, var(--line) 9px 11px);
    background-size: calc(100% - 28px) calc(100% - 28px); background-position: 14px 16px; background-repeat: no-repeat;
}
.book-left { left: 0; border-radius: 6px 2px 2px 6px; box-shadow: inset -12px 0 12px -12px rgba(0,0,0,.3); }
.book-right { right: 0; border-radius: 2px 6px 6px 2px; box-shadow: inset 12px 0 12px -12px rgba(0,0,0,.3); }
.book-flip { left: 50%; border-radius: 2px 6px 6px 2px; transform-origin: left center; animation: page-turn 2.4s cubic-bezier(.45,.05,.35,1) infinite; animation-delay: calc(var(--n) * .4s); }
.book-flip::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: linear-gradient(to right, rgba(0,0,0,.18), transparent 70%); opacity: 0; animation: inherit; animation-name: page-shade; }
.book-ribbon { position: absolute; left: 26px; top: -8px; width: 10px; height: 42px; background: var(--accent); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%); transform: translateZ(4px); }
@keyframes page-turn {
    0%, 8% { transform: translateZ(1px) rotateY(0); }
    50%, 100% { transform: translateZ(1px) rotateY(-180deg); }
}
@keyframes page-shade { 0%, 8% { opacity: 0; } 29% { opacity: 1; } 50%, 100% { opacity: 0; } }

/* Landing cover: blocks pop in, then the checklist ticks itself off */
.l-cover .c-block, .l-cover .c-on rect { transform-box: fill-box; transform-origin: center; }
.l-cover .c-tick path { stroke-dasharray: 20; }
body:not(.is-loading) .l-cover .c-block { animation: block-in .55s cubic-bezier(.2,.8,.2,1.15) both; animation-delay: calc(var(--d) * .09s); }
body:not(.is-loading) .l-cover .c-on rect { animation: box-on .22s ease-out both; animation-delay: calc(.7s + var(--i) * .11s); }
body:not(.is-loading) .l-cover .c-tick path { animation: tick-draw .25s ease-out both; animation-delay: calc(.82s + var(--i) * .11s); }
@keyframes block-in { from { opacity: 0; transform: translateY(14px) scale(.85); } }
@keyframes box-on { from { opacity: 0; transform: scale(.4); } }
@keyframes tick-draw { from { stroke-dashoffset: 20; } to { stroke-dashoffset: 0; } }

@media (prefers-reduced-motion: reduce) {
    .book-flip, .book-flip::after, body:not(.is-loading) .l-cover * { animation: none !important; }
}

.footer { border-top: 1px solid var(--line); padding: var(--space-5) 0; text-align: center; font-size: 12px; line-height: 16px; color: var(--ink-muted); }

@media (max-width: 900px) {
    .topic-layout { grid-template-columns: 1fr; }
    .aside { position: static; }
}
@media (max-width: 720px) {
    .grid { columns: 1; }
    .grid > .card { margin-bottom: var(--space-4); }
    .card { padding: var(--space-4); }
    .t-display { font-size: 36px; line-height: 40px; }
    .t-h1 { font-size: 26px; line-height: 32px; }
    .hero { gap: var(--space-4); padding: var(--space-6) 0; }
    .hero .btn { width: 100%; }
    .topbar .page { flex-wrap: wrap; height: auto; padding-top: var(--space-3); padding-bottom: var(--space-3); }
    .topbar .search-wrap { order: 3; flex-basis: 100%; }
    .kbd { display: none; }
}

/* ---- Accounts: sign in / sign up pages and the header account menu ---- */
.link { color: var(--primary-text); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.auth-wrap { display: grid; place-items: start center; padding: var(--space-7) var(--space-4) var(--space-8); }
.auth-card { width: 100%; max-width: 420px; padding: var(--space-6); }
.auth-glyph { display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--radius-md); background: var(--primary-soft); color: var(--primary-text); margin-bottom: var(--space-4); }
.auth-lead { margin: var(--space-2) 0 var(--space-5); }
.auth-alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: 14px; line-height: 20px; margin-bottom: var(--space-4); border: 1px solid; }
.auth-alert.is-error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: color-mix(in srgb, var(--danger) 8%, transparent); }
.auth-alert.is-ok { color: var(--primary-text); border-color: color-mix(in srgb, var(--primary) 35%, transparent); background: var(--primary-soft); }
.auth-form { display: grid; gap: var(--space-4); }
.field { display: grid; gap: 6px; }
.field-label { font-weight: 700; font-size: 14px; line-height: 20px; }
.input { height: 44px; padding: 0 var(--space-3); border: 1px solid var(--line-control); border-radius: var(--radius-md); background: var(--surface-000); color: var(--ink); font: inherit; width: 100%; }
.input:focus { outline: 2px solid var(--focus); outline-offset: 2px; }
.check-row { display: flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.check-row input { width: 18px; height: 18px; accent-color: var(--primary); }
.auth-submit { width: 100%; justify-content: center; margin-top: var(--space-2); }
.auth-switch { margin: var(--space-5) 0 0; text-align: center; }

.account { position: relative; flex: none; }
.account-btn { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: var(--radius-pill); background: var(--primary-soft); color: var(--primary-text); font: 600 15px/1 var(--font-display); text-transform: uppercase; cursor: pointer; }
.account-btn:hover { filter: brightness(.96); }
.account .menu { left: auto; right: 0; min-width: 240px; }
.account-head { padding: var(--space-2) var(--space-3) var(--space-3); border-bottom: 1px solid var(--line); margin-bottom: var(--space-2); }
.account-head .t-h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-state { display: inline-flex; align-items: center; gap: 6px; }
.save-state.is-error { color: var(--danger); }

/* ---- Learner dashboard (#/me) ---- */
.dash { padding: 0; }
/* Dashboard is full screen: the header spans the window, sidebar is pinned to the left edge at full height */
.page-wide { max-width: none; padding: 0 var(--space-5); }
.dash-head { display: flex; align-items: flex-end; gap: var(--space-5); flex-wrap: wrap; padding: 0 0 var(--space-5); }

/* Sidebar + main column */
.dash-layout { display: grid; grid-template-columns: 264px minmax(0, 1fr); align-items: start; min-height: calc(100vh - 65px); }
.dash-main { min-width: 0; width: 100%; max-width: 1440px; padding: var(--space-6) var(--space-7) var(--space-8); }
.dash-section { margin-bottom: var(--space-7); }
.dash-layout [id] { scroll-margin-top: 88px; }
.dash-side { position: sticky; top: 65px; display: flex; flex-direction: column; gap: var(--space-5); height: calc(100vh - 65px); padding: var(--space-5) var(--space-4); background: var(--surface-000); border-right: 1px solid var(--line); overflow-y: auto; }
.side-profile { display: flex; align-items: center; gap: var(--space-3); padding-bottom: var(--space-4); border-bottom: 1px solid var(--line); }
.side-avatar { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: var(--radius-pill); background: var(--primary); color: var(--on-primary); font: 600 18px/1 var(--font-display); text-transform: uppercase; }
.side-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-nav, .side-foot { display: grid; gap: 2px; }
.side-foot { margin-top: auto; padding-top: var(--space-4); border-top: 1px solid var(--line); }   /* pinned to the bottom of the sidebar */
.side-link { display: flex; align-items: center; gap: var(--space-3); width: 100%; padding: var(--space-2) var(--space-3); border: 0; border-radius: var(--radius-md); background: none; color: var(--ink-muted); font-weight: 700; font-size: 14px; line-height: 20px; text-align: left; cursor: pointer; }
.side-link:hover { background: var(--surface-200); color: var(--ink); }
.side-group { display: grid; gap: var(--space-2); }
.side-label { padding: 0 var(--space-3); }
.side-class { display: grid; gap: 6px; width: 100%; padding: var(--space-2) var(--space-3); border: 0; border-radius: var(--radius-md); background: none; text-align: left; cursor: pointer; font-size: 14px; line-height: 20px; }
.side-class:hover { background: var(--surface-200); }
.side-class.is-active { background: var(--primary-soft); }
.side-class.is-active .side-class-top > .grow { font-weight: 700; color: var(--primary-text); }
.side-class-top { display: flex; align-items: center; gap: var(--space-2); }
.side-class .bar { background: var(--surface-200); }
.side-class.is-active .bar { background: var(--surface-000); }

/* Charts: one filter row above, two cards side by side */
.chart-select { display: inline-flex; align-items: center; gap: var(--space-2); }
.chart-select .input { height: 36px; width: auto; padding-right: var(--space-6); }
.dash-charts { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: var(--space-4); align-items: start; }
.chart-card { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); align-content: start; padding: var(--space-5); }
.chart-head { display: flex; align-items: flex-start; gap: var(--space-3); }
.chart-sub { margin: 2px 0 0; }
.chart-toggle { flex: none; font-size: 14px; }
.chart-plot { position: relative; }

/* Study calendar (heatmap): one primary hue, light → dark for more topics; dark mode reverses naturally (dark → bright) */
.heat-scroll { overflow-x: auto; padding-top: 2px; direction: rtl; }   /* rtl: a scrolling calendar opens on the newest weeks */
.heat { --cell: minmax(6px, 16px); direction: ltr; display: grid; grid-template-columns: 28px auto; grid-template-areas: ". months" "days grid"; column-gap: var(--space-2); row-gap: 4px; width: max-content; min-width: 100%; margin-left: auto; padding-right: 20px; box-sizing: border-box; }   /* room for the last month name */
.heat-months { grid-area: months; display: grid; grid-template-columns: repeat(var(--weeks), var(--cell)); column-gap: 3px; }
.heat-months span { font-size: 12px; line-height: 16px; color: var(--ink-muted); white-space: nowrap; overflow: visible; width: 0; }
.heat-days { grid-area: days; position: sticky; left: 0; z-index: 1; background: var(--surface-000); display: grid; grid-template-rows: repeat(7, 1fr); row-gap: 3px; }
.heat-days span { font-size: 11px; line-height: 1; color: var(--ink-muted); display: flex; align-items: center; }
.heat-grid { grid-area: grid; display: grid; grid-template-columns: repeat(var(--weeks), var(--cell)); grid-template-rows: repeat(7, auto); grid-auto-flow: column; gap: 3px; }
.heat-cell { display: block; aspect-ratio: 1; min-width: 6px; border-radius: 3px; background: var(--surface-200); }
.heat-cell.l1 { background: color-mix(in srgb, var(--primary) 40%, var(--surface-200)); }
.heat-cell.l2 { background: color-mix(in srgb, var(--primary) 62%, var(--surface-200)); }
.heat-cell.l3 { background: color-mix(in srgb, var(--primary) 82%, var(--surface-200)); }
.heat-cell.l4 { background: var(--primary); }
.heat-cell.is-future { background: transparent; }
.heat-grid .heat-cell:not(.is-future):hover { outline: 2px solid var(--ink); outline-offset: 1px; }
.heat-legend { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: var(--space-3); }
.heat-legend .heat-cell { width: 12px; }
.heat-legend .t-sm { margin: 0 4px; }
.heat-key { margin-left: auto; font-size: 12px; color: var(--ink-muted); }
.chart-card > .chips { margin: 0; }
.chart-card > .chart-select { justify-self: start; }
/* Ranked horizontal bars (subjects): one hue; the subject glyph carries identity */
.hbar-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3); }
.hbar-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; padding: 4px var(--space-2); margin: 0 calc(-1 * var(--space-2)); border-radius: var(--radius-sm); }
.hbar-row:hover, .hbar-row:focus-visible { background: var(--surface-200); }
.hbar-name { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.hbar-name .t-sm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.hbar-bar { display: block; flex: none; height: 12px; background: var(--primary); border-radius: 0 4px 4px 0; transition: width .3s var(--ease-out, ease-out); }
.hbar-value { flex: none; font-size: 12px; }

/* Tooltip: value first, label second */
.chart-tip { position: absolute; z-index: 5; transform: translate(-50%, calc(-100% - 8px)); display: grid; gap: 2px; padding: 6px 10px; background: var(--ink); color: var(--surface-000); border-radius: var(--radius-sm); font-size: 12px; line-height: 16px; white-space: nowrap; pointer-events: none; box-shadow: var(--shadow-pop); }
.chart-tip strong { font: 600 14px/18px var(--font-mono); }

/* Table view of a chart */
.chart-table { max-height: 240px; overflow-y: auto; }
.chart-table table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; }
.chart-table th { position: sticky; top: 0; background: var(--surface-000); text-align: left; font-weight: 700; color: var(--ink-muted); padding: var(--space-2); border-bottom: 1px solid var(--line); }
.chart-table td { padding: 6px var(--space-2); border-bottom: 1px solid var(--line); }
.chart-table .n { text-align: right; }
.chart-table .num { font-variant-numeric: tabular-nums; color: var(--ink); }
.dash-continue { gap: var(--space-4); max-width: 100%; }
.dash-continue-text { display: grid; gap: 2px; min-width: 0; }
.dash-continue-text > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-continue-label { font: 500 12px/16px var(--font-mono); opacity: .85; }
.dash-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); margin-bottom: var(--space-7); }
.dash-stat { display: grid; gap: var(--space-1); padding: var(--space-4) var(--space-5); }
.dash-stat-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-md); background: var(--primary-soft); color: var(--primary-text); margin-bottom: var(--space-2); flex: none; }
.dash-stat-num { font: 600 32px/36px var(--font-mono); color: var(--ink); }   /* standalone figure: proportional digits */
.dash-cols { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }   /* the sidebar takes the side column now */
.dash-section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.dash-section-head .t-h2 { display: flex; align-items: center; gap: var(--space-2); }
.dash-section-head .t-h2 .icon { color: var(--primary-text); }
.dash-empty { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.dash-empty .dash-stat-icon { margin: 0; }
.dash-classes { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-4); }
.dash-class { display: grid; gap: var(--space-4); padding: var(--space-5); }
.dash-class-head { display: flex; align-items: center; gap: var(--space-3); }
.dash-class-head:hover .t-h3 { color: var(--primary-text); }
.dash-subjects { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.dash-subjects li { display: flex; align-items: center; gap: var(--space-3); }
.dash-subject-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-subject-bar { width: 64px; flex: none; }
.dash-subject-num { min-width: 40px; text-align: right; }
.dash-class-next { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3); margin: 0 calc(-1 * var(--space-2)) calc(-1 * var(--space-2)); border-radius: var(--radius-md); background: var(--well); }
.dash-class-next:hover { color: var(--primary-text); }
.dash-class-next .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.dash-recent { padding: var(--space-3); }
.dash-recent ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); column-gap: var(--space-2); }
.dash-recent-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); }
.dash-recent-row:hover { background: var(--surface-200); }
.dash-recent-row .grow { display: grid; min-width: 0; }
.dash-recent-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-recent-check { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: var(--on-primary); flex: none; }
/* Continue card, Almost done, Revise today */
.dash-next { margin-bottom: var(--space-6); padding: var(--space-5) var(--space-6); box-shadow: var(--shadow-card), inset 3px 0 0 var(--accent); }
.dash-next-in { display: grid; gap: var(--space-4); }
.dash-next-where, .dash-next-main { display: flex; align-items: center; gap: var(--space-4); }
.dash-next-main { flex-wrap: wrap; }
.dash-next-text { display: grid; gap: 2px; min-width: 0; }
.dash-next-text > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-next-title { margin: 0; }
.dash-next-bar { margin: 0; }
.dash-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-5); }
.dash-pair .dash-section-head { min-height: 40px; }
.dash-list { padding: var(--space-2); }
.dash-list ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.dash-list-empty { margin: 0; padding: var(--space-3); }
.dash-list-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); }
.dash-list-row:hover { background: var(--surface-200); }
.dash-list-text { display: grid; min-width: 0; }
.dash-list-text > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-list-title { font-weight: 700; }
.dash-list-meter { display: grid; gap: 4px; justify-items: end; width: 64px; flex: none; }
.dash-list-meter .bar { width: 100%; }
.dash-list-icon { display: grid; place-items: center; width: 28px; height: 28px; flex: none; border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary-text); }
.side-count { font: 600 12px/18px var(--font-mono); min-width: 22px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--primary); color: var(--on-primary); text-align: center; }
@media (max-width: 1100px) { .dash-pair { grid-template-columns: minmax(0, 1fr); gap: 0; } }
@media (max-width: 720px) {
    .dash-next { padding: var(--space-4); }
    .dash-next-main .btn { width: 100%; justify-content: center; }
}

@media (max-width: 1100px) {
    .dash-charts { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
    .dash-cols { grid-template-columns: 1fr; }
    .dash-stats { grid-template-columns: repeat(2, 1fr); }
    /* Sidebar folds into a block above the dashboard; section links scroll sideways */
    .dash-layout { grid-template-columns: 1fr; }
    .dash-layout { min-height: 0; }
    .dash-side { position: static; height: auto; gap: var(--space-4); border-right: 0; border-bottom: 1px solid var(--line); }
    .side-foot { margin-top: 0; }
    .dash-main { padding: var(--space-5) var(--space-4) var(--space-7); }
    .page-wide { padding: 0 var(--space-4); }
    .side-nav { display: flex; gap: var(--space-2); overflow-x: auto; margin: 0 calc(-1 * var(--space-4)); padding: 0 var(--space-4); }
    .side-nav .side-link { width: auto; flex: none; background: var(--surface-200); }
    .side-group { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
    .side-group .side-label { grid-column: 1 / -1; }
    .side-foot { display: flex; gap: var(--space-2); }
    .side-foot .side-link { width: auto; }
}
@media (max-width: 720px) {
    .dash-head { padding-top: var(--space-6); }
    .dash-continue { width: 100%; justify-content: space-between; }
    .dash-stat-num { font-size: 26px; line-height: 30px; }
}
/* ---- Motion ------------------------------------------------------------
   One easing, short durations, everything moves up a few pixels and fades in.
   Entry animations use fill-mode "backwards" so nothing keeps a transform once done
   (transforms would trap the header menu and break hover lifts). */
:root { --ease-out: cubic-bezier(.2, .7, .2, 1); --ease-pop: cubic-bezier(.3, 1.5, .5, 1); }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes bar-grow { from { width: 0; } }
@keyframes ring-fill { from { stroke-dashoffset: 323.6; } }
@keyframes tag-in { from { opacity: 0; transform: scale(.6); } }
@keyframes spin-in { from { opacity: 0; transform: rotate(-90deg) scale(.6); } }

/* View entry (class is re-added by tulikaMotion.enter() on every navigation) */
.is-entering { animation: fade .25s ease-out backwards; }
.is-entering .rise { animation: rise .45s var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * 70ms); }
.is-entering .stagger > * { animation: rise .42s var(--ease-out) backwards; animation-delay: calc(120ms + var(--i, 0) * 45ms); }
.is-entering .stagger .stagger > * { animation-delay: calc(200ms + var(--i, 0) * 35ms); }
.is-entering .bar > i { animation: bar-grow .8s var(--ease-out) backwards; animation-delay: .25s; }
.is-entering .ring-fg { animation: ring-fill 1s var(--ease-out) backwards; animation-delay: .15s; }
body.is-loading .is-entering, body.is-loading .is-entering * { animation-play-state: paused; }

/* Landing sections reveal on scroll */
.reveal-on [data-reveal] { transition: opacity .6s var(--ease-out), transform .6s var(--ease-out); }
.reveal-on [data-reveal]:not(.is-in) { opacity: 0; transform: translateY(24px); }
.reveal-on [data-reveal]:not(.is-in) .rise,
.reveal-on [data-reveal]:not(.is-in) .stagger > * { animation: none; }
.reveal-on [data-reveal].is-in { transform: none; }

/* Chapter lists and the class menu drop open */
.t-drop { transition: opacity .2s ease-out, transform .22s var(--ease-out); }
.t-drop-from { opacity: 0; transform: translateY(-6px); }
.t-drop-to { opacity: 1; transform: none; }
.t-fade { transition: opacity .12s ease-in; }
.t-fade-from { opacity: 1; }
.t-fade-to { opacity: 0; }
.menu.t-drop-from { transform: translateY(-6px) scale(.98); transform-origin: top left; }

/* Hover and press */
a.card, .res, .result, .l-class { transition: transform .18s var(--ease-out), box-shadow .18s ease-out; }
a.card:hover, .res:hover, .result:hover, .l-class:hover { transform: translateY(-2px); }
.btn { transition: transform .12s ease-out, filter .15s ease-out, background .15s ease-out, color .15s ease-out; }
.btn:active, .chip:active, .theme-btn:active { transform: scale(.97); }
.chip { transition: background .15s ease-out, border-color .15s ease-out, color .15s ease-out, transform .12s ease-out; }
.btn .icon, .l-open .icon, .result > span:last-child .icon, .l-class-go .icon { transition: transform .18s var(--ease-out); }
.btn:hover .icon:last-child, .l-open:hover .icon, .result:hover > span:last-child .icon, .l-class:hover .l-class-go .icon { transform: translateX(3px); }
.res-icon { transition: transform .2s var(--ease-pop); }
.res:hover .res-icon { transform: scale(1.08); }
.glyph { transition: transform .2s var(--ease-pop); }
.card:hover .card-head .glyph { transform: rotate(-6deg) scale(1.06); }
.theme-btn svg { animation: spin-in .35s var(--ease-pop); }
.topic-title, .res-title { transition: color .15s ease-out; }

/* Ticking a topic */
.check { transition: background .15s ease-out, border-color .15s ease-out, transform .12s ease-out; }
.check:active { transform: scale(.88); }
.check::after { transform: rotate(-45deg) translate(1px, -1px) scale(.3); transition: opacity .12s ease-out, transform .25s var(--ease-pop); }
.check:checked::after { transform: rotate(-45deg) translate(1px, -1px) scale(1); }
.next-tag { animation: tag-in .3s var(--ease-pop) backwards; animation-delay: .35s; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
    .reveal-on [data-reveal] { opacity: 1 !important; transform: none !important; }
    .loader { animation: loader-fallback 0s 8s forwards !important; }   /* keep the no-JS safety net */
}
