/* Sandstone (default) */

:root,
[data-theme="sandstone"] {
    --color-bg: #f5f0e8;
    --color-surface: #ffffff;
    --color-header: #3b2f1e;
    --color-header-text: #fdf6ec;
    --color-accent: #d4790e;
    --color-text: #2c2416;
    --color-text-muted: #7a6e5f;
    --color-link: #b35c00;
    --color-border: #d9d0c3;
    --color-triassic: #c0392b;
    --color-jurassic: #27ae60;
    --color-cretaceous: #2471a3;
    --color-triassic-bg: #fce4e1;
    --color-jurassic-bg: #dff5e8;
    --color-cretaceous-bg: #dbeaf5;
    --color-badge-locked: #ccc;
    --color-badge-unlocked: #d4790e;
    --color-badge-bg: #fff8ef;
    --color-footer-link: #f0c97a;
    --color-loading-bg: rgba(59, 47, 30, 0.85);
    --radius: 6px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    --transition: 0.2s ease;
}

/* Glacier */

[data-theme="glacier"] {
    --color-bg: #e8f0f8;
    --color-surface: #f7fafd;
    --color-header: #1e3a52;
    --color-header-text: #e8f4fc;
    --color-accent: #5ba4cf;
    --color-text: #1a2e3d;
    --color-text-muted: #5e7a8f;
    --color-link: #2980b9;
    --color-border: #c5d8e8;
    --color-triassic: #d45b5b;
    --color-jurassic: #3ba876;
    --color-cretaceous: #4a8fc2;
    --color-triassic-bg: #fce8e8;
    --color-jurassic-bg: #e0f5ec;
    --color-cretaceous-bg: #dbeaf8;
    --color-badge-locked: #b8cdd9;
    --color-badge-unlocked: #5ba4cf;
    --color-badge-bg: #edf5fc;
    --color-footer-link: #8ec6e8;
    --color-loading-bg: rgba(30, 58, 82, 0.88);
}

/* Jungle */

[data-theme="jungle"] {
    --color-bg: #e8f2e6;
    --color-surface: #f5faf4;
    --color-header: #1a3a1a;
    --color-header-text: #e8f5e4;
    --color-accent: #2d8659;
    --color-text: #1a2e1a;
    --color-text-muted: #5a7a5a;
    --color-link: #1e7040;
    --color-border: #bdd4b8;
    --color-triassic: #c44e3d;
    --color-jurassic: #2d8e4e;
    --color-cretaceous: #3878a8;
    --color-triassic-bg: #fce4df;
    --color-jurassic-bg: #d5f0de;
    --color-cretaceous-bg: #dce8f4;
    --color-badge-locked: #b5ccb0;
    --color-badge-unlocked: #2d8659;
    --color-badge-bg: #eaf5e7;
    --color-footer-link: #8ad4a0;
    --color-loading-bg: rgba(26, 58, 26, 0.88);
}

/* Campfire */

[data-theme="campfire"] {
    --color-bg: #1e1610;
    --color-surface: #2a2018;
    --color-header: #352820;
    --color-header-text: #f0dcc4;
    --color-accent: #c97b2a;
    --color-text: #e8d5c0;
    --color-text-muted: #a89278;
    --color-link: #e0a84c;
    --color-border: #4a3828;
    --color-triassic: #d46a5a;
    --color-jurassic: #5aaa6e;
    --color-cretaceous: #5a9cc8;
    --color-triassic-bg: #3a2220;
    --color-jurassic-bg: #1e3022;
    --color-cretaceous-bg: #1e2a38;
    --color-badge-locked: #5a4a38;
    --color-badge-unlocked: #c97b2a;
    --color-badge-bg: #352a1e;
    --color-footer-link: #e0a84c;
    --color-loading-bg: rgba(30, 22, 16, 0.92);
}

/* Deep Sea */

[data-theme="deep_sea"] {
    --color-bg: #0c1a24;
    --color-surface: #132838;
    --color-header: #0a1e30;
    --color-header-text: #b8dce8;
    --color-accent: #1a6b8a;
    --color-text: #c0dae6;
    --color-text-muted: #6a98b0;
    --color-link: #40b0d4;
    --color-border: #1e3e52;
    --color-triassic: #d06050;
    --color-jurassic: #40b878;
    --color-cretaceous: #48a0d8;
    --color-triassic-bg: #2a1a1a;
    --color-jurassic-bg: #0e2a1e;
    --color-cretaceous-bg: #0e2030;
    --color-badge-locked: #2a4050;
    --color-badge-unlocked: #40b0d4;
    --color-badge-bg: #162e40;
    --color-footer-link: #60c0e0;
    --color-loading-bg: rgba(12, 26, 36, 0.92);
}

/* Volcano */

[data-theme="volcano"] {
    --color-bg: #1a0e0e;
    --color-surface: #2a1414;
    --color-header: #301010;
    --color-header-text: #f0d0c0;
    --color-accent: #c0392b;
    --color-text: #e8ccc0;
    --color-text-muted: #a87868;
    --color-link: #e06848;
    --color-border: #4a2020;
    --color-triassic: #e04030;
    --color-jurassic: #50a860;
    --color-cretaceous: #4890c0;
    --color-triassic-bg: #3a1a18;
    --color-jurassic-bg: #1a2e1a;
    --color-cretaceous-bg: #182030;
    --color-badge-locked: #503030;
    --color-badge-unlocked: #e06848;
    --color-badge-bg: #341a18;
    --color-footer-link: #f0a080;
    --color-loading-bg: rgba(26, 14, 14, 0.92);
}

/* Reset */

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
}

a {
    color: var(--color-link);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* Layout */

body {
    display: flex;
    flex-direction: column;
}

#app-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 1.2rem;
    background: var(--color-header);
    color: var(--color-header-text);
    flex-shrink: 0;
    z-index: 1000;
    flex-wrap: wrap;
}

#app-main {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

#map {
    flex: 1;
    z-index: 1;
}

#app-footer {
    padding: 0.5rem 1.2rem;
    background: var(--color-header);
    color: var(--color-header-text);
    font-size: 0.78rem;
    text-align: center;
    flex-shrink: 0;
    z-index: 1000;
}
#app-footer a {
    color: var(--color-footer-link);
}
#app-footer .sep {
    margin: 0 0.4rem;
    opacity: 0.4;
}
#app-footer .credits {
    margin-top: 0.2rem;
    opacity: 0.7;
}

/* Header */

.header-brand h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1.1;
}
.header-brand .tagline {
    font-size: 0.72rem;
    opacity: 0.7;
    display: block;
}

.header-search {
    flex: 1;
    min-width: 180px;
    max-width: 360px;
}
.header-search input {
    width: 100%;
    padding: 0.45rem 0.8rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.15);
    color: var(--color-header-text);
    outline: none;
    transition: background var(--transition);
}
.header-search input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}
.header-search input:focus {
    background: rgba(255, 255, 255, 0.25);
}

.header-filters {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 0.35rem 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: var(--radius);
    background: transparent;
    color: var(--color-header-text);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition);
}
.filter-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}
.filter-btn.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #fff;
    font-weight: 600;
}
.filter-btn.triassic.active {
    background: var(--color-triassic);
    border-color: var(--color-triassic);
}
.filter-btn.jurassic.active {
    background: var(--color-jurassic);
    border-color: var(--color-jurassic);
}
.filter-btn.cretaceous.active {
    background: var(--color-cretaceous);
    border-color: var(--color-cretaceous);
}

/* Stats Panel */

#stats-panel {
    width: 260px;
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    overflow-y: auto;
    z-index: 500;
    flex-shrink: 0;
    transition: margin-right var(--transition);
}

#stats-panel.collapsed {
    margin-right: -260px;
}

#stats-toggle {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 600;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    display: none;
}

#stats-content {
    padding: 1rem;
}

#stats-content h2 {
    font-size: 1.05rem;
    margin-bottom: 0.8rem;
    color: var(--color-header);
}

.stat-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1.2rem;
}

.stat {
    display: flex;
    flex-direction: column;
    padding: 0.6rem;
    background: var(--color-bg);
    border-radius: var(--radius);
}
.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-accent);
    line-height: 1.1;
}
.stat-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Badges */

#badges-section h3 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: var(--color-header);
}

#badges-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.badge-card {
    padding: 0.5rem;
    border-radius: var(--radius);
    text-align: center;
    background: var(--color-bg);
    border: 2px solid var(--color-badge-locked);
    opacity: 0.5;
    transition: all var(--transition);
}
.badge-card.unlocked {
    border-color: var(--color-badge-unlocked);
    opacity: 1;
    background: var(--color-badge-bg);
}
.badge-icon {
    font-size: 1.5rem;
    display: block;
    margin-bottom: 0.15rem;
}
.badge-name {
    font-size: 0.7rem;
    font-weight: 600;
    display: block;
}
.badge-desc {
    font-size: 0.6rem;
    color: var(--color-text-muted);
    display: block;
}

/* Progress actions */

#progress-actions {
    margin-top: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.action-btn {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition);
}
.action-btn:hover {
    background: var(--color-bg);
    border-color: var(--color-accent);
}

/* Map marker popups */

.site-popup {
    min-width: 220px;
    font-size: 0.85rem;
    line-height: 1.45;
}
.site-popup h3 {
    font-size: 1rem;
    margin-bottom: 0.3rem;
    color: var(--color-header);
}
.site-popup .period-tag {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #fff;
    margin-bottom: 0.4rem;
}
.period-tag.triassic  { background: var(--color-triassic); }
.period-tag.jurassic  { background: var(--color-jurassic); }
.period-tag.cretaceous { background: var(--color-cretaceous); }

.site-popup .detail-row {
    margin: 0.15rem 0;
}
.site-popup .detail-label {
    font-weight: 600;
    color: var(--color-text-muted);
}
.site-popup .species-list {
    margin-top: 0.3rem;
    padding-left: 1.1rem;
}
.site-popup .species-list li {
    font-style: italic;
    margin-bottom: 0.1rem;
}
.site-popup .podcast-link {
    display: inline-block;
    margin-top: 0.5rem;
    padding: 0.3rem 0.7rem;
    background: var(--color-accent);
    color: #fff;
    border-radius: var(--radius);
    font-size: 0.78rem;
    font-weight: 600;
}
.site-popup .podcast-link:hover {
    text-decoration: none;
    opacity: 0.9;
}

/* Loading overlay */

#loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--color-loading-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.4s ease;
}
#loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}
.loading-content {
    text-align: center;
    color: var(--color-header-text);
}
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Theme Picker */

.header-theme {
    position: relative;
}

#theme-toggle {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: var(--radius);
    color: var(--color-header-text);
    padding: 0.35rem 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all var(--transition);
}
#theme-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
}

#theme-picker {
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.5rem;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-4px);
    transition: all 0.15s ease;
    z-index: 1100;
}
#theme-picker.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

#theme-picker-list {
    display: flex;
    gap: 0.4rem;
}

.theme-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    outline: none;
}
.theme-swatch:hover {
    transform: scale(1.15);
}
.theme-swatch.active {
    border-color: var(--color-text);
    box-shadow: 0 0 0 2px var(--color-surface), 0 0 0 4px var(--color-text);
}

/* Responsive */

@media (max-width: 768px) {
    #app-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        padding: 0.5rem 0.8rem;
    }
    .header-brand {
        display: flex;
        align-items: baseline;
        gap: 0.5rem;
    }
    .header-brand h1 {
        font-size: 1.2rem;
    }
    .header-search {
        max-width: none;
    }
    .header-filters {
        justify-content: center;
    }

    #stats-panel {
        position: absolute;
        top: 0;
        right: 0;
        height: 100%;
        box-shadow: var(--shadow);
        margin-right: -260px;
        transition: margin-right 0.3s ease;
    }
    #stats-panel.open {
        margin-right: 0;
    }
    #stats-toggle {
        display: block;
    }

    #app-footer .foss-notice {
        display: block;
        margin-top: 0.2rem;
    }
    #app-footer .sep {
        display: none;
    }
}
