:root {
    /* Color Palette - Storybook */
    --bg-color: #FAF3E3;
    --header-bg: #FAF3E3;
    --primary-color: #D86B3D; /* Terracotta */
    --secondary-color: #E8A93A; /* Mustard/Ochre */
    --tertiary-green: #4C6B4F; /* Forest Green */
    --tertiary-teal: #3E7C7B; /* Dusty Teal */
    --text-color: #2B2A4C; /* Deep Indigo */
    --text-light: #4A4A68;
    
    /* Typography */
    --font-heading: 'Lora', serif;
    --font-body: 'Nunito Sans', sans-serif;
    
    /* Shadows and Borders */
    --shadow-soft: 0 4px 15px rgba(43, 42, 76, 0.08);
    --shadow-hover: 0 10px 25px rgba(43, 42, 76, 0.12);
    --border-radius-lg: 20px;
    --border-radius-md: 16px;
    --border-radius-pill: 50px;
}

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

body {
    font-family: var(--font-body);
    font-size: 18px;
    line-height: 1.6;
    background-color: var(--bg-color);
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noise)' opacity='0.05'/%3E%3C/svg%3E");
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

body.page-transitioning {
    opacity: 0;
    transform: translateY(10px);
}

/* Global Focus Styles */
*:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 3px;
    border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

/* Header & Controls */
header {
    background: var(--header-bg);
    padding: 1.5rem 3rem;
    box-shadow: var(--shadow-soft);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1.5rem;
    position: relative;
    z-index: 10;
}

.logo h1 {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    color: var(--primary-color);
    font-weight: 800;
    letter-spacing: -0.5px;
}

.logo p {
    color: var(--text-light);
    font-weight: 500;
    font-size: 1.1rem;
}

.nav-btn {
    background-color: var(--primary-color);
    color: white;
    text-decoration: none;
    padding: 0.8rem 1.5rem;
    border-radius: var(--border-radius-pill);
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.1rem;
    min-height: 44px;
    min-width: 44px;
    box-shadow: 0 4px 10px rgba(216, 107, 61, 0.2);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease, box-shadow 0.2s ease;
    display: inline-block;
}

.nav-btn:hover {
    transform: translateY(-2px) scale(1.02);
    background-color: #c05d33;
    box-shadow: 0 6px 15px rgba(216, 107, 61, 0.3);
    color: white;
}

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

.map-controls {
    margin-top: -14rem; /* Pull filters extremely close to the map */
    justify-content: center;
    position: relative;
    z-index: 10;
}

select {
    appearance: none;
    background: #F8F9FA;
    border: 2px solid transparent;
    padding: 1.2rem 2.2rem;
    border-radius: var(--border-radius-pill);
    font-family: var(--font-body);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.3s ease;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%232D3436%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 1.2rem top 50%;
    background-size: 0.65rem auto;
    padding-right: 3rem;
    min-height: 44px;
    min-width: 44px;
}

select:hover, select:focus {
    border-color: var(--secondary-color);
    outline: none;
    background-color: white;
}

.btn-primary, .btn-secondary {
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: var(--border-radius-pill);
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 44px;
    min-width: 44px;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn-primary {
    background: var(--primary-color);
    box-shadow: 0 4px 15px rgba(216, 107, 61, 0.3);
}

.btn-primary:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 8px 25px rgba(216, 107, 61, 0.4);
}

.btn-secondary {
    background: var(--secondary-color);
    color: var(--text-color);
    box-shadow: 0 4px 15px rgba(232, 169, 58, 0.3);
}

.btn-secondary:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 8px 25px rgba(232, 169, 58, 0.4);
}

/* Map Container */
.map-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem 2rem 0; /* Reduced top padding */
    position: relative;
}

.world-map {
    width: 100%;
    max-width: 1400px; /* Made map bigger */
    height: auto;
    filter: drop-shadow(0 20px 30px rgba(0,0,0,0.08));
    margin-bottom: -6rem; /* Pull filters closer */
}

.map-region {
    transition: fill 0.3s ease, filter 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: pointer;
    transform-origin: center;
}

@keyframes wiggle {
    0% { transform: rotate(0deg); }
    25% { transform: rotate(-1deg); }
    50% { transform: rotate(1deg); }
    75% { transform: rotate(-1deg); }
    100% { transform: rotate(0deg); }
}

.map-region:hover {
    fill: var(--tertiary-green) !important;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.2));
    animation: wiggle 0.6s ease-in-out infinite;
}

.map-region.selected {
    fill: var(--primary-color) !important;
}

.map-region.dimmed {
    opacity: 0.3;
    pointer-events: none;
}

/* Welcome Text & Static Label */
.welcome-text {
    text-align: center;
    margin: 0.5rem auto 0;
    max-width: 600px;
}

.welcome-text h2 {
    font-family: var(--font-heading);
    color: var(--accent-color);
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.welcome-text p {
    color: var(--text-color);
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

.static-map-label {
    display: inline-block;
    background: var(--accent-color);
    color: white;
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.2rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    transition: background-color 0.3s ease;
}

/* Story Gallery Grid */
.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto 4rem;
}

/* Story Card */
.story-card {
    background: white;
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-soft);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.4s ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    border: 2px solid transparent;
}

.story-card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: var(--shadow-hover);
    border-color: rgba(216, 107, 61, 0.2);
}

.story-card h3 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: #2d3436;
    margin-bottom: 0.5rem;
}

.story-card .card-region {
    font-weight: 700;
    color: var(--tertiary-teal);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.story-card .card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: auto;
}

.card-meta .badge {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 2rem;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal-backdrop {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(45, 52, 54, 0.6);
    backdrop-filter: blur(8px);
}

.modal-content {
    background: white;
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    border-radius: var(--border-radius-lg);
    position: relative;
    z-index: 101;
    overflow-y: auto;
    box-shadow: 0 25px 50px rgba(0,0,0,0.2);
    transform: translateY(0) scale(1);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal.hidden .modal-content {
    transform: translateY(50px) scale(0.95);
}

.btn-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: rgba(0,0,0,0.05);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-color);
}

.btn-close:hover {
    background: #ff4757;
    color: white;
    transform: rotate(90deg);
}

.story-header {
    padding: 3rem 2.5rem 2rem;
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
    color: white;
    background-color: var(--secondary-color); /* Default, overridden in JS */
}

.story-region {
    text-transform: uppercase;
    font-size: 0.9rem;
    letter-spacing: 2px;
    font-weight: 800;
    opacity: 0.9;
}

#story-title {
    font-family: var(--font-heading);
    font-size: 2.8rem;
    margin: 0.5rem 0 1.5rem;
    line-height: 1.1;
}

.story-meta {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.badge {
    background: var(--bg-color);
    color: var(--text-color);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-pill);
    font-weight: 700;
    font-size: 0.9rem;
    border: 1px solid rgba(0,0,0,0.1);
}

.story-body {
    padding: 2.5rem;
    font-size: 1.25rem;
    line-height: 1.8;
    color: var(--text-color);
}

.story-body p {
    margin-bottom: 1.5rem;
}

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

/* Animations & Responsiveness */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    
    .controls {
        justify-content: center;
    }
    
    .logo h1 { font-size: 1.8rem; }
    
    #story-title { font-size: 2.2rem; }
    .story-body { font-size: 1.1rem; padding: 1.5rem; }
}


/* =========================================
   SUBMIT STORY PAGE
   ========================================= */
.submit-container {
    max-width: 800px;
    margin: 2rem auto 4rem;
    padding: 0 2rem;
}

.submit-card {
    background: white;
    border-radius: 24px;
    padding: 3rem;
    box-shadow: 0 15px 40px rgba(0,0,0,0.08);
}

.submit-card h2 {
    text-align: center;
    color: var(--primary-color);
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.submit-subtitle {
    text-align: center;
    color: #636e72;
    margin-bottom: 2.5rem;
    font-size: 1.1rem;
    line-height: 1.6;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: #2d3436;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group textarea {
    width: 100%;
    padding: 1rem;
    border: 2px solid #dfe6e9;
    border-radius: 12px;
    font-family: var(--font-body);
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group input[type="file"] {
    width: 100%;
    padding: 0.5rem 0;
    font-family: var(--font-body);
}

.submit-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 1.2rem;
    border-radius: 30px;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 8px 15px rgba(108, 92, 237, 0.3);
}

.submit-btn:hover {
    transform: translateY(-3px);
    background-color: #5a4bcf;
    box-shadow: 0 12px 20px rgba(108, 92, 237, 0.4);
}

.secondary-btn {
    background-color: var(--accent-color);
    box-shadow: 0 8px 15px rgba(253, 160, 133, 0.3);
    margin-top: 1rem;
}

.secondary-btn:hover {
    background-color: #e68d71;
    box-shadow: 0 12px 20px rgba(253, 160, 133, 0.4);
}

.status-message {
    text-align: center;
    padding: 2rem;
    border-radius: 16px;
    background: #f8f9fa;
    margin-top: 1rem;
}

.status-message.success {
    background: #e8f8f5;
    border: 2px solid #1abc9c;
}

.status-message.success h3 {
    color: #1abc9c;
    margin-bottom: 0.5rem;
    font-size: 2rem;
}

.status-message.error {
    background: #fdfefe;
    border: 2px solid #e74c3c;
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border-left-color: var(--primary-color);
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

/* Map Animations & Enhancements */
@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-10px) rotate(2deg); }
}

@keyframes pulse-wave {
    0% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.1); opacity: 0.2; }
    100% { transform: scale(1); opacity: 0.6; }
}

.floating-cloud {
    position: absolute;
    opacity: 0.7;
    animation: float 8s ease-in-out infinite;
    pointer-events: none;
    z-index: 5;
}

.ocean-wave {
    animation: pulse-wave 4s ease-in-out infinite;
    transform-origin: center;
}

/* Global Night Mode overrides */
[data-theme="night"] {
    --bg-color: #1A1A2E;
    --header-bg: #16213E;
    --text-color: #EAE0C8;
    --text-light: #B0A8B9;
    --shadow-soft: 0 4px 15px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 10px 25px rgba(0, 0, 0, 0.6);
}

[data-theme="night"] body {
    background-image: none; /* remove noise for clearer night sky */
}

[data-theme="night"] .btn-secondary {
    background-color: #0F3460;
    color: #EAE0C8;
    border-color: #0F3460;
}

[data-theme="night"] .btn-icon {
    background-color: #16213E;
    color: #EAE0C8;
}

[data-theme="night"] .btn-icon.active {
    background-color: var(--primary-color);
}

/* Audio Controls */
#music-toggle-btn {
    background-color: var(--tertiary-teal);
    transition: all 0.3s ease;
}

#music-toggle-btn:hover {
    background-color: #2c5958;
}

#music-toggle-btn.music-active {
    background-color: var(--tertiary-green);
    animation: gentle-pulse 2s infinite ease-in-out;
}

@keyframes gentle-pulse {
    0% { transform: scale(1); box-shadow: 0 4px 10px rgba(76, 107, 79, 0.2); }
    50% { transform: scale(1.05); box-shadow: 0 8px 20px rgba(76, 107, 79, 0.4); }
    100% { transform: scale(1); box-shadow: 0 4px 10px rgba(76, 107, 79, 0.2); }
}


/* Surprise Animation Overlay */
.surprise-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(250, 243, 227, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

[data-theme="night"] .surprise-overlay,
body.high-contrast .surprise-overlay {
    background: rgba(43, 42, 76, 0.95);
}

.surprise-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.book-anim {
    font-size: 6rem;
    animation: flipBookPage 1.2s infinite cubic-bezier(0.45, 0, 0.55, 1);
    transform-style: preserve-3d;
}

@keyframes flipBookPage {
    0% { transform: perspective(600px) rotateY(0deg); }
    100% { transform: perspective(600px) rotateY(360deg); }
}

.surprise-text {
    font-family: var(--font-heading);
    font-size: 2rem;
    color: var(--primary-color);
    margin-top: 1.5rem;
    font-weight: 800;
    animation: pulseText 1s infinite alternate;
}

@keyframes pulseText {
    0% { opacity: 0.7; transform: scale(0.95); }
    100% { opacity: 1; transform: scale(1.05); }
}


/* Status Badges on Story Cards */
.status-badges {
    float: right;
    display: flex;
    gap: 0.2rem;
    font-size: 1.2rem;
    line-height: 1;
}

.status-icon {
    display: inline-block;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}
