/* =========================================
   1. GLOBAL VARIABLES & RESET
   ========================================= */
:root {
    --bg-color: #050505;
    --sidebar-bg: #0a0a0a;
    --card-bg: rgba(255, 255, 255, 0.08);
    --card-border: rgba(255, 255, 255, 0.15);
    --accent: #4488ff;
    /* Default Blue */
    --accent-glow: rgba(100, 200, 255, 0.15);
    --text-main: #ffffff;
    --text-muted: #cccccc;

    /* Specific Theme Colors */
    --correct: #44ff44;
    --wrong: #ff4444;
}

/* Theme Overrides */
.theme-purple {
    --accent: #aa44ff;
}

.theme-gold {
    --accent: #ffcc00;
}

.theme-cyan {
    --accent: #00ccff;
}

.theme-teal {
    --accent: #2a9d8f;
}

.theme-red {
    --accent: #ff4444;
}

.theme-earth {
    --accent: #8c7356;
}

.theme-blue {
    --accent: #4488ff;
}


.theme-light-blue {
    --bg-color: #eaf4ff;
    --sidebar-bg: #dcecff;
    --card-bg: rgba(255, 255, 255, 0.78);
    --card-border: rgba(100, 160, 230, 0.35);
    --accent: #4a9fff;
    --accent-glow: rgba(74, 159, 255, 0.2);
    --text-main: #0f2a44;
    --text-muted: #3c5f82;
}

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

body,
html {
    width: 100%;
    height: 100%;
    /* overflow: hidden; -> Default for apps, overridden for Index if needed */
    background: var(--bg-color);
    font-family: 'Outfit', sans-serif;
    color: var(--text-main);
    display: flex;
    flex-direction: row;
}

/* =========================================
   2. SIDEBAR
   ========================================= */
#sidebar {
    width: 400px;
    min-width: 400px;
    height: 100%;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--card-border);
    /* unified border color */
    overflow-y: auto;
    padding: 40px;
    box-sizing: border-box;
    z-index: 10;
    display: flex;
    flex-direction: column;
}

/* Sorting.html had distinct width, unifying to 400px for consistency unless broken */
/* Sorting was 350px. 400px is better for consistency. */

#sidebar h1 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    color: var(--accent);
}

/* Index uses gradient text for h1, we can keep that rule specific to index or allow .gradient-text class */
.gradient-text {
    background: linear-gradient(to right, #fff, #ccc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: #fff;
    /* Fallback */
}

#sidebar p {
    font-size: 1rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 20px;
}

#sidebar h2 {
    font-size: 1.2rem;
    margin-top: 20px;
    margin-bottom: 10px;
    color: #fff;
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
}

.back-link {
    display: inline-block;
    margin-bottom: 30px;
    text-decoration: none;
    color: #888;
    border: 1px solid #444;
    padding: 5px 10px;
    border-radius: 4px;
    transition: 0.3s;
    font-size: 12px;
    width: fit-content;
}

.back-link:hover {
    color: #fff;
    border-color: #666;
}

/* Stat Box (Shared by Planetarium & Flag Guesser) */
.stat-box {
    background: color-mix(in srgb, var(--sidebar-bg) 72%, white);
    padding: 15px;
    border-radius: 4px;
    /* Unified radius */
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    margin-bottom: 20px;
    border: 1px solid var(--card-border);
    /* Added border from flag guesser */
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* From flag guesser */
}

/* =========================================
   3. MAIN CONTENT AREAS
   ========================================= */
/* Generic Canvas Container */
#canvas-container,
#main-content {
    flex-grow: 1;
    position: relative;
    height: 100%;
    background: var(--bg-color);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Index Main Area */
main.index-content {
    opacity: 0;
    animation: fade-in-content 1s ease-out 3s forwards;
    flex-grow: 1;
    height: 100%;
    overflow-y: auto;
    padding: 3rem;
    text-align: left;
}

@keyframes fade-in-content {
    to {
        opacity: 1;
    }
}

/* Index Grid & Cards */
.section-title {
    font-size: 1.5rem;
    color: var(--text-main);
    margin: 3rem 0 1rem 0;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 0.5rem;
}

.deploy-footer {
    margin-top: 40px;
    padding: 18px 0 8px;
    border-top: 1px solid var(--card-border);
    color: var(--text-muted);
    font-size: 0.85rem;
    opacity: 0.75;
}

#latest-commit {
    display: inline-block;
    margin-left: 6px;
    padding: 3px 8px;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main);
    font-family: "Courier New", monospace;
    font-size: 0.78rem;
    line-height: 1.2;
}

.link-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    width: 100%;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 2rem;
    text-decoration: none;
    color: var(--text-main);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.05), transparent);
    transform: translateX(-100%);
    transition: 0.5s;
}

.card:hover::before {
    transform: translateX(100%);
}

.card:hover {
    transform: translateY(-5px);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
}

.card h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.card p {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.card-icon {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #fff;
}

/* =========================================
   4. UI CONTROLS (Simulations)
   ========================================= */
#controls {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: rgba(0, 0, 0, 0.85);
    /* Darker for better contrast */
    padding: 20px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    width: 280px;
    z-index: 20;
}

.control-group,
.slider-group {
    margin-bottom: 0;
    background: transparent;
    padding: 0;
    border: none;
    color: #ccc;
    font-size: 0.9rem;
}

label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.8rem;
    color: #888;
    font-weight: bold;
}

select,
button,
input[type="range"] {
    width: 100%;
    padding: 10px;
    background: #222;
    border: 1px solid #444;
    color: #fff;
    border-radius: 4px;
    font-family: inherit;
    margin-bottom: 10px;
}

input[type="range"] {
    margin-top: 5px;
    margin-bottom: 5px;
}

button {
    background: rgba(var(--accent-rgb), 0.1);
    /* Hack: standard accent rgb? Let's use var with manual hex alpha for now or calc */
    background: #222;
    /* Default fallback */
    border: 1px solid var(--accent);
    color: var(--accent);
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
}

button:hover,
button.active {
    background: var(--accent);
    color: #fff;
}

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

.toggle-group {
    display: flex;
    gap: 5px;
}

.toggle-group button {
    flex: 1;
    font-size: 0.8rem;
}

/* Status / Time Overlay */
#status-overlay,
#time-display {
    position: absolute;
    bottom: 20px;
    left: 20px;
    /* Standardize left */
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 20px;
    border-radius: 20px;
    color: #fff;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    /* Planetarium had centered time display. Let's keep specific override there if needed, 
       but left bottom is good default */
}

/* Planetarium Override */
.planetarium-time {
    bottom: 30px;
    left: 50% !important;
    transform: translateX(-50%);
    background: transparent !important;
    text-shadow: 0 2px 4px #000;
    font-size: 1.2rem !important;
    pointer-events: none;
}

/* =========================================
   5. SPECIFIC PAGES (Flag Guesser, etc)
   ========================================= */
/* Flag Guesser */
#game-area {
    flex-grow: 1;
    position: relative;
    height: 100%;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#flag-container {
    width: 100%;
    max-width: 600px;
    height: 350px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 40px;
    background: #0a0a0a;
    border: 2px solid #333;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

#flag-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

#options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    width: 100%;
    max-width: 800px;
}

.option-btn {
    padding: 20px;
    font-size: 1.2rem;
    height: auto;
    /* override general button height/padding if any */
}

.option-btn.correct {
    background: rgba(68, 255, 68, 0.2) !important;
    border-color: var(--correct) !important;
    color: var(--correct) !important;
}

.option-btn.wrong {
    background: rgba(255, 68, 68, 0.2) !important;
    border-color: var(--wrong) !important;
    color: var(--wrong) !important;
}

.score-row {
    display: flex;
    justify-content: space-between;
}

.score-val {
    font-weight: bold;
    color: var(--accent);
}

.loading {
    color: #888;
    font-size: 1.5rem;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.5;
    }
}

/* =========================================
   6. ANIMATIONS (Index)
   ========================================= */
.ambient-glow {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at center, var(--accent-glow) 0%, transparent 60%);
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: -1;
    animation: pulse-glow 8s ease-in-out infinite alternate;
}

@keyframes pulse-glow {
    0% {
        opacity: 0.5;
        transform: translate(-50%, -50%) scale(0.8);
    }

    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.2);
    }
}

#intro-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fade-out-overlay 1s ease-in-out 2.5s forwards;
}

.intro-text {
    font-size: 3rem;
    font-weight: 700;
    opacity: 0;
    transform: translateY(20px);
    animation: slide-up-fade 2s cubic-bezier(0.2, 0.8, 0.2, 1) 0.5s forwards;
}

@keyframes slide-up-fade {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }

    20% {
        opacity: 1;
        transform: translateY(0);
    }

    80% {
        opacity: 1;
        transform: translateY(0);
    }

    100% {
        opacity: 0;
        transform: translateY(-20px);
    }
}

@keyframes fade-out-overlay {
    to {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }
}

/* =========================================
   7. MOBILE RESPONSIVE
   ========================================= */
@media (max-width: 900px) {
    body {
        flex-direction: column;
        overflow: auto;
        /* Allow scroll on mobile */
        height: auto;
    }

    #sidebar {
        width: 100%;
        min-width: 0;
        height: auto;
        padding: 40px 20px;
        order: 2;
        /* Content first? Or Sidebar first? Index has Sidebar first naturally. */
    }

    /* Index sidebar override */


    /* App sidebar override - usually want app on top? 
       For now, keeping standard flow: Sidebar -> Main. 
       Actually, standard HTML flow is Sidebar first in DOM. 
       Mobile often moves sidebar to bottom or hamburger.
       Let's sticky to simple column layout.
    */

    main,
    #canvas-container,
    #game-area {
        height: 60vh;
        /* Fixed height for app area on mobile */
        width: 100%;
    }

    main.index-content {
        padding: 20px;
        overflow: visible;
        height: auto;
    }
}
