/* ============================================================
   MathsLearn — Core Stylesheet
   ============================================================ */

:root {
  /* Brand colors */
  --color-primary: #4338ca;
  --color-primary-dark: #3730a3;
  --color-primary-light: #818cf8;
  --color-accent: #0ea5a4;
  --color-accent-light: #99f6e4;

  /* Neutrals */
  --color-bg: #f8f9fc;
  --color-surface: #ffffff;
  --color-surface-alt: #f1f3f9;
  --color-border: #e4e7ef;
  --color-text: #1b1f2a;
  --color-text-muted: #5b6072;
  --color-text-faint: #8b90a0;

  /* Feedback */
  --color-success: #16a34a;
  --color-warning: #d97706;
  --color-danger: #dc2626;

  /* Typography */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Source Serif 4", Georgia, serif;

  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4.5rem;

  /* Radii & shadow */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(20, 22, 40, 0.06), 0 1px 1px rgba(20, 22, 40, 0.04);
  --shadow-md: 0 8px 24px rgba(27, 31, 42, 0.08);
  --shadow-lg: 0 20px 48px rgba(27, 31, 42, 0.14);

  --max-width: 1200px;
  --header-h: 72px;
}

[data-theme="dark"] {
  --color-bg: #0f1117;
  --color-surface: #171a23;
  --color-surface-alt: #1e212c;
  --color-border: #2a2e3a;
  --color-text: #eef0f6;
  --color-text-muted: #a8acbd;
  --color-text-faint: #6f7484;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #0f1117;
    --color-surface: #171a23;
    --color-surface-alt: #1e212c;
    --color-border: #2a2e3a;
    --color-text: #eef0f6;
    --color-text-muted: #a8acbd;
    --color-text-faint: #6f7484;
  }
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: var(--header-h); }
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
button { font-family: inherit; cursor: pointer; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 var(--space-3); font-weight: 700; }
p { margin: 0 0 var(--space-4); color: var(--color-text-muted); }

.container {
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 0.7rem 1.3rem;
  border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.95rem;
  border: 1px solid transparent;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--color-primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--color-primary-dark); box-shadow: var(--shadow-md); }
.btn-ghost { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-ghost:hover { background: var(--color-surface-alt); }
.btn-sm { padding: 0.45rem 0.9rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  display: flex; align-items: center;
  background: color-mix(in srgb, var(--color-surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: var(--space-5); width: 100%; }

.brand { display: flex; align-items: center; gap: var(--space-2); font-weight: 800; font-size: 1.25rem; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 800;
  box-shadow: var(--shadow-sm);
}
.brand-text span { color: var(--color-accent); }

.main-nav { display: flex; align-items: center; gap: var(--space-5); }
.main-nav a {
  font-weight: 600; font-size: 0.95rem; color: var(--color-text-muted);
  padding: var(--space-2) 0; position: relative;
}
.main-nav a:hover, .main-nav a.active { color: var(--color-text); }
.main-nav a.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -6px; height: 2px;
  background: var(--color-primary); border-radius: 2px;
}

.header-actions { display: flex; align-items: center; gap: var(--space-3); }

.theme-toggle, .nav-toggle {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--color-border); background: var(--color-surface);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text);
}
.theme-toggle:hover, .nav-toggle:hover { background: var(--color-surface-alt); }
.nav-toggle { display: none; }
.theme-toggle svg.icon-moon { display: none; }
[data-theme="dark"] .theme-toggle svg.icon-sun { display: none; }
[data-theme="dark"] .theme-toggle svg.icon-moon { display: block; }

/* ---------- Mobile nav ---------- */
@media (max-width: 880px) {
  .nav-toggle { display: flex; }
  .main-nav {
    position: fixed; inset: var(--header-h) 0 0 0;
    background: var(--color-bg);
    flex-direction: column; align-items: stretch;
    padding: var(--space-5);
    transform: translateY(-110%);
    transition: transform .3s ease;
    overflow-y: auto;
  }
  .main-nav.open { transform: translateY(0); }
  .main-nav a { padding: var(--space-4) 0; font-size: 1.1rem; border-bottom: 1px solid var(--color-border); }
}

/* ---------- Hero ---------- */
.hero {
  padding: var(--space-8) 0 var(--space-7);
  background:
    radial-gradient(60% 50% at 85% 0%, color-mix(in srgb, var(--color-accent) 18%, transparent), transparent 70%),
    radial-gradient(50% 50% at 10% 10%, color-mix(in srgb, var(--color-primary) 16%, transparent), transparent 70%);
}
.hero-inner { text-align: center; max-width: 760px; margin-inline: auto; }
.eyebrow {
  display: inline-flex; align-items: center; gap: var(--space-2);
  background: var(--color-surface); border: 1px solid var(--color-border);
  padding: 0.4rem 0.9rem; border-radius: 999px; font-size: 0.8rem; font-weight: 700;
  color: var(--color-primary); margin-bottom: var(--space-5);
}
.hero h1 { font-size: clamp(2rem, 5vw, 3.1rem); letter-spacing: -0.02em; }
.hero h1 em { font-style: normal; color: var(--color-primary); }
.hero-sub { font-size: 1.1rem; max-width: 600px; margin-inline: auto var(--space-6); margin-top: 0;}

.search-box {
  display: flex; align-items: center; gap: var(--space-2);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 999px; padding: var(--space-2) var(--space-2) var(--space-2) var(--space-5);
  box-shadow: var(--shadow-md);
  max-width: 620px; margin-inline: auto;
}
.search-box input {
  flex: 1; border: 0; outline: 0; background: transparent;
  font-size: 1rem; color: var(--color-text); font-family: inherit;
}
.search-box input::placeholder { color: var(--color-text-faint); }
.search-box button { border-radius: 999px; }

.hero-stats { display: flex; gap: var(--space-6); justify-content: center; margin-top: var(--space-7); flex-wrap: wrap; }
.stat strong { display: block; font-size: 1.6rem; color: var(--color-text); }
.stat span { font-size: 0.85rem; color: var(--color-text-faint); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Quick browse chips ---------- */
.browse-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: center; margin-top: var(--space-6); }
.chip {
  padding: 0.5rem 1rem; border-radius: 999px; border: 1px solid var(--color-border);
  background: var(--color-surface); font-size: 0.85rem; font-weight: 600; color: var(--color-text-muted);
}
.chip:hover { border-color: var(--color-primary); color: var(--color-primary); }

/* ---------- Sections ---------- */
.section { padding: var(--space-7) 0; }
.section-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: var(--space-6); gap: var(--space-4); flex-wrap: wrap;
}
.section-head h2 { font-size: 1.6rem; margin-bottom: var(--space-1); }
.section-head p { margin: 0; }
.section-alt { background: var(--color-surface-alt); }
.section-link { font-weight: 700; color: var(--color-primary); font-size: 0.9rem; white-space: nowrap; }
.section-link:hover { text-decoration: underline; }

/* ---------- Category grid ---------- */
.category-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
}
.category-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-3);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.category-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: var(--color-primary-light); }
.category-icon {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
  color: var(--color-primary); font-size: 1.3rem;
}
.category-card h3 { font-size: 1rem; margin: 0; }
.category-card span { font-size: 0.82rem; color: var(--color-text-faint); }

/* ---------- Content cards ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-5); }
.content-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); overflow: hidden; display: flex; flex-direction: column;
  transition: transform .18s ease, box-shadow .18s ease;
}
.content-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.card-thumb {
  height: 120px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  display: flex; align-items: center; justify-content: center; color: #fff;
  font-size: 2rem; font-weight: 800; letter-spacing: -0.02em; opacity: 0.92;
}
.card-body { padding: var(--space-4) var(--space-5) var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); flex: 1; }
.card-tags { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.tag {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: 0.2rem 0.6rem; border-radius: 999px;
  background: color-mix(in srgb, var(--color-accent) 14%, transparent); color: var(--color-accent);
}
.tag.alt { background: color-mix(in srgb, var(--color-primary) 12%, transparent); color: var(--color-primary); }
.content-card h3 { font-size: 1.05rem; margin: 0; }
.card-meta { margin-top: auto; display: flex; align-items: center; justify-content: space-between; font-size: 0.78rem; color: var(--color-text-faint); padding-top: var(--space-3); border-top: 1px solid var(--color-border); }

/* ---------- Books strip ---------- */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-5); }
.book-card { text-align: center; }
.book-cover {
  aspect-ratio: 3/4; border-radius: var(--radius-sm);
  background: linear-gradient(160deg, var(--color-surface-alt), var(--color-border));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--color-text-faint); font-size: 0.85rem;
  box-shadow: var(--shadow-sm); margin-bottom: var(--space-3);
  border: 1px solid var(--color-border);
}
.book-card h4 { font-size: 0.9rem; margin: 0 0 var(--space-1); }
.book-card span { font-size: 0.78rem; color: var(--color-text-faint); }

/* ---------- CTA band ---------- */
.cta-band {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  border-radius: var(--radius-lg); padding: var(--space-7) var(--space-6);
  color: #fff; text-align: center; margin: var(--space-7) auto 0;
}
.cta-band h2 { font-size: 1.7rem; margin-bottom: var(--space-2); }
.cta-band p { color: color-mix(in srgb, #fff 80%, transparent); max-width: 520px; margin-inline: auto var(--space-5); }
.cta-band .btn-primary { background: #fff; color: var(--color-primary-dark); }
.cta-band .btn-primary:hover { background: color-mix(in srgb, #fff 90%, var(--color-primary)); }

/* ---------- Breadcrumb ---------- */
.breadcrumb { display: flex; flex-wrap: wrap; gap: var(--space-2); font-size: 0.85rem; color: var(--color-text-faint); padding: var(--space-4) 0; }
.breadcrumb a:hover { color: var(--color-primary); }
.breadcrumb .sep { opacity: 0.6; }

/* ---------- Filters (listing pages) ---------- */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: var(--space-3);
  background: var(--color-surface); border: 1px solid var(--color-border);
  padding: var(--space-4); border-radius: var(--radius-md); margin-bottom: var(--space-6);
}
.filter-bar select, .filter-bar input[type="search"] {
  flex: 1; min-width: 150px; padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm); border: 1px solid var(--color-border);
  background: var(--color-surface-alt); color: var(--color-text); font-family: inherit; font-size: 0.9rem;
}

/* ---------- Pagination ---------- */
.pagination { display: flex; justify-content: center; gap: var(--space-2); margin-top: var(--space-6); flex-wrap: wrap; }
.pagination a, .pagination span {
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); border: 1px solid var(--color-border); font-weight: 600; font-size: 0.9rem;
}
.pagination a:hover { border-color: var(--color-primary); color: var(--color-primary); }
.pagination .active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ---------- Article / content page ---------- */
.article-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: var(--space-7); align-items: start; }
.article-header h1 { font-size: 2rem; }
.article-meta { display: flex; gap: var(--space-4); flex-wrap: wrap; color: var(--color-text-faint); font-size: 0.85rem; margin-bottom: var(--space-5); }
.article-body { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-6); }
.article-body h2 { font-size: 1.3rem; margin-top: var(--space-6); }
.article-body h2:first-child { margin-top: 0; }
.article-body p, .article-body li { color: var(--color-text); }
.article-body ul, .article-body ol { padding-left: 1.3rem; margin-bottom: var(--space-4); }
.article-body table, .preview-pane table, .editor-surface table {
  width: 100%; border-collapse: collapse; margin: var(--space-5) 0; font-size: 0.95rem;
}
.article-body th, .article-body td,
.preview-pane th, .preview-pane td,
.editor-surface th, .editor-surface td {
  border: 1px solid var(--color-border); padding: 0.55rem 0.8rem; text-align: left;
}
.article-body th, .preview-pane th, .editor-surface th { background: var(--color-surface-alt); font-weight: 700; }

/* Controlled text sizes — a fixed set so content never ends up with
   dozens of random one-off sizes. Used by the editor's font-size
   control and rendered identically on the public article page. */
.text-size-sm { font-size: 0.85em; }
.text-size-md { font-size: 1em; }
.text-size-lg { font-size: 1.3em; }
.text-size-xl { font-size: 1.7em; font-weight: 700; line-height: 1.3; }
mark { background: #fef08a; color: inherit; padding: 0.05em 0.15em; border-radius: 3px; }
.formula-block {
  background: var(--color-surface-alt); border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius-sm); padding: var(--space-4) var(--space-5); margin: var(--space-5) 0;
  overflow-x: auto;
}
.example-block {
  border: 1px dashed var(--color-border); border-radius: var(--radius-sm);
  padding: var(--space-4) var(--space-5); margin: var(--space-5) 0; background: color-mix(in srgb, var(--color-accent) 6%, transparent);
}
.example-block strong { color: var(--color-accent); }

.sidebar-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-5); margin-bottom: var(--space-5);
}
.sidebar-card h4 { font-size: 0.95rem; margin-bottom: var(--space-4); }
.sidebar-list li { display: flex; justify-content: space-between; gap: var(--space-2); padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border); font-size: 0.85rem; }
.sidebar-list li:last-child { border-bottom: 0; }
.sidebar-list a:hover { color: var(--color-primary); }

@media (max-width: 920px) {
  .article-layout { grid-template-columns: 1fr; }
}

/* ---------- Footer ---------- */
.site-footer { background: var(--color-surface-alt); border-top: 1px solid var(--color-border); margin-top: var(--space-8); padding: var(--space-7) 0 var(--space-5); }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: var(--space-6); margin-bottom: var(--space-6); }
.footer-col h4 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-faint); margin-bottom: var(--space-4); }
.footer-col ul li { margin-bottom: var(--space-2); }
.footer-col a { color: var(--color-text-muted); font-size: 0.9rem; }
.footer-col a:hover { color: var(--color-primary); }
.footer-about p { font-size: 0.9rem; max-width: 320px; }
.footer-bottom {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--space-3);
  padding-top: var(--space-5); border-top: 1px solid var(--color-border);
  font-size: 0.8rem; color: var(--color-text-faint);
}
@media (max-width: 780px) {
  .footer-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- Empty / error states ---------- */
.state-box {
  text-align: center; padding: var(--space-8) var(--space-5);
  background: var(--color-surface); border: 1px dashed var(--color-border); border-radius: var(--radius-lg);
}
.state-box .state-code { font-size: 4rem; font-weight: 800; color: var(--color-primary-light); line-height: 1; margin-bottom: var(--space-3); }
.state-box h2 { margin-bottom: var(--space-2); }

/* ---------- Class/Exam picker strip ---------- */
.level-strip { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: center; margin-top: var(--space-6); }
.level-strip .chip.exam { border-style: dashed; }
.level-group-label {
  width: 100%; text-align: center; font-size: 0.72rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: .06em; color: var(--color-text-faint); margin: var(--space-4) 0 var(--space-1);
}
.level-group-label:first-child { margin-top: 0; }

/* ---------- Tabs (class landing page) ---------- */
.tab-bar {
  display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border); margin-bottom: var(--space-6);
  scrollbar-width: thin;
}
.tab-btn {
  flex: none; padding: 0.65rem 1.1rem; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-weight: 700; font-size: 0.9rem; color: var(--color-text-muted);
  border: 1px solid transparent; border-bottom: none; white-space: nowrap;
  display: flex; align-items: center; gap: var(--space-2);
}
.tab-btn .count { font-size: 0.72rem; background: var(--color-surface-alt); border-radius: 999px; padding: 0.05rem 0.5rem; color: var(--color-text-faint); }
.tab-btn:hover { color: var(--color-text); background: var(--color-surface-alt); }
.tab-btn[aria-selected="true"] {
  color: var(--color-primary); background: var(--color-surface);
  border-color: var(--color-border); border-bottom: 2px solid var(--color-surface);
  margin-bottom: -1px;
}
.tab-panel[hidden] { display: none; }

/* ---------- Class hero (smaller, page-top banner) ---------- */
.level-hero {
  background: linear-gradient(135deg, color-mix(in srgb, var(--color-primary) 10%, transparent), color-mix(in srgb, var(--color-accent) 10%, transparent));
  border-radius: var(--radius-lg); padding: var(--space-6); margin-bottom: var(--space-6);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-5); flex-wrap: wrap;
}
.level-hero h1 { font-size: 1.6rem; margin-bottom: var(--space-1); }
.level-hero p { margin: 0; }
.level-hero-icon {
  width: 60px; height: 60px; border-radius: var(--radius-md); flex: none;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.4rem;
}

/* ---------- Download button (article pages only — never on Books) ---------- */
.download-bar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  background: var(--color-surface-alt); border: 1px solid var(--color-border);
  border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5); flex-wrap: wrap;
}
.download-bar p { margin: 0; font-size: 0.82rem; }

/* ---------- Print / "Download PDF" watermark ----------
   The Download button triggers the browser's print dialog, where the
   user picks "Save as PDF". These rules only apply when printing, so
   the on-screen page is unaffected. A tiled diagonal watermark (brand
   name) covers every page, plus one explicit line naming the exact
   source URL and download time — the two together make a downloaded
   file traceable back to where it came from. */
.print-watermark { display: none; }

@page { size: A4; margin: 15mm; }

@media print {
  .site-header, .site-footer, .breadcrumb, .download-bar,
  aside, .main-nav, .btn, .pagination, .filter-bar, .tab-bar { display: none !important; }

  body { background: #fff; color: #000; }
  .article-body { border: none; box-shadow: none; padding: 0; }
  main .container { max-width: 100%; padding: 0; }
  .article-layout { display: block; }

  /* Never split a formula, example, table or image across two
     printed pages — keeps long notes/papers readable once saved
     as a PDF, no matter how much the admin has written. */
  .formula-block, .example-block, table, img, .card { break-inside: avoid; page-break-inside: avoid; }
  h2, h3 { break-after: avoid; page-break-after: avoid; }

  .print-watermark {
    display: block;
    position: fixed; inset: 0; z-index: 9999; pointer-events: none;
    background-repeat: repeat;
    background-size: 320px 220px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='220'%3E%3Ctext x='10' y='120' font-family='sans-serif' font-size='22' fill='rgba(0,0,0,0.09)' transform='rotate(-28 160 110)'%3EMathsLearn.online%3C/text%3E%3C/svg%3E");
  }
  .print-source-line {
    display: block !important;
    margin-top: var(--space-6); padding-top: var(--space-3);
    border-top: 1px dashed #999; font-size: 0.72rem; color: #555;
  }
}
.print-source-line { display: none; }

/* ---------- Utilities ---------- */
.mt-0 { margin-top: 0; }
.text-center { text-align: center; }

/* ---------- Full-screen A4 "PDF view" (js/reader.js) ---------- */
.reader-overlay {
  position: fixed; inset: 0; z-index: 10000;
  display: flex; flex-direction: column; background: #525659;
}
.reader-bar {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: #2b2d31; color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.reader-title { font-weight: 700; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.reader-btn {
  border: 1px solid rgba(255,255,255,.35); background: transparent; color: #fff;
  padding: 8px 14px; border-radius: 8px; font-size: 0.85rem; font-weight: 700; cursor: pointer;
}
.reader-btn:hover { background: rgba(255,255,255,.12); }
.reader-exit { background: #dc2626; border-color: #dc2626; }
.reader-exit:hover { background: #b91c1c; }
.reader-scroll { flex: 1 1 auto; overflow: auto; padding: 20px 12px 48px; }

/* The A4 sheet: 210mm wide, 297mm min height, 15mm margins (= @page margin).
   A faint dashed guide marks where each printed page will end. */
.reader-sheet {
  box-sizing: border-box;
  width: 210mm; min-height: 297mm; margin: 0 auto;
  padding: 15mm; border: none; border-radius: 2px;
  background-color: #fff; color: #1b1f2a;
  box-shadow: 0 6px 24px rgba(0,0,0,.45);
  position: relative;
  background-image: repeating-linear-gradient(to bottom,
    transparent 0, transparent calc(297mm - 7px),
    #cfd5df calc(297mm - 7px), #cfd5df calc(297mm - 6px),
    #e6e9ef calc(297mm - 6px), #e6e9ef 297mm);
  overflow-wrap: anywhere;
}
.reader-sheet .katex-display { overflow-x: auto; overflow-y: hidden; }
.reader-sheet p, .reader-sheet li { color: #1b1f2a; }
.reader-sheet .formula-block, .reader-sheet .example-block { color: #1b1f2a; }
.reader-sheet img { max-width: 100%; height: auto; }
.reader-sheet [hidden] { display: none !important; }

@media print {
  /* Printing from the reader: show only the sheet, flat, on white. */
  body.reader-open > *:not(.reader-overlay):not(.print-watermark) { display: none !important; }
  .reader-overlay { position: static; display: block; background: #fff; }
  .reader-bar { display: none !important; }
  .reader-scroll { overflow: visible; padding: 0; }
  .reader-sheet { width: auto; min-height: 0; padding: 0; box-shadow: none; background-image: none; zoom: 1 !important; }
  html { overflow: visible !important; }
}

@media screen {
  .reader-sheet > [data-pg] { margin-top: var(--pg) !important; }
}
/* Public pages: hide the built-in sample cards until the real list has loaded
   (no flash of demo cards that then disappear). */
html.live-loading [data-card]:not([data-live]),
html.live-loading .book-grid .book-card:not([data-live]) { visibility: hidden; }

/* ---------- Mobile: both actions (Full Screen + Download) always visible ---------- */
.download-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.view-article { display: block; max-width: 860px; margin-inline: auto; }
.view-article .article-body { overflow-wrap: anywhere; }
.view-article .article-body img { max-width: 100%; height: auto; }
.view-article .article-body table { display: block; overflow-x: auto; }
.view-article .article-body .katex-display { overflow-x: auto; overflow-y: hidden; }
.view-state { text-align: center; padding: var(--space-8, 4rem) var(--space-4); }
@media (max-width: 640px) {
  .download-bar { flex-direction: column; align-items: stretch; }
  .download-actions { flex-direction: column; }
  .download-actions .btn { width: 100%; justify-content: center; padding-block: 0.7rem; font-size: 0.9rem; }
  .article-header h1 { font-size: 1.5rem; }
  .article-body { padding: var(--space-4); }
  .reader-bar { padding: 8px 10px; }
  .reader-title { font-size: 0.8rem; }
  .reader-btn { padding: 9px 11px; font-size: 0.8rem; }
  .reader-scroll { padding: 10px 6px 40px; }
}

/* A `hidden` element must always stay hidden, even if a class (like .btn)
   sets its own display value. */
[hidden] { display: none !important; }

/* ---------- Mobile header fix ----------
   The closed slide-down menu used translateY(-110%) from a start point
   BELOW the header, so its bottom edge still covered the header bar on
   phones (logo + buttons looked cut off). Slide it fully out of view and
   hide it while closed. */
@media (max-width: 880px) {
  .main-nav {
    transform: translateY(calc(-100% - var(--header-h) - 8px));
    visibility: hidden;
    transition: transform .3s ease, visibility 0s linear .3s;
  }
  .main-nav.open {
    transform: translateY(0);
    visibility: visible;
    transition: transform .3s ease, visibility 0s;
  }
}


/* ============================================================
   Home page: compact hero, real stats, live sections
   ============================================================ */
.hero { padding: var(--space-6) 0 var(--space-6); }
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.5rem); margin-bottom: var(--space-3); }
.hero-sub { font-size: 1rem; margin: 0 auto var(--space-4); }
.hero-stats { margin-top: var(--space-5); gap: var(--space-6); }
.hero-stats[hidden], .section[hidden] { display: none !important; }
.stat strong { font-size: 1.35rem; }

/* class / exam picker: one tidy strip, labels inline */
.level-strip-compact { gap: 6px; margin-top: var(--space-4); align-items: center; }
.level-strip-compact .chip { padding: 0.35rem 0.85rem; font-size: 0.82rem; }
.level-strip-compact .level-group-label {
  width: auto; margin: 0 2px 0 10px; font-size: 0.68rem; text-align: left;
}
.level-strip-compact .level-group-label:first-child { margin-left: 0; }

.section { padding: var(--space-6) 0; }
.home-book-grid { display: flex; flex-wrap: wrap; gap: var(--space-5); }
.home-book-grid .book-card { width: 150px; }

/* centre the paragraph inside the call-to-action band */
.cta-band p { margin: 0 auto var(--space-5); }


/* ---------- typed shapes: show.circle(radius=5) etc. (js/shapes.js) ---------- */
.shape-figure { margin: 0.9em auto; text-align: center; break-inside: avoid; page-break-inside: avoid; }
.shape-figure svg { max-width: 100%; height: auto; color: var(--color-text, #111); }
.shape-figure .s-shape { fill: none; stroke: currentColor; stroke-width: 0.05; }
.shape-figure .s-fill { fill: rgba(79, 70, 229, 0.08); }
.shape-figure .s-line { fill: none; stroke: currentColor; stroke-width: 0.05; }
.shape-figure .s-text { fill: currentColor; font: 0.5px system-ui, "Segoe UI", sans-serif; }
.shape-figure figcaption { font-size: 0.8rem; color: var(--color-text-muted, #555); margin-top: 0.2em; }
.shape-error { background: #fef9c3; border: 1px solid #eab308; color: #854d0e; padding: 0.5em 0.8em; border-radius: 6px; font-size: 0.85rem; margin: 0.6em 0; }


/* tighter reading text (matches the editor) */
.article-body p { margin: 0 0 0.6em; line-height: 1.65; }
.article-body h2 { margin: 1.1em 0 0.4em; }
.article-body h3 { margin: 1em 0 0.35em; }
.article-body ul, .article-body ol { margin: 0.3em 0 0.6em; }
.article-body li { margin: 0.1em 0; }

/* ---------- MCQ options: evenly spaced, wrap on small screens ---------- */
.mcq-options { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem 2.6rem; margin: 0.4em 0 0.9em; }
.mcq-opt { white-space: normal; min-width: 4.5rem; }

/* Lists written in the editor: the global `ul { list-style:none }` reset hid every bullet,
   on the student pages and in the PDF. Bring the markers back for content. */
.article-body ul { list-style: disc outside; padding-left: 1.5rem; }
.article-body ol { list-style: decimal outside; padding-left: 1.5rem; }
.article-body li { margin: 0.15em 0; }
.article-body ul ul { list-style: circle outside; }
