/* ==========================================================================
   НВО и ДЗИ - дизайн система
   Един файл за целия сайт. Слоевете определят приоритета (по-късен слой печели):
   reset → tokens → base → legacy → layout → components → pages → utilities
   Цветовете идват само от токените; тъмната тема е html[data-theme="dark"]
   (атрибута го слага js/theme.js синхронно, преди първото рисуване).
   ========================================================================== */

@layer reset, tokens, base, legacy, layout, components, pages, utilities;

/* --- Шрифт: Inter Variable (OFL, self-hosted, fonts/inter/OFL.txt) --- */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../fonts/inter/inter-cyrillic-ext.woff2") format("woff2");
  unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../fonts/inter/inter-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../fonts/inter/inter-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../fonts/inter/inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ==========================================================================
   reset
   ========================================================================== */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body, h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd, ul, ol { margin: 0; }
  ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }
  img, svg, video, canvas { display: block; max-width: 100%; }
  svg { flex-shrink: 0; }
  input, button, textarea, select { font: inherit; color: inherit; }
  button { cursor: pointer; }
  table { border-collapse: collapse; }
  :where([hidden]) { display: none !important; }
}

/* ==========================================================================
   tokens
   ========================================================================== */
@layer tokens {
  :root {
    /* Икони като CSS маска за повтарящите се елементи в големите таблици (без SVG възли на ред). */
    --ci-plus: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E");
    --ci-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
    --ci-globe: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M2 12h20M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z'/%3E%3C/svg%3E");
    --ci-file: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6M8 13h8M8 17h5'/%3E%3C/svg%3E");

    color-scheme: light;

    /* Повърхности и текст */
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-2: #f0f3f8;
    --surface-3: #e6ebf3;
    --surface-glass: rgb(255 255 255 / 0.82);
    --border: #e1e6ee;
    --border-strong: #c9d1dd;
    --text: #0d1424;
    --text-2: #3a465c;
    --text-3: #4d586d;
    --text-4: #5c687d;

    /* Акценти */
    --primary: #2f54e0;
    --primary-hover: #2443bf;
    --primary-soft: #ecf1ff;
    --primary-soft-2: #d9e3ff;
    --primary-rgb: 47 84 224;
    --on-primary: #ffffff;
    /* Фонът на маркиран ред в таблица - плътен, за да не "прелива" под закрепените
       колони при хоризонтален скрол (--primary-soft е полупрозрачен в тъмна тема). */
    --row-selected: #e6ecff;
    --accent: #e8850c;
    --accent-soft: #fff3e2;
    --on-accent: #ffffff;

    --success: #0f7a43;
    --success-soft: #e5f6ec;
    --warning: #b45309;
    --warning-soft: #fff4e0;
    --danger: #c62f2f;
    --danger-soft: #fdecec;

    /* Графики: БЕЛ/МАТ и палитра за сравнение (без двойки червено/зелено) */
    --chart-bel: #2f54e0;
    --chart-mat: #e8850c;
    --chart-1: #2f54e0;
    --chart-2: #e8850c;
    --chart-3: #0f8f86;
    --chart-4: #c2367a;
    --chart-5: #7a4fd6;
    --chart-6: #0b7fb3;
    --chart-7: #a8590a;
    --chart-8: #4b5b75;
    --chart-9: #5f8f12;
    --chart-10: #b0306a;
    --chart-grid: #e8ecf2;
    --chart-axis: #5f6b82;

    /* Ранг: високо → синьо, ниско → кехлибарено */
    --rank-hi: #2f54e0;
    --rank-lo: #e8850c;

    /* Видове училища (Д / О / Ч / ДУ): значки, чипове, графиката в статистиката.
       Общинските (най-честите) са неутрални, частните - с акцента, както досега; държавните
       не са в основния син цвят, за да не се бъркат с връзките и избраните чипове. */
    --type-s: #0b7069;
    --type-s-soft: #e2f3f1;
    --type-m: var(--text-2);
    --type-m-soft: var(--surface-3);
    --type-p: var(--warning);
    --type-p-soft: var(--accent-soft);
    --type-r: #7a4fd6;
    --type-r-soft: #f1ebfd;

    /* Типография */
    --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Code", "Roboto Mono", Menlo, monospace;
    --fs-2xs: 0.6875rem;
    --fs-xs: 0.75rem;
    --fs-sm: 0.8125rem;
    --fs-md: 0.875rem;
    --fs-base: 1rem;
    --fs-lg: 1.125rem;
    --fs-xl: 1.25rem;
    --fs-2xl: 1.5rem;
    --fs-3xl: 1.875rem;
    --fs-4xl: 2.25rem;
    --fs-5xl: 3rem;

    /* Отстъпи (4px грид) */
    --sp-1: 0.25rem;
    --sp-2: 0.5rem;
    --sp-3: 0.75rem;
    --sp-4: 1rem;
    --sp-5: 1.25rem;
    --sp-6: 1.5rem;
    --sp-8: 2rem;
    --sp-10: 2.5rem;
    --sp-12: 3rem;
    --sp-16: 4rem;
    --sp-20: 5rem;

    /* Форми */
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;
    --radius-full: 9999px;

    --shadow-xs: 0 1px 2px rgb(16 24 40 / 0.05);
    --shadow-sm: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.06);
    --shadow-md: 0 4px 10px -2px rgb(16 24 40 / 0.08), 0 2px 4px -2px rgb(16 24 40 / 0.05);
    --shadow-lg: 0 16px 32px -8px rgb(16 24 40 / 0.14), 0 6px 12px -6px rgb(16 24 40 / 0.08);
    --shadow-overlay: 0 24px 64px -12px rgb(16 24 40 / 0.28), 0 8px 20px -8px rgb(16 24 40 / 0.12);
    --ring: 0 0 0 3px rgb(var(--primary-rgb) / 0.32);

    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
    --dur-fast: 120ms;
    --dur: 200ms;

    --header-h: 64px;
    --container: 1240px;
    --container-wide: 1440px;
    --measure: 70ch;
  }

  [data-theme="dark"] {
    color-scheme: dark;

    --bg: #0a0e16;
    --surface: #111724;
    --surface-2: #171f2f;
    --surface-3: #1f293c;
    --surface-glass: rgb(10 14 22 / 0.8);
    --border: #232d40;
    --border-strong: #34405a;
    --text: #e7ebf3;
    --text-2: #b4bdcd;
    --text-3: #a3adbf;
    --text-4: #8590a5;

    --primary: #7d9cff;
    --primary-hover: #9db4ff;
    --primary-soft: rgb(125 156 255 / 0.13);
    --primary-soft-2: rgb(125 156 255 / 0.24);
    --primary-rgb: 125 156 255;
    --on-primary: #0a1024;
    --row-selected: #1d2740;
    --accent: #f5a54a;
    --accent-soft: rgb(245 165 74 / 0.14);
    --on-accent: #1d1003;

    --success: #4cc98a;
    --success-soft: rgb(76 201 138 / 0.14);
    --warning: #f0b45c;
    --warning-soft: rgb(240 180 92 / 0.14);
    --danger: #ff7b7b;
    --danger-soft: rgb(255 123 123 / 0.14);

    --chart-bel: #7d9cff;
    --chart-mat: #f5a54a;
    --chart-1: #7d9cff;
    --chart-2: #f5a54a;
    --chart-3: #3fc7b9;
    --chart-4: #f07ab2;
    --chart-5: #b195ff;
    --chart-6: #4cc0f0;
    --chart-7: #e0a060;
    --chart-8: #a3b1c9;
    --chart-9: #9ccc4a;
    --chart-10: #ff8fba;
    --chart-grid: #1f293c;
    --chart-axis: #8e99ad;

    --rank-hi: #7d9cff;
    --rank-lo: #f5a54a;

    --type-s: #3fc7b9;
    --type-s-soft: rgb(63 199 185 / 0.14);
    --type-p: var(--accent);
    --type-r: #b195ff;
    --type-r-soft: rgb(177 149 255 / 0.15);

    --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4), 0 1px 3px rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 10px -2px rgb(0 0 0 / 0.5), 0 2px 4px -2px rgb(0 0 0 / 0.35);
    --shadow-lg: 0 16px 32px -8px rgb(0 0 0 / 0.6), 0 6px 12px -6px rgb(0 0 0 / 0.4);
    --shadow-overlay: 0 24px 64px -12px rgb(0 0 0 / 0.7), 0 8px 20px -8px rgb(0 0 0 / 0.5);
  }
}

/* ==========================================================================
   base
   ========================================================================== */
@layer base {
  /* Инлайн код (адреси, параметри) се пренася на тесен екран, вместо да разпъва страницата. */
  :not(pre) > code { overflow-wrap: anywhere; }

  html {
    font-size: 100%;
    scroll-behavior: smooth;
  }
  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
  }

  body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    font-feature-settings: "cv11", "ss03";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }
  main { flex: 1 0 auto; }

  h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
    color: var(--text);
    text-wrap: balance;
  }
  h1 { font-size: var(--fs-3xl); letter-spacing: -0.03em; }
  h2 { font-size: var(--fs-xl); }
  h3 { font-size: var(--fs-lg); }
  h4 { font-size: var(--fs-base); }
  p { text-wrap: pretty; }

  a {
    color: var(--primary);
    text-decoration-line: underline;
    text-decoration-color: transparent;
    text-decoration-thickness: 1.5px;
    text-underline-offset: 0.2em;
    transition: color var(--dur-fast) var(--ease), text-decoration-color var(--dur-fast) var(--ease);
  }
  a:hover { color: var(--primary-hover); text-decoration-color: currentColor; }

  :focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
  }
  ::selection { background: var(--primary-soft-2); color: var(--text); }

  hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-6) 0; }
  code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.92em; }
  code {
    padding: 0.1em 0.35em;
    border-radius: var(--radius-xs);
    background: var(--surface-2);
    border: 1px solid var(--border);
  }
  small { font-size: var(--fs-sm); }
  strong, b { font-weight: 650; }
  abbr[title] { text-decoration: underline dotted; cursor: help; }

  [id] { scroll-margin-top: calc(var(--header-h) + var(--sp-4)); }
  .num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }
  .sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
  }
  .skip-link {
    position: absolute;
    left: var(--sp-4);
    top: -100px;
    z-index: 1000;
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: var(--on-primary);
    font-weight: 600;
  }
  .skip-link:focus { top: var(--sp-3); color: var(--on-primary); }
}

/* ==========================================================================
   legacy - имената от старата тема, за инлайн стиловете и скриптовете в
   блог статиите и вграждането (четат --color-* / --chart-* с getComputedStyle)
   ========================================================================== */
@layer legacy {
  :root, [data-theme="dark"] {
    --color-primary: var(--primary);
    --color-primary-light: var(--primary-hover);
    --color-primary-lighter: var(--primary-soft);
    --color-primary-dark: var(--primary-hover);
    --color-primary-rgb: 47, 84, 224;
    --color-accent: var(--accent);
    --color-accent-light: var(--accent-soft);
    --color-on-primary: var(--on-primary);
    --color-on-accent: var(--on-accent);
    --color-surface: var(--surface);
    --color-bg: var(--bg);
    --color-bg-alt: var(--surface-2);
    --color-surface-glass: var(--surface-glass);
    --color-text: var(--text);
    --color-text-muted: var(--text-3);
    --color-text-light: var(--text-4);
    --color-border: var(--border);
    --color-border-light: var(--surface-2);
    --color-success: var(--success);
    --color-danger: var(--danger);
    --color-footer-bg: var(--surface);
    --container-max: var(--container);
    --header-height: var(--header-h);
  }
  [data-theme="dark"] { --color-primary-rgb: 125, 156, 255; }
}

/* ==========================================================================
   layout
   ========================================================================== */
@layer layout {
  .container {
    width: 100%;
    max-width: var(--container);
    margin-inline: auto;
    padding-inline: clamp(1rem, 4vw, 2rem);
  }
  .container--wide { max-width: var(--container-wide); }
  .container--narrow { max-width: 820px; }

  .stack { display: flex; flex-direction: column; gap: var(--stack-gap, var(--sp-4)); }
  .stack--sm { --stack-gap: var(--sp-2); }
  .stack--lg { --stack-gap: var(--sp-8); }
  .cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cluster-gap, var(--sp-2)); }
  .cluster--between { justify-content: space-between; }
  .grid-auto {
    display: grid;
    gap: var(--grid-gap, var(--sp-4));
    grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--grid-min, 240px)), 1fr));
  }

  .page { padding-block: var(--sp-8) var(--sp-16); }
  .section { margin-top: var(--sp-12); }
  .section:first-child { margin-top: 0; }
  .section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--sp-3) var(--sp-6);
    margin-bottom: var(--sp-5);
  }
  .section-title { font-size: var(--fs-2xl); }
  .section-lead { color: var(--text-3); margin-top: var(--sp-1); max-width: var(--measure); }

  /* --- Заглавна част на страница --- */
  .page-head { padding-block: var(--sp-8) var(--sp-6); }
  .page-head__eyebrow {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--primary);
    margin-bottom: var(--sp-2);
  }
  .page-head__title { font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.75rem); }
  .page-head__lead {
    margin-top: var(--sp-3);
    font-size: var(--fs-lg);
    color: var(--text-3);
    max-width: var(--measure);
  }
  .page-head__actions { margin-top: var(--sp-5); }

  /* --- Хедър --- */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface-glass);
    -webkit-backdrop-filter: saturate(1.6) blur(14px);
    backdrop-filter: saturate(1.6) blur(14px);
    border-bottom: 1px solid var(--border);
  }
  .site-header__inner {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    height: var(--header-h);
  }
  .brand {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    color: var(--text);
    font-weight: 750;
    font-size: var(--fs-lg);
    letter-spacing: -0.02em;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .brand:hover { color: var(--text); text-decoration: none; }
  .brand__mark {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    color: #fff;
    background: linear-gradient(135deg, #3b63f0 0%, #6a4fe0 100%);
    box-shadow: 0 2px 6px -1px rgb(59 99 240 / 0.45);
  }
  .brand__mark svg { width: 18px; height: 18px; }
  .brand__and { color: var(--text-3); font-weight: 600; }

  .site-nav {
    display: flex;
    align-items: center;
    gap: var(--sp-1);
    min-width: 0;
  }
  .exam-switch {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    border-radius: var(--radius-full);
    background: var(--surface-2);
    border: 1px solid var(--border);
    margin-right: var(--sp-2);
  }
  .exam-switch a {
    padding: 0.32rem 0.8rem;
    border-radius: var(--radius-full);
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--text-2);
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  }
  .exam-switch a:hover { color: var(--text); background: var(--surface); }
  .exam-switch a[aria-current] {
    background: var(--surface);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
  }
  [data-theme="dark"] .exam-switch a[aria-current] { background: var(--surface-3); }
  .site-nav__link {
    padding: 0.4rem 0.7rem;
    border-radius: var(--radius-sm);
    font-size: var(--fs-md);
    font-weight: 550;
    color: var(--text-2);
    text-decoration: none;
    white-space: nowrap;
  }
  .site-nav__link:hover { color: var(--text); background: var(--surface-2); }
  .site-nav__link[aria-current] { color: var(--primary); background: var(--primary-soft); }

  .site-header__actions {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    margin-left: auto;
  }
  .search-trigger {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    height: 38px;
    width: 260px;
    padding: 0 var(--sp-2) 0 var(--sp-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface);
    color: var(--text-3);
    font-size: var(--fs-md);
    text-align: left;
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  }
  .search-trigger:hover { border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
  .search-trigger svg { width: 16px; height: 16px; }
  .search-trigger__label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Подредът на навигацията на по-тесни екрани: втори ред с хоризонтален скрол */
  @media (max-width: 1180px) {
    .search-trigger { width: 38px; padding: 0; justify-content: center; }
    .search-trigger__label { display: none; }
  }
  @media (max-width: 520px) {
    .exam-switch__suffix { display: none; }
    .exam-switch a { padding-inline: 0.85rem; }
  }
  @media (max-width: 900px) {
    .site-header__inner { flex-wrap: wrap; height: auto; padding-block: var(--sp-2); row-gap: var(--sp-2); }
    .site-nav {
      order: 3;
      flex: 1 0 100%;
      overflow-x: auto;
      scrollbar-width: none;
      margin-inline: calc(-1 * clamp(1rem, 4vw, 2rem));
      padding-inline: clamp(1rem, 4vw, 2rem);
      padding-bottom: 2px;
      -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
      mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
    }
    .site-nav::-webkit-scrollbar { display: none; }
    .site-nav__link { padding-inline: 0.55rem; }
    :root { --header-h: 104px; }
  }
  /* Телефон: целият втори ред (класове + Балове · Статистика · Блог) се побира без скрол. */
  @media (max-width: 520px) {
    .exam-switch { margin-right: 4px; }
    .exam-switch a { padding-inline: 0.55rem; font-size: var(--fs-sm); }
    .site-nav { gap: 2px; }
    .site-nav__link { padding-inline: 0.4rem; font-size: var(--fs-sm); }
  }
  @media (max-width: 374px) {
    .exam-switch { margin-right: 2px; }
    .exam-switch a { padding-inline: 0.5rem; }
    .site-nav { gap: 0; }
    .site-nav__link { padding-inline: 0.35rem; }
  }
  /* Под 352px "Блог" не се побира - минава в менюто "Още". */
  .menu-narrow { display: none; }
  @media (max-width: 351px) {
    .site-nav__link--blog { display: none; }
    .menu-narrow { display: list-item; }
  }

  /* --- Меню "Още" --- */
  .menu-panel {
    /* Еднакъв отстъп отляво и отдясно - колкото страничния отстъп на .container. */
    --menu-edge: clamp(1rem, 4vw, 2rem);
    position: absolute;
    right: var(--menu-edge);
    top: calc(100% + 8px);
    width: min(820px, 100% - 2 * var(--menu-edge));
    padding: var(--sp-5);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-overlay);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--sp-5);
  }
  .menu-panel[hidden] { display: none; }
  .site-header .container { position: relative; }
  .menu-panel h2 {
    font-size: var(--fs-xs);
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-4);
    margin-bottom: var(--sp-2);
  }
  .menu-panel ul { list-style: none; padding: 0; display: grid; gap: 2px; }
  .menu-panel a {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 0.4rem 0.5rem;
    margin-inline: -0.5rem;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: var(--fs-md);
    font-weight: 500;
    text-decoration: none;
  }
  .menu-panel a:hover { background: var(--surface-2); color: var(--text); }
  .menu-panel a svg { width: 16px; height: 16px; color: var(--text-3); }
  /* Стрелката за външна връзка е до текста (4px), не в края на колоната - там изглежда като част от съседната колона. */
  .menu-panel .ext::after { content: "↗"; color: var(--text-3); font-size: 0.85em; margin-left: calc(var(--sp-1) - var(--sp-2)); }
  @media (max-width: 760px) {
    .menu-panel {
      /* Колоните по съдържанието: лявата (Kaggle, e-xplore.education) е по-широка, за да е всичко на един ред. */
      grid-template-columns: auto auto;
      max-height: calc(100vh - var(--header-h) - 24px);
      overflow-y: auto;
      gap: var(--sp-4);
      padding: var(--sp-4);
    }
    /* Заглавията не разширяват колоната - пренасят се. */
    .menu-panel h2 { contain: inline-size; }
  }
  /* Под 360px менюто е почти на цялата ширина и с по-малки отстъпи - иначе дългите редове се пренасят. */
  @media (max-width: 359px) {
    .menu-panel {
      --menu-edge: var(--sp-2);
      gap: var(--sp-3);
      padding: var(--sp-3);
    }
  }

  /* --- Breadcrumbs --- */
  .breadcrumbs { font-size: var(--fs-sm); color: var(--text-3); }
  .breadcrumbs ol { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1); list-style: none; padding: 0; margin: 0; }
  .breadcrumbs li { display: inline-flex; align-items: center; gap: var(--sp-1); }
  .breadcrumbs li + li::before { content: "/"; color: var(--text-4); margin-right: var(--sp-1); }
  .breadcrumbs a { color: var(--text-3); }
  .breadcrumbs a:hover { color: var(--primary); }
  .breadcrumbs [aria-current] { color: var(--text-2); font-weight: 550; }

  /* --- Футър --- */
  .site-footer {
    margin-top: var(--sp-16);
    border-top: 1px solid var(--border);
    background: var(--surface);
    font-size: var(--fs-md);
    color: var(--text-3);
  }
  .site-footer__grid {
    display: grid;
    grid-template-columns: 1.4fr repeat(4, minmax(0, 1fr));
    gap: var(--sp-8);
    padding-block: var(--sp-12) var(--sp-8);
  }
  .site-footer__about p { margin-top: var(--sp-3); max-width: 34ch; }
  .site-footer h2 {
    font-size: var(--fs-xs);
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-4);
    margin-bottom: var(--sp-3);
  }
  .site-footer ul { list-style: none; padding: 0; display: grid; gap: var(--sp-2); }
  .site-footer a { color: var(--text-2); }
  .site-footer a:hover { color: var(--primary); }
  .site-footer__inline { display: inline-flex; flex-wrap: wrap; gap: 0 var(--sp-2); }
  .site-footer__bottom {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: var(--sp-3) var(--sp-6);
    padding-block: var(--sp-5) var(--sp-8);
    border-top: 1px solid var(--border);
    font-size: var(--fs-sm);
  }
  .joke { font-style: italic; color: var(--text-3); max-width: 70ch; }
  .joke__author { font-style: normal; color: var(--text-4); white-space: nowrap; }
  .support { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-1); }
  @media (max-width: 1000px) {
    .site-footer__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .site-footer__about { grid-column: 1 / -1; }
  }
  @media (max-width: 520px) {
    .site-footer__grid { grid-template-columns: 1fr; gap: var(--sp-6); }
  }
}

/* ==========================================================================
   components
   ========================================================================== */
@layer components {
  /* --- Икони --- */
  .icon { width: 1.125em; height: 1.125em; flex-shrink: 0; }

  /* --- Бутони --- */
  .btn {
    --btn-h: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    height: var(--btn-h);
    padding: 0 var(--sp-4);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: var(--fs-md);
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    user-select: none;
    box-shadow: var(--shadow-xs);
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
      color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  }
  .btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
  .btn:active { transform: translateY(1px); }
  .btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
  .btn svg { width: 16px; height: 16px; }
  .btn--primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
  .btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--on-primary); }
  .btn--soft { background: var(--primary-soft); border-color: transparent; color: var(--primary); box-shadow: none; }
  .btn--soft:hover { background: var(--primary-soft-2); color: var(--primary); }
  .btn--ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
  .btn--ghost:hover { background: var(--surface-2); color: var(--text); }
  .btn--sm { --btn-h: 32px; padding: 0 var(--sp-3); font-size: var(--fs-sm); border-radius: var(--radius-xs); }
  .btn--lg { --btn-h: 46px; padding: 0 var(--sp-6); font-size: var(--fs-base); border-radius: var(--radius-md); }
  .btn--pill { border-radius: var(--radius-full); }
  .btn--icon { width: var(--btn-h); padding: 0; }
  .btn.is-busy { opacity: 0.6; pointer-events: none; }

  .icon-btn {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface);
    color: var(--text-2);
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
  }
  .icon-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--border-strong); }
  .icon-btn[aria-expanded="true"] { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
  .icon-btn svg { width: 18px; height: 18px; }
  .theme-toggle > span { display: grid; place-items: center; }
  .theme-toggle .icon-sun { display: none; }
  [data-theme="dark"] .theme-toggle .icon-sun { display: block; }
  [data-theme="dark"] .theme-toggle .icon-moon { display: none; }

  .kbd {
    display: inline-grid;
    place-items: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-3);
    font-family: var(--font-sans);
    font-size: var(--fs-xs);
    font-weight: 600;
  }
  @media (max-width: 1180px) { .search-trigger .kbd { display: none; } }

  /* --- Меню с бутон "Изтегли ▾": <details data-popover> (поведението - ui/popover.js) --- */
  .menu-button { position: relative; display: inline-block; flex-shrink: 0; }
  .menu-button > summary { list-style: none; cursor: pointer; }
  .menu-button > summary::-webkit-details-marker { display: none; }
  .menu-button[open] > summary { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
  .menu-button__caret { display: inline-grid; place-items: center; margin-left: -2px; color: var(--text-3); transition: transform var(--dur-fast) var(--ease); }
  .menu-button__caret svg { width: 14px; height: 14px; }
  details[open] > summary .menu-button__caret { transform: rotate(180deg); color: var(--primary); }
  .menu-button__short { display: none; }
  .menu-button__panel {
    position: absolute;
    z-index: 30;
    top: calc(100% + 6px);
    right: 0;
    width: max-content;
    min-width: 260px;
    max-width: min(340px, calc(100vw - 32px));
    display: grid;
    gap: 2px;
    padding: var(--sp-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    text-align: left;
  }
  .menu-button--start .menu-button__panel { right: auto; left: 0; }
  .menu-button__title {
    margin: 0;
    padding: var(--sp-1) var(--sp-2) var(--sp-2);
    font-size: var(--fs-xs);
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-4);
  }
  .menu-button__item {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr);
    align-items: start;
    column-gap: var(--sp-3);
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font: inherit;
    line-height: 1.3;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
  }
  .menu-button__item:hover, .menu-button__item:focus-visible { background: var(--primary-soft); color: var(--text); text-decoration: none; }
  .menu-button__item svg { width: 18px; height: 18px; margin-top: 1px; color: var(--text-3); }
  .menu-button__item:hover svg, .menu-button__item:focus-visible svg { color: var(--primary); }
  .menu-button__item strong { font-size: var(--fs-md); font-weight: 650; }
  .menu-button__hint { display: block; font-size: var(--fs-sm); color: var(--text-3); }
  .menu-button__note {
    margin: var(--sp-1) 0 0;
    padding: var(--sp-2) var(--sp-2) var(--sp-1);
    border-top: 1px solid var(--border);
    font-size: var(--fs-xs);
    color: var(--text-4);
  }
  @media (max-width: 560px) {
    .menu-button__long { display: none; }
    .menu-button__short { display: inline; }
  }

  /* Експортът в реда с бутоните на заглавието - изтласкан вдясно. */
  .page-head__export { margin-left: auto; }

  /* --- Chips --- */
  .chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: 32px;
    max-width: 100%;
    padding: 0 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface);
    color: var(--text-2);
    font-size: var(--fs-sm);
    font-weight: 550;
    white-space: nowrap;
    text-decoration: none;
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  }
  a.chip:hover, button.chip:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-2); text-decoration: none; }
  .chip[aria-pressed="true"], .chip[aria-current], .chip.is-active {
    background: var(--primary-soft);
    border-color: color-mix(in srgb, var(--primary) 35%, transparent);
    color: var(--primary);
  }
  .chip svg { width: 14px; height: 14px; }
  .chip__label { overflow: hidden; text-overflow: ellipsis; }
  .chip__x {
    display: inline-grid;
    place-items: center;
    width: 20px;
    height: 20px;
    margin-right: -0.4rem;
    padding: 0;
    border: 0;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--text-3);
  }
  .chip__x:hover { background: var(--surface-3); color: var(--text); }
  .chip__x svg { width: 12px; height: 12px; }
  .chip--muted .chip__label { opacity: 0.45; text-decoration: line-through; }
  .dot {
    width: 10px;
    height: 10px;
    border-radius: var(--radius-full);
    background: var(--dot, var(--text-4));
    flex-shrink: 0;
  }

  /* --- Значки --- */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    height: 22px;
    padding: 0 0.55rem;
    border-radius: var(--radius-full);
    background: var(--surface-2);
    color: var(--text-2);
    font-size: var(--fs-xs);
    font-weight: 600;
    white-space: nowrap;
    vertical-align: middle;
  }
  .badge--primary { background: var(--primary-soft); color: var(--primary); }
  .badge--accent { background: var(--accent-soft); color: var(--warning); }
  [data-theme="dark"] .badge--accent { color: var(--accent); }
  .badge--success { background: var(--success-soft); color: var(--success); }
  .badge--closed { background: var(--surface-3); color: var(--text-3); }

  /* Видът на училището: буквата (Д / О / Ч / ДУ) в таблиците и чиповете; модификаторите
     оцветяват и обикновена .badge с цялата дума (страницата на училището). */
  .type-badge {
    display: inline-grid;
    place-items: center;
    min-width: 1.45rem;
    height: 1.3rem;
    padding: 0 0.3rem;
    border-radius: 6px;
    font-size: var(--fs-xs);
    font-weight: 700;
    line-height: 1;
    vertical-align: middle;
  }
  .type-badge--s { background: var(--type-s-soft); color: var(--type-s); }
  .type-badge--m { background: var(--type-m-soft); color: var(--type-m); }
  .type-badge--p { background: var(--type-p-soft); color: var(--type-p); }
  .type-badge--r { background: var(--type-r-soft); color: var(--type-r); }
  /* "Тип / №" в таблиците: значка с еднаква ширина (колкото "ДУ") и място с фиксирана ширина,
     подравнено вдясно - блокът е еднакъв на всеки ред, така че буквите и номерата са в колони,
     без назъбване, а колоната остава центрирана. */
  .type-no {
    display: inline-grid;
    grid-template-columns: 1.9rem 3.5ch;
    align-items: center;
    column-gap: 0.45rem;
    vertical-align: middle;
  }
  .type-no .type-badge { width: 100%; padding: 0; }
  .type-no__n { color: var(--text-3); text-align: right; font-variant-numeric: tabular-nums; }

  /* --- Сегментиран контрол --- */
  .seg {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .seg::-webkit-scrollbar { display: none; }
  .seg > button, .seg > a {
    height: 30px;
    padding: 0 0.8rem;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-2);
    font-size: var(--fs-sm);
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
  }
  .seg > button:hover, .seg > a:hover { color: var(--text); text-decoration: none; }
  .seg > [aria-pressed="true"], .seg > [aria-selected="true"], .seg > [aria-current] {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
  }
  [data-theme="dark"] .seg > [aria-pressed="true"],
  [data-theme="dark"] .seg > [aria-selected="true"],
  [data-theme="dark"] .seg > [aria-current] { background: var(--surface-3); }
  .seg--pill { border-radius: var(--radius-full); }
  .seg--pill > button, .seg--pill > a { border-radius: var(--radius-full); }

  /* --- Карти --- */
  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
  }
  .card--pad { padding: clamp(var(--sp-4), 3vw, var(--sp-6)); }
  .card__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-4) clamp(var(--sp-4), 3vw, var(--sp-6));
    border-bottom: 1px solid var(--border);
  }
  .card__title { font-size: var(--fs-lg); }
  .card__body { padding: clamp(var(--sp-4), 3vw, var(--sp-6)); }
  a.card-link {
    display: block;
    color: inherit;
    text-decoration: none;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
  }
  a.card-link:hover {
    color: inherit;
    border-color: var(--border-strong);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
  }

  /* --- KPI плочки --- */
  .kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 132px), 1fr));
    gap: var(--sp-3);
  }
  .kpi {
    padding: var(--sp-4);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    border: 1px solid var(--border);
  }
  .kpi__label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-3); letter-spacing: 0.02em; }
  .kpi__value {
    margin-top: var(--sp-1);
    font-size: var(--fs-2xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
  }
  .kpi__value small { font-size: var(--fs-md); font-weight: 550; color: var(--text-3); letter-spacing: 0; }
  .kpi__hint { margin-top: var(--sp-1); font-size: var(--fs-xs); color: var(--text-3); }

  /* --- Полета --- */
  .field { display: grid; gap: var(--sp-1); }
  .field__label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
  .field > .seg { justify-self: start; }
  .input, .select {
    width: 100%;
    height: 40px;
    padding: 0 var(--sp-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: var(--fs-md);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  }
  .input::placeholder { color: var(--text-4); }
  .input:hover, .select:hover { border-color: var(--text-4); }
  .input:focus, .select:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
  .select {
    appearance: none;
    padding-right: 2.25rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238d98ab' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    cursor: pointer;
  }
  .input-icon { position: relative; }
  .input-icon > svg {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    width: 16px;
    height: 16px;
    transform: translateY(-50%);
    color: var(--text-4);
    pointer-events: none;
  }
  .input-icon > .input { padding-left: 2.25rem; }

  /* --- Превключвател (checkbox) --- */
  .switch {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--fs-sm);
    font-weight: 550;
    color: var(--text-2);
    cursor: pointer;
    user-select: none;
  }
  .switch input {
    appearance: none;
    position: relative;
    width: 36px;
    height: 20px;
    margin: 0;
    border-radius: var(--radius-full);
    background: var(--border-strong);
    cursor: pointer;
    transition: background var(--dur) var(--ease);
    flex-shrink: 0;
  }
  .switch input::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform var(--dur) var(--ease);
  }
  .switch input:checked { background: var(--primary); }
  .switch input:checked::after { transform: translateX(16px); }

  /* --- Combobox / листбокс --- */
  .combo { position: relative; }
  .combo__list {
    position: absolute;
    z-index: 60;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    max-height: min(420px, 60vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--sp-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
  }
  .combo__group {
    padding: var(--sp-2) var(--sp-3) var(--sp-1);
    font-size: var(--fs-2xs);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-4);
  }
  .combo__opt {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 0.5rem var(--sp-3);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: var(--fs-md);
    cursor: pointer;
    text-decoration: none;
  }
  .combo__opt:hover { color: var(--text); text-decoration: none; }
  .combo__opt[aria-selected="true"], .combo__opt.is-active { background: var(--primary-soft); }
  .combo__opt-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .combo__opt-meta { color: var(--text-3); font-size: var(--fs-xs); white-space: nowrap; }
  .combo__opt[aria-checked="true"] .combo__check { opacity: 1; }
  .combo__check { opacity: 0; color: var(--primary); width: 16px; height: 16px; }
  .combo__empty { padding: var(--sp-4) var(--sp-3); color: var(--text-3); font-size: var(--fs-md); }

  /* --- Таблици --- */
  .table-wrap {
    position: relative;
    overflow: auto;
    max-width: 100%;
    overscroll-behavior-x: contain;
    overscroll-behavior-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
  }
  .table-wrap--tall { max-height: min(76vh, 900px); }
  /* Плаващо копие на заглавния ред под горните ленти (ui/sticky-head.js) - само на телефон,
     където таблиците нямат собствен вертикален скрол. Под лентите на страниците (school-nav 20,
     stats-toc 15), за да се плъзга под тях в края на таблицата; над закрепените клетки (до 3). */
  .table-float {
    position: fixed;
    z-index: 12;
    overflow: hidden;
    background: var(--surface-2);
    box-shadow: 0 1px 0 var(--border), 0 8px 14px -10px rgb(0 0 0 / 0.35);
  }
  .data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--fs-md);
    font-variant-numeric: tabular-nums;
  }
  .data-table th, .data-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
  }
  /* Закрепваме цялото thead като един блок: при два реда заглавия (години + БЕЛ/МАТ)
     вторият ред не може да се размести спрямо първия. */
  .data-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .data-table thead th {
    vertical-align: bottom;
    background: var(--surface-2);
    color: var(--text-3);
    font-size: var(--fs-sm);
    font-weight: 650;
    letter-spacing: 0.02em;
  }
  .data-table tbody tr:hover { background: var(--surface-2); }
  .data-table tbody tr:last-child td { border-bottom: 0; }
  .data-table .num { text-align: right; }
  .data-table .center { text-align: center; }
  .data-table .muted { color: var(--text-3); }
  /* Броят ученици до стойността: фиксирана ширина, за да са числата подравнени по точката. */
  .data-table .sub { display: inline-block; min-width: 4ch; margin-left: 2px; color: var(--text-4); font-size: var(--fs-xs); text-align: left; }
  .data-table .group-start { border-left: 1px solid var(--border); }
  .data-table td.wrap { white-space: normal; min-width: 14rem; }
  /* Маркиран ред: плътен фон - закрепените колони (position: sticky) не трябва да
     пропускат съдържанието, което се плъзга под тях при хоризонтален скрол. */
  .data-table tr.is-selected td { background: var(--row-selected); }
  .data-table tr.divider-top td { border-top: 2px solid var(--border-strong); }
  .data-table--sticky-first th:first-child, .data-table--sticky-first td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--surface);
  }
  .data-table--sticky-first thead th:first-child { z-index: 3; background: var(--surface-2); }
  .data-table--compact th, .data-table--compact td { padding: 0.45rem 0.6rem; }
  .th-sort {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    white-space: nowrap;
    cursor: pointer;
  }
  .th-sort:hover { color: var(--text); }
  .th-sort svg { width: 12px; height: 12px; opacity: 0.35; }
  [aria-sort="ascending"] .th-sort, [aria-sort="descending"] .th-sort { color: var(--primary); }
  [aria-sort="ascending"] .th-sort svg, [aria-sort="descending"] .th-sort svg { opacity: 1; }
  [aria-sort="ascending"] .th-sort svg { transform: rotate(180deg); }
  .num .th-sort { flex-direction: row-reverse; }
  /* При row-reverse иконата е първа и няма базова линия - подравняваме бутона по долния ръб,
     за да са надписите на един ред с тези в съседните клетки. */
  .th-sort { vertical-align: bottom; }

  /* Клетка "Ранг": число + лента */
  .rank {
    display: inline-grid;
    grid-template-columns: 6ch minmax(40px, 1fr);
    align-items: center;
    gap: var(--sp-2);
    min-width: 92px;
    text-align: right;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
  }
  .rank__bar {
    position: relative;
    flex: 1;
    height: 6px;
    min-width: 40px;
    border-radius: var(--radius-full);
    background: var(--surface-3);
    overflow: hidden;
  }
  .rank__bar::after {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: calc(var(--v, 0) * 1%);
    border-radius: inherit;
    background: color-mix(in oklab, var(--rank-hi) calc(var(--v, 0) * 1%), var(--rank-lo));
  }

  /* --- Табове --- */
  .tabs {
    display: flex;
    gap: var(--sp-1);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs > [role="tab"], .tabs > a {
    position: relative;
    padding: var(--sp-3) var(--sp-3);
    border: 0;
    background: none;
    color: var(--text-3);
    font-size: var(--fs-md);
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
  }
  .tabs > [role="tab"]:hover, .tabs > a:hover { color: var(--text); }
  .tabs > [aria-selected="true"], .tabs > [aria-current] { color: var(--text); }
  .tabs > [aria-selected="true"]::after, .tabs > [aria-current]::after {
    content: "";
    position: absolute;
    left: var(--sp-3);
    right: var(--sp-3);
    bottom: -1px;
    height: 2px;
    border-radius: 2px;
    background: var(--primary);
  }

  /* --- Банер / известие --- */
  .banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-2) var(--sp-4);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius-md);
    border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
    background: var(--accent-soft);
    color: var(--text);
    font-size: var(--fs-md);
  }
  .banner svg { width: 18px; height: 18px; color: var(--warning); }
  [data-theme="dark"] .banner svg { color: var(--accent); }
  .banner--info { border-color: color-mix(in srgb, var(--primary) 30%, transparent); background: var(--primary-soft); }
  .banner--info svg { color: var(--primary) !important; }
  .banner__action { margin-left: auto; font-weight: 600; white-space: nowrap; }

  /* --- Празно състояние --- */
  .empty {
    display: grid;
    place-items: center;
    gap: var(--sp-3);
    padding: var(--sp-10) var(--sp-6);
    text-align: center;
    color: var(--text-3);
  }
  .empty__icon {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: var(--surface-2);
    color: var(--text-3);
  }
  .empty__icon svg { width: 22px; height: 22px; }
  .empty__title { font-size: var(--fs-base); font-weight: 650; color: var(--text); }

  /* --- Разгъваем блок --- */
  .disclosure { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
  .disclosure > summary {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-4);
    cursor: pointer;
    font-weight: 600;
    font-size: var(--fs-md);
    list-style: none;
  }
  .disclosure > summary::-webkit-details-marker { display: none; }
  .disclosure > summary::after {
    content: "";
    width: 8px;
    height: 8px;
    margin-left: auto;
    border-right: 2px solid var(--text-3);
    border-bottom: 2px solid var(--text-3);
    transform: rotate(45deg) translateY(-2px);
    transition: transform var(--dur) var(--ease);
  }
  .disclosure[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
  .disclosure__body { padding: 0 var(--sp-4) var(--sp-4); color: var(--text-2); font-size: var(--fs-md); }
  .disclosure--plain { border: 0; background: none; }
  .disclosure--plain > summary { padding-inline: 0; color: var(--primary); width: fit-content; }
  .disclosure--plain > summary::after { margin-left: var(--sp-1); border-color: currentColor; }
  .disclosure--plain .disclosure__body { padding-inline: 0; }

  /* --- Диалог --- */
  .dialog {
    width: min(560px, calc(100vw - 2rem));
    max-height: calc(100vh - 4rem);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-overlay);
  }
  .dialog::backdrop { background: rgb(10 14 22 / 0.45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
  .dialog[open] { animation: dialog-in var(--dur) var(--ease); }
  @keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
  .dialog__head {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border);
  }
  .dialog__title { font-size: var(--fs-lg); }
  .dialog__head .icon-btn { margin-left: auto; border: 0; }
  .dialog__body { padding: var(--sp-5); overflow: auto; }
  .dialog__foot {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-2);
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--border);
  }

  /* --- Търсене (command palette) --- */
  .palette {
    width: min(640px, calc(100vw - 1.5rem));
    margin-top: min(12vh, 120px);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-overlay);
    overflow: hidden;
  }
  .palette::backdrop { background: rgb(10 14 22 / 0.45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
  .palette[open] { animation: dialog-in var(--dur) var(--ease); }
  .palette__field { display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-4); border-bottom: 1px solid var(--border); }
  .palette__field svg { width: 20px; height: 20px; color: var(--text-3); }
  .palette__input {
    flex: 1;
    height: 56px;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text);
    font-size: var(--fs-lg);
  }
  .palette__input::placeholder { color: var(--text-4); }
  .palette__input::-webkit-search-cancel-button { display: none; }
  .palette__field .icon-btn { border: 0; }
  .palette__results { max-height: min(480px, 60vh); overflow-y: auto; overscroll-behavior: contain; padding: var(--sp-2); }
  .palette__hint {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-4);
    padding: var(--sp-2) var(--sp-4);
    border-top: 1px solid var(--border);
    color: var(--text-4);
    font-size: var(--fs-xs);
  }
  .palette__hint span { display: inline-flex; align-items: center; gap: var(--sp-1); }
  @media (pointer: coarse) { .palette__hint { display: none; } }
  .palette__item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 0.55rem var(--sp-3);
    border-radius: var(--radius-sm);
    color: var(--text);
    text-decoration: none;
  }
  .palette__item:hover { color: var(--text); text-decoration: none; background: var(--surface-2); }
  .palette__item.is-active { background: var(--primary-soft); }
  .palette__item-icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-3);
    flex-shrink: 0;
  }
  .palette__item.is-active .palette__item-icon { background: var(--surface); color: var(--primary); }
  .palette__item-icon svg { width: 16px; height: 16px; }
  .palette__item-main { flex: 1; min-width: 0; display: grid; }
  .palette__item-title { display: block; font-size: var(--fs-md); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .palette__item-sub { display: block; font-size: var(--fs-xs); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .palette__row { display: flex; align-items: center; gap: var(--sp-2); }
  .palette__row > .palette__item { flex: 1; min-width: 0; }
  .palette__links { display: flex; align-items: center; gap: var(--sp-1); flex-shrink: 0; padding-right: var(--sp-2); }
  .palette__links .badge { height: 22px; padding: 0 0.5rem; text-decoration: none; }
  .palette__links .badge:hover { background: var(--primary-soft-2); color: var(--primary); }
  .palette mark { background: none; color: var(--primary); font-weight: 700; }
  @media (max-width: 560px) { .palette__links { display: none; } }

  /* --- Toast --- */
  .toast-host {
    position: fixed;
    left: 50%;
    bottom: var(--sp-6);
    z-index: 1000;
    display: grid;
    gap: var(--sp-2);
    transform: translateX(-50%);
    pointer-events: none;
  }
  .toast {
    padding: 0.6rem var(--sp-4);
    border-radius: var(--radius-full);
    background: var(--text);
    color: var(--bg);
    font-size: var(--fs-md);
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    animation: toast-in var(--dur) var(--ease);
  }
  @keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

  /* --- Skeleton --- */
  .skeleton {
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
    background-size: 200% 100%;
    animation: skeleton 1.4s ease-in-out infinite;
  }
  @keyframes skeleton { to { background-position: -200% 0; } }

  /* --- Текстове (методология, помощ) --- */
  .prose { color: var(--text-2); max-width: var(--measure); }
  .prose > * + * { margin-top: var(--sp-3); }
  .prose h2, .prose h3 { color: var(--text); margin-top: var(--sp-6); }
  .prose ul, .prose ol { padding-left: 1.25em; }
  .prose li + li { margin-top: var(--sp-1); }
  .prose a { text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); }
  .muted { color: var(--text-3); }
  .lead { font-size: var(--fs-lg); color: var(--text-3); }

  /* --- Списък с линкове (стрелки) --- */
  .link-list { list-style: none; padding: 0; display: grid; gap: var(--sp-1); }
  .link-list a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-weight: 550;
    text-decoration: none;
  }
  .link-list a:hover { background: var(--surface-2); color: var(--text); }
  .link-list a::after { content: "→"; color: var(--text-4); }

  /* --- Подкрепа (копиране на адрес) --- */
  .copy-btn { position: relative; }
  .copy-btn.is-copied { border-color: var(--success); color: var(--success); }
  .copy-btn.is-copied::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-xs);
    background: var(--text);
    color: var(--bg);
    font-size: var(--fs-2xs);
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
  }

  /* --- Графики --- */
  .chart { position: relative; width: 100%; min-height: 320px; }
  .chart-frame {
    padding: var(--sp-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
  }
  .chart-title { font-size: var(--fs-md); font-weight: 650; color: var(--text-2); margin-bottom: var(--sp-2); }
  .highcharts-tooltip-box { stroke-width: 1px; }
}

/* ==========================================================================
   utilities
   ========================================================================== */
@layer utilities {
  .mt-0 { margin-top: 0 !important; }
  .mt-2 { margin-top: var(--sp-2) !important; }
  .mt-4 { margin-top: var(--sp-4) !important; }
  .mt-6 { margin-top: var(--sp-6) !important; }
  .mt-8 { margin-top: var(--sp-8) !important; }
  .w-full { width: 100%; }
  .text-sm { font-size: var(--fs-sm); }
  .text-xs { font-size: var(--fs-xs); }
  .nowrap { white-space: nowrap; }
  .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  @media (max-width: 640px) { .hide-sm { display: none !important; } }
  @media (min-width: 641px) { .show-sm { display: none !important; } }
  @media print {
    .site-header, .site-footer, .no-print { display: none !important; }
    body { background: #fff; }
  }
}

/* ==========================================================================
   pages - страница по клас (/4/, /7/, /10/, /12/)
   ========================================================================== */
@layer pages {
  .grade-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: var(--sp-5) var(--sp-8);
    padding-top: var(--sp-8);
  }
  .grade-hero__side .field { min-width: 240px; }
  .grade-hero__side .field__label { display: inline-flex; align-items: center; gap: var(--sp-1); }
  .grade-hero__side .field__label svg { width: 14px; height: 14px; }
  /* Редът под заглавието: бързите връзки, а след тях "Изтегли данните". */
  .grade-hero__links {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-2);
  }
  /* "Изтегли данните" - същият бутон като над таблиците, отделен от връзките с разделител
     (действие с данните, а не връзка към друга страница). */
  .grade-hero__export { margin-left: var(--sp-2); padding-left: var(--sp-4); border-left: 1px solid var(--border); }
  @media (max-width: 760px) {
    .grade-hero { grid-template-columns: 1fr; align-items: start; }
    .grade-hero__side .field { min-width: 0; }
  }
  /* Кратките надписи на бутоните са за по-тесните екрани. */
  .chip__short { display: none; }
  /* Таблет и малък лаптоп: кратки надписи ("Класация 2026", "По години", "Изтегли") -
     връзките и "Изтегли" остават на един ред. */
  @media (max-width: 1099px) {
    .grade-hero__links .chip__long, .grade-hero__links .menu-button__long { display: none; }
    .grade-hero__links .chip__short, .grade-hero__links .menu-button__short { display: inline; }
  }
  /* Телефон: компактно въведение - графиката да се вижда още на първия екран. */
  @media (max-width: 640px) {
    .grade-hero { gap: var(--sp-3); padding-top: var(--sp-5); }
    .grade-hero .page-head__lead { display: none; }
    .grade-hero .page-head__eyebrow { margin-bottom: var(--sp-1); }
    .grade-hero__side .field { display: flex; align-items: center; gap: var(--sp-3); }
    .grade-hero__side .field__label { flex-shrink: 0; margin: 0; }
    .grade-hero__side .select { flex: 1; min-width: 0; }
    .grade-hero .chip__long { display: none; }
    .grade-hero .chip__short { display: inline; }
    .grade-page #compare { margin-top: var(--sp-6); }
    .grade-page .compare__lead { display: none; }
  }
  /* Телефон и таблет до 767 px: връзките и "Изтегли" - две равни колони с еднакви бутони
     (без назъбени редове и самотни бутони). При нечетен брой първият - националната
     класация - е на цял ред. Панелът с годините е закотвен за целия блок, под него. */
  @media (max-width: 767px) {
    .grade-hero__links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); position: relative; }
    .grade-hero__links > :first-child:nth-last-child(odd) { grid-column: 1 / -1; }
    .grade-hero__links .chip { width: 100%; height: 40px; justify-content: center; font-size: var(--fs-md); }
    .grade-hero__links .btn { --btn-h: 40px; width: 100%; font-size: var(--fs-md); }
    .grade-hero__export { margin-left: 0; padding-left: 0; border-left: 0; }
    .grade-hero__links > :first-child:nth-last-child(odd) .chip__long { display: inline; }
    .grade-hero__links > :first-child:nth-last-child(odd) .chip__short { display: none; }
    .grade-hero__links .year-links { position: static; }
  }
  /* Най-тесните екрани: надписът "Година" остава само за екранните четци (иконата се вижда),
     за да не се отрязва изборът "2026 - актуални данни". */
  @media (max-width: 359px) {
    .grade-hero__side .field__label .chip__short {
      position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
    }
  }

  .year-links { position: relative; }
  .year-links > summary { list-style: none; cursor: pointer; }
  .year-links > summary::-webkit-details-marker { display: none; }
  .year-links[open] > summary { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
  .year-links__panel {
    position: absolute;
    z-index: 30;
    top: calc(100% + 6px);
    left: 0;
    display: grid;
    grid-template-columns: repeat(3, auto);
    gap: var(--sp-1);
    padding: var(--sp-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
  }
  .year-links__panel a {
    padding: 0.35rem 0.7rem;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-weight: 600;
    font-size: var(--fs-md);
    text-align: center;
    text-decoration: none;
    font-variant-numeric: tabular-nums;
  }
  .year-links__panel a:hover { background: var(--primary-soft); color: var(--primary); }

  .history-banner { margin-top: var(--sp-4); }

  /* --- Сравнение --- */
  .compare .card__body { display: grid; gap: var(--sp-4); }
  .compare__actions .btn { --btn-h: 34px; }
  .compare__picker { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--sp-3); min-width: 0; }
  .compare__add { flex: 0 1 380px; min-width: min(100%, 260px); }
  .compare__add .input { text-overflow: ellipsis; }
  .compare__add .combo__list { min-width: min(560px, calc(100vw - 2rem)); }
  .compare__chips {
    flex: 1 1 320px;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    margin: 0;
    padding: 4px 0 0;
    list-style: none;
  }
  .compare__chips .chip { max-width: 100%; min-width: 0; overflow: hidden; }
  .compare__chips .chip__label { min-width: 0; }
  .compare__chips .chip { padding-right: 0.55rem; height: 32px; }
  .chip__toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
  }
  .compare__subject { justify-self: start; }
  .compare__charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); }
  .compare__charts .chart { min-height: 300px; }
  .chart-skeleton { height: 300px; }
  @media (min-width: 1100px) {
    .compare__subject { display: none; }
  }
  @media (max-width: 1099px) {
    /* minmax(0, …): иначе колоната не става по-тясна от вече начертаната графика и при
       завъртане от landscape към portrait графиката остава широка (Highcharts мери колоната). */
    .compare__charts { grid-template-columns: minmax(0, 1fr); }
    .compare__charts[data-show="b"] [data-subject="m"],
    .compare__charts[data-show="m"] [data-subject="b"] { display: none; }
  }
  @media (max-width: 640px) {
    .compare .chart-frame { padding: var(--sp-2) 0 0; border: 0; }
  }

  /* Година без изпит в графика (markNoExamYears): вертикален надпис с фона на ивицата - линиите минават под него. */
  .chart-no-exam {
    display: block;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    padding: 6px 1px;
    background: var(--surface-2);
    color: var(--text-3);
    font-family: var(--font-sans);
    font-size: 11px;
    line-height: 1;
    white-space: nowrap;
  }

  /* Highcharts tooltip (useHTML) */
  .tt { min-width: 240px; font-family: var(--font-sans); }
  .tt__year { font-weight: 700; margin-bottom: 4px; }
  .tt__row {
    display: grid;
    grid-template-columns: 10px minmax(120px, 1fr) auto auto;
    align-items: center;
    gap: 6px 8px;
    padding: 1px 0;
  }
  .tt__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
  .tt__val { font-weight: 700; font-variant-numeric: tabular-nums; }
  .tt__sub { color: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }

  /* --- Градове --- */
  .city-filter { width: min(280px, 100%); }
  .city-switch { display: grid; gap: var(--sp-4); margin-bottom: var(--sp-5); }
  /* Телефон: областните градове в един хоризонтален ред (вместо ~1 екран бутони преди класацията). */
  @media (max-width: 640px) {
    .city-switch { gap: var(--sp-3); }
    .city-switch__group--main > .cluster {
      flex-wrap: nowrap;
      overflow-x: auto;
      scrollbar-width: none;
      margin-inline: calc(-1 * clamp(1rem, 4vw, 2rem));
      padding: 2px clamp(1rem, 4vw, 2rem);
      -webkit-mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 28px), transparent);
      mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 28px), transparent);
    }
    .city-switch__group--main > .cluster::-webkit-scrollbar { display: none; }
    .city-switch__group--main .city-chip { flex-shrink: 0; }
  }
  .city-switch__group { display: grid; gap: var(--sp-2); }
  .city-switch__label {
    font-size: var(--fs-xs);
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-4);
  }
  .city-chip--big { font-weight: 650; color: var(--text); }
  .city-chip[aria-current] {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--on-primary);
  }
  .city-chip[aria-current]:hover { background: var(--primary-hover); color: var(--on-primary); }
  .city-switch__more > summary {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    cursor: pointer;
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--primary);
    list-style: none;
    margin-bottom: var(--sp-2);
  }
  .city-switch__more > summary::-webkit-details-marker { display: none; }
  .city-switch__more > summary::after {
    content: "";
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
    transition: transform var(--dur) var(--ease);
  }
  .city-switch__more[open] > summary::after { transform: rotate(-135deg) translateY(-1px); }

  .city-panel__head { align-items: center; }
  /* Името на града и броят училища на един ред, с вертикална черта между тях. Ако не се
     съберат (дълго име на телефон), броят минава на нов ред: всеки елемент има черта отляво,
     а чертата на първия във всеки ред е изтеглена извън видимото (overflow-x: clip). */
  .city-panel__heading { min-width: 0; overflow-x: clip; }
  .city-panel__heading-row {
    --sep: var(--sp-3);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    row-gap: 2px;
    margin-left: calc(-1 * var(--sep) - 1px);
  }
  .city-panel__heading-row > * {
    margin: 0 var(--sep) 0 0;
    padding-left: var(--sep);
    border-left: 1px solid var(--border-strong);
  }
  .city-panel__count { font-size: var(--fs-sm); color: var(--text-3); }
  /* Телефон: кратко - "214 училища", "35 от 156 училища"; годината е в "Класация 2026", видовете - в чиповете. */
  @media (max-width: 640px) {
    .count__long { display: none; }
  }
  /* Експортът - отделно меню в края на бутоните, с разделител. */
  .city-panel__export { margin-left: var(--sp-1); padding-left: var(--sp-3); border-left: 1px solid var(--border); }
  /* Телефон: бутоните - две равни колони под заглавието, както в началото на страницата;
     при нечетен брой първият (класацията на отделна страница) е на цял ред. */
  @media (max-width: 640px) {
    .city-panel__actions { flex-basis: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); }
    .city-panel__actions > :first-child:nth-last-child(odd) { grid-column: 1 / -1; }
    .city-panel .city-panel__actions .btn { --btn-h: 40px; width: 100%; justify-content: center; }
    .city-panel__export { margin-left: 0; padding-left: 0; border-left: 0; }
  }
  .city-panel__title { font-size: var(--fs-2xl); }
  /* "Покажи само": видовете училища - чипове с броя училища; нищо избрано = всички. В панела на
     града е вдясно в реда с табовете (общ филтър за двата таба), на страниците по град и година -
     ред в главата на таблицата. */
  .type-filter {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-2);
  }
  .type-filter__label {
    margin-right: var(--sp-1);
    font-size: var(--fs-xs);
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-4);
  }
  .card__head > .type-filter { flex-basis: 100%; container-type: inline-size; }
  /* Когато етикетът и чиповете не се събират в един ред (таблет), етикетът е над тях -
     чиповете остават в един ред, без самотен чип на нов ред. */
  @container (max-width: 699px) {
    .type-filter__label { flex-basis: 100%; margin: 0; }
  }
  .type-chip { padding-left: 0.4rem; }
  .type-chip__count { color: var(--text-4); font-variant-numeric: tabular-nums; }
  .type-chip[aria-pressed="true"] .type-chip__count { color: inherit; }
  /* Телефон: равни колони без скрол встрани - 2 вида в един ред, 3 в три колони, 4 в 2×2.
     Чипът е на два реда (името, под него буквата и броят), за да се събират имената и на 320 px. */
  @media (max-width: 640px) {
    .type-filter { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .type-filter[data-n="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .type-filter__label { grid-column: 1 / -1; margin: 0; }
    .type-chip {
      display: grid;
      grid-template-columns: auto auto;
      grid-template-areas: "name name" "badge count";
      justify-content: center;
      align-items: center;
      gap: 3px 0.35rem;
      height: auto;
      min-height: 48px;
      padding: 0.35rem 0.4rem;
      border-radius: var(--radius-md);
    }
    .type-chip .type-badge { grid-area: badge; }
    .type-chip__name { grid-area: name; justify-self: center; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
    .type-chip__count { grid-area: count; font-size: var(--fs-xs); }
  }
  /* Три вида под 360 px: малко по-дребни имена, за да не се отрязват ("Общински"). */
  @media (max-width: 359px) {
    .type-filter[data-n="3"] { gap: 6px; }
    .type-filter[data-n="3"] .type-chip { padding-inline: 0.15rem; }
    .type-filter[data-n="3"] .type-chip__name { font-size: var(--fs-xs); }
  }
  /* Ред с табовете: табовете вляво, вдясно "Покажи само" (видът училища - общ за двата таба).
     Когато не се събират в един ред (таблет, телефон), чиповете са отделен ред под табовете;
     границата зависи от броя видове (data-types). Таблицата започва веднага под реда. */
  .city-panel__bar { container-type: inline-size; }
  /* --stacked: 0 - един ред; 1 - чиповете под табовете (табовете с долна граница, чиповете с отстъп). */
  .city-panel__barrow {
    --stacked: 0;
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: var(--sp-4);
    padding-inline: clamp(var(--sp-2), 2vw, var(--sp-4));
    border-bottom: 1px solid var(--border);
  }
  .city-panel__bar .city-panel__tabs {
    padding-inline: calc(var(--stacked) * var(--sp-2));
    border-bottom: calc(var(--stacked) * 1px) solid var(--border);
  }
  .city-panel__view {
    display: flex;
    align-items: center;
    padding: calc(var(--stacked) * var(--sp-3)) calc(var(--stacked) * var(--sp-4)) 0;
  }
  .city-panel__view:empty { display: none; }
  @container (max-width: 1099px) {
    .city-panel__bar[data-types="4"] .city-panel__barrow { --stacked: 1; display: block; padding-inline: 0; border-bottom: 0; }
  }
  @container (max-width: 979px) {
    .city-panel__bar[data-types="3"] .city-panel__barrow { --stacked: 1; display: block; padding-inline: 0; border-bottom: 0; }
  }
  @container (max-width: 849px) {
    .city-panel__bar[data-types="2"] .city-panel__barrow { --stacked: 1; display: block; padding-inline: 0; border-bottom: 0; }
  }
  @media (max-width: 640px) {
    .city-panel__barrow { --stacked: 1; display: block; padding-inline: 0; border-bottom: 0; }
    .city-panel__view { padding-inline: var(--sp-3); }
    .city-panel__view > .type-filter { flex: 1 1 auto; min-width: 0; }
    /* Двата таба - по половин ширина, с кратки надписи ("Класация"), без скрол встрани. */
    .city-panel__tabs > [role="tab"] { flex: 1 1 0; text-align: center; }
    .tabs__long { display: none; }
  }
  .city-panel__body { padding: clamp(var(--sp-4), 1.25vw, var(--sp-6)); }
  .city-panel .btn { --btn-h: 34px; }

  /* Уточнението в заглавието ("26" в "БЕЛ 26") - по-леко от предмета. */
  .th-qual { color: var(--text-4); font-weight: 500; }
  [aria-sort="ascending"] .th-qual, [aria-sort="descending"] .th-qual { color: inherit; }
  .ranking__foot {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-3) var(--sp-6);
    margin-top: var(--sp-4);
  }
  .ranking__foot .disclosure { max-width: 640px; }

  .ranking .col-pos {
    position: sticky;
    left: 0;
    z-index: 1;
    width: 48px;
    min-width: 48px;
    background: var(--surface);
  }
  .ranking .col-name {
    position: sticky;
    left: 48px;
    z-index: 1;
    min-width: 216px;
    background: var(--surface);
    box-shadow: inset -1px 0 0 var(--border);
  }
  .ranking thead .col-pos, .ranking thead .col-name { z-index: 3; background: var(--surface-2); }
  .ranking tbody tr:hover .col-pos, .ranking tbody tr:hover .col-name { background: var(--surface-2); }
  /* Значката "Д" има фон като hover-а - на посочения ред я потъмняваме, за да не изчезне. */
  .data-table tbody tr:hover .badge:not(.badge--accent) { background: var(--surface-3); }
  /* Плътна боя (не transparent): закрепените № и име не бива да "преливат" върху
     колоните, които се плъзгат под тях. */
  .ranking tr.is-selected td,
  .ranking tr.is-selected .col-pos,
  .ranking tr.is-selected .col-name { background: var(--row-selected); }
  /* Колоните са по-тесни от другите таблици (0.6rem), за да се събират всички години и при
     "ДЗИ-2 26" (12 клас) на 1280 px без хоризонтален скрол. */
  .ranking th, .ranking td { padding-inline: 0.6rem; }
  .ranking .rank { grid-template-columns: 6ch 44px; min-width: 0; }
  /* Колоните по години: центрирани; стойността и броят ученици са с фиксирана ширина,
     така че блокът е еднакъв на всеки ред и точките остават подравнени. */
  .ranking .yv { padding-inline: 0.4rem; text-align: center; }
  .ranking .yv .v { display: inline-block; min-width: 6ch; text-align: right; }
  .ranking .col-report { padding-inline: 0.5rem; }
  .ranking td { padding-block: 0.4rem; }
  .compare__chips .chip__label { max-width: min(320px, 100%); }
  .school-cell { display: flex; align-items: center; gap: var(--sp-2); }
  .school-cell > a:first-of-type { font-weight: 600; }
  /* "Училище" поема свободното място; когато то не стига, дългите имена се отрязват с "…"
     (без пренасяне - пълното име е в подсказката и в профила). Иконките не се свиват. */
  .ranking .col-name { width: 100%; max-width: 0; }
  .ranking .school-cell > a:first-of-type { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ranking .school-cell > .add-toggle, .ranking .school-cell > .web-link { flex-shrink: 0; }
  .web-link { display: inline-grid; color: var(--text-4); }
  .web-link:hover { color: var(--primary); }
  .ci::before {
    content: "";
    display: block;
    width: var(--ci-size, 14px);
    height: var(--ci-size, 14px);
    background: currentColor;
    -webkit-mask: var(--ci) center / contain no-repeat;
    mask: var(--ci) center / contain no-repeat;
  }
  .ci--file { --ci: var(--ci-file); --ci-size: 15px; }
  .web-link.ci { --ci: var(--ci-globe); }
  .add-toggle.ci { --ci: var(--ci-plus); }
  .add-toggle.ci[aria-pressed="true"] { --ci: var(--ci-check); }
  .add-toggle {
    --dot: var(--primary);
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    padding: 0;
    flex-shrink: 0;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-full);
    background: var(--surface);
    color: var(--text-3);
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  }
  .add-toggle:hover { border-color: var(--primary); color: var(--primary); }
  .add-toggle[aria-pressed="true"] { background: var(--dot); border-color: var(--dot); color: #fff; }
  .icon-btn--sm { width: 30px; height: 30px; }
  .icon-btn--sm svg { width: 15px; height: 15px; }
  .ranking__subhead td {
    background: var(--surface-2) !important;
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 650;
    letter-spacing: 0.02em;
    position: static !important;
  }
  .ranking__inactive td { color: var(--text-3); }
  /* "Средни резултати": две подсекции - "По училища" и "По ученици" (заглавие и обяснение), във
     всяка по таблица за предмет. Таблиците в подсекция са една до друга или една под друга, а
     подсекциите - една до друга, когато се събират (тогава 4 таблици в ред) - според ширината и
     броя колони (data-n = Общо + показаните видове), така че всяка таблица е близо до естествената
     си ширина: без празни полета в таблиците и около тях. Стойностите са центрирани. */
  .averages__box { container-type: inline-size; }
  .averages__modes { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-6) var(--sp-6); }
  @container (min-width: 620px) { .averages__modes[data-n="1"] { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  @container (min-width: 1100px) { .averages__modes[data-n="3"] { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  @container (min-width: 1360px) { .averages__modes[data-n="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  /* Подсекциите една до друга: заглавията им са в общ ред на решетката (subgrid), така че
     таблиците започват на една височина, дори обясненията да са на различен брой редове.
     (Подсекцията не е container - containment изключва subgrid; container е .averages__pairbox.) */
  .averages__mode {
    min-width: 0;
    display: grid;
    grid-row: span 2;
    grid-template-rows: subgrid;
    row-gap: var(--sp-3);
  }
  .averages__pairbox { container-type: inline-size; min-width: 0; }
  .averages__pair { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-4) var(--sp-5); }
  @container (min-width: 250px) { .averages__modes[data-n="1"] .averages__pair { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  @container (min-width: 540px) { .averages__modes[data-n="3"] .averages__pair { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  @container (min-width: 660px) { .averages__modes[data-n="4"] .averages__pair { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  @container (min-width: 780px) { .averages__modes[data-n="5"] .averages__pair { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  /* Заглавието и обяснението на един ред с разделител (както името на града и броя); ако не се
     съберат, обяснението е отдолу, без разделител. */
  .averages__head { min-width: 0; overflow-x: clip; }
  .averages__head-row {
    --sep: var(--sp-3);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    row-gap: 2px;
    margin-left: calc(-1 * var(--sep) - 1px);
  }
  .averages__head-row > * {
    margin: 0 var(--sep) 0 0;
    padding-left: var(--sep);
    border-left: 1px solid var(--border-strong);
  }
  .averages__heading { font-size: var(--fs-lg); font-weight: 650; }
  .averages__hint { font-size: var(--fs-sm); color: var(--text-3); }
  .averages__title {
    margin: 0 0 var(--sp-2);
    font-size: var(--fs-sm);
    font-weight: 650;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .averages .data-table th, .averages .data-table td { text-align: center; }
  /* Равни колони - числата стоят на равни разстояния, независимо от дължината на заглавията. */
  @media (min-width: 641px) {
    .averages .data-table { table-layout: fixed; }
  }
  /* Видовете в заглавието: пълните имена, а когато таблицата е тясна за тях (телефон, две
     таблици една до друга на таблет) - цветните букви от чиповете "Покажи само" над нея. */
  .averages__subject { container-type: inline-size; min-width: 0; }
  .avg-type .type-badge { display: none; }
  /* "Година" → "Год." в много тесни таблици (шест колони на 320 px). */
  .avg-year--short { display: none; }
  @container (max-width: 279px) {
    .avg-year { display: none; }
    .avg-year--short { display: inline; }
  }
  @container (max-width: 529px) {
    .averages__modes[data-n="5"] .avg-type__name { display: none; }
    .averages__modes[data-n="5"] .avg-type .type-badge { display: inline-grid; }
  }
  @container (max-width: 444px) {
    .averages__modes[data-n="4"] .avg-type__name { display: none; }
    .averages__modes[data-n="4"] .avg-type .type-badge { display: inline-grid; }
  }
  @container (max-width: 359px) {
    .averages__modes[data-n="3"] .avg-type__name { display: none; }
    .averages__modes[data-n="3"] .avg-type .type-badge { display: inline-grid; }
  }
  @container (max-width: 189px) {
    .averages__modes[data-n="1"] .avg-type__name { display: none; }
    .averages__modes[data-n="1"] .avg-type .type-badge { display: inline-grid; }
  }

  .code-box { height: auto; padding: var(--sp-3); font-family: var(--font-mono); font-size: var(--fs-sm); resize: vertical; }

  /* --- Лента "N училища в графиката · Виж" - когато графиката е над видимата част --- */
  /* Лентата е в страницата винаги и се показва само с прозрачност (.is-visible от grade.js):
     в Safari на iPhone закрепен елемент, който се появи от display: none или с анимация на
     transform по време на скрол, понякога се рисува на грешно място и се движи със съдържанието.
     Центрирането е без transform (margin-inline: auto), за да не се бие с нищо. */
  .tray {
    position: fixed;
    left: 0;
    right: 0;
    bottom: max(var(--sp-4), env(safe-area-inset-bottom));
    z-index: 90;
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    width: fit-content;
    margin-inline: auto;
    padding: 6px 6px 6px var(--sp-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    font-size: var(--fs-md);
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--dur) var(--ease), visibility 0s linear var(--dur);
  }
  .tray.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity var(--dur) var(--ease), visibility 0s;
  }
  .tray .btn { border-radius: var(--radius-full); }
  /* Телефон: "Сподели · Вгради · Изчисти" на свой ред под заглавието, с видими надписи
     (само иконите - верига, </>, кошче - не са достатъчно ясни). */
  @media (max-width: 560px) {
    .compare .card__head { flex-wrap: wrap; row-gap: var(--sp-2); }
    .compare__actions { flex-basis: 100%; flex-wrap: wrap; gap: var(--sp-1); margin-left: -0.6rem; }
  }
  @media (max-width: 419px) {
    .compare__actions { gap: 0; margin-left: -0.4rem; }
    .compare__actions .btn { padding-inline: 0.4rem; gap: 0.3rem; }
  }
  /* 320 px: "Сподели · Вгради · Изчисти" - само с надписи, за да са на един ред. */
  @media (max-width: 359px) {
    .compare__actions .btn svg { display: none; }
  }
}

/* ==========================================================================
   pages - вградими графики (/{клас}/embed.html)
   ========================================================================== */
@layer pages {
  body.embed { min-height: 0; overflow: hidden; background: var(--bg); }
  .embed__charts { padding: var(--sp-2) var(--sp-3) 0; }
  .embed__frame { margin: 0 0 var(--sp-2); }
  .embed__frame .chart { min-height: 0; }
  .embed__footer { padding: var(--sp-1) 0 var(--sp-2); text-align: center; font-size: var(--fs-sm); }
  .embed__error { padding: var(--sp-8) var(--sp-4); color: var(--text-3); text-align: center; }
  .embed__footer a { color: var(--text-3); }
  .embed__footer a:hover { color: var(--primary); }
}

/* ==========================================================================
   pages - документация за вграждането (/embed/)
   ========================================================================== */
@layer pages {
  .embed-gen__grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: var(--sp-6); }
  .embed-gen__grid .cluster { align-items: flex-end; gap: var(--sp-4); }
  .embed-gen__preview { display: grid; align-content: start; gap: var(--sp-1); }
  .embed-gen__preview iframe {
    width: 100%;
    height: 1000px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg);
  }
  .embed-gen .compare__chips { margin-top: var(--sp-2); }
  @media (max-width: 1000px) { .embed-gen__grid { grid-template-columns: 1fr; } }
  .code-block {
    margin: 0;
    padding: var(--sp-4);
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    font-size: var(--fs-sm);
    line-height: 1.6;
  }
  .code-block code { padding: 0; border: 0; background: none; }
  .docs-table td:first-child { white-space: nowrap; }
}

@layer pages {
  @media (max-width: 640px) {
    .city-panel__body { padding: var(--sp-3); }
    /* Закрепени са № и името; рангът (само числото) е до тях и се вижда без скрол,
       а следващата колона се подава - знак, че таблицата продължава надясно. */
    .ranking .col-pos { width: 34px; min-width: 34px; padding-inline: 0.35rem; }
    .ranking .col-name { left: 34px; width: 180px; min-width: 180px; max-width: 180px; }
    .ranking .web-link { display: none; }
    .ranking .rank { grid-template-columns: auto; }
    .ranking .rank__bar { display: none; }
  }
  /* "Средни резултати": по-тесни клетки на телефон - до шест колони (Година, Общо и четирите
     вида) се събират без скрол встрани. */
  @media (max-width: 640px) {
    .averages th, .averages td { padding-inline: 0.5rem; }
  }
  @media (max-width: 359px) {
    .ranking .col-name { width: 140px; min-width: 140px; max-width: 140px; }
    .ranking .col-rank { padding-inline: 0.5rem; }
    .averages th, .averages td { padding-inline: 0.35rem; }
    .averages .data-table { font-size: var(--fs-sm); }
  }
}

/* ==========================================================================
   pages - профил на училище (/school/{код}/)
   ========================================================================== */
@layer pages {
  .school-page .breadcrumbs { margin-bottom: var(--sp-4); }
  .school-hero {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-5);
    padding: clamp(var(--sp-5), 3vw, var(--sp-8));
  }
  .school-hero__main { display: flex; align-items: flex-start; gap: var(--sp-4); min-width: 0; flex: 1 1 420px; }
  .school-hero__icon {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    border-radius: var(--radius-md);
    background: var(--primary-soft);
    color: var(--primary);
  }
  .school-hero__icon svg { width: 26px; height: 26px; }
  .school-hero__title { font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.25rem); }
  .school-hero__official { margin-top: var(--sp-1); max-width: var(--measure); color: var(--text-2); font-size: var(--fs-md); }
  .school-hero__meta { margin-top: var(--sp-3); gap: var(--sp-2) var(--sp-3); font-size: var(--fs-md); }
  .school-hero__fact { display: inline-flex; align-items: center; gap: var(--sp-1); color: var(--text-3); }
  .school-hero__fact svg { width: 15px; height: 15px; }
  .school-hero__note { display: flex; gap: var(--sp-2); align-items: flex-start; margin-top: var(--sp-3); max-width: var(--measure); color: var(--text-3); font-size: var(--fs-sm); }
  .school-hero__note svg { flex-shrink: 0; width: 15px; height: 15px; margin-top: 2px; }
  .school-nav {
    position: sticky;
    top: var(--header-h);
    z-index: 20;
    display: flex;
    justify-content: center;
    margin: var(--sp-4) calc(-1 * clamp(1rem, 4vw, 2rem)) 0;
    padding: var(--sp-2) clamp(1rem, 4vw, 2rem);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
  .school-nav .seg > a { height: 32px; padding-inline: 1rem; }
  .school-nav .seg > a.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
  [data-theme="dark"] .school-nav .seg > a.is-active { background: var(--surface-3); }
  .school-grade { margin-top: var(--sp-6); scroll-margin-top: calc(var(--header-h) + 64px); }
  .school-grade__body { display: grid; gap: var(--sp-5); }
  .school-grade__grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr); gap: var(--sp-4); align-items: start; }
  .school-grade__grid .table-wrap { max-height: 420px; }
  .school-grade__links { gap: var(--sp-2); }
  .school-grade__links .chip:first-child { background: var(--primary-soft); border-color: transparent; color: var(--primary); font-weight: 650; }
  .school-related { display: grid; gap: var(--sp-2); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
  .school-related__label { font-size: var(--fs-xs); font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-4); }
  @media (max-width: 900px) {
    .school-grade__grid { grid-template-columns: minmax(0, 1fr); } /* виж .compare__charts */
  }
  @media (max-width: 640px) {
    .school-grade .card__head .btn { width: 100%; }
    .school-grade .chart-frame { padding: var(--sp-2) 0 0; border: 0; }
  }
  /* Телефон: връзките в секцията на клас - две равни колони с кратки надписи
     ("Графика", "В града", "В страната", "Балове", "НВО 7 клас"); при нечетен брой
     първата ("Виж в графиката") е на цял ред с пълния надпис. */
  @media (max-width: 640px) {
    .school-grade__links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); }
    .school-grade__links .chip { width: 100%; height: 40px; justify-content: center; }
    .school-grade__links > :first-child:nth-last-child(odd) { grid-column: 1 / -1; }
    .school-grade__links .chip__long { display: none; }
    .school-grade__links .chip__short { display: inline; }
    .school-grade__links > :first-child:nth-last-child(odd) .chip__long { display: inline; }
    .school-grade__links > :first-child:nth-last-child(odd) .chip__short { display: none; }
  }
  /* Телефон: "Близки по успех" - списък на цели редове (имената са с различна дължина и не се
     събират в две колони); дълго име минава на втори ред, стрелката вдясно води към профила. */
  @media (max-width: 640px) {
    .school-related .cluster { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-2); }
    .school-related .chip {
      justify-content: space-between;
      width: 100%;
      height: auto;
      min-height: 40px;
      padding: 0.5rem 1rem;
      border-radius: var(--radius-sm);
      white-space: normal;
    }
    .school-related .chip::after {
      content: "";
      flex-shrink: 0;
      width: 7px;
      height: 7px;
      margin-right: 2px;
      border-top: 2px solid var(--text-4);
      border-right: 2px solid var(--text-4);
      transform: rotate(45deg);
    }
  }
  /* Телефон: бутоните в картата на училището - две равни колони. При три бутона
     "Изтегли PDF" е най-отгоре на цял ред, при един - той е на цял ред; "Балове" е кратко. */
  @media (max-width: 640px) {
    .school-hero__actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); width: 100%; }
    .school-hero__actions .btn { --btn-h: 40px; width: 100%; justify-content: center; }
    .school-hero__actions > :only-child,
    .school-hero__actions > :first-child:nth-last-child(3) ~ .btn--primary { grid-column: 1 / -1; }
    .school-hero__actions > :first-child:nth-last-child(3) ~ .btn--primary { order: -1; }
    .school-hero__actions .chip__long { display: none; }
    .school-hero__actions .chip__short { display: inline; }
    .school-hero__actions > :only-child .chip__long { display: inline; }
    .school-hero__actions > :only-child .chip__short { display: none; }
  }

  /* Телефон: бутоните под заглавието (балове, класации по град и година) - две равни колони
     по 40 px, без назъбени редове; при нечетен брой първият е на цял ред с пълния надпис,
     търсачката (балове - всички градове) - също. Помощта и "Изтегли" са като другите бутони. */
  @media (max-width: 640px) {
    .page-head__actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); }
    .page-head__actions > :first-child:nth-last-child(odd) { grid-column: 1 / -1; }
    .page-head__actions .btn { --btn-h: 40px; width: 100%; padding-inline: var(--sp-2); }
    .page-head__actions .btn--sm { font-size: var(--fs-md); border-radius: var(--radius-sm); }
    .page-head__actions .btn--ghost { background: var(--surface); border-color: var(--border-strong); box-shadow: var(--shadow-xs); color: var(--text); }
    .page-head__actions .menu-button { width: 100%; margin-left: 0; }
    .page-head__actions .input-icon { width: 100%; }
    .page-head__actions .chip__long { display: none; }
    .page-head__actions .chip__short { display: inline; }
    .page-head__actions > :first-child:nth-last-child(odd) .chip__long { display: inline; }
    .page-head__actions > :first-child:nth-last-child(odd) .chip__short { display: none; }
  }
  /* Таблет и малък лаптоп: в страниците с балове кратките надписи ("НВО 7 клас", "Градове",
     "Как да четем", "Изтегли") - бутоните остават на един ред, без самотен "Изтегли" отдолу. */
  @media (min-width: 641px) and (max-width: 1023px) {
    :is(.balove-page, .balove-hub) .page-head__actions .chip__long,
    :is(.balove-page, .balove-hub) .page-head__actions .menu-button__long { display: none; }
    :is(.balove-page, .balove-hub) .page-head__actions .chip__short,
    :is(.balove-page, .balove-hub) .page-head__actions .menu-button__short { display: inline; }
  }
  /* Най-тесните екрани: "Класация" без годината (тя е в заглавието на страницата). */
  @media (max-width: 359px) {
    .page-head__year { display: none; }
  }
  /* ==========================================================================
     страници по град и година (/{клас}/{град}/, /{клас}/{година}/)
     ========================================================================== */
  .landing .breadcrumbs { margin-bottom: var(--sp-2); }
  .landing .page-head__eyebrow svg { width: 15px; height: 15px; }
  .landing__subtitle { margin-top: var(--sp-2); font-size: var(--fs-xl); font-weight: 650; color: var(--text-2); }
  .landing__years { margin-bottom: var(--sp-5); gap: var(--sp-2); }
  .landing__years .chip[aria-current] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
  .landing__filters { flex: 1 1 420px; }
  .landing__filters .input-icon { flex: 0 1 320px; min-width: 200px; }
  .landing__filters .select { width: auto; min-width: 200px; }
  /* Ограничена ширина - на широк екран числата стоят до имената, а не в другия край на екрана. */
  .landing__card { max-width: 920px; }
  .landing__table { border: 0; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
  .landing__table .data-table td:nth-child(2) { white-space: normal; min-width: 220px; }
}

/* ==========================================================================
   pages - балове (/7/balove/ и /7/balove/{град}/)
   ========================================================================== */
@layer pages {
  .balove-page .page-head__eyebrow svg, .balove-hub .page-head__eyebrow svg { width: 15px; height: 15px; }
  .balove-page .page-head__title { font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.25rem); }
  .balove-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-4); }
  .balove-filters__school { flex: 1 1 280px; }
  .balove-filters__profile { flex: 1 1 280px; }
  .balove-filters__gender { min-height: 40px; }
  .balove-filters .combo__list { max-height: min(460px, 60vh); }
  /* Името на избраното училище и връзката към профила му - на един ред; на телефон връзката е под името, на цял ред. */
  .balove-detail__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2) var(--sp-4); margin-bottom: var(--sp-3); }
  .balove-detail__school { font-size: var(--fs-lg); }
  @media (max-width: 640px) {
    .balove-detail__head .btn { --btn-h: 40px; width: 100%; justify-content: center; }
  }
  .balove-detail__table { width: auto; min-width: 100%; }
  /* "Класиране" остава закрепено вляво, докато годините се скролват настрани. */
  .balove-detail__table .col-klass { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: inset -1px 0 0 var(--border); }
  .balove-detail__table thead .col-klass { z-index: 3; background: var(--surface-2); }
  .balove-detail__table tbody tr:hover .col-klass { background: var(--surface-2); }
  .balove-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); margin-top: var(--sp-4); }
  .balove-charts .chart { min-height: 290px; }
  @media (max-width: 900px) { .balove-charts { grid-template-columns: minmax(0, 1fr); } } /* виж .compare__charts */
  .balove-overview { margin-top: var(--sp-8); }
  .balove-overview__search { width: min(340px, 100%); }
  .balove-overview .table-wrap { container-type: inline-size; }
  .balove-overview__table { table-layout: fixed; min-width: 760px; }
  .balove-overview__table .col-num { width: 2.75rem; padding-inline: 0.4rem 0.5rem; }
  .balove-overview__table .col-school { width: 13rem; }
  .balove-overview__table .col-score { width: 6rem; }
  .balove-overview__table .col-trend { width: 4.5rem; }
  .balove-overview__table td { overflow: hidden; }
  /* Редовете може да са на няколко реда текст - числата стоят до първия ред, не по средата. */
  .balove-overview__table tbody td { vertical-align: top; }
  .balove-overview__table .clip { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* Името на паралелката се пренася, не се реже: различават се по края ("- НЕ (РИЧЕ)"). */
  .balove-overview__table .col-profile .clip { white-space: normal; }
  /* Дълги думи ("Електрообзавеждане") не се побират в тясната колона: пренасяме с тире, където
     браузърът има речник за български, иначе - на произволно място, вместо да излизат от клетката. */
  .balove-overview__table .col-profile .clip,
  .ov-school, .ov-profile { overflow-wrap: anywhere; hyphens: auto; }
  .balove-overview__table tbody tr[data-code] { cursor: pointer; }
  /* Закрепени са номерът и паралелката: "Училище" и годините се превъртат под тях. */
  .balove-overview__table .col-num,
  .balove-overview__table .col-profile { position: sticky; z-index: 1; background: var(--surface); }
  .balove-overview__table .col-num { left: 0; }
  .balove-overview__table .col-profile { left: 2.75rem; box-shadow: inset -1px 0 0 var(--border); }
  /* Компактен изглед (под 1024 px, balove.js): училище и паралелка са една колона с два реда.
     На тесен екран колоната е точно колкото № + тя + последната година да се виждат без скрол
     настрани (най-малко 9rem); щом всички колони се събират - поема цялото свободно място. */
  .balove-overview__table--compact { width: 100%; min-width: 0; }
  .balove-overview__table--compact th.col-profile { width: max(9rem, calc(100cqw - 2.75rem - 6rem)); }
  @container (min-width: 40rem) {
    .balove-overview__table--compact th.col-profile { width: auto; }
  }
  .balove-overview__table--compact td.col-profile { white-space: normal; }
  .ov-school { display: block; color: var(--text); font-size: var(--fs-sm); font-weight: 650; }
  .ov-profile { display: block; margin-top: 2px; color: var(--text-2); line-height: 1.35; }
  .ov-sorts { display: grid; justify-items: start; gap: 2px; }
  /* Два бутона в една клетка: активен е само този, по който е подредено. */
  .balove-overview__table th[aria-sort] .ov-sorts .th-sort:not(.is-sorted) { color: inherit; }
  .balove-overview__table th[aria-sort] .ov-sorts .th-sort:not(.is-sorted) svg { opacity: 0.35; transform: none; }
  .balove-overview__table .ov-sorts .th-sort.is-sorted { color: var(--primary); }
  .balove-overview__table .ov-sorts .th-sort.is-sorted svg { opacity: 1; transform: none; }
  .balove-overview__table .ov-sorts .th-sort.is-asc svg { transform: rotate(180deg); }
  .balove-overview__table thead .col-num,
  .balove-overview__table thead .col-profile { z-index: 3; background: var(--surface-2); }
  .balove-overview__table tbody tr:hover .col-num,
  .balove-overview__table tbody tr:hover .col-profile { background: var(--surface-2); }
  .balove-overview__table tbody tr[data-code]:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
  /* Скриваме само вертикалната лента (Chromium/Safari), защото остава видима след като
     излезеш с мишката от таблицата; хоризонталната се запазва - тя показва, че годините
     продължават надясно. Във Firefox лентите са overlay и не се задържат. */
  .balove-overview .table-wrap::-webkit-scrollbar:vertical { width: 0; height: 0; }
  .balove-overview .table-wrap::-webkit-scrollbar:horizontal { height: 10px; }
  .trend { font-weight: 800; font-size: var(--fs-base); }
  .trend--up { color: var(--primary); }
  .trend--down { color: var(--accent); }
  .trend--same { color: var(--text-4); }

  .balove-hub__search { width: min(320px, 100%); }
  .balove-hub__tier { margin-top: var(--sp-8); }
  .balove-hub__tier .city-switch__label { display: block; margin-bottom: var(--sp-3); }
  .balove-hub__grid { --grid-min: 200px; --grid-gap: var(--sp-3); list-style: none; padding: 0; }
  .balove-city { display: grid; gap: 2px; height: 100%; padding: var(--sp-4); }
  .balove-city__name { font-weight: 700; font-size: var(--fs-base); }
  .balove-city__meta { color: var(--text-3); font-size: var(--fs-sm); }
  .balove-city__years { color: var(--text-4); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
  .balove-city--big { border-color: color-mix(in srgb, var(--primary) 30%, var(--border)); }
  .balove-city--big .balove-city__name { color: var(--primary); font-size: var(--fs-lg); }
}

/* ==========================================================================
   pages - обобщена статистика (/stats/)
   ========================================================================== */
@layer pages {
  .stats-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--sp-5) var(--sp-8); }
  .stats-head > div:first-child { flex: 1 1 520px; }
  .stats-head__grade { display: grid; gap: var(--sp-2); justify-items: start; }
  .stats-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--sp-8); align-items: start; }
  .stats-toc {
    position: sticky;
    top: calc(var(--header-h) + var(--sp-4));
    display: grid;
    gap: var(--sp-2);
  }
  .stats-toc ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; }
  .stats-toc a {
    display: block;
    padding: 0.45rem 0.75rem;
    border-left: 2px solid var(--border);
    color: var(--text-3);
    font-size: var(--fs-md);
    font-weight: 550;
    text-decoration: none;
  }
  .stats-toc a:hover { color: var(--text); border-color: var(--border-strong); }
  .stats-toc a.is-active { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
  .stats-main { min-width: 0; }
  .stats-chapter { scroll-margin-top: calc(var(--header-h) + var(--sp-4)); }
  .stats-chapter + .stats-chapter { margin-top: var(--sp-12); }
  .stats-chapter__title { display: flex; align-items: center; gap: var(--sp-3); font-size: var(--fs-2xl); margin-bottom: var(--sp-4); }
  .stats-chapter__icon {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--primary);
  }
  .stats-chapter__icon svg { width: 18px; height: 18px; }
  .stat-section + .stat-section { margin-top: var(--sp-4); }
  .stat-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-3) var(--sp-5);
    padding: var(--sp-5) clamp(var(--sp-4), 3vw, var(--sp-6)) 0;
  }
  .stat-head__text { flex: 1 1 420px; min-width: 0; }
  .stat-grade { font-size: var(--fs-xs); font-weight: 650; color: var(--primary); margin-bottom: 2px; }
  .stat-title { font-size: var(--fs-lg); }
  .stat-note { margin-top: var(--sp-2); color: var(--text-3); font-size: var(--fs-md); max-width: var(--measure); }
  .stat-tools .select { width: auto; min-width: 200px; height: 36px; font-size: var(--fs-sm); }
  .stat-body { display: grid; gap: var(--sp-3); padding: var(--sp-3) clamp(var(--sp-4), 3vw, var(--sp-6)) var(--sp-5); }
  .stat-body > .stat-note, .stat-body > .stat-detail { margin: 0; }
  .stat-help .disclosure__body { padding-bottom: var(--sp-2); }
  .stat-chart { min-height: 400px; }
  .stat-sub { display: block; margin-bottom: var(--sp-2); font-size: var(--fs-sm); }
  .stats-page .two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); }
  .stats-page .table-wrap { max-height: 560px; }
  .stats-page .data-table td.pos { color: var(--success); font-weight: 650; }
  .stats-page .data-table td.neg { color: var(--danger); font-weight: 650; }
  .stats-page .data-table td:nth-child(2) { white-space: normal; min-width: 180px; }
  /* Колоните след "Училище" са числа - вдясно, за да са подравнени по точката. */
  .stats-page .data-table th:nth-child(n+3), .stats-page .data-table td:nth-child(n+3) { text-align: right; }
  .stats-loading { margin-top: var(--sp-2); }
  @media (max-width: 1000px) {
    .stats-layout { grid-template-columns: 1fr; gap: var(--sp-4); }
    .stats-toc {
      position: sticky;
      top: var(--header-h);
      z-index: 15;
      margin-inline: calc(-1 * clamp(1rem, 4vw, 2rem));
      padding: var(--sp-2) clamp(1rem, 4vw, 2rem);
      background: color-mix(in srgb, var(--bg) 90%, transparent);
      -webkit-backdrop-filter: blur(10px);
      backdrop-filter: blur(10px);
    }
    .stats-toc > .city-switch__label { display: none; }
    .stats-toc ol { display: flex; gap: var(--sp-2); overflow-x: auto; scrollbar-width: none; }
    .stats-toc ol::-webkit-scrollbar { display: none; }
    .stats-toc a { white-space: nowrap; border: 1px solid var(--border); border-radius: var(--radius-full); padding: 0.3rem 0.8rem; background: var(--surface); }
    .stats-toc a.is-active { border-radius: var(--radius-full); }
    .stats-chapter { scroll-margin-top: calc(var(--header-h) + 56px); }
  }
  @media (max-width: 700px) {
    /* minmax(0, …): широката таблица се скролира в рамката си, вместо да разпъва колоната. */
    .stats-page .two-col { grid-template-columns: minmax(0, 1fr); }
    .stat-tools, .stat-tools .section-city-filter, .stat-tools .select { width: 100%; }
    .stat-chart { min-height: 340px; }
  }
}

/* ==========================================================================
   pages - начална страница (/)
   ========================================================================== */
@layer pages {
  .home-hero {
    position: relative;
    overflow: hidden;
    padding: clamp(var(--sp-12), 8vw, 6.5rem) 0 clamp(var(--sp-10), 6vw, var(--sp-16));
    background:
      radial-gradient(900px 380px at 15% -10%, color-mix(in srgb, var(--primary) 16%, transparent), transparent 70%),
      radial-gradient(700px 320px at 95% 0%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 70%);
    border-bottom: 1px solid var(--border);
  }
  .home-hero__inner { max-width: 920px; text-align: center; }
  .home-hero .page-head__eyebrow { justify-content: center; }
  .home-hero .page-head__eyebrow svg { width: 15px; height: 15px; }
  .home-hero__title {
    font-size: clamp(2rem, 1.2rem + 3.6vw, 3.5rem);
    font-weight: 800;
    letter-spacing: -0.035em;
    line-height: 1.08;
  }
  .home-hero__lead { max-width: 640px; margin: var(--sp-5) auto 0; font-size: var(--fs-lg); color: var(--text-3); }
  .home-search { display: grid; justify-items: center; gap: var(--sp-3); margin-top: var(--sp-8); }
  .home-search .input-icon { width: min(620px, 100%); }
  .home-search .input-icon > svg { left: 1.1rem; width: 20px; height: 20px; }
  @media (max-width: 640px), (pointer: coarse) { .home-search__hint { display: none; } }
  .home-search__input {
    height: 58px;
    padding-left: 3.1rem !important;
    border-radius: var(--radius-full);
    font-size: var(--fs-lg);
    box-shadow: var(--shadow-lg);
  }

  .home-exams { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 270px), 1fr)); gap: var(--sp-4); }
  .home-exam { display: grid; gap: var(--sp-4); padding: var(--sp-5); align-content: start; }
  .home-exam__main { display: flex; align-items: center; gap: var(--sp-3); color: var(--text); text-decoration: none; }
  .home-exam__main:hover { color: var(--primary); text-decoration: none; }
  .home-exam__badge {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #3b63f0 0%, #6a4fe0 100%);
    color: #fff;
    font-size: var(--fs-xl);
    font-weight: 800;
  }
  .home-exam__head { display: grid; gap: 2px; }
  .home-exam__title { font-size: var(--fs-lg); font-weight: 750; }
  .home-exam__stats { display: grid; grid-template-columns: auto auto 1fr; align-items: end; gap: var(--sp-4); }
  .home-exam__stats > div { display: grid; }
  .home-exam__label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-3); }
  .home-exam__value { font-size: var(--fs-2xl); font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
  .home-exam__spark { width: 100%; max-width: 140px; height: 40px; justify-self: end; overflow: visible; }
  .home-exam__spark path { fill: none; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
  .home-exam__spark .spark-b { stroke: var(--chart-bel); }
  .home-exam__spark .spark-m { stroke: var(--chart-mat); }
  .home-exam__note { margin-top: calc(-1 * var(--sp-2)); }
  .home-exam__links { gap: var(--sp-2); }
  .home-exam__links .chip { height: 30px; }

  .home-balove { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-4) var(--sp-6); padding: var(--sp-6); }
  .home-balove__icon {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    background: var(--accent-soft);
    color: var(--warning);
  }
  [data-theme="dark"] .home-balove__icon { color: var(--accent); }
  .home-balove__icon svg { width: 26px; height: 26px; }
  .home-balove__text { flex: 1 1 320px; display: grid; gap: 2px; }
  .home-balove__title { font-size: var(--fs-xl); font-weight: 750; }
  .home-posts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: var(--sp-4); }
  .home-posts .post-card-title { font-size: var(--fs-lg); }
  .home-posts .post-card-excerpt { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
  .home-tool { display: grid; gap: var(--sp-1); }
  .home-tool__icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    margin-bottom: var(--sp-2);
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--primary);
  }
  .home-tool__icon svg { width: 20px; height: 20px; }
}

/* ==========================================================================
   pages - "За проекта" и 404
   ========================================================================== */
@layer pages {
  .about__section + .about__section { margin-top: var(--sp-4); }
  .about__section h2 { font-size: var(--fs-xl); }
  .about__section { scroll-margin-top: calc(var(--header-h) + var(--sp-4)); }
  .about__addr code { word-break: break-all; }
  .not-found { padding-block: var(--sp-16); }
  .not-found__code { font-size: var(--fs-5xl); font-weight: 800; letter-spacing: -0.04em; color: var(--primary); line-height: 1; }
}

/* ==========================================================================
   pages - таблиците на телефон
   ========================================================================== */
@layer pages {
  /* На телефон (и при докосване) таблиците нямат собствен вертикален скрол: таблица заема почти
     целия екран и иначе пръстът "засяда" в нея, докато не превърти всички редове. Плъзгането
     нагоре и надолу скролва страницата, настрани - колоните; заглавният ред остава видим чрез
     плаващото копие (.table-float). Същото условие като TOUCH_TABLES в ui/sticky-head.js. */
  @media (max-width: 767px), (hover: none) and (pointer: coarse) {
    .table-wrap,
    .school-grade__grid .table-wrap,
    .stats-page .table-wrap { max-height: none; }
  }
}
