/* Smart Reader Pro — PWA-Grade Design System */

/* ─── Accessibility (axe) fixes ────────────────────────────────────────
   Inactive mode tabs sat at 3.98:1 (light) / 2.09:1 (sepia) on the pill
   background — below the 4.5:1 AA minimum. Dark/nordic already pass. */
body.theme-light .mode-tab:not(.active) { color: #334155; }
body.theme-sepia .mode-tab:not(.active) { color: #433422; }

/* Screen-reader-only content (used for the reader screen's h1) */
.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Keyboard focus for the scrollable reading viewport (axe: scrollable-region-focusable) */
.viewport-container:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Keyboard focus for the scrollable playlist container (a11y: axe
   scrollable-region-focusable) */
.playlist-items-container:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

:root {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.85);
    --card-border: rgba(255, 255, 255, 0.1);
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --accent-color: #38bdf8;
    --accent-contrast: #0b1120; /* text on --accent-color: 8.8:1 on the light-blue default accent */
    --accent-hover: #0ea5e9;
    --accent-glow: rgba(56, 189, 248, 0.35);
    --highlight-bg: rgba(56, 189, 248, 0.25);
    --nav-bg: rgba(15, 23, 42, 0.8);
    --font-family: 'Noto Sans Georgian', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-serif: 'Noto Serif Georgian', Georgia, serif;
    --font-mono: 'JetBrains Mono', monospace;
    --font-size: 28px;
    --line-height: 1.8;
    --max-reading-width: 860px;
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-soft: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 25px var(--accent-glow);
}

body.theme-light {
    --bg-color: #f8fafc;
    --card-bg: rgba(255, 255, 255, 0.9);
    --card-border: rgba(0, 0, 0, 0.08);
    --text-color: #0f172a;
    --text-muted: #475569;
    --accent-color: #0369a1;
    --accent-contrast: #ffffff; /* white on #0369a1 = 5.9:1 */
    --accent-hover: #075985;
    --accent-glow: rgba(3, 105, 161, 0.25);
    --highlight-bg: rgba(254, 240, 138, 0.7);
    --nav-bg: rgba(255, 255, 255, 0.85);
    --shadow-soft: 0 10px 30px -10px rgba(0, 0, 0, 0.08);
}

body.theme-sepia {
    --bg-color: #f4ecd8;
    --card-bg: rgba(253, 246, 227, 0.95);
    --card-border: rgba(91, 70, 54, 0.15);
    --text-color: #433422;
    --text-muted: #8c7355;
    --accent-color: #b45309;
    --accent-contrast: #ffffff; /* white on #b45309 = 5.0:1 */
    --accent-hover: #92400e;
    --accent-glow: rgba(180, 83, 9, 0.25);
    --highlight-bg: rgba(253, 224, 71, 0.45);
    --nav-bg: rgba(244, 236, 216, 0.85);
}

body.theme-nordic {
    --bg-color: #242933;
    --card-bg: rgba(46, 52, 64, 0.9);
    --card-border: rgba(136, 192, 208, 0.15);
    --text-color: #eceff4;
    --text-muted: #d8dee9;
    --accent-color: #88c0d0;
    --accent-contrast: #1b2430; /* white on #88c0d0 was 2.0:1 — use dark text */
    --accent-hover: #81a1c1;
    --accent-glow: rgba(136, 192, 208, 0.3);
    --highlight-bg: rgba(136, 192, 208, 0.3);
    --nav-bg: rgba(36, 41, 51, 0.85);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    transition: background-color 0.25s ease, border-color 0.25s ease, color 0.2s ease;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    /* Use dvh (dynamic viewport height) which accounts for mobile browser chrome */
    height: 100dvh;
    height: 100vh; /* fallback */
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* Prevent pull-to-refresh and overscroll bounce — feels native */
    overscroll-behavior: none;
    /* Remove iOS tap flash */
    -webkit-tap-highlight-color: transparent;
    /* Prevent text selection flicker on tap */
    -webkit-touch-callout: none;
    /* Optimize for touch */
    touch-action: manipulation;
    /* Prevent iOS font size adjustment on rotate */
    -webkit-text-size-adjust: 100%;
}

/* Document & Info Pages (Privacy Policy, Terms of Service, About, FAQ) - Fully Scrollable */
html.doc-html,
body.doc-body,
body:has(.doc-page) {
    height: auto !important;
    min-height: 100% !important;
    min-height: 100dvh !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    display: block !important;
    overscroll-behavior-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    -webkit-touch-callout: default !important;
    touch-action: auto !important;
}

/* All interactive elements: faster tap response, no highlight */
button, a, [role="button"], .sample-chip, .mode-card, .mode-tab, .dropzone {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    cursor: pointer;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-thumb {
    background: var(--card-border);
    border-radius: 4px;
}

/* Global App Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Safe-area-inset-top handles notch and Dynamic Island on iOS PWA.
       --safe-top-fallback is set by JS (setupSafeAreaGuard) when iOS
       standalone mode reports a stuck 0px inset — header would otherwise
       render under the status bar clock/battery. */
    padding: max(12px, calc(env(safe-area-inset-top) + 8px), calc(var(--safe-top-fallback, 0px) + 8px)) 20px 12px 20px;
    background: var(--nav-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--card-border);
    z-index: 100;
    flex-shrink: 0;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    padding: 6px 10px;
    border-radius: var(--radius-md);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    min-width: 0;
    flex: 1;
    overflow: hidden;
}

.brand:hover {
    background: var(--surface);
    transform: translateY(-1px);
}

.brand:active {
    transform: scale(0.97);
}

.brand-icon,
.brand-logo-img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    object-fit: contain;
    filter: drop-shadow(0 2px 8px var(--accent-glow));
    flex-shrink: 0;
    display: block;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.brand:hover .brand-logo-img,
.brand:hover .brand-icon {
    transform: scale(1.06);
}

.brand-title {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text-color);
    white-space: nowrap;
    flex-shrink: 0;
}

.status-badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 20px;
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    flex-shrink: 0;
}

body.theme-light .status-badge {
    background: rgba(5, 150, 105, 0.15);
    color: #047857;
    border-color: rgba(4, 120, 87, 0.3);
}

.status-text-full {
    display: inline;
}

.status-text-short {
    display: none;
}

.status-badge.offline {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border-color: rgba(245, 158, 11, 0.3);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* UI Buttons & Controls */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    color: var(--text-color);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.btn:hover {
    border-color: var(--accent-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: var(--accent-color);
    color: var(--accent-contrast);
    border: none;
    box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary:hover {
    background: var(--accent-hover);
    color: var(--accent-contrast);
}

.btn-icon {
    padding: 10px;
    border-radius: 50%;
    width: 42px;
    height: 42px;
}

.btn-fullscreen {
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-fullscreen:hover {
    border-color: var(--accent-color);
    box-shadow: var(--shadow-glow);
}

.btn-fullscreen.active {
    border-color: var(--accent-color);
    background: var(--highlight-bg);
    box-shadow: var(--shadow-glow);
}

/* Screens Layout */
.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* ─── HOME SCREEN (App Dashboard Layout) ─────────────────────────────────── */
#setup-screen {
    max-width: 620px;
    margin: 0 auto;
    width: 100%;
    padding: 14px 16px max(16px, env(safe-area-inset-bottom)) 16px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    display: flex;
    flex: 1;
}

#setup-screen::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

/* Compact hero */
.home-hero {
    text-align: center;
    padding: 4px 0 2px;
    flex-shrink: 0;
}

.home-hero h1 {
    font-size: clamp(1.4rem, 4.5vw, 2.1rem);
    line-height: 1.2;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--text-color) 0%, var(--accent-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 3px;
}

.home-subtitle {
    font-size: clamp(0.75rem, 2.2vw, 0.85rem);
    line-height: 1.3;
    color: var(--text-muted);
    letter-spacing: 0.2px;
}

/* ─── MODE CARDS GRID ──────────────────────────────────────────────────────── */
.mode-cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    flex-shrink: 0;
}

.mode-card-youtube:hover,
.mode-card-youtube.selected {
    border-color: #ef4444 !important;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.4) !important;
}

.mode-card-youtube.selected {
    background: rgba(239, 68, 68, 0.15) !important;
}

.mode-card {
    height: 74px;
    justify-content: center;
    background: var(--card-bg);
    border: 1.5px solid var(--card-border);
    border-radius: 14px;
    padding: 8px 4px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-family: inherit;
    color: var(--text-color);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1),
                border-color 0.18s ease,
                box-shadow 0.18s ease,
                background 0.18s ease;
    user-select: none;
    -webkit-user-select: none;
}

.mode-card:hover {
    border-color: var(--accent-color);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.mode-card:active {
    transform: scale(0.94) translateY(0);
    background: var(--highlight-bg);
    border-color: var(--accent-color);
    box-shadow: none;
}

.mode-card.selected {
    border-color: var(--accent-color);
    background: var(--highlight-bg);
    box-shadow: var(--shadow-glow);
}

.mode-card.selected .mode-card-sub {
    color: var(--text-color);
    font-weight: 600;
}

.mode-card-icon {
    font-size: 24px;
    line-height: 1;
    filter: drop-shadow(0 2px 6px var(--accent-glow));
}

.mode-card-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-color);
}

.mode-card-sub {
    font-size: 9px;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.2;
}

/* ─── INPUT SECTION ────────────────────────────────────────────────────────── */
.input-section {
    width: 100%;
    overflow: visible;
}

/* Dropzone & Input Box */
.input-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    gap: 12px;
    backdrop-filter: blur(16px);
}

/* ── Input Tabs Navigation ─────────────────────────────────────────────────── */
.input-tabs-nav {
    display: flex;
    background: rgba(0, 0, 0, 0.22);
    padding: 4px;
    border-radius: var(--radius-md);
    gap: 4px;
    border: 1px solid var(--card-border);
}

.input-tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
    user-select: none;
}

.input-tab-btn:hover {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.05);
}

.input-tab-btn.active {
    color: var(--text-color);
    background: rgba(56, 189, 248, 0.15);
    border-color: rgba(56, 189, 248, 0.35);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.input-tab-btn .tab-icon {
    font-size: 14px;
    line-height: 1;
}

.input-tab-btn .tab-badge {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    font-weight: 500;
}

.input-tab-btn.active .tab-badge {
    background: rgba(56, 189, 248, 0.25);
    color: var(--accent-color);
}

/* Light / Sepia theme adjustments for tabs */
body.theme-light .input-tabs-nav {
    background: rgba(0, 0, 0, 0.04);
}
body.theme-light .input-tab-btn.active {
    background: rgba(3, 105, 161, 0.12);
    border-color: rgba(3, 105, 161, 0.3);
    color: var(--accent-color);
}
body.theme-sepia .input-tabs-nav {
    background: rgba(0, 0, 0, 0.04);
}
body.theme-sepia .input-tab-btn.active {
    background: rgba(180, 83, 9, 0.14);
    border-color: rgba(180, 83, 9, 0.3);
    color: var(--accent-color);
}
/* Sepia: #b45309 on the washed tab bg measured 3.56:1 (axe) — darker accent text */
body.theme-sepia .input-tab-btn.active .tab-title {
    color: #92400e;
}
/* Sepia: lang badge #b45309 on its indigo-tint bg measured 4.0:1 (axe) */
body.theme-sepia .badge-lang {
    color: #92400e;
}

/* ── Input Tab Panes ───────────────────────────────────────────────────────── */
.input-tab-pane {
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Textarea Header Toolbar ───────────────────────────────────────────────── */
.text-area-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 2px;
}

.samples-select-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 180px;
}

.sample-select-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

.sample-select-wrapper {
    position: relative;
    flex: 1;
    max-width: 280px;
}

.sample-dropdown {
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    padding: 5px 26px 5px 10px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
}

.sample-dropdown:hover {
    border-color: var(--accent-color);
    background: rgba(255, 255, 255, 0.08);
}

.sample-dropdown:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.sample-dropdown option,
.sample-dropdown optgroup {
    background: #1e293b;
    color: #f8fafc;
}

body.theme-light .sample-dropdown {
    background: rgba(0, 0, 0, 0.03);
}

body.theme-light .sample-dropdown option,
body.theme-light .sample-dropdown optgroup {
    background: #ffffff;
    color: #0f172a;
}

body.theme-sepia .sample-dropdown option,
body.theme-sepia .sample-dropdown optgroup {
    background: #fdf6e3;
    color: #433422;
}

.sample-select-wrapper::after {
    content: '▾';
    position: absolute;
    right: 9px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    font-size: 11px;
    color: var(--text-muted);
}

/* Dedicated Clear Button */
.btn-clear-text {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    user-select: none;
}

.btn-clear-text:not(:disabled):hover {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.35);
    color: #ef4444;
}

.btn-clear-text:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

/* Dropzone (Roomy & Modern) */
.dropzone {
    border: 1.5px dashed var(--card-border);
    border-radius: var(--radius-md);
    padding: 16px 14px;
    text-align: center;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.dropzone-roomy {
    min-height: 125px;
    padding: 20px 16px;
}

.dropzone-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.dropzone-inner .dropzone-icon {
    font-size: 28px;
    line-height: 1;
}

.dropzone-inner .dropzone-content {
    display: flex;
    flex-direction: column;
    gap: 3px;
    text-align: center;
}

.dropzone-badges {
    display: flex;
    gap: 6px;
    margin-top: 4px;
    flex-wrap: wrap;
    justify-content: center;
}

.fmt-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

body.theme-light .fmt-badge {
    background: rgba(0, 0, 0, 0.06);
}

.tab-pane-tip {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 2px 8px;
    line-height: 1.4;
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--accent-color);
    background: var(--highlight-bg);
}

.dropzone-icon {
    font-size: 20px;
    line-height: 1;
    flex-shrink: 0;
}

.dropzone-title {
    font-size: 13px;
    font-weight: 600;
}

.dropzone-text {
    font-size: 12px;
    color: var(--text-muted);
}

/* URL Samples Row inside URL Tab */
.url-samples-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 2px 4px;
}

.url-samples-label {
    font-size: 12px;
    color: var(--text-muted);
}

/* URL Fetcher Card */
.url-fetch-wrapper {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 7px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.url-fetch-wrapper:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: rgba(255, 255, 255, 0.05);
}

.url-fetch-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.url-icon {
    font-size: 1.1rem;
    user-select: none;
    opacity: 0.85;
    flex-shrink: 0;
}

.url-fetch-input-group input[type="url"] {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-color);
    font-size: 14px;
    font-family: inherit;
    min-width: 0;
}

.url-fetch-input-group input[type="url"]::placeholder {
    color: var(--text-muted);
    font-size: 13px;
}

.url-status-msg {
    font-size: 13px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.4;
    animation: fadeIn 0.2s ease;
}

.url-status-msg.success {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.url-status-msg.error {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.url-status-msg.loading {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-color);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.text-area-wrapper {
    position: relative;
    width: 100%;
}

textarea#main-text-input {
    width: 100%;
    min-height: 110px;
    height: 130px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--card-border);
    background: rgba(0, 0, 0, 0.1);
    color: var(--text-color);
    font-family: inherit;
    font-size: 15px;
    line-height: 1.55;
    resize: vertical;
    outline: none;
}

textarea#main-text-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-meta-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-muted);
    padding: 0 4px;
}

.badge-lang {
    font-weight: 600;
    color: var(--accent-color);
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.25);
    padding: 2px 9px;
    border-radius: 12px;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
}

.samples-row {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.sample-chip {
    font-size: 11px;
    padding: 5px 11px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--card-border);
    cursor: pointer;
    color: var(--text-muted);
}

.sample-chip:hover {
    color: var(--accent-color);
    border-color: var(--accent-color);
}

.chip-toggle {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--card-border);
    cursor: pointer;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
    user-select: none;
}

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

.chip-toggle.active {
    background: rgba(74, 144, 226, 0.18);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

#reader-skip-num-btn.active {
    background: rgba(74, 144, 226, 0.22);
    border-color: var(--accent-color);
    color: var(--accent-color);
    box-shadow: 0 0 10px rgba(74, 144, 226, 0.35);
}

.action-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 2px;
    flex-wrap: wrap;
}

.action-row .btn {
    padding: 12px 32px;
    font-size: 15px;
    font-weight: 700;
}

/* Reader Screen Layout */
#reader-screen {
    display: none;
    flex-direction: column;
    height: 100%;
}

.reader-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: var(--nav-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--card-border);
    gap: 12px;
    flex-shrink: 0;
    position: relative;
    z-index: 50;
    min-width: 0;
}

.reader-nav-left,
.reader-nav-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    z-index: 2;
}

.reader-nav-center {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-weight: 600;
    font-size: 13.5px;
    border-radius: var(--radius-md);
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-back:active {
    transform: scale(0.95);
}

.btn-export-audio {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-md);
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent-color);
    border: 1px solid rgba(56, 189, 248, 0.3);
    white-space: nowrap;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
}

.btn-export-audio:hover {
    background: rgba(56, 189, 248, 0.22);
    box-shadow: var(--shadow-glow);
}

.btn-export-audio:active {
    transform: scale(0.95);
}

.btn-export-audio:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-focus-mode {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-md);
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--card-border);
    white-space: nowrap;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
}

.btn-focus-mode:hover {
    border-color: var(--accent-color);
    box-shadow: var(--shadow-glow);
    color: var(--accent-color);
}

.btn-focus-mode:active {
    transform: scale(0.95);
}

.btn-focus-mode.active {
    background: var(--highlight-bg);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

/* Focus-mode active button: the default accent-on-highlight pairs measured
   below 4.5:1 in three themes (axe, focus-mode scan). Dark/brighter text
   variants used per theme; sepia's amber bg needs dark brown text. */
body.theme-dark .btn-focus-mode.active {
    color: #7dd3fc;
}
body.theme-light .btn-focus-mode.active {
    color: #075985;
}
body.theme-sepia .btn-focus-mode.active {
    color: #6b3804;
    border-color: #6b3804;
}
body.theme-nordic .btn-focus-mode.active {
    color: #b8dcea;
    border-color: #b8dcea;
}

.focus-btn-icon {
    font-size: 14px;
    line-height: 1;
}

.nav-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.select-control {
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--card-border);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    max-width: 200px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

.select-control:focus {
    border-color: var(--accent-color);
}

/* Mode Switcher Tabs (iOS Segmented Control) */
.mode-tabs {
    display: inline-flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.25);
    padding: 3px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    gap: 3px;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.mode-tabs::-webkit-scrollbar {
    display: none;
}

.mode-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 13px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 9px;
    cursor: pointer;
    color: var(--text-muted);
    border: none;
    background: transparent;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
}

.mode-tab:hover {
    color: var(--text-color);
}

.mode-tab.active {
    background: var(--accent-color);
    color: var(--accent-contrast);
    box-shadow: 0 2px 8px var(--accent-glow);
}

.mode-tab-youtube {
    color: #f87171;
}

.mode-tab-youtube:hover {
    color: #ef4444;
}

.mode-tab-youtube.active {
    background: #ef4444 !important;
    color: #ffffff !important;
    box-shadow: 0 2px 10px rgba(239, 68, 68, 0.5) !important;
}

/* Main Reader Viewport */
.viewport-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 30px 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

/* Fix flexbox center overflow bug: align to top so all paragraphs are reachable from slide 1! */
#reader-screen.mode-continuous .viewport-container,
.viewport-container:has(#continuous-view[style*="flex"]) {
    align-items: flex-start !important;
}

/* ─── STRICT MODE ISOLATION (Slides vs RSVP vs Continuous) ─── */
#reader-screen.mode-rsvp .slide-card,
#reader-screen.mode-continuous .slide-card,
.slide-card[style*="display: none"],
.slide-card[hidden] {
    display: none !important;
}

#reader-screen:not(.mode-rsvp) .rsvp-box,
.rsvp-box[style*="display: none"],
.rsvp-box[hidden] {
    display: none !important;
}

#reader-screen:not(.mode-continuous) .continuous-view,
.continuous-view[style*="display: none"],
.continuous-view[hidden] {
    display: none !important;
}

/* Slide Display Card */
.slide-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 36px 44px;
    width: 100%;
    max-width: var(--max-reading-width);
    min-height: auto;
    margin: auto 0; /* Centers vertically if fits, begins at top if long — prevents clipping */
    display: block; /* Flow text from top down — never cut off initial lines */
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    position: relative;
    box-sizing: border-box;
    animation: slideFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideFadeIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.slide-content-text {
    font-size: var(--slide-font-size, var(--font-size));
    line-height: var(--line-height);
    text-align: left;
    text-wrap: pretty;
    hyphens: auto;
    word-break: break-word;
    white-space: pre-line;
}

body.serif .slide-content-text {
    font-family: var(--font-serif);
}

/* Bionic Reading Styling */
.bionic-bold {
    font-weight: 700;
    color: var(--accent-color);
}

/* ElevenLabs-Style Word Boundary & Karaoke Highlighting (Fluid, zero layout shift) */
.word-span {
    display: inline-block;
    cursor: pointer;
    border-radius: 6px;
    padding: 2px 5px;
    margin: 0 1px;
    box-sizing: border-box;
    transition: background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
    transform: none;
}

.word-span:hover {
    background: rgba(255, 255, 255, 0.08);
}

body.theme-light .word-span:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Active Karaoke Highlight (Fluid, non-flickering, zero layout shifts) */
.word-span.active-word {
    background: rgba(245, 158, 11, 0.32);
    color: var(--text-color);
    font-weight: inherit; /* PREVENT GLYPH EXPANSION & LINE JUMPING */
    transform: none;      /* PREVENT ANTIALIASING RASTER JITTER */
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.4), 0 0 0 1px rgba(245, 158, 11, 0.55);
    z-index: 1;
    position: relative;
}

body.theme-light .word-span.active-word {
    background: rgba(217, 119, 6, 0.22);
    color: #0f172a;
    font-weight: inherit;
    transform: none;
    box-shadow: 0 0 10px rgba(217, 119, 6, 0.3), 0 0 0 1px rgba(217, 119, 6, 0.45);
}

body.theme-sepia .word-span.active-word {
    background: rgba(180, 83, 9, 0.25);
    color: #2c1810;
    font-weight: inherit;
    transform: none;
    box-shadow: 0 0 10px rgba(180, 83, 9, 0.3), 0 0 0 1px rgba(180, 83, 9, 0.45);
}

body.theme-oled .word-span.active-word {
    background: rgba(245, 158, 11, 0.38);
    color: #ffffff;
    font-weight: inherit;
    transform: none;
    box-shadow: 0 0 14px rgba(245, 158, 11, 0.55), 0 0 0 1px rgba(245, 158, 11, 0.7);
}

.word-span.spoken-word {
    opacity: 0.95;
    background: transparent;
    box-shadow: none;
}

/* RSVP Speed Reader View */
.rsvp-box {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 600px;
    height: 240px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    position: relative;
}

.rsvp-reticle {
    position: relative;
    width: 100%;
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px dashed var(--card-border);
    border-bottom: 1px dashed var(--card-border);
    font-size: 48px;
    font-family: var(--font-mono);
}

.rsvp-reticle::before, .rsvp-reticle::after {
    content: '';
    position: absolute;
    left: 45%;
    width: 2px;
    height: 12px;
    background: var(--accent-color);
}
.rsvp-reticle::before { top: 0; }
.rsvp-reticle::after { bottom: 0; }

.orp-char {
    color: #ef4444;
    font-weight: 700;
}

.rsvp-controls {
    margin-top: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Continuous Reading View */
.continuous-view {
    display: none;
    flex-direction: column;
    max-width: var(--max-reading-width);
    width: 100%;
    gap: 16px;
    padding: 24px 0 80px 0;
    margin: 0 auto;
}

.continuous-paragraph {
    padding: 16px 20px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: calc(var(--font-size) * 0.85);
    line-height: var(--line-height);
    border: 1px solid transparent;
}

.continuous-paragraph:hover {
    background: rgba(255, 255, 255, 0.03);
}

.continuous-paragraph.active {
    background: var(--card-bg);
    border-color: var(--accent-color);
    box-shadow: var(--shadow-glow);
}

/* Bottom Player & Nav Bar */
.bottom-player-bar {
    background: var(--nav-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--card-border);
    /* Safe area inset bottom + generous clearance for ergonomic thumb comfort */
    padding: 12px 24px calc(env(safe-area-inset-bottom, 20px) + 16px) 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
    flex-shrink: 0;
    z-index: 50;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.25);
}

/* Meta row: slide counter, soundwave visualizer, quick speed toggle */
.player-meta-row {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 0 4px;
    min-height: 28px;
}

.player-meta-left {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    z-index: 1;
}

.player-meta-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.player-meta-center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 0;
}

.progress-indicator {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06);
    padding: 3px 10px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    letter-spacing: 0.3px;
    user-select: none;
    -webkit-user-select: none;
}

body.theme-light .progress-indicator {
    background: rgba(0, 0, 0, 0.05);
}

/* Quick Font Size Pill in Player Meta Bar */
.quick-font-pill {
    background: rgba(168, 85, 247, 0.12);
    color: #c084fc;
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 12px;
    padding: 3px 9px;
    font-size: 12px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body.theme-light .quick-font-pill {
    background: rgba(147, 51, 234, 0.08);
    color: #7e22ce;
    border-color: rgba(147, 51, 234, 0.25);
}

.quick-font-pill:hover {
    background: rgba(168, 85, 247, 0.22);
}

.quick-font-pill:active {
    transform: scale(0.92);
}

.font-pill-icon {
    font-weight: 800;
    letter-spacing: -0.5px;
}

/* Quick Font Popover */
.quick-font-popover {
    position: absolute;
    bottom: calc(100% + 12px);
    right: 0;
    min-width: 215px;
    background: var(--nav-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    padding: 12px 14px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: popoverFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
}

@keyframes popoverFadeIn {
    from { opacity: 0; transform: translateY(8px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.font-popover-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    text-align: center;
}

.font-popover-stepper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 4px;
    border: 1px solid var(--card-border);
}

body.theme-light .font-popover-stepper {
    background: rgba(0, 0, 0, 0.04);
}

.font-step-btn {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-color);
    border-radius: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
}

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

.font-step-btn:active {
    transform: scale(0.92);
}

.font-step-value {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-color);
    min-width: 60px;
    text-align: center;
}

.btn-autofit-chip {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 7px 10px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.15s ease;
    font-family: inherit;
}

.btn-autofit-chip:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-autofit-chip.active {
    background: rgba(168, 85, 247, 0.15);
    border-color: rgba(168, 85, 247, 0.4);
    color: #c084fc;
}

body.theme-light .btn-autofit-chip.active {
    background: rgba(147, 51, 234, 0.1);
    color: #7e22ce;
    border-color: rgba(147, 51, 234, 0.3);
}

.autofit-badge {
    font-size: 10px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
}

.btn-autofit-chip.active .autofit-badge {
    background: #a855f7;
    color: #fff;
}

/* Popover Divider */
.popover-divider {
    height: 1px;
    background: var(--card-border);
    margin: 2px 0;
    opacity: 0.6;
}

/* Words Presets Row */
.words-presets-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
}

.words-preset-chip {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 6px 0;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-color);
    cursor: pointer;
    text-align: center;
    transition: all 0.15s ease;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

body.theme-light .words-preset-chip {
    background: rgba(0, 0, 0, 0.04);
}

.words-preset-chip:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-color);
}

.words-preset-chip.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: var(--accent-contrast);
    box-shadow: 0 2px 8px var(--accent-glow);
}

/* Light theme override (body.theme-light .words-preset-chip has higher
   specificity than .active and washed out the accent bg — re-assert it) */
body.theme-light .words-preset-chip.active {
    background: var(--accent-color);
    color: var(--accent-contrast);
}

/* Autofit badge: white on #a855f7 measured 3.95:1 (axe) — dark plum text */
.btn-autofit-chip.active .autofit-badge {
    background: #a855f7;
    color: #1e1033;
}

/* Words Stepper & Manual Input Row */
.words-stepper-row {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 4px;
    border: 1px solid var(--card-border);
}

body.theme-light .words-stepper-row {
    background: rgba(0, 0, 0, 0.04);
}

.words-input-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 0 8px;
    height: 32px;
    box-sizing: border-box;
}

.words-number-input {
    width: 100%;
    min-width: 0;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    font-family: inherit;
    outline: none;
    -moz-appearance: textfield;
}

.words-number-input::-webkit-outer-spin-button,
.words-number-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.words-input-unit {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-left: 4px;
    white-space: nowrap;
    user-select: none;
}

/* Settings Drawer Custom Words Row */
.drawer-custom-words-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.words-apply-btn {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 8px;
    white-space: nowrap;
    height: 32px;
}

.quick-speed-pill {
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent-color);
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: 12px;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.quick-speed-pill:hover {
    background: rgba(56, 189, 248, 0.22);
}

.quick-speed-pill:active {
    transform: scale(0.92);
    background: rgba(56, 189, 248, 0.3);
}

/* Controls Row: Prev, Play, Next */
.player-controls-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    gap: 16px;
}

.player-step-btn {
    flex: 1;
    max-width: 140px;
    padding: 12px 18px;
    border-radius: 16px;
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
    -webkit-user-select: none;
}

.player-step-btn:hover {
    border-color: var(--accent-color);
    box-shadow: var(--shadow-glow);
}

.player-step-btn:active {
    transform: scale(0.94);
    background: var(--highlight-bg);
}

.play-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.play-btn-large {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: var(--accent-color);
    color: var(--accent-contrast);
    border: none;
    cursor: pointer;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 22px var(--accent-glow);
    transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.18s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.play-btn-large:hover {
    transform: scale(1.06);
    box-shadow: 0 8px 28px var(--accent-glow);
}

.play-btn-large:active {
    transform: scale(0.92);
}

/* Audio Visualizer Canvas */
#visualizer-canvas {
    height: 28px;
    width: 120px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.05);
    display: block;
}

body.theme-dark #visualizer-canvas {
    background: rgba(255, 255, 255, 0.04);
}

.drawer-sheet-handle {
    display: none;
}

/* Top Level Progress Bar */
.master-progress-track {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: rgba(0, 0, 0, 0.1);
}

#master-progress-fill {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 0.3s ease;
}

/* Settings & AI Drawer */
.slide-drawer {
    position: fixed;
    top: 0;
    right: -380px;
    width: 360px;
    height: 100vh;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border-left: 1px solid var(--card-border);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    padding: 30px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

.slide-drawer.open {
    right: 0;
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.drawer-title {
    font-size: 1.2rem;
    font-weight: 700;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-group label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
}

/* AI Assistant Result Card */
.ai-card {
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 16px;
    font-size: 14px;
    line-height: 1.6;
}

/* ─── RESPONSIVE / TABLET & NARROW DESKTOP ─────────────────────────────────── */
/* Hide desktop-only inline nav controls (voice dropdown, rate slider) and fullscreen button
   on touch tablets (iPad portrait & landscape) and screens narrower than 1150px
   to prevent 4-column collisions while preserving full access via Settings drawer and player pill */
@media (max-width: 1150px) {
    .desktop-only { display: none !important; }
}

/* ─── RESPONSIVE / MOBILE ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .settings-text { display: none !important; }

    .app-header {
        padding: max(10px, calc(env(safe-area-inset-top) + 6px), calc(var(--safe-top-fallback, 0px) + 6px)) 14px 10px 14px;
        gap: 8px;
    }
    .brand {
        gap: 6px;
        padding: 4px 6px;
    }
    .brand-title {
        font-size: 1.05rem;
    }
    .brand-icon,
    .brand-logo-img {
        width: 24px;
        height: 24px;
        border-radius: 6px;
    }
    .status-badge {
        font-size: 0.68rem;
        padding: 2px 7px;
    }
    .status-text-full {
        display: none !important;
    }
    .status-text-short {
        display: inline !important;
        font-size: 11px;
        font-weight: 600;
    }
    .header-controls {
        gap: 6px;
    }
    .btn-fullscreen {
        padding: 7px 9px;
        border-radius: 12px;
        font-size: 15px;
        min-width: 36px;
        height: 36px;
    }
    .btn-settings {
        padding: 7px 11px;
        border-radius: 12px;
        font-size: 15px;
    }

    /* Setup screen: tighter on mobile */
    #setup-screen {
        padding: 10px 12px max(12px, env(safe-area-inset-bottom)) 12px;
        gap: 10px;
    }

    /* Mode cards: 4 columns on mobile */
    .mode-cards-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }
    .mode-card {
        height: 74px;
        justify-content: center;
        padding: 6px 4px 6px;
        border-radius: 12px;
        gap: 3px;
    }
    .mode-card-icon { font-size: 22px; }
    .mode-card-label { font-size: 11px; }
    .mode-card-sub { font-size: 8px; line-height: 1.1; }

    .input-card {
        padding: 12px 10px;
        gap: 10px;
        border-radius: 16px;
    }
    .input-tabs-nav {
        padding: 3px;
        gap: 3px;
    }
    .input-tab-btn {
        padding: 7px 6px;
        font-size: 12px;
        gap: 4px;
    }
    .input-tab-btn .tab-badge {
        display: none;
    }
    .text-area-toolbar {
        gap: 6px;
    }
    .samples-select-group {
        min-width: 140px;
    }
    .sample-select-label {
        font-size: 11px;
    }
    .sample-dropdown {
        font-size: 11px;
        padding: 4px 22px 4px 8px;
    }
    .btn-clear-text {
        font-size: 11px;
        padding: 4px 8px;
    }
    .dropzone-roomy {
        min-height: 100px;
        padding: 14px 10px;
    }
    .dropzone-inner .dropzone-icon {
        font-size: 24px;
    }
    .dropzone-text {
        display: none;
    }
    .samples-row, .url-samples-row {
        display: flex;
        gap: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        padding-bottom: 4px;
        scrollbar-width: none;
    }
    .samples-row::-webkit-scrollbar, .url-samples-row::-webkit-scrollbar { display: none; }
    .sample-chip {
        flex-shrink: 0;
        font-size: 11px;
        padding: 5px 10px;
    }
    textarea#main-text-input {
        min-height: 110px;
        height: 120px;
        font-size: 16px; /* 16px prevents iOS auto-zoom on focus! */
        padding: 12px;
        line-height: 1.5;
    }
    .input-meta-bar {
        font-size: 12px;
    }
    /* Simplified action row — start & queue buttons on mobile */
    .action-row {
        margin-top: 4px;
        display: flex;
        gap: 8px;
        width: 100%;
    }
    .action-row #start-btn {
        flex: 1.3;
        padding: 14px 10px;
        font-size: 16px;
        font-weight: 700;
        border-radius: 14px;
    }
    .action-row #btn-add-queue {
        flex: 1;
        padding: 14px 8px;
        font-size: 13.5px;
        font-weight: 600;
        border-radius: 14px;
    }

    /* Active Reader Screen Navigation */
    .reader-nav {
        padding: 8px 10px;
        gap: 6px;
        overflow-x: visible;
        flex-shrink: 0;
    }
    .btn-back {
        padding: 6px 9px;
        font-size: 12px;
        flex-shrink: 0;
    }
    .btn-back .back-text {
        font-size: 12px;
    }
    .mode-tabs {
        display: inline-flex;
        align-items: center;
        gap: 3px;
        padding: 2px 3px;
        border-radius: 10px;
        flex-shrink: 0;
    }
    .mode-tab {
        padding: 6px 9px;
        font-size: 14px;
        min-width: 32px;
        justify-content: center;
        border-radius: 8px;
        flex-shrink: 0;
    }
    .mode-tab-label {
        display: none !important;
    }
    .mode-tab-icon {
        font-size: 16px;
        line-height: 1;
    }
    .btn-export-audio {
        padding: 6px 8px;
        font-size: 12px;
        gap: 4px;
        border-radius: 9px;
        flex-shrink: 0;
    }
    .btn-focus-mode {
        padding: 6px 8px;
        font-size: 12px;
        gap: 4px;
        border-radius: 9px;
        flex-shrink: 0;
    }

    .viewport-container {
        padding: 14px 12px;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .slide-card {
        padding: 20px 16px;
        min-height: auto;
        max-height: none;
        margin: auto 0;
        display: block;
        border-radius: 18px;
        overflow: visible;
    }
    .slide-content-text {
        text-align: left !important;
        font-size: clamp(15px, calc(var(--slide-font-size, var(--font-size)) * 0.78), 32px) !important;
        line-height: 1.62;
        letter-spacing: 0.01em;
        word-break: normal;
        overflow-wrap: break-word;
        hyphens: manual;
    }

    /* RSVP & Continuous Mode Responsiveness on Mobile */
    .rsvp-box {
        width: 100%;
        max-width: 95%;
        height: auto;
        min-height: 190px;
        padding: 16px 12px;
        margin: auto 0;
    }
    .rsvp-reticle {
        font-size: clamp(26px, 7.5vw, 42px);
        height: 75px;
    }
    .rsvp-controls {
        margin-top: 14px;
        gap: 10px;
        font-size: 13px;
        flex-wrap: wrap;
        justify-content: center;
    }
    .rsvp-controls input[type="range"] {
        width: 110px;
    }
    .continuous-view {
        padding: 12px 6px calc(env(safe-area-inset-bottom, 20px) + 90px) 6px;
        gap: 12px;
    }
    .continuous-paragraph {
        padding: 14px 16px;
        font-size: clamp(15px, calc(var(--slide-font-size, var(--font-size)) * 0.76), 28px) !important;
        line-height: 1.68;
        border-radius: 14px;
    }

    /* Bottom Player Bar: Elevated for iOS Home Indicator */
    .bottom-player-bar {
        padding: 10px 14px calc(env(safe-area-inset-bottom, 20px) + 16px) 14px;
        gap: 8px;
    }
    .player-meta-row {
        padding: 0 4px;
    }
    .quick-font-popover {
        right: -6px;
        min-width: 215px;
        max-width: 270px;
    }
    #visualizer-canvas {
        width: 70px;
        height: 26px;
    }
    .player-controls-row {
        gap: 12px;
    }
    .player-step-btn {
        padding: 11px 14px;
        max-width: 110px;
        font-size: 13px;
    }
    .play-btn-large {
        width: 56px;
        height: 56px;
        font-size: 22px;
    }

    /* iOS Bottom Sheet Modal Drawer */
    .drawer-sheet-handle {
        display: block;
        width: 44px;
        height: 5px;
        background: rgba(255, 255, 255, 0.28);
        border-radius: 3px;
        margin: 0 auto 10px auto;
        cursor: pointer;
    }
    body.theme-light .drawer-sheet-handle {
        background: rgba(0, 0, 0, 0.22);
    }
    .slide-drawer {
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: 85dvh !important;
        border-left: none !important;
        border-top: 1px solid var(--card-border) !important;
        border-radius: 24px 24px 0 0 !important;
        transform: translateY(102%) !important;
        transition: transform 0.36s cubic-bezier(0.16, 1, 0.3, 1) !important;
        padding: 14px 20px calc(env(safe-area-inset-bottom, 20px) + 20px) 20px !important;
        box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.6) !important;
    }
    .slide-drawer.open {
        transform: translateY(0) !important;
    }
}

/* Extra small phones (iPhone 6s, SE) */
@media (max-width: 375px) {
    .mode-cards-grid {
        gap: 4px;
    }
    .mode-card {
        padding: 8px 2px 6px;
        border-radius: 10px;
    }
    .mode-card-icon { font-size: 18px; }
    .mode-card-label { font-size: 9.5px; }
    .mode-card-sub { display: none; }

    /* Compact header and reader-nav on 375px and narrower */
    .header-controls {
        gap: 4px;
    }
    .btn-fullscreen {
        padding: 6px 7px;
        font-size: 14px;
        min-width: 32px;
        height: 32px;
    }
    .btn-playlist .playlist-text {
        display: none;
    }
    .btn-back {
        padding: 5px 7px;
    }
    .btn-export-audio {
        padding: 5px 7px;
    }
    .btn-focus-mode {
        padding: 5px 7px;
    }
    .btn-focus-mode .focus-btn-text {
        display: none;
    }
}

/* ─── DRAWER BACKDROP ──────────────────────────────────────────────────────── */
.drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}
.drawer-backdrop.active {
    display: block;
}

/* ─── PWA INSTALL BANNER ───────────────────────────────────────────────────── */
.pwa-install-banner {
    position: fixed;
    bottom: max(16px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(120%);
    width: calc(100% - 32px);
    max-width: 480px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1100;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px var(--card-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.pwa-install-banner--visible {
    transform: translateX(-50%) translateY(0);
}

.pwa-install-banner--hiding {
    transform: translateX(-50%) translateY(130%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 1, 1);
}

.pwa-banner-icon {
    font-size: 28px;
    flex-shrink: 0;
    filter: drop-shadow(0 2px 8px var(--accent-glow));
}

.pwa-banner-body {
    flex: 1;
    min-width: 0;
}

.pwa-banner-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 3px;
}

.pwa-banner-sub {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.pwa-share-icon {
    display: inline-block;
    font-size: 13px;
}

.pwa-banner-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.pwa-btn-install {
    background: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 2px 10px var(--accent-glow);
    transition: opacity 0.15s;
}
.pwa-btn-install:active { opacity: 0.8; }

.pwa-btn-dismiss {
    background: none;
    border: 1px solid var(--card-border);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    flex-shrink: 0;
    transition: background 0.15s;
}
.pwa-btn-dismiss:active { background: var(--highlight-bg); }

/* ─── SHARE BUTTON VISIBILITY ─────────────────────────────────────────────── */
@media (max-width: 768px) {
    #share-btn {
        display: inline-flex !important;
    }
}

/* ─── REDUCED MOTION ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* ─── APP FOOTER ─────────────────────────────────────────────────────────── */
.app-footer {
    margin-top: 20px;
    padding: 16px 8px 10px;
    border-top: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    width: 100%;
}

.footer-links {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px 12px;
}

.footer-link-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    text-decoration: none;
}

.footer-link-btn:hover {
    color: var(--accent-color);
    background: rgba(56, 189, 248, 0.08);
}

.footer-sep {
    color: var(--card-border);
    font-size: 11px;
    user-select: none;
}

.footer-bottom {
    font-size: 11.5px;
    color: var(--text-muted);
    opacity: 0.85;
}

#top-ge-counter-container {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 4px;
    min-height: 31px;
    min-width: 88px;
}

#top-ge-counter-container img {
    width: 88px;
    height: 31px;
    display: block;
    aspect-ratio: 88 / 31;
}

/* ─── INFO MODAL ─────────────────────────────────────────────────────────── */
.info-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.info-modal-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.info-modal {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 720px;
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
    transform: scale(0.94) translateY(12px);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

.info-modal-backdrop.active .info-modal {
    transform: scale(1) translateY(0);
}

.info-modal-header {
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--card-border);
    background: rgba(255, 255, 255, 0.02);
}

.info-modal-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.info-modal-icon {
    font-size: 20px;
}

.info-modal-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-color);
}

.info-modal-close {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.info-modal-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.18);
    border-bottom: 1px solid var(--card-border);
    overflow-x: auto;
    scrollbar-width: none;
}

.info-modal-tabs::-webkit-scrollbar {
    display: none;
}

.info-tab-btn {
    flex: 1;
    min-width: 110px;
    padding: 12px 10px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    text-align: center;
    transition: all 0.2s;
}

.info-tab-btn:hover {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.03);
}

.info-tab-btn.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
    background: rgba(56, 189, 248, 0.06);
}

.info-modal-body {
    padding: 22px 24px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
}

.info-tab-panel {
    display: none;
    animation: fadeInModalTab 0.2s ease-out;
}

.info-tab-panel.active {
    display: block;
}

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

.info-callout {
    background: rgba(56, 189, 248, 0.08);
    border-left: 3px solid var(--accent-color);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-color);
}

.info-callout-warning {
    background: rgba(234, 179, 8, 0.08);
    border-left: 3px solid #eab308;
}

.info-section-title {
    font-size: 14.5px;
    font-weight: 700;
    color: var(--accent-color);
    margin: 16px 0 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.info-text {
    font-size: 13.5px;
    line-height: 1.65;
    color: var(--text-color);
    margin-bottom: 10px;
    opacity: 0.92;
}

.info-list {
    margin: 6px 0 14px 20px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-color);
}

.info-list li {
    margin-bottom: 5px;
}

.info-external-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 14px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--accent-color);
    text-decoration: none;
}

.info-external-link:hover {
    text-decoration: underline;
}

.modal-faq-item {
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.02);
    overflow: hidden;
    transition: border-color 0.2s;
}

.modal-faq-item:hover {
    border-color: var(--accent-color);
}

.modal-faq-header {
    padding: 11px 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 600;
    user-select: none;
}

.modal-faq-chevron {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.25s ease;
}

.modal-faq-item.open .modal-faq-chevron {
    transform: rotate(180deg);
    color: var(--accent-color);
}

.modal-faq-body {
    padding: 0 14px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0, 1, 0, 1), padding 0.25s ease;
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--text-color);
    opacity: 0.9;
}

.modal-faq-item.open .modal-faq-body {
    padding: 0 14px 12px;
    max-height: 400px;
    transition: max-height 0.35s ease-in, padding 0.25s ease;
}

.info-modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.02);
}

.info-modal-version {
    font-size: 12px;
    color: var(--text-muted);
}

@media (max-width: 600px) {
    .info-modal {
        max-height: 90vh;
        border-radius: var(--radius-md);
    }
    .info-modal-body {
        padding: 16px;
    }
    .info-tab-btn {
        padding: 10px 6px;
        font-size: 12px;
        min-width: 85px;
    }
}

/* Floating Notification Toast */
.srp-toast {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(15, 23, 42, 0.92);
    color: #f8fafc;
    border: 1px solid rgba(56, 189, 248, 0.35);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 0 15px rgba(56, 189, 248, 0.2);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 10px 20px;
    border-radius: 9999px;
    font-size: 13.5px;
    font-weight: 500;
    z-index: 99999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
    max-width: 90vw;
    text-overflow: ellipsis;
    overflow: hidden;
}

body.theme-light .srp-toast {
    background: rgba(255, 255, 255, 0.94);
    color: #0f172a;
    border-color: rgba(56, 189, 248, 0.5);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 0 15px rgba(56, 189, 248, 0.15);
}

.srp-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ─── PLAYLIST / READING QUEUE & LIBRARY ──────────────────────────────────── */
.btn-playlist {
    position: relative;
    padding: 8px 13px;
    border-radius: 12px;
    font-size: 13.5px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-playlist:hover {
    border-color: var(--accent-color);
    box-shadow: var(--shadow-glow);
}
.btn-playlist .playlist-icon {
    font-size: 16px;
}
.playlist-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    border-radius: 10px;
    background: var(--accent-color);
    color: var(--accent-contrast);
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}
.playlist-badge:empty, .playlist-badge[data-count="0"] {
    display: none;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-color);
    border: 1px solid var(--card-border);
}
.btn-secondary:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

/* Playlist Drawer Styles */
#playlist-drawer {
    width: 390px;
    max-width: 94vw;
}

.playlist-summary-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
}

.playlist-summary-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.playlist-total-time {
    font-weight: 700;
    color: var(--accent-color);
    display: flex;
    align-items: center;
    gap: 5px;
}

.playlist-summary-actions {
    display: flex;
    gap: 6px;
}

.btn-playlist-action {
    padding: 5px 9px;
    font-size: 11.5px;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.btn-playlist-action:hover {
    color: var(--text-color);
    border-color: var(--accent-color);
}

.playlist-items-container {
    display: flex;
    flex-direction: column;
    gap: 9px;
    overflow-y: auto;
    padding-right: 4px;
    flex: 1;
}

.playlist-item {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 11px 12px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    transition: all 0.2s ease;
    position: relative;
}

.playlist-item:hover {
    border-color: rgba(56, 189, 248, 0.4);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}

.playlist-item.active {
    border-color: var(--accent-color);
    background: rgba(56, 189, 248, 0.08);
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.2);
}

.playlist-item.completed {
    opacity: 0.82;
}

.playlist-item-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.playlist-item-title-group {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 1;
    min-width: 0;
}

.playlist-item-num {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-muted);
    min-width: 18px;
}

.playlist-item-title {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.playlist-item.active .playlist-item-title {
    color: var(--accent-color);
}

.playlist-item-duration {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 6px;
    border-radius: 6px;
    white-space: nowrap;
}

.playlist-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11.5px;
    color: var(--text-muted);
}

.playlist-item-progress-text {
    font-size: 11px;
    color: var(--text-muted);
}

.playlist-item-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-item-ctrl {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    padding: 3px 5px;
    border-radius: 6px;
    transition: all 0.15s;
    font-family: inherit;
}
.btn-item-ctrl:hover {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.1);
}
.btn-item-ctrl.play-now {
    color: var(--accent-color);
    font-weight: 700;
    font-size: 14px;
}

.playlist-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 16px;
    color: var(--text-muted);
    gap: 12px;
}
.playlist-empty-icon {
    font-size: 40px;
    opacity: 0.85;
}
.playlist-empty-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-color);
}
.playlist-empty-desc {
    font-size: 12.5px;
    line-height: 1.5;
}

/* Reader navigation queue button */
.btn-reader-queue {
    padding: 6px 11px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s;
}
.btn-reader-queue:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

/* Playlist Toolbar & Import/Export Styles */
.playlist-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 2px;
}

.btn-playlist-tool {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 10px;
    font-size: 11.5px;
    font-weight: 600;
    border-radius: 8px;
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.25);
    color: var(--accent-color);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-playlist-tool:hover {
    background: rgba(56, 189, 248, 0.16);
    border-color: var(--accent-color);
    transform: translateY(-1px);
}

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

/* Playlist Import Modal */
.playlist-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: playlistFadeIn 0.2s ease-out;
}

.playlist-modal-card {
    background: var(--card-bg, #1e293b);
    border: 1px solid var(--card-border, rgba(255, 255, 255, 0.12));
    border-radius: var(--radius-lg, 16px);
    width: 100%;
    max-width: 440px;
    padding: 20px 22px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 14px;
    animation: playlistScaleUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.playlist-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.playlist-modal-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.playlist-modal-desc {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 0;
}

.playlist-modal-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-playlist-choice {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 12px 14px;
    border-radius: var(--radius-md, 12px);
    border: 1px solid var(--card-border, rgba(255, 255, 255, 0.12));
    background: rgba(255, 255, 255, 0.04);
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: all 0.2s ease;
    width: 100%;
}

.btn-playlist-choice:hover {
    border-color: var(--accent-color);
    background: rgba(56, 189, 248, 0.09);
    transform: translateY(-1px);
}

.btn-playlist-choice .choice-title {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--text-color);
}

.btn-playlist-choice .choice-subtitle {
    font-size: 11.5px;
    color: var(--text-muted);
    line-height: 1.35;
}

@keyframes playlistFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes playlistScaleUp {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* ─── WCAG AA contrast fixes (axe: color-contrast) ───────────────────────
   Sepia's --text-muted sat at ~3.5:1 on its cards, nordic's chips at 4.4:1
   and nordic's selected mode cards at 4.0:1 — all below the AA 4.5:1 floor.
   Kept at the END of the file so these values win over the theme blocks. */
body.theme-sepia { --text-muted: #6b5540; }
body.theme-nordic {
    --text-muted: #e5e9f0;
    --highlight-bg: rgba(136, 192, 208, 0.18);
}
/* Online status badge: the default #10b981 green measured 1.89:1 on sepia's
   tan header and 4.48:1 on nordic's dark-teal header (axe, reader scan). */
body.theme-sepia .status-badge:not(.offline) {
    color: #065f46;
    border-color: rgba(6, 95, 70, 0.35);
}
body.theme-nordic .status-badge:not(.offline) {
    color: #6ee7b7;
    border-color: rgba(110, 231, 183, 0.3);
}

/* Sepia: the offline badge's amber was 1.55:1 on its tan background */
body.theme-sepia .status-badge.offline {
    color: #92400e;
    border-color: rgba(146, 64, 14, 0.35);
}
/* Light theme online badge: #047857 on its mint background measured 4.47:1 */
body.theme-light .status-badge {
    color: #046b4e;
    border-color: rgba(4, 107, 78, 0.35);
}

/* The karaoke highlight (amber wash) needs local text colours per theme —
   white on it measured 2-3:1 in the light-background themes. */
body.theme-sepia .word-span.active-word { background: rgba(180, 83, 9, 0.28); color: #2c1810; }
body.theme-nordic .word-span.active-word { background: rgba(136, 192, 208, 0.28); color: #1b2430; }

/* Reader top-bar pills: accent/purple labels on the light sepia tints were
   1.95–3.95:1. Sepia needs its darker shades (accent-hover 5.6:1, purple-800
   5.2–6.5:1); nordic already passes with the defaults. */
body.theme-sepia .btn-export-audio,
body.theme-sepia .quick-speed-pill,
body.theme-sepia .btn-autofit-chip {
    color: #92400e;
}

body.theme-sepia .quick-font-pill,
body.theme-sepia .quick-font-pill .font-pill-icon {
    color: #6b21a8;
}

/* ═══════════════════════════════════════════════════════════════════════
   YOUTUBE PRESENTATION MODE
   Clean, cinematic reading experience optimized for screen recording.
   Two formats: Video (16:9) and Shorts (9:16).
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── Chrome Hiding ─────────────────────────────────────────────────── */
#reader-screen.youtube-mode .reader-nav,
#reader-screen.youtube-mode .bottom-player-bar,
#reader-screen.youtube-mode .master-progress-track {
    display: none !important;
}

/* Hide the global app header when YouTube mode is active */
body.yt-mode-active .app-header {
    display: none !important;
}

/* ─── The Reader Screen — Fixed Full Cinema Viewport ─────────────────── */
#reader-screen.youtube-mode {
    position: fixed !important;
    inset: 0 !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 9999 !important;
    background: #000000 !important;
    color: #f8fafc !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* ─── Viewport — Full-screen Centering ──────────────────────────────── */
#reader-screen.youtube-mode .viewport-container {
    flex: 1 1 0% !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    background: #000000 !important;
    overflow: hidden !important;
}

/* ─── Slide Card — Cinematic Styling & Perfect Vertical Centering ───── */
#reader-screen.youtube-mode .slide-card {
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    max-width: 100% !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 100% !important;
    margin: 0 !important;
    padding: 70px 24px 100px !important;
    background: transparent !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    animation: none !important;
    box-sizing: border-box !important;
}

/* ─── Text — Centered Cinematic Typography (Theme-Independent Bright) ─ */
#reader-screen.youtube-mode,
#reader-screen.youtube-mode .slide-card,
#reader-screen.youtube-mode .slide-content-text {
    color: #f8fafc !important;
}

#reader-screen.youtube-mode .slide-content-text {
    text-align: center !important;
    max-width: 82% !important;
    margin: auto 0 !important;
    line-height: 1.85 !important;
    letter-spacing: 0.02em !important;
    text-shadow: 0 2px 14px rgba(0, 0, 0, 0.7) !important;
    color: #f8fafc !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
}

/* ─── 16:9 VIDEO Layout ─────────────────────────────────────────────── */
#reader-screen.youtube-mode.yt-video .viewport-container {
    width: 100% !important;
    height: 100% !important;
}

#reader-screen.youtube-mode.yt-video .slide-content-text {
    font-size: var(--yt-font-size, clamp(22px, 3.4vw, 48px)) !important;
    max-width: 80% !important;
}

/* ─── 9:16 SHORTS Layout ────────────────────────────────────────────── */
#reader-screen.youtube-mode.yt-shorts .viewport-container {
    max-width: min(56.25vh, 100vw) !important;
    height: 100% !important;
    margin: 0 auto !important;
    border-left: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.1) !important;
    background: #000000 !important;
}

#reader-screen.youtube-mode.yt-shorts .slide-content-text {
    font-size: var(--yt-font-size, clamp(22px, 5.6vw, 38px)) !important;
    max-width: 90% !important;
    line-height: 1.65 !important;
    letter-spacing: 0.015em !important;
}

/* ─── YouTube Overlay ───────────────────────────────────────────────── */
.yt-overlay {
    position: absolute;
    inset: 0;
    z-index: 100;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Title Bar (top) - completely hidden in YouTube presentation mode for clean video */
.yt-title-bar {
    display: none !important;
}

/* Top Controls (Slide counter + Quick exit button, auto-hides for clean screen recording) */
.yt-top-controls {
    position: absolute;
    top: max(16px, env(safe-area-inset-top, 16px));
    right: max(16px, env(safe-area-inset-right, 16px));
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 106;
    pointer-events: auto;
    transition: opacity 0.35s ease, transform 0.35s ease;
}

#reader-screen.youtube-mode.yt-cursor-hidden .yt-top-controls {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translateY(-8px);
}

.yt-slide-number {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.65);
    font-variant-numeric: tabular-nums;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 4px 10px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.yt-top-exit-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    touch-action: manipulation;
    padding: 0;
}

.yt-top-exit-btn:hover {
    background: rgba(239, 68, 68, 0.6);
    border-color: #ef4444;
    transform: scale(1.08);
}

.yt-top-exit-btn:active {
    transform: scale(0.92);
}

/* Progress Bar (bottom) */
.yt-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(255, 255, 255, 0.15);
    z-index: 102;
}

.yt-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #38bdf8, #818cf8);
    border-radius: 0 2px 2px 0;
    transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.5);
}

/* ─── Floating Controls (center, auto-hide, iOS Safe Area) ─────────── */
.yt-floating-controls {
    position: absolute;
    bottom: max(32px, calc(env(safe-area-inset-bottom, 0px) + 24px));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 22px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    pointer-events: auto;
    opacity: 1;
    transition: opacity 0.4s ease, transform 0.3s ease;
    z-index: 103;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.65);
}

.yt-floating-controls.yt-controls-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(12px);
}

.yt-ctrl-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.yt-ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.22);
    transform: scale(1.08);
}

.yt-ctrl-btn:active {
    transform: scale(0.94);
}

.yt-exit-btn {
    background: rgba(239, 68, 68, 0.25);
    color: #fca5a5;
    font-weight: 700;
}

.yt-exit-btn:hover {
    background: rgba(239, 68, 68, 0.45);
}

.yt-record-btn {
    color: #ef4444;
    transition: all 0.25s ease;
}

.yt-record-btn:hover {
    background: rgba(239, 68, 68, 0.25);
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.5);
}

.yt-record-btn.recording {
    background: rgba(239, 68, 68, 0.4) !important;
    border: 1.5px solid #ef4444 !important;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.7) !important;
    animation: ytPulseRec 1.2s infinite ease-in-out;
}

/* ─── Recording Indicator Badge ─────────────────────────────────────── */
.yt-record-badge {
    position: absolute;
    top: max(16px, env(safe-area-inset-top, 16px));
    left: max(16px, env(safe-area-inset-left, 16px));
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 20px;
    background: rgba(220, 38, 38, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(239, 68, 68, 0.6);
    color: #fca5a5;
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    z-index: 105;
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.4);
    animation: ytFadeIn 0.3s ease;
    pointer-events: auto;
}

.yt-rec-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 8px #ef4444;
    animation: ytPulseRec 1.2s infinite ease-in-out;
}

.yt-rec-text {
    font-size: 11px;
    opacity: 0.85;
    letter-spacing: 0.05em;
}

@keyframes ytPulseRec {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.18); opacity: 0.6; }
}

.yt-ctrl-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.2);
    margin: 0 4px;
}

/* ─── Cursor Auto-Hide ──────────────────────────────────────────────── */
#reader-screen.youtube-mode.yt-cursor-hidden,
#reader-screen.youtube-mode.yt-cursor-hidden * {
    cursor: none !important;
}

/* ─── YouTube Word Highlighting (Silky smooth, zero layout shift) ───── */
#reader-screen.youtube-mode .word-span {
    color: rgba(248, 250, 252, 0.78) !important;
    display: inline-block !important;
    padding: 2px 5px !important;
    margin: 0 1px !important;
    border-radius: 6px !important;
    box-sizing: border-box !important;
    transform: none !important;
    transition: color 0.16s ease, background-color 0.16s ease, box-shadow 0.16s ease !important;
}

#reader-screen.youtube-mode .word-span.spoken-word {
    color: rgba(248, 250, 252, 0.4) !important;
    background: transparent !important;
    box-shadow: none !important;
}

#reader-screen.youtube-mode .word-span.active-word {
    background: rgba(245, 158, 11, 0.35) !important;
    color: #ffffff !important;
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8) !important;
    box-shadow: 0 0 14px rgba(245, 158, 11, 0.5), 0 0 0 1px rgba(245, 158, 11, 0.6) !important;
    border-radius: 6px !important;
    transform: none !important;
    display: inline-block !important;
}

/* ─── Format Picker Modal (Always High Contrast Slate Dark) ─────────── */
.yt-format-picker-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: ytFadeIn 0.25s ease;
    padding: 20px;
}

.yt-format-picker-content {
    background: #0f172a !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 24px;
    padding: 32px 28px;
    max-width: 440px;
    width: 100%;
    text-align: center;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.1);
    animation: ytSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    color: #f8fafc !important;
    box-sizing: border-box;
}

.yt-format-title {
    font-size: 22px;
    font-weight: 800;
    color: #ffffff !important;
    margin-bottom: 8px;
}

.yt-format-desc {
    font-size: 14px;
    line-height: 1.5;
    color: #94a3b8 !important;
    margin-bottom: 24px;
}

.yt-format-options {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 24px;
}

.yt-format-option {
    flex: 1;
    padding: 20px 14px;
    border-radius: 18px;
    border: 2px solid rgba(255, 255, 255, 0.14) !important;
    background: #1e293b !important;
    cursor: pointer;
    transition: all 0.22s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: #f8fafc !important;
    text-align: center;
    touch-action: manipulation;
}

.yt-format-option:hover,
.yt-format-option:focus-visible {
    border-color: #38bdf8 !important;
    background: #1e3a5f !important;
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(56, 189, 248, 0.25);
}

.yt-format-option:active {
    transform: translateY(0);
}

.yt-format-preview {
    border-radius: 10px;
    background: #090d16 !important;
    border: 1.5px solid rgba(56, 189, 248, 0.4) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 800;
    color: #38bdf8 !important;
    font-variant-numeric: tabular-nums;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6);
}

.yt-preview-landscape {
    width: 100px;
    height: 56px; /* 16:9 */
}

.yt-preview-portrait {
    width: 56px;
    height: 100px; /* 9:16 */
}

.yt-format-label {
    font-size: 16px;
    font-weight: 700;
    color: #ffffff !important;
}

.yt-format-size {
    font-size: 12px;
    font-weight: 500;
    color: #94a3b8 !important;
}

.yt-format-cancel {
    width: 100%;
    padding: 13px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.16) !important;
    background: rgba(255, 255, 255, 0.06) !important;
    color: #cbd5e1 !important;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
}

.yt-format-cancel:hover {
    background: rgba(255, 255, 255, 0.12) !important;
    color: #ffffff !important;
}

/* ─── YouTube Mode Button Styling ───────────────────────────────────── */
.btn-youtube-mode {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 700;
    border-radius: var(--radius-md);
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.4);
    white-space: nowrap;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
}

.btn-youtube-mode:hover {
    background: rgba(239, 68, 68, 0.25);
    border-color: #ef4444;
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.45);
    transform: translateY(-1px);
}

.btn-youtube-mode:active {
    transform: scale(0.95);
}

.btn-youtube-mode .yt-btn-icon {
    font-size: 15px;
    line-height: 1;
}

.btn-youtube-mode .yt-btn-text {
    font-size: 12.5px;
    letter-spacing: 0.02em;
}

body.theme-light .btn-youtube-mode {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fca5a5;
}

body.theme-light .btn-youtube-mode:hover {
    background: #fecaca;
    box-shadow: 0 0 16px rgba(220, 38, 38, 0.25);
}

/* ─── Animations ────────────────────────────────────────────────────── */
@keyframes ytFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes ytSlideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── YouTube Mode — Mobile Overrides ───────────────────────────────── */
@media (max-width: 768px) {
    #reader-screen.youtube-mode .slide-card {
        padding: max(60px, calc(env(safe-area-inset-top, 0px) + 50px)) 16px max(90px, calc(env(safe-area-inset-bottom, 0px) + 70px)) !important;
    }

    #reader-screen.youtube-mode .slide-content-text {
        max-width: 92% !important;
        text-align: center !important;
        font-size: var(--yt-font-size, clamp(18px, 5.2vw, 32px)) !important;
    }

    #reader-screen.youtube-mode.yt-shorts .viewport-container {
        max-width: 100vw !important;
        border: none !important;
    }

    .yt-floating-controls {
        bottom: max(28px, calc(env(safe-area-inset-bottom, 0px) + 20px)) !important;
        padding: 8px 12px !important;
        gap: 6px !important;
        border-radius: 20px !important;
    }

    .yt-ctrl-btn {
        width: 38px !important;
        height: 38px !important;
        font-size: 16px !important;
    }

    .yt-format-picker-content {
        padding: 24px 18px !important;
        border-radius: 20px !important;
    }

    .yt-format-options {
        gap: 12px !important;
    }

    .yt-format-option {
        padding: 16px 10px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/* ─── FOCUS / ZEN MODE (100% Theme Harmony & Immersive Reading) ──────────── */
/* ═══════════════════════════════════════════════════════════════════════════ */

/* Hide non-reading UI elements when Focus Mode is active */
body.focus-mode-active .app-header,
body.focus-mode-active .reader-nav,
body.focus-mode-active .bottom-player-bar,
body.focus-mode-active .pwa-install-banner,
body.focus-mode-active .drawer-backdrop {
    display: none !important;
}

/* Fullscreen Reader Container — 100% inherits the active theme's background */
body.focus-mode-active #reader-screen {
    position: fixed !important;
    inset: 0 !important;
    z-index: 9999 !important;
    width: 100vw !important;
    height: 100dvh !important;
    padding: 0 !important;
    margin: 0 !important;
    background: var(--bg-color) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    user-select: none;
    -webkit-user-select: none;
}

/* Central Viewport in Focus Mode */
body.focus-mode-active .viewport-container {
    flex: 1 !important;
    width: 100% !important;
    max-width: 1080px !important;
    margin: 0 auto !important;
    padding: max(74px, calc(env(safe-area-inset-top) + 64px)) 24px max(96px, calc(env(safe-area-inset-bottom) + 76px)) 24px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    border: none !important;
    background: transparent !important;
    box-sizing: border-box !important;
}

/* Default: Authentic Slide Card Presentation (100% Theme Harmony) */
body.focus-mode-active .slide-card {
    width: 100% !important;
    max-width: var(--max-reading-width, 860px) !important;
    min-height: 220px;
    background: var(--card-bg) !important;
    border: 1px solid var(--card-border) !important;
    border-radius: var(--radius-lg, 16px) !important;
    box-shadow: var(--shadow-soft) !important;
    padding: 38px 46px !important;
    margin: auto 0 !important;
    display: block !important;
    box-sizing: border-box !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    transition: all 0.25s ease !important;
}

body.focus-mode-active .slide-content-text {
    width: 100% !important;
    text-align: left !important;
    color: var(--text-color) !important;
    font-family: var(--font-family) !important;
    font-size: var(--slide-font-size, var(--font-size, 26px)) !important;
    line-height: var(--line-height, 1.8) !important;
    text-wrap: pretty !important;
    hyphens: auto !important;
    word-break: break-word !important;
}

/* Optional Layout Choice: Centered / Minimalist Frameless */
body.focus-mode-active.focus-style-centered .slide-card {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    padding: 12px 0 !important;
    max-width: 900px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

body.focus-mode-active.focus-style-centered .slide-content-text {
    text-align: center !important;
    font-size: clamp(24px, 4.5vw, 42px) !important;
    line-height: 1.75 !important;
}

@media (max-width: 600px) {
    body.focus-mode-active .viewport-container {
        padding: max(64px, calc(env(safe-area-inset-top) + 54px)) 16px max(86px, calc(env(safe-area-inset-bottom) + 66px)) 16px !important;
    }
    body.focus-mode-active .slide-card {
        padding: 24px 20px !important;
        min-height: 180px;
        border-radius: 14px !important;
    }
    body.focus-mode-active.focus-style-centered .slide-card {
        padding: 8px 0 !important;
    }
    .focus-layout-btn .focus-layout-text {
        display: none;
    }
}

/* ─── Focus Floating Overlay ─────────────────────────────────────────────── */
.focus-overlay {
    position: fixed !important;
    inset: 0 !important;
    pointer-events: none;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: max(16px, calc(env(safe-area-inset-top) + 10px)) max(18px, env(safe-area-inset-right)) max(18px, calc(env(safe-area-inset-bottom) + 10px)) max(18px, env(safe-area-inset-left));
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Controls fade out automatically during playback */
.focus-overlay.focus-controls-hidden {
    opacity: 0;
    pointer-events: none !important;
}

/* Top Bar: Counter + Layout Switcher + Close */
.focus-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    pointer-events: auto;
    z-index: 10001;
}

.focus-top-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.focus-counter {
    font-size: 13px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 20px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    letter-spacing: 0.5px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.focus-layout-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 20px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-color);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.focus-layout-btn:hover {
    background: var(--highlight-bg);
    border-color: var(--accent-color);
    transform: scale(1.05);
}

.focus-layout-btn:active {
    transform: scale(0.95);
}

.focus-close-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 1.5px solid var(--card-border);
    color: var(--text-color);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
}

.focus-close-btn:hover {
    background: var(--accent-color);
    color: #ffffff;
    border-color: var(--accent-color);
    transform: scale(1.08);
}

.focus-close-btn:active {
    transform: scale(0.95);
}

/* Bottom Floating Pill (Glassmorphism + Theme Harmony) */
.focus-floating-bar {
    align-self: center;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 22px;
    border-radius: 40px;
    background: var(--card-bg);
    border: 1.5px solid var(--card-border);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.25), 0 0 0 1px var(--card-border);
    pointer-events: auto;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 10001;
    margin-bottom: max(14px, env(safe-area-inset-bottom));
}

.focus-ctrl-btn {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 20px;
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.focus-ctrl-btn:hover {
    background: var(--highlight-bg);
    color: var(--accent-color);
    transform: scale(1.1);
}

.focus-ctrl-btn:active {
    transform: scale(0.92);
}

.focus-play-btn {
    width: 52px;
    height: 52px;
    background: var(--accent-color) !important;
    color: #ffffff !important;
    font-size: 24px;
    box-shadow: 0 4px 18px var(--accent-glow);
}

.focus-play-btn:hover {
    background: var(--accent-hover) !important;
    color: #ffffff !important;
    transform: scale(1.08);
    box-shadow: 0 6px 24px var(--accent-glow);
}

