:root {
    --frame: #f4c95d;
    --page-bg: #0c0a10;
    
    /* Frontend Design Tokens */
    --brand-primary: #FF9933; /* Saffron/Chai */
    --brand-hover: #E68A2E;
    --brand-accent: #f4c95d;
    
    --bg-surface: rgba(12, 10, 16, 0.45);
    --bg-card: rgba(255, 255, 255, 0.04);
    --border-card: rgba(255, 255, 255, 0.1);
    
    --text-primary: #FFFFFF;
    --text-secondary: #E0E7FF;
    --text-muted: #94A3B8;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

body {
    margin: 0;
    padding: 0;
    color: var(--text-primary);
    background-color: var(--page-bg);
    font-family: 'Inter', sans-serif;
}

/* Layout Containers */
#app {
    width: 100%;
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at center, #1a1424 0%, var(--page-bg) 62%);
}

#game-container {
    position: relative;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    width: min(100vw - 16px, 1280px);
    height: min(100vh - 16px, 880px);
    max-width: 100%;
    max-height: 100%;
    padding: 10px;
    border-radius: 8px;
    background: linear-gradient(145deg, #2a2438, #0f0c14);
    box-shadow:
        0 0 0 3px var(--frame),
        0 18px 48px rgba(0, 0, 0, 0.65),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

#game-canvas-host {
    position: relative;
    flex: 1 1 0; /* Changed to flex-basis 0 to ensure it grows correctly without initial size bias */
    min-height: 0; /* Important for flex-shrink/grow in some browsers */
    width: 100%;
    overflow: hidden;
    border-radius: 4px;
    background: #0a080c;
}

#game-container canvas {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 4px;
    vertical-align: top;
    image-rendering: auto;
}

/* Menu Overlay System - Now lives inside game-canvas-host */
#menu-overlay {
    position: absolute;
    inset: 0; /* Fill the host exactly */
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, transparent 0%, rgba(12, 10, 16, 0.45) 100%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease-out;
}

#menu-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.menu-card {
    width: min(94%, 560px);
    background: var(--bg-card);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border-card);
    border-radius: 24px;
    padding: 32px;
    box-shadow: var(--shadow-lg), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    text-align: center;
    transform: translateY(20px);
    transition: transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

#menu-overlay.active .menu-card {
    transform: translateY(0);
}

.menu-title {
    font-family: 'Clash Display', sans-serif;
    font-size: 56px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--brand-accent);
    margin: 0 0 8px 0;
    text-transform: uppercase;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.menu-subtitle {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 40px;
}

.menu-save-info {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 32px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.account-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.account-chip {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #2b1800;
    background: linear-gradient(120deg, #ffc065, #ff9b2f);
    font-weight: 700;
}

.auth-modal {
    position: absolute;
    inset: 0;
    z-index: 110;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.auth-modal.open {
    opacity: 1;
    pointer-events: auto;
}

.auth-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(6, 5, 8, 0.72);
    backdrop-filter: blur(4px);
}

.auth-modal-card {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(92%, 460px);
    border-radius: 18px;
    padding: 18px;
    text-align: left;
    background:
        radial-gradient(circle at top right, rgba(255, 153, 51, 0.24), transparent 55%),
        linear-gradient(150deg, rgba(34, 28, 42, 0.96), rgba(9, 8, 12, 0.94));
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 24px 56px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.11);
}

.spectate-modal-card {
    width: min(94%, 720px);
}

.auth-modal-title {
    margin: 6px 0 8px;
    font-family: 'Clash Display', sans-serif;
    font-size: 28px;
    letter-spacing: 0.01em;
    color: #ffcf85;
}

.auth-modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.26);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.spectate-columns {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 14px;
    margin-top: 10px;
}

.spectate-player-list,
.spectate-top-list {
    display: grid;
    gap: 8px;
    max-height: 220px;
    overflow: auto;
    padding-right: 2px;
}

.spectate-player {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
    text-align: left;
    font: inherit;
}

.spectate-player.active {
    border-color: rgba(255, 192, 101, 0.7);
    background: linear-gradient(120deg, rgba(255, 196, 101, 0.2), rgba(255, 155, 47, 0.1));
}

.spectate-focus {
    margin-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding-top: 12px;
}

.spectate-focus-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.spectate-focus-grid div {
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.04);
}

.spectate-focus-grid span {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
}

.spectate-focus-grid strong {
    display: block;
    margin-top: 3px;
    color: var(--text-primary);
}

.leaderboard-panel {
    text-align: left;
    background: linear-gradient(160deg, rgba(22, 18, 28, 0.75), rgba(12, 11, 17, 0.85));
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px;
    padding: 16px;
    margin-bottom: 24px;
}

.leaderboard-heading {
    margin-bottom: 10px;
}

.leaderboard-list {
    display: grid;
    gap: 8px;
}

.leaderboard-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.leaderboard-row.is-top {
    background: linear-gradient(120deg, rgba(255, 196, 101, 0.22), rgba(255, 155, 47, 0.14));
    border: 1px solid rgba(255, 192, 101, 0.4);
}

.leaderboard-meta {
    display: flex;
    gap: 10px;
    align-items: center;
    min-width: 0;
}

.leaderboard-rank {
    color: var(--brand-accent);
    font-weight: 700;
    font-size: 14px;
}

.leaderboard-name {
    color: var(--text-secondary);
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-score {
    color: var(--text-primary);
    font-weight: 700;
    font-size: 14px;
}

.leaderboard-empty {
    color: var(--text-muted);
    font-size: 13px;
}

.account-heading {
    margin-bottom: 10px;
}

.account-status {
    font-size: 15px;
    color: var(--text-secondary);
    margin: 8px 0 6px;
}

.account-message {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 10px 0 0;
}

.auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 12px 0 12px;
}

.auth-tab {
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-secondary);
    border-radius: 11px;
    padding: 10px 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.18s ease-out;
}

.auth-tab.active {
    color: #201102;
    border-color: rgba(255, 184, 92, 0.72);
    background: linear-gradient(110deg, #ffd08a, #ff9f39);
}

.auth-form {
    display: grid;
    gap: 8px;
}

.auth-form-elevated {
    background: rgba(8, 7, 12, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.11);
    border-radius: 14px;
    padding: 12px;
}

.btn-auth {
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 14px;
    box-shadow: 0 5px 0 #b36b24;
}

.auth-form input {
    appearance: none;
    width: 100%;
    box-sizing: border-box;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(10, 8, 12, 0.8);
    color: var(--text-primary);
    padding: 12px 14px;
    font: inherit;
}

.auth-form input::placeholder {
    color: rgba(224, 231, 255, 0.5);
}

.auth-form input:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(244, 201, 93, 0.18);
}

.save-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.save-stats {
    font-size: 18px;
    font-weight: 500;
    color: var(--text-secondary);
}

.menu-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-primary {
    background: var(--brand-primary);
    color: #000;
    font-family: 'Clash Display', sans-serif;
    font-weight: 600;
    font-size: 18px;
    padding: 16px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease-out;
    box-shadow: 0 4px 0px #b36b24;
}

.btn-primary:hover {
    background: var(--brand-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 0px #b36b24;
}

.btn-primary:active {
    transform: translateY(2px);
    box-shadow: 0 0px 0px #b36b24;
}

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    font-size: 15px;
    padding: 14px;
    border-radius: 12px;
    border: 1px solid var(--border-card);
    cursor: pointer;
    transition: all 0.2s ease-out;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.btn-solid {
    background: rgba(255, 255, 255, 0.08);
}

.btn-solid:hover {
    background: rgba(255, 255, 255, 0.14);
}

@media (max-width: 700px) {
    .menu-card {
        width: calc(100% - 20px);
        padding: 24px 18px;
    }

    .menu-title {
        font-size: 46px;
    }

    .save-stats {
        font-size: 16px;
    }

    .auth-modal-card {
        width: calc(100% - 20px);
        padding: 16px;
    }

    .spectate-columns {
        grid-template-columns: 1fr;
    }

    .spectate-focus-grid {
        grid-template-columns: 1fr;
    }
}

.menu-footer {
    margin-top: 32px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.6;
}
