/* =====================================================
   Salomatlik Madaniyati — Theme System (Light + Dark)
   ===================================================== */

:root {
    --brand: #16a34a;
    --brand-2: #059669;
    --brand-glow: rgba(22, 163, 74, 0.35);
    --brand-soft: rgba(22, 163, 74, 0.1);
    --accent: #14b8a6;
    --warn: #f59e0b;
    --danger: #ef4444;
    --info: #0ea5e9;

    /* Light theme defaults */
    --bg: #f1f5f9;
    --bg-grad: radial-gradient(1200px 600px at 10% -10%, rgba(22,163,74,0.18), transparent 60%),
               radial-gradient(900px 500px at 90% 110%, rgba(20,184,166,0.18), transparent 60%),
               linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
    --surface: rgba(255, 255, 255, 0.85);
    --surface-solid: #ffffff;
    --surface-2: #f8fafc;
    --border: rgba(15, 23, 42, 0.08);
    --border-strong: rgba(15, 23, 42, 0.16);
    --text: #0f172a;
    --text-muted: #64748b;
    --text-soft: #475569;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.05);
    --shadow: 0 10px 30px -12px rgba(15, 23, 42, 0.18), 0 4px 8px -6px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 25px 50px -20px rgba(15, 23, 42, 0.25);
    --navbar-bg: rgba(255, 255, 255, 0.7);
    --navbar-border: rgba(15, 23, 42, 0.06);
    --code-bg: #f1f5f9;
}

[data-theme="dark"] {
    --bg: #0b1120;
    --bg-grad: radial-gradient(1200px 600px at 10% -10%, rgba(22,163,74,0.22), transparent 60%),
               radial-gradient(900px 500px at 90% 110%, rgba(14,165,233,0.18), transparent 60%),
               linear-gradient(180deg, #0b1120 0%, #060912 100%);
    --surface: rgba(17, 24, 39, 0.78);
    --surface-solid: #111827;
    --surface-2: #0f172a;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --text-soft: #cbd5e1;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6), 0 4px 8px -6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 25px 50px -20px rgba(0, 0, 0, 0.7);
    --navbar-bg: rgba(11, 17, 32, 0.7);
    --navbar-border: rgba(255, 255, 255, 0.06);
    --code-bg: #1e293b;
}

/* =================== Base =================== */

.rank-gold { background-color: color-mix(in srgb, var(--surface-solid) 85%, #eab308) !important; }
.rank-silver { background-color: color-mix(in srgb, var(--surface-solid) 85%, #94a3b8) !important; }
.rank-bronze { background-color: color-mix(in srgb, var(--surface-solid) 85%, #d97706) !important; }
.rank-current { background-color: var(--brand-soft) !important; font-weight: bold; }
.medal { font-size: 1.5rem; }
.anketa-results-table { min-width: 760px; }
.anketa-question-column { width: 45%; }
.anketa-page, .anketa-page .card { color: var(--text); }

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    background: var(--bg);
    background-image: var(--bg-grad);
    background-attachment: fixed;
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased;
}

main { flex: 1; }

a { color: var(--brand); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--brand-2); }

h1, h2, h3, h4, h5, h6 { color: var(--text); font-weight: 700; letter-spacing: -0.01em; }

.text-muted { color: var(--text-muted) !important; }
.text-soft { color: var(--text-soft) !important; }
hr { border-color: var(--border); }

/* =================== Navbar =================== */

.navbar.sm-nav {
    background: var(--navbar-bg) !important;
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--navbar-border);
    padding: 0.75rem 0;
}
.navbar.sm-nav .navbar-brand {
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--text) !important;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.navbar.sm-nav .navbar-brand .brand-mark {
    width: 38px; height: 38px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--accent) 100%);
    box-shadow: 0 8px 24px -8px var(--brand-glow);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.15rem;
}
.navbar.sm-nav .nav-link {
    color: var(--text-soft) !important;
    font-weight: 500;
    padding: 0.5rem 0.9rem !important;
    border-radius: 0.6rem;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.navbar.sm-nav .nav-link:hover {
    color: var(--brand) !important;
    background: var(--brand-soft);
}
.navbar.sm-nav .nav-link.active {
    color: var(--brand) !important;
    background: var(--brand-soft);
}
.navbar.sm-nav .navbar-toggler {
    border-color: var(--border-strong);
    color: var(--text);
}
.navbar.sm-nav .navbar-toggler-icon {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='%2316a34a' stroke-width='2.5' stroke-linecap='round' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E");
}

/* Header and left navigation. */
.navbar.sm-header { min-height: 88px; z-index: 1030; }
.sm-header > .container-fluid { gap: 0.75rem; padding-inline: 1rem; }
.navbar.sm-header .navbar-brand {
    white-space: normal;
    max-width: 235px;
    margin: 0;
    font-size: 1.1rem;
}
.sm-header .brand-mark { flex-shrink: 0; }
.sm-header .sm-account-links {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
    min-width: 0;
}
.sm-header .dropdown-toggle { max-width: 240px; overflow-wrap: anywhere; }
.sm-header .dropdown-menu { position: absolute; }
.sm-header .theme-toggle { margin-left: 0; }
.sm-sidebar .navbar-nav { gap: 0.35rem; width: 100%; }
.sm-sidebar .nav-link { width: 100%; overflow-wrap: anywhere; }

/* Nested sidebar links keep their parent pages accessible. */
.sm-nav-row { display: flex; align-items: center; }
.sm-nav-row > .nav-link { flex: 1; min-width: 0; }
.sm-submenu-toggle {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    background: transparent;
    color: var(--text-soft);
}
.sm-submenu-toggle:hover { background: var(--brand-soft); color: var(--brand); }
.sm-submenu-toggle:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.sm-submenu-toggle .bi { display: inline-block; transition: transform 0.2s; }
.sm-submenu-toggle[aria-expanded="true"] .bi { transform: rotate(180deg); }
.sm-submenu {
    list-style: none;
    padding-left: 0.65rem;
    margin: 0.25rem 0 0.5rem 0.75rem;
    border-left: 1px solid var(--border-strong);
}
.navbar.sm-sidebar .sm-submenu .nav-link { font-size: 0.85rem; padding: 0.5rem !important; }

@media (min-width: 992px) {
    body.sm-has-sidebar { padding-left: 270px; }
    .navbar.sm-header { height: 88px; }
    .sm-has-sidebar .navbar.sm-header { margin-left: -270px; }
    .navbar.sm-sidebar {
        position: fixed;
        inset: 88px auto 0 0;
        width: 270px;
        overflow-y: auto;
        align-items: flex-start;
        border-bottom: 0;
        border-right: 1px solid var(--navbar-border);
        padding: 1.5rem 1rem;
        z-index: 1020;
    }
    .navbar.sm-sidebar > .container-fluid { padding: 0; }
    .navbar.sm-sidebar .navbar-nav { flex-direction: column; }
    body > main.container,
    body > .container,
    body > .sm-footer > .container { max-width: 100%; padding-inline: 2rem; }
}

@media (max-width: 991.98px) {
    .sm-header .sm-account-links { flex-wrap: wrap; justify-content: flex-end; }
    .navbar.sm-header .navbar-brand { max-width: 215px; font-size: 1rem; }
    .navbar.sm-sidebar { padding: 0; }
    .sm-sidebar .navbar-collapse.show,
    .sm-sidebar .navbar-collapse.collapsing { padding-block: 1rem; }
}

@media print {
    body.sm-has-sidebar { padding-left: 0; }
    .navbar.sm-sidebar, .navbar.sm-header { display: none; }
}

/* Theme toggle button */
.theme-toggle {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    width: 40px; height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.25s ease;
    margin-left: 0.5rem;
}
.theme-toggle:hover {
    transform: rotate(20deg);
    border-color: var(--brand);
    color: var(--brand);
}
.theme-toggle .bi { font-size: 1.05rem; }
[data-theme="light"] .theme-toggle .bi-moon-stars-fill { display: inline-block; }
[data-theme="light"] .theme-toggle .bi-sun-fill { display: none; }
[data-theme="dark"]  .theme-toggle .bi-moon-stars-fill { display: none; }
[data-theme="dark"]  .theme-toggle .bi-sun-fill { display: inline-block; }

/* Dropdown menu themed */
.dropdown-menu {
    background: var(--surface-solid);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: 0.85rem;
    padding: 0.5rem;
}
.dropdown-item {
    color: var(--text-soft);
    border-radius: 0.55rem;
    padding: 0.55rem 0.9rem;
    font-weight: 500;
}
.dropdown-item:hover, .dropdown-item:focus {
    background: var(--brand-soft);
    color: var(--brand);
}
.dropdown-item.text-danger:hover { background: rgba(239,68,68,0.1); color: var(--danger); }
.dropdown-divider { border-color: var(--border); }

/* =================== Cards =================== */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1rem;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}
.card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
    border-color: var(--border-strong);
}
.card-custom { /* legacy class kept */
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1rem;
    box-shadow: var(--shadow-sm);
}
.card-header {
    background: transparent !important;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-weight: 600;
}
.card-header.bg-success {
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%) !important;
    color: #fff !important;
    border-bottom: none;
}
.card-body { color: var(--text-soft); }
.sm-general-test .card { color: var(--text); }
.card-title { color: var(--text); }

/* =================== Buttons =================== */

.btn {
    border-radius: 0.7rem;
    font-weight: 600;
    padding: 0.55rem 1.2rem;
    transition: all 0.2s ease;
    border-width: 1.5px;
}
.btn-success, .btn-success:focus {
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
    border: none;
    color: #fff;
    box-shadow: 0 8px 22px -10px var(--brand-glow);
}
.btn-success:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 26px -10px var(--brand-glow);
    color: #fff;
}
.btn-outline-success {
    border-color: var(--brand);
    color: var(--brand);
    background: transparent;
}
.btn-outline-success:hover {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}
.btn-outline-light {
    border-color: rgba(255,255,255,0.6);
    color: #fff;
}
.btn-outline-light:hover { background: rgba(255,255,255,0.15); color: #fff; }
.btn-light {
    background: var(--surface-solid);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-outline-primary { border-color: var(--info); color: var(--info); }
.btn-outline-primary:hover { background: var(--info); color: #fff; }
.btn-outline-info { border-color: var(--info); color: var(--info); }
.btn-outline-info:hover { background: var(--info); color: #fff; }
.btn-outline-warning { border-color: var(--warn); color: var(--warn); }
.btn-outline-warning:hover { background: var(--warn); color: #fff; }
.btn-outline-secondary { border-color: var(--border-strong); color: var(--text-soft); }
.btn-outline-secondary:hover { background: var(--text-soft); color: var(--surface-solid); border-color: var(--text-soft); }
.btn-outline-dark { border-color: var(--text); color: var(--text); }
.btn-outline-dark:hover { background: var(--text); color: var(--surface-solid); }

/* =================== Forms =================== */

.form-control, .form-select {
    background: var(--surface-solid);
    border: 1.5px solid var(--border-strong);
    color: var(--text);
    border-radius: 0.7rem;
    padding: 0.65rem 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus, .form-select:focus {
    background: var(--surface-solid);
    color: var(--text);
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--brand-soft);
}
.form-control::placeholder { color: var(--text-muted); }
.form-label { color: var(--text); font-weight: 500; }

/* =================== Badges =================== */

.badge {
    font-weight: 600;
    padding: 0.4em 0.75em;
    border-radius: 0.55rem;
}
.badge.bg-success { background: var(--brand) !important; color: #fff; }
.badge.bg-warning { background: var(--warn) !important; }
.badge.bg-danger  { background: var(--danger) !important; color: #fff; }
.badge.bg-info    { background: var(--info) !important; color: #fff; }
.badge.bg-secondary { background: var(--text-muted) !important; color: #fff; }
.badge.bg-primary { background: var(--info) !important; color: #fff; }

/* Soft badges (utility) */
.badge-soft-success { background: var(--brand-soft); color: var(--brand); }
.badge-soft-warn { background: rgba(245,158,11,0.12); color: var(--warn); }
.badge-soft-info { background: rgba(14,165,233,0.12); color: var(--info); }

/* =================== Tables =================== */

.table {
    color: var(--text);
    border-color: var(--border);
}
.table > :not(caption) > * > * {
    background: transparent;
    color: var(--text-soft);
    border-bottom-color: var(--border);
    padding: 1rem 0.85rem;
}
.table thead th {
    color: var(--text);
    font-weight: 700;
    border-bottom: 2px solid var(--border-strong);
    text-transform: uppercase;
    font-size: 0.78rem;
    letter-spacing: 0.06em;
}
.table-hover tbody tr:hover > * { background: var(--brand-soft); color: var(--text); }

/* =================== Alerts =================== */

.alert {
    border: 1px solid var(--border);
    border-radius: 0.85rem;
    background: var(--surface);
    color: var(--text-soft);
    padding: 1rem 1.2rem;
}
.alert-success { background: var(--brand-soft); color: var(--brand); border-color: rgba(22,163,74,0.25); }
.alert-info    { background: rgba(14,165,233,0.1); color: var(--info); border-color: rgba(14,165,233,0.25); }
.alert-warning { background: rgba(245,158,11,0.1); color: var(--warn); border-color: rgba(245,158,11,0.25); }
.alert-danger  { background: rgba(239,68,68,0.1); color: var(--danger); border-color: rgba(239,68,68,0.25); }

/* =================== Breadcrumbs =================== */

.breadcrumb {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.65rem 1rem;
    border-radius: 0.7rem;
}
.breadcrumb-item, .breadcrumb-item a { color: var(--text-muted); }
.breadcrumb-item.active { color: var(--text); font-weight: 600; }
.breadcrumb-item + .breadcrumb-item::before { color: var(--text-muted); }

/* =================== Progress =================== */

.progress {
    background: var(--border);
    border-radius: 999px;
    height: 8px;
    overflow: hidden;
}
.progress-bar { background: linear-gradient(90deg, var(--brand) 0%, var(--accent) 100%); }

/* =================== Footer =================== */

.sm-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    color: var(--text-soft);
    margin-top: 4rem;
    padding: 2.5rem 0 1.5rem;
}
.sm-footer h5, .sm-footer h6 { color: var(--text); }
.sm-footer a { color: var(--text-muted); }
.sm-footer a:hover { color: var(--brand); }

/* =================== Hero =================== */

.hero-section {
    position: relative;
    color: #fff;
    padding: 5rem 1rem 5.5rem;
    border-radius: 1.5rem;
    margin-bottom: 3rem;
    overflow: hidden;
    background: linear-gradient(135deg, #16a34a 0%, #0ea5e9 100%);
    isolation: isolate;
}
.hero-section::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(800px 350px at 20% 15%, rgba(255,255,255,0.18), transparent 60%),
        radial-gradient(700px 350px at 85% 90%, rgba(255,255,255,0.12), transparent 60%);
    pointer-events: none;
    z-index: -1;
}
.hero-section::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255,255,255,0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.06) 1px, transparent 1px);
    background-size: 36px 36px;
    mask-image: radial-gradient(ellipse at center, #000 30%, transparent 80%);
    -webkit-mask-image: radial-gradient(ellipse at center, #000 30%, transparent 80%);
    pointer-events: none;
    z-index: -1;
}
[data-theme="dark"] .hero-section {
    background: linear-gradient(135deg, #064e3b 0%, #0c4a6e 100%);
}
.hero-section h1 {
    font-weight: 800;
    font-size: clamp(2rem, 4vw, 3rem);
    color: #fff;
    line-height: 1.15;
}
.hero-section .lead { color: rgba(255,255,255,0.9); }

/* =================== Module / Feature Cards =================== */

.module-card {
    border-radius: 1.15rem;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    height: 100%;
    transition: all 0.3s ease;
    position: relative;
}
.module-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 0%, var(--brand-soft) 100%);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}
.module-card:hover {
    transform: translateY(-6px);
    border-color: var(--brand);
    box-shadow: 0 18px 40px -16px var(--brand-glow);
}
.module-card:hover::before { opacity: 1; }
.module-card .module-icon-wrap {
    width: 64px; height: 64px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--accent) 100%);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    margin-bottom: 1.2rem;
    box-shadow: 0 14px 32px -12px var(--brand-glow);
}
.module-card .card-title { color: var(--text); }
.module-card .card-text { color: var(--text-muted); }

/* =================== Stat Card =================== */

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1.1rem;
    padding: 1.5rem;
    height: 100%;
    transition: all 0.25s;
    position: relative;
    overflow: hidden;
}
.stat-card:hover {
    transform: translateY(-3px);
    border-color: var(--brand);
    box-shadow: var(--shadow);
}
.stat-card .stat-icon {
    width: 52px; height: 52px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    margin-bottom: 1rem;
}
.stat-card .stat-icon.success { background: var(--brand-soft); color: var(--brand); }
.stat-card .stat-icon.info    { background: rgba(14,165,233,0.12); color: var(--info); }
.stat-card .stat-icon.warn    { background: rgba(245,158,11,0.12); color: var(--warn); }
.stat-card .stat-icon.primary { background: rgba(99,102,241,0.12); color: #6366f1; }
.stat-card .stat-label { color: var(--text-muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.stat-card .stat-value { font-size: 1.85rem; font-weight: 800; color: var(--text); margin: 0.25rem 0; }

/* =================== Page header =================== */

.page-header { margin-bottom: 2rem; }
.page-header h1 { font-weight: 800; color: var(--text); display: flex; align-items: center; gap: 0.7rem; }
.page-header p { color: var(--text-muted); font-size: 1.05rem; margin: 0; }

/* =================== Lesson content =================== */

.lesson-content {
    color: var(--text-soft);
    line-height: 1.8;
    font-size: 1.04rem;
}
.lesson-content p { margin-bottom: 1rem; }
.sm-lecture-content { overflow-wrap: anywhere; }
.sm-lecture-content img { height: auto; }

/* Book typography for the introduction and all lecture topics. */
.lecture-reader {
    --book-paper: #fffdf7;
    --book-ink: #292b28;
    --book-muted: #6b7066;
    --book-rule: #e5e1d6;
    max-width: 920px;
    margin-inline: auto;
    color: var(--text);
}
[data-theme="dark"] .lecture-reader {
    --book-paper: #18212b;
    --book-ink: #e1e5df;
    --book-muted: #acb7ad;
    --book-rule: #34413d;
}
.lecture-reader > .page-header { margin-bottom: 1.25rem; }
.lecture-contents {
    padding: 1rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: .75rem;
}
.lecture-contents summary { cursor: pointer; font-weight: 600; }
.lecture-contents summary > span:last-child { float: right; margin-left: 1rem; }
.lecture-contents a[aria-current="page"] { font-weight: 700; text-decoration: underline; text-underline-offset: .2em; }
.lecture-book {
    background: var(--book-paper);
    color: var(--book-ink);
    border: 1px solid var(--book-rule);
    border-radius: 3px 12px 12px 3px;
    box-shadow: inset 7px 0 12px -10px #0006, 4px 4px 0 -1px var(--book-paper), 4px 4px 0 0 var(--book-rule), 0 18px 45px -25px #0005;
    padding: clamp(1.4rem, 5vw, 4.5rem);
    font-family: Georgia, 'Times New Roman', serif;
}
.lecture-book-header { text-align: center; margin: .5rem 0 2.75rem; }
.lecture-book-kicker, .lecture-book-position, .lecture-book-footer {
    font-family: 'Inter', sans-serif;
    font-size: .78rem;
    letter-spacing: .08em;
    color: var(--book-muted);
}
.lecture-book-kicker { text-transform: uppercase; margin-bottom: 1.3rem; }
.lecture-book h1 {
    font-family: inherit;
    color: var(--book-ink);
    font-size: clamp(1.8rem, 3vw, 2.6rem);
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -.02em;
    text-wrap: balance;
}
.lecture-book-position { margin-top: 1.25rem; }
.lecture-book-keywords {
    font-size: 1rem;
    font-style: italic;
    line-height: 1.7;
    color: var(--book-muted);
    margin-bottom: 2.25rem;
}
.lecture-book-section {
    color: var(--book-ink);
    font-family: inherit;
    font-size: clamp(1.3rem, 2vw, 1.65rem);
    line-height: 1.45;
    margin: 0 0 1.75rem;
    text-wrap: balance;
}
.lecture-book-text { font-size: 1.15rem; line-height: 1.95; }
.lecture-book-text p {
    margin: 0 0 .9em;
    text-indent: 1.75em;
    text-align: justify;
    hyphens: auto;
    orphans: 3;
    widows: 3;
}
.lecture-book-text > p:first-child, .lecture-book-text figure + p { text-indent: 0; }
.lecture-book-text figure { break-inside: avoid; }
.lecture-book-text img { max-width: 100%; }
.lecture-book-footer {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 3rem;
    padding-top: 1.1rem;
    border-top: 1px solid var(--book-rule);
}
@media (max-width: 575.98px) {
    .lecture-book { padding: 1.5rem 1.15rem; }
    .lecture-book-header { margin-bottom: 2rem; }
    .lecture-book-text { font-size: 1.075rem; line-height: 1.85; }
    .lecture-book-text p { text-align: start; text-indent: 1.25em; }
    .lecture-contents summary > span:last-child { float: none; display: block; margin: .35rem 0 0 1rem; }
}
.lesson-content strong { color: var(--text); }
.lesson-content code {
    background: var(--code-bg);
    padding: 0.15rem 0.4rem;
    border-radius: 0.35rem;
    color: var(--brand);
    font-size: 0.9em;
}

/* Six mechanisms, arranged around their shared purpose. */
.mechanisms-panel { container-type: inline-size; }
.mechanisms-diagram {
    position: relative;
    display: grid;
    grid-template-columns: 30% 30% 30%;
    grid-template-rows: repeat(3, minmax(140px, auto));
    gap: 10px 5%;
    isolation: isolate;
}
.mechanisms-arrows {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    color: var(--text-muted);
    z-index: -1;
    pointer-events: none;
}
.mechanisms-center {
    grid-column: 2;
    grid-row: 1 / 4;
    align-self: center;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 260px;
    margin: 0;
    padding: 28px 18px;
    border: 2px solid #9464b4;
    border-radius: 50%;
    background: #f0e7f8;
    color: #583676;
    text-align: center;
    font-size: clamp(1rem, 2cqi, 1.35rem);
    font-weight: 800;
    line-height: 1.5;
}
.mechanism-node {
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
    padding: 18px 14px;
    border: 1.5px solid var(--node-border);
    border-radius: 18px;
    background: var(--node-bg);
    color: var(--node-text);
    text-decoration: none;
    transition: box-shadow .2s;
}
.mechanism-node:hover { color: var(--node-text); box-shadow: var(--shadow); }
.mechanism-node:focus-visible { outline: 3px solid var(--brand); outline-offset: 4px; }
.mechanism-node h3 { font-size: clamp(1rem, 1.7cqi, 1.15rem); font-weight: 750; line-height: 1.35; margin: 0 0 8px; }
.mechanism-node p { font-size: .94rem; line-height: 1.5; margin: 0; }
.mechanism-node--1 { grid-area: 1 / 1; --node-bg: #fff3c4; --node-border: #c9a844; --node-text: #665014; }
.mechanism-node--2 { grid-area: 2 / 1; --node-bg: #e0f1cc; --node-border: #7aa65a; --node-text: #365723; }
.mechanism-node--3 { grid-area: 3 / 1; --node-bg: #f9dce4; --node-border: #c87c92; --node-text: #79364e; }
.mechanism-node--4 { grid-area: 1 / 3; --node-bg: #fce7cc; --node-border: #ce9b59; --node-text: #72501d; }
.mechanism-node--5 { grid-area: 2 / 3; --node-bg: #dceefa; --node-border: #6195bb; --node-text: #285678; }
.mechanism-node--6 { grid-area: 3 / 3; --node-bg: #e8dff5; --node-border: #9d82bc; --node-text: #5c427c; }
[data-theme="dark"] .mechanism-node {
    background: color-mix(in srgb, var(--node-border) 18%, var(--surface));
    color: var(--text);
}
[data-theme="dark"] .mechanisms-center { background: #352640; color: #eedffb; }
article[id^="definition-"] { scroll-margin-top: 100px; }
@container (max-width: 700px) {
    .mechanisms-diagram { grid-template-columns: 1fr; grid-template-rows: auto; gap: 18px; padding-left: 24px; }
    .mechanisms-arrows { display: none; }
    .mechanisms-diagram::before { content: ""; position: absolute; left: 6px; top: 75px; bottom: 65px; border-left: 2px solid var(--text-muted); }
    .mechanisms-center { grid-area: auto; min-height: 150px; border-radius: 32px; padding: 22px; font-size: 1.1rem; }
    .mechanism-node { grid-area: auto; position: relative; min-height: 130px; }
    .mechanism-node::before { content: ""; position: absolute; left: -19px; top: 50%; width: 17px; border-top: 2px solid var(--text-muted); }
    .mechanisms-center::before { content: ""; position: absolute; left: 2px; top: 71px; width: 10px; height: 10px; border-top: 2px solid var(--text-muted); border-right: 2px solid var(--text-muted); transform: rotate(45deg); }
}

/* Custom scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--brand); }

/* =================== Animations =================== */

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fadeUp 0.5s ease both; }
.fade-up-delay-1 { animation: fadeUp 0.5s ease 0.06s both; }
.fade-up-delay-2 { animation: fadeUp 0.5s ease 0.12s both; }
.fade-up-delay-3 { animation: fadeUp 0.5s ease 0.18s both; }

/* List groups themed */
.list-group-item {
    background: transparent;
    color: var(--text-soft);
    border-color: var(--border);
}

/* Avoid Bootstrap white-bg overrides on inputs/cards in dark mode */
[data-theme="dark"] .bg-light { background: var(--surface-2) !important; color: var(--text-soft); }
[data-theme="dark"] .text-dark { color: var(--text) !important; }
[data-theme="dark"] img.card-img-top { filter: brightness(0.92); }

/* Research questionnaires and comparison report */
.research-table { min-width: 720px; }
.research-track { height: 16px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.research-bar { height: 100%; min-width: 0; }
.survey-question input[type="radio"] { accent-color: var(--brand); }
@media print {
    .research-table { min-width: 0; }
    .table-responsive { overflow: visible; }
    .research-bar { print-color-adjust: exact; }
}
