:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    /* Improved contrast from #6b7280 */
    --text-placeholder: #6b7280;
    /* Separate placeholder color */
    --bg-body: #ffffff;
    --bg-input: #f3f4f6;
    --border-color: #e5e7eb;
    --font-family: 'Inter', sans-serif;
    /* Accessibility */
    --focus-ring: rgba(59, 130, 246, 0.5);
    --focus-ring-offset: 2px;
}

/* Dark Mode Theme */
[data-theme="dark"] {
    --primary-color: #60a5fa;
    --primary-hover: #93c5fd;
    --danger-color: #f87171;
    --danger-hover: #fca5a5;
    --text-primary: #f3f4f6;
    --text-secondary: #d1d5db;
    --text-placeholder: #9ca3af;
    --bg-body: #111827;
    --bg-input: #1f2937;
    --border-color: #374151;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background: var(--bg-body);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    justify-content: center;
    overflow-y: auto;
}

.app-container {
    width: 100%;
    max-width: 800px;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    /* Reduced gap slightly as sections now have padding */
}

/* Header */
.main-header {
    text-align: center;
    margin-bottom: 10px;
}

.main-header h1 {
    color: var(--primary-color);
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.main-header p {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Language Switcher */
.lang-switcher {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}

.lang-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.5rem;
    padding: 4px 8px;
    transition: all 0.2s;
    opacity: 0.5;
    filter: grayscale(80%);
    /* Muted when inactive */
}

.lang-btn:hover {
    opacity: 0.8;
    filter: grayscale(0%);
    background: rgba(0, 0, 0, 0.05);
}

.lang-btn.active {
    opacity: 1;
    filter: grayscale(0%);
    background: var(--bg-input);
    border-color: var(--border-color);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    transform: scale(1.1);
}

/* Theme Toggle Button */
.theme-toggle-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    padding: 6px 10px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
}

.theme-toggle-btn:hover {
    background: var(--bg-input);
}

.theme-toggle-btn .theme-icon-light,
.theme-toggle-btn .theme-icon-dark {
    font-size: 1.3rem;
    color: var(--text-secondary);
}

/* Show/hide icons based on theme */
.theme-icon-dark {
    display: none;
}

.theme-icon-light {
    display: inline;
}

[data-theme="dark"] .theme-icon-dark {
    display: inline;
}

[data-theme="dark"] .theme-icon-light {
    display: none;
}

/* --- GROUP CONTAINERS (Settings, Quick Play, Bible) --- */
.group-container {
    background: var(--bg-input);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 10px;
    transition: all 0.3s ease;
    /* Visual depth for hierarchy */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.03);
}

/* Header for groups (Settings, Bible, etc) */
.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

/* Make header clickable only if it's collapsible */
.group-container.collapsible .group-header {
    cursor: pointer;
    margin-bottom: 0;
    /* Remove margin when collapsed, added back via padding in content */
    user-select: none;
    /* Accessibility: make focusable via keyboard */
    border-radius: 8px;
    padding: 8px;
    margin: -8px;
}

/* Focus state for collapsible headers */
.group-container.collapsible .group-header:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: var(--focus-ring-offset);
}

.group-header h4 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.chevron-icon {
    color: var(--text-secondary);
    transition: transform 0.3s ease;
}

/* Content Area inside Groups */
.group-content {
    transition: all 0.3s ease-in-out;
    opacity: 1;
    max-height: 1000px;
    /* Arbitrary large height for animation */
    overflow: hidden;
}

/* If collapsible header has margin when open */
.group-container.collapsible .group-content {
    margin-top: 15px;
}

/* Collapsed State */
.group-container.collapsed .group-content {
    max-height: 0;
    margin-top: 0;
    opacity: 0;
}

.group-container.collapsed .chevron-icon {
    transform: rotate(-90deg);
}

/* --- FORM ELEMENTS --- */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

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

.input-group.full-width {
    grid-column: span 2;
}

.input-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-group label span {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.form-select,
.form-input {
    padding: 12px 16px;
    /* Changed to use CSS variable for dark mode support */
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 0.95rem;
    color: var(--text-primary);
    width: 100%;
    transition: all 0.2s;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}

.form-input {
    background-image: none;
}

.form-select:focus,
.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Controls Area */
.controls-area {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 5px;
}

.timer-display {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--primary-color);
    font-weight: 600;
    font-size: 1.1rem;
    font-variant-numeric: tabular-nums;
}

.control-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.icon-btn {
    background: var(--bg-input);
    border: none;
    border-radius: 8px;
    /* Improved touch target: minimum 44x44px */
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: #e5e7eb;
    color: var(--text-primary);
}

/* Focus state for icon buttons */
.icon-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: var(--focus-ring-offset);
}

/* Quick Play & Bible specific styling inheriting form group-container */
.quick-group {
    margin-bottom: 20px;
}

.quick-group:last-child {
    margin-bottom: 0;
}

.quick-group h4 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.quick-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.quick-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-family: var(--font-family);
    font-size: 0.95rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.quick-btn span {
    font-size: 1.2rem;
    color: var(--primary-color);
}

.quick-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Focus state for quick buttons */
.quick-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: var(--focus-ring-offset);
}

.quick-btn.playing {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.quick-btn.playing span {
    color: white;
}

/* Disabled state for quick buttons (while audio is playing) */
.quick-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.quick-btn:disabled:hover {
    border-color: var(--border-color);
    transform: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Bible Controls */
.bible-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.bible-select-group {
    display: flex;
    gap: 10px;
    flex: 1;
    flex-wrap: wrap;
}

.bible-select-group .form-select {
    min-width: 100px;
}

.verse-range {
    display: flex;
    align-items: center;
    gap: 8px;
}

.verse-range span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.verse-range .form-select {
    width: 85px;
    /* Increased from 75px to fit text */
    min-width: 70px;
    padding-left: 10px;
    padding-right: 32px;
}

.bible-preview {
    margin-top: 15px;
    padding: 12px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary);
    min-height: 60px;
    max-height: 150px;
    overflow-y: auto;
    white-space: pre-wrap;
}

.bible-preview.placeholder {
    color: var(--text-secondary);
    font-style: italic;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--primary-color);
    border: none;
    border-radius: 8px;
    color: white;
    font-family: var(--font-family);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

/* Focus state for action buttons */
.action-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: var(--focus-ring-offset);
}

.action-btn:disabled {
    background: #d1d5db;
    color: #9ca3af;
    cursor: not-allowed;
    box-shadow: none;
}

.action-btn span {
    font-size: 1.2rem;
}

/* Secondary action button variant */
.action-btn.secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.action-btn.secondary:hover:not(:disabled) {
    background: #e5e7eb;
    border-color: var(--primary-color);
}

/* Bible action buttons container */
.bible-action-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Action Buttons Main */
.action-buttons {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin: 20px 0;
}

.btn-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#audio-visualizer {
    width: 100%;
    height: 16px;
    background: linear-gradient(90deg, #e5e7eb, #f3f4f6);
    border-radius: 8px;
    margin-top: 8px;
    transition: background 0.3s ease;
}

/* Enhanced visualizer during recording */
.recording~#audio-visualizer,
.btn-wrapper:has(.recording) #audio-visualizer {
    background: linear-gradient(90deg, #fecaca, #fee2e2);
}

.circle-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.circle-btn span {
    font-size: 32px;
}

.circle-btn.primary {
    background-color: var(--primary-color);
    color: white;
}

.circle-btn.primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.3);
}

.circle-btn.primary.recording {
    background-color: var(--danger-color);
    animation: pulse 2s infinite, glow 2s infinite;
}

.circle-btn.primary.recording:hover {
    background-color: var(--danger-hover);
}

/* Focus state for circle buttons */
.circle-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 4px;
}

.circle-btn.secondary {
    background-color: var(--bg-input);
    color: var(--text-primary);
}

.circle-btn.secondary:hover:not(:disabled) {
    background-color: #e5e7eb;
    transform: translateY(-2px);
}

.circle-btn:disabled {
    background-color: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none;
}

.btn-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Transcript Grid */
.transcript-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.text-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.text-panel h3 {
    font-size: 1rem;
    color: var(--primary-color);
    font-weight: 600;
}

.text-content {
    background: var(--bg-input);
    border-radius: 12px;
    padding: 20px;
    height: 300px;
    overflow-y: auto;
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
    text-align: left;
}

.bible-verse-card {
    background-color: #f0f9ff;
    border-left: 4px solid #0ea5e9;
    padding: 8px;
    margin: 8px 0;
    font-size: 0.9em;
    color: #0c4a6e;
}

[data-theme="dark"] .bible-verse-card {
    background-color: #0c4a6e;
    border-left: 4px solid #38bdf8;
    color: #e0f2fe;
}

.text-content.placeholder {
    color: var(--text-secondary);
    font-style: italic;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* Muted TTS Button */
.icon-btn.muted {
    background: var(--danger-color);
    color: white;
}

.icon-btn.muted:hover {
    background: var(--danger-hover);
}

/* Loading Spinner */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Status Bar */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 8px;
    font-size: 0.85rem;
    color: #92400e;
    margin-bottom: 10px;
}

.status-bar.hidden {
    display: none;
}

.status-bar.error {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #991b1b;
}

.status-bar.success {
    background: #d1fae5;
    border-color: #6ee7b7;
    color: #065f46;
}

/* Translation Pending Indicator */
.translation-pending {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #eff6ff;
    border-radius: 8px;
    color: var(--primary-color);
    font-size: 0.9rem;
    margin: 8px 0;
}

.translation-pending.hidden {
    display: none;
}

/* Responsive */
@media (max-width: 640px) {
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .input-group.full-width {
        grid-column: span 1;
    }

    .transcript-grid {
        grid-template-columns: 1fr;
    }

    /* Improved Bible controls for mobile */
    .bible-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .bible-select-group {
        flex-direction: column;
        gap: 8px;
    }

    .bible-select-group .form-select {
        width: 100%;
        min-width: unset;
    }

    .verse-range {
        justify-content: center;
    }

    .action-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ========================== */
/* ENHANCED UI/UX ADDITIONS   */
/* ========================== */

/* Glow animation for recording state */
@keyframes glow {

    0%,
    100% {
        box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
    }

    50% {
        box-shadow: 0 0 40px rgba(239, 68, 68, 0.6);
    }
}

/* Empty State Styles */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px 20px;
    text-align: center;
}

.empty-state .empty-icon {
    font-size: 48px;
    color: #d1d5db;
    margin-bottom: 16px;
}

.empty-state .empty-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state .empty-subtitle {
    font-size: 0.9rem;
    color: var(--text-placeholder);
    font-style: normal;
}

/* Keyboard Shortcut Hints */
kbd {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.75rem;
    font-family: var(--font-family);
    margin-left: 6px;
    color: var(--text-secondary);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1f2937;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
}

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

.toast.success {
    background: #059669;
}

.toast.error {
    background: #dc2626;
}

/* Bible Verse Highlight (in translation output) */
.bible-verse-highlight {
    background-color: #f0f9ff;
    border-left: 4px solid #0ea5e9;
    padding: 10px 12px;
    margin: 10px 0;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.bible-verse-highlight:hover {
    transform: translateX(2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    background-color: #e0f2fe;
}

.bible-verse-highlight .verse-ref {
    font-weight: 600;
    color: #0369a1;
    display: block;
    margin-bottom: 4px;
    font-size: 0.85rem;
}

.bible-verse-highlight .verse-text {
    color: #0c4a6e;
    font-size: 0.95rem;
    line-height: 1.5;
}

/* Processing Indicator */
.processing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #eff6ff;
    border-radius: 16px;
    font-size: 0.8rem;
    color: var(--primary-color);
    margin: 4px 0;
}

.processing-indicator .dot {
    width: 6px;
    height: 6px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: processing-pulse 1.4s infinite ease-in-out;
}

.processing-indicator .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.processing-indicator .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes processing-pulse {

    0%,
    80%,
    100% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Timestamp for transcript segments */
.segment-timestamp {
    font-size: 0.75rem;
    color: var(--text-placeholder);
    margin-right: 8px;
    font-variant-numeric: tabular-nums;
}

/* Transcript segment styling */
.transcript-segment {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.transcript-segment:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -100%;
    left: 16px;
    background: var(--primary-color);
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    z-index: 1000;
    text-decoration: none;
    font-weight: 500;
}

.skip-link:focus {
    top: 16px;
}

/* ========================== */
/* DARK MODE SUPPORT          */
/* ========================== */

/* System preference: dark mode */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --primary-color: #60a5fa;
        --primary-hover: #3b82f6;
        --danger-color: #f87171;
        --danger-hover: #ef4444;
        --text-primary: #f3f4f6;
        --text-secondary: #d1d5db;
        --text-placeholder: #9ca3af;
        --bg-body: #111827;
        --bg-input: #1f2937;
        --border-color: #374151;
        --focus-ring: rgba(96, 165, 250, 0.5);
    }

    :root:not([data-theme="light"]) body {
        color-scheme: dark;
    }

    :root:not([data-theme="light"]) .form-select,
    :root:not([data-theme="light"]) .form-input {
        background-color: #374151;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%239ca3af'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    }

    :root:not([data-theme="light"]) .form-input {
        background-image: none;
    }

    :root:not([data-theme="light"]) .quick-btn {
        background: #374151;
        border-color: #4b5563;
    }

    :root:not([data-theme="light"]) .bible-preview {
        background: #374151;
    }

    :root:not([data-theme="light"]) .status-bar {
        background: #422006;
        border-color: #854d0e;
        color: #fef3c7;
    }

    :root:not([data-theme="light"]) .status-bar.error {
        background: #450a0a;
        border-color: #7f1d1d;
        color: #fecaca;
    }

    :root:not([data-theme="light"]) .status-bar.success {
        background: #052e16;
        border-color: #166534;
        color: #bbf7d0;
    }

    :root:not([data-theme="light"]) .bible-verse-highlight {
        background-color: #1e3a5f;
        border-left-color: #38bdf8;
    }

    :root:not([data-theme="light"]) .bible-verse-highlight:hover {
        background-color: #1e3a8a;
    }

    :root:not([data-theme="light"]) .bible-verse-highlight .verse-ref {
        color: #7dd3fc;
    }

    :root:not([data-theme="light"]) .bible-verse-highlight .verse-text {
        color: #bae6fd;
    }

    :root:not([data-theme="light"]) .processing-indicator {
        background: #1e3a5f;
    }

    :root:not([data-theme="light"]) kbd {
        background: #374151;
        border-color: #4b5563;
    }

    :root:not([data-theme="light"]) .circle-btn:disabled {
        background-color: #374151;
        color: #6b7280;
    }

    :root:not([data-theme="light"]) .action-btn:disabled {
        background: #374151;
        color: #6b7280;
    }

    :root:not([data-theme="light"]) .transcript-segment {
        border-bottom-color: rgba(255, 255, 255, 0.1);
    }
}

/* Manual dark theme override */
[data-theme="dark"] {
    --primary-color: #60a5fa;
    --primary-hover: #3b82f6;
    --danger-color: #f87171;
    --danger-hover: #ef4444;
    --text-primary: #f3f4f6;
    --text-secondary: #d1d5db;
    --text-placeholder: #9ca3af;
    --bg-body: #111827;
    --bg-input: #1f2937;
    --border-color: #374151;
    --focus-ring: rgba(96, 165, 250, 0.5);
}

[data-theme="dark"] body {
    color-scheme: dark;
}

[data-theme="dark"] .form-select,
[data-theme="dark"] .form-input {
    background-color: #374151;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%239ca3af'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}

[data-theme="dark"] .form-input {
    background-image: none;
}

[data-theme="dark"] .quick-btn {
    background: #374151;
    border-color: #4b5563;
}

[data-theme="dark"] .bible-preview {
    background: #374151;
}

[data-theme="dark"] .status-bar {
    background: #422006;
    border-color: #854d0e;
    color: #fef3c7;
}

[data-theme="dark"] .status-bar.error {
    background: #450a0a;
    border-color: #7f1d1d;
    color: #fecaca;
}

[data-theme="dark"] .status-bar.success {
    background: #052e16;
    border-color: #166534;
    color: #bbf7d0;
}

[data-theme="dark"] .bible-verse-highlight {
    background-color: #1e3a5f;
    border-left-color: #38bdf8;
}

[data-theme="dark"] .bible-verse-highlight:hover {
    background-color: #1e3a8a;
}

[data-theme="dark"] .bible-verse-highlight .verse-ref {
    color: #7dd3fc;
}

[data-theme="dark"] .bible-verse-highlight .verse-text {
    color: #bae6fd;
}

[data-theme="dark"] .processing-indicator {
    background: #1e3a5f;
}

[data-theme="dark"] kbd {
    background: #374151;
    border-color: #4b5563;
}

[data-theme="dark"] .circle-btn:disabled {
    background-color: #374151;
    color: #6b7280;
}

[data-theme="dark"] .action-btn:disabled {
    background: #374151;
    color: #6b7280;
}

[data-theme="dark"] .transcript-segment {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

/* ========================== */
/* SMOOTH SCROLL              */
/* ========================== */

html {
    scroll-behavior: smooth;
}

/* For transcript areas, add smooth scrolling */
.text-content {
    scroll-behavior: smooth;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {

    html,
    .text-content {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========================== */
/* PLAYLIST STYLES            */
/* ========================== */

.playlist-container {
    margin-top: 15px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.playlist-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: #f9fafb;
    border-bottom: 1px solid var(--border-color);
}

.playlist-header h5 {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
}

.playlist-header h5 span {
    font-size: 1.1rem;
}

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

.icon-btn.small {
    min-width: 32px;
    min-height: 32px;
    padding: 6px;
}

.icon-btn.small span {
    font-size: 1.1rem;
}

.playlist-items {
    max-height: 200px;
    overflow-y: auto;
}

.playlist-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 20px;
    color: var(--text-secondary);
}

.playlist-empty-state span {
    font-size: 2rem;
    color: #d1d5db;
    margin-bottom: 8px;
}

.playlist-empty-state p {
    font-size: 0.9rem;
    margin: 0;
}

.playlist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.15s ease;
}

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

.playlist-item:hover {
    background: #f9fafb;
}

.playlist-item.playing {
    background: #eff6ff;
    border-left: 3px solid var(--primary-color);
}

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

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

.playlist-item-preview {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.playlist-item-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.playlist-item-btn {
    background: transparent;
    border: none;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s ease;
}

.playlist-item-btn:hover {
    background: #e5e7eb;
    color: var(--text-primary);
}

.playlist-item-btn.play:hover {
    background: var(--primary-color);
    color: white;
}

.playlist-item-btn.preview:hover {
    background: #6366f1;
    color: white;
}

.playlist-item-btn.remove:hover {
    background: var(--danger-color);
    color: white;
}

.playlist-item-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.playlist-item-btn:disabled:hover {
    background: transparent;
    color: var(--text-secondary);
}

.playlist-item-btn span {
    font-size: 1.1rem;
}

/* Mobile adjustments for playlist */
@media (max-width: 640px) {
    .playlist-item {
        padding: 8px 10px;
    }

    .playlist-item-preview {
        display: none;
    }
}

/* Range Slider Styles */
.form-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

.form-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease;
}

.form-range::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.form-range::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Range value display */
.range-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-color);
    min-width: 40px;
    text-align: center;
}

/* Silero settings group with inline layout */
.silero-settings {
    display: flex;
    flex-direction: row !important;
    align-items: center;
    gap: 12px;
}

.silero-settings label {
    flex-shrink: 0;
    min-width: fit-content;
}

.silero-settings .form-range {
    flex: 1;
}

/* Hint icon tooltip */
.hint-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: help;
    border-radius: 50%;
    margin-left: 4px;
    transition: color 0.2s;
}

.hint-icon:hover {
    color: var(--primary-color);
}

/* ================================ */
/* INSTANT CSS TOOLTIPS             */
/* ================================ */

.has-tooltip {
    position: relative;
    cursor: help;
}

.has-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 0;
    top: 100%;
    margin-top: 8px;
    padding: 10px 14px;
    background: #1f2937;
    color: white;
    font-size: 0.8rem;
    font-weight: 400;
    line-height: 1.4;
    border-radius: 8px;
    white-space: pre-line;
    min-width: 200px;
    max-width: 280px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);

    /* Instant appear */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
    pointer-events: none;
}

/* Arrow */
.has-tooltip::before {
    content: '';
    position: absolute;
    left: 20px;
    top: 100%;
    margin-top: 2px;
    border: 6px solid transparent;
    border-bottom-color: #1f2937;
    z-index: 1001;

    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s;
    pointer-events: none;
}

.has-tooltip:hover::after,
.has-tooltip:hover::before {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Ensure tooltip doesn't overflow on mobile */
@media (max-width: 640px) {
    .has-tooltip::after {
        left: -10px;
        min-width: 180px;
        max-width: 220px;
        font-size: 0.75rem;
    }

    .has-tooltip::before {
        left: 15px;
    }
}

/* QR Code Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
    /* simple hide */
}

.modal-content {
    background: var(--bg-body);
    width: 90%;
    max-width: 400px;
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    animation: modalSlideUp 0.3s ease-out;
    border: 1px solid var(--border-color);
}

@keyframes modalSlideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

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

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

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.close-btn:hover {
    color: var(--danger-color);
}

.modal-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    text-align: center;
}

.modal-body p {
    color: var(--text-secondary);
    margin: 0;
}

.qr-wrapper {
    background: white;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.qr-wrapper img {
    display: block;
    width: 200px;
    height: 200px;
}

.link-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    padding: 8px 12px;
    border-radius: 8px;
    width: 100%;
}

.link-wrapper a {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.9rem;
}

.link-wrapper a:hover {
    text-decoration: underline;
}

/* Session code row in QR modal — shows current code + regenerate button */
.session-code-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
    padding: 12px;
    background: var(--bg-input);
    border-radius: 8px;
}

.session-code-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.session-code-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.session-code-value {
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: 2px;
}

.session-code-hint {
    font-size: 0.7rem;
    color: var(--text-placeholder);
    font-style: italic;
}

#btn-regenerate-session {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: var(--font-family);
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

#btn-regenerate-session:hover {
    background: var(--bg-body);
    border-color: var(--danger-color);
    color: var(--danger-color);
}

#btn-regenerate-session .material-symbols-rounded {
    font-size: 18px;
}

/* Listener Page Styles */

/* ... (previous styles might be here, but we are appending or adding new ones. 
   Since I cannot easily append without reading first, I will add this to style.css or a <style> block if it was a single file. 
   Wait, listener.html links to css/style.css? Yes. 
   Let's check if listener.html has its own styles or uses style.css. 
   listener.html uses css/style.css.
   I should add the overlay styles to css/style.css.
*/
.start-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    /* Above everything */
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: opacity 0.3s ease;
}

.start-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
}

.start-content {
    text-align: center;
    color: white;
    animation: pulse 2s infinite;
}

.start-content span {
    font-size: 4rem;
    margin-bottom: 16px;
    display: block;
}

.start-content p {
    font-size: 1.5rem;
    font-weight: 500;
    margin: 0;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Multi-Select Language Container */
.multi-select-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    background: var(--bg-input);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    max-height: 120px;
    overflow-y: auto;
}

/* On mobile, drop the inner scroll. Narrow viewport packs only ~2 chips/row,
 * so 12 languages need ~6 rows (~210px) — the 120px cap on desktop hides the
 * bottom half (English/Vietnamese/Korean depending on locale order) behind an
 * awkward inner scroll that's hard to operate by touch. Let the container
 * grow naturally and the page handle scrolling instead. */
@media (max-width: 640px) {
    .multi-select-container {
        max-height: none;
        overflow-y: visible;
    }
}

.multi-select-container .lang-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.875rem;
    user-select: none;
}

.multi-select-container .lang-chip:hover {
    border-color: var(--primary-color);
}

.multi-select-container .lang-chip.selected {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.multi-select-container .lang-chip .chip-checkbox {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.multi-select-container .lang-chip.selected .chip-checkbox {
    background: white;
    border-color: white;
}

.multi-select-container .lang-chip.selected .chip-checkbox::after {
    content: '✓';
    font-size: 10px;
    color: var(--primary-color);
    font-weight: bold;
}

/* Listener count badge */
.lang-chip .listener-count {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}

.lang-chip.selected .listener-count {
    background: rgba(255, 255, 255, 0.3);
}

/* Primary language styling */
.multi-select-container .lang-chip.primary.selected {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    border-color: #d97706;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
}

.multi-select-container .lang-chip.primary.selected:hover {
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.5);
}

.multi-select-container .lang-chip.primary .chip-checkbox {
    border-color: #fbbf24;
}

.multi-select-container .lang-chip.primary.selected .chip-checkbox {
    background: white;
    border-color: white;
}

.multi-select-container .lang-chip.primary.selected .chip-checkbox::after {
    color: #d97706;
}

/* Primary star icon */
.lang-chip .primary-star {
    color: #fde68a;
    font-size: 0.9rem;
    margin-right: 2px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Bible version dropdown in language chip */
.lang-chip .chip-bible-version {
    font-family: inherit;
    font-size: 0.7rem;
    padding: 2px 4px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.2);
    color: inherit;
    cursor: pointer;
    margin-left: 4px;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lang-chip .chip-bible-version:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.6);
}

.lang-chip.selected .chip-bible-version {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

.lang-chip.primary .chip-bible-version {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(251, 191, 36, 0.5);
}

/* User Guide Modal Styles */
.modal-content.large-modal {
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.guide-body {
    text-align: left;
    padding: 10px 4px;
    overflow-y: auto;
    flex: 1;
}

.guide-section {
    margin-bottom: 24px;
    padding: 16px;
    border-radius: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

.guide-section h4 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.guide-section ul,
.guide-section ol {
    margin: 10px 0 10px 20px;
    color: var(--text-secondary);
}

.guide-sublist {
    margin-top: 5px !important;
    margin-bottom: 5px !important;
    font-size: 0.9em;
    list-style-type: disc !important;
}

.guide-section li {
    margin-bottom: 6px;
}

.guide-section.critical {
    background: #fff1f2;
    border-color: #fca5a5;
}

[data-theme="dark"] .guide-section.critical {
    background: #450a0a;
    border-color: #7f1d1d;
}

.warning-text {
    font-weight: 600;
    color: #e11d48;
    margin-top: 10px;
    font-style: italic;
}

[data-theme="dark"] .warning-text {
    color: #fda4af;
}

.guide-note {
    font-size: 0.9rem;
    font-style: italic;
    color: var(--text-secondary);
    margin-top: 10px;
}

.wide-btn {
    width: 100%;
    border-radius: 8px;
    padding: 12px;
    font-weight: 600;
}

.modal-footer {
    margin-top: 20px;
    display: flex;
    justify-content: center;
}

/* Guide Language Grid */
.guide-lang-section {
    margin-bottom: 20px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 20px;
}

.guide-label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.lang-grid-small {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.guide-lang-btn {
    font-size: 1.8rem;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
}

.guide-lang-btn:hover {
    background: var(--bg-hover);
    transform: translateY(-2px);
}

.guide-lang-btn.selected {
    background: var(--primary-color-light);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-color);
}

/* ================================ */
/* SERMON MEMORY PANEL              */
/* ================================ */

#memory-group .group-header h4 {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.memory-mode-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    background: var(--primary-color);
    color: white;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
}

.memory-mode-badge.hidden {
    display: none;
}

/* Mode-specific colors */
.memory-mode-badge[data-mode="prayer"],
.memory-mode-badge[data-mode="benediction"] {
    background: #8b5cf6;
}

.memory-mode-badge[data-mode="praise"] {
    background: #f59e0b;
}

.memory-mode-badge[data-mode="lament"] {
    background: #6b7280;
}

.memory-mode-badge[data-mode="exhortation"] {
    background: var(--danger-color);
}

.memory-mode-badge[data-mode="story_narration"] {
    background: #10b981;
}

.memory-mode-badge[data-mode="welcome"],
.memory-mode-badge[data-mode="transition"] {
    background: #64748b;
}

/* Empty state */
.memory-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
    padding: 24px 16px;
    color: var(--text-placeholder);
    font-size: 0.9rem;
    line-height: 1.5;
}

.memory-empty .material-symbols-rounded {
    font-size: 36px;
    color: var(--text-placeholder);
    opacity: 0.6;
}

.memory-empty p {
    max-width: 480px;
}

.memory-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.memory-body.hidden {
    display: none;
}

.memory-empty.hidden {
    display: none;
}

.memory-row {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 12px;
    padding: 8px 12px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.92rem;
    line-height: 1.45;
    align-items: start;
}

.memory-label {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding-top: 2px;
}

.memory-value {
    color: var(--text-primary);
    word-break: break-word;
}

.memory-value:empty::before {
    content: '—';
    color: var(--text-placeholder);
}

.memory-value.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* Full-summary row uses a vertical (block) layout — label on top, prose
   scrollable container below. Keeps long text readable without bloating
   the panel. */
.memory-row.memory-row-block {
    grid-template-columns: 1fr;
    gap: 6px;
}

.memory-value.memory-value-prose {
    display: block;
    max-height: 220px;
    overflow-y: auto;
    white-space: pre-wrap;
    line-height: 1.55;
    font-size: 0.9rem;
    padding: 8px 10px;
    background: var(--bg-input);
    border-radius: 6px;
    color: var(--text-primary);
}

.memory-value.memory-value-prose:empty::before {
    content: 'No service-wide summary yet — accumulates after a few summary cycles.';
    color: var(--text-placeholder);
    font-style: italic;
    font-size: 0.85rem;
}

.memory-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-size: 0.82rem;
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

.memory-tag.term-pair {
    font-family: var(--font-family);
}

.memory-tag.term-pair .term-arrow {
    margin: 0 4px;
    color: var(--text-secondary);
}

.memory-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-placeholder);
    padding: 4px 4px 0;
}

.memory-meta .material-symbols-rounded {
    font-size: 14px;
}

@media (max-width: 640px) {
    .memory-row {
        grid-template-columns: 1fr;
        gap: 4px;
    }
}

/* Header actions (edit button next to chevron) */
.memory-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

#btn-memory-edit {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    transition: background 0.15s, color 0.15s;
}

#btn-memory-edit:hover:not(:disabled) {
    background: var(--bg-input);
    color: var(--primary-color);
}

#btn-memory-edit:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

#btn-memory-edit.editing {
    color: var(--primary-color);
    background: var(--bg-input);
}

#btn-memory-reset {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    transition: background 0.15s, color 0.15s;
}

#btn-memory-reset:hover:not(:disabled) {
    background: var(--bg-input);
    color: var(--danger-color);
}

#btn-memory-reset:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Edit form inputs */
.memory-row.editing {
    background: var(--bg-input);
    border-color: var(--primary-color);
}

.memory-edit-input,
.memory-edit-select,
.memory-edit-textarea {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: var(--font-family);
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.4;
}

.memory-edit-textarea {
    resize: vertical;
    min-height: 60px;
}

.memory-edit-input:focus,
.memory-edit-select:focus,
.memory-edit-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.memory-edit-hint {
    display: block;
    font-size: 0.72rem;
    color: var(--text-placeholder);
    margin-top: 4px;
    font-style: italic;
}

/* Save / Cancel buttons */
.memory-edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

.memory-edit-actions .pending-notice {
    flex: 1;
    font-size: 0.78rem;
    color: var(--primary-color);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.memory-edit-actions .pending-notice.hidden {
    display: none;
}

.memory-edit-actions .pending-notice .material-symbols-rounded {
    font-size: 14px;
}

.btn-memory-save,
.btn-memory-cancel {
    padding: 6px 14px;
    border-radius: 6px;
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
}

.btn-memory-save {
    background: var(--primary-color);
    color: white;
}

.btn-memory-save:hover {
    background: var(--primary-hover);
}

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

.btn-memory-cancel:hover {
    background: var(--bg-input);
    color: var(--text-primary);
}