        :root {
            --primary: #0891b2;
            --secondary: #164e63;
            --accent: #22d3ee;
            --bg-dark: #0c1222;
            --bg-card: #151d2e;
            --header-bg: #0f172a;
            --text-primary: #f1f5f9;
            --text-secondary: #94a3b8;
            --user-bubble-bg: #0891b2;
            --user-bubble-text: #ffffff;
            --agent-bubble-bg: #1e293b;
            --agent-bubble-text: #f1f5f9;
            --input-bg: #1e293b;
            --input-border: #334155;
            --input-text: #f1f5f9;
            --border-radius: 1rem;
            --bubble-radius: 1.25rem;
            --button-radius: 0.75rem;
            --input-radius: 0.75rem;
            --font-family: 'DM Sans', sans-serif;
            --font-mono: 'Space Mono', monospace;
            --body-size: 14px;
            --line-height: 1.6;
            --success: #34d399;
            --warning: #f59e0b;
            --error: #ef4444;
            --pattern-opacity: 0.05;
            --pattern-color: var(--text-secondary);
        }

        /* ── Light mode overrides ─────────────────────────────────────── */
        [data-theme="light"] {
            --bg-dark: #ffffff;
            --bg-card: #f8fafc;
            --header-bg: #ffffff;
            --text-primary: #1e293b;
            --text-secondary: #64748b;
            --user-bubble-text: #ffffff;
            --agent-bubble-bg: #f1f5f9;
            --agent-bubble-text: #1e293b;
            --input-bg: #ffffff;
            --input-border: #e2e8f0;
            --input-text: #1e293b;
        }

        [data-theme="light"] .glass-card {
            background: var(--bg-card);
            backdrop-filter: none;
            border: 1px solid var(--input-border);
            box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
        }

        [data-theme="light"] ::-webkit-scrollbar-track {
            background: #f1f5f9;
        }

        [data-theme="light"] ::-webkit-scrollbar-thumb {
            background: #cbd5e1;
        }

        [data-theme="light"] ::-webkit-scrollbar-thumb:hover {
            background: #94a3b8;
        }

        /* ── Utility modifier classes ─────────────────────────────────── */

        /* Remove glassmorphism: solid background, no blur */
        .no-glass .glass-card {
            background: var(--bg-card);
            backdrop-filter: none;
            -webkit-backdrop-filter: none;
        }

        /* Remove all box-shadows */
        .no-shadows *,
        .no-shadows .glass-card,
        .no-shadows .glow-button,
        .no-shadows .notif-dropdown {
            box-shadow: none !important;
        }

        /* Remove glow from buttons */
        .no-glow .glow-button,
        .no-glow .glow-button:hover {
            box-shadow: none !important;
        }

        /* Disable all CSS animations and transitions */
        .no-animations *,
        .no-animations *::before,
        .no-animations *::after {
            animation: none !important;
            transition: none !important;
        }

        /* ── CSS-only background patterns ────────────────────────────── */

        /* Dot grid pattern */
        .bg-pattern-dots {
            position: relative;
        }
        .bg-pattern-dots::after {
            content: '';
            position: absolute;
            inset: 0;
            pointer-events: none;
            opacity: var(--pattern-opacity);
            background-image: radial-gradient(circle, var(--pattern-color) 1px, transparent 1px);
            background-size: 24px 24px;
            z-index: 0;
        }

        /* Square grid pattern */
        .bg-pattern-grid {
            position: relative;
        }
        .bg-pattern-grid::after {
            content: '';
            position: absolute;
            inset: 0;
            pointer-events: none;
            opacity: var(--pattern-opacity);
            background-image:
                linear-gradient(to right, var(--pattern-color) 1px, transparent 1px),
                linear-gradient(to bottom, var(--pattern-color) 1px, transparent 1px);
            background-size: 32px 32px;
            z-index: 0;
        }

        /* Diagonal stripe pattern */
        .bg-pattern-diagonal {
            position: relative;
        }
        .bg-pattern-diagonal::after {
            content: '';
            position: absolute;
            inset: 0;
            pointer-events: none;
            opacity: var(--pattern-opacity);
            background-image: repeating-linear-gradient(
                45deg,
                var(--pattern-color) 0,
                var(--pattern-color) 1px,
                transparent 0,
                transparent 50%
            );
            background-size: 16px 16px;
            z-index: 0;
        }

        /* Wave (sine-like) pattern using SVG data URI */
        .bg-pattern-waves {
            position: relative;
        }
        .bg-pattern-waves::after {
            content: '';
            position: absolute;
            inset: 0;
            pointer-events: none;
            opacity: var(--pattern-opacity);
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='20'%3E%3Cpath d='M0 10 C10 0, 20 20, 40 10 S70 0, 80 10' fill='none' stroke='%2394a3b8' stroke-width='1'/%3E%3C/svg%3E");
            background-repeat: repeat;
            background-size: 80px 20px;
            z-index: 0;
        }

        /* ── Base styles ──────────────────────────────────────────────── */

        * {
            font-family: var(--font-family);
            box-sizing: border-box;
        }

        /* SVG icon sizing fallbacks (in case Tailwind CDN fails to load) */
        svg.w-3, svg.h-3 { width: 0.75rem; height: 0.75rem; }
        svg.w-3\.5, svg.h-3\.5 { width: 0.875rem; height: 0.875rem; }
        svg.w-4, svg.h-4 { width: 1rem; height: 1rem; }
        svg.w-5, svg.h-5 { width: 1.25rem; height: 1.25rem; }
        svg.w-6, svg.h-6 { width: 1.5rem; height: 1.5rem; }
        svg.w-8, svg.h-8 { width: 2rem; height: 2rem; }
        svg.w-12, svg.h-12 { width: 3rem; height: 3rem; }
        svg[fill="none"] { display: inline-block; vertical-align: middle; flex-shrink: 0; }
        svg[fill="currentColor"] { display: inline-block; vertical-align: middle; flex-shrink: 0; }

        body {
            background: var(--bg-dark);
            background-image:
                radial-gradient(ellipse at 20% 0%, rgba(8, 145, 178, 0.15) 0%, transparent 50%),
                radial-gradient(ellipse at 80% 100%, rgba(34, 211, 238, 0.1) 0%, transparent 50%);
            min-height: 100vh;
            color: var(--text-primary);
        }

        .glass-card {
            background: rgba(21, 29, 46, 0.8);
            backdrop-filter: blur(20px);
            border: 1px solid rgba(148, 163, 184, 0.1);
        }

        .voice-ring {
            animation: pulse-ring 2s ease-out infinite;
        }

        @keyframes pulse-ring {
            0% { transform: scale(1); opacity: 0.8; }
            50% { transform: scale(1.15); opacity: 0.4; }
            100% { transform: scale(1); opacity: 0.8; }
        }

        .listening-wave {
            animation: wave 1.2s ease-in-out infinite;
        }

        @keyframes wave {
            0%, 100% { transform: scaleY(0.5); }
            50% { transform: scaleY(1); }
        }

        .message-appear {
            animation: slideUp 0.3s ease-out;
        }

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

        .typing-dot {
            animation: bounce 1.4s ease-in-out infinite;
        }

        .typing-dot:nth-child(2) { animation-delay: 0.2s; }
        .typing-dot:nth-child(3) { animation-delay: 0.4s; }

        @keyframes bounce {
            0%, 60%, 100% { transform: translateY(0); }
            30% { transform: translateY(-8px); }
        }

        .gradient-text {
            background: linear-gradient(135deg, var(--accent), var(--primary));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .glow-button {
            box-shadow: 0 0 30px rgba(34, 211, 238, 0.3);
            transition: all 0.3s ease;
        }

        .glow-button:hover {
            box-shadow: 0 0 50px rgba(34, 211, 238, 0.5);
            transform: scale(1.05);
        }

        .glow-button:active {
            transform: scale(0.95);
        }

        .scrollbar-hide::-webkit-scrollbar {
            display: none;
        }

        .scrollbar-hide {
            -ms-overflow-style: none;
            scrollbar-width: none;
        }

        input:focus, textarea:focus {
            outline: none;
            box-shadow: 0 0 0 2px var(--accent);
        }

        .audio-visualizer {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 3px;
            height: 40px;
        }

        .audio-bar {
            width: 4px;
            background: linear-gradient(to top, var(--primary), var(--accent));
            border-radius: 2px;
            transition: height 0.1s ease;
        }

        /* Responsive media styles */
        .media-container {
            max-width: 100%;
            overflow: hidden;
        }

        .media-image {
            max-width: 100%;
            max-height: 300px;
            object-fit: contain;
            border-radius: 0.5rem;
        }

        .media-video {
            max-height: 400px;
            width: 100%;
            border-radius: 0.5rem;
        }

        /* Touch-friendly controls: larger tap targets on mobile */
        @media (max-width: 640px) {
            .media-image {
                max-height: 200px;
            }

            .media-video {
                max-height: 250px;
            }

            .media-container a,
            .media-container button {
                min-height: 44px;
                min-width: 44px;
                display: inline-flex;
                align-items: center;
                justify-content: center;
            }
        }

        /* Media lightbox overlay */
        .media-lightbox {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.9);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 9999;
            padding: 1rem;
            animation: fadeIn 0.2s ease;
        }

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

        .media-lightbox-content {
            position: relative;
            max-width: 90vw;
            max-height: 90vh;
        }

        .media-lightbox-img {
            max-width: 90vw;
            max-height: 85vh;
            object-fit: contain;
            border-radius: 0.5rem;
        }

        .media-lightbox-close {
            position: absolute;
            top: -12px;
            right: -12px;
            width: 36px;
            height: 36px;
            background: rgba(30, 41, 59, 0.9);
            border: 1px solid rgba(148, 163, 184, 0.3);
            border-radius: 50%;
            color: var(--text-primary);
            font-size: 1.25rem;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 10000;
        }

        .media-lightbox-close:hover {
            background: rgba(51, 65, 85, 0.9);
        }

        /* ── Feedback buttons ─────────────────────────────────────────── */
        .feedback-wrap {
            margin-top: 8px;
        }

        .feedback-buttons {
            display: flex;
            align-items: center;
            gap: 4px;
        }

        .feedback-btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 24px;
            height: 24px;
            border: none;
            border-radius: 6px;
            background: transparent;
            color: rgba(148, 163, 184, 0.5);
            cursor: pointer;
            padding: 0;
            transition: color 0.15s ease, background 0.15s ease;
        }

        .feedback-btn:hover:not(:disabled) {
            color: var(--text-secondary);
            background: rgba(148, 163, 184, 0.1);
        }

        .feedback-btn:disabled {
            cursor: default;
        }

        .feedback-btn-up.active {
            color: var(--success);
        }

        .feedback-btn-down.active {
            color: #f87171;
        }

        .feedback-confirm {
            display: none;
            align-items: center;
            gap: 3px;
            font-size: 11px;
            color: var(--success);
            animation: fadeIn 0.2s ease;
        }

        .correction-form, .feedback-form-up {
            margin-top: 8px;
            display: none;
            flex-direction: column;
            gap: 6px;
            animation: fadeIn 0.15s ease;
        }

        .correction-input, .feedback-comment-input, .feedback-comment-input-down {
            width: 100%;
            background: rgba(15, 23, 42, 0.6);
            border: 1px solid rgba(148, 163, 184, 0.2);
            border-radius: 8px;
            padding: 8px 10px;
            font-size: 12px;
            color: #e2e8f0;
            resize: vertical;
            min-height: 52px;
            outline: none;
            transition: border-color 0.15s ease;
        }

        .correction-input:focus, .feedback-comment-input:focus, .feedback-comment-input-down:focus {
            border-color: rgba(34, 211, 238, 0.4);
        }

        .correction-input::placeholder, .feedback-comment-input::placeholder, .feedback-comment-input-down::placeholder {
            color: rgba(148, 163, 184, 0.4);
        }

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

        .correction-submit-btn {
            padding: 4px 12px;
            font-size: 11px;
            border-radius: 6px;
            border: none;
            background: rgba(34, 211, 238, 0.15);
            color: var(--accent);
            cursor: pointer;
            transition: background 0.15s ease;
        }

        .correction-submit-btn:hover {
            background: rgba(34, 211, 238, 0.25);
        }

        .correction-cancel-btn {
            padding: 4px 10px;
            font-size: 11px;
            border-radius: 6px;
            border: none;
            background: transparent;
            color: rgba(148, 163, 184, 0.6);
            cursor: pointer;
            transition: color 0.15s ease;
        }

        .correction-cancel-btn:hover {
            color: var(--text-secondary);
        }

        /* ============================================================================
           Notification Bell System
           ============================================================================ */

        .notif-bell-btn {
            position: relative;
            width: 36px;
            height: 36px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 8px;
            background: transparent;
            border: none;
            cursor: pointer;
            color: var(--text-secondary);
            transition: background 0.2s ease, color 0.2s ease;
            flex-shrink: 0;
        }

        .notif-bell-btn:hover {
            background: rgba(6, 182, 212, 0.1);
            color: #e2e8f0;
        }

        .notif-bell-btn.active {
            color: #06b6d4;
        }

        .notif-badge {
            position: absolute;
            top: 2px;
            right: 2px;
            min-width: 16px;
            height: 16px;
            background: var(--error);
            color: #fff;
            font-size: 10px;
            font-weight: 700;
            line-height: 16px;
            text-align: center;
            border-radius: 8px;
            padding: 0 3px;
            pointer-events: none;
        }

        .notif-badge.hidden {
            display: none;
        }

        /* Push opt-in toggle button */
        .notif-push-btn {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            height: 28px;
            padding: 0 8px;
            border-radius: 6px;
            background: transparent;
            border: 1px solid rgba(148, 163, 184, 0.2);
            cursor: pointer;
            color: #64748b;
            font-size: 11px;
            font-weight: 500;
            transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
            flex-shrink: 0;
            white-space: nowrap;
        }

        .notif-push-btn:hover {
            background: rgba(6, 182, 212, 0.08);
            color: var(--text-secondary);
            border-color: rgba(6, 182, 212, 0.3);
        }

        .notif-push-btn.push-enabled {
            color: #06b6d4;
            border-color: rgba(6, 182, 212, 0.4);
            background: rgba(6, 182, 212, 0.06);
        }

        .notif-push-btn.push-enabled:hover {
            background: rgba(6, 182, 212, 0.12);
        }

        .notif-push-label {
            line-height: 1;
        }

        /* Dropdown panel */
        .notif-dropdown {
            position: absolute;
            top: calc(100% + 8px);
            right: 0;
            width: 340px;
            background: rgba(21, 29, 46, 0.97);
            border: 1px solid rgba(148, 163, 184, 0.15);
            border-radius: 12px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
            z-index: 200;
            overflow: hidden;
            display: none;
            backdrop-filter: blur(20px);
        }

        .notif-dropdown.open {
            display: block;
            animation: notifDropIn 0.18s ease-out;
        }

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

        .notif-dropdown-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 12px 16px;
            border-bottom: 1px solid rgba(148, 163, 184, 0.15);
        }

        .notif-dropdown-header h4 {
            font-size: 0.875rem;
            font-weight: 600;
            color: var(--text-primary);
            margin: 0;
        }

        .notif-mark-all-btn {
            font-size: 0.75rem;
            color: #06b6d4;
            background: none;
            border: none;
            cursor: pointer;
            padding: 0;
            transition: color 0.15s ease;
        }

        .notif-mark-all-btn:hover {
            color: var(--accent);
        }

        .notif-list {
            max-height: 320px;
            overflow-y: auto;
        }

        .notif-item {
            display: flex;
            align-items: flex-start;
            gap: 10px;
            padding: 10px 16px;
            cursor: pointer;
            transition: background 0.15s ease;
            border-bottom: 1px solid rgba(71, 85, 105, 0.2);
        }

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

        .notif-item:hover {
            background: rgba(6, 182, 212, 0.06);
        }

        .notif-item.unread {
            background: rgba(6, 182, 212, 0.04);
        }

        .notif-item.unread:hover {
            background: rgba(6, 182, 212, 0.1);
        }

        .notif-unread-dot {
            width: 7px;
            height: 7px;
            border-radius: 50%;
            background: #06b6d4;
            flex-shrink: 0;
            margin-top: 5px;
        }

        .notif-unread-dot.read {
            background: transparent;
        }

        .notif-item-body {
            flex: 1;
            min-width: 0;
        }

        .notif-item-title {
            font-size: 0.8125rem;
            font-weight: 600;
            color: var(--text-primary);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .notif-item-title.read {
            font-weight: 400;
            color: var(--text-secondary);
        }

        .notif-item-preview {
            font-size: 0.75rem;
            color: var(--text-secondary);
            margin-top: 2px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }

        .notif-item-time {
            font-size: 0.6875rem;
            color: #64748b;
            margin-top: 3px;
        }

        .notif-dropdown-footer {
            padding: 10px 16px;
            border-top: 1px solid rgba(148, 163, 184, 0.15);
            text-align: center;
        }

        .notif-view-all-btn {
            font-size: 0.8125rem;
            color: #06b6d4;
            background: none;
            border: none;
            cursor: pointer;
            padding: 0;
            transition: color 0.15s ease;
        }

        .notif-view-all-btn:hover {
            color: var(--accent);
        }

        .notif-empty {
            padding: 32px 16px;
            text-align: center;
            color: var(--text-secondary);
            font-size: 0.8125rem;
        }

        /* Priority indicators */
        .notif-priority-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            flex-shrink: 0;
            margin-top: 5px;
        }

        .notif-priority-dot.normal   { background: #3b82f6; }
        .notif-priority-dot.high     { background: var(--warning); }
        .notif-priority-dot.critical { background: var(--error); }

        /* ============================================================
           Notification Toast Container
           ============================================================ */
        .notif-toast-container {
            position: fixed;
            top: 80px; /* below header */
            right: 20px;
            z-index: 10000;
            display: flex;
            flex-direction: column;
            gap: 8px;
            max-width: 380px;
        }

        .notif-toast {
            background: white;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            padding: 12px 16px;
            border-left: 4px solid #00897B; /* default teal */
            animation: notifSlideIn 0.3s ease-out;
            cursor: pointer;
            position: relative;
            max-width: 380px;
        }

        .notif-toast.priority-high     { border-left-color: #F59E0B; }
        .notif-toast.priority-critical { border-left-color: #EF4444; }

        .notif-toast-title  { font-weight: 600; font-size: 14px; margin-bottom: 4px; color: #1B2A4A; }
        .notif-toast-body   { font-size: 13px; color: #666; line-height: 1.4; }
        .notif-toast-close  {
            position: absolute; top: 8px; right: 8px;
            background: none; border: none; cursor: pointer;
            color: #999; font-size: 16px; line-height: 1;
        }
        .notif-toast-close:hover { color: #333; }
        .notif-toast-action {
            margin-top: 8px; font-size: 12px; color: #00897B; font-weight: 500;
        }

        @keyframes notifSlideIn {
            from { transform: translateX(100%); opacity: 0; }
            to   { transform: translateX(0);    opacity: 1; }
        }
        @keyframes notifFadeOut {
            from { opacity: 1; transform: translateX(0); }
            to   { opacity: 0; transform: translateX(100%); }
        }
        .notif-toast.removing {
            animation: notifFadeOut 0.3s ease-in forwards;
        }

        /* ── Story Player (Phase 4) — sticky pre-rendered story audio bar ───── */
        .story-player {
            position: sticky;
            top: 0;
            z-index: 30;
            margin: 0 0 12px 0;
            padding: 10px 12px;
            background: var(--bg-card, #151d2e);
            border: 1px solid var(--input-border, #334155);
            border-radius: 12px;
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
            color: var(--text-primary, #f1f5f9);
            font-family: var(--font-family, sans-serif);
            font-size: 13px;
            backdrop-filter: blur(8px);
            -webkit-backdrop-filter: blur(8px);
        }
        .story-player-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            margin-bottom: 8px;
        }
        .story-player-title {
            display: flex;
            align-items: center;
            gap: 8px;
            min-width: 0;
            font-weight: 600;
            color: var(--text-primary, #f1f5f9);
        }
        .story-player-icon { font-size: 16px; line-height: 1; }
        .story-player-filename {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 260px;
        }
        .story-player-meta {
            display: flex;
            align-items: center;
            gap: 10px;
            color: var(--text-secondary, #94a3b8);
            font-size: 12px;
        }
        .story-player-paracount { white-space: nowrap; }
        .story-player-close {
            background: transparent;
            border: 1px solid transparent;
            color: var(--text-secondary, #94a3b8);
            cursor: pointer;
            width: 24px;
            height: 24px;
            border-radius: 6px;
            font-size: 16px;
            line-height: 1;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 0;
        }
        .story-player-close:hover {
            background: rgba(255,255,255,0.06);
            color: var(--text-primary, #f1f5f9);
            border-color: var(--input-border, #334155);
        }
        .story-player-controls {
            display: flex;
            align-items: center;
            gap: 10px;
        }
        .story-player-play,
        .story-player-skipback {
            background: var(--primary, #0891b2);
            color: #fff;
            border: none;
            border-radius: 8px;
            padding: 6px 10px;
            font-size: 13px;
            cursor: pointer;
            line-height: 1;
            min-width: 36px;
        }
        .story-player-play { min-width: 40px; }
        .story-player-play:hover,
        .story-player-skipback:hover {
            background: var(--accent, #22d3ee);
            color: var(--header-bg, #0f172a);
        }
        /* Wrap groups slider + chapter-mark overlay so ticks position
           relative to the slider track width. */
        .story-player-progress-wrap {
            position: relative;
            flex: 1 1 auto;
            display: flex;
            align-items: center;
        }
        .story-player-progress {
            flex: 1 1 auto;
            -webkit-appearance: none;
            appearance: none;
            height: 6px;
            background: var(--input-bg, #1e293b);
            border-radius: 3px;
            outline: none;
            cursor: pointer;
            position: relative;
            z-index: 1;
        }
        /* Chapter marks: positioned ticks over the slider track. */
        .story-player-chapter-marks {
            position: absolute;
            left: 0; right: 0;
            top: 50%;
            transform: translateY(-50%);
            height: 14px;
            pointer-events: none;
            z-index: 2;
        }
        .story-player-chapter-tick {
            position: absolute;
            top: 0;
            transform: translateX(-50%);
            width: 3px;
            height: 14px;
            background: rgba(245, 158, 11, 0.85);
            border: none;
            border-radius: 2px;
            padding: 0;
            cursor: pointer;
            pointer-events: auto;
            transition: background 0.15s ease, transform 0.15s ease;
        }
        .story-player-chapter-tick:hover {
            background: #fbbf24;
            transform: translateX(-50%) scaleY(1.4);
        }
        .story-player-progress::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 14px;
            height: 14px;
            background: var(--accent, #22d3ee);
            border-radius: 50%;
            border: 2px solid var(--header-bg, #0f172a);
            cursor: pointer;
        }
        .story-player-progress::-moz-range-thumb {
            width: 14px;
            height: 14px;
            background: var(--accent, #22d3ee);
            border-radius: 50%;
            border: 2px solid var(--header-bg, #0f172a);
            cursor: pointer;
        }
        .story-player-time-current,
        .story-player-time-total {
            font-family: var(--font-mono, monospace);
            font-size: 11px;
            color: var(--text-secondary, #94a3b8);
            min-width: 42px;
            text-align: center;
        }
        .story-player-now {
            margin-top: 10px;
            padding: 8px 10px;
            background: rgba(255,255,255,0.03);
            border: 1px solid var(--input-border, #334155);
            border-radius: 8px;
            max-height: 84px;
            overflow-y: auto;
            font-size: 12.5px;
            line-height: 1.55;
            color: var(--text-primary, #f1f5f9);
            white-space: pre-wrap;
        }
        .story-player-now:empty { display: none; }

        /* ===== Preparing-state player (spinner + countdown + bar) ===== */
        .story-player.story-preparing { padding: 14px 16px; }
        .story-preparing-status {
            font-size: 12px;
            color: var(--accent, #0ea5e9);
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-right: 8px;
        }
        .story-preparing-body {
            display: flex;
            align-items: center;
            gap: 14px;
            margin-top: 8px;
        }
        .story-preparing-spinner {
            width: 32px;
            height: 32px;
            border: 3px solid rgba(255, 255, 255, 0.15);
            border-top-color: var(--accent, #0ea5e9);
            border-radius: 50%;
            animation: story-preparing-spin 0.9s linear infinite;
            flex-shrink: 0;
        }
        @keyframes story-preparing-spin {
            to { transform: rotate(360deg); }
        }
        .story-preparing-info { flex: 1; min-width: 0; }
        .story-preparing-line1 {
            font-size: 13px;
            color: var(--text-primary, #e2e8f0);
            margin-bottom: 4px;
        }
        .story-preparing-line2 {
            font-size: 12px;
            color: var(--text-secondary, #94a3b8);
            font-variant-numeric: tabular-nums;
            margin-bottom: 8px;
        }
        .story-preparing-bar {
            height: 4px;
            background: rgba(255, 255, 255, 0.08);
            border-radius: 2px;
            overflow: hidden;
        }
        .story-preparing-bar-fill {
            height: 100%;
            background: linear-gradient(90deg, var(--accent, #0ea5e9), var(--primary, #06b6d4));
            border-radius: 2px;
            transition: width 0.6s ease-out;
        }
        [data-theme="light"] .story-preparing-spinner {
            border-color: rgba(0, 0, 0, 0.08);
            border-top-color: var(--accent, #0284c7);
        }
        [data-theme="light"] .story-preparing-bar {
            background: rgba(0, 0, 0, 0.08);
        }
        /* Error state — stop spinner, color the bar red */
        .story-preparing-spinner-stopped {
            animation: none !important;
            border-top-color: #ef4444;
            opacity: 0.7;
        }
        .story-preparing-hint {
            color: var(--text-secondary, #94a3b8);
        }

        /* ===== In-player search bar ===== */
        .story-player-search {
            display: flex;
            align-items: center;
            gap: 6px;
            padding: 4px 0 6px;
        }
        .story-player-search-input {
            flex: 1 1 auto;
            background: rgba(255, 255, 255, 0.06);
            border: 1px solid rgba(255, 255, 255, 0.12);
            border-radius: 999px;
            color: var(--text-primary, #e2e8f0);
            padding: 6px 12px;
            font-size: 12px;
            outline: none;
            transition: background 0.15s ease, border-color 0.15s ease;
        }
        .story-player-search-input:focus {
            background: rgba(255, 255, 255, 0.09);
            border-color: var(--accent, #0ea5e9);
        }
        .story-player-search-input::placeholder {
            color: rgba(226, 232, 240, 0.5);
        }
        .story-player-search-btn {
            background: rgba(14, 165, 233, 0.18);
            border: 1px solid rgba(14, 165, 233, 0.32);
            color: var(--accent, #0ea5e9);
            border-radius: 999px;
            padding: 4px 12px;
            cursor: pointer;
            font-size: 14px;
            line-height: 1;
            transition: background 0.15s ease;
        }
        .story-player-search-btn:hover {
            background: rgba(14, 165, 233, 0.28);
        }
        .story-player-search-msg {
            font-size: 11px;
            color: rgba(226, 232, 240, 0.7);
            min-width: 0;
            max-width: 220px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        /* ===== Voice picker (used in both preparing + playing UI) ===== */
        .story-voice-row {
            display: flex;
            justify-content: flex-end;
            padding: 6px 0 2px;
        }
        .story-voice-picker {
            position: relative;
            font-size: 12px;
        }
        .story-voice-toggle {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 4px 10px;
            background: rgba(255, 255, 255, 0.06);
            border: 1px solid rgba(255, 255, 255, 0.12);
            border-radius: 999px;
            color: var(--text-primary, #e2e8f0);
            cursor: pointer;
            font-size: 12px;
            transition: background 0.15s ease;
        }
        .story-voice-toggle:hover {
            background: rgba(255, 255, 255, 0.10);
        }
        .story-voice-icon { font-size: 14px; opacity: 0.85; }
        .story-voice-current { font-weight: 500; }
        .story-voice-caret { opacity: 0.7; font-size: 10px; }
        .story-voice-menu {
            position: absolute;
            right: 0;
            top: calc(100% + 4px);
            min-width: 280px;
            max-height: 360px;
            overflow-y: auto;
            background: var(--bg-card, #1e293b);
            border: 1px solid var(--input-border, rgba(255, 255, 255, 0.15));
            border-radius: 10px;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
            padding: 6px 0;
            z-index: 1000;
        }
        .story-voice-group {
            padding: 6px 12px 4px;
            font-size: 11px;
            font-weight: 600;
            color: var(--accent, #0ea5e9);
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }
        .story-voice-group:not(:first-child) {
            margin-top: 4px;
            border-top: 1px solid rgba(255, 255, 255, 0.06);
            padding-top: 8px;
        }
        .story-voice-option {
            display: block;
            width: 100%;
            text-align: left;
            padding: 6px 14px;
            background: transparent;
            border: none;
            color: var(--text-primary, #e2e8f0);
            font-size: 13px;
            cursor: pointer;
            font-family: inherit;
        }
        .story-voice-option:hover {
            background: rgba(255, 255, 255, 0.06);
        }
        .story-voice-option-active {
            background: rgba(14, 165, 233, 0.12);
            color: var(--accent, #38bdf8);
            font-weight: 600;
        }
        .story-voice-option-active::before { content: '● '; }
        .story-voice-option-default {
            display: block;
        }
        .story-voice-option-hint {
            display: block;
            font-size: 11px;
            color: var(--text-secondary, #94a3b8);
            margin-top: 2px;
            font-weight: 400;
        }
        .story-voice-sep {
            height: 1px;
            background: rgba(255, 255, 255, 0.08);
            margin: 4px 0;
        }
        [data-theme="light"] .story-voice-sep {
            background: rgba(0, 0, 0, 0.08);
        }
        [data-theme="light"] .story-voice-toggle {
            background: rgba(0, 0, 0, 0.04);
            border-color: rgba(0, 0, 0, 0.1);
            color: var(--text-primary, #1e293b);
        }
        [data-theme="light"] .story-voice-toggle:hover {
            background: rgba(0, 0, 0, 0.08);
        }
        [data-theme="light"] .story-voice-menu {
            background: #fff;
            border-color: rgba(0, 0, 0, 0.1);
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
        }
        [data-theme="light"] .story-voice-option {
            color: #1e293b;
        }
        [data-theme="light"] .story-voice-option:hover {
            background: rgba(0, 0, 0, 0.04);
        }

        /* ===== Pre-flight narration voice picker (above chat input) ===== */
        #narration-voice-bar {
            margin: 0 auto 6px;
            max-width: 48rem;
        }
        .narration-voice-wrap {
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }
        .narration-voice-label {
            font-size: 11px;
            color: var(--text-secondary, #94a3b8);
        }
        .narration-voice-reset {
            font-size: 11px;
            color: var(--text-secondary, #94a3b8);
            background: none;
            border: none;
            cursor: pointer;
            text-decoration: underline;
            padding: 0 4px;
            font-family: inherit;
        }
        .narration-voice-reset:hover {
            color: var(--accent, #38bdf8);
        }
        .narration-voice-toast {
            position: fixed;
            bottom: 90px;
            right: 20px;
            background: var(--accent, #0ea5e9);
            color: white;
            padding: 10px 14px;
            border-radius: 8px;
            font-size: 13px;
            font-weight: 500;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
            z-index: 2000;
            opacity: 1;
            transition: opacity 0.5s ease;
        }
        .narration-voice-toast-fade { opacity: 0; }

        /* ===== Story video overlay =====
           Full-screen looping video shown while the cached MP3 plays.
           Sticky story-player floats above; bottom prompt + controls stay
           visible. z-index choreography (bottom-to-top):
              0   = body
              15  = video overlay
              22  = sticky audio player (forced above overlay when active)
              30  = bottom input-container
        */
        .story-video-overlay-hidden { display: none !important; }
        #story-video-overlay {
            position: fixed;
            inset: 0;
            z-index: 15;
            background: #000;
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
        }
        #story-video-loop {
            width: 100%;
            height: 100%;
            object-fit: cover;
            background: #000;
        }
        /* When the video is showing, hide the chat messages but keep the
           sticky story-player visible (it's inside #conversation-box). */
        body.story-video-active #messages { visibility: hidden; }
        body.story-video-active #conversation-box {
            background: transparent !important;
            border-color: transparent !important;
        }
        body.story-video-active .story-player {
            position: fixed !important;
            top: 8px;
            left: 50%;
            transform: translateX(-50%);
            width: min(48rem, calc(100vw - 16px));
            z-index: 22 !important;
            background: rgba(15, 23, 42, 0.78) !important;
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
            border-color: rgba(255, 255, 255, 0.18) !important;
        }
        /* Hide everything else in the conversation box while video plays
           (e.g. the preparing UI, message bubbles). */
        body.story-video-active #conversation-box > *:not(.story-player) {
            visibility: hidden;
        }

        /* Light-mode contrast tweaks */
        [data-theme="light"] .story-player {
            background: var(--bg-card, #f8fafc);
            border-color: var(--input-border, #e2e8f0);
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
        }
        [data-theme="light"] .story-player-now {
            background: rgba(0,0,0,0.025);
        }
