/* ============================================================ tokens */
:root {
  --bg: #0b0f17; --bg2: #101624; --card: #141b2b; --card2: #1a2336; --line: #253049; --line2: #31405f;
  --text: #e6ebf5; --text2: #cfd7e6; --muted: #8e9bb4; --head: #ffffff; --head2: #ffe1c9;
  --accent: #ff8a3d; --accent2: #ffc14d; --teal: #2dd4bf; --violet: #a78bfa; --ok: #34d399; --bad: #f87171;
  --code-bg: #0d1320; --code-text: #dbe4f3; --inline-code: #1c2539; --inline-code-text: #ffd9b8;
  --topbar: rgba(11, 15, 23, .78); --sidebar: rgba(16, 22, 36, .6);
  --radius: 14px; --shadow: 0 10px 30px rgba(0, 0, 0, .35); --topbar-h: 60px;
  --mono: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f6f7fb; --bg2: #eef1f7; --card: #ffffff; --card2: #f2f4f9; --line: #e0e5ef; --line2: #cfd6e4;
  --text: #1c2333; --text2: #333d52; --muted: #6a7488; --head: #0f1524; --head2: #b4521a;
  --accent: #f0702a; --accent2: #e8a317; --ok: #0f9f6e; --bad: #dc3d3d;
  --inline-code: #fff0e5; --inline-code-text: #a2420f;
  --topbar: rgba(246, 247, 251, .82); --sidebar: rgba(255, 255, 255, .7);
  --shadow: 0 8px 24px rgba(23, 32, 58, .08);
  color-scheme: light;
}

/* ============================================================ base */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 16px); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.68 var(--sans); transition: background .3s, color .3s; overflow-x: hidden; }
a { color: var(--accent2); }
[data-theme="light"] a { color: #c25a12; }
code { font-family: var(--mono); font-size: .87em; background: var(--inline-code); padding: .1em .38em; border-radius: 6px; color: var(--inline-code-text); overflow-wrap: anywhere; }
kbd { font-family: var(--mono); font-size: .72em; border: 1px solid currentColor; border-bottom-width: 2px; border-radius: 4px; padding: 0 .35em; opacity: .75; }
.btn kbd { margin-left: .4em; }
.small { font-size: .8rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
::selection { background: rgba(255, 138, 61, .35); }

/* background orbs */
.bg-orbs { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.bg-orbs span { position: absolute; width: 520px; height: 520px; border-radius: 50%; filter: blur(110px); opacity: .15; animation: float 22s ease-in-out infinite; }
.bg-orbs span:nth-child(1) { background: var(--accent); top: -160px; left: -120px; }
.bg-orbs span:nth-child(2) { background: var(--violet); bottom: -200px; right: -120px; animation-delay: -7s; }
.bg-orbs span:nth-child(3) { background: var(--teal); top: 40%; left: 45%; animation-delay: -14s; opacity: .07; }
[data-theme="light"] .bg-orbs span { opacity: .08; }
@keyframes float { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(60px, 40px) scale(1.12); } }

/* reading progress */
.read-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 40; pointer-events: none; }
#read-progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--teal), var(--accent)); }

/* ============================================================ top bar */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: 1rem;
  padding: 0 1.2rem; padding-left: max(1.2rem, env(safe-area-inset-left)); background: var(--topbar);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--head) !important; text-decoration: none; font-size: 1.12rem; white-space: nowrap; }
.brand b { color: var(--accent); }
.brand-sub { color: var(--muted); font-weight: 400; }
.brand-logo { font-size: 1.5rem; animation: wiggle 5s ease-in-out infinite; display: inline-block; }
@keyframes wiggle { 0%, 90%, 100% { transform: rotate(0); } 93% { transform: rotate(-12deg); } 96% { transform: rotate(10deg); } }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; flex: none; background: var(--card); border: 1px solid var(--line); color: var(--text); font-size: 1.1rem; border-radius: 10px; cursor: pointer; transition: border-color .2s, transform .15s; }
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:active { transform: scale(.94); }
.menu-btn { display: none; }
.progress-wrap { flex: 1; display: flex; align-items: center; gap: .7rem; max-width: 380px; margin-left: auto; font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.progress { flex: 1; height: 8px; background: var(--card2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 99px; transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.countdown { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; padding: .3rem .75rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); white-space: nowrap; }
.cd-label { font-size: .64rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.cd-time { font-family: var(--mono); font-weight: 700; color: var(--accent2); font-size: 1.02rem; font-variant-numeric: tabular-nums; }
[data-theme="light"] .cd-time { color: var(--accent); }
.countdown.urgent { border-color: var(--bad); } .countdown.urgent .cd-time { color: var(--bad); animation: pulse 1s infinite; }
.countdown.live { border-color: var(--ok); } .countdown.live .cd-time { color: var(--ok); }
@keyframes pulse { 50% { opacity: .55; } }

/* ============================================================ layout */
.layout { position: relative; z-index: 1; display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: calc(100vh - var(--topbar-h)); }
.sidebar { position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; overscroll-behavior: contain; padding: 1rem .8rem 2rem; border-right: 1px solid var(--line); background: var(--sidebar); scrollbar-width: thin; }
.sidebar-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .35rem; margin: 0 .2rem .8rem; }
.sidebar-stats div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .4rem .2rem; text-align: center; line-height: 1.2; min-width: 0; }
.sidebar-stats b { display: block; font-size: 1.05rem; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sidebar-stats b small { font-size: .62rem; color: var(--muted); font-weight: 500; }
.sidebar-stats span { font-size: .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.nav-search { margin: 0 .2rem .9rem; }
.nav-search input { width: 100%; font: inherit; font-size: .84rem; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .45rem .7rem; outline: none; transition: border-color .2s, box-shadow .2s; }
.nav-search input::placeholder { color: var(--muted); }
.nav-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 138, 61, .15); }
.nav-link.filtered-out, .nav-group.filtered-out { display: none; }
.nav-group { margin-bottom: .9rem; }
.nav-group-title { font-size: .68rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 0 .6rem .3rem; }
.nav-link { display: grid; grid-template-columns: 1.6rem 1fr auto auto; align-items: center; gap: .35rem; padding: .46rem .6rem; border-radius: 10px; color: var(--text2) !important; text-decoration: none; font-size: .89rem; line-height: 1.35; transition: background .2s, transform .2s, color .2s; position: relative; }
.nav-link:hover { background: var(--card2); transform: translateX(3px); color: var(--head) !important; }
.nav-link.active { background: linear-gradient(90deg, rgba(255, 138, 61, .2), rgba(255, 138, 61, .02)); color: var(--head) !important; font-weight: 600; }
.nav-link.active::before { content: ""; position: absolute; left: 0; top: 18%; bottom: 18%; width: 3px; border-radius: 3px; background: var(--accent); }
.nav-min { font-size: .7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-check { width: 1.15rem; height: 1.15rem; display: grid; place-items: center; font-size: .66rem; border-radius: 50%; border: 1px solid var(--line2); color: transparent; transition: all .3s; }
.nav-link.done .nav-check { background: var(--ok); border-color: var(--ok); color: #fff; }
.nav-foot { padding: .6rem; display: grid; gap: .6rem; justify-items: start; border-top: 1px solid var(--line); margin-top: .5rem; }
.backdrop { display: none; }

.main { padding: 2rem clamp(1rem, 4vw, 3.5rem) 6rem; max-width: 1080px; width: 100%; min-width: 0; }

/* ============================================================ lesson */
#main.htmx-swapping .lesson { opacity: 0; transform: translateY(8px); transition: all .15s ease-in; }
.lesson { animation: slideIn .45s cubic-bezier(.2, .8, .2, 1); }
@keyframes slideIn { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.lesson-body > * { animation: rise .5s both cubic-bezier(.2, .8, .2, 1); }
.lesson-body > *:nth-child(2) { animation-delay: .04s; } .lesson-body > *:nth-child(3) { animation-delay: .08s; }
.lesson-body > *:nth-child(4) { animation-delay: .12s; } .lesson-body > *:nth-child(5) { animation-delay: .16s; }
.lesson-body > *:nth-child(n+6) { animation-delay: .2s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.lesson-head { margin-bottom: 1.4rem; }
.crumb { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .1em; }
.lesson-head h1 { font-size: clamp(1.6rem, 4.2vw, 2.4rem); line-height: 1.2; margin: .3rem 0 .6rem; display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.lesson-title { background: linear-gradient(90deg, var(--head), var(--head2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lesson-meta { display: flex; gap: .5rem; flex-wrap: wrap; }
.toc { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: 1rem; align-items: center; }
.toc-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-right: .3rem; }
.toc a { font-size: .78rem; padding: .18rem .65rem; border-radius: 99px; border: 1px solid var(--line); color: var(--text2) !important; text-decoration: none; background: var(--card); transition: all .2s; }
.toc a:hover, .toc a.on { border-color: var(--accent); color: var(--head) !important; background: rgba(255, 138, 61, .1); }

.lesson-body h2 { font-size: clamp(1.2rem, 3vw, 1.42rem); margin: 2.4rem 0 .8rem; padding-bottom: .45rem; border-bottom: 1px solid var(--line); color: var(--head); }
.lesson-body h2::before { content: "◆ "; color: var(--accent); font-size: .8em; }
.lesson-body h3 { font-size: 1.08rem; margin: 1.5rem 0 .5rem; color: var(--head2); }
.lesson-body p, .lesson-body li { color: var(--text2); }
.lesson-body ul, .lesson-body ol { padding-left: 1.3rem; }
.lesson-body li { margin: .3rem 0; }
.lesson-body li::marker { color: var(--accent); }
.table-scroll { overflow-x: auto; margin: 1rem 0; border-radius: 12px; border: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
.lesson-body table:not(.rt) { border-collapse: collapse; width: 100%; font-size: .91rem; margin: 0; }
.lesson-body table:not(.rt) th, .lesson-body table:not(.rt) td { border-bottom: 1px solid var(--line); padding: .55rem .75rem; text-align: left; vertical-align: top; }
.lesson-body table:not(.rt) th { background: var(--card2); color: var(--head2); font-weight: 600; white-space: nowrap; }
.lesson-body table:not(.rt) tr:last-child td { border-bottom: 0; }
.lesson-body table:not(.rt) td + td, .lesson-body table:not(.rt) th + th { border-left: 1px solid var(--line); }
.lesson-body table:not(.rt) tbody tr:hover td, .lesson-body table:not(.rt) tr:hover td { background: rgba(255, 138, 61, .04); }

/* chips / badges */
.chip { display: inline-block; font-size: .76rem; padding: .14rem .6rem; border-radius: 99px; background: var(--card2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge { display: inline-block; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: .14rem .55rem; border-radius: 6px; background: var(--violet); color: #1b1240; }
.lvl-easy { background: var(--ok); color: #03301f; } .lvl-medium { background: var(--accent2); color: #4a2a00; } .lvl-hard { background: var(--bad); color: #4a0b0b; }

/* cards */
.card { background: linear-gradient(180deg, var(--card), var(--bg2)); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin: 1.1rem 0; box-shadow: var(--shadow); min-width: 0; }
[data-theme="light"] .card { background: var(--card); }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr)); margin: 1rem 0; }
.grid .card { margin: 0; transition: transform .25s, border-color .25s; }
.grid .card:hover { transform: translateY(-4px); border-color: rgba(255, 138, 61, .5); }
.card h4 { margin: 0 0 .4rem; color: var(--head); }
.card p { margin: .35rem 0; font-size: .93rem; }
.stat { font-size: 2rem; font-weight: 800; background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1.1; }

/* callouts */
.callout { border-radius: 12px; padding: .85rem 1.1rem .85rem 3rem; margin: 1.1rem 0; position: relative; border: 1px solid; }
.callout::before { position: absolute; left: 1rem; top: .8rem; font-size: 1.15rem; }
.callout.tip { background: rgba(45, 212, 191, .07); border-color: rgba(45, 212, 191, .35); } .callout.tip::before { content: "💡"; }
.callout.trap { background: rgba(248, 113, 113, .07); border-color: rgba(248, 113, 113, .35); } .callout.trap::before { content: "⚠️"; }
.callout.info { background: rgba(167, 139, 250, .07); border-color: rgba(167, 139, 250, .35); } .callout.info::before { content: "ℹ️"; }
.callout.key { background: rgba(255, 193, 77, .08); border-color: rgba(255, 193, 77, .45); } .callout.key::before { content: "🔑"; }
.callout p:first-child { margin-top: 0; } .callout p:last-child { margin-bottom: 0; }

/* code (always dark, both themes) */
pre { background: var(--code-bg); border: 1px solid #253049; border-radius: 12px; padding: 1rem 1.1rem; overflow-x: auto; font-size: .85rem; line-height: 1.58; position: relative; color: var(--code-text); -webkit-overflow-scrolling: touch; tab-size: 4; }
pre code { background: none; padding: 0; color: inherit; font-size: inherit; overflow-wrap: normal; }
pre .copy { position: absolute; top: .45rem; right: .45rem; font: 600 .7rem var(--sans); background: #1a2336; color: #93a0b8; border: 1px solid #31405f; border-radius: 6px; padding: .2rem .55rem; cursor: pointer; opacity: 0; transition: opacity .2s, color .2s; }
pre:hover .copy, pre .copy:focus { opacity: 1; } pre .copy:hover { color: #fff; }
@media (hover: none) { pre .copy { opacity: .85; } }
.tk-kw { color: #ff9e64; font-weight: 600; } .tk-str { color: #9ece6a; } .tk-num { color: #e0af68; }
.tk-com { color: #6b7896; font-style: italic; } .tk-fn { color: #7dcfff; } .tk-bi { color: #bb9af7; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.two-col > .card { margin: 0; }
.label { font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-bottom: .3rem; }

/* buttons */
.btn { font: inherit; font-size: .9rem; font-weight: 600; border: 0; cursor: pointer; padding: .55rem 1rem; border-radius: 10px; color: #1a0e02; background: linear-gradient(135deg, var(--accent), var(--accent2)); transition: transform .15s, box-shadow .2s, filter .2s; box-shadow: 0 6px 18px rgba(255, 138, 61, .22); display: inline-flex; align-items: center; gap: .25rem; min-height: 40px; }
.btn:hover { transform: translateY(-2px); filter: brightness(1.07); }
.btn:active { transform: translateY(0) scale(.98); }
.btn:disabled { opacity: .6; cursor: progress; transform: none; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line2); box-shadow: none; }
.btn.ghost:hover { border-color: var(--accent); }
.btn.small { padding: .35rem .75rem; font-size: .8rem; min-height: 32px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: .7rem; }

/* quiz */
.quiz { border-left: 3px solid var(--violet); }
.quiz-q { font-weight: 600; margin-bottom: .7rem; color: var(--head); }
.quiz-opts { display: grid; gap: .45rem; }
.quiz-opt { display: flex; gap: .65rem; align-items: center; padding: .55rem .8rem; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; transition: border-color .2s, background .2s; }
.quiz-opt:hover { border-color: var(--accent); background: rgba(255, 138, 61, .05); }
.quiz-opt input { accent-color: var(--accent); width: 1.05rem; height: 1.05rem; flex: none; }
.quiz-opt:has(input:checked) { border-color: var(--accent); background: rgba(255, 138, 61, .1); }
.quiz-opt.right { border-color: var(--ok); background: rgba(52, 211, 153, .1); }
.quiz-opt.right::after { content: "✓"; margin-left: auto; color: var(--ok); font-weight: 700; }
.quiz-opt.wrong { border-color: var(--bad); background: rgba(248, 113, 113, .08); }
.quiz-opt.wrong::after { content: "✗"; margin-left: auto; color: var(--bad); font-weight: 700; }
.quiz.answered-ok { border-left-color: var(--ok); }
.quiz.answered-ok .quiz-q .badge { background: var(--ok); color: #03301f; }
.quiz.answered-ok .quiz-q .badge::after { content: " ✓"; }

/* verdicts */
.verdict { margin-top: .8rem; padding: .65rem .9rem; border-radius: 10px; animation: pop .35s cubic-bezier(.2, 1.6, .4, 1); overflow-wrap: anywhere; }
.verdict.ok { background: rgba(52, 211, 153, .12); border: 1px solid rgba(52, 211, 153, .45); }
.verdict.bad { background: rgba(248, 113, 113, .1); border: 1px solid rgba(248, 113, 113, .45); animation: shake .4s; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

/* exercises */
.exercise { border-left: 3px solid var(--accent); position: relative; transition: border-color .3s; }
.exercise.solved { border-left-color: var(--ok); }
.solved-mark { display: none; margin-left: auto; font-size: .76rem; font-weight: 700; color: var(--ok); }
.exercise.solved .solved-mark { display: inline; animation: pop .4s; }
.ex-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.ex-head h3 { margin: 0; font-size: 1.06rem; color: var(--head); }
.ex-prompt { margin: .6rem 0 .8rem; color: var(--text2); }
.ex-prompt ul { margin: .3rem 0; }
.code-editor { display: block; width: 100%; font-family: var(--mono); font-size: .86rem; line-height: 1.55; color: #e7eefb; background: var(--code-bg); border: 1px solid #253049; border-radius: 10px; padding: .8rem; resize: vertical; tab-size: 4; outline: none; transition: border-color .2s, box-shadow .2s; white-space: pre; overflow-x: auto; min-height: 120px; caret-color: var(--accent); }
.code-editor:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 138, 61, .18); }
.code-editor.edited { border-left: 3px solid var(--accent2); }
.btn:disabled[hx-get] { cursor: not-allowed; }

/* mock contest timer */
.mock-timer { border-left: 3px solid var(--teal); }
.mock-pill { position: fixed; left: 1.2rem; bottom: 1.2rem; z-index: 26; display: none; align-items: center; gap: .4rem; padding: .45rem .85rem; border-radius: 99px; background: var(--card); border: 1px solid var(--teal); color: var(--text) !important; text-decoration: none; font: 700 .9rem var(--mono); box-shadow: var(--shadow); font-variant-numeric: tabular-nums; }
.mock-pill.on { display: inline-flex; animation: pop .3s; }
.mock-pill.warn { border-color: var(--accent2); color: var(--accent2) !important; }
.mt-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.mt-time { font-family: var(--mono); font-size: clamp(1.8rem, 6vw, 2.6rem); font-weight: 800; letter-spacing: .04em; color: var(--teal); font-variant-numeric: tabular-nums; line-height: 1.2; margin: .2rem 0 .4rem; }
.mt-bar { height: 6px; border-radius: 99px; background: var(--card2); border: 1px solid var(--line); overflow: hidden; }
.mt-bar > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--teal), var(--accent)); transition: width 1s linear; }
.mock-timer.running .mt-time { color: var(--ok); }
.mock-timer.warn .mt-time { color: var(--accent2); }
.mock-timer.over { border-left-color: var(--bad); }
.mock-timer.over .mt-time { color: var(--bad); animation: pulse 1s 3; }
.mt-solved { margin-left: auto; font-weight: 600; }
@media (max-width: 640px) { .mock-pill { left: 1rem; bottom: 1rem; } }
.ex-result:empty { display: none; }
.ex-result { margin-top: .6rem; min-width: 0; }
.hint, .solution { margin-top: .8rem; padding: .75rem .95rem; border-radius: 10px; background: rgba(255, 193, 77, .08); border: 1px dashed rgba(255, 193, 77, .5); animation: pop .3s; }
.solution { background: rgba(167, 139, 250, .07); border-color: rgba(167, 139, 250, .45); }
.solution pre { margin: .4rem 0; }
.sol-title { font-weight: 700; margin-bottom: .2rem; }
.tests { display: grid; gap: .35rem; margin-top: .5rem; }
.test { padding: .4rem .75rem; border-radius: 8px; font-size: .88rem; min-width: 0; }
.test.ok { background: rgba(52, 211, 153, .07); color: var(--ok); }
.test.bad { background: rgba(248, 113, 113, .07); color: var(--bad); }
.test-detail { color: var(--text); margin-top: .35rem; display: grid; gap: .15rem; }
.test-detail b { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.test-detail pre { margin: 0 0 .4rem; padding: .5rem .7rem; font-size: .79rem; max-height: 220px; white-space: pre-wrap; word-break: break-word; }
.table-wrap { overflow-x: auto; margin: .4rem 0; max-width: 100%; -webkit-overflow-scrolling: touch; }
table.rt { border-collapse: collapse; font-family: var(--mono); font-size: .79rem; width: auto; margin: 0; }
table.rt th, table.rt td { border: 1px solid var(--line); padding: .25rem .6rem; white-space: nowrap; }
table.rt th { background: var(--card2); color: var(--head2); }
table.rt tr:nth-child(even) td { background: rgba(127, 127, 127, .05); }
i.null { color: var(--muted); }
.muted { color: var(--muted); font-size: .88rem; }
details.expected { margin-top: .5rem; } details summary { cursor: pointer; color: var(--accent2); font-weight: 600; }
[data-theme="light"] details summary { color: var(--accent); }

/* schema */
.schema-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.schema-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); gap: .5rem; }
.schema-table { padding: .45rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card2); }
.schema-name { font-family: var(--mono); font-weight: 700; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: .9rem; }
.schema-name:hover, .schema-name.on { text-decoration: underline; }
.schema-name.on::after { content: " ▾"; }
.schema-cols { font-family: var(--mono); font-size: .74rem; color: var(--muted); overflow-wrap: anywhere; }
.peek:not(:empty) { margin-top: .8rem; animation: pop .3s; }
.peek-title { font-weight: 700; font-family: var(--mono); }

/* timeline */
.timeline { position: relative; margin: 1rem 0 1rem .5rem; padding-left: 1.4rem; border-left: 2px dashed var(--line2); }
.timeline .t { position: relative; margin-bottom: .85rem; color: var(--text2); }
.timeline .t::before { content: ""; position: absolute; left: -1.88rem; top: .45rem; width: .8rem; height: .8rem; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(255, 138, 61, .2); }
.timeline .t b { color: var(--accent2); font-family: var(--mono); }
[data-theme="light"] .timeline .t b { color: var(--accent); }

/* lesson footer */
.lesson-foot { margin-top: 3rem; padding-top: 1.4rem; border-top: 1px solid var(--line); }
.done-btn.is-done { background: linear-gradient(135deg, #10b981, #34d399); }
.pagers { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.2rem; }
.pager { display: flex; flex-direction: column; padding: .85rem 1rem; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--text) !important; background: var(--card); transition: border-color .2s, transform .2s; min-width: 0; }
.pager.next { text-align: right; grid-column: 2; }
.pager:hover { border-color: var(--accent); transform: translateY(-2px); }
.pager small { color: var(--muted); }

/* spinner */
.spinner { width: 18px; height: 18px; border: 2px solid var(--line2); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator, .spinner.on { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.run-status { padding: .4rem 0; } .run-status::before { content: "⏳ "; }

/* hero */
.hero { padding: 1.5rem; border-radius: 18px; background: radial-gradient(circle at 10% 10%, rgba(255, 138, 61, .22), transparent 50%), radial-gradient(circle at 90% 80%, rgba(167, 139, 250, .18), transparent 50%), var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.hero p { font-size: 1.04rem; margin-top: 0; }

/* toast, confetti, back-to-top */
.toast { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 60; background: var(--card); color: var(--text); border: 1px solid var(--ok); padding: .7rem 1rem; border-radius: 12px; box-shadow: var(--shadow); animation: pop .3s; transition: opacity .35s, transform .35s; }
.toast.out { opacity: 0; transform: translateY(8px); }
.confetti { position: fixed; z-index: 70; width: 8px; height: 12px; border-radius: 2px; pointer-events: none; animation: burst 1s ease-out forwards; }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; } }
.to-top { position: fixed; right: 1.4rem; bottom: 1.4rem; z-index: 25; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line2); background: var(--card); color: var(--text); font-size: 1.1rem; cursor: pointer; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .25s, transform .25s, border-color .2s; }
.to-top:hover { border-color: var(--accent); }
body.scrolled .to-top { opacity: 1; transform: none; pointer-events: auto; }

/* ============================================================ responsive */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); }
  .progress-wrap { max-width: 220px; }
}
@media (max-width: 900px) {
  :root { --topbar-h: 56px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: grid; }
  .sidebar { position: fixed; left: 0; top: var(--topbar-h); bottom: 0; height: auto; width: min(310px, 86vw); z-index: 35; transform: translateX(-105%); transition: transform .3s cubic-bezier(.2, .8, .2, 1); background: var(--bg2); box-shadow: 10px 0 40px rgba(0, 0, 0, .35); padding-bottom: calc(2rem + env(safe-area-inset-bottom)); }
  body.nav-open .sidebar { transform: none; }
  .backdrop { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 34; background: rgba(0, 0, 0, .45); opacity: 0; pointer-events: none; transition: opacity .3s; backdrop-filter: blur(2px); }
  body.nav-open .backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  .progress-wrap { display: none; }
  .countdown { margin-left: auto; }
  .main { padding: 1.4rem 1rem 6rem; }
}
@media (max-width: 640px) {
  body { font-size: 15.5px; }
  .topbar { gap: .55rem; padding: 0 .7rem; }
  .brand-sub, .cd-label { display: none; }
  .countdown { padding: .35rem .6rem; }
  .cd-time { font-size: .92rem; }
  .icon-btn { width: 38px; height: 38px; }
  .two-col { grid-template-columns: minmax(0, 1fr); }
  .card { padding: .95rem 1rem; }
  .callout { padding: .8rem .9rem .8rem 2.6rem; }
  .callout::before { left: .8rem; }
  pre { font-size: .78rem; padding: .85rem .9rem; border-radius: 10px; margin-left: -.25rem; margin-right: -.25rem; }
  .code-editor { font-size: .8rem; }
  .row .btn { flex: 1 1 auto; justify-content: center; }
  .row .btn kbd { display: none; }
  .pagers { grid-template-columns: minmax(0, 1fr); }
  .pager.next { grid-column: 1; }
  .pager-spacer { display: none; }
  .toast { left: 1rem; right: 1rem; bottom: 1rem; text-align: center; }
  .to-top { right: 1rem; bottom: 1rem; }
  .lesson-body table:not(.rt) { font-size: .84rem; }
  .lesson-body table:not(.rt) th { white-space: normal; }
  .timeline { margin-left: .3rem; }
}
@media (max-width: 380px) {
  .brand-text { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  html { scroll-behavior: auto; }
}
@media print {
  .topbar, .sidebar, .bg-orbs, .to-top, .lesson-foot, .exercise form, .read-progress, .mock-pill, .mock-timer, .quiz .row { display: none !important; }
  .layout { display: block; } body { background: #fff; color: #000; }
}
