:root {
    --bg-color: #f0f0f0;
    --panel-border: 4px solid #000;
    --shadow: 10px 10px 0px rgba(0, 0, 0, 0.2);
    --text-color: #333;
    --accent-color: #ffcc00;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Comic Neue', cursive;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

@media (max-width: 600px) {
    body {
        padding: 0.5rem;
        /* Reduced global padding */
    }
}

header {
    text-align: center;
    margin-bottom: 3rem;
    position: relative;
}

/* Model Selector */
.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Comic Neue', cursive;
    font-size: 0.9rem;
    background: #fff;
    padding: 8px 12px;
    border: 2px solid #000;
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.2);
}

.model-selector label {
    font-weight: bold;
}

.model-selector select {
    font-family: 'Comic Neue', cursive;
    font-size: 0.9rem;
    padding: 4px 8px;
    border: 2px solid #000;
    background: #fff;
    cursor: pointer;
}


h1 {
    font-family: 'Bangers', cursive;
    font-size: 4rem;
    margin: 0;
    text-transform: uppercase;
    color: #000;
    text-shadow: 4px 4px 0px var(--accent-color);
    letter-spacing: 2px;
}

header p {
    font-size: 1.5rem;
    margin-top: 0.5rem;
}

.comic-grid {
    display: grid;
    /* Mobile first: 1 column */
    grid-template-columns: 1fr;
    gap: 1.5rem;
    max-width: 1300px;
    width: 100%;
    padding: 0 10px;
    /* Add padding for small screens */
}

@media (min-width: 600px) {
    .comic-grid {
        grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
        gap: 3rem;
        padding: 0;
    }
}

/* Panel container - now a flex row with image and button side by side */
/* Panel container */
.panel {
    background: #fff;
    border: var(--panel-border);
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    /* Mobile first: Stack vertically */
    position: relative;
    overflow: visible;
}

@media (min-width: 600px) {
    .panel {
        flex-direction: row;
        /* Desktop: Side-by-side */
    }
}

.panel.reorder-enabled {
    cursor: grab;
}

.panel.reorder-enabled:active {
    cursor: grabbing;
}

.panel.dragging {
    opacity: 0.5;
    transform: rotate(5deg);
    cursor: grabbing;
}

.panel.drag-over {
    transform: scale(1.02);
    opacity: 0.8;
}

.panel.drop-target {
    outline: 4px solid var(--accent-color);
    outline-offset: 4px;
    box-shadow: 0 0 20px rgba(255, 204, 0, 0.6);
    transform: scale(1.02);
}

.panel.double-wide {
    grid-column: span 2;
    aspect-ratio: 8 / 3;
    /* Maintain height but double width */
}

.panel.double-wide .panel-image-wrapper {
    aspect-ratio: 8 / 3;
}

@media (max-width: 950px) {
    .panel.double-wide {
        grid-column: span 1;
        aspect-ratio: auto;
    }

    .panel.double-wide .panel-image-wrapper {
        aspect-ratio: 4 / 3;
    }
}


.panel-placeholder {
    border: 2px dashed var(--accent-color);
    background: rgba(255, 204, 0, 0.1);
    border-radius: 8px;
    margin: 3rem 0;
}


.panel:hover {
    transform: translate(-5px, -5px);
    box-shadow: 15px 15px 0px rgba(0, 0, 0, 0.3);
}

/* Image wrapper to contain image and speech bubbles */
.panel-image-wrapper {
    position: relative;
    flex: 1;
    overflow: hidden;
    line-height: 0;
    font-size: 0;
    /* Force 4:3 aspect ratio */
    aspect-ratio: 4 / 3;
}

.panel img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    object-position: center top;
    /* Slight scale to prevent any hairline rendering gaps/borders */
    transform: scale(1.01);
}

/* Relocated Resize Button */
.panel-resize-btn {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #333;
    border-radius: 50%;
    cursor: pointer;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, opacity 0.2s;
    opacity: 0;
}

.panel:hover .panel-resize-btn {
    opacity: 1;
}

.panel-resize-btn:hover {
    transform: scale(1.1);
    background: #fff;
}

from {
    opacity: 0;
    transform: scale(0.98);
}

to {
    opacity: 1;
    transform: scale(1);
}

to {
    opacity: 1;
    transform: scale(1);
}


.text-bracket {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.95), rgba(0, 0, 0, 0.5) 80%, rgba(0, 0, 0, 0));
    padding: 40px 20px 20px 20px;
    /* Bigger touch target/visual area */
    /* More padding at top for gradient fade */
    font-size: 1rem;
    font-family: 'Comic Neue', cursive;
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    z-index: 5;
    pointer-events: none;
    text-align: center;
    font-weight: bold;
    letter-spacing: 0.5px;
    /* Dynamic height for long text */
    min-height: fit-content;
    max-height: 60%;
    overflow-y: auto;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.4;
}

.text-bracket.editing,
.caption-display.editing {
    pointer-events: auto;
    cursor: text;
    outline: 2px dashed var(--accent-color);
    outline-offset: 2px;
    background: rgba(0, 0, 0, 0.85);
    user-select: text;
    -webkit-user-select: text;
}

/* Caption Wrapper - contains caption + edit/delete buttons */
.caption-wrapper {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 5;
}

.caption-wrapper .text-bracket {
    position: relative;
}

/* Caption Edit Button */
.caption-edit-btn {
    position: absolute;
    top: 10px;
    right: 35px;
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #333;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 10;
    pointer-events: auto;
}

/* Caption Delete Button */
.caption-delete-btn {
    position: absolute;
    top: 10px;
    right: 5px;
    width: 24px;
    height: 24px;
    background: #c62828;
    color: white;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 10;
    pointer-events: auto;
}

.caption-wrapper:hover .caption-edit-btn,
.caption-wrapper:hover .caption-delete-btn {
    opacity: 1;
    visibility: visible;
}

.caption-edit-btn:hover {
    background: #fff;
    transform: scale(1.1);
}

.caption-delete-btn:hover {
    background: #f44336;
    transform: scale(1.1);
}

.bubble {
    position: absolute;
    background: #fff;
    border: 3px solid #000;
    border-radius: 50% / 10%;
    padding: 1rem;
    text-align: center;
    font-family: 'Comic Neue', cursive;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.3;
    color: #000;
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.1);
    max-width: 60%;
    z-index: 10;
}

.bubble.thought {
    border-style: dashed;
    color: #555;
    border-radius: 20px;
}

/* Positioning */
.bubble.top-left {
    top: 20px;
    left: 20px;
}

.bubble.top-right {
    top: 20px;
    right: 20px;
}

.bubble.bottom-left {
    bottom: 20px;
    left: 20px;
}

.bubble.bottom-right {
    bottom: 20px;
    right: 20px;
}

@media (max-width: 600px) {
    h1 {
        font-size: 2.5rem;
    }

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

    .panel {
        flex-direction: column;
    }

    /* Mobile: Hide controls by default, show only when panel is tapped */
    .regenerate-btn {
        position: relative;
        width: 100%;
        border-radius: 0;
        right: auto;
        top: auto;
        transform: none !important;
        opacity: 0;
        pointer-events: none;
        writing-mode: horizontal-tb !important;
        text-orientation: mixed !important;
        margin-top: 5px;
        box-shadow: none !important;
        border: none;
        border-top: 2px solid #000;
        background: #222;
        /* Show emoji icon, hide text via span */
        font-size: 1.2rem;
        padding: 10px;
        transition: opacity 0.2s ease;
    }

    .regenerate-btn .btn-text {
        display: none;
    }

    /* Show controls when panel is tapped */
    .panel.tapped .regenerate-btn {
        opacity: 1;
        pointer-events: auto;
    }

    .panel:hover .regenerate-btn {
        /* Reset hover behavior for mobile */
        opacity: 0;
        transform: none;
    }

    .panel.tapped:hover .regenerate-btn {
        opacity: 1;
    }

    .undo-btn {
        position: relative;
        width: 100%;
        left: auto;
        top: auto;
        transform: none !important;
        opacity: 0;
        pointer-events: none;
        writing-mode: horizontal-tb !important;
        text-orientation: mixed !important;
        border: none;
        border-bottom: 2px solid #000;
        background: #444;
        font-size: 1rem;
        padding: 10px;
        box-shadow: none !important;
        display: flex !important;
        transition: opacity 0.2s ease;
    }

    .panel.tapped .undo-btn {
        opacity: 1;
        pointer-events: auto;
    }

    /* Adjust delete button for mobile - hidden by default */
    .delete-btn {
        opacity: 0;
        pointer-events: none;
        width: 36px;
        height: 36px;
        top: 5px;
        right: 5px;
        background: rgba(255, 0, 0, 0.8);
        transition: opacity 0.2s ease;
    }

    .panel.tapped .delete-btn {
        opacity: 1;
        pointer-events: auto;
    }

    /* Adjust resize button for mobile - hidden by default */
    .panel-resize-btn {
        opacity: 0;
        pointer-events: none;
        width: 36px;
        height: 36px;
        background: rgba(255, 255, 255, 0.9);
        transition: opacity 0.2s ease;
    }

    .panel.tapped .panel-resize-btn {
        opacity: 1;
        pointer-events: auto;
    }

    /* History navigation - hidden by default */
    .hist-nav {
        opacity: 0;
        pointer-events: none;
        background: rgba(0, 0, 0, 0.5);
        padding: 5px;
        transition: opacity 0.2s ease;
    }

    .panel.tapped .hist-nav {
        opacity: 1;
        pointer-events: auto;
    }

    .panel:hover {
        transform: none;
        box-shadow: var(--shadow);
    }

    /* Panel text controls - hidden by default */
    .panel-text-controls {
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    .panel.tapped .panel-text-controls {
        opacity: 1;
        pointer-events: auto;
    }
}

/* Regeneration UI - Absolutely positioned, inside the panel on the right */
.regenerate-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    border: 2px solid #fff;
    padding: 15px 10px;
    font-family: 'Bangers', cursive;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    border-radius: 5px;
}

@media (max-width: 600px) {
    .regenerate-btn {
        padding: 8px 6px;
        font-size: 0.9rem;
        right: 5px;
    }

    .undo-btn {
        padding: 10px;
        font-size: 1rem;
        left: -40px;
        width: 40px;
    }

    .hist-nav {
        font-size: 1rem;
        padding: 5px;
    }
}

.panel:hover .regenerate-btn,
.panel.tapped .regenerate-btn {
    opacity: 1;
    pointer-events: auto;
}

.regenerate-btn:hover {
    background: var(--accent-color);
    color: #000;
    transform: translateY(-50%) scale(1.05);
    border-color: #000;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: #fff;
    padding: 2rem;
    border: 4px solid #000;
    width: 95%;
    /* Wider on mobile */
    max-width: 600px;
    box-shadow: 10px 10px 0px var(--accent-color);
    position: relative;
    font-family: 'Comic Neue', cursive;
    max-height: 90vh;
    /* Prevent vertical overflow */
    overflow-y: auto;
    /* Scroll if too tall */
}

@media (max-width: 600px) {
    .modal-content {
        padding: 1rem;
        width: 98%;
        box-shadow: 5px 5px 0px var(--accent-color);
        margin: 10px;
    }
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
}

.modal h2 {
    font-family: 'Bangers', cursive;
    margin-top: 0;
}

#promptInput {
    width: 100%;
    height: 150px;
    margin: 1rem 0;
    padding: 1rem;
    font-family: monospace;
    border: 2px solid #ccc;
    resize: vertical;
}

#generateBtn {
    background: #000;
    color: #fff;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    font-family: 'Bangers', cursive;
    cursor: pointer;
    width: 100%;
    transition: background 0.2s;
}

#generateBtn:hover {
    background: var(--accent-color);
    color: #000;
}

/* Reference images info */
.reference-info {
    font-size: 0.85rem;
    color: #666;
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #f5f5f5;
    border-radius: 4px;
}

/* History Navigation Arrows */
.hist-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: 2px solid #fff;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 90;
    padding: 10px;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    pointer-events: none;
}

.panel:hover .hist-nav {
    opacity: 1;
    pointer-events: auto;
}

.hist-nav:hover {
    background: var(--accent-color);
    color: #000;
}

.hist-left {
    left: 10px;
}

.hist-right {
    right: 70px;
    /* Left of regenerate button */
}

/* Delete Button */
.delete-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: 2px solid #fff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    z-index: 95;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    pointer-events: none;
}

.panel:hover .delete-btn {
    opacity: 1;
    pointer-events: auto;
}

.delete-btn:hover {
    background: #ff0000;
    color: white;
    transform: scale(1.1);
}

/* Undo Button - Positioned on the left side */
.undo-btn {
    position: absolute;
    left: -60px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    /* Hidden by default, shown by JS if history exists */
    align-items: center;
    justify-content: center;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    background: #000;
    color: #fff;
    border: 2px solid #fff;
    padding: 20px 15px;
    /* Enlarged */
    font-family: 'Bangers', cursive;
    font-size: 1.3rem;
    /* Enlarged */
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    box-shadow: -5px 5px 0px rgba(0, 0, 0, 0.3);
}

/* Bridge the gap between panel and button */
.undo-btn::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 100%;
    width: 30px;
    /* Covers the gap */
    background: transparent;
}

.panel:hover .undo-btn {
    opacity: 1;
    pointer-events: auto;
}


.undo-btn:hover {
    background: #ff4757;
    color: #fff;
    transform: translateY(-50%) scale(1.05);
}

/* Modal Form Elements */
.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
    font-family: 'Bangers', cursive;
    font-size: 1.1rem;
}

.modal textarea {
    width: 100%;
    padding: 0.5rem;
    border: 2px solid #ccc;
    border-radius: 4px;
    font-family: monospace;
    resize: vertical;
}

.options-row {
    margin: 1rem 0;
    display: flex;
    align-items: center;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-family: 'Comic Neue', cursive;
    font-size: 1.1rem;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
}

/* Toast Notification Container */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2000;
    pointer-events: none;
}

.toast {
    background: #fff;
    border: 3px solid #000;
    box-shadow: 5px 5px 0px rgba(0, 0, 0, 0.2);
    padding: 1rem 1.5rem;
    min-width: 250px;
    font-family: 'Comic Neue', cursive;
    font-weight: bold;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastSlideIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: auto;
}

.toast.success {
    border-left: 8px solid #4CAF50;
}

.toast.error {
    border-left: 8px solid #F44336;
}

.toast.info {
    border-left: 8px solid var(--accent-color);
}

.toast.hiding {
    animation: toastFadeOut 0.3s ease forwards;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(50px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* --- VIEWER CONTROLS --- */
.viewer-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.viewer-controls h2 {
    margin: 0;
    font-family: 'Bangers', cursive;
    font-size: 2rem;
}

.story-title-row {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 5px;
}

.controls-right {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.style-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Comic Neue', cursive;
    font-size: 0.9rem;
    background: #fff;
    padding: 8px 12px;
    border: 2px solid #000;
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.2);
}

.style-selector label {
    font-weight: bold;
}

.style-selector select {
    font-family: 'Comic Neue', cursive;
    font-size: 0.9rem;
    padding: 4px 8px;
    border: 2px solid #000;
    background: #fff;
    cursor: pointer;
}

/* --- STORY CREATOR STYLES --- */

nav {
    font-size: 1.5rem;
    font-family: 'Bangers', cursive;
    margin-top: 1rem;
}

nav a {
    color: #333;
    text-decoration: none;
    margin: 0 10px;
    padding-bottom: 5px;
}

nav a.active {
    color: #000;
    border-bottom: 3px solid var(--accent-color);
}

.creator-container {
    max-width: 800px;
    width: 100%;
    background: #fff;
    padding: 2rem;
    border: var(--panel-border);
    box-shadow: var(--shadow);
}

@media (max-width: 600px) {
    .creator-container {
        padding: 0.5rem;
        /* Reduced padding */
        width: 100%;
        border: none;
        /* No border on mobile */
        box-shadow: 5px 5px 0px rgba(0, 0, 0, 0.2);
    }

    .style-input-group>div {
        flex-direction: column;
        gap: 5px;
    }

    #stylePresetSelect,
    #styleInput,
    .model-selector select {
        width: 100% !important;
        /* Full width */
        flex: 1 1 auto !important;
        min-width: 0 !important;
    }

    #autoStyleBtn {
        width: 100%;
        /* Full width button */
    }
}

.step {
    margin-bottom: 2rem;
    padding: 1.5rem;
    border: 2px dashed #ccc;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.step.disabled {
    opacity: 0.5;
    pointer-events: none;
    background: #f9f9f9;
}

.step.hidden-step {
    display: none;
}

.step h2 {
    font-family: 'Bangers', cursive;
    margin-top: 0;
}

textarea {
    width: 100%;
    min-height: 120px;
    padding: 1rem;
    font-family: 'Comic Neue', cursive;
    font-size: 1.1rem;
    border: 2px solid #000;
    margin-bottom: 1rem;
    resize: vertical;
}

.action-btn {
    background: #000;
    color: #fff;
    border: none;
    padding: 10px 20px;
    font-family: 'Bangers', cursive;
    font-size: 1.2rem;
    cursor: pointer;
    transition: transform 0.1s;
}

.action-btn:hover {
    background: var(--accent-color);
    color: #000;
    transform: scale(1.05);
}

.action-btn.primary {
    width: 100%;
    font-size: 1.5rem;
    padding: 15px;
}

.action-btn.quick-create {
    background: var(--accent-color);
    color: #000;
    font-size: 1.1rem;
    padding: 10px 20px;
    border: 2px solid #000;
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.action-btn.quick-create:hover {
    background: #fff;
    transform: scale(1.05);
    box-shadow: 6px 6px 0px rgba(0, 0, 0, 0.4);
}

/* Toggle Switch */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-family: 'Comic Neue', cursive;
    font-size: 0.85rem;
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    width: 44px;
    height: 24px;
    background: #ccc;
    border-radius: 24px;
    position: relative;
    transition: background 0.3s;
    border: 2px solid #000;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    top: 1px;
    left: 2px;
    transition: transform 0.3s;
    border: 1px solid #000;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent-color);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

.toggle-label {
    font-weight: bold;
}

/* Style Preview */
.style-preview-container {
    width: 60px;
    height: 45px;
    border: 2px solid #000;
    border-radius: 4px;
    overflow: hidden;
    background: #f0f0f0;
}

.style-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.panel-input-group {
    margin-bottom: 1rem;
    border-left: 5px solid var(--accent-color);
    padding-left: 10px;
}

.panel-input-group label {
    font-weight: bold;
    display: block;
}

.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    z-index: 5000;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #ccc;
    border-top: 5px solid #000;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

input[type="text"]#storyTitle {
    width: 100%;
    font-size: 1.3rem;
    padding: 10px;
    margin-bottom: 1rem;
    border: 3px solid #000;
    font-family: 'Bangers', cursive;
}

/* Panel Actions */
.panel-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.delete-story-btn {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
    padding: 0 5px;
}

.delete-story-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* --- STORY LIST STYLES --- */
#storyList {
    list-style: none;
    padding: 0;
    margin: 0;
}

#storyList li {
    margin-bottom: 10px;
}

#storyList li a {
    display: block;
    background: linear-gradient(135deg, #ffcc00 0%, #ffdd44 50%, #ffcc00 100%);
    color: #000;
    padding: 12px 15px;
    border: 3px solid #000;
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.3);
    font-family: 'Bangers', cursive;
    font-size: 1.1rem;
    text-decoration: none;
    letter-spacing: 1px;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

#storyList li a::before {
    content: '📖 ';
}

#storyList li a:hover {
    background: linear-gradient(135deg, #fff176 0%, #ffee58 50%, #fff176 100%);
    transform: translateX(5px) scale(1.02);
    box-shadow: 6px 6px 0px rgba(0, 0, 0, 0.4);
}

#storyList li a.active,
#storyList li a:active {
    background: linear-gradient(135deg, #000 0%, #333 100%);
    color: var(--accent-color);
    box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.5);
    transform: translateX(3px);
}

.delete-story-btn {
    background: rgba(255, 0, 0, 0.1);
    border: 2px solid #c62828;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    opacity: 0.7;
    transition: all 0.2s;
    padding: 4px 8px;
    margin-left: 8px;
}

.delete-story-btn:hover {
    opacity: 1;
    background: #c62828;
    color: white;
    transform: scale(1.1);
}

/* Story Sidebar Container */
.story-sidebar {
    background: #fff;
    border: 3px solid #000;
    box-shadow: 5px 5px 0px rgba(0, 0, 0, 0.2);
    padding: 15px;
}

.story-sidebar h3 {
    font-family: 'Bangers', cursive;
    font-size: 1.5rem;
    margin: 0 0 15px 0;
    padding-bottom: 10px;
    border-bottom: 3px solid var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Trash page styles */
.trash-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    padding: 20px;
}

.trash-item {
    background: #fff;
    border: 3px solid #000;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.2);
    padding: 10px;
}

.trash-item img {
    width: 100%;
    height: auto;
    display: block;
}

.trash-item-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.trash-item-actions button {
    flex: 1;
    padding: 8px;
    border: 2px solid #000;
    font-family: 'Comic Neue', cursive;
    font-weight: bold;
    cursor: pointer;
}

.restore-btn {
    background: #e8f5e9;
}

.restore-btn:hover {
    background: #4CAF50;
    color: white;
}

.perm-delete-btn {
    background: #ffebee;
}

.perm-delete-btn:hover {
    background: #c62828;
    color: white;
}

.trash-empty {
    text-align: center;
    padding: 60px 20px;
    font-family: 'Comic Neue', cursive;
    font-size: 1.3rem;
    color: #666;
}

.trash-filename {
    font-size: 0.75rem;
    color: #666;
    margin-top: 8px;
    word-break: break-all;
}

/* Modal Actions */
.modal-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.secondary-btn {
    background: #f5f5f5;
    border: 2px solid #000;
    padding: 10px 20px;
    font-family: 'Comic Neue', cursive;
    font-weight: bold;
    cursor: pointer;
}

.secondary-btn:hover {
    background: #e0e0e0;
}

/* Modal Tabs */
.modal-tabs {
    display: inline-flex;
    gap: 0;
    margin-bottom: 15px;
    background: #e0e0e0;
    border-radius: 20px;
    padding: 3px;
}

.modal-tab {
    padding: 6px 16px;
    background: transparent;
    border: none;
    border-radius: 17px;
    font-family: 'Comic Neue', cursive;
    font-size: 0.85rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #666;
}

.modal-tab.active {
    background: #000;
    color: #fff;
}

.modal-tab:hover:not(.active) {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Regenerate Modal Styling */
.regen-modal .input-group {
    margin-bottom: 15px;
}

.regen-modal .input-group label {
    display: block;
    margin-bottom: 6px;
    font-family: monospace;
    font-size: 0.9rem;
    color: #555;
}

.regen-modal textarea,
.regen-modal .modal-select {
    width: 100%;
    padding: 10px;
    border: 2px solid #ccc;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9rem;
    background: #fff;
    transition: border-color 0.2s ease;
}

.regen-modal textarea:focus,
.regen-modal .modal-select:focus {
    outline: none;
    border-color: #000;
}

.regen-modal #promptInput {
    height: 120px;
    resize: vertical;
}

.regen-modal #stylePromptInput {
    height: 60px;
    resize: vertical;
}

/* History Grid */
.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    max-height: 400px;
    overflow-y: auto;
    padding: 5px;
}

.history-item {
    background: #fff;
    border: 3px solid #000;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-item:hover {
    transform: translateY(-3px);
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.2);
    border-color: var(--accent-color);
}

.history-thumbnail {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-bottom: 2px solid #000;
    background: #f0f0f0;
}

.history-info {
    padding: 10px;
}

.history-date {
    font-size: 0.75rem;
    color: #666;
    margin-bottom: 5px;
}

.history-prompt {
    font-size: 0.85rem;
    color: #333;
    font-family: 'Comic Neue', cursive;
    line-height: 1.3;
    max-height: 50px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-empty {
    color: #666;
    font-style: italic;
    text-align: center;
    padding: 40px 20px;
    grid-column: 1 / -1;
}

/* Story Details Section */

/* Remove outer border from sidebar - keep only inner section borders */
.story-sidebar {
    border: none !important;
    box-shadow: none !important;
    background: transparent;
}

/* Stories Section - separated from buttons */
.stories-section {
    background: #fff;
    border: 3px solid #000;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.2);
    width: 100%;
    box-sizing: border-box;
}

.stories-section h3 {
    font-family: 'Bangers', cursive;
    font-size: 1.4rem;
    margin: 0 0 10px 0;
    color: #333;
    border-bottom: 3px solid var(--accent-color);
    padding-bottom: 8px;
}

.sidebar-actions {
    background: #fff;
    border: 3px solid #000;
    padding: 15px;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.2);
}

/* Sidebar Selectors (Model & Style) */
.viewer-controls-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.viewer-controls-right .style-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.viewer-controls-right .style-selector label {
    font-family: 'Comic Neue', cursive;
    font-weight: 700;
    white-space: nowrap;
}

.viewer-controls-right .style-selector select {
    padding: 8px 12px;
    border: 2px solid #000;
    border-radius: 4px;
    font-family: 'Comic Neue', cursive;
    font-size: 0.95rem;
    cursor: pointer;
}

.sidebar-selectors .model-selector,
.sidebar-selectors .style-selector {
    margin-bottom: 10px;
    width: 100%;
}

.sidebar-selectors .model-selector select,
.sidebar-selectors .style-selector select {
    width: 100%;
    padding: 8px;
    margin-top: 5px;
}

/* Prominent Story Title */
.story-title {
    font-family: 'Bangers', cursive;
    font-size: 2.5rem;
    color: #000;
    text-shadow: 3px 3px 0 var(--accent-color);
    margin: 30px 0 20px 0;
    padding: 15px 0;
    border-bottom: 4px solid #000;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.toggle-details-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: 2px solid #000;
    padding: 8px 12px;
    font-family: 'Bangers', cursive;
    font-size: 0.95rem;
    cursor: pointer;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
    white-space: nowrap;
    border-radius: 4px;
}

.toggle-details-btn:hover {
    transform: translateY(-2px);
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.3);
}



/* Speech Bubble Wrapper */
.speech-bubble-wrapper {
    position: absolute;
    z-index: 100;
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
}

/* Bubble Delete Button */
.speech-bubble-wrapper .bubble-delete-btn {
    position: absolute;
    top: 0;
    right: 0;
    transform: translate(50%, -50%);
    width: 20px;
    height: 20px;
    background: #c62828;
    color: white;
    border: 2px solid #fff;
    border-radius: 50%;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer !important;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
}

.speech-bubble-wrapper:hover .bubble-delete-btn {
    opacity: 1;
    visibility: visible;
}

.speech-bubble-wrapper .bubble-delete-btn:hover {
    background: #f44336;
    transform: translate(50%, -50%) scale(1.1);
}

/* Speech Bubble Base Styles */
.speech-bubble {
    position: relative;
    background: white;
    border: 3px solid #000;
    border-radius: 15px;
    padding: 10px 15px;
    font-family: 'Comic Neue', cursive;
    font-weight: bold;
    font-size: 0.9rem;
    max-width: 200px;
    min-width: 60px;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.2);
    z-index: 1;
}

.speech-bubble:focus {
    outline: 2px dashed var(--accent-color);
    outline-offset: 2px;
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
}

.speech-bubble[contenteditable="true"] {
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
}

.speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -15px;
    left: 20px;
    border-width: 15px 10px 0;
    border-style: solid;
    border-color: #000 transparent transparent;
}

.speech-bubble::before {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 22px;
    border-width: 12px 8px 0;
    border-style: solid;
    border-color: white transparent transparent;
    z-index: 1;
}

/* Per-Panel Text Controls */
.panel-text-controls {
    position: absolute;
    bottom: 10px;
    left: 10px;
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 50;
}

.panel:hover .panel-text-controls {
    opacity: 1;
}

.panel-text-btn {
    width: 32px;
    height: 32px;
    border: 2px solid #000;
    background: #fff;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
    transition: all 0.15s ease;
}

.panel-text-btn:hover {
    background: #f0f0f0;
    transform: translateY(-2px);
}

.panel-text-btn.active {
    background: var(--accent-color);
    box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.panel-lock-btn {
    width: 32px;
    height: 32px;
    border: 2px solid #000;
    background: #4CAF50;
    color: white;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
    transition: all 0.15s ease;
}

.panel-lock-btn:hover {
    background: #43a047;
    transform: translateY(-2px);
}

.panel-lock-btn.hidden {
    display: none;
}

/* New Panel Control Buttons */
.add-caption-btn,
.edit-caption-btn,
.delete-caption-btn,
.add-bubble-btn {
    width: 32px;
    height: 32px;
    border: 2px solid #000;
    background: #fff;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
    transition: all 0.15s ease;
}

/* Panel Info Button - Top Left */
.panel-info-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 28px;
    height: 28px;
    border: 2px solid #000;
    background: #2196F3;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
    transition: all 0.15s ease;
    z-index: 20;
    opacity: 0;
}

.panel:hover .panel-info-btn,
.panel.tapped .panel-info-btn {
    opacity: 1;
}

.panel-info-btn:hover {
    transform: scale(1.1);
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.3);
}

/* Image Pan Handle - Centered */
.image-pan-handle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    cursor: move;
    z-index: 30;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    font-size: 0;
    color: transparent;
}

.panel:hover .image-pan-handle,
.panel.tapped .image-pan-handle {
    opacity: 1;
}

.image-pan-handle:hover,
.image-pan-handle.active {
    background: rgba(255, 255, 255, 0.6);
    border-color: #fff;
}

/* Icon inside handle */
.image-pan-handle::after {
    content: '✥';
    color: #333;
    font-size: 24px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-shadow: 0 0 2px rgba(255, 255, 255, 0.8);
}

.add-caption-btn,
.add-bubble-btn {
    position: relative;
}

.add-caption-btn::after,
.add-bubble-btn::after {
    content: '+';
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background: #4caf50;
    color: white;
    font-size: 12px;
    font-weight: bold;
    line-height: 12px;
    text-align: center;
    border-radius: 50%;
    border: 1px solid #fff;
    box-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

.add-caption-btn {
    background: #fff;
}

.add-bubble-btn {
    background: #e3f2fd;
}

.panel-info-btn:hover,
.add-caption-btn:hover,
.edit-caption-btn:hover,
.delete-caption-btn:hover,
.add-bubble-btn:hover {
    transform: translateY(-2px);
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.3);
}

.delete-caption-btn:hover {
    background: #ffcdd2;
}

.add-caption-btn.hidden,
.edit-caption-btn.hidden,
.delete-caption-btn.hidden {
    display: none;
}

/* Speech bubbles container */
.speech-bubbles-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.speech-bubbles-container .speech-bubble {
    pointer-events: auto;
}


/* Panel info modal */
.panel-info-modal {
    text-align: left;
    background: #e0e0e0;
    padding: 15px;
    border-radius: 8px;
}

.panel-info-modal h3 {
    margin-top: 0;
    font-family: 'Bangers', cursive;
    color: #333;
}

.panel-info-modal .info-section {
    margin-bottom: 15px;
}

.panel-info-modal .info-section strong {
    display: block;
    margin-bottom: 5px;
    color: #222;
}

.panel-info-modal .info-section p {
    margin: 0;
    padding: 10px;
    background: #fff;
    border-radius: 5px;
    font-size: 0.9rem;
    border: 1px solid #ccc;
}

.panel-info-modal .info-section ul {
    margin: 0;
    padding: 10px 10px 10px 30px;
    background: #fff;
    border-radius: 5px;
    border: 1px solid #ccc;
}

.panel-lock-btn.locked {
    background: #c62828;
    /* Red for locked */
}

.panel-lock-btn.locked:hover {
    background: #b71c1c;
}

.set-preview-btn {
    width: 32px;
    height: 32px;
    border: 2px solid #000;
    background: #fff;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
    transition: all 0.15s ease;
}

.set-preview-btn:hover {
    background: #e3f2fd;
    transform: translateY(-2px);
}

.set-preview-btn.active {
    background: #2196F3;
    color: #fff;
    box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.story-details {
    background: #fff;
    border: 3px solid #000;
    margin-bottom: 20px;
    /* Space above grid */
    padding: 20px;
    box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.2);
}

.story-section {
    margin-bottom: 20px;
}

.story-section:last-child {
    margin-bottom: 0;
}

.story-section h3 {
    font-family: 'Bangers', cursive;
    font-size: 1.3rem;
    margin: 0 0 10px 0;
    color: #000;
    text-shadow: 2px 2px 0 var(--accent-color);
}

.enhanced-story-content {
    font-family: 'Comic Neue', cursive;
    line-height: 1.6;
    color: #333;
    max-height: 200px;
    overflow-y: auto;
    padding: 10px;
    background: #f9f9f9;
    border: 2px solid #ddd;
}

.enhanced-story-content p {
    margin: 0 0 10px 0;
}

.panel-prompts-content {
    max-height: 300px;
    overflow-y: auto;
}

.prompt-item {
    background: #f5f5f5;
    border: 2px solid #ddd;
    padding: 10px;
    margin-bottom: 10px;
}

.prompt-label {
    font-family: 'Bangers', cursive;
    font-size: 1rem;
    color: var(--accent-color);
    margin-bottom: 5px;
}

.prompt-text {
    font-family: 'Comic Neue', cursive;
    font-size: 0.9rem;
    color: #555;
    line-height: 1.4;
}

.no-content {
    color: #999;
    font-style: italic;
}

/* Input Groups */
.input-group {
    margin-bottom: 15px;
}

.input-group label {
    display: block;
    margin-bottom: 5px;
    font-family: 'Bangers', cursive;
    color: #333;
}

.input-group textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid #ccc;
    font-family: 'Comic Neue', cursive;
    font-size: 1rem;
    resize: vertical;
}

.style-input-group {
    flex-grow: 1;
    margin: 0 10px;
}

.style-input-group label {
    display: block;
    font-family: 'Bangers', cursive;
    color: #333;
    margin-bottom: 2px;
}

.style-input-group textarea {
    width: 100%;
    padding: 8px;
    border: 3px solid #000;
    font-family: 'Comic Neue', cursive;
    border-radius: 4px;
}

.final-actions {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

/* --- SPEECH BUBBLES --- */
/* Note: .panel-image-wrapper has overflow:hidden for images, 
   but bubbles use high z-index and stay within bounds via JS clamping */

.speech-bubble {
    position: absolute;
    background: white;
    border: 3px solid black;
    border-radius: 20px;
    padding: 10px 15px;
    font-family: 'Comic Neue', cursive;
    font-weight: bold;
    font-size: 1rem;
    text-align: center;
    color: black;
    z-index: 200;
    /* Higher than controls so always visible */
    min-width: 80px;
    max-width: 220px;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.2);
    cursor: move;
    user-select: none;
    /* Default position - overridden by JS */
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
}

.speech-bubble:hover {
    box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.3);
    z-index: 60;
}

.speech-bubble:focus {
    outline: 2px dashed #ff9800;
    background: #fffDE7;
    cursor: text;
    user-select: text;
}

/* Tail for bubble - simplified */
.speech-bubble::before {
    content: '';
    position: absolute;
    bottom: -15px;
    left: 20px;
    border-width: 15px 10px 0;
    border-style: solid;
    border-color: black transparent;
    display: block;
    width: 0;
}

.speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 23px;
    border-width: 13px 7px 0;
    border-style: solid;
    border-color: white transparent;
    display: block;
    width: 0;
}



/* ============================================
   CONFIRMATION DIALOG (replaces browser confirm/alert)
   ============================================ */
.confirm-dialog {
    display: none;
    position: fixed;
    z-index: 3000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.confirm-dialog.active {
    display: flex;
}

.confirm-dialog-content {
    background-color: #fff;
    padding: 2rem;
    border: 4px solid #000;
    width: 90%;
    max-width: 450px;
    box-shadow: 10px 10px 0px var(--accent-color);
    font-family: 'Comic Neue', cursive;
    text-align: center;
    animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@media (max-width: 600px) {
    .confirm-dialog-content {
        padding: 1.5rem;
        box-shadow: 5px 5px 0px var(--accent-color);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

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

.confirm-dialog-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.confirm-dialog-icon.warning {
    color: #ff9800;
}

.confirm-dialog-icon.error {
    color: #f44336;
}

.confirm-dialog-icon.success {
    color: #4CAF50;
}

.confirm-dialog-icon.info {
    color: #2196f3;
}

.confirm-dialog-title {
    font-family: 'Bangers', cursive;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    letter-spacing: 1px;
}

.confirm-dialog-message {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    line-height: 1.5;
    color: #555;
}

.confirm-dialog-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.confirm-dialog-btn {
    padding: 12px 24px;
    font-family: 'Bangers', cursive;
    font-size: 1.1rem;
    border: 3px solid #000;
    cursor: pointer;
    transition: all 0.2s ease;
}

.confirm-dialog-btn.primary {
    background: #000;
    color: #fff;
}

.confirm-dialog-btn.primary:hover {
    background: var(--accent-color);
    color: #000;
    transform: scale(1.05);
}

.confirm-dialog-btn.secondary {
    background: #fff;
    color: #000;
}

.confirm-dialog-btn.secondary:hover {
    background: #eee;
    transform: scale(1.05);
}

.confirm-dialog-btn.danger {
    background: #f44336;
    color: #fff;
    border-color: #c62828;
}

.confirm-dialog-btn.danger:hover {
    background: #c62828;
    transform: scale(1.05);
}

/* ============================================
   SETTINGS MODAL
   ============================================ */
.settings-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #fff;
    border: 3px solid #000;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 900;
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-btn:hover {
    background: var(--accent-color);
    transform: rotate(45deg) scale(1.1);
}

.settings-modal {
    display: none;
    position: fixed;
    z-index: 2500;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
}

.settings-modal.active {
    display: flex;
}

.settings-modal-content {
    background-color: #fff;
    padding: 2rem;
    border: 4px solid #000;
    width: 90%;
    max-width: 500px;
    box-shadow: 10px 10px 0px var(--accent-color);
    position: relative;
    font-family: 'Comic Neue', cursive;
    animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.settings-modal h2 {
    font-family: 'Bangers', cursive;
    margin-top: 0;
    padding-right: 30px;
}

.settings-close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.settings-close:hover {
    color: #f44336;
}

.settings-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px dashed #ddd;
}

.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.settings-section h3 {
    font-family: 'Bangers', cursive;
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
    color: #333;
}

.settings-row {
    margin-bottom: 1rem;
}

.settings-row label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
    font-size: 0.95rem;
}

.settings-row input[type="text"],
.settings-row input[type="password"] {
    width: 100%;
    padding: 10px;
    border: 2px solid #000;
    font-family: 'Comic Neue', cursive;
    font-size: 1rem;
}

.settings-row .hint {
    font-size: 0.85rem;
    color: #666;
    margin-top: 0.5rem;
}

.settings-save-btn {
    width: 100%;
    padding: 12px;
    background: #000;
    color: #fff;
    border: none;
    font-family: 'Bangers', cursive;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}

.settings-save-btn:hover {
    background: var(--accent-color);
    color: #000;
}

/* ============================================
   LOGIN MODAL
   ============================================ */
.login-modal {
    display: none;
    position: fixed;
    z-index: 4000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    align-items: center;
    justify-content: center;
}

.login-modal.active {
    display: flex;
}

.login-modal-content {
    background-color: #fff;
    padding: 2.5rem;
    border: 4px solid #000;
    width: 90%;
    max-width: 400px;
    box-shadow: 10px 10px 0px var(--accent-color);
    font-family: 'Comic Neue', cursive;
    text-align: center;
    animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.login-modal h2 {
    font-family: 'Bangers', cursive;
    font-size: 2rem;
    margin-top: 0;
    margin-bottom: 1.5rem;
}

.login-modal .login-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.login-row {
    margin-bottom: 1rem;
    text-align: left;
}

.login-row label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
}

.login-row input {
    width: 100%;
    padding: 12px;
    border: 2px solid #000;
    font-family: 'Comic Neue', cursive;
    font-size: 1rem;
}

.login-error {
    color: #f44336;
    font-weight: bold;
    margin-bottom: 1rem;
    display: none;
}

.login-error.visible {
    display: block;
}

.login-btn {
    width: 100%;
    padding: 14px;
    background: #000;
    color: #fff;
    border: none;
    font-family: 'Bangers', cursive;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 1rem;
}

.login-btn:hover {
    background: var(--accent-color);
    color: #000;
}

/* ============================================
   TOGGLE CAPTIONS BUTTON
   ============================================ */
.toggle-captions-btn {
    width: 100%;
    background-color: #2196f3;
    color: white;
    border: none;
    padding: 10px;
    cursor: pointer;
    font-family: 'Bangers', cursive;
    font-size: 1.1rem;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
    transition: background 0.2s;
}

.toggle-captions-btn:hover {
    background-color: #1565c0;
}

.toggle-captions-btn.active {
    background-color: #4CAF50;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
}

/* ============================================
   TEXT OVERLAY BUTTON GROUP
   ============================================ */
.text-overlay-group {
    display: flex;
    gap: 5px;
    margin-top: 10px;
}

.overlay-btn {
    flex: 1;
    background-color: #888;
    color: #ccc;
    border: 2px solid #666;
    padding: 12px 8px;
    cursor: pointer;
    font-family: 'Bangers', cursive;
    font-size: 1rem;
    border-radius: 5px;
    transition: all 0.2s ease;
    opacity: 0.6;
}

.overlay-btn:hover {
    opacity: 0.8;
    transform: scale(1.02);
}

.overlay-btn.active {
    opacity: 1;
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.overlay-btn.active[data-mode="captions"] {
    background-color: #2196f3;
    border-color: #1565c0;
}

.overlay-btn.active[data-mode="bubbles"] {
    background-color: #9c27b0;
    border-color: #6a1b9a;
}

.overlay-btn.active[data-mode="none"] {
    background-color: #666;
    border-color: #444;
}

/* ============================================
   FEATURED STORIES SECTION (Index Page)
   ============================================ */
.featured-stories-section {
    max-width: 1300px;
    width: 100%;
    margin-bottom: 40px;
    padding: 20px;
    background: #fff;
    border: 4px solid #000;
    box-shadow: 8px 8px 0px rgba(0, 0, 0, 0.15);
}

.featured-stories-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 3px solid #000;
}

.featured-stories-header h2 {
    font-family: 'Bangers', cursive;
    font-size: 2rem;
    margin: 0;
    letter-spacing: 1px;
}

.view-all-link {
    font-family: 'Comic Neue', cursive;
    font-weight: bold;
    color: #000;
    text-decoration: none;
    padding: 8px 16px;
    border: 2px solid #000;
    background: var(--accent-color);
    transition: all 0.2s;
}

.view-all-link:hover {
    transform: translateY(-2px);
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.2);
}

.featured-stories-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

@media (max-width: 1200px) {
    .featured-stories-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .featured-stories-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 500px) {
    .featured-stories-grid {
        grid-template-columns: 1fr;
    }
}

.featured-story-card {
    background: #fff;
    border: 3px solid #000;
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.featured-story-card:hover {
    transform: translateY(-5px);
    box-shadow: 5px 5px 0px rgba(0, 0, 0, 0.2);
}

.featured-story-card-image-wrapper {
    position: relative;
    width: 100%;
    height: 220px;
    overflow: hidden;
}

.featured-story-card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.featured-story-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    background: #FFD700;
    color: #000;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: bold;
}

.featured-story-badge.recent {
    background: #4CAF50;
    color: #fff;
}

.featured-story-card-content {
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.featured-story-card-title,
.featured-story-card h3,
.featured-story-card-content h3 {
    font-family: 'Bangers', cursive;
    font-size: 1.35rem;
    margin: 0;
    padding: 0;
    color: #000;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    border: none !important;
    border-bottom: none !important;
    background: none;
}

.featured-story-card-meta {
    display: flex;
    gap: 8px;
    font-size: 1.05rem;
    color: #666;
    flex-shrink: 0;
}

.featured-story-card-views {
    display: flex;
    align-items: center;
    gap: 3px;
}

.featured-stories-loading {
    text-align: center;
    padding: 40px;
    color: #666;
}

.featured-stories-empty {
    text-align: center;
    padding: 30px;
    color: #999;
    font-style: italic;
}

/* Featured stories in sidebar (gallery page) */
.story-sidebar .featured-stories-section {
    max-width: 100%;
    margin-bottom: 20px;
    padding: 15px;
}

.story-sidebar .featured-stories-header h2 {
    font-size: 1.3rem;
}

.story-sidebar .featured-stories-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

@media (max-width: 768px) {
    .story-sidebar .featured-stories-grid {
        grid-template-columns: 1fr;
    }
}


/* Gallery Layout - Side Navigation */
.gallery-layout {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 20px;
    width: 100%;
    position: relative;
}

/* Ensure main viewer takes central space */
.comic-viewer {
    flex: 1;
    max-width: 1300px;
}

/* Side Navigation Arrows (Sticky) */
.nav-arrow.side-nav {
    position: sticky;
    top: 50vh;
    /* Center vertically relative to viewport */
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.8);
    border: 3px solid #000;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* font-size removed, using SVG size */
    box-shadow: 5px 5px 0px rgba(0, 0, 0, 0.2);
    z-index: 100;
    flex-shrink: 0;
    /* Prevent shrinking */
    transition: all 0.2s ease;
    padding: 0;
    /* Remove padding to center SVG */
}

.nav-arrow.side-nav svg {
    display: block;
}

.nav-arrow.side-nav:hover {
    transform: translateY(-50%) scale(1.1);
    background: #fff;
    box-shadow: 8px 8px 0px rgba(0, 0, 0, 0.3);
    color: var(--accent-color);
}

.nav-arrow.side-nav:disabled {
    opacity: 0.3;
    pointer-events: none;
    box-shadow: none;
}

/* Mobile: Move arrows to bottom because side space is limited */
@media (max-width: 800px) {
    .gallery-layout {
        flex-direction: column;
        align-items: center;
    }

    .nav-arrow.side-nav {
        position: static;
        /* No longer sticky */
        transform: none;
        width: 100%;
        border-radius: 8px;
        margin: 10px 0;
    }

    /* Reorder for mobile: Top arrow (Prev) above, Bottom arrow (Next) below */
    #prevStoryBtn {
        order: -1;
    }

    #nextStoryBtn {
        order: 2;
    }

    .comic-viewer {
        order: 1;
    }
}

/* Legacy wrapper removal backup */
.story-title-wrapper {
    display: none;
}