/* ============================================
   ЛОКАЛЬНЫЕ ШРИФТЫ
============================================ */
@font-face {
    font-family: 'Caveat';
    src: url('../fonts/HQYSaversText.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Caveat';
    src: url('../fonts/HQYSaversText.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Special Elite';
    src: url('../fonts/HQYSaversText.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* ============================================
   ПЕРЕМЕННЫЕ — СВЕТЛАЯ ТЕМА
============================================ */
:root {
    --paper-color: #f5f0e6;
    --paper-light: #faf8f3;
    --paper-lines: #c8d4e8;
    --margin-line: rgba(196, 69, 54, 0.35);

    --ink-color: #35355e;
    --ink-light: #4a4a5a;

    --wood-dark: #3d3020;
    --wood-mid: #4a3d2a;
    --wood-light: #5c4a2a;

    --accent-red: #c44536;
    --accent-gold: #d4a03c;

    --sticky-yellow: #fff9c4;

    --cream: #f5f0e6;
    --cream-dark: #e8e0d0;
    --cream-hover: #ebe5d8;

    --line-height: 32px;
    --paper-padding-top: 80px;
    --paper-padding-left: 100px;
    --margin-position: 70px;
    --paper-padding-right: 50px;

    --bg-gradient-top: #5c4a2a;
    --bg-gradient-mid: #3d3020;
    --bg-gradient-bot: #2d2418;
    --bg-stripe-color: rgba(0, 0, 0, 0.02);

    --panel-text: rgba(245, 240, 230, 1);
    --panel-text-dim: rgba(245, 240, 230, 0.5);
    --panel-text-faint: rgba(245, 240, 230, 0.35);
    --panel-border: rgba(245, 240, 230, 0.1);
    --panel-border-strong: rgba(245, 240, 230, 0.15);
    --panel-item-bg: rgba(245, 240, 230, 0.06);
    --panel-hover-bg: rgba(245, 240, 230, 0.1);
    --panel-btn-bg: rgba(245, 240, 230, 0.1);
    --panel-btn-hover: rgba(245, 240, 230, 0.2);
    --panel-scrollbar: rgba(245, 240, 230, 0.15);

    --modal-overlay: rgba(45, 36, 24, 0.92);
}

/* ============================================
   ПЕРЕМЕННЫЕ — ТЁМНАЯ ТЕМА
============================================ */
[data-theme="dark"] {
    --paper-color: #2a2a3e;
    --paper-light: #32324a;
    --paper-lines: rgba(100, 149, 237, 0.08);
    --margin-line: rgba(220, 80, 80, 0.12);

    --ink-color: #e0d8cc;
    --ink-light: #8a8298;

    --wood-dark: #1a1a2e;
    --wood-mid: #22223a;
    --wood-light: #2a2a4a;

    --accent-red: #e07060;
    --accent-gold: #7c6fa0;

    --sticky-yellow: #3a3a55;

    --cream: #2a2a3e;
    --cream-dark: #3a3a55;
    --cream-hover: #32324a;

    --bg-gradient-top: #1a1a2e;
    --bg-gradient-mid: #16162a;
    --bg-gradient-bot: #101024;
    --bg-stripe-color: rgba(255, 255, 255, 0.01);

    --panel-text: rgba(224, 216, 204, 1);
    --panel-text-dim: rgba(224, 216, 204, 0.5);
    --panel-text-faint: rgba(224, 216, 204, 0.3);
    --panel-border: rgba(224, 216, 204, 0.08);
    --panel-border-strong: rgba(224, 216, 204, 0.12);
    --panel-item-bg: rgba(224, 216, 204, 0.05);
    --panel-hover-bg: rgba(224, 216, 204, 0.08);
    --panel-btn-bg: rgba(224, 216, 204, 0.08);
    --panel-btn-hover: rgba(224, 216, 204, 0.15);
    --panel-scrollbar: rgba(224, 216, 204, 0.1);

    --modal-overlay: rgba(10, 10, 20, 0.92);
}

/* ============================================
   СБРОС
============================================ */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ============================================
   BODY И ФОН
============================================ */
body {
    min-height: 100vh;
    font-family: 'Special Elite', monospace;
    overflow-x: hidden;
    position: relative;
    /* УБРАТЬ ВСЕ ФОНЫ */
}

#bgCanvas {
    position: fixed;
    inset: 0;
    z-index: -1;
    transition: opacity 0.4s ease;
}

/* ============================================
   ОСНОВНОЙ КОНТЕЙНЕР
============================================ */
.app-container {
    position: relative;
    z-index: 1;
    display: flex; /* <-- УЖЕ ЕСТЬ */
    justify-content: center; /* <-- УЖЕ ЕСТЬ */
    align-items: flex-start; /* <-- УЖЕ ЕСТЬ */
    padding: 30px 40px; /* <-- ИЗМЕНИТЬ НА 30px 40px */
    min-height: 100vh;
    box-sizing: border-box; /* <-- ДОБАВИТЬ */
}

/* ============================================
   ЛИСТ БУМАГИ
============================================ */
.paper-sheet {
    position: relative;
    width: 100%;
    max-width: 750px;
    min-height: calc(100vh - 60px); /* <-- УБЕРИ, не нужно, flex сам справится */
    background-color: var(--paper-color);
    border-radius: 6px;
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.1),
        0 8px 16px rgba(0, 0, 0, 0.1),
        0 16px 32px rgba(0, 0, 0, 0.15),
        inset 0 0 80px rgba(139, 105, 20, 0.03);
    overflow: hidden;
    flex-grow: 1; /* <-- ДОБАВИТЬ, чтобы занимал доступную высоту */
}

.paper-lines {
    position: absolute;
    top: var(--paper-padding-top);
    left: var(--paper-padding-left);
    right: 40px;
    bottom: 40px;
    background: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent calc(var(--line-height) - 1.5px),
        var(--paper-lines) calc(var(--line-height) - 1.5px),
        var(--paper-lines) var(--line-height)
    );
    pointer-events: none;
    transition: all 0.4s ease;
    z-index: 1;
    filter: blur(0.5px);
}

.margin-line {
    position: absolute;
    top: 40px;
    bottom: 40px;
    left: var(--margin-position);
    width: 2.5px;
    background: var(--margin-line);
    pointer-events: none;
    transition: all 0.4s ease;
    z-index: 1;
    filter: blur(0.5px);
}

.paper-holes {
    position: absolute;
    left: 25px;
    top: 0;
    bottom: 0;
    width: 26px;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    align-items: center;
    padding: 40px 0;
    pointer-events: none;
    z-index: 2;
    box-sizing: border-box;
}

.paper-hole {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--wood-dark);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
}

/* ============================================
   ЗВЁЗДОЧКИ
============================================ */
.star-zone {
    position: absolute;
    width: 45px;
    height: 45px;
    cursor: pointer;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.star-zone:hover { transform: scale(1.1); }

.star-zone.top-left     { top: 45px;    left: 15px;  }
.star-zone.bottom-left  { bottom: 45px; left: 15px;  }
.star-zone.bottom-right { bottom: 45px; right: 15px; }

.star-zone .star-icon {
    width: 28px;
    height: 28px;
    opacity: 0.3; /* было 0.15 */
    transition: all 0.3s ease;
}

.star-zone:hover .star-icon {
    opacity: 0.6; /* было 0.4 */
}

.star-zone .star-icon path {
    fill: none;
    stroke: var(--accent-gold);
    stroke-width: 2.5; /* было 1.5 */
}

.star-zone.active .star-icon { opacity: 1; }

.star-zone.active .star-icon path {
    fill: var(--accent-gold);
    stroke: var(--accent-gold);
    stroke-dasharray: 100;
    animation: drawStar 0.6s ease forwards;
}

@keyframes drawStar {
    0%   { stroke-dashoffset: 100; fill: transparent; }
    60%  { stroke-dashoffset: 0;   fill: transparent; }
    100% { stroke-dashoffset: 0;   fill: var(--accent-gold); }
}

/* ============================================
   КОНТЕНТ ЛИСТА
============================================ */
.paper-content-wrapper {
    position: relative;
    padding: var(--paper-padding-top) var(--paper-padding-right) 80px var(--paper-padding-left);
    min-height: 800px;
    z-index: 3;
}

.story-header {
    font-size: 18px;
    line-height: var(--line-height);
    color: var(--ink-light);
    opacity: 0.6;
    margin-bottom: 0;
    pointer-events: none;
    user-select: none;
}

.story-input {
    font-size: 18px;
    line-height: var(--line-height);
    color: var(--ink-color);
    white-space: pre-wrap;
    word-wrap: break-word;
    outline: none;
    min-height: calc(var(--line-height) * 3);
    cursor: text;
    font-family: 'Special Elite', monospace;
}

.story-input:focus { outline: none; }

.story-input:empty::before {
    content: 'напишите тему или нажмите Enter...';
    color: var(--ink-light);
    opacity: 0.35;
    font-style: italic;
}

.no-ideas-btn {
    display: block;
    margin-top: 12px;
    font-family: 'Caveat', cursive;
    font-size: 1.1rem;
    color: var(--ink-light);
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.35;
    transition: opacity 0.2s;
    text-decoration: underline;
    text-decoration-style: dashed;
    text-underline-offset: 3px;
}

.no-ideas-btn:hover { opacity: 0.7; }
.no-ideas-btn.hidden { display: none; }

/* Курсор печати */
.typing-cursor {
    display: inline;
    animation: cursorBlink 0.7s infinite;
}

@keyframes cursorBlink {
    0%, 50%  { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Устаревший текст */
.outdated-text {
    color: var(--ink-light);
    opacity: 0.7;
    transition: color 0.5s ease, opacity 0.5s ease;
}

/* Анимация исчезновения */
.fading-out-text {
    display: inline;
    animation: fadeOutAndUp 0.4s ease-out forwards;
}

@keyframes fadeOutAndUp {
    from { opacity: 1; }
    to   { opacity: 0; transform: translateY(-8px); }
}

/* ============================================
   ДАТА НА ЛИСТЕ
============================================ */
.paper-date {
    position: absolute;
    top: 45px;
    right: var(--paper-padding-right);
    font-family: 'Caveat', cursive;
    font-size: 14px;
    color: var(--ink-light);
    opacity: 0.5;
    z-index: 4;
}

/* ============================================
   КНОПКИ УПРАВЛЕНИЯ — ДЕСКТОП
============================================ */
.controls {
    position: fixed;
    bottom: 25px;
    right: 25px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 100;
}

.control-btn {
    width: 46px;
    height: 46px;
    background: var(--cream);
    border: 2px solid var(--cream-dark);
    border-radius: 12px;
    cursor: pointer;
    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.5);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
}

.control-btn:hover {
    transform: translateY(-2px);
    background: var(--cream-hover);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.13);
}

.control-btn:active {
    transform: translateY(0);
}

.control-btn svg {
    width: 22px;
    height: 22px;
    display: block;
    flex-shrink: 0;
    pointer-events: none;
}

/* Убиваем старый текст если где-то остался */
.control-btn-text {
    display: none !important;
}

/* Поток */
.control-btn.stream-btn svg {
    stroke: var(--accent-gold);
}

/* Стоп */
.control-btn.stop-btn {
    background: #f5e8e6;
    border-color: #e8d8d4;
}

[data-theme="dark"] .control-btn.stop-btn {
    background: #3e2a2a;
    border-color: #4a3535;
}

.control-btn.stop-btn svg {
    fill: var(--accent-red);
    stroke: none;
}

/* Озвучка активна */
.control-btn.speak-btn.speaking {
    background: var(--accent-gold);
    border-color: var(--accent-gold);
    animation: pulse 1.2s ease-in-out infinite;
}

.control-btn.speak-btn.speaking svg {
    stroke: white;
    fill: white;
}

.control-btn:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}

/* Тултип при наведении */
.control-btn::before {
    content: attr(title);
    position: absolute;
    right: 56px;
    background: var(--ink-color);
    color: var(--cream);
    font-family: 'Caveat', cursive;
    font-size: 0.95rem;
    padding: 5px 12px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 101;
}

.control-btn:hover::before {
    opacity: 1;
}

/* ============================================
   НИЖНЕЕ МЕНЮ — только мобильные
============================================ */
.bottom-nav {
    display: none;
}

/* ============================================
   БОКОВАЯ ПАНЕЛЬ
============================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    height: 100%;
    background: linear-gradient(
        180deg,
        var(--wood-mid) 0%,
        var(--wood-dark) 50%,
        var(--bg-gradient-bot) 100%
    );
    box-shadow: 5px 0 30px rgba(0, 0, 0, 0.5);
    transition: transform 0.4s ease;
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateX(-100%);
}

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

@media (min-width: 769px) {
    .sidebar:hover { transform: translateX(0); }
}

/* Стрелка сайдбара */
.sidebar-arrow {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 65px;
    background: var(--panel-btn-bg);
    border-radius: 0 10px 10px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 201;
    transition: all 0.3s ease;
}

.sidebar-arrow:hover {
    background: var(--panel-btn-hover);
    width: 26px;
}

.sidebar-arrow::after {
    content: '';
    border: solid var(--panel-text-dim);
    border-width: 0 2px 2px 0;
    padding: 5px;
    transform: rotate(-45deg);
    margin-left: -4px;
}

/* Крестик закрытия */
.sidebar-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 32px;
    height: 32px;
    background: var(--panel-btn-bg);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.sidebar.open .sidebar-close {
    opacity: 0.6;
    pointer-events: all;
}

.sidebar-close:hover {
    opacity: 1 !important;
    background: var(--panel-btn-hover);
}

.sidebar-close svg {
    width: 18px;
    height: 18px;
    stroke: var(--panel-text);
    stroke-width: 2;
    fill: none;
}

/* Оверлей сайдбара */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.sidebar-header {
    padding: 30px 20px 20px;
    border-bottom: 1px solid var(--panel-border);
}

.sidebar-title {
    font-family: 'Caveat', cursive;
    font-size: 1.6rem;
    color: var(--accent-gold);
}

.sidebar-tabs {
    display: flex;
    padding: 15px 20px;
    gap: 10px;
}

.sidebar-tab {
    flex: 1;
    padding: 10px 12px;
    font-family: 'Special Elite', monospace;
    font-size: 0.75rem;
    color: var(--panel-text-dim);
    background: transparent;
    border: 1px solid var(--panel-border-strong);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sidebar-tab:hover {
    color: var(--panel-text);
    border-color: var(--panel-text-dim);
}

.sidebar-tab.active {
    color: var(--wood-dark);
    background: var(--accent-gold);
    border-color: var(--accent-gold);
}

[data-theme="dark"] .sidebar-tab.active { color: #e0d8cc; }

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.sidebar-content::-webkit-scrollbar { width: 5px; }
.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--panel-scrollbar);
    border-radius: 3px;
}

/* ============================================
   КАРТОЧКИ АРХИВА
============================================ */
.archive-card {
    background: var(--cream);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--cream-dark);
}

.archive-card:hover {
    transform: translateX(5px);
    background: var(--paper-light);
}

.archive-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.archive-card-star {
    width: 14px;
    height: 14px;
    fill: var(--accent-gold);
    flex-shrink: 0;
}

.archive-card-title {
    font-family: 'Caveat', cursive;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--ink-color);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.archive-card-preview {
    font-size: 0.8rem;
    color: var(--ink-light);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.archive-card-date {
    font-size: 0.65rem;
    color: var(--ink-light);
    opacity: 0.5;
    margin-top: 8px;
    display: block;
}

.archive-card-delete {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 22px;
    height: 22px;
    background: var(--cream-dark);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.archive-card:hover .archive-card-delete { opacity: 0.6; }

.archive-card-delete:hover {
    opacity: 1 !important;
    background: #f0e0dc;
}

[data-theme="dark"] .archive-card-delete:hover { background: #4a3535; }

.archive-card-delete svg {
    width: 12px;
    height: 12px;
    stroke: var(--accent-red);
    stroke-width: 2.5;
    fill: none;
}

.archive-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--panel-text-faint);
    font-family: 'Caveat', cursive;
    font-size: 1.15rem;
}

/* ============================================
   ПАНЕЛЬ НАСТРОЕК
============================================ */
.settings-overlay {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    z-index: 299;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.settings-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    max-width: 100vw;
    background: linear-gradient(
        180deg,
        var(--wood-mid) 0%,
        var(--wood-dark) 50%,
        var(--bg-gradient-bot) 100%
    );
    z-index: 300;
    transform: translateX(100%);
    transition: transform 0.35s ease;
    display: flex;
    flex-direction: column;
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.5);
}

.settings-panel.open { transform: translateX(0); }

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

.settings-title {
    font-family: 'Caveat', cursive;
    font-size: 1.6rem;
    font-weight: normal;
    color: var(--accent-gold);
}

.settings-close {
    width: 32px;
    height: 32px;
    background: var(--panel-btn-bg);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
    transition: all 0.2s;
    border-radius: 8px;
}

.settings-close:hover {
    opacity: 1;
    background: var(--panel-btn-hover);
}

.settings-close svg {
    width: 18px;
    height: 18px;
    stroke: var(--panel-text);
    stroke-width: 2;
    fill: none;
}

.settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px 30px;
}

.settings-content::-webkit-scrollbar { width: 5px; }
.settings-content::-webkit-scrollbar-thumb {
    background: var(--panel-scrollbar);
    border-radius: 3px;
}

.settings-section { margin-bottom: 28px; }

.settings-section-title {
    font-family: 'Special Elite', monospace;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--panel-text-dim);
    margin-bottom: 12px;
    opacity: 0.7;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    background: var(--panel-item-bg);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    margin-bottom: 8px;
}

.settings-item-vertical {
    flex-direction: column;
    align-items: stretch;
}

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

.settings-label {
    font-family: 'Caveat', cursive;
    font-size: 1.1rem;
    color: var(--panel-text);
    display: block;
    margin-bottom: 2px;
}

.settings-hint {
    font-family: 'Special Elite', monospace;
    font-size: 0.68rem;
    color: var(--panel-text-faint);
    line-height: 1.5;
}

/* Toggle */
.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--panel-border-strong);
    border-radius: 24px;
    transition: background 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: var(--panel-text);
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.toggle-switch input:checked + .toggle-slider { background: var(--accent-gold); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

/* Слайдеры */
.settings-slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.slider-label-left,
.slider-label-right {
    font-family: 'Caveat', cursive;
    font-size: 0.85rem;
    color: var(--panel-text-faint);
    white-space: nowrap;
    min-width: 60px;
}

.slider-label-left  { text-align: right; }
.slider-label-right { text-align: left;  }

.settings-range {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--panel-border-strong);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.settings-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-gold);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
    transition: transform 0.15s;
}

.settings-range::-webkit-slider-thumb:hover { transform: scale(1.15); }

.settings-range::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-gold);
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.settings-range-value {
    font-family: 'Special Elite', monospace;
    font-size: 0.78rem;
    color: var(--accent-gold);
    font-weight: bold;
    min-width: 34px;
    text-align: center;
}

.settings-reset-btn {
    width: 100%;
    padding: 12px;
    background: transparent;
    border: 1px dashed var(--panel-text-faint);
    color: var(--panel-text-dim);
    font-family: 'Caveat', cursive;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s;
    margin-top: 8px;
}

.settings-reset-btn:hover {
    color: var(--accent-red);
    border-color: var(--accent-red);
}

/* ============================================
   КОНТЕКСТНОЕ МЕНЮ
============================================ */
.context-menu {
    position: fixed;
    z-index: 600;
    background: linear-gradient(180deg, var(--wood-mid) 0%, var(--wood-dark) 100%);
    border: 1px solid var(--panel-border-strong);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    padding: 6px 0;
    min-width: 200px;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.15s, transform 0.15s;
    pointer-events: none;
}

.context-menu.visible {
    opacity: 1;
    transform: scale(1);
    pointer-events: all;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    font-family: 'Caveat', cursive;
    font-size: 1.05rem;
    color: var(--panel-text);
    cursor: pointer;
    transition: background 0.15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.context-menu-item:hover { background: var(--panel-hover-bg); }

.context-menu-item svg {
    width: 16px;
    height: 16px;
    stroke: var(--accent-gold);
    stroke-width: 2;
    fill: none;
    flex-shrink: 0;
}

.context-menu-divider {
    height: 1px;
    background: var(--panel-border);
    margin: 4px 0;
}

/* ============================================
   МОДАЛКИ
============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    z-index: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-box {
    background: var(--paper-color);
    width: 90%;
    max-width: 460px;
    border-radius: 4px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    transform: translateY(20px);
    transition: transform 0.3s;
}

.modal-overlay.active .modal-box { transform: translateY(0); }

.modal-header {
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--cream-dark);
}

.modal-title {
    font-family: 'Caveat', cursive;
    font-size: 1.5rem;
    color: var(--ink-color);
}

.modal-body { padding: 20px 24px; }

.modal-input {
    width: 100%;
    padding: 12px 16px;
    font-family: 'Special Elite', monospace;
    font-size: 0.95rem;
    color: var(--ink-color);
    background: var(--paper-light);
    border: 1px solid var(--cream-dark);
    border-radius: 6px;
    outline: none;
    resize: vertical;
    min-height: 60px;
    transition: border-color 0.2s;
}

.modal-input:focus { border-color: var(--accent-gold); }

.modal-footer {
    display: flex;
    gap: 10px;
    padding: 16px 24px 24px;
    justify-content: flex-end;
}

.modal-btn {
    padding: 10px 24px;
    font-family: 'Caveat', cursive;
    font-size: 1.15rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

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

.modal-btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.modal-btn-secondary {
    background: var(--cream-dark);
    color: var(--ink-color);
}

.modal-btn-secondary:hover { background: var(--cream-hover); }

/* ============================================
   ПРЕВЬЮ ЦИТАТЫ / ЭКСПОРТА
============================================ */
.quote-preview-container {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.quote-canvas-wrap {
    border: 1px solid var(--cream-dark);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.quote-canvas-wrap canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

.quote-nav {
    display: flex;
    align-items: center;
    gap: 12px;
}

.quote-nav-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--cream-dark);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.quote-nav-btn:hover {
    background: var(--cream-hover);
    transform: scale(1.08);
}

.quote-nav-btn svg {
    width: 16px;
    height: 16px;
    stroke: var(--ink-color);
    stroke-width: 2;
    fill: none;
}

.quote-page-indicator {
    font-family: 'Caveat', cursive;
    font-size: 1rem;
    color: var(--ink-light);
}

/* ============================================
   СТИКЕРЫ
============================================ */
.sticky-note {
    position: fixed;
    background: var(--sticky-yellow);
    padding: 18px 22px;
    box-shadow:
        3px 3px 12px rgba(0, 0, 0, 0.12),
        inset 0 -2px 4px rgba(0, 0, 0, 0.03);
    font-family: 'Caveat', cursive;
    font-size: 1.05rem;
    color: var(--ink-color);
    line-height: 1.5;
    max-width: 250px;
    z-index: 400;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
    border-radius: 2px;
}

.sticky-note.visible {
    opacity: 1;
    pointer-events: auto;
}

.sticky-note::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 14px;
    background: rgba(180, 160, 100, 0.3);
    border-radius: 2px;
}

.sticky-note .close-sticky {
    position: absolute;
    top: 2px;
    right: 8px;
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--ink-light);
    cursor: pointer;
    opacity: 0.35;
    line-height: 1;
}

.sticky-note .close-sticky:hover { opacity: 0.7; }

.sticky-arrow {
    display: inline-block;
    animation: bounce 1s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-4px); }
}

.sticky-note.sticky-1 { top: 100px; left: 50px; transform: rotate(-2deg); }
.sticky-note.sticky-2 { top: 100px; right: 120px; left: auto; transform: rotate(2deg); }
.sticky-note.sticky-3 { bottom: 200px; left: 50px; transform: rotate(-1deg); }

/* ============================================
   ПРИВЕТСТВЕННЫЙ ЭКРАН
============================================ */
.welcome-screen {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.welcome-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.welcome-paper {
    background: var(--paper-color);
    width: 90%;
    max-width: 520px;
    padding: 42px;
    border-radius: 3px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    position: relative;
    transform: rotate(-1deg);
}

.welcome-title {
    font-family: 'Caveat', cursive;
    font-size: 2.2rem;
    color: var(--ink-color);
    margin-bottom: 22px;
    text-align: center;
}

.welcome-text {
    font-family: 'Caveat', cursive;
    font-size: 1.25rem;
    color: var(--ink-color);
    line-height: 1.7;
    margin-bottom: 12px;
}

.welcome-text span {
    color: var(--accent-gold);
    font-weight: 600;
}

/* Правильно — стилизуем обе кнопки в welcome-paper */
.welcome-paper button {
    display: block;
    width: 100%;
    margin: 32px auto 0;
    padding: 14px 50px;
    font-family: 'Caveat', cursive;
    font-size: 1.5rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

/* Стили для основной кнопки "Начать" */
#startBtn {
    background: var(--ink-color);
    border: 2px solid var(--ink-color);
    color: var(--cream);
}
#startBtn:hover {
    background: var(--accent-gold);
    border-color: var(--accent-gold);
}

/* Стили для кнопки "Покажи что тут есть" (уже есть .tour-start-btn) */
.tour-start-btn {
    margin-top: 10px;
    padding: 12px 20px;
    background: transparent;
    border: 2px solid var(--accent-gold);
    color: var(--accent-gold);
    font-size: 1.1rem;
}
.tour-start-btn:hover {
    background: var(--accent-gold);
    color: #fff;
}

/* ============================================
   УВЕДОМЛЕНИЯ
============================================ */
.notification {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(30px);
    padding: 12px 26px;
    background: var(--ink-color);
    color: var(--cream);
    font-family: 'Caveat', cursive;
    font-size: 1.1rem;
    border-radius: 8px;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
    pointer-events: none;
    white-space: nowrap;
}

.notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================
   POPUP "ПРОДОЛЖИТЬ"
============================================ */
.rewrite-popup {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 160;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.rewrite-popup.visible {
    opacity: 1;
    pointer-events: all;
    transform: translateX(-50%) translateY(0);
}

.rewrite-popup-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 28px;
    font-family: 'Caveat', cursive;
    font-size: 19px;
    color: var(--ink-color);
    background: var(--cream);
    border: 2px solid var(--cream-dark);
    border-radius: 50px;
    cursor: pointer;
    box-shadow:
        0 6px 24px rgba(61, 48, 32, 0.18),
        0 2px 8px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.7);
    transition: all 0.2s ease;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
}

.rewrite-popup-btn:hover {
    background: var(--cream-hover);
    border-color: var(--accent-gold);
    box-shadow:
        0 8px 28px rgba(61, 48, 32, 0.22),
        0 4px 12px rgba(0, 0, 0, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.7);
    transform: translateY(-2px);
}

.rewrite-popup-btn:active { transform: translateY(0); }

.rewrite-popup-btn svg {
    width: 22px;
    height: 22px;
    stroke: var(--accent-gold);
    stroke-width: 2.5;
    fill: none;
    flex-shrink: 0;
}

[data-theme="dark"] .rewrite-popup-btn {
    background: var(--cream);
    border-color: var(--cream-dark);
    color: var(--ink-color);
}

[data-theme="dark"] .rewrite-popup-btn:hover {
    border-color: var(--accent-gold);
}

/* ============================================
   АНИМАЦИИ ГЕНЕРАЦИИ
============================================ */

/* Ожидание — inline после текста */
.typing-wait {
    display: inline;
    font-family: 'Caveat', cursive;
    color: var(--ink-light);
    pointer-events: none;
    font-style: italic;
    opacity: 0;
    animation: fadeInWait 0.4s ease forwards;
}

@keyframes fadeInWait {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 0.7; transform: translateY(0); }
}

.typing-wait-title {
    display: inline;
    font-size: 1.1rem;
    font-weight: 600;
    font-style: italic;
}

.typing-wait-phrase {
    display: inline;
    font-size: 1.05rem;
    font-style: italic;
    transition: opacity 0.5s ease;
}

.typing-wait-phrase.changing {
    opacity: 0;
    transform: translateY(-3px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.typing-wait-phrase.arriving {
    opacity: 0;
    transform: translateY(3px);
}

.typing-wait-phrase.arrived {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Курсор */
.typing-cursor {
    display: inline;
    animation: cursorBlink 0.7s infinite;
    color: var(--ink-light);
    opacity: 0.6;
}

@keyframes cursorBlink {
    0%, 49%  { opacity: 0.6; }
    50%, 100% { opacity: 0; }
}

/* Устаревший текст */
.outdated-text {
    color: var(--ink-light);
    opacity: 0.5;
    transition: color 0.5s ease, opacity 0.5s ease;
}

/* Исчезновение текста при обрезке */
.fading-out-text {
    display: inline;
    animation: fadeOutAndUp 0.4s ease-out forwards;
}

@keyframes fadeOutAndUp {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(-8px); }
}

/* Проявление нового текста */
.story-input.text-reveal {
    animation: none; /* убираем на весь input */
}

.generated-text-node {
    animation: revealGenerated 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes revealGenerated {
    from {
        opacity: 0;
        filter: blur(4px);
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        filter: blur(0);
        transform: translateY(0);
    }
}

/* Появление заготовки "нет идей" */
.story-input .prompt-reveal {
    display: inline;
    animation: promptAppear 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes promptAppear {
    from {
        opacity: 0;
        letter-spacing: 0.15em;
        filter: blur(3px);
    }
    to {
        opacity: 1;
        letter-spacing: normal;
        filter: blur(0);
    }
}

/* ============================================
   ОБЩИЕ АНИМАЦИИ
============================================ */
@keyframes pulse {
    0%, 100% { transform: scale(1);    opacity: 1;   }
    50%       { transform: scale(1.08); opacity: 0.9; }
}

/* ============================================
   МОБИЛЬНАЯ АДАПТАЦИЯ
============================================ */
@media (max-width: 768px) {

    :root {
        --paper-padding-left: 75px;
        --margin-position: 55px;
        --paper-padding-right: 25px;
        --line-height: 28px;
    }

    body {
        background: linear-gradient(
            180deg,
            var(--bg-gradient-top) 0%,
            var(--bg-gradient-mid) 50%,
            var(--bg-gradient-bot) 100%
        ) !important;
        background-image: none !important;
    }

    body::before {
        display: block !important;
        background: var(--wood-mid);
    }

    [data-theme="dark"] body {
        background: var(--paper-color) !important;
    }

    /* Скрываем десктопные кнопки */
    #desktopControls { display: none !important; }

    /* Скрываем стрелку */
    .sidebar-arrow { display: none !important; }

    /* Нижнее меню */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 62px;
        background: linear-gradient(180deg, var(--wood-mid) 0%, var(--wood-dark) 100%);
        border-top: 1px solid var(--panel-border-strong);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
        z-index: 150;
        flex-direction: row;
        align-items: stretch;
        justify-content: space-around;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .bottom-nav-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        background: none;
        border: none;
        cursor: pointer;
        color: var(--panel-text-dim);
        font-size: 9px;
        font-family: 'Special Elite', monospace;
        padding: 6px 2px;
        transition: color 0.2s;
        -webkit-tap-highlight-color: transparent;
        letter-spacing: 0.03em;
    }

    .bottom-nav-btn svg {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
    }

    .bottom-nav-btn:active { color: var(--accent-gold); }
    .bottom-nav-btn.active { color: var(--accent-gold); }

    .bottom-nav-btn.speaking {
        color: var(--accent-gold);
        animation: pulse 1.2s ease-in-out infinite;
    }

    /* Контейнер */
    .app-container {
        padding: 16px 16px 78px;
    }

    /* Лист */
    .paper-sheet {
        min-height: auto;
        border-radius: 6px;
        box-shadow:
            0 2px 8px rgba(0, 0, 0, 0.08),
            0 4px 16px rgba(0, 0, 0, 0.08);
    }

    /* Текст */
    .story-header,
    .story-input { font-size: 16px; }

    /* Дырки */
    .paper-holes {
        left: 12px;
        padding: 30px 0;
    }
    .paper-hole { width: 16px; height: 16px; }

    /* Текстура */
    .paper-texture { background-size: 150px 150px; }

    /* Звёздочки */
    .star-zone            { width: 40px; height: 40px; }
    .star-zone .star-icon { width: 24px; height: 24px; }
    .star-zone.top-left     { top: 35px;    left: 10px;  }
    .star-zone.bottom-left  { bottom: 35px; left: 10px;  }
    .star-zone.bottom-right { bottom: 35px; right: 10px; }

    /* Сайдбар */
    .sidebar             { width: 100vw; }
    .sidebar:hover       { transform: translateX(-100%); }
    .sidebar.open        { transform: translateX(0); }
    .sidebar.open:hover  { transform: translateX(0); }

    /* Настройки */
    .settings-panel { width: 100vw; }

    /* Контекстное меню */
    .context-menu { min-width: 170px; }

    /* Модалки */
    .modal-box { width: 95%; }

    /* Уведомление */
    .notification { bottom: 74px; }

    /* Popup */
    .rewrite-popup {
        bottom: 70px;
    }

    .rewrite-popup-btn {
        font-size: 17px;
        padding: 11px 22px;
    }

    /* Стикеры */
    .sticky-note {
        font-size: 0.95rem;
        padding: 14px 16px;
        max-width: 200px;
    }

    .sticky-note.sticky-1 { top: 70px;  left: 10px;  transform: rotate(-2deg); }
    .sticky-note.sticky-2 { top: 200px; right: 10px; left: auto; transform: rotate(2deg); }
    .sticky-note.sticky-3 { top: 330px; left: 10px;  transform: rotate(-1deg); }

    /* Приветствие */
    .welcome-paper { padding: 28px 24px; }
    .welcome-title { font-size: 1.85rem; }
    .welcome-text  { font-size: 1.12rem; }
}

.settings-select {
    width: 100%;
    padding: 10px 14px;
    font-family: 'Caveat', cursive;
    font-size: 1.05rem;
    color: var(--panel-text);
    background: var(--panel-item-bg);
    border: 1px solid var(--panel-border-strong);
    border-radius: 6px;
    cursor: pointer;
    outline: none;
    margin-top: 10px;
    transition: all 0.2s;
}

.settings-select:hover {
    border-color: var(--accent-gold);
}

.settings-select:focus {
    border-color: var(--accent-gold);
    background: var(--panel-hover-bg);
}

.settings-select option {
    background: var(--wood-dark);
    color: var(--panel-text);
    padding: 8px;
}

/* ===== TUTORIAL ===== */
.tutorial-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    pointer-events: all;
}
.tutorial-overlay.hidden { display: none; }

.tutorial-spotlight-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.tutorial-tooltip {
    position: fixed;
    z-index: 10002;
    background: var(--paper, #fdf8f0);
    border: 2px solid #e8a838;
    border-radius: 16px;
    padding: 16px 18px 14px;
    max-width: 280px;
    min-width: 180px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.22);
    font-family: 'Caveat', cursive;
    pointer-events: all;
}

/* На мобилке делаем уже */
@media (max-width: 768px) {
    .tutorial-tooltip {
        max-width: 240px;
        min-width: 160px;
        padding: 14px 16px 12px;
    }
    
    .tutorial-text {
        font-size: 1rem;
        margin-bottom: 10px;
    }
    
    .tutorial-next-btn {
        padding: 8px;
        font-size: 0.95rem;
    }
}
/* hidden — сдвигаем за экран, НЕ display:none */
.tutorial-tooltip.hidden {
    left: -9999px !important;
    top: -9999px !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.tutorial-close {
    position: absolute;
    top: 8px; right: 10px;
    background: none; border: none;
    font-size: 14px;
    color: var(--ink-light, #888);
    cursor: pointer;
    opacity: 0.5;
    padding: 2px 6px;
    transition: opacity 0.15s;
}
.tutorial-close:hover { opacity: 1; }

.tutorial-text {
    font-size: 1.05rem;
    color: var(--ink, #2c2c3e);
    line-height: 1.4;
    margin: 0 0 12px;
    padding-right: 20px;
}

.tutorial-next-btn {
    display: block;
    width: 100%;
    padding: 9px;
    background: #e8a838;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-family: 'Caveat', cursive;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
.tutorial-next-btn:hover { background: #d4922a; transform: scale(1.02); }
.tutorial-next-btn:active { transform: scale(0.98); }

/* Скрываем враппер стрелок — больше не нужен */
.tutorial-arrow-wrap { display: none; }

/* Welcome screen кнопки */
.tour-start-btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 12px 20px;
    background: transparent;
    border: 2px solid #e8a838;
    border-radius: 12px;
    color: #e8a838;
    font-family: 'Caveat', cursive;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.tour-start-btn:hover {
    background: #e8a838;
    color: #fff;
}
