/**
 * Signal Switch
 * =====================================
 * Mobile-First, Fully Responsive
 */

/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
    --bg-primary: #0a0f0a;
    --bg-secondary: #1a1f1a;
    --bg-panel: rgba(15, 20, 15, 0.95);

    --color-gold: #ffd700;
    --color-gold-dark: #b8860b;
    --color-gold-glow: rgba(255, 215, 0, 0.3);

    --color-success: #4ade80;
    --color-danger: #f87171;

    --text-light: #f5f0e6;
    --text-muted: #a89f8c;

    --border-gold: 2px solid var(--color-gold);

    --font-display: 'Cinzel Decorative', serif;
    --font-body: 'Cinzel', serif;

    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px var(--color-gold-glow);
}

.light-theme {
    --bg-primary: #f5f0e6;
    --bg-secondary: #e8e0d0;
    --bg-panel: rgba(255, 250, 240, 0.95);

    --color-gold: #8b4513;
    --color-gold-dark: #5d3a1a;
    --color-gold-glow: rgba(139, 69, 19, 0.2);

    --text-light: #2d2a26;
    --text-muted: #5d5a56;
}

/* ============================================
   RESET & BASE
   ============================================ */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-body);
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-light);
    line-height: 1.5;
}

h1,
h2,
h3 {
    font-family: var(--font-display);
    text-transform: uppercase;
    letter-spacing: 3px;
    color: var(--color-gold);
}

/* ============================================
   SCREEN SYSTEM - FOOLPROOF CENTERING
   ============================================ */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    /* JS will toggle this */
    justify-content: center;
    align-items: center;
    z-index: 100;
}

/* Force flex and centering when active */
.screen.active {
    display: flex !important;
}

/* ============================================
   LOADING SCREEN
   ============================================ */
#screen-loading {
    background: #000;
    z-index: 9999;
}

.loading-content {
    text-align: center;
    width: 300px;
}

.loading-title {
    font-family: var(--font-display);
    font-size: 2.5rem;
    color: var(--color-gold);
    text-shadow: 0 0 20px var(--color-gold-glow);
    margin-bottom: 30px;
}

.loading-bar-container {
    height: 8px;
    background: #222;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--color-gold-dark);
}

.loading-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--color-gold-dark), var(--color-gold));
    transition: width 0.3s ease;
}

/* ============================================
   MAIN MENU SCREEN
   ============================================ */
#screen-menu {
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 20px;
    gap: 30px;
}

.game-logo {
    text-align: center;
}

.game-logo h1 {
    font-size: clamp(2rem, 8vw, 4rem);
    line-height: 1.1;
    text-shadow: 0 4px 0 #000, 0 0 40px var(--color-gold-glow);
    margin-bottom: 10px;
}

.tagline {
    font-size: clamp(0.8rem, 2vw, 1.1rem);
    color: var(--text-muted);
    border-top: 1px solid var(--color-gold);
    border-bottom: 1px solid var(--color-gold);
    padding: 8px 20px;
    display: inline-block;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 350px;
}

.menu-small-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.stats-panel {
    display: flex;
    justify-content: center;
    gap: 40px;
    background: var(--bg-panel);
    border: var(--border-gold);
    border-radius: 12px;
    padding: 15px 30px;
    box-shadow: var(--shadow-soft);
}

.stat-item {
    text-align: center;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--color-gold);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    font-family: var(--font-display);
    text-transform: uppercase;
    letter-spacing: 2px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(180deg, #ffd700 0%, #b8860b 100%);
    color: #1a0f00;
    font-weight: 900;
    padding: 18px 40px;
    border-radius: 10px;
    border: 2px solid #ffe066;
    box-shadow: 0 6px 0 #8b5a00, 0 8px 20px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 #8b5a00, 0 12px 30px rgba(0, 0, 0, 0.5);
    filter: brightness(1.1);
}

.btn-primary:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #8b5a00;
}

.btn-large {
    width: 100%;
}

.btn-title {
    display: block;
    font-size: 1.3rem;
}

.btn-subtitle {
    display: block;
    font-size: 0.7rem;
    font-family: var(--font-body);
    text-transform: none;
    opacity: 0.8;
    margin-top: 2px;
}

.btn-outline,
.btn-small {
    background: transparent;
    color: var(--text-muted);
    padding: 12px 25px;
    border-radius: 8px;
    border: 2px solid var(--text-muted);
    font-size: 0.9rem;
    font-weight: bold;
}

.btn-outline:hover,
.btn-small:hover {
    color: var(--color-gold);
    border-color: var(--color-gold);
    background: rgba(255, 215, 0, 0.1);
    box-shadow: 0 0 20px var(--color-gold-glow);
}

.btn-back {
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-light);
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid var(--text-muted);
    font-size: 0.8rem;
}

/* ============================================
   LEVEL SELECT SCREEN
   ============================================ */
#screen-level-select {
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.level-select-container {
    background: var(--bg-panel);
    border: 3px solid var(--color-gold);
    border-radius: 20px;
    padding: clamp(15px, 4vw, 30px);
    width: 95%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-glow), var(--shadow-soft);
    margin: auto;
    /* Secondary centering safeguard */
}

.level-select-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 12px;
    overflow-y: auto;
    padding: 10px 5px;
}

.level-button {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.03);
    border: 2px solid var(--text-muted);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-muted);
}

.level-button:hover:not(.locked) {
    transform: scale(1.08);
    border-color: var(--color-gold);
    background: var(--color-gold);
    color: #000;
}

/* ============================================
   GAME SCREEN
   ============================================ */
#screen-game {
    background: var(--bg-primary);
}

.game-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

.game-hud {
    background: var(--bg-panel);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--color-gold);
    flex-shrink: 0;
    z-index: 10;
}

.canvas-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

#game-canvas {
    max-width: 100%;
    max-height: 100%;
    border: 4px solid var(--color-gold-dark);
    border-radius: 8px;
    box-shadow: var(--shadow-soft);
    background: #000;
}

.game-controls {
    background: var(--bg-panel);
    padding: 15px;
    border-top: 2px solid var(--color-gold);
    text-align: center;
    flex-shrink: 0;
}

/* ============================================
   OVERLAYS
   ============================================ */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.overlay.active {
    display: flex !important;
}

.overlay-content {
    background: var(--bg-panel);
    border: 3px solid var(--color-gold);
    border-radius: 20px;
    padding: 30px;
    width: 90%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    text-align: center;
    box-shadow: var(--shadow-glow), var(--shadow-soft);
}

.btn-toggle {
    display: block;
    width: 100%;
    padding: 14px;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid var(--text-muted);
    border-radius: 8px;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-toggle.active {
    border-color: var(--color-success);
    background: rgba(74, 222, 128, 0.15);
    color: var(--color-success);
}

/* Win/Lose Specifics */
.stars-display {
    font-size: 3rem;
    color: var(--color-gold);
    letter-spacing: 12px;
    margin: 20px 0;
}

.win-stats {
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 25px;
    width: 100%;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
}

.overlay-btns-force {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 15px !important;
    width: 100% !important;
    margin-top: 25px !important;
    padding-bottom: 10px !important;
}

.overlay-btns-force .btn {
    width: 100% !important;
    max-width: 260px !important;
    margin: 0 auto !important;
    display: block !important;
    position: relative !important;
    transform: none !important;
    /* Disable any floating/absolute positioning */
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (min-width: 1024px) {
    .menu-container {
        flex-direction: row;
        gap: 60px;
    }

    .game-logo {
        flex: 1;
        border-right: 2px solid var(--color-gold-dark);
        padding-right: 60px;
    }

    .game-logo h1 {
        font-size: 5rem;
    }

    .menu-buttons {
        flex: 0 0 400px;
    }

    .game-container {
        flex-direction: row;
    }

    .game-hud {
        flex-direction: column;
        width: 220px;
        height: 100%;
        border-bottom: none;
        border-right: 2px solid var(--color-gold);
        padding: 30px 15px;
        gap: 20px;
    }

    .game-controls {
        width: 200px;
        height: 100%;
        border-top: none;
        border-left: 2px solid var(--color-gold);
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 20px;
    }

    .game-controls .btn-primary {
        width: 100%;
        min-width: unset;
    }
}

.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-panel);
    color: var(--text-light);
    padding: 15px 30px;
    border-radius: 10px;
    border: 2px solid var(--color-gold);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 9999;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================
   AUDIO CONTROLS (QUICK ACCESS)
   ============================================ */
.audio-controls-top {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 15px;
    z-index: 200;
}

.btn-icon {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--color-gold);
    color: var(--color-gold);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.btn-icon:hover {
    background: var(--color-gold);
    color: #000;
    transform: scale(1.1);
    box-shadow: 0 0 15px var(--color-gold-glow);
}

.btn-icon.off {
    opacity: 0.5;
    border-color: var(--text-muted);
    color: var(--text-muted);
    filter: grayscale(100%);
}

/* ============================================
   Popup Close Button (Top Left)
   ============================================ */
.overlay-content {
    position: relative;
    /* Ensure absolute positioning works */
}

.btn-close-corner {
    position: absolute;
    top: 15px;
    left: 15px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 5px;
    z-index: 10;
}

.btn-close-corner:hover {
    color: var(--color-danger);
    transform: scale(1.2);
    text-shadow: 0 0 10px rgba(248, 113, 113, 0.5);
}