/* ExamMaster static topic pages (scripts/generate_topic_pages.py).
   Tokens copy Brand.light / Brand.dark in lib/theme/brand.dart, the same set
   scripts/etl/papers/archive.css uses, so a topic page read from a search
   result sits in the same catalogue as the app it hands off to. Type is the
   app's bundled Lato from the Flutter asset tree; nothing is fetched from a
   third party except KaTeX, and only on pages that carry TeX. */

@font-face {
  font-family: "Lato";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/assets/fonts/Lato-Regular.ttf") format("truetype");
}
@font-face {
  font-family: "Lato";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/assets/fonts/Lato-Italic.ttf") format("truetype");
}
@font-face {
  font-family: "Lato";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/assets/assets/fonts/Lato-Bold.ttf") format("truetype");
}
@font-face {
  font-family: "Lato";
  font-style: normal;
  font-weight: 900;
  font-display: swap;
  src: url("/assets/assets/fonts/Lato-Black.ttf") format("truetype");
}

:root {
  --accent: #4338ca;
  --accent-deep: #312e81;
  --accent-soft: #eef0fe;
  --accent-line: #c9cdf6;
  --ground: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #f2f3f5;
  --hairline: #e4e6ea;
  --ink: #212427;
  --ink-soft: #4c5158;
  --ink-muted: #80858c;
  --on-accent: #ffffff;
  --good: #1a7f4b;
  --shadow-lift: 0 1px 2px rgb(23 40 73 / 6%), 0 6px 18px -12px rgb(23 40 73 / 18%);
  --radius-chip: 6px;
  --radius-card: 10px;
  --radius-tile: 14px;
  --wrap: 1180px;
  --measure: 760px;
  --bar: 64px;
  --ease: 160ms cubic-bezier(0.2, 0, 0, 1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #818cf8;
    --accent-deep: #a5b0ff;
    --accent-soft: #24263f;
    --accent-line: #3c3f6a;
    --ground: #131417;
    --surface: #1c1e22;
    --surface-alt: #26292e;
    --hairline: #33363b;
    --ink: #f2f3f5;
    --ink-soft: #c3c7cd;
    --ink-muted: #8e939a;
    --on-accent: #151534;
    --good: #4ade80;
    --shadow-lift: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 18px -12px rgb(0 0 0 / 50%);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--ground);
  color: var(--ink);
  font-family: "Lato", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-chip);
}
.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 20;
  padding: 8px 12px; border-radius: var(--radius-chip);
  background: var(--accent); color: var(--on-accent); font-weight: 700;
}
.skip-link:focus { top: 12px; }
.wrap { width: min(var(--wrap), 100%); margin: 0 auto; padding: 0 16px; }

/* ---- Site chrome -------------------------------------------------------- */
.site-bar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--hairline);
}
.site-bar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: var(--bar);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--ink); font-size: 17px; font-weight: 900; letter-spacing: -0.3px;
}
.brand:hover { text-decoration: none; }
.mark {
  display: inline-grid; place-items: center; width: 26px; height: 26px;
  border-radius: 7px; background: var(--accent); color: var(--on-accent);
  font-size: 14px; font-weight: 900; line-height: 1;
}
.site-bar-links { display: none; }
.site-bar-links a {
  color: var(--ink-soft); font-size: 14px; font-weight: 700;
  padding: 10px 12px; border-radius: var(--radius-chip);
  transition: color var(--ease), background-color var(--ease);
}
.site-bar-links a:hover { color: var(--ink); background: var(--surface-alt); text-decoration: none; }
.signup-nav {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; padding: 0 16px; border-radius: var(--radius-chip);
  background: var(--accent); color: var(--on-accent);
  font-size: 13.5px; font-weight: 700; white-space: nowrap;
  transition: background-color var(--ease), transform var(--ease);
}
.signup-nav:hover { text-decoration: none; background: var(--accent-deep); }
.signup-nav:active { transform: translateY(1px); }

/* ---- Breadcrumbs & hero ------------------------------------------------- */
.breadcrumbs { margin: 16px 0 0; }
.breadcrumbs ol {
  display: flex; flex-wrap: wrap; gap: 2px 0; margin: 0; padding: 0;
  list-style: none; font-size: 13px; line-height: 1.5; color: var(--ink-muted);
}
.breadcrumbs li { min-width: 0; overflow-wrap: anywhere; }
.breadcrumbs a { color: var(--ink-soft); font-weight: 700; }
.breadcrumbs a:hover { color: var(--accent); text-decoration: none; }
.breadcrumbs li:not(:last-child)::after { content: "/"; margin: 0 8px; color: var(--hairline); }

.topic-layout { display: grid; gap: 28px; margin: 20px 0 48px; }
.topic-article { min-width: 0; max-width: var(--measure); }
.kicker {
  margin: 0 0 8px; color: var(--accent); font-size: 12.5px; font-weight: 900;
  letter-spacing: 0.08em; text-transform: uppercase;
}
h1 {
  margin: 0 0 12px; font-size: clamp(28px, 4.6vw, 40px); line-height: 1.12;
  font-weight: 900; letter-spacing: -0.6px; overflow-wrap: anywhere;
}
.lede { margin: 0 0 14px; font-size: 18px; line-height: 1.5; color: var(--ink-soft); }
.intro { margin: 0 0 18px; font-size: 16.5px; color: var(--ink); }
.facts {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 22px; padding: 0; list-style: none;
}
.facts li {
  padding: 5px 10px; border-radius: 999px; background: var(--surface);
  border: 1px solid var(--hairline); font-size: 13px; font-weight: 700; color: var(--ink-soft);
}

/* ---- Contents ---------------------------------------------------------- */
.contents {
  margin: 0 0 28px; padding: 14px 18px; border-radius: var(--radius-card);
  background: var(--surface); border: 1px solid var(--hairline);
}
.contents h2 { margin: 0 0 8px; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
.contents ol { margin: 0; padding-left: 22px; columns: 1; }
.contents li { margin: 3px 0; font-size: 15px; }
.contents a { color: var(--ink); font-weight: 700; }
.contents a:hover { color: var(--accent); }

/* ---- Concept sections ----------------------------------------------------- */
.concept { margin: 0 0 32px; padding-top: 8px; scroll-margin-top: calc(var(--bar) + 12px); }
.concept h2 {
  margin: 0 0 10px; font-size: 24px; line-height: 1.2; font-weight: 900; letter-spacing: -0.3px;
}
.concept h2 .n { color: var(--accent); margin-right: 8px; font-variant-numeric: tabular-nums; }
.concept p { margin: 0 0 12px; }
.concept .em { font-style: italic; }
.concept .strong { font-weight: 700; }

.figure-note, .media-figure {
  margin: 14px 0 16px; padding: 12px 16px; border-radius: var(--radius-card);
  background: var(--accent-soft); border-left: 3px solid var(--accent);
  color: var(--ink-soft); font-size: 15px;
}
.figure-note b { color: var(--ink); }
.media-figure { padding: 0; overflow: hidden; border-left: 0; background: var(--surface); border: 1px solid var(--hairline); }
.media-figure img { display: block; width: 100%; height: auto; }
.media-figure figcaption { padding: 10px 14px; font-size: 14px; color: var(--ink-soft); }

.steps { margin: 12px 0 16px; padding: 0; list-style: none; counter-reset: step; }
.steps-label { margin: 12px 0 6px; font-size: 13px; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted); }
.steps li {
  position: relative; margin: 0 0 8px; padding: 10px 14px 10px 44px;
  border-radius: var(--radius-card); background: var(--surface); border: 1px solid var(--hairline);
}
.steps li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 12px; top: 10px; width: 22px; height: 22px;
  border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); font-size: 12px; font-weight: 900;
}
.steps li b { display: block; margin-bottom: 2px; }

.rows { margin: 12px 0 16px; padding: 0; list-style: none; display: grid; gap: 6px; }
.rows li { display: flex; justify-content: space-between; gap: 14px; padding: 8px 12px; border-radius: var(--radius-chip); background: var(--surface); border: 1px solid var(--hairline); font-size: 15px; }
.rows li span:last-child { font-weight: 700; text-align: right; }
.rows li.good span:last-child { color: var(--good); }

.variants { margin: 12px 0 16px; padding: 0; list-style: none; display: grid; gap: 6px; }
.variants li { padding: 8px 12px; border-radius: var(--radius-chip); background: var(--surface-alt); font-size: 15px; }
.variants li b { margin-right: 6px; }

.table-wrap { margin: 12px 0 16px; overflow-x: auto; border-radius: var(--radius-card); border: 1px solid var(--hairline); background: var(--surface); }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table-wrap caption { text-align: left; padding: 10px 14px 4px; font-weight: 900; }
.table-wrap .table-intro { padding: 0 14px 8px; margin: 0; color: var(--ink-soft); font-size: 14px; }
.table-wrap th, .table-wrap td { padding: 8px 14px; border-top: 1px solid var(--hairline); text-align: left; vertical-align: top; }
.table-wrap th { font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-muted); }

.example {
  margin: 14px 0 18px; padding: 14px 16px; border-radius: var(--radius-card);
  background: var(--surface); border: 1px solid var(--accent-line);
}
.example h3 { margin: 0 0 6px; font-size: 16px; }
.example .problem { font-weight: 700; }
.example ol { margin: 8px 0; padding-left: 22px; }
.ledger { margin: 8px 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.ledger li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; border-radius: var(--radius-chip); background: var(--surface-alt); font-size: 15px; }
.ledger li span:last-child { font-weight: 700; white-space: nowrap; }
.pairs { margin: 8px 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.pairs li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; border-radius: var(--radius-chip); background: var(--surface-alt); font-size: 15px; }
.tiles { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; padding: 0; list-style: none; }
.tiles li { padding: 4px 10px; border-radius: var(--radius-chip); background: var(--surface-alt); font-size: 14px; }
.tiles li small { display: block; color: var(--ink-muted); }
.protip { margin: 10px 0 0; padding: 8px 12px; border-radius: var(--radius-chip); background: var(--accent-soft); font-size: 14.5px; }
.protip b { color: var(--accent); }

pre.code {
  margin: 12px 0 16px; padding: 12px 14px; overflow-x: auto; border-radius: var(--radius-card);
  background: #14161a; color: #e6e8ec; font-size: 13.5px; line-height: 1.5; tab-size: 4;
}
pre.code code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.code-label { margin: 12px 0 -8px; font-size: 13px; font-weight: 900; color: var(--ink-muted); }

details.check {
  margin: 12px 0 16px; padding: 12px 16px; border-radius: var(--radius-card);
  background: var(--surface); border: 1px solid var(--hairline);
}
details.check summary { cursor: pointer; font-weight: 700; }
details.check summary::before { content: "Quick check · "; color: var(--accent); font-weight: 900; }
details.check ol { margin: 10px 0 6px; padding-left: 22px; }
details.check li { margin: 3px 0; }
details.check li.answer { font-weight: 700; color: var(--good); }
details.check .explanation { margin: 6px 0 0; color: var(--ink-soft); font-size: 15px; }

.section { margin: 0 0 28px; }
.section h2 { margin: 0 0 10px; font-size: 20px; font-weight: 900; }
.section ul { margin: 0; padding-left: 20px; }
.section li { margin: 4px 0; }
.formula-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.formula-list li { padding: 10px 14px; border-radius: var(--radius-card); background: var(--surface); border: 1px solid var(--hairline); overflow-x: auto; }
.traps li::marker { color: var(--accent); }

.recap { margin: 0 0 28px; padding: 16px 18px; border-radius: var(--radius-tile); background: var(--surface); border: 1px solid var(--hairline); }
.recap h2 { margin: 0 0 6px; font-size: 20px; font-weight: 900; }
.recap > p { margin: 0 0 10px; color: var(--ink-soft); }
.recap dl { margin: 0; display: grid; gap: 8px; }
.recap dt { font-weight: 900; }
.recap dd { margin: 0 0 4px; color: var(--ink-soft); }

/* ---- Conversion ----------------------------------------------------------- */
.cta {
  margin: 8px 0 28px; padding: 22px 22px 24px; border-radius: var(--radius-tile);
  background: linear-gradient(135deg, var(--accent), var(--accent-deep)); color: #fff;
  box-shadow: var(--shadow-lift);
}
.cta h2 { margin: 0 0 6px; font-size: 22px; line-height: 1.2; font-weight: 900; letter-spacing: -0.3px; }
.cta p { margin: 0 0 14px; font-size: 15.5px; opacity: 0.94; }
.cta ul { margin: 0 0 16px; padding-left: 20px; font-size: 15px; }
.cta li { margin: 3px 0; }
.cta-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 46px; padding: 0 20px; border-radius: 8px; background: #fff; color: #1f2937;
  font-weight: 900; font-size: 15px;
}
.cta-button:hover { text-decoration: none; background: #eef0fe; }
.cta small { display: block; margin-top: 10px; font-size: 13px; opacity: 0.8; }

/* ---- Related ------------------------------------------------------------ */
.related { min-width: 0; }
.related h2 { margin: 0 0 10px; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
.related ul { margin: 0 0 22px; padding: 0; list-style: none; display: grid; gap: 6px; }
.related li a {
  display: block; padding: 10px 14px; border-radius: var(--radius-card); background: var(--surface);
  border: 1px solid var(--hairline); color: var(--ink); font-weight: 700; font-size: 15px;
  transition: border-color var(--ease), transform var(--ease);
}
.related li a:hover { text-decoration: none; border-color: var(--accent-line); transform: translateY(-1px); }
.related li.next a { border-color: var(--accent-line); background: var(--accent-soft); }
.related li.next a small { display: block; color: var(--accent); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; }

.syllabus { margin: 0 0 28px; }
.syllabus h2 { margin: 0 0 8px; font-size: 20px; font-weight: 900; letter-spacing: -0.2px; }
.syllabus > p { margin: 0 0 12px; color: var(--ink-soft); }
.topic-index { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.topic-index li a {
  display: block; padding: 12px 14px; border-radius: var(--radius-card);
  background: var(--surface); border: 1px solid var(--hairline);
  color: var(--ink); font-weight: 700; font-size: 15.5px;
  transition: border-color var(--ease), transform var(--ease);
}
.topic-index li a:hover { text-decoration: none; border-color: var(--accent-line); transform: translateY(-1px); }
.topic-index li small {
  display: block; margin-top: 4px; color: var(--ink-soft);
  font-weight: 400; font-size: 14px; line-height: 1.45;
}

.site-footer { border-top: 1px solid var(--hairline); background: var(--surface); }
.site-footer-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; padding: 18px 16px; font-size: 13.5px; color: var(--ink-muted); }
.site-footer-row p { margin: 0; }
.site-footer-row a { margin-right: 14px; color: var(--ink-soft); font-weight: 700; }

/* ---- Ads (scripts/adsense.py) -------------------------------------------- */
/* Distinct from content by spacing and label, never by sitting between concepts. */
.ad-unit { margin: 28px 0 8px; padding-top: 12px; border-top: 1px solid var(--hairline); }
.ad-unit-label { display: block; margin-bottom: 6px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
.ad-unit .adsbygoogle { min-height: 100px; }

/* ---- Math ---------------------------------------------------------------- */
.math { white-space: nowrap; }
.math-display { display: block; overflow-x: auto; margin: 6px 0 10px; text-align: center; }
.katex { font-size: 1.05em; }

/* Phone and wide are different layouts (BrandLayout.wide = 900). */
@media (min-width: 900px) {
  .site-bar-links { display: flex; gap: 2px; }
  .topic-layout { grid-template-columns: minmax(0, 1fr) 300px; gap: 40px; align-items: start; }
  .related { position: sticky; top: calc(var(--bar) + 16px); }
  .contents ol { columns: 2; column-gap: 24px; }
}
