/* ───────────────────────────────────────────
   Choose Your Own Adventure — Main Styles
   ─────────────────────────────────────────── */

:root {
    --story-bg: #2d5016;
    --story-border: #007bff;
    --primary: #e74c3c;
    --primary-hover: #c0392b;
    --sidebar-bg: #f5f5f5;
    --sidebar-width: 320px;
    --text: #333;
    --text-muted: #777;
    --border-color: #ddd;
    --choice-bg: #f8f9fa;
    --choice-hover: #e9ecef;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    display: flex;
    min-height: 100vh;
    background: #fff;
}

/* ─── Layout ─── */

/* Wrapper: sticky flex row — sidebar + toggle button sit side-by-side */
.sidebar-wrapper {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    align-items: flex-start;
    flex-shrink: 0;
    z-index: 100;
}

/* Outer sidebar — width collapses to 0, inner content clips */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    overflow: hidden;
    transition: width 0.3s ease;
}

.sidebar.sidebar-collapsed {
    width: 0;
}

/* Inner sidebar — fixed width so text never reflows during animation */
.sidebar-inner {
    width: var(--sidebar-width);
    height: 100%;
    overflow-y: auto;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem 1rem;
}

/* ─── Sidebar Toggle Button ─── */

/* Tab that sits flush against the sidebar's right edge */
#sidebar-toggle {
    flex-shrink: 0;
    align-self: flex-start;
    position: sticky;
    top: 1.5rem;
    width: 20px;
    height: 40px;
    padding: 0;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-left: none;          /* merges with sidebar's right border */
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.07);
    transition: background 0.15s, color 0.15s;
}

#sidebar-toggle:hover {
    background: #e2e2e2;
    color: var(--text);
}

/* When sidebar is collapsed, restore the left border so the tab looks standalone */
.sidebar-collapsed + #sidebar-toggle {
    border-left: 1px solid var(--border-color);
    border-radius: 6px;
}

/* ─── Mobile backdrop ─── */

#sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;
}

#sidebar-backdrop.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

.main-content {
    flex: 1;
    padding: 2rem 3rem;
    max-width: 960px;
    margin: 0 auto;
}

/* ─── Header ─── */

.header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.header-icon {
    width: 64px;
    height: 64px;
    border-radius: 8px;
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
}

.subtitle {
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 2rem;
}

/* ─── Sidebar Sections ─── */

.sidebar-section {
    margin-bottom: 1.25rem;
}

.sidebar-section h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.sidebar-section label {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.35rem;
}

.sidebar hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1rem 0;
}

.emoji-row {
    font-size: 0.9rem;
}

/* ─── Sliders ─── */

.slider-row {
    position: relative;
}

.slider-value, .age-value {
    font-weight: 700;
    color: var(--primary);
    font-size: 1.1rem;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
    margin-top: 0.25rem;
}

/* ─── Segmented Controls ─── */

.segmented-control {
    display: flex;
    border: 2px solid var(--primary);
    border-radius: 6px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.segmented-control button {
    flex: 1;
    padding: 0.4rem 0;
    background: transparent;
    border: none;
    border-right: 1px solid var(--primary);
    color: var(--primary);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
}

.segmented-control button:last-child {
    border-right: none;
}

.segmented-control button.active {
    background: var(--primary);
    color: white;
}

.segmented-control button:not(:disabled):not(.active):hover {
    background: rgba(231, 76, 60, 0.12);
}

.segmented-control button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.age-display {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.25rem;
}

.rating-label {
    font-size: 0.85rem;
}

.rating-badge {
    font-size: 1.3rem;
    font-weight: 700;
}

/* ─── Buttons ─── */

.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    text-align: center;
}

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

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

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

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

.btn-start {
    background: var(--primary);
    color: white;
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
}

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

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--choice-hover);
}

.btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
}

.btn-choice {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: var(--choice-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.btn-choice:hover {
    background: var(--choice-hover);
    border-color: var(--story-border);
}

.btn-choice.choice-selected {
    background: #e0e0e0;
    color: #888;
    border-color: #bbb;
    cursor: not-allowed;
    font-style: italic;
}

.btn-choice.choice-unchosen {
    opacity: 0.4;
    cursor: not-allowed;
}

.choice-loading {
    margin-top: 0.75rem;
}

.choice-loading .muted {
    margin-top: 0.35rem;
    text-align: center;
}

/* ─── Story Container ─── */

.story-layout {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
}

.story-text-column {
    flex: 1;
    min-width: 0;
}

.story-image-column {
    width: 320px;
    flex-shrink: 0;
}

.story-container {
    background: var(--story-bg);
    color: white;
    padding: 1.5rem;
    border-radius: 10px;
    border-left: 4px solid var(--story-border);
    line-height: 1.7;
    font-size: 1.05rem;
}

.story-image {
    width: 100%;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* ─── Choices Counter ─── */

.choices-section {
    margin-top: 1.5rem;
}

.choices-section h3 {
    margin-bottom: 0.75rem;
}

.choices-counter-row {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
    margin-bottom: 2rem;
}

.choices-counter {
    display: inline-block;
    background: #f0f2f6;
    color: #222;
    padding: 0.45em 1.1em;
    border-radius: 2em;
    font-weight: 700;
    font-size: 0.95em;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* ─── End Screen ─── */

.end-screen {
    text-align: center;
    padding: 2rem;
    margin-top: 1.5rem;
}

.end-screen h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* ─── Form Inputs ─── */

.input-textarea, .input-text {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
}

.input-textarea:focus, .input-text:focus {
    outline: none;
    border-color: var(--story-border);
    box-shadow: 0 0 0 2px rgba(0,123,255,0.15);
}

.input-sm {
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
}

.scenario-input {
    margin-bottom: 1rem;
}

.scenario-input h3 {
    margin-bottom: 0.5rem;
}

.scenario-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
    margin-bottom: 0.75rem;
}

.btn-begin {
    background: var(--primary);
    color: white;
    padding: 0.7rem 1.6rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s, transform 0.1s;
}

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

.btn-begin:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* ─── Auth Form ─── */

.auth-form-container {
    max-width: 400px;
    margin: 0 auto;
}

.tab-buttons {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
}

.tab-btn {
    flex: 1;
    padding: 0.6rem;
    background: var(--choice-bg);
    border: 1px solid var(--border-color);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
}

.tab-btn:first-child {
    border-radius: 6px 0 0 6px;
}

.tab-btn:last-child {
    border-radius: 0 6px 6px 0;
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.form-group label {
    font-weight: 500;
    font-size: 0.9rem;
}

.auth-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.user-email {
    font-size: 0.85rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── Word List ─── */

.word-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.word-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.6rem;
    background: #e9ecef;
    border-radius: 1rem;
    font-size: 0.85rem;
}

.word-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
}

.word-remove:hover {
    color: var(--primary);
}

.word-form {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.word-form .input-text {
    flex: 1;
}

/* ─── Checkpoints ─── */

.checkpoint-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.checkpoint-item {
    padding: 0.75rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

.checkpoint-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.35rem;
}

.checkpoint-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.checkpoint-status {
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    font-weight: 500;
}

.status-complete {
    background: #d4edda;
    color: #155724;
}

.status-progress {
    background: #fff3cd;
    color: #856404;
}

.checkpoint-preview {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

/* ─── Loading ─── */

.loading-screen {
    text-align: center;
    padding: 3rem;
}

.spinner-container {
    margin-top: 3rem;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

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

/* Image loading */
.image-loading {
    text-align: center;
}

.placeholder-pulse {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.loading-bar {
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    margin-top: 0.5rem;
    overflow: hidden;
}

.loading-bar-fill {
    width: 30%;
    height: 100%;
    background: var(--story-border);
    border-radius: 2px;
    animation: loading-progress 2s ease-in-out infinite;
}

@keyframes loading-progress {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

/* Image generating status bar (shown below existing image while new one generates) */
.image-status-bar {
    margin-top: 0.5rem;
    text-align: center;
}

.image-status-bar .muted {
    margin-top: 0.25rem;
}

/* ─── Error / Success banners ─── */

.error-banner {
    background: #f8d7da;
    color: #721c24;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.success-banner {
    background: #d4edda;
    color: #155724;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

/* ─── Social sign-in buttons ─── */

.btn-social {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.6rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: #fff;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background 0.15s;
}
.btn-social:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.btn-google { border-color: #dadce0; color: #3c4043; }
.btn-google:hover:not(:disabled) { background: #f8f9fa; }
.btn-facebook { border-color: #1877f2; color: #1877f2; }
.btn-facebook:hover:not(:disabled) { background: #f0f4ff; }

/* ─── Auth divider ─── */

.auth-divider {
    text-align: center;
    margin: 1rem 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    position: relative;
}
.auth-divider::before,
.auth-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 42%;
    height: 1px;
    background: var(--border-color);
}
.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }

/* ─── Auth alt links ─── */

.auth-alt-link {
    text-align: center;
    margin-top: 0.75rem;
    font-size: 0.88rem;
    color: var(--text-muted);
}
.auth-alt-link a { color: var(--primary); text-decoration: none; }
.auth-alt-link a:hover { text-decoration: underline; }

.auth-footer-link {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.auth-footer-link a { color: var(--text-muted); text-decoration: underline; }

.form-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

/* ─── Email verification warning in sidebar ─── */

.verification-warning {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 4px;
    font-size: 0.82rem;
    color: #856404;
}
.verification-warning p { margin: 0 0 0.35rem; }

/* ─── Sidebar locked (unauthenticated) ─── */

.sidebar-locked #sidebar-toggle {
    display: none !important;
}

/* ─── Verification pending ─── */

.verify-pending-container {
    max-width: 480px;
    margin: 3rem auto;
    padding: 2rem;
    text-align: center;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--card-bg, #fff);
}
.verify-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.verify-pending-container h2 { margin: 0.25rem 0 1rem; font-size: 1.4rem; }
.verify-actions { margin: 1.5rem 0; }
.cooldown-notice {
    padding: 0.75rem 1rem;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #856404;
    display: inline-block;
}
.cooldown-notice p { margin: 0; }
.verify-refresh-hint { font-size: 0.88rem; color: var(--text-muted); margin-top: 1.25rem; }

/* ─── Sidebar footer links ─── */

.sidebar-footer {
    margin-top: auto;
    padding-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}
.sidebar-footer a {
    color: var(--text-muted);
    text-decoration: none;
}
.sidebar-footer a:hover { text-decoration: underline; }

/* ─── Story History ─── */

.story-history {
    margin-top: 2rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.75rem;
}

.story-history summary {
    cursor: pointer;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.history-part {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.history-part:last-child {
    border-bottom: none;
}

.history-choice {
    font-style: italic;
    color: var(--story-border);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

/* ─── Utilities ─── */

.muted {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
    accent-color: var(--primary);
    width: 1.1rem;
    height: 1.1rem;
}

/* ─── Responsive ─── */

@media (max-width: 768px) {
    /* Wrapper takes no space — sidebar and toggle both go fixed */
    .sidebar-wrapper {
        position: static;
        height: 0;
        overflow: visible;
        z-index: 1000;
    }

    /* Sidebar becomes a fixed slide-over panel */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        width: var(--sidebar-width);
        z-index: 1000;
        overflow: hidden;
        /* On mobile use transform so width stays constant */
        transition: transform 0.3s ease;
        transform: translateX(0);
    }

    .sidebar.sidebar-collapsed {
        transform: translateX(-100%);
        width: var(--sidebar-width);    /* keep width so slide animation works */
    }

    /* Toggle becomes a fixed hamburger/close button in the corner */
    #sidebar-toggle {
        position: fixed;
        top: 0.65rem;
        left: 0.65rem;
        z-index: 1001;
        width: 36px;
        height: 36px;
        border: 1px solid var(--border-color) !important;
        border-left: 1px solid var(--border-color) !important;
        border-radius: 6px !important;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
        font-size: 1.1rem;
    }

    .main-content {
        padding: 1.5rem;
        padding-top: 3.5rem;
        width: 100%;
    }

    .story-layout {
        flex-direction: column;
    }

    .story-image-column {
        width: 100%;
    }

    .choices-counter-row {
        justify-content: center;
    }
}

/* ─── Narration Controls ─── */

.narration-controls {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-top: 0.6rem;
    flex-wrap: nowrap;
}

/* Play / Pause button */
.btn-play-pause {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 50%;
    border: 2px solid var(--story-border);
    background: none;
    color: var(--story-border);
    font-size: 0.7rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    padding: 0;
}

.btn-play-pause:hover:not(:disabled) {
    background: var(--story-border);
    color: white;
}

.btn-play-pause:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    border-color: #aaa;
    color: #aaa;
}

/* Speaker / volume icon button */
.btn-speaker {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.1rem 0.2rem;
    border-radius: 4px;
    transition: opacity 0.15s, background 0.15s;
    flex-shrink: 0;
}

.btn-speaker:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.06);
}

.btn-speaker:disabled,
.btn-speaker-disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.btn-speaker-sample {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Inline volume slider */
.volume-slider-wrapper {
    display: flex;
    align-items: center;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 90px;
    height: 4px;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    background: linear-gradient(
        to right,
        var(--story-border) 0%,
        var(--story-border) var(--vol-pct, 100%),
        #ccc var(--vol-pct, 100%),
        #ccc 100%
    );
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: white;
    border: 2px solid var(--story-border);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.volume-slider::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: white;
    border: 2px solid var(--story-border);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.volume-slider::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: #ccc;
}

.volume-slider::-moz-range-progress {
    height: 4px;
    border-radius: 2px;
    background: var(--story-border);
}

/* Loading / status */
.narration-status-text {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.narration-loading-bar {
    flex: 1;
    max-width: 90px;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
    overflow: hidden;
}

.narration-loading-bar .loading-bar-fill {
    height: 100%;
    background: var(--story-border);
}

/* Sidebar voice row */
.narration-voice-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.narration-voice-select {
    flex: 1;
    padding: 0.3rem 0.4rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
    background: white;
    color: var(--text);
}

.narration-disabled {
    opacity: 0.45;
    pointer-events: none;
}
}
