:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #1b2130;
  --muted: #5b6475;
  --border: #dde2ea;
  --accent: #3b5bdb;
  --accent-soft: #e7ecff;
  --ok: #2b8a3e;
  --phy: #1c7ed6;
  --chem: #2b8a3e;
  --math: #c2255c;
  --radius: 12px;
  --glass: rgba(255, 255, 255, .78);
  --grid-line: rgba(59, 91, 219, .07);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11141b;
    --surface: #1a1f2a;
    --surface-2: #232a38;
    --text: #e6e9ef;
    --muted: #9aa3b5;
    --border: #2e3647;
    --accent: #7c96ff;
    --accent-soft: #252f4d;
    --ok: #51cf66;
    --phy: #4dabf7;
    --chem: #51cf66;
    --math: #f06595;
    --glass: rgba(26, 31, 42, .78);
    --grid-line: rgba(124, 150, 255, .07);
  }
}
:root[data-theme="dark"] {
  --bg: #11141b;
  --surface: #1a1f2a;
  --surface-2: #232a38;
  --text: #e6e9ef;
  --muted: #9aa3b5;
  --border: #2e3647;
  --accent: #7c96ff;
  --accent-soft: #252f4d;
  --ok: #51cf66;
  --phy: #4dabf7;
  --chem: #51cf66;
  --math: #f06595;
  --glass: rgba(26, 31, 42, .78);
  --grid-line: rgba(124, 150, 255, .07);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background-color: var(--bg);
  background-image:
    radial-gradient(40vw 40vw at 0% 10%, color-mix(in srgb, var(--phy) 14%, transparent), transparent 70%),
    radial-gradient(40vw 40vw at 100% 0%, color-mix(in srgb, var(--math) 12%, transparent), transparent 70%),
    radial-gradient(50vw 40vw at 50% 100%, color-mix(in srgb, var(--chem) 12%, transparent), transparent 70%),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: auto, auto, auto, 28px 28px, 28px 28px;
  background-attachment: fixed;
  min-height: 100vh;
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.9rem; margin: .4em 0 .3em; }
h2 { font-size: 1.3rem; margin: 1.6em 0 .6em; }
h3 { font-size: 1.05rem; margin: 0 0 .4em; }

.container { max-width: 960px; margin: 0 auto; padding: 0 16px; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  padding: 10px 24px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 14px rgba(0, 0, 0, .05);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  color: #fff; background: linear-gradient(135deg, var(--phy), var(--accent));
}
.brand-logo svg { width: 22px; height: 22px; }
.brand-text { font-weight: 800; font-size: 1.25rem; letter-spacing: -.01em; }
.brand-text span { color: var(--accent); }
.topbar nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); font-weight: 500; padding: 6px 10px; border-radius: 8px; }
.topbar nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.topbar nav a.active { color: var(--accent); background: var(--accent-soft); }
.icon-btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 1rem;
}

.search {
  width: 100%; padding: 12px 14px; font-size: 1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.results { margin-top: 10px; }
.results a { display: block; padding: 8px 12px; border-radius: 8px; }
.results a:hover { background: var(--surface-2); text-decoration: none; }
.results small { color: var(--muted); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px;
}
a.card { display: block; color: var(--text); transition: border-color .15s, transform .15s; }
a.card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--c, var(--accent)); }
.progress-label { font-size: .85rem; color: var(--muted); margin-top: 6px; }

.chapter-list { display: grid; gap: 8px; }
.chapter-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; color: var(--text);
}
.chapter-row:hover { border-color: var(--accent); text-decoration: none; }
.chapter-row .num {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: .85rem;
  background: var(--surface-2); color: var(--muted);
}
.chapter-row.done .num { background: var(--ok); color: #fff; }
.chapter-row .title { flex: 1; font-weight: 500; }
.chapter-row small { color: var(--muted); }

.crumbs { font-size: .9rem; color: var(--muted); margin-top: 18px; }
.badge {
  display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); vertical-align: middle;
}

.topics { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; list-style: none; }
.topics li { font-size: .9rem; }
.topics a {
  display: block; background: var(--surface-2); color: var(--text); border-radius: 8px; padding: 4px 10px;
  border: 1px solid transparent;
}
.topics a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.hint { color: var(--muted); font-size: .88rem; margin: -6px 0 8px; }

.concept { margin-bottom: 10px; }
.concept p { margin: 0; }

.formulas { display: grid; gap: 8px; }
.formula {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 10px 14px; overflow-x: auto;
}

.example { margin-bottom: 12px; }
.example .q { font-weight: 500; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.steps { margin: 8px 0 0; padding-left: 22px; }
.steps li { margin-bottom: 4px; }
.ans {
  margin-top: 8px; padding: 8px 12px; border-radius: 8px;
  background: color-mix(in srgb, var(--ok) 12%, transparent);
}

.btn {
  display: inline-block; padding: 10px 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.pager { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 28px 0; }

.syl-subject { margin-bottom: 26px; }
.syl-chapter { margin-bottom: 10px; }
.syl-chapter strong { display: block; }
.syl-chapter span { color: var(--muted); font-size: .92rem; }

.pattern td, .pattern th { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.pattern { border-collapse: collapse; width: 100%; font-size: .93rem; }
.table-wrap { overflow-x: auto; }

.footer { color: var(--muted); font-size: .85rem; padding-top: 30px; padding-bottom: 30px; border-top: 1px solid var(--border); margin-top: 40px; }

.katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

@media (max-width: 560px) {
  h1 { font-size: 1.5rem; }
  .topbar nav { gap: 10px; font-size: .92rem; }
}

/* ---------- Home page ---------- */
.container.wide { max-width: 1180px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.subject-columns {
  display: grid; gap: 24px; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; margin-top: 32px;
}
.subject-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* pastel title box with an icon on each side */
.subject-banner {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 16px 14px; border-radius: 16px; color: var(--text);
  background: color-mix(in srgb, var(--c) 14%, var(--surface));
  border: 2px solid color-mix(in srgb, var(--c) 45%, transparent);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--c) 18%, transparent);
  transition: transform .15s;
}
.subject-banner:hover { text-decoration: none; transform: translateY(-2px); }
.subject-banner span { font-size: 1.55rem; font-weight: 800; letter-spacing: .02em; text-transform: uppercase; }
.banner-ico { width: 34px; height: 34px; color: var(--c); flex: none; }

/* frosted card listing the chapters */
.topic-card {
  background: var(--glass);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: 2px solid color-mix(in srgb, var(--c) 30%, transparent);
  border-radius: 16px; padding: 8px 16px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .06);
}
.class-label {
  font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  margin: 12px 0 2px;
}
.topic-list { list-style: none; margin: 0; padding: 0; }
.topic-item {
  display: flex; align-items: center; gap: 12px; padding: 8px; margin: 0 -8px; border-radius: 10px; color: var(--text);
}
.topic-item:hover { background: color-mix(in srgb, var(--c) 9%, transparent); text-decoration: none; }
.topic-icon {
  flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent);
}
.topic-icon .ico { width: 20px; height: 20px; }
.topic-item.done .topic-icon { color: #fff; background: var(--ok); }
.topic-text { min-width: 0; flex: 1; }
.topic-text b { display: block; font-size: .98rem; line-height: 1.3; }
.topic-text small {
  display: block; color: var(--muted); font-size: .8rem; line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topic-text small::before { content: "• "; color: var(--c); }
.topic-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; padding-top: 12px;
  border-top: 1px solid var(--border); font-size: .85rem; color: var(--muted);
}
.topic-foot a {
  display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: #fff; background: var(--c);
  padding: 7px 12px; border-radius: 9px;
}
.topic-foot a:hover { text-decoration: none; filter: brightness(1.08); }
.topic-foot .ico { width: 16px; height: 16px; }

.section-title { font-size: 1.4rem; margin: 40px 0 14px; }
.glass { background: var(--glass); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }

@media (max-width: 1000px) {
  .subject-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .subject-columns { grid-template-columns: minmax(0, 1fr); margin-top: 20px; }
  .topbar nav { gap: 2px; }
  .topbar nav a { padding: 5px 8px; font-size: .92rem; }
  .topbar { padding: 10px 16px; }
  .brand-text { font-size: 1.1rem; }
  .brand-logo { width: 32px; height: 32px; }
}

/* ---------- Chapter page (coaching-app layout) ---------- */
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

.ch-hero { display: flex; gap: 16px; align-items: center; margin-top: 10px; border-top: 4px solid var(--c); }
.topic-icon.big { width: 58px; height: 58px; border-radius: 16px; }
.topic-icon.big .ico { width: 28px; height: 28px; }
.ch-hero-text { min-width: 0; }
.ch-hero h1 { margin: .1em 0 .25em; }
.ch-kicker { font-size: .78rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--c); }
.ch-stats { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .86rem; color: var(--muted); }
.ch-score { display: inline-flex; align-items: center; gap: 4px; color: var(--ok); font-weight: 600; }
.ch-score .ico { width: 15px; height: 15px; }

.tabs {
  position: sticky; top: var(--topbar-h, 58px); z-index: 5;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px;
  margin: 14px 0 18px; padding: 5px; border-radius: 14px;
  background: var(--glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0, 0, 0, .06);
}
.tab {
  display: flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 6px; border-radius: 10px;
  color: var(--muted); font-weight: 600; font-size: .95rem;
}
.tab .ico { width: 18px; height: 18px; flex: none; }
.tab:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.tab.active { color: #fff; background: var(--c); }
.tab-title { font-size: 1.2rem; margin: 26px 0 10px; }

.learn h3 { display: flex; align-items: center; gap: 8px; }
.learn h3 .ico, .callout b .ico { width: 18px; height: 18px; flex: none; }
.learn .hint { margin: 0 0 8px; }

.theory { margin-top: 14px; }
.theory h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font-size: 1.2rem; }
.theory-num {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-size: .9rem; color: #fff; background: var(--c);
}
.theory > p { margin: 0 0 10px; font-size: 1.02rem; line-height: 1.7; }
.callout { margin-top: 12px; padding: 10px 14px; border-radius: 10px; border-left: 4px solid; }
.callout b { display: flex; align-items: center; gap: 7px; font-size: .9rem; }
.callout p { margin: 4px 0 0; }
.callout ul { margin: 6px 0 0; padding-left: 20px; }
.callout li { margin-bottom: 3px; }
.callout.analogy { background: color-mix(in srgb, #f59f00 12%, transparent); border-color: #f59f00; }
.callout.analogy b { color: #e67700; }
.callout.points { background: color-mix(in srgb, var(--ok) 10%, transparent); border-color: var(--ok); }
.callout.points b { color: var(--ok); }
.callout.mistake { background: color-mix(in srgb, #e03131 9%, transparent); border-color: #e03131; }
.callout.mistake b { color: #e03131; }
.callout.check { background: color-mix(in srgb, var(--accent) 9%, transparent); border-color: var(--accent); }
.callout.check b { color: var(--accent); }
.callout details { margin-top: 6px; }

.lvl {
  display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap;
}
.lvl-1 { color: #2b8a3e; background: color-mix(in srgb, #2b8a3e 14%, transparent); }
.lvl-2 { color: #1971c2; background: color-mix(in srgb, #1971c2 14%, transparent); }
.lvl-3 { color: #c2255c; background: color-mix(in srgb, #c2255c 14%, transparent); }
.lvl-filter { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 14px; }
.chip {
  font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; padding: 6px 12px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
}
.chip span { opacity: .7; font-weight: 500; }
.chip.active { color: #fff; background: var(--c); border-color: var(--c); }
.ex-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 6px; font-size: .9rem; }
.ex-topic { color: var(--muted); font-size: .82rem; }
.example .q, .pq .q { font-weight: 500; }
.card.flash { animation: flash 1.6s ease-out; scroll-margin-top: calc(var(--topbar-h, 58px) + 70px); }
@keyframes flash { from { box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 45%, transparent); } to { box-shadow: none; } }

.score-bar { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.score-ico { flex: none; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; color: #fff; background: #f59f00; }
.score-ico .ico { width: 22px; height: 22px; }
.score-text { flex: 1; min-width: 0; font-size: .92rem; }
.score-text .progress { margin-top: 6px; }
.score-text .progress > div { background: var(--ok); }
.reset-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; font-size: .88rem; }
.reset-btn .ico { width: 16px; height: 16px; }
.btn:disabled { opacity: .5; cursor: default; }

.pq { margin-bottom: 12px; border-left: 4px solid var(--border); }
.pq.is-right { border-left-color: var(--ok); }
.pq.is-wrong { border-left-color: #e03131; }
.options { display: grid; gap: 8px; margin-top: 10px; }
.opt {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; cursor: pointer;
  font: inherit; color: var(--text); background: var(--surface); padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 10px;
}
.opt:hover:not(:disabled) { border-color: var(--c); background: color-mix(in srgb, var(--c) 6%, var(--surface)); }
.opt:disabled { cursor: default; }
.opt-key {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: .8rem; font-weight: 700; background: var(--surface-2); color: var(--muted);
}
.opt.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--surface)); }
.opt.right .opt-key { background: var(--ok); color: #fff; }
.opt.wrong { border-color: #e03131; background: color-mix(in srgb, #e03131 10%, var(--surface)); }
.opt.wrong .opt-key { background: #e03131; color: #fff; }
.num-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.num-input {
  width: 160px; padding: 9px 12px; font: inherit; color: var(--text); background: var(--surface);
  border: 1.5px solid var(--border); border-radius: 10px;
}
.num-input:focus { outline: 2px solid var(--c); outline-offset: 1px; }
.num-input.shake { animation: shake .3s; border-color: #e03131; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.num-unit { color: var(--muted); }
.verdict { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-weight: 600; }
.verdict .ico { width: 18px; height: 18px; }
.verdict.ok { color: var(--ok); }
.verdict.no { color: #e03131; }
.solution { margin-top: 8px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-size: .95rem; }
.done-row { margin-top: 26px; }

@media (max-width: 560px) {
  .tab { flex-direction: column; gap: 2px; font-size: .78rem; padding: 7px 2px; }
  .ch-hero { align-items: flex-start; }
  .topic-icon.big { width: 46px; height: 46px; }
  .score-bar { flex-wrap: wrap; }
}
