:root {
    --bg: #0a0b0e;
    --text: #e8ebf0;
    --muted: #9aa3af;
    --card: #12141a;
    --border: #202531;
    --accent: #6ea8fe;
    --accent-hover: #5b92e5;
    --accent-2: #9b59b6;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --scroll-track: #1a1d26;
    --scroll-thumb: #3e4658;
    --player-bg: #1a1d26;

    /* Шрифты */
    --font-family-sans: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    --font-family-serif: 'Georgia', 'Times New Roman', serif;
    --current-font: var(--font-family-sans);

    --highlight-bg: #fff176;
    --highlight-text: #000;

    --fav-color: #ffd700;
    --font-size: 16px;
    --line-height: 1.6;
    --nav-height: 60px;
    --player-height: 80px;

    /* Цвета карты (Темная тема - приглушенные) */
    --map-fe: #2c5282;
    /* Дальний восток */
    --map-sib: #553c9a;
    /* Сибирь */
    --map-ural: #97266d;
    /* Урал */
    --map-nw: #975a16;
    /* Северо-Запад */
    --map-cen: #276749;
    /* Центр */
    --map-vol: #dd6b20;
    /* Поволжье */
    --map-south: #2b6cb0;
    /* Юг */
    --map-kav: #9b2c2c;
    /* Кавказ */
    --map-stroke: #1a202c;
    --map-hover-stroke: #fff;
}

:root.light {
    --bg: #f8fafc;
    --text: #0f172a;
    --muted: #475569;
    --card: #fff;
    --border: #e2e8f0;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-2: #7c3aed;
    --shadow: 0 6px 20px rgba(2, 6, 23, 0.08);
    --scroll-track: #e2e8f0;
    --scroll-thumb: #94a3b8;
    --player-bg: #fff;

    --highlight-bg: #fef08a;

    /* Цвета карты (Светлая тема - яркие пастельные) */
    --map-fe: #90CDF4;
    --map-sib: #B794F4;
    --map-ural: #F687B3;
    --map-nw: #F6E05E;
    --map-cen: #68D391;
    --map-vol: #F6AD55;
    --map-south: #63B3ED;
    --map-kav: #FC8181;
    --map-stroke: #fff;
    --map-hover-stroke: #2d3748;
}

/* Режим засечек (Serif) */
body.serif-mode {
    --current-font: var(--font-family-serif);
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    margin: 0;
    padding-top: 70px;
    padding-bottom: var(--player-height);
    /* Отступ для плеера */
    font-family: var(--current-font);
    font-size: var(--font-size);
    line-height: var(--line-height);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

@media (max-width: 768px) {
    body {
        padding-bottom: calc(var(--nav-height) + var(--player-height));
    }
}

* {
    scrollbar-width: auto;
    scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

::-webkit-scrollbar {
    width: 16px;
}

::-webkit-scrollbar-track {
    background: var(--scroll-track);
}

::-webkit-scrollbar-thumb {
    background-color: var(--scroll-thumb);
    border-radius: 10px;
    border: 4px solid var(--scroll-track);
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--accent);
}

/* Шапка */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 70px;
    z-index: 1000;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}

.site-header .brand {
    display: flex;
    align-items: center;
    z-index: 2;
}

.site-header .brand h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    white-space: nowrap;
}

.logo-container {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
}

.logo {
    height: 40px;
    width: auto;
    display: block;
}

.header-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 2;
}

.progress {
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 4px;
    background: transparent;
    z-index: 1001;
}

.progress .bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    transition: width 0.1s linear;
    box-shadow: 0 0 10px var(--accent);
}

/* Сетка и Сайдбар */
.layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    align-items: start;
}

/* Sidebar — обычный grid-элемент, sticky в inner-обёртке */
.sidebar {
    align-self: start;
    margin: 0;
    min-width: 0;
    transition: transform 0.3s;
}

.sidebar-inner {
    position: sticky;
    top: 90px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-right: 5px;
}

.content {
    margin: 0;
    min-height: 60vh;
    display: grid;
    gap: 16px;
}

/* МОБИЛЬНАЯ НАВИГАЦИЯ */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--nav-height);
    background: var(--card);
    border-top: 1px solid var(--border);
    z-index: 5000;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.3);
}

.nav-item {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 10px;
    text-transform: uppercase;
    text-align: center;
    cursor: pointer;
    flex: 1;
    height: 100%;
    font-weight: 600;
}

.nav-item:hover,
.nav-item.active {
    color: var(--accent);
}

/* ЭЛЕМЕНТЫ */
.ege-timer {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    padding: 15px;
    border-radius: 12px;
    text-align: center;
    font-weight: bold;
    box-shadow: var(--shadow);
    font-size: 14px;
    line-height: 1.4;
}

.ege-timer span {
    font-size: 20px;
    display: block;
    margin-top: 4px;
}

/* Поиск */
.search-container {
    position: relative;
}

.search-box {
    display: flex;
    gap: 8px;
}

.search-box input {
    flex-grow: 1;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 16px;
    min-width: 0;
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent);
}

.btn-search {
    width: 46px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--accent);
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-search:hover {
    background: var(--border);
}

.search-history {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
    z-index: 100;
    margin-top: 5px;
    overflow: hidden;
}

.search-history-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-history-item:last-child {
    border-bottom: none;
}

.search-history-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

/* Оглавление */
.toc,
.sources {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card);
    box-shadow: var(--shadow);
}

.toc .toc-title,
.sources h2 {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-weight: 600;
    margin: 0;
    font-size: 16px;
}

.toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.toc-chapter {
    border-bottom: 1px solid var(--border);
}

.toc-chapter:last-child {
    border-bottom: none;
}

.toc-chapter-header {
    padding: 12px 14px;
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    font-weight: 500;
    font-size: 15px;
    color: var(--text);
    transition: background 0.2s;
    line-height: 1.4;
}

.toc-chapter-header span:first-child {
    flex-grow: 1;
    margin-right: 10px;
}

.toc-chapter-header:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* АКТИВНАЯ ГЛАВА (SpyScroll) */
.toc-chapter.active .toc-chapter-header {
    color: var(--accent);
    background: rgba(37, 99, 235, 0.1);
    border-left: 3px solid var(--accent);
}

.toc-toggle-icon {
    transition: transform 0.2s;
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
}

.toc-chapter.open .toc-toggle-icon {
    transform: rotate(180deg);
}

.toc-chapter.open .toc-chapter-header {
    color: var(--accent);
}

.toc-progress {
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid var(--border);
    display: none;
    font-size: 13px;
    color: var(--muted);
}

.toc-chapter.open .toc-progress {
    display: block;
}

.progress-checks {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 5px;
}

.progress-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.progress-label input[type="checkbox"] {
    accent-color: var(--accent);
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.toc-articles {
    list-style: none;
    margin: 0;
    padding: 5px 0 10px 0;
    display: none;
    background: rgba(0, 0, 0, 0.1);
}

.toc-chapter.open .toc-articles {
    display: block;
}

.toc-articles li a {
    display: block;
    padding: 6px 14px 6px 30px;
    text-decoration: none;
    color: var(--muted);
    font-size: 13px;
    transition: color 0.2s;
}

.toc-articles li a:hover {
    color: var(--accent);
    background: rgba(255, 255, 255, 0.05);
}

/* Карточки */
.card {
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 14px;
    background: var(--card);
    box-shadow: var(--shadow);
    padding: 20px;
    scroll-margin-top: 90px;

    /* АНИМАЦИЯ ПОЯВЛЕНИЯ */
    animation: fadeIn 0.4s ease-out forwards;
    opacity: 0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card.highlight {
    animation: flash 1.5s ease-out;
}

@keyframes flash {
    0% {
        background-color: var(--accent-2);
    }

    100% {
        background-color: var(--card);
    }
}

.card header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 15px;
}

.card .header-content {
    flex-grow: 1;
}

.card .title {
    margin: 0;
    font-size: 1.2em;
    color: var(--accent);
    font-weight: 700;
}

.card .meta {
    display: inline-flex;
    gap: 8px;
    flex-shrink: 0;
}

.card .body p {
    margin: 10px 0;
}

.breadcrumbs {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    margin-bottom: 4px;
}

.card .explain {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px dashed var(--border);
}

.card .explain summary {
    cursor: pointer;
    color: var(--muted);
    font-weight: 600;
}

.card .explain summary:hover {
    color: var(--accent);
}

.card .explain-body {
    background: rgba(255, 255, 255, 0.03);
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
    font-size: 0.95em;
}

/* --- ПРОГРЕСС ЧТЕНИЯ --- */
.card-footer {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

.btn-read {
    font-size: 13px;
    padding: 5px 14px;
    border-radius: 20px;
    border: 1.5px solid var(--border);
    background: none;
    cursor: pointer;
    color: var(--muted);
    transition: all 0.2s;
    font-family: inherit;
}
.btn-read:hover { border-color: #22c55e; color: #22c55e; }
.btn-read.read {
    background: rgba(34, 197, 94, 0.12);
    border-color: #22c55e;
    color: #22c55e;
    font-weight: 600;
}

/* Баннер активного поиска (только мобиле) */
.mobile-search-banner {
    display: none;
}
@media (max-width: 768px) {
    .mobile-search-banner {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 8px 16px;
        background: rgba(79, 70, 229, 0.12);
        border-bottom: 1px solid var(--border);
        font-size: 13px;
        color: var(--text);
        position: sticky;
        top: 60px;
        z-index: 100;
    }
    .mobile-search-banner[hidden] { display: none !important; }
}
.mobile-search-banner-clear {
    background: none;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
    color: var(--muted);
    white-space: nowrap;
    font-family: inherit;
    transition: all 0.2s;
}
.mobile-search-banner-clear:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.progress-summary {
    background: var(--surface2);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 0;
}
.progress-summary-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}
.progress-summary-fill {
    height: 100%;
    background: linear-gradient(90deg, #22c55e, #16a34a);
    border-radius: 2px;
    transition: width 0.4s ease;
}

/* TOC прогресс по главе */
.toc-chapter-header {
    display: flex;
    align-items: center;
    gap: 6px;
}
.toc-chapter-progress {
    font-size: 11px;
    color: var(--muted);
    margin-left: auto;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}
.toc-progress-bar {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 12px 6px;
}
.toc-progress-bar-fill {
    height: 100%;
    background: #22c55e;
    border-radius: 2px;
    transition: width 0.3s;
}

/* --- ПАНЕЛЬ ЗАМЕТОК --- */
.notes-list-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.notes-list-item:hover { background: var(--surface2); }
.notes-list-item:last-child { border-bottom: none; }
.notes-list-title { font-weight: 600; color: var(--accent); font-size: 14px; margin-bottom: 4px; }
.notes-list-preview { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- ЗАМЕТКИ --- */
.note-container {
    margin-top: 10px;
    padding: 10px;
    background: rgba(255, 241, 118, 0.05);
    border: 1px dashed var(--muted);
    border-radius: 8px;
    animation: fadeIn 0.3s;
}

.note-area {
    width: 100%;
    min-height: 60px;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 0.95em;
    resize: vertical;
}

.note-area:focus {
    outline: none;
}

/* --- ФЛЕШ КАРТОЧКИ --- */
.flashcard-wrapper {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.flashcard-container {
    perspective: 1000px;
    width: 100%;
    max-width: 500px;
    height: 300px;
}

.flashcard {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    cursor: pointer;
    border-radius: 16px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.flashcard.flipped {
    transform: rotateY(180deg);
}

.flashcard .front,
.flashcard .back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    border-radius: 16px;
    background: var(--card);
    border: 2px solid var(--border);
}

.flashcard .front {
    color: var(--accent);
    font-size: 1.5em;
    font-weight: bold;
}

.flashcard .back {
    transform: rotateY(180deg);
    color: var(--text);
    font-size: 1.1em;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.05), rgba(124, 58, 237, 0.05));
    border-color: var(--accent);
}

.flashcard .hint {
    margin-top: 20px;
    font-size: 0.6em;
    color: var(--muted);
    font-weight: normal;
}

.flashcard-controls {
    display: flex;
    align-items: center;
    gap: 20px;
}

/* --- ACTION SHEET (CONTEXT MENU) --- */
.action-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -5px 25px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    padding-bottom: 20px;
    /* Safe area */
    animation: slideUp 0.3s ease-out;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
}

.action-sheet-header {
    padding: 15px;
    text-align: center;
    font-size: 0.9em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
}

.action-sheet-body {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    padding: 10px;
    gap: 10px;
}

.sheet-btn {
    background: none;
    border: none;
    color: var(--text);
    font-size: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 15px;
    border-radius: 12px;
    cursor: pointer;
}

.sheet-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--accent);
}

/* --- AUDIO PLAYER --- */
.audio-player {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--player-height);
    background: var(--player-bg);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
    z-index: 6000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 5px 20px;
    animation: slideUp 0.3s;
}

@media (max-width: 768px) {
    .audio-player {
        bottom: var(--nav-height);
    }
}

.player-info {
    text-align: center;
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 5px;
    color: var(--accent);
    font-weight: 600;
}

.player-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.player-btn {
    background: none;
    border: none;
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
    transition: transform 0.1s;
}

.player-btn:active {
    transform: scale(0.9);
}

.player-btn.play {
    font-size: 28px;
    color: var(--accent);
}

.player-btn.rate {
    font-size: 14px;
    font-weight: bold;
    color: var(--muted);
    width: 40px;
}

.player-btn.close {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    color: var(--muted);
}

.player-bar {
    height: 3px;
    background: var(--accent);
    width: 0%;
    /* Анимируется через JS */
    position: absolute;
    top: 0;
    left: 0;
    transition: width 0.2s linear;
}

/* --- PWA BANNER --- */
.install-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    background: var(--card);
    border: 1px solid var(--accent);
    border-radius: 12px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 8000;
    animation: slideUp 0.5s ease-out;
}

@media (max-width: 768px) {
    .install-banner {
        bottom: 80px;
        /* Выше навигации */
    }
}

.install-content {
    display: flex;
    align-items: center;
    gap: 15px;
}

.install-logo {
    width: 50px;
    height: 50px;
    border-radius: 10px;
}

.install-text {
    font-size: 14px;
}

.install-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* --- FONT SETTINGS (NEW) --- */
.font-family-switch {
    display: flex;
    gap: 10px;
    background: rgba(255, 255, 255, 0.05);
    padding: 5px;
    border-radius: 8px;
}

.radio-label {
    flex: 1;
    position: relative;
    cursor: pointer;
}

.radio-label input {
    position: absolute;
    opacity: 0;
}

.radio-label span {
    display: block;
    text-align: center;
    padding: 8px;
    border-radius: 6px;
    background: transparent;
    transition: background 0.2s;
    font-size: 14px;
}

.radio-label input:checked+span {
    background: var(--accent);
    color: white;
}

/* --- MAP ZOOM & LIST (NEW) --- */
.map-zoom-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.map-zoom-controls button {
    width: 36px;
    height: 36px;
    font-size: 18px;
    background: var(--card);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.region-list {
    list-style: none;
    margin: 0;
    padding: 0 10px 10px 10px;
}

.region-list li {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
}

.flag-placeholder {
    width: 24px;
    height: 16px;
    background: linear-gradient(180deg, white 33%, blue 33%, blue 66%, red 66%);
    display: inline-block;
    border: 1px solid #ccc;
    flex-shrink: 0;
}

/* --- FAV FOLDERS (NEW) --- */
.fav-folders {
    margin-bottom: 15px;
    animation: fadeIn 0.3s;
}

.fav-actions {
    display: flex;
    gap: 8px;
}

.folder-select {
    flex-grow: 1;
    padding: 8px;
    border-radius: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
}


.fav-folder-selector {
    margin-top: 10px;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-folder-select {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--accent);
    border-radius: 4px;
    padding: 2px 5px;
    font-size: 12px;
}

/* Общее */
.term {
    border-bottom: 1px dotted var(--accent);
    cursor: help;
    transition: all 0.2s;
}

.term:hover {
    color: var(--accent);
    border-bottom-style: solid;
}

.cross-link {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-bottom-color 0.2s;
}

.cross-link:hover {
    border-bottom-color: var(--accent);
}

mark {
    background-color: var(--highlight-bg);
    color: var(--highlight-text);
    padding: 2px 0;
    border-radius: 2px;
}

#tooltip {
    position: fixed;
    z-index: 9999;
    background: var(--card);
    border: 1px solid var(--accent);
    color: var(--text);
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    font-size: 14px;
    line-height: 1.5;
    max-width: 300px;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
}

#tooltip.show {
    opacity: 1;
    visibility: visible;
}

#tooltip b {
    color: var(--accent);
    display: block;
    margin-bottom: 4px;
    font-size: 15px;
}

/* Кнопки */
.btn {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 16px;
}

.btn:hover {
    filter: brightness(1.2);
    border-color: var(--muted);
}

.btn[aria-pressed="true"] {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-ghost {
    border-color: transparent;
    background: transparent;
    color: var(--muted);
    padding: 6px 10px;
    font-size: 18px;
}

.btn-ghost:hover {
    color: var(--accent);
    background: rgba(255, 255, 255, 0.05);
}

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

.btn-block {
    width: 100%;
    justify-content: center;
    gap: 10px;
    font-weight: 600;
    margin-bottom: 8px;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-lg {
    padding: 12px 24px;
    font-size: 18px;
}

.feedback-btn {
    margin-top: 10px;
    border-style: dashed;
}

/* --- КАРТОЧКА АВТОРА --- */
.author-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    margin-top: 10px;
    transition: border-color 0.2s;
}
.author-card:hover { border-color: var(--accent); }

.author-avatar {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    object-fit: cover;
    object-position: center top;
    flex-shrink: 0;
    border: 2px solid var(--accent);
}

.author-info {
    flex: 1;
    min-width: 0;
}

.author-name {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    line-height: 1.2;
}

.author-desc {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
    line-height: 1.3;
}

.author-tags {
    display: flex;
    gap: 4px;
    margin-top: 5px;
}

.author-tag {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 20px;
    background: rgba(79, 70, 229, 0.15);
    color: var(--accent);
    letter-spacing: 0.3px;
}

.author-tg {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 10px;
    border-radius: 10px;
    background: rgba(41, 182, 246, 0.12);
    color: #29b6f6;
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
    transition: background 0.2s;
}
.author-tg:hover { background: rgba(41, 182, 246, 0.25); }

.badge {
    background: var(--accent);
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 12px;
    min-width: 20px;
}

.btn-fav,
.btn-share,
.btn-note {
    font-size: 22px;
    color: var(--muted);
    transition: transform 0.2s, color 0.2s;
}

.btn-fav:hover,
.btn-share:hover,
.btn-note:hover {
    transform: scale(1.2);
    color: var(--fav-color);
}

.btn-share:hover {
    color: var(--accent);
}

.btn-note:hover {
    color: #fff176;
}

.btn-fav.active {
    color: var(--fav-color);
}

.btn-up,
.btn-return {
    position: fixed;
    cursor: pointer;
    z-index: 2000;
    transition: all 0.3s ease;
    opacity: 0;
    visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-up {
    bottom: 40px;
    right: 40px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: white;
    font-size: 30px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4);
}

.btn-return {
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--card);
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 10px 20px;
    border-radius: 30px;
    font-weight: 600;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

.btn-up.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.btn-return.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.btn-up:hover {
    background: var(--accent-hover);
    transform: scale(1.1);
}

.btn-return:hover {
    background: var(--accent);
    color: #fff;
}

#toast {
    visibility: hidden;
    min-width: 250px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 8px;
    padding: 16px;
    position: fixed;
    z-index: 3000;
    left: 50%;
    bottom: 30px;
    transform: translateX(-50%);
    font-size: 16px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.3s, bottom 0.3s;
}

#toast.show {
    visibility: visible;
    opacity: 1;
    bottom: 50px;
}

/* УВЕДОМЛЕНИЕ ОБ ОБНОВЛЕНИИ */
.toast-update {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: var(--card);
    border: 1px solid var(--accent);
    color: var(--text);
    padding: 15px 20px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 15px;
    animation: slideUp 0.3s ease-out;
}

.toast-update[hidden] {
    display: none !important;
}

.toast-update button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

.toast-update button:hover {
    opacity: 0.9;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Модальные окна */
dialog {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card);
    color: var(--text);
    box-shadow: 0 50px 100px rgba(0, 0, 0, 0.8);
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    cursor: pointer;
}

.large-dialog {
    width: 95%;
    max-width: 1200px;
    padding: 0;
}

.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.dialog-header h3 {
    margin: 0;
}

#dialogBody {
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
}

.dialog-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.02);
}

.toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

/* --- УЛУЧШЕННАЯ КАРТА РФ --- */
.map-wrapper {
    display: grid;
    grid-template-columns: 2.5fr 1fr;
    height: 70vh;
    min-height: 500px;
}

.map-container {
    padding: 20px;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    border-radius: 8px;
}

.map-instruction {
    margin-bottom: 15px;
    font-size: 20px;
    font-weight: bold;
    color: var(--text);
    text-align: center;
    margin-top: 0;
}

#russiaMap {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 5px 15px rgba(0, 0, 0, 0.2));
}

.region {
    stroke: var(--map-stroke);
    stroke-width: 2;
    transition: all 0.3s ease;
    cursor: pointer;
    opacity: 0.9;
}

#reg-fe {
    fill: var(--map-fe);
}

#reg-sib {
    fill: var(--map-sib);
}

#reg-ural {
    fill: var(--map-ural);
}

#reg-nw {
    fill: var(--map-nw);
}

#reg-cen {
    fill: var(--map-cen);
}

#reg-vol {
    fill: var(--map-vol);
}

#reg-south {
    fill: var(--map-south);
}

#reg-kav {
    fill: var(--map-kav);
}

.region:hover {
    opacity: 1;
    transform: scale(1.015);
    stroke: var(--map-hover-stroke);
    z-index: 10;
    filter: brightness(1.1);
}

.map-info-panel {
    padding: 25px;
    border-left: 1px solid var(--border);
    overflow-y: auto;
    background: var(--card);
}

#mapRegionTitle {
    margin-top: 0;
    color: var(--accent);
    font-size: 1.5em;
    border-bottom: 2px solid var(--border);
    padding-bottom: 12px;
    margin-bottom: 15px;
}

#mapRegionList {
    padding-left: 20px;
    color: var(--text);
    font-size: 16px;
    line-height: 1.7;
}

#mapRegionList li {
    margin-bottom: 8px;
}

/* Словарь */
.dictionary-content {
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px;
}

.dict-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
}

.dict-term {
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 5px;
    display: block;
}

/* Настройки шрифта */
.mini-dialog {
    width: 300px;
    padding: 20px;
    position: fixed;
    top: 70px;
    right: 20px;
    margin: 0;
    left: auto;
    transform-origin: top right;
}

.setting-group {
    margin-bottom: 15px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--muted);
}

.range-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 4px;
}

.range-controls button {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    font-weight: bold;
}

.range-controls button:hover {
    background: var(--accent);
    color: white;
}

.range-controls span {
    font-weight: 600;
    min-width: 40px;
    text-align: center;
}

/* --- ЗАДАНИЕ 23 --- */
.game23-body {
    padding: 30px;
}

.game23-task {
    font-size: 1.1em;
    color: var(--muted);
    margin-bottom: 10px;
}

.task23-question {
    font-size: 1.5em;
    margin: 0 0 20px 0;
    color: var(--accent);
}

.game23-hint {
    font-size: 0.9em;
    margin-bottom: 15px;
    font-weight: bold;
}

.task23-options {
    display: grid;
    gap: 10px;
    margin-bottom: 25px;
}

.task23-option {
    padding: 15px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.05em;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
}

.task23-option:hover {
    background: rgba(255, 255, 255, 0.02);
    border-color: var(--muted);
}

.task23-option.selected {
    border-color: var(--accent);
    background: rgba(37, 99, 235, 0.1);
    box-shadow: 0 0 15px rgba(37, 99, 235, 0.2);
}

.task23-option.selected::before {
    content: '✓';
    color: var(--accent);
    font-weight: bold;
}

.task23-option.correct {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
}

.task23-option.wrong {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    opacity: 0.7;
}

/* Игра 13 */
.game-dialog {
    width: 90%;
    max-width: 600px;
    padding: 0;
    border: none;
    overflow: hidden;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    color: white;
}

.game-header h3 {
    margin: 0;
    font-size: 18px;
}

#gameStartScreen,
#gamePlayScreen {
    padding: 30px;
    text-align: center;
}

.stats-preview {
    margin: 20px 0;
    font-size: 1.2em;
    color: var(--muted);
}

.btn-reset-highscore {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--muted);
    padding: 2px 6px;
    border-radius: 6px;
    transition: background 0.2s;
}
.btn-reset-highscore:hover {
    background: var(--surface2);
}

#highScore {
    color: var(--accent);
    font-weight: bold;
}

.game-score {
    font-size: 1.1em;
    color: var(--muted);
    margin-bottom: 20px;
    text-align: right;
}

#currentScore {
    color: var(--accent);
    font-weight: bold;
}

.question-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 30px 20px;
    margin-bottom: 30px;
    font-size: 1.2em;
    font-weight: 500;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2);
}

.answers-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.ans-btn {
    padding: 15px;
    border-radius: 10px;
    border: 2px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 1em;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
}

.ans-btn:hover {
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.02);
}

.ans-btn.correct {
    background: #22c55e;
    border-color: #22c55e;
    color: #fff;
    transform: scale(1.05);
}

.ans-btn.wrong {
    background: #ef4444;
    border-color: #ef4444;
    color: #fff;
    opacity: 0.7;
    animation: shake 0.4s;
}

.game-feedback {
    margin-top: 20px;
    height: 24px;
    font-weight: bold;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

@media (max-width: 600px) {
    .answers-grid {
        grid-template-columns: 1fr;
    }

    .mini-dialog {
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        right: auto;
        width: 90%;
    }

    .dictionary-content {
        grid-template-columns: 1fr;
    }

    .map-wrapper {
        grid-template-columns: 1fr;
        height: auto;
        display: flex;
        flex-direction: column;
    }

    .map-container {
        height: 350px;
    }

    .map-info-panel {
        height: 300px;
        border-left: none;
        border-top: 1px solid var(--border);
    }

    #russiaMap text {
        display: none;
    }
}

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

    .sidebar {
        position: fixed;
        top: 70px;
        left: 0;
        width: 100%;
        height: calc(100vh - 70px - var(--nav-height));
        background: var(--bg);
        z-index: 4000;
        padding: 20px;
        padding-bottom: 30px;
        transform: translateX(-100%);
        max-height: none;
        overflow-y: auto; /* скролл внутри сайдбара */
        -webkit-overflow-scrolling: touch;
    }

    .sidebar.visible {
        transform: translateX(0);
    }

    .btn-up {
        width: 50px;
        height: 50px;
        bottom: 80px;
        right: 20px;
        font-size: 24px;
    }

    .site-header .brand h1 {
        display: none;
    }

    .logo {
        height: 35px;
    }

    .btn-return {
        bottom: 120px;
    }

    .mobile-nav {
        display: flex;
    }

    .header-tools {
        display: none;
    }

    /* Карта — вертикально */
    .map-wrapper {
        grid-template-columns: 1fr;
    }
    .map-container {
        height: 300px;
    }
    .map-info-panel {
        height: auto;
        border-left: none;
        border-top: 1px solid var(--border);
        padding-top: 12px;
    }

    /* Сетка ответов — одна колонка */
    .answers-grid {
        grid-template-columns: 1fr;
    }

    /* Словарь — одна колонка */
    .dictionary-content {
        grid-template-columns: 1fr;
    }

    /* mini-dialog — по центру экрана */
    .mini-dialog {
        position: fixed;
        top: 50% !important;
        left: 50% !important;
        right: auto !important;
        transform: translate(-50%, -50%) !important;
        width: calc(100vw - 32px) !important;
        max-width: 420px;
        margin: 0;
    }

    /* Задание 23 — меньше padding */
    .game23-body {
        padding: 15px;
    }

    /* Вопрос 23 — перенос длинных слов */
    .task23-question {
        word-break: break-word;
        overflow-wrap: break-word;
        font-size: 1.2em;
    }

    /* Диалоги — ограничить высоту */
    dialog {
        max-height: 95vh;
        overflow-y: auto;
    }
    .large-dialog {
        max-height: 95vh;
        overflow-y: auto;
    }

    /* Флэш-карточки */
    .flashcard-container {
        height: 220px;
    }

    /* Поиск в сайдбаре скрыт на мобильном (есть отдельная вкладка) */
    .sidebar .search-container {
        display: none;
    }

    /* На мобильном sidebar-inner — просто flex-контейнер без sticky */
    .sidebar-inner {
        position: static;
        top: auto;
        min-height: 100%;
    }
}

/* --- MOBILE TOOLS BOTTOM SHEET --- */
.mobile-sheet {
    position: fixed;
    bottom: var(--nav-height);
    left: 0;
    right: 0;
    background: var(--card);
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    z-index: 4700; /* Выше поискового оверлея (4500) и сайдбара (4000) */
    box-shadow: 0 -5px 30px rgba(0,0,0,0.4);
    padding: 16px;
    animation: slideUp 0.25s ease;
}

.mobile-sheet[hidden] {
    display: none !important;
}

.mobile-sheet-header {
    font-weight: 700;
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--text);
    text-align: center;
}

.mobile-sheet-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.sheet-tool-btn {
    background: var(--border);
    border: none;
    border-radius: 12px;
    padding: 12px 10px;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    text-align: left;
    font-weight: 500;
}

.sheet-tool-btn:active {
    background: var(--accent);
    color: white;
}

/* --- MOBILE SEARCH OVERLAY --- */
.mobile-search-overlay {
    position: fixed;
    top: 70px;
    left: 0;
    right: 0;
    bottom: var(--nav-height);
    background: var(--bg);
    z-index: 4500;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 12px;
}

.mobile-search-overlay[hidden] { display: none; }

.mobile-search-header {
    display: flex;
    gap: 10px;
    align-items: center;
}

.mobile-search-header input {
    flex: 1;
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 16px;
}

.mobile-search-header input:focus {
    outline: none;
    border-color: var(--accent);
}

.mobile-search-results {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mobile-search-result-item {
    padding: 14px 16px;
    background: var(--card);
    border-radius: 12px;
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 14px;
}

.mobile-search-result-item strong {
    display: block;
    color: var(--accent);
    font-size: 15px;
    margin-bottom: 4px;
}

.mobile-search-result-item:active {
    background: var(--border);
}

@media print {

    .header-tools,
    .sidebar,
    .btn-up,
    .btn-return,
    #scrollProgress,
    .meta,
    .toggle,
    .game-dialog,
    #fontSettingsDialog,
    #dictionaryDialog,
    .mobile-nav,
    #mapDialog,
    #game23Dialog,
    #flashcardsDialog,
    #shareDialog,
    .toast-update,
    .action-sheet,
    .audio-player,
    .install-banner {
        display: none !important;
    }

    body {
        padding-top: 0;
        padding-bottom: 0;
        background: white;
        color: black;
        font-size: 12pt;
    }

    .layout {
        display: block;
        padding: 0;
        margin: 0;
    }

    .site-header {
        position: static;
        border-bottom: 2px solid black;
        box-shadow: none;
        height: auto;
        padding: 10px 0;
    }

    .logo-container {
        position: static;
        transform: none;
        display: inline-block;
    }

    .card {
        border: none;
        border-bottom: 1px solid #ccc;
        box-shadow: none;
        background: white;
        color: black;
        break-inside: avoid;
        padding: 10px 0;
        animation: none !important;
        opacity: 1 !important;
    }

    .card .title {
        color: black;
        text-decoration: underline;
    }

    details.explain {
        display: block !important;
        border: none;
    }

    details.explain[hidden] {
        display: none !important;
    }

    .explain-body {
        background: none;
        border: 1px solid #eee;
        padding: 10px;
        color: #333;
    }

    :root {
        --bg: #fff;
        --text: #000;
        --card: #fff;
    }
}