/**
 * סיפור שנבנה – עיצוב וינטג' מקצועי
 * PWA, אייקונים, נגישות
 */
:root,
[data-theme="sepia"] {
    --paper: #f2e8d8;
    --paper-dark: #e6dcc8;
    --paper-darker: #d9ccb4;
    --ink: #2c2416;
    --ink-soft: #5a4a32;
    --accent: #6b4423;
    --accent-light: #a67c52;
    --highlight: #c9a86c;
    --reading-word: #8b4512;
    --shadow-soft: 0 2px 10px rgba(44, 36, 22, 0.1);
    --shadow-vintage: 0 4px 20px rgba(44, 36, 22, 0.12);
    --radius: 6px;
    --radius-lg: 10px;
    --font-reading: 'Frank Ruhl Libre', 'David', Georgia, serif;
    --font-ui: 'Heebo', 'David', sans-serif;
    --border-vintage: 2px solid var(--accent-light);
}

/* ערכת ירוק עדין (סג׳) */
[data-theme="sage"] {
    --paper: #e8f0e8;
    --paper-dark: #dce6dc;
    --paper-darker: #c9d8c9;
    --ink: #1a2a1a;
    --ink-soft: #3d4d3d;
    --accent: #2d5a2d;
    --accent-light: #4a7c4a;
    --highlight: #6b9e6b;
    --reading-word: #2d5a2d;
    --shadow-soft: 0 2px 10px rgba(26, 42, 26, 0.08);
    --shadow-vintage: 0 4px 20px rgba(45, 90, 45, 0.1);
    --border-vintage: 2px solid var(--accent-light);
}

/* ערכת כחול־אפור (סלייט) */
[data-theme="slate"] {
    --paper: #e8ecf0;
    --paper-dark: #dce2ea;
    --paper-darker: #c9d2de;
    --ink: #1a2230;
    --ink-soft: #3d4a5c;
    --accent: #3d5a7a;
    --accent-light: #5a7a9e;
    --highlight: #7a9ec4;
    --reading-word: #3d5a7a;
    --shadow-soft: 0 2px 10px rgba(26, 34, 48, 0.08);
    --shadow-vintage: 0 4px 20px rgba(61, 90, 122, 0.12);
    --border-vintage: 2px solid var(--accent-light);
}

/* ערכת שמנת חם */
[data-theme="cream"] {
    --paper: #f5efe6;
    --paper-dark: #ebe2d6;
    --paper-darker: #dfd2c2;
    --ink: #2a2218;
    --ink-soft: #554a38;
    --accent: #b8860b;
    --accent-light: #d4a84b;
    --highlight: #e8c878;
    --reading-word: #8b6914;
    --shadow-soft: 0 2px 10px rgba(42, 34, 24, 0.08);
    --shadow-vintage: 0 4px 20px rgba(184, 134, 11, 0.15);
    --border-vintage: 2px solid var(--accent-light);
}

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

/* נגישות: דילוג לתוכן, טקסט מוסתר */
.skip-link {
    position: absolute;
    top: -3rem;
    right: 1rem;
    z-index: 1001;
    padding: 0.6rem 1rem;
    background: var(--accent);
    color: var(--paper);
    text-decoration: none;
    border-radius: var(--radius);
    font-weight: 600;
    transition: top 0.2s;
}
.skip-link:focus {
    top: 1rem;
    outline: 2px solid var(--ink);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

[hidden] {
    display: none !important;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font-ui);
    background: var(--paper);
    -webkit-tap-highlight-color: transparent;
    background-image:
        linear-gradient(180deg, var(--paper) 0%, var(--paper) 30%, var(--paper-dark) 100%),
        url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.06'/%3E%3C/svg%3E");
    min-height: 100vh;
    color: var(--ink);
    line-height: 1.65;
    transition: background 0.3s ease, color 0.2s ease;
}

/* אייקונים – גודל קבוע (מניעת התנפחות באייפון) */
.icon {
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    max-width: 18px;
    max-height: 18px;
    vertical-align: middle;
    flex-shrink: 0;
    display: inline-block;
}
.icon-logo {
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
    max-width: 22px;
    max-height: 22px;
    vertical-align: middle;
    margin-left: 0.35rem;
}
.btn .icon,
.mode-link .icon,
a.btn-sec .icon { margin-left: 0.3rem; }
.mode-link .icon,
.header-actions .icon { margin-left: 0.25rem; }
[dir="rtl"] .btn .icon,
[dir="rtl"] .mode-link .icon { margin-left: 0; margin-right: 0.3rem; }
[dir="rtl"] .icon-logo { margin-left: 0; margin-right: 0.35rem; }
[dir="rtl"] .header-actions .icon { margin-left: 0; margin-right: 0.25rem; }

.vintage-theme .app-wrap {
    max-width: 640px;
    margin: 0 auto;
    padding: 12px 16px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
}
@media (min-width: 600px) {
    .vintage-theme .app-wrap { padding: 16px 20px; }
}

/* Header – קומפקטי, אפליקטיבי */
.header {
    text-align: center;
    padding: 0.85rem 1rem;
    background: linear-gradient(180deg, var(--paper-dark) 0%, var(--paper-darker) 100%);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-vintage);
    margin-bottom: 1rem;
    border: 1px solid var(--accent-light);
    position: relative;
}
.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 15%;
    right: 15%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-light), transparent);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    opacity: 0.5;
}

.logo {
    margin: 0 0 0.2rem;
    font-family: var(--font-reading);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--ink);
    display: inline-flex;
    align-items: center;
}
.logo .icon { color: var(--accent); }

.tagline {
    margin: 0 0 0.6rem;
    color: var(--ink-soft);
    font-size: 0.8rem;
    line-height: 1.4;
}

.mode-nav {
    margin-bottom: 0.6rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: center;
}

.mode-link {
    display: inline-flex;
    align-items: center;
    padding: 0.4rem 0.75rem;
    font-size: 0.875rem;
    color: var(--ink-soft);
    text-decoration: none;
    border: 1px solid var(--accent-light);
    border-radius: var(--radius);
    font-weight: 500;
    background: var(--paper);
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.mode-link .icon { color: inherit; }

.mode-link:hover {
    background: var(--paper-dark);
    color: var(--ink);
    border-color: var(--accent);
}

.mode-link.active {
    background: var(--accent);
    color: var(--paper);
    border-color: var(--accent);
}
.mode-link.active .icon { color: inherit; }

.header-actions {
    display: flex;
    gap: 0.4rem;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}
.header-actions .btn {
    display: inline-flex;
    align-items: center;
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
}

.theme-switcher {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
}
.theme-label {
    font-size: 0.75rem;
    color: var(--ink-soft);
    margin-left: 0.25rem;
}
.theme-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--paper-darker);
    background: var(--paper-dark);
    color: var(--ink-soft);
    cursor: pointer;
    font-family: var(--font-ui);
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.theme-btn:hover {
    background: var(--highlight);
    color: var(--ink);
    border-color: var(--accent-light);
}
.theme-btn.active,
.theme-btn[aria-pressed="true"] {
    background: var(--accent);
    color: var(--paper);
    border-color: var(--accent);
}

.btn-menu {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.85rem;
    font-size: 0.9rem;
}

/* Buttons – קומפקטי */
.btn {
    font-family: var(--font-ui);
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius);
    border: 1px solid var(--accent);
    font-weight: 600;
    cursor: pointer;
    font-size: 0.875rem;
    background: var(--paper-dark);
    color: var(--ink);
    transition: background 0.15s, color 0.15s;
}

.btn:hover {
    background: var(--accent-light);
    color: var(--paper);
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

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

.btn-primary:hover {
    background: var(--ink);
    border-color: var(--ink);
}

.btn-sec {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    padding: 0.45rem 0.75rem;
    font-size: 0.8rem;
    border-radius: var(--radius);
    font-weight: 600;
    margin: 2px;
    border: 1px solid var(--accent-light);
    background: var(--paper-dark);
    color: var(--ink);
}

.btn-sec:hover {
    background: var(--highlight);
    color: var(--ink);
}

.btn-acc, .btn-disclosure {
    background: var(--ink-soft);
    color: var(--paper);
    border-color: var(--ink-soft);
}

.btn-tts {
    background: var(--accent);
    color: var(--paper);
    border-color: var(--accent);
}

.btn-tts-stop {
    background: var(--ink);
    color: var(--paper);
    border-color: var(--ink);
}

.mode-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}
.mode-buttons .btn {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}
.btn-viewer { background: var(--paper-dark); color: var(--ink); border: var(--border-vintage); }
.btn-writer { background: var(--accent); color: var(--paper); border: 2px solid var(--accent); }

/* Layout with TOC – קומפקטי */
.layout-with-toc {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.toc-sidebar {
    flex: 0 0 180px;
    position: sticky;
    top: 12px;
    background: linear-gradient(180deg, var(--paper-dark) 0%, var(--paper-darker) 100%);
    border: 1px solid var(--accent-light);
    border-radius: var(--radius-lg);
    padding: 0.7rem 0.9rem;
    box-shadow: var(--shadow-vintage);
}
.toc-sidebar[hidden] {
    display: none !important;
}

.toc-title {
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.toc-title .icon { color: var(--accent); }

.toc-list {
    margin: 0;
    padding-inline-start: 20px;
    list-style: none;
}

.toc-list li {
    margin: 0.25rem 0;
}

.toc-list a {
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 0.8rem;
    line-height: 1.35;
    display: block;
    padding: 0.25rem 0;
    border-bottom: 1px solid transparent;
}

.toc-list a:hover,
.toc-list a.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.content-area {
    flex: 1;
    min-width: 0;
}

/* Cards – קומפקטי, אפליקטיבי */
.card {
    background: linear-gradient(180deg, var(--paper-dark) 0%, var(--paper-darker) 100%);
    border-radius: var(--radius-lg);
    padding: 0.9rem 1.1rem;
    margin-bottom: 0.9rem;
    box-shadow: var(--shadow-vintage);
    border: 1px solid var(--accent-light);
}

.card h2, .card h3 {
    margin: 0 0 0.6rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
}

.controls-title { font-size: 0.9rem; margin-bottom: 0.5rem; font-weight: 600; }
.control-label { display: block; font-size: 0.8rem; margin-bottom: 0.25rem; color: var(--ink-soft); }

/* Login */
.login-card .hint {
    margin: 0 0 12px;
    font-size: 0.9rem;
    color: var(--ink-soft);
}

#form-login {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 280px;
}

#form-login input {
    font-family: var(--font-ui);
    font-size: 1rem;
    padding: 10px 14px;
    border: 1px solid var(--accent-light);
    border-radius: var(--radius);
    direction: ltr;
    background: var(--paper);
}

#author-password {
    width: 100%;
}

#pincode {
    width: 100%;
    text-align: center;
}

#form-login input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Export heading */
.export-section .btn { display: inline-flex; align-items: center; }

/* Controls strip – קומפקטי */
.controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.6rem;
}

.control-group label {
    display: block;
    font-size: 0.78rem;
    margin-bottom: 0.2rem;
    color: var(--ink-soft);
}

.control-group input[type="range"] {
    width: 100%;
    max-width: 120px;
    vertical-align: middle;
    height: 6px;
}

.control-group select {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    border: 1px solid var(--accent-light);
    border-radius: var(--radius);
    background: var(--paper);
    font-family: var(--font-ui);
    color: var(--ink);
}

.btn.small { padding: 0.35rem 0.6rem; font-size: 0.8rem; }

.lang-tabs .lang-btn {
    padding: 0.35rem 0.6rem;
    margin: 0 2px 2px 0;
    font-size: 0.78rem;
    border: 1px solid var(--accent-light);
    background: var(--paper);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-ui);
    color: var(--ink-soft);
}

.lang-tabs .lang-btn:hover {
    background: var(--paper-dark);
    color: var(--ink);
}

.lang-tabs .lang-btn.active {
    background: var(--accent);
    color: var(--paper);
    border-color: var(--accent);
}

/* Story text – קומפקטי, נוח לקריאה */
.story-text {
    font-family: var(--font-reading);
    font-size: 1.05rem;
    line-height: 1.75;
    min-height: 80px;
    max-height: 320px;
    overflow: auto;
    padding: 0.75rem 0;
    -webkit-overflow-scrolling: touch;
    color: var(--ink);
}

.story-text .sentence-block {
    margin-bottom: 1em;
}

.story-text .word {
    transition: background 0.15s, color 0.15s;
    padding: 0 1px;
    border-radius: 2px;
}

.story-text .word.reading {
    background: var(--highlight);
    color: var(--reading-word);
    font-weight: 600;
}

.story-text.empty::before {
    content: 'הסיפור עדיין ריק. הוסף את המשפט הראשון (מצב סופר).';
    color: var(--ink-soft);
}

.story-actions {
    margin-top: 0.6rem;
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}
.story-actions .btn { display: inline-flex; align-items: center; }
.btn-fullscreen { display: inline-flex; align-items: center; gap: 0.35rem; }
.btn-fullscreen .icon-fs-out.hidden { display: none; }
.btn-fullscreen .icon-fs-in.hidden { display: none; }
.btn-fullscreen.is-fullscreen .icon-fs-in { display: none; }
.btn-fullscreen.is-fullscreen .icon-fs-out { display: inline-block; }
.btn-fullscreen.is-fullscreen .icon-fs-out.hidden { display: inline-block; }

.writer-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.25rem;
}
.writer-block-header h2 { margin: 0; }

/* מסך שלם – קריאה וכתיבה */
.story-card.card:fullscreen,
.story-card.card::-webkit-full-screen,
#writer-block:fullscreen,
#writer-block::-webkit-full-screen {
    max-width: none;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--paper);
    padding: 1.5rem 2rem;
    justify-content: center;
}
.story-card.card:fullscreen .story-text,
.story-card.card::-webkit-full-screen .story-text {
    flex: 1;
    overflow: auto;
}
.story-card.card:fullscreen .story-actions,
.story-card.card::-webkit-full-screen .story-actions {
    flex-shrink: 0;
    margin-top: 1rem;
}
#writer-block:fullscreen,
#writer-block::-webkit-full-screen {
    justify-content: flex-start;
}
#writer-block:fullscreen .writer-block-header,
#writer-block::-webkit-full-screen .writer-block-header {
    flex-shrink: 0;
}
#writer-block:fullscreen form,
#writer-block::-webkit-full-screen form {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-top: 0.5rem;
}
#writer-block:fullscreen textarea,
#writer-block::-webkit-full-screen textarea {
    flex: 1;
    min-height: 140px;
}

.loading-placeholder {
    padding: 2rem;
    text-align: center;
    color: var(--ink-soft);
    font-size: 0.95rem;
}
.story-text.loading {
    min-height: 4rem;
}

/* Add sentence – סופר, קומפקטי */
.can-add-msg {
    margin: 0 0 0.5rem;
    font-size: 0.8rem;
    color: var(--ink-soft);
}

.can-add-msg.waiting {
    color: var(--accent);
    font-weight: 500;
}
.can-add-msg.your-turn {
    color: var(--accent);
    font-weight: 600;
    background: rgba(201, 168, 108, 0.25);
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius);
    border: 1px solid var(--accent-light);
}

.waiting-strip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: linear-gradient(90deg, rgba(107, 68, 35, 0.08) 0%, transparent 100%);
    border: 1px solid var(--accent-light);
}
.waiting-strip .waiting-icon { font-size: 1.1rem; }
.waiting-strip .waiting-text { font-size: 0.9rem; color: var(--ink-soft); }
.waiting-strip[hidden] { display: none !important; }

#sentence-input {
    width: 100%;
    font-family: var(--font-reading);
    font-size: 0.95rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--accent-light);
    border-radius: var(--radius);
    resize: vertical;
    min-height: 56px;
    background: var(--paper);
    color: var(--ink);
}

#sentence-input:focus {
    outline: none;
    border-color: var(--accent);
}

#form-add.disabled #sentence-input,
#form-add.disabled #btn-add-submit {
    opacity: 0.7;
    pointer-events: none;
}

.char-count {
    display: block;
    font-size: 0.75rem;
    color: var(--ink-soft);
    margin: 0.2rem 0 0.5rem;
}

/* Stats – קומפקטי */
.stats-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.stat-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.65rem;
    font-size: 0.85rem;
    background: var(--paper);
    border-radius: var(--radius);
    border: 1px solid rgba(107,68,35,0.2);
}

.stat-row .label { flex: 1; font-weight: 500; }
.stat-row .words { color: var(--ink-soft); font-weight: 600; }
.stat-row .percent {
    background: var(--accent-light);
    color: var(--paper);
    padding: 0.2rem 0.5rem;
    font-size: 0.8rem;
    border-radius: 4px;
    font-weight: 700;
    min-width: 44px;
    text-align: center;
}

.export-section,
.export-actions {
    margin-top: 0.75rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.export-heading {
    font-size: 0.9rem;
    margin: 0 0 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--ink);
}

.status-msg {
    font-size: 0.9rem;
    margin: 0.5rem 0;
    color: var(--ink-soft);
}
.status-msg:not(.hidden) {
    color: var(--accent);
}

/* טוסט הודעות */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 50%;
    transform: translate(50%, 0);
    max-width: 90vw;
    width: 320px;
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius);
    font-weight: 500;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 1002;
    animation: toast-in 0.25s ease;
}
.toast--success { background: #2d5a27; color: #fff; }
.toast--error { background: #8b2e2e; color: #fff; }
.toast--info { background: var(--accent); color: var(--paper); }
@keyframes toast-in {
    from { opacity: 0; transform: translate(50%, 0.5rem); }
    to { opacity: 1; transform: translate(50%, 0); }
}

/* תפריט צד נפתח */
.side-menu {
    position: fixed;
    top: 0;
    right: 0;
    width: min(320px, 92vw);
    max-width: 320px;
    height: 100%;
    height: 100dvh;
    background: var(--paper);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease, visibility 0.25s;
    visibility: hidden;
    border-left: 1px solid var(--paper-darker);
}
.side-menu.is-open {
    transform: translateX(0);
    visibility: visible;
}
.side-menu[hidden] {
    display: none !important;
}
.side-menu:not([hidden]).is-open {
    display: flex !important;
}

.side-menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.side-menu-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
}
.side-menu-overlay[hidden] {
    display: none !important;
}

.side-menu-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}
.side-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--paper-darker);
    flex-shrink: 0;
    background: var(--paper-dark);
}
.side-menu-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
}
.btn-icon-close {
    padding: 0.4rem;
    border: none;
    background: transparent;
    color: var(--ink-soft);
    cursor: pointer;
    border-radius: var(--radius);
}
.btn-icon-close:hover {
    background: var(--paper-darker);
    color: var(--ink);
}
.side-menu-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 1rem;
    padding-bottom: 2rem;
}
.side-menu-section {
    margin-bottom: 1.25rem;
}
.side-menu-section h3 {
    margin: 0 0 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink-soft);
}
.side-menu-section .theme-switcher {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}
.side-menu-section .theme-btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.8rem;
}
.side-controls .control-group {
    margin-bottom: 0.75rem;
}
.side-controls .control-group label,
.side-controls .control-group .control-label {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
    color: var(--ink-soft);
}
.side-controls input[type="range"] {
    width: 100%;
    max-width: 100%;
}
.side-menu-links {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.btn-block {
    width: 100%;
    justify-content: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.side-menu-section .btn-sec.btn-block {
    display: inline-flex;
}

/* Panels */
.panel {
    position: fixed;
    top: 50%;
    right: 50%;
    transform: translate(50%, -50%);
    background: var(--paper-dark);
    padding: 24px 28px;
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    max-width: 90vw;
    width: 400px;
    z-index: 1000;
    border: 1px solid var(--accent-light);
}

.panel {
    border: var(--border-vintage);
    box-shadow: 0 12px 40px rgba(44,36,22,0.25);
}
.panel h2 { margin: 0 0 0.5rem; font-size: 1rem; color: var(--ink); }
.panel ul { margin: 0 0 0.75rem; padding-inline-start: 1.2rem; font-size: 0.9rem; }
.panel p { margin: 0 0 0.75rem; font-size: 0.9rem; }
.writer-terms-content { max-height: 60vh; overflow-y: auto; }
.writer-terms-content ul { margin: 0.5rem 0 0.75rem; }
.writer-terms-content li { margin: 0.35rem 0; }
.footer-terms-link { background: none; border: none; color: var(--ink-soft); font-size: 0.85rem; text-decoration: underline; }
.footer-terms-link:hover { color: var(--accent); }
.btn-link, .writer-terms-link .btn-text { background: none; border: none; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: inherit; }
.btn-link:hover, .writer-terms-link .btn-text:hover { color: var(--ink); }
.btn-close-acc {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.875rem;
    background: var(--accent);
    color: var(--paper);
    border-color: var(--accent);
}

.panel.hidden { display: none !important; }
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(44,36,22,0.35);
    z-index: 999;
}
.overlay.hidden { display: none !important; }

.hidden { display: none !important; }

.footer {
    text-align: center;
    padding: 0.75rem 1rem;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    color: var(--ink-soft);
    font-size: 0.8rem;
    border-top: 1px solid var(--accent-light);
    margin-top: 0.75rem;
}

/* מובייל – אייפון וכו' */
@media (max-width: 600px) {
    .layout-with-toc { flex-direction: column; gap: 0.75rem; }
    .toc-sidebar {
        position: static;
        flex: none;
        width: 100%;
        padding: 0.6rem 0.8rem;
    }
    .toc-title { font-size: 0.85rem; }
    .logo { font-size: 1.2rem; }
    .logo .icon { width: 20px; height: 20px; min-width: 20px; min-height: 20px; max-width: 20px; max-height: 20px; }
    .tagline { font-size: 0.75rem; }
}

/* מניעת zoom באייפון בשדות */
@supports (-webkit-touch-callout: none) {
    input, select, textarea, .btn { font-size: max(16px, 0.875rem); }
}

@media (prefers-reduced-motion: reduce) {
    .btn:hover { transform: none; }
    .story-text .word { transition: none; }
    .toast { animation: none; }
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media print {
    .skip-link, .header-actions, .mode-nav, .controls-strip, .story-actions,
    .side-menu, .side-menu-overlay, .add-card, .btn, .toc-sidebar, .panel, .overlay, .toast { display: none !important; }
    .header { border: none; }
    body { background: #fff; }
}
