/* Локальные шрифты. Раньше грузились с fonts.googleapis.com: 600 мс
   только на список начертаний, потом ещё десяток файлов с чужого
   домена — а до Google из России ходит через раз. Отсюда «сайт
   стал медленнее» при том, что страницы отдаются за 80 мс.

   Взято ровно то, что используется в CSS: Cormorant 400/500/600
   плюс курсивы 400/500, Plex Sans 400/500/600, Plex Mono 400.
   Лишние веса не качаем — каждый из них браузер тянул бы при
   первом заходе независимо от того, применяется он или нет.

   Кириллица и латиница разнесены через unicode-range: браузер
   берёт только нужное подмножество, файлы грузятся параллельно.
   Вьетнамский и греческий, которые отдавал Google, выброшены. */


@font-face {
    font-family: 'Cormorant Garamond';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/CormorantGaramond-400-cyrillic.7baf6d32c023.woff2") format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
    font-family: 'Cormorant Garamond';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/CormorantGaramond-400-latin.3007c5acec83.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;
}

@font-face {
    font-family: 'Cormorant Garamond';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/CormorantGaramond-500-cyrillic.4690c74113a7.woff2") format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
    font-family: 'Cormorant Garamond';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/CormorantGaramond-500-latin.d62e7df62dd3.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;
}

@font-face {
    font-family: 'Cormorant Garamond';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/CormorantGaramond-600-cyrillic.4af3d2101dbf.woff2") format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
    font-family: 'Cormorant Garamond';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/CormorantGaramond-600-latin.e15c62ae5a22.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;
}

@font-face {
    font-family: 'Cormorant Garamond';
    font-style: italic;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/CormorantGaramond-400i-cyrillic.0c5ae8dcc051.woff2") format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
    font-family: 'Cormorant Garamond';
    font-style: italic;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/CormorantGaramond-400i-latin.95f875e7d230.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;
}

@font-face {
    font-family: 'Cormorant Garamond';
    font-style: italic;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/CormorantGaramond-500i-cyrillic.93fa214c036f.woff2") format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
    font-family: 'Cormorant Garamond';
    font-style: italic;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/CormorantGaramond-500i-latin.cbd4c2248690.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;
}

@font-face {
    font-family: 'IBM Plex Sans';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/IBMPlexSans-400-cyrillic.6e0805c960c3.woff2") format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
    font-family: 'IBM Plex Sans';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/IBMPlexSans-400-latin.fd614a0cd4db.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;
}

@font-face {
    font-family: 'IBM Plex Sans';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/IBMPlexSans-500-cyrillic.6917011cb2c3.woff2") format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
    font-family: 'IBM Plex Sans';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/IBMPlexSans-500-latin.d8fb67ccd0a6.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;
}

@font-face {
    font-family: 'IBM Plex Sans';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/IBMPlexSans-600-cyrillic.12a1cae04317.woff2") format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
    font-family: 'IBM Plex Sans';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/IBMPlexSans-600-latin.36dda28b4dde.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;
}

@font-face {
    font-family: 'IBM Plex Mono';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/IBMPlexMono-400-cyrillic.cd34c7793d97.woff2") format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
    font-family: 'IBM Plex Mono';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/IBMPlexMono-400-latin.814fe1615d4d.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;
}

/* medlib — «Античный манускрипт»: базовая палитра и фундамент вёрстки */

:root {
    --bg: #F5F0E6;
    --text: #1A1A1A;
    --accent-1: #8B2E1F;
    --accent-2: #8B6F1F;
    --divider: #D4CCB8;
    --card-light: #EDE3CE;
    --card-dark: #D8C9A8;

    --serif: 'Cormorant Garamond', 'Georgia', serif;
    --sans: 'IBM Plex Sans', -apple-system, sans-serif;
    --mono: 'IBM Plex Mono', 'Courier New', monospace;

    --plate: #F5F0E6;
    --nav-bg: rgba(245, 240, 230, 0.85);
}

[data-theme="dark"] {
    --bg: #16120D;
    --text: #E8E0D2;
    --accent-1: #C0562F;
    --accent-2: #CF8C63;
    --divider: #3A3025;
    --card-light: #241D15;
    --card-dark: #1F1913;
    --plate: #EFE7D7;
    --nav-bg: rgba(22, 18, 13, 0.85);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body,
h1, h2, h3, h4, h5, h6,
p,
figure {
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.25s ease, color 0.25s ease;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--serif);
    font-weight: 600;
    letter-spacing: 0.01em;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-width: 100%;
    display: block;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Верхняя навигация */

.nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg); /* fallback для браузеров без backdrop-filter */
    border-bottom: 1px solid var(--divider);
}

/* Переход по якорю (#subjects с главной) браузер отсчитывает от верха окна,
   не зная про sticky-шапку, — цель уезжает под неё и заголовок обрезается.
   Высоту шапки в число не зашить: на мобильном меню переносится на вторую
   строку и она вдвое выше. Реальное значение измеряет скрипт и кладёт
   в --nav-height; 80px — запасное значение, если скрипт не отработал. */
:root {
    --nav-height: 80px;
}

[id] {
    scroll-margin-top: calc(var(--nav-height) + 16px);
}

@supports (backdrop-filter: blur(10px)) or (-webkit-backdrop-filter: blur(10px)) {
    .nav {
        background: var(--nav-bg);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
}

.nav__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    padding: 1rem 2rem;
}

.nav__logo {
    font-family: var(--serif);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.nav__logo em {
    font-style: italic;
    color: var(--accent-1);
}

.nav__brand {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav__tagline {
    font-family: var(--sans);
    font-size: 10px;
    font-weight: 400;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--accent-2);
    opacity: 0.7;
    line-height: 1;
}

.nav__links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    list-style: none;
    flex: 1;
}

.nav__links a {
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    transition: color 0.2s ease;
}

.nav__links a:hover {
    color: var(--accent-1);
}

.nav-link--primary {
    font-weight: 500;
    position: relative;
}

.nav-link--primary::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -4px;
    height: 1.5px;
    background: var(--accent-1);
    opacity: 0.7;
}

.nav-link--primary:hover::after {
    opacity: 1;
}

.nav__search {
    display: flex;
    align-items: center;
    position: relative;
}

.nav__search input {
    font-family: var(--sans);
    font-size: 0.9rem;
    background: var(--card-light);
    border: 1px solid var(--divider);
    border-radius: 999px;
    padding: 0.5rem 1rem 0.5rem 40px;
    color: var(--text);
    min-width: 360px;
    width: clamp(360px, 30vw, 420px);
    outline: none;
    transition: border-color 0.2s ease;
}

.nav__search-icon {
    position: absolute;
    left: 14px;
    display: flex;
    color: var(--accent-2);
    pointer-events: none;
}

.nav__search input:focus {
    border-color: var(--accent-2);
}

.nav__search input::-webkit-search-cancel-button,
.nav__search input::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
    display: none;
}

.nav__search input::-ms-clear {
    display: none;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--divider);
    border-radius: 50%;
    background: transparent;
    color: var(--accent-2);
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease;
}

.theme-toggle:hover {
    border-color: var(--accent-1);
    color: var(--accent-1);
}

.theme-toggle .theme-icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .theme-icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .theme-icon-moon { display: block; }

/* Кнопка «наверх» — интерфейс, не содержание: гротеск нигде не звучит
   (иконка без текста), только токены поверхности/рамки/приглушённого
   текста, общие для обеих тем. */
.scroll-top-btn {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--card-light);
    border: 1px solid var(--divider);
    color: var(--accent-2);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.scroll-top-btn:hover {
    border-color: var(--accent-1);
    color: var(--accent-1);
}

.scroll-top-btn.is-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
    .scroll-top-btn {
        transition: none;
    }
}

/* Футер */

.footer {
    border-top: 1px solid var(--divider);
    margin-top: 4rem;
    padding: 2.5rem 0;
}

.footer__quote {
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.25rem;
    color: var(--accent-1);
    text-align: center;
    margin-bottom: 1rem;
}

.footer__meta {
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--text);
    opacity: 0.6;
    text-align: center;
    letter-spacing: 0.02em;
}

.footer__links {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 1rem;
    list-style: none;
}

.footer__links a {
    font-size: 0.85rem;
    color: var(--text);
    opacity: 0.7;
    transition: opacity 0.2s ease, color 0.2s ease;
}

.footer__links a:hover {
    opacity: 1;
    color: var(--accent-1);
}

/* Hero */

.hero {
    position: relative;
    min-height: 85vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.hero-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr);
    align-items: center;
    gap: clamp(2.5rem, 6vw, 6rem);
}

.hero-text {
    align-self: stretch;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.hero-engraving {
    display: flex;
    justify-content: center;
    margin: 0;
}

.hero-engraving img {
    width: 100%;
    max-width: 560px;
    height: auto;
    max-height: min(64vh, 660px);
    object-fit: contain;
}

.engraving-dark { display: none; }

[data-theme="light"] .engraving-light { mix-blend-mode: multiply; }

[data-theme="dark"] .engraving-light { display: none; }
[data-theme="dark"] .engraving-dark {
    display: block;
    mix-blend-mode: screen;
}

.hero-eyebrow {
    position: relative;
    display: inline-flex;
    align-items: center;
    font-family: var(--sans);
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-2);
    padding-left: 3rem;
    margin-bottom: 2rem;
}

.hero-eyebrow::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 2.25rem;
    height: 1px;
    background: var(--accent-2);
    transform: translateY(-50%);
}

.hero-quote {
    font-family: var(--serif);
    font-style: italic;
    font-weight: 500;
    font-size: clamp(2.625rem, 6vw, 5.25rem);
    line-height: 1.05;
    color: var(--text);
    margin-bottom: 1.5rem;
}

.hero-attribution {
    font-family: var(--sans);
    font-size: 0.85rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text);
    opacity: 0.6;
    margin-bottom: 2.5rem;
}

.hero-lead {
    font-family: var(--serif);
    font-size: clamp(1.375rem, 2vw, 1.625rem);
    line-height: 1.5;
    max-width: 640px;
    color: var(--text);
    opacity: 0.85;
    margin-bottom: 2.5rem;
}

.hero-cta-group {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.hero-cta {
    display: inline-block;
    font-family: var(--sans);
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    padding: 0.9rem 1.75rem;
    border-radius: 2px;
    transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease, transform 0.2s ease;
}

.hero-cta.primary,
.hero-cta.primary:visited,
.hero-cta.primary:link,
.hero-cta.primary:active,
.hero-cta.primary:focus {
    background: var(--accent-1);
    color: var(--bg);
    border: 1px solid var(--accent-1);
}

.hero-cta.primary:hover {
    background: transparent;
    color: var(--accent-1);
    transform: translateY(-2px);
}

.hero-cta.secondary,
.hero-cta.secondary:visited,
.hero-cta.secondary:link {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--divider);
}

.hero-cta.secondary:hover {
    border-color: var(--accent-1);
    color: var(--accent-1);
    transform: translateY(-2px);
}

/* Section */

.section {
    padding: 120px 0;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 2rem;
    margin-bottom: 4rem;
}

.section-eyebrow {
    position: relative;
    display: inline-flex;
    align-items: center;
    font-family: var(--sans);
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-2);
    padding-left: 2.5rem;
    margin-bottom: 0.75rem;
}

.section-eyebrow::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 1.75rem;
    height: 1px;
    background: var(--accent-2);
    transform: translateY(-50%);
}

.section-title {
    font-family: var(--serif);
    font-size: 3.5rem;
    font-weight: 500;
}

.section-title em {
    font-style: italic;
    color: var(--accent-1);
}

.section-descr {
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.15rem;
    opacity: 0.7;
    max-width: 340px;
    text-align: right;
}

/* Subjects grid */

.subjects-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 40px;
}

.subject-card--morphological {
    --card-bg-light: #A8563A;
    --card-bg-dark: #8B4327;
    --card-text: #F5F0E6;
    --card-accent: #D4CCB8;
}

.subject-card--functional {
    --card-bg-light: #7A2E2E;
    --card-bg-dark: #5C1E1E;
    --card-text: #F5F0E6;
    --card-accent: #D4CCB8;
}

.subject-card--clinical {
    --card-bg-light: #4A6741;
    --card-bg-dark: #3A5033;
    --card-text: #F5F0E6;
    --card-accent: #D4CCB8;
}

.subject-card--micro {
    --card-bg-light: #3D5A80;
    --card-bg-dark: #2E4560;
    --card-text: #F5F0E6;
    --card-accent: #D4CCB8;
}

.subject-card--general {
    --card-bg-light: #4A4A4A;
    --card-bg-dark: #333333;
    --card-text: #F5F0E6;
    --card-accent: #D4CCB8;
}

.subject-card--surgical {
    --card-bg-light: #96662A;
    --card-bg-dark: #7A5220;
    --card-text: #F5F0E6;
    --card-accent: #D4CCB8;
}

.subject-card--diagnostic {
    --card-bg-light: #6B5580;
    --card-bg-dark: #4A3860;
    --card-text: #F5F0E6;
    --card-accent: #D4CCB8;
}

.subject-card--humanities {
    --card-bg-light: #6B5A45;
    --card-bg-dark: #52442F;
    --card-text: #F5F0E6;
    --card-accent: #D4CCB8;
}

[data-theme="dark"] .subject-card--morphological {
    --card-bg-light: #8E4326;
    --card-bg-dark: #6E321B;
}
[data-theme="dark"] .subject-card--functional {
    --card-bg-light: #6E2C2C;
    --card-bg-dark: #532020;
}
[data-theme="dark"] .subject-card--micro {
    --card-bg-light: #2F4770;
    --card-bg-dark: #223555;
}
[data-theme="dark"] .subject-card--clinical {
    --card-bg-light: #3E5636;
    --card-bg-dark: #2E4028;
}
[data-theme="dark"] .subject-card--surgical {
    --card-bg-light: #806029;
    --card-bg-dark: #61481E;
}
[data-theme="dark"] .subject-card--diagnostic {
    --card-bg-light: #573F62;
    --card-bg-dark: #412F49;
}
[data-theme="dark"] .subject-card--general {
    --card-bg-light: #383029;
    --card-bg-dark: #29231D;
}
[data-theme="dark"] .subject-card--humanities {
    --card-bg-light: #5A4630;
    --card-bg-dark: #443524;
}

[data-theme="dark"] .subject-card--morphological,
[data-theme="dark"] .subject-card--functional,
[data-theme="dark"] .subject-card--micro,
[data-theme="dark"] .subject-card--clinical,
[data-theme="dark"] .subject-card--surgical,
[data-theme="dark"] .subject-card--diagnostic,
[data-theme="dark"] .subject-card--general,
[data-theme="dark"] .subject-card--humanities {
    --card-text: #F0E8DA;
    --card-accent: #C0AE92;
}

.subject-card {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    aspect-ratio: 3 / 4;
    padding: 1.75rem;
    overflow: hidden;
    background: linear-gradient(160deg, var(--card-bg-light) 0%, var(--card-bg-dark) 100%);
    color: var(--card-text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.12);
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1),
                box-shadow 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.subject-card::before,
.subject-card::after {
    content: '';
    position: absolute;
    pointer-events: none;
}

.subject-card::before {
    inset: 10px;
    border: 1px solid var(--card-text);
    opacity: 0.55;
}

.subject-card::after {
    inset: 14px;
    border: 1px solid var(--card-text);
    opacity: 0.35;
}

.subject-spine {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: auto;
    width: 3px;
    background: linear-gradient(
        to left,
        rgba(0, 0, 0, 0.15) 0%,
        rgba(0, 0, 0, 0) 100%
    );
    border-right: none;
    pointer-events: none;
    z-index: 1;
}

.subject-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1), 0 16px 32px rgba(0, 0, 0, 0.18);
}

.subject-card--coming-soon {
    opacity: 0.45;
    filter: saturate(0.6);
    pointer-events: none;
    cursor: default;
}

.subject-coming-soon-badge {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--card-text);
    background: rgba(0, 0, 0, 0.4);
    padding: 8px 18px;
    border-radius: 999px;
    z-index: 5;
    white-space: nowrap;
}

.subject-top {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.subject-number {
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.75rem;
    color: var(--card-text);
    opacity: 0.7;
}

.subject-ornament {
    font-size: 1.1rem;
    color: var(--card-text);
    opacity: 0.5;
}

.subject-bottom {
    position: relative;
    z-index: 1;
    padding-top: 10%;
    min-height: 200px;
    text-align: center;
}

.subject-name {
    font-family: var(--serif);
    font-size: 2.5rem;
    font-weight: 500;
    line-height: 1.05;
    color: var(--card-text);
    margin-bottom: 0;
    overflow-wrap: break-word;
    hyphens: manual;
    -webkit-hyphens: manual;
}

.subject-name--long {
    font-size: 2.3rem;
    letter-spacing: -0.01em;
}
.subject-name--xlong { font-size: 1.75rem; }

.subject-divider {
    width: 40px;
    height: 1px;
    margin: 48px auto 1rem;
    background: var(--card-accent);
    opacity: 0.6;
}

.subject-latin {
    font-family: var(--serif);
    font-style: italic;
    font-weight: 400;
    font-size: 20px;
    letter-spacing: 0.02em;
    color: var(--card-text);
    opacity: 0.8;
    margin-top: 8px;
    line-height: 1.3;
}

.subject-meta {
    font-family: var(--serif);
    font-style: italic;
    font-size: 1rem;
    color: var(--card-text);
    opacity: 0.7;
}

/* Subject detail page */

.subject-page--morphological {
    --page-accent: #A8563A;
}

.subject-page--functional {
    --page-accent: #7A2E2E;
}

.subject-page--clinical {
    --page-accent: #4A6741;
}

.subject-page--micro {
    --page-accent: #3D5A80;
}

.subject-page--general {
    --page-accent: #4A4A4A;
}

.subject-page--surgical {
    --page-accent: #96662A;
}

.subject-page--diagnostic {
    --page-accent: #6B5580;
}

.subject-page--humanities {
    --page-accent: #6B5A45;
}

[data-theme="dark"] .subject-page--morphological,
[data-theme="dark"] .subject-page--functional,
[data-theme="dark"] .subject-page--micro,
[data-theme="dark"] .subject-page--clinical,
[data-theme="dark"] .subject-page--surgical,
[data-theme="dark"] .subject-page--diagnostic,
[data-theme="dark"] .subject-page--general,
[data-theme="dark"] .subject-page--humanities {
    --page-accent: #C0562F;
}

.subject-page-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 60px;
    padding-top: 80px;
    padding-bottom: 80px;
}

.sidebar {
    min-width: 0;
    border-right: 1px solid var(--divider);
    padding-right: 32px;
    position: sticky;
    top: 96px;
    align-self: start;
}

.sidebar-eyebrow {
    font-family: var(--sans);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-2);
    margin-bottom: 8px;
}

.sidebar-title {
    font-family: var(--serif);
    font-weight: 600;
    font-size: 32px;
    letter-spacing: -0.01em;
    color: var(--page-accent);
    margin-bottom: 32px;
    overflow-wrap: break-word;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
}

.sidebar-nav-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: 4px;
    font-family: var(--sans);
    font-size: 14px;
    color: var(--text);
    text-decoration: none;
    transition: background 0.15s ease;
}

.sidebar-nav-item:hover {
    background: rgba(139, 111, 31, 0.08);
}

.sidebar-nav-item.active {
    background: var(--page-accent);
    color: var(--bg);
    font-weight: 500;
}

.sidebar-nav-item .count {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--page-accent);
    opacity: 0.7;
}

.sidebar-nav-item.active .count {
    color: var(--divider);
}

.sidebar-nav-group {
    display: flex;
    flex-direction: column;
    margin-left: 17px;
}

.sidebar-nav-group--sub {
    margin-left: 16px;
    border-left: 1px solid transparent;
}

.sidebar-nav-group--sub.active {
    border-left-color: color-mix(in srgb, var(--page-accent) 55%, transparent);
}

.sidebar-nav-group--sub .sidebar-nav-item.active {
    margin-left: 4px;
}

.sidebar-nav-item.child {
    font-size: 13px;
    opacity: 0.75;
}

.sidebar-nav-item.child.active {
    opacity: 1;
    background: var(--page-accent);
}

.sidebar-nav-item.grandchild {
    font-size: 12px;
    opacity: 0.65;
}

.sidebar-nav-item.grandchild.active {
    opacity: 1;
    background: var(--page-accent);
}

.sidebar-group-title {
    font-family: var(--sans);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--accent-2);
    padding: 8px 12px;
    margin-top: 16px;
}

.file-list-area {
    min-width: 0;
    padding-left: 20px;
}

.topics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 40px;
}

.topic-tile {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 100px;
    padding: 20px;
    border: 1px solid var(--divider);
    border-radius: 4px;
    background: var(--card-light);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.topic-tile:hover {
    border-color: var(--page-accent);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(26, 26, 26, 0.08);
}

/* В поиске карточки тем не привязаны к предмету странице — --page-accent
   там не задан, а цвет в этой системе означает предмет: разные предметы
   в одной выдаче не должны красить карточки в разные цвета. */
.search-topics .topic-tile:hover {
    border-color: var(--accent-2);
}

.topic-tile-name {
    font-family: var(--serif);
    font-weight: 500;
    font-size: 20px;
    line-height: 1.2;
    margin-bottom: 8px;
}

.topic-tile-path {
    font-family: var(--sans);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent-2);
    margin-bottom: 8px;
}

.topic-tile-count {
    font-family: var(--sans);
    font-size: 13px;
    color: var(--accent-2);
}

.subtopics-section {
    margin-bottom: 48px;
}

.subtopics-section h2 {
    font-family: var(--serif);
    font-size: 24px;
    font-weight: 500;
    margin-bottom: 16px;
}

.breadcrumb {
    font-size: 13px;
    color: var(--accent-2);
    letter-spacing: 0.03em;
    margin-bottom: 16px;
}

.breadcrumb--mobile {
    display: none;
}

.breadcrumb a {
    color: var(--accent-2);
    text-decoration: none;
    transition: color 0.2s ease;
}

.breadcrumb a:hover {
    color: var(--text);
}

.breadcrumb .sep {
    margin: 0 8px;
    color: var(--page-accent);
    opacity: 0.5;
}

.file-list-header {
    font-family: var(--serif);
    font-weight: 500;
    font-size: 48px;
    letter-spacing: -0.01em;
    color: var(--page-accent);
    margin-bottom: 8px;
}

.file-list-subtitle {
    font-family: var(--serif);
    font-style: italic;
    font-size: 18px;
    color: var(--accent-2);
    margin-bottom: 40px;
}

.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 12px;
    margin: 0 -12px;
    border-bottom: 1px solid var(--divider);
    border-radius: 4px;
    transition: background 0.2s ease, padding-left 0.2s ease;
    content-visibility: auto;
    contain-intrinsic-size: auto 99px;
}

.file-item:hover {
    background: rgba(139, 111, 31, 0.05);
    padding-left: 20px;
}

.file-info {
    min-width: 0;
}

.file-title {
    font-family: var(--serif);
    font-weight: 500;
    font-size: 20px;
    color: var(--text);
    margin-bottom: 6px;
    overflow-wrap: break-word;
}

.file-meta {
    font-family: var(--sans);
    font-size: 13px;
    color: var(--accent-2);
}

.file-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-action {
    font-family: var(--sans);
    font-size: 13px;
    padding: 6px 14px;
    border-radius: 3px;
    border: 1px solid transparent;
    text-decoration: none;
    transition: all 0.15s ease;
    cursor: pointer;
    white-space: nowrap;
}

.file-action--view {
    color: var(--accent-2);
    border-color: var(--divider);
}

.file-action--view:hover {
    color: var(--accent-2);
    border-color: var(--accent-2);
}

.file-action--download {
    background: var(--page-accent, var(--accent-1));
    color: var(--bg);
    border-color: var(--page-accent, var(--accent-1));
}

.file-action--download:hover {
    filter: brightness(0.85);
}

.file-favorite {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    color: var(--accent-2);
    opacity: 0.6;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.file-favorite:hover {
    opacity: 1;
    color: var(--accent-1);
}

.file-favorite.is-active {
    opacity: 1;
    color: var(--accent-1);
}

.file-badge {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.1em;
    border: 1px solid;
    padding: 4px 10px;
    border-radius: 3px;
    margin-left: 8px;
    white-space: nowrap;
    min-width: 60px;
    text-align: center;
}

.file-badge--pdf {
    color: var(--accent-1);
    border-color: var(--accent-1);
}

.file-badge--docx {
    color: var(--accent-2);
    border-color: var(--accent-2);
}

.file-badge--pptx {
    color: var(--text);
    border-color: var(--text);
}

.file-badge--mp4 {
    color: var(--text);
    border-color: var(--text);
}

.file-badge--other {
    color: var(--accent-2);
    border-color: var(--accent-2);
    opacity: 0.7;
}

/* Favorites page */

.favorites-page {
    padding: 60px 0 100px;
    min-height: 60vh;
}

.favorites-list {
    display: flex;
    flex-direction: column;
}

.favorites-empty {
    font-family: var(--serif);
    font-style: italic;
    font-size: 20px;
    color: var(--accent-2);
    padding: 40px 0;
    text-align: center;
}

/* Search page */

.search-page {
    padding: 60px 0 100px;
    min-height: 60vh;
}

.search-summary {
    font-family: var(--serif);
    font-style: italic;
    font-size: 18px;
    color: var(--accent-2);
    margin-bottom: 40px;
}


.search-results-list {
    display: flex;
    flex-direction: column;
}

/* Плавное сворачивание: grid-template-rows 1fr → 0fr анимируется,
   display:none — нет. overflow:hidden у ребёнка обязателен, иначе
   содержимое вылезет за пределы схлопнутой строки грида; min-width:0 —
   та же защита от grid blowout на длинных именах файлов, что уже
   применялась у .sidebar/.file-list-area. */
.search-collapsible {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.search-collapsible.is-collapsed {
    grid-template-rows: 0fr;
}

/* Длинные группы (51 учебник и т.п.) переключают высоту мгновенно —
   браузер иначе считает конечную высоту в первом кадре, и раскрытие
   читается как рывок. У коротких групп и «Предметы»/«Темы» этой
   проблемы нет — там transition остаётся. */
.search-collapsible--instant {
    transition: none;
}

.search-collapsible > * {
    overflow: hidden;
    min-width: 0;
    /* Резерв сверху под подъём карточки при hover (.subject-card:hover
       translateY(-6px), .topic-tile:hover translateY(-2px)) — без него
       overflow:hidden обрезает обложку по верхнему краю. Отрицательный
       margin компенсирует отступ снаружи, чтобы вертикальный ритм
       страницы не сдвинулся. */
    padding-top: 8px;
    margin-top: -8px;
    opacity: 1;
    transition: opacity 0.2s ease-out;
}

.search-collapsible.is-collapsed > * {
    opacity: 0;
    transition: opacity 0.15s ease-out;
}

@media (prefers-reduced-motion: reduce) {
    .search-collapsible {
        transition: none;
    }

    .search-collapsible > * {
        transition: none;
    }
}

.search-section-title {
    font-family: var(--serif);
    font-style: italic;
    font-weight: 500;
    font-size: 26px;
    letter-spacing: 0.02em;
    color: var(--accent-2);
    margin: 32px 0 24px;
    opacity: 0.8;
}

/* Заголовок группы материалов — тот же .search-section-title снаружи
   (h2), но кликабельный: текст наследует шрифт/цвет через
   font/color/letter-spacing: inherit, кнопка сама — только сброс. */
.search-group-toggle {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    width: 100%;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    color: inherit;
    letter-spacing: inherit;
    text-align: left;
    cursor: pointer;
}

.search-group-chevron {
    flex: 0 0 auto;
    color: var(--accent-2);
    transition: transform 0.2s ease;
}

.search-group-toggle[aria-expanded="true"] .search-group-chevron {
    transform: rotate(180deg);
}

.search-subjects {
    margin-bottom: 48px;
}

.search-subjects + .search-section-title,
.search-subjects + .search-topics {
    margin-top: 48px;
}

.search-subjects .subjects-grid {
    gap: 24px;
    /* Наследует template-columns из основного правила .subjects-grid */
}

.search-topics {
    margin-bottom: 48px;
}

.search-topics + .search-section-title {
    margin-top: 48px;
}

.search-empty {
    padding: 0 0 120px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.search-empty-quote {
    font-family: var(--serif);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(48px, 6vw, 88px);
    line-height: 1.05;
    letter-spacing: -0.01em;
    color: var(--accent-1);
}

.search-empty-attribution {
    font-family: var(--sans);
    font-size: 16px;
    font-weight: 400;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--accent-2);
}

.search-empty-hint {
    font-family: var(--serif);
    font-size: 18px;
    line-height: 1.5;
    color: var(--accent-2);
    max-width: 480px;
    margin-top: 32px;
}

.search-page--empty .section-header {
    justify-content: center;
    text-align: center;
}

.search-page--empty .section-header > div {
    text-align: center;
}

.search-page--empty .section-title {
    text-align: center;
}

@media (max-width: 900px) {
    .container {
        padding: 0 1.25rem;
    }

    .nav__tagline {
        display: none;
    }

    .subject-page-layout {
        grid-template-columns: 1fr;
        padding-top: 40px;
        padding-bottom: 40px;
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--divider);
        padding-right: 0;
        padding-bottom: 24px;
        position: static;
    }

    .file-list-area {
        padding-left: 0;
    }

    .nav__inner {
        flex-wrap: wrap;
        align-items: flex-start;
        padding: 1rem 1.25rem;
        row-gap: 1rem;
    }

    .nav__brand {
        align-items: flex-start;
    }

    .nav__links {
        order: 3;
        width: 100%;
        justify-content: flex-start;
        padding-left: 0;
        margin-left: 0;
        gap: 20px;
    }

    .nav__search {
        order: 2;
    }

    .nav__search input {
        min-width: 0;
        width: 160px;
    }

    .theme-toggle {
        order: 2;
    }

    .footer__links {
        flex-wrap: wrap;
        gap: 1rem 1.5rem;
    }

    .hero {
        min-height: auto;
        padding: 4rem 0;
    }

    .hero-grid {
        grid-template-columns: 1fr;
    }

    .hero-engraving {
        display: none;
    }

    .hero-cta-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .section {
        padding: 64px 0;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .section-descr {
        max-width: none;
        text-align: left;
    }

    .subjects-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .hero {
        padding: 40px 0 60px;
    }

    .hero-quote {
        font-size: clamp(56px, 14vw, 88px);
    }

    .hero-attribution {
        font-size: 11px;
        margin-top: 8px;
    }

    .hero-lead {
        font-size: 1.25rem;
        margin: 24px 0 32px;
        line-height: 1.55;
    }

    .section-title {
        font-size: clamp(34px, 9vw, 64px);
        line-height: 1.05;
        letter-spacing: -0.02em;
        /* Длинные термины («Офтальмология») не влезают в строку на узких
           экранах, а Cormorant не переносит внутри слова — разрешаем явно,
           иначе слово выходит за край экрана. */
        overflow-wrap: break-word;
        hyphens: auto;
    }

    .subjects-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .search-subjects .subject-card {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        aspect-ratio: 3 / 4;
    }

    /* Только названия в 12-13 букв («Офтальмология», «Микробиология»,
       «Эпидемиология», «Нутрициология») — на узкой мобильной обложке
       они не помещались в строку и рвались посреди слова. Переносить
       нельзя: одна буква «я» на второй строке хуже, чем есть.
       Остальные обложки сохраняют исходный кегль 2.5rem.
       Правило живёт только в медиазапросе — на десктопе класса
       subject-name--narrow нет ни в одном правиле. */
    .subject-name--narrow {
        font-size: 2.25rem;
    }

    .subject-name--narrower {
        font-size: 2.05rem;
    }


    .subject-page-layout {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .breadcrumb--mobile {
        display: block;
        grid-column: 1 / -1;
    }

    .file-list-area .breadcrumb {
        display: none;
    }

    .sidebar {
        width: 100%;
    }

    .sidebar-eyebrow {
        display: none;
    }

    .sidebar-title {
        font-size: 28px;
    }

    .sidebar-group-title,
    .sidebar-nav-group {
        display: none;
    }

    .file-list-header {
        display: none;
    }

    .file-list-header.page-title--topic {
        display: block;
        font-size: 26px;
    }

    .file-list-subtitle {
        margin-bottom: 16px;
    }

    .file-item {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .file-info {
        width: 100%;
    }

    .file-actions {
        display: grid;
        grid-template-columns: 1fr 1fr 44px 60px;
        width: 100%;
        gap: 8px;
    }

    .file-action--view {
        grid-column: 1;
    }

    .file-action--download {
        grid-column: 2;
    }

    .file-action--view,
    .file-action--download {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .file-favorite {
        grid-column: 3;
        min-width: 44px;
        min-height: 44px;
    }

    .file-badge {
        grid-column: 4;
        margin-left: 0;
    }

    .scroll-top-btn {
        right: 16px;
        bottom: calc(16px + env(safe-area-inset-bottom));
    }
}

/* About page */

.about-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 80px 0 120px;
}

.about-header {
  margin-bottom: 72px;
}

.about-eyebrow {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--accent-1);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.about-eyebrow::before {
  content: '';
  width: 24px;
  height: 1px;
  background: var(--accent-1);
}

.about-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(48px, 6vw, 72px);
  line-height: 1;
  letter-spacing: -0.015em;
  color: var(--text);
}

.about-title em {
  font-style: italic;
  font-weight: 400;
  color: var(--accent-1);
}

.about-section {
  margin-bottom: 56px;
}

.about-section-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 28px;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: 20px;
}

.about-section p {
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 16px;
}

.about-section p:last-child {
  margin-bottom: 0;
}

.about-lead {
  font-family: var(--serif) !important;
  font-style: italic;
  font-size: 24px !important;
  color: var(--accent-1) !important;
  margin-bottom: 24px !important;
  line-height: 1.4 !important;
}

.about-link {
  color: var(--accent-1);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-1);
  padding-bottom: 1px;
  transition: opacity 0.15s;
}

.about-link:hover {
  opacity: 0.7;
}

.about-disclaimer {
  margin-top: 80px;
  padding-top: 32px;
  border-top: 1px solid var(--divider);
}

.about-disclaimer p {
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.6;
  color: var(--accent-2);
  font-style: italic;
}

@media (prefers-reduced-motion: no-preference) {
    ::view-transition-old(root) {
        animation: none;
    }
    ::view-transition-new(root) {
        animation: reveal-circle 1.15s cubic-bezier(0.25, 0.6, 0.3, 1);
        z-index: 2;
    }
    @keyframes reveal-circle {
        from {
            clip-path: circle(0 at var(--reveal-x) var(--reveal-y));
        }
        to {
            clip-path: circle(var(--reveal-r) at var(--reveal-x) var(--reveal-y));
        }
    }
}

.theme-switching body {
    transition: none;
}
