:root {
    --text-color: #2c2c2c;
    --placeholder-color: #888;
    --input-bg: rgba(255, 255, 255, 0.4);
    --input-border: rgba(255, 255, 255, 0.6);
    --focus-border: rgba(200, 200, 200, 0.8);
}

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

body {
    font-family: 'Inter', sans-serif;
    color: var(--text-color);
    min-height: 100vh;
    width: 100vw;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Changed from center to allow scrolling from top */
    /* Luxurious Pearl Gradient */
    background: radial-gradient(circle at 50% 0%, #fdfbf7 0%, #f3f4f6 40%, #e8e8e8 100%),
        linear-gradient(120deg, rgba(255, 255, 255, 0.8) 0%, rgba(240, 240, 255, 0.2) 100%);
    background-blend-mode: soft-light;
}

.container {
    text-align: center;
    width: 100%;
    max-width: 600px;
    padding: 2rem;
    animation: fadeIn 1.5s ease-out;
}

header {
    margin-bottom: 3rem;
}

.title {
    font-family: 'Playfair Display', serif;
    font-size: 3.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
    background: linear-gradient(45deg, #1a1a1a, #4a4a4a);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tagline {
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #666;
    opacity: 0.8;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Image Preview & Status Button */
.image-preview-container {
    position: relative;
    margin-top: 0.5rem;
    border-radius: 8px;
    overflow: hidden;
}

.status-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    transition: all 0.2s ease;
    z-index: 10;
    padding: 0;
}

.status-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.05);
}

/* Loading State */
.status-btn.loading {
    cursor: pointer;
    /* Allow clicking to cancel */
}

/* Default: Hide all icons */
.spinner-ring,
.stop-icon,
.check-icon,
.delete-icon {
    display: none;
}

/* Loading State Visibility */
.status-btn.loading .spinner-ring {
    display: block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    position: absolute;
}

.status-btn.loading .stop-icon {
    display: block;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.2s;
    font-weight: bold;
}

.status-btn.loading:hover .stop-icon {
    opacity: 1;
}

.status-btn.loading:hover .spinner-ring {
    opacity: 0.3;
}

/* Success State Visibility */
.status-btn.success {
    background: #4caf50;
}

.status-btn.success .check-icon {
    display: block;
}

.status-btn.success .delete-icon {
    display: none;
    /* Hidden by default */
    font-size: 20px;
    line-height: 1;
}

.status-btn.success:hover {
    background: #f44336;
}

.status-btn.success:hover .check-icon {
    display: none;
}

.status-btn.success:hover .delete-icon {
    display: block;
}

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

.input-group {
    position: relative;
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    align-items: center;
}

input[type="text"] {
    width: 100%;
    padding: 1.2rem 3.5rem 1.2rem 1.5rem;
    /* Added right padding for button */
    font-family: 'Inter', sans-serif;
    font-size: 1.1rem;
    color: var(--text-color);
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 12px;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.02);
    backdrop-filter: blur(10px);
}

input[type="text"]::placeholder {
    color: var(--placeholder-color);
    font-weight: 300;
}

input[type="text"]:focus {
    background: rgba(255, 255, 255, 0.7);
    border-color: var(--focus-border);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
}

.action-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.2s ease;
    color: #666;
    z-index: 10;
}

.action-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: #333;
}

.action-btn:disabled {
    opacity: 0;
    cursor: default;
    pointer-events: none;
}

.arrow-btn {
    background-color: #ff9999;
    background-size: 200% 200%;
    animation: magicalColorChange 5s ease infinite;
    color: white;
    width: 40px;
    height: 40px;
    padding: 0;
    box-shadow: 0 2px 8px rgba(255, 153, 153, 0.4);
}

.arrow-btn:hover {
    background-color: #ff8080;
    color: white;
    transform: translateY(-50%) scale(1.05);
    box-shadow: 0 4px 12px rgba(255, 153, 153, 0.5);
}

.loading-container {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    display: none;
    /* Hidden by default */
    align-items: center;
    justify-content: center;
    /* Ensure it doesn't affect layout */
    margin: 0;
    padding: 0;
}

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

.spinner {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid rgba(255, 153, 153, 0.2);
    border-top-color: #ff9999;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.stop-btn {
    position: relative;
    /* Reset absolute from .action-btn */
    right: auto;
    top: auto;
    transform: none;
    width: 24px;
    height: 24px;
    padding: 0;
    color: #ff6666;
    background: white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.stop-btn:hover {
    color: #ff4d4d;
    background: #fff0f0;
    transform: scale(1.1);
}

.message {
    margin-top: 2rem;
    font-family: 'Playfair Display', serif;
    font-size: 1.1rem;
    font-style: italic;
    color: #444;
    min-height: 1.5em;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.message.visible {
    opacity: 1;
}

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

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

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

@keyframes magicalColorChange {
    0% {
        background-position: 0% 50%;
        background-color: #ff9999;
    }

    50% {
        background-position: 100% 50%;
        background-color: #ffb366;
    }

    100% {
        background-position: 0% 50%;
        background-color: #ff99cc;
    }
}

.story-container {
    margin-top: 3rem;
    text-align: left;
    opacity: 0;
    transition: opacity 0.8s ease;
    max-height: 0;
    overflow: hidden;
}

.story-container.visible {
    opacity: 1;
    max-height: 5000px;
    /* Allow expansion */
    overflow: visible;
}

.book-title {
    font-family: 'Playfair Display', serif;
    font-size: 2rem;
    margin-bottom: 2rem;
    text-align: center;
    color: #333;
}

.book-cover {
    margin-bottom: 2rem;
    text-align: center;
}

.cover-image {
    width: 100%;
    max-width: 400px;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    display: inline-block;
}

.book-page {
    background: rgba(255, 255, 255, 0.6);
    padding: 1.5rem;
    padding-top: 2.5rem;
    margin-bottom: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    position: relative;
}

.book-page p {
    font-family: 'Inter', sans-serif;
    line-height: 1.6;
    color: #444;
}

.page-number {
    position: absolute;
    top: 0.5rem;
    right: 1rem;
    font-size: 0.7rem;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.page-image {
    width: 100%;
    height: auto;
    border-radius: 4px;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    display: block;
}

.image-error {
    background: rgba(255, 243, 205, 0.6);
    border: 1px solid rgba(255, 193, 7, 0.3);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: 150px;
}

.image-error-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.image-error-message {
    font-family: 'Inter', sans-serif;
    color: #856404;
    line-height: 1.6;
    flex: 1;
}

.character-inputs {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
    animation: fadeIn 0.5s ease-out;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.character-input-group {
    background: rgba(255, 255, 255, 0.7);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    width: 100%;
    text-align: left;
}


.character-input-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.character-input-label {
    display: block;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: #444;
    margin-bottom: 0;
}

.upload-ref-btn {
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: #666;
    font-family: 'Inter', sans-serif;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.upload-ref-btn:hover {
    background: #f8f9fa;
    color: #333;
    border-color: rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
}

.upload-ref-btn:disabled {
    opacity: 0.6;
    cursor: wait;
    transform: none;
}

.character-description-input {
    width: 100%;
    padding: 0.8rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    outline: none;
    resize: vertical;
    min-height: 80px;
    transition: all 0.2s ease;
}

.character-description-input:focus {
    background: rgba(255, 255, 255, 0.9);
    border-color: var(--focus-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.character-description-input::placeholder {
    color: #999;
    font-style: italic;
}