:root {
    /* Unified Palette */
    --primary: #4F46E5;
    --primary-dark: #4338CA;
    --secondary: #10B981;
    --accent: #FD79A8;
    --bg: #F3F4F6;
    --card-bg: #FFFFFF;
    --text: #1F2937;
    --text-light: #6B7280;
    --white: #ffffff;
    
    /* UI Constants */
    --border-radius: 16px;
    --shadow: 0 10px 20px rgba(0,0,0,0.08);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

.noto-color-emoji-regular {
  font-family: "Noto Color Emoji", sans-serif;
  font-weight: 400;
  font-style: normal;
}

body {
    font-family: 'Nunito', 'Segoe UI', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

body.app-mode {
    height: 100vh;
    overflow: hidden;
}

/* --- Shared Components --- */

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    width: 100%;
}

/* Header (App & Landing Shared) */
header {
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header nav {
    width: 100%;
}

nav.full-width-nav {
    display: flex;
    justify-content: space-between;
}

/* App Header Specifics */
body.app-mode header {
    background: var(--card-bg);
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    z-index: 10;
}

/* Landing/Content Header Specifics */
body:not(.app-mode) header {
    padding: 2rem 0;
}

h1 {
    margin: 0;
    font-weight: 800;
}

/* Navigation & Links */
a {
    color: var(--primary);
    text-decoration: none;
}

.back-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
}
.back-link:hover { text-decoration: underline; }

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    text-decoration: none;
}

/* Language Dropdown */
.lang-dropdown-container {
    position: relative;
    display: inline-block;
}

.lang-btn {
    background: white;
    border: 1px solid #E5E7EB;
    border-radius: 20px;
    padding: 6px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
    font-weight: 700;
    color: var(--text);
    font-size: 0.9rem;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.lang-btn:hover {
    background: #F9FAFB;
    border-color: #D1D5DB;
}

.lang-code {
    color: var(--text);
}

.lang-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 120%;
    background-color: white;
    min-width: 220px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    z-index: 100;
    padding: 8px;
    border: 1px solid #F3F4F6;
    max-height: 400px;
    overflow-y: auto;
}

.lang-menu.show {
    display: block;
    animation: fadeIn 0.2s ease-out;
}

.lang-item {
    color: var(--text);
    padding: 8px 12px;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 8px;
    transition: background 0.1s;
    font-size: 0.9rem;
    font-weight: 600;
}

.lang-item:hover {
    background-color: #F3F4F6;
}

.lang-item.active {
    background-color: #EEF2FF;
    color: var(--primary);
}

.check-icon {
    margin-left: auto;
    color: var(--primary);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* User Menu */
.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
}

.user-email {
    font-weight: 600;
    color: var(--text);
}

.btn-logout {
    text-decoration: none;
    color: var(--accent);
    font-weight: 700;
    font-size: 0.8rem;
    border: 1px solid var(--accent);
    padding: 4px 10px;
    border-radius: 20px;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: var(--accent);
    color: white;
}

/* --- App Mode (Home) Styles --- */

.app-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
    background: #fff;
    position: relative;
}

@media (min-width: 601px) {
    .app-container {
        margin: 20px auto;
        border-radius: var(--border-radius);
        box-shadow: var(--shadow);
        height: calc(100vh - 40px);
    }
}

/* Avatar Preview */
.avatar-stage {
    flex: 1;
    background: radial-gradient(circle at center, #fff 0%, #f0f0f0 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    min-height: 300px;
}

.avatar-stage svg {
    width: 260px;
    height: 280px;
    filter: drop-shadow(0 10px 15px rgba(0,0,0,0.1));
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.avatar-stage.loading svg {
    opacity: 0.5;
    transform: scale(0.95);
}

/* Controls Panel */
.controls-panel {
    background: var(--card-bg);
    display: grid;
    grid-template-columns: 130px 1fr;
    grid-template-rows: 1fr auto;
    height: 45%;
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.05);
    z-index: 5;
    overflow: hidden;
}

/* Tabs (Sidebar) */
.category-tabs {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px 10px 60px 10px; /* Added bottom padding for scrolling */
    gap: 10px;
    border-right: 1px solid #eee;
    border-bottom: none;
    background: #F8F9FA;
    grid-row: 1 / -1;
    grid-column: 1;
}

.category-tabs::-webkit-scrollbar {
    width: 4px;
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 12px 5px;
    border-radius: 12px;
    font-weight: 700;
    color: #636E72;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    text-align: center;
}

.tab-btn:hover {
    background: rgba(79, 70, 229, 0.1); /* Updated to primary color */
    color: var(--primary);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

/* Options Grid */
.options-viewport {
    grid-column: 2;
    grid-row: 1;
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #FAFAFA;
}

.options-grid {
    display: none;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 12px;
}

.options-grid.color-grid {
    row-gap: 24px; /* Double vertical spacing for colors */
}

.options-grid.active {
    display: grid;
}

.option-item {
    aspect-ratio: 1;
    background: white;
    border-radius: 12px;
    border: 2px solid transparent;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.8rem;
    text-align: center;
    padding: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: all 0.2s;
    overflow: hidden;
    word-break: break-word;
}

.option-item:hover {
    transform: translateY(-2px);
}

.option-item.selected {
    border-color: var(--primary);
    background: #F0EEFC;
}

.option-item.has-icon {
    padding: 5px;
}

.option-item.has-icon svg {
    width: 100%;
    height: 100%;
}

/* Color Swatches */
.option-item.color-swatch {
    border-radius: 50%;
    width: 60px;
    height: 60px;
    margin: 0 auto;
}

.option-item.color-swatch.selected {
    transform: scale(1.1);
    box-shadow: 0 0 0 3px white, 0 0 0 5px var(--primary);
}

/* Bottom Actions */
.game-actions {
    grid-column: 2;
    grid-row: 2;
    padding: 15px 20px;
    display: flex;
    gap: 15px;
    background: white;
    border-top: 1px solid #eee;
}

.action-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: transform 0.1s;
}

.action-btn:active {
    transform: scale(0.98);
}

.btn-random {
    background: #FFEAA7;
    color: #D35400;
}

.btn-save {
    background: var(--secondary);
    color: white;
}

/* --- Landing Page Styles --- */

.landing-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 0;
}

.hero {
    text-align: center;
    max-width: 800px;
    margin: 0 auto;
}

.hero h1 {
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 1.5rem;
    line-height: 1.1;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero p.subtitle {
    font-size: 1.25rem;
    color: var(--text-light);
    margin-bottom: 3rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.auth-card {
    background: white;
    padding: 2.5rem;
    border-radius: 1rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    max-width: 450px;
    margin: 0 auto;
    text-align: left;
}

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

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text);
}

input[type="email"], input[type="text"], textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid #D1D5DB;
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: border-color 0.15s ease;
    font-family: inherit;
}

input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

button[type="submit"] {
    width: 100%;
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 0.875rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.15s ease;
    font-family: inherit;
}

button[type="submit"]:hover {
    background-color: var(--primary-dark);
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-top: 5rem;
    text-align: left;
}

.feature-card {
    background: white;
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.feature-icon {
    font-size: 2rem;
    margin-bottom: 1rem;
    display: block;
}

.feature-title {
    font-weight: 700;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.feature-desc {
    color: var(--text-light);
    font-size: 0.95rem;
}

.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.alert-success {
    background-color: #D1FAE5;
    color: #065F46;
}

.alert-error {
    background-color: #FEE2E2;
    color: #991B1B;
}

footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-light);
    font-size: 0.875rem;
}

/* --- Sponsors Page Styles --- */

.cta-button {
    display: inline-block;
    background: var(--primary);
    color: white;
    padding: 1rem 2rem;
    border-radius: 0.5rem;
    font-weight: 700;
    text-decoration: none;
    transition: background 0.2s;
    font-size: 1.1rem;
}
.cta-button:hover { background: var(--primary-dark); }

section {
    padding: 4rem 0;
}

.section-title {
    text-align: center;
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 1rem;
    color: var(--text);
}

.section-subtitle {
    text-align: center;
    color: var(--text-light);
    max-width: 600px;
    margin: 0 auto 3rem;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}

.card {
    background: var(--white);
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.card-icon { font-size: 2.5rem; margin-bottom: 1rem; display: block; }
.card h3 { margin-bottom: 0.5rem; font-size: 1.25rem; color: var(--text); }
.card p { color: var(--text-light); font-size: 0.95rem; }

.funding-list {
    list-style: none;
    padding: 0;
    max-width: 600px;
    margin: 0 auto;
}
.funding-list li {
    background: white;
    padding: 1rem 1.5rem;
    margin-bottom: 1rem;
    border-radius: 0.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    font-weight: 600;
    color: var(--text);
}

.form-section {
    background: white;
    padding: 3rem;
    border-radius: 1rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    max-width: 600px;
    margin: 0 auto;
}

.illustration {
    background: #E0E7FF;
    aspect-ratio: 4;
    border-radius: 1rem;
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-weight: bold;
    font-size: 1.2rem;
    background-image: url('/banner.webp');
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}

/* --- Legal Page Styles --- */
.legal-card {
    background: white;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
.legal-card h2 { margin-top: 1.5rem; color: #1F2937; }

/* --- API Docs Styles --- */
.api-section {
    background: white;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
}

.api-section h2 {
    font-size: 1.5rem;
    color: var(--text);
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--bg);
    padding-bottom: 0.5rem;
}

.api-section h3 {
    font-size: 1.1rem;
    color: var(--text);
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

/* Mobile Menu Overlay Default (Hidden on Desktop) */
.mobile-menu-overlay {
    display: none;
}

code {
    background: #F1F5F9;
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.9em;
    color: #E11D48;
}

pre {
    border-radius: 0.5rem;
    overflow: hidden;
    margin: 1rem 0;
}

.endpoint-box {
    background: #1E293B;
    color: #E2E8F0;
    padding: 1rem;
    border-radius: 0.5rem;
    font-family: monospace;
    display: flex;
    align-items: center;
    gap: 1rem;
    overflow-x: auto;
}
.method {
    background: #10B981;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-weight: bold;
    font-size: 0.8rem;
}

/* Mobile Styles */
@media (max-width: 600px) {
    body.app-mode {
        height: 100dvh; /* Fix for iOS address bar */
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: flex !important;
        align-items: center;
        gap: 15px;
    }

    .app-container {
        margin: 0;
        border-radius: 0;
        height: calc(100dvh - 60px); /* Adjust for header height */
        box-shadow: none;
    }

    header {
        padding: 10px 15px;
        padding-top: calc(10px + env(safe-area-inset-top)); /* Add safe area for iOS notch */
        height: auto;
        min-height: 60px;
    }

    .logo {
        font-size: 1.2rem;
    }

    /* Mobile Header Buttons */
    .menu-btn-mobile, .btn-save-mobile {
        background: none;
        border: none;
        cursor: pointer;
        padding: 5px;
        color: var(--text);
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .btn-save-mobile {
        font-size: 1.5rem;
    }

    .save-text {
        font-size: 1rem;
        font-weight: 700;
        margin-left: 8px;
        display: inline-block;
    }

    /* Controls Panel */
    .controls-panel {
        border-radius: 20px 20px 0 0;
        grid-template-columns: 80px 1fr; /* Smaller tabs column */
    }

    .category-tabs {
        padding: 10px 5px 80px 5px;
    }

    .tab-btn {
        font-size: 0.7rem;
        padding: 8px 2px;
        word-break: break-all; /* Allow breaking anywhere */
        overflow-wrap: anywhere;
        hyphens: auto;
    }

    .options-viewport {
        padding: 15px;
    }

    .options-grid {
        grid-template-columns: repeat(3, 1fr); /* 3 icons per row */
        gap: 8px;
        padding-bottom: 80px; /* Extra bottom padding for scrolling */
    }

    .options-grid.color-grid {
        row-gap: 24px; /* Double vertical spacing for colors on mobile */
    }

    .game-actions {
        display: none; /* Hide bottom actions on mobile */
    }
    
    /* Mobile Menu Overlay */
    .mobile-menu-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 1000;
        display: none;
        justify-content: flex-end;
    }

    .mobile-menu-overlay.active {
        display: flex;
    }

    .mobile-menu-content {
        background: white;
        width: 80%;
        max-width: 300px;
        height: 100%;
        padding: 20px;
        box-shadow: -5px 0 15px rgba(0,0,0,0.1);
        display: flex;
        flex-direction: column;
        gap: 20px;
        animation: slideInRight 0.3s ease-out;
    }

    @keyframes slideInRight {
        from { transform: translateX(100%); }
        to { transform: translateX(0); }
    }

    .mobile-menu-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 10px;
        border-bottom: 1px solid #eee;
        padding-bottom: 10px;
    }

    .mobile-menu-header h2 {
        margin: 0;
        font-size: 1.5rem;
    }

    .close-btn {
        background: none;
        border: none;
        font-size: 1.5rem;
        cursor: pointer;
        color: var(--text-light);
    }

    .mobile-user-info {
        display: flex;
        flex-direction: column;
        gap: 5px;
    }

    .mobile-user-info .label, .mobile-lang-selector .label {
        font-size: 0.8rem;
        color: var(--text-light);
        font-weight: 700;
    }

    .mobile-user-info .value {
        font-weight: 600;
        word-break: break-all;
    }

    .mobile-lang-selector {
        display: flex;
        flex-direction: column;
        gap: 5px;
    }

    .lang-select {
        padding: 10px;
        border-radius: 8px;
        border: 1px solid #ddd;
        font-size: 1rem;
        background: white;
    }

    .btn-logout-mobile {
        margin-top: auto;
        text-align: center;
        background: var(--accent);
        color: white;
        padding: 12px;
        border-radius: 8px;
        text-decoration: none;
        font-weight: 700;
    }
}
