/* ============================================
   CIRCUIT PUZZLE - Stylesheet
   ============================================ */

/* ============================================
   IMPORTS & FONTS
   ============================================ */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@700&family=Orbitron:wght@400;700&family=Quicksand:wght@300;500&display=swap');

/* ============================================
   CSS VARIABLES (Design Tokens)
   ============================================ */
:root {
    /* Colors */
    --color-bg-primary: #050505;
    --color-bg-overlay: rgba(0, 0, 0, 0.7);
    --color-text-primary: rgba(255, 255, 255, 0.8);
    --color-text-secondary: rgba(255, 255, 255, 0.6);
    --color-text-tertiary: rgba(255, 255, 255, 0.5);
    --color-accent-cyan: #00f2ff;
    --color-accent-purple: #bd00ff;
    --color-accent-glow: rgba(0, 242, 255, 0.4);
    --color-button-power: #00f2ff;
    
    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;
    
    /* Typography */
    --font-primary: 'Quicksand', sans-serif;
    --font-display: 'Orbitron', sans-serif;
    --font-logo: 'Montserrat', sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.2rem;
    --font-size-xl: 1.5rem;
    --font-size-2xl: 2rem;
    --font-size-3xl: 3rem;
    --font-size-4xl: 4rem;
    --font-size-5xl: 5rem;
    
    /* Effects */
    --blur-backdrop: blur(5px);
    --blur-overlay: blur(4px);
    --shadow-glow: 0 0 15px rgba(0, 242, 255, 0.4);
    --shadow-canvas: 0 0 50px rgba(0, 255, 255, 0.05);
    --shadow-text: 0 0 10px rgba(255, 255, 255, 0.3);
    --shadow-title: 0 0 20px #00f2ff;
    /* Overlay card shell */
    --color-bg-card: #0A0A14;
    --overlay-border-color: rgba(0, 242, 255, 0.4);  /* accent cyan @ 40% */
    --overlay-shadow-color: rgba(0, 242, 255, 0.2); /* accent cyan @ 20% */

    /* Dynamic theme tokens */
    --color-level-text: var(--color-accent-cyan);
    
    /* Transitions */
    --transition-fast: 0.2s;
    --transition-base: 0.3s;
    --transition-slow: 0.5s;
    
    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 30px;
    
    /* Z-index Layers */
    --z-base: 1;
    --z-ui: 10;
    --z-overlay: 20;
}

/* ============================================
   RESET & BASE STYLES
   ============================================ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: var(--color-bg-primary);
    background-image: url('../img/bg.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    overflow: hidden;
    touch-action: none;
    font-family: var(--font-primary);
    color: var(--color-text-primary);
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
}

/* ============================================
   GAME CONTAINER
   ============================================ */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: var(--spacing-sm);
    overflow: hidden;
    min-height: 100vh;
    min-width: 100vw;
}

/* ============================================
   CANVAS
   ============================================ */
canvas {
    box-shadow: 
        0 0 60px rgba(0, 242, 255, 0.15),
        0 0 120px rgba(0, 242, 255, 0.08),
        0 8px 40px rgba(0, 0, 0, 0.5),
        0 2px 8px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        inset 0 -1px 0 rgba(0, 0, 0, 0.5);
    border-radius: var(--radius-md);
    transition: transform var(--transition-base) ease, box-shadow var(--transition-base) ease;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    background: transparent;
    border: none;
    position: relative;
    backdrop-filter: blur(10px);
    overflow: hidden;
    object-fit: contain;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    /* Optimize rendering performance */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    will-change: transform;
}

/* ============================================
   UI LAYER
   ============================================ */
.ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: var(--spacing-xs);
    z-index: var(--z-ui);
    pointer-events: none;
}

.ui-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0;
}

.ui-header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    flex-shrink: 0;
}

.ui-header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    flex-shrink: 0;
}

.level-display {
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--color-level-text);
    font-family: var(--font-display);
    transition: all var(--transition-base) ease;
    pointer-events: auto;
    text-shadow: 0 0 8px rgba(0, 242, 255, 0.6), 0 0 15px rgba(0, 242, 255, 0.3);
    letter-spacing: 1px;
    height: 44px;
    display: flex;
    align-items: center;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    backdrop-filter: none;
    box-sizing: border-box;
}

.moves-needed-display {
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--color-accent-cyan);
    font-family: var(--font-display);
    transition: all var(--transition-base) ease;
    pointer-events: auto;
    text-shadow: 0 0 8px rgba(0, 242, 255, 0.6), 0 0 15px rgba(0, 242, 255, 0.3);
    letter-spacing: 1px;
    height: 44px;
    display: flex;
    align-items: center;
    padding: 0 var(--spacing-sm);
    margin: 0 0 0 var(--spacing-xs);
    background: rgba(0, 242, 255, 0.05);
    border: 2px solid rgba(0, 242, 255, 0.2);
    border-radius: var(--radius-sm);
    backdrop-filter: var(--blur-backdrop);
    box-sizing: border-box;
    min-width: 90px;
    justify-content: center;
}


.btn.btn-icon {
    width: 44px;
    height: 44px;
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm) !important;
    background: var(--color-button-power);
    backdrop-filter: var(--blur-backdrop);
    border: 2px solid var(--color-button-power);
    color: rgba(255, 255, 255, 1);
    pointer-events: auto;
    min-width: 44px;
    min-height: 44px;
    text-transform: none;
    font-size: 0;
    transition: all var(--transition-base) ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.btn-icon svg {
    width: 24px;
    height: 24px;
    stroke: rgba(255, 255, 255, 1);
    stroke-width: 2.5;
    fill: none;
    transition: all var(--transition-base) ease;
}

.btn-icon:hover {
    background: var(--color-button-power);
    border-color: var(--color-button-power);
    filter: brightness(1.2);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3), 0 0 15px var(--color-button-power);
    transform: translateY(-2px) scale(1.05);
}

.btn-icon.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Hint UI removed */

.btn-icon:hover svg {
    transform: scale(1.1);
    stroke: rgba(255, 255, 255, 1);
}

.btn-icon:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.btn-icon:focus-visible {
    outline: 2px solid var(--color-button-power);
    outline-offset: 3px;
    box-shadow: 0 0 8px var(--color-button-power);
}

/* ============================================
   TYPOGRAPHY
   ============================================ */
h1 {
    font-family: var(--font-display);
    font-size: var(--font-size-xl);
    font-weight: 700;
    letter-spacing: 1px;
    background: linear-gradient(90deg, var(--color-accent-cyan), var(--color-accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: var(--spacing-xs);
    line-height: 1.2;
}


/* ============================================
   BUTTONS
   ============================================ */
.btn {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: var(--blur-backdrop);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 10px 20px;
    border-radius: var(--radius-lg);
    color: white;
    cursor: pointer;
    transition: all var(--transition-fast) ease;
    font-family: var(--font-display);
    text-transform: uppercase;
    font-size: var(--font-size-sm);
    font-weight: 400;
    pointer-events: auto;
    outline: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.btn:active {
    transform: translateY(0);
}

.btn:focus-visible {
    outline: 2px solid var(--color-accent-cyan);
    outline-offset: 2px;
}

.btn-large {
    /* Common large pill button (_LargeButton) */
    width: 100%;
    max-width: 360px;
    font-size: clamp(0.75rem, 1.1vw + 0.65rem, 1.125rem); /* ~12–18px responsive */
    padding: 14px 24px;
    font-weight: 700;
    letter-spacing: 0.1em; /* ~1.5–2.5px */
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    border: 1.5px solid rgba(255, 255, 255, 0.24);
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center; /* center button name */
    text-align: center;
}

.btn-large:hover {
    background: rgba(255, 255, 255, 0.16);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.55);
    transform: translateY(-2px);
}

.logo-container {
    text-align: center;
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
    width: 100%;
    --logo-size: 48px;
    --logo-width: 220px;
}

.logo-image {
    width: min(var(--logo-width), 60vw);
    height: auto;
    display: block;
    margin: 0 auto;
    user-select: none;
    -webkit-user-drag: none;
}

.logo-subtitle {
    /* Subtitle spec */
    font-size: calc(var(--logo-size) * 0.6);
    letter-spacing: clamp(1.5px, 0.45vw, 2.5px);
    color: rgba(255, 255, 255, 0.6);
    font-family: var(--font-logo);
    font-weight: 400;
    margin-top: var(--spacing-xs);
}

/* ============================================
   SCREEN MODES (HOME vs GAME)
   ============================================ */
#game-container[data-screen="home"] .ui-layer,
#game-container[data-screen="home"] canvas,
#game-container[data-screen="home"] #win-overlay,
#game-container[data-screen="home"] #game-over-overlay,
#game-container[data-screen="home"] #solution-overlay {
    display: none !important;
}

/* ============================================
   LEVEL SELECTION OVERLAY
   ============================================ */
#level-selection-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Let bg.png show through */
    background: transparent;
    backdrop-filter: none;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    flex-direction: column;
    z-index: calc(var(--z-overlay) + 3);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--transition-slow) ease, visibility var(--transition-slow) ease;
}

#level-selection-overlay[aria-hidden="false"] {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.level-selection-modal {
    /* Full-screen home screen (no popup card) */
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    padding: var(--spacing-lg) var(--spacing-md);
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    -webkit-overflow-scrolling: touch;
    /* Use the page bg.png; only a light dark wash here */
    background: rgba(0, 0, 0, 0.25);
    border: none;
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
    display: flex;
    flex-direction: column;
}

.level-selection-header {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: var(--spacing-sm);
    padding-bottom: 0;
    border-bottom: none;
}

.level-selection-content {
    width: 100%;
    flex: 1;
}

.level-path-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md) 0;
}

.level-path-row {
    display: flex;
    align-items: center;
    justify-content: center;
    column-gap: var(--spacing-sm);
    row-gap: var(--spacing-xs);
    flex-wrap: wrap;
}

.level-connector,
.level-connector-vertical {
    display: none !important; /* remove lines between cards */
}

.level-node {
    /* Level card spec: 80x80 rounded square */
    width: 80px;
    height: 80px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all var(--transition-base) ease;
    border: 2px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: var(--blur-backdrop);
    overflow: hidden;
    transform: translateZ(0);
}

.level-node.locked {
    /* Locked gradient + animated border/glow */
    background: linear-gradient(135deg,
        rgba(26, 26, 46, 1.0) 0%,
        rgba(22, 33, 62, 1) 50%,
        rgba(15, 20, 25, 1.0) 100%);
    border: 2px solid rgba(74, 85, 104, 0.5);
    box-shadow:
        0 0 24px 2px rgba(45, 55, 72, 0.16),
        0 10px 24px -4px rgba(0, 0, 0, 0.7);
    animation: levelPulseLocked 2.8s ease-in-out infinite;
    cursor: not-allowed;
}

.level-node.unlocked {
    /* Neutral unlocked (no special spec given) */
    background: rgba(0, 0, 0, 0.18);
    border: 2px solid rgba(0, 242, 255, 0.25);
    box-shadow: 0 0 10px rgba(0, 242, 255, 0.12);
    cursor: pointer;
}

.level-node.unlocked:hover {
    transform: scale(1.1);
    border-color: var(--color-accent-cyan);
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.5);
    background: rgba(0, 242, 255, 0.1);
}

.level-node.completed {
    background: linear-gradient(135deg,
        rgba(8, 51, 68, 0.85) 0%,
        rgba(6, 78, 59, 0.90) 50%,
        rgba(8, 51, 68, 0.85) 100%);
    border: 2.5px solid rgba(16, 185, 129, 0.6);
    box-shadow: 0 0 18px 1px rgba(16, 185, 129, 0.2);
}

.level-node.current {
    /* Current spec (NEON_CYAN + purple) */
    --neon-cyan: #22D3EE;
    background: linear-gradient(135deg,
        rgba(34, 211, 238, 0.38) 0%,
        rgba(8, 51, 68, 0.95) 50%,
        rgba(189, 0, 255, 0.25) 100%);
    border: 3px solid rgba(34, 211, 238, 0.95);
    transform: scale(1.08);
    box-shadow:
        0 0 36px 3px rgba(34, 211, 238, 0.65),
        0 0 24px 2px rgba(189, 0, 255, 0.26);
    animation: levelPulseCurrent 2.6s ease-in-out infinite;
}

@keyframes levelPulseLocked {
    0%, 100% {
        border-color: rgba(74, 85, 104, 0.4);
        box-shadow:
            0 0 20px 2px rgba(45, 55, 72, 0.12),
            0 10px 24px -4px rgba(0, 0, 0, 0.7);
    }
    50% {
        border-color: rgba(74, 85, 104, 0.6);
        box-shadow:
            0 0 28px 2px rgba(45, 55, 72, 0.20),
            0 10px 24px -4px rgba(0, 0, 0, 0.7);
    }
}

@keyframes levelPulseCurrent {
    0%, 100% {
        transform: scale(1.08);
        border-color: rgba(34, 211, 238, 0.9);
        box-shadow:
            0 0 28px 3px rgba(34, 211, 238, 0.5),
            0 0 20px 2px rgba(189, 0, 255, 0.20);
        background: linear-gradient(135deg,
            rgba(34, 211, 238, 0.30) 0%,
            rgba(8, 51, 68, 0.95) 50%,
            rgba(189, 0, 255, 0.20) 100%);
    }
    50% {
        transform: scale(1.08);
        border-color: rgba(34, 211, 238, 1.0);
        box-shadow:
            0 0 40px 3px rgba(34, 211, 238, 0.8),
            0 0 28px 2px rgba(189, 0, 255, 0.32);
        background: linear-gradient(135deg,
            rgba(34, 211, 238, 0.45) 0%,
            rgba(8, 51, 68, 0.95) 50%,
            rgba(189, 0, 255, 0.30) 100%);
    }
}

.level-number {
    font-family: var(--font-display);
    font-size: var(--font-size-base);
    font-weight: 700;
    color: var(--color-text-primary);
    line-height: 1;
    margin-bottom: 2px;
}

.level-node.completed .level-number {
    color: rgba(16, 185, 129, 0.9);
    text-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.level-node.current .level-number {
    color: rgba(34, 211, 238, 0.95);
    text-shadow: 0 0 10px rgba(34, 211, 238, 0.6);
}

.level-status {
    font-size: var(--font-size-sm);
    line-height: 1;
    color: var(--color-accent-cyan);
}

.level-node.locked .level-status {
    color: rgba(160, 174, 192, 0.9);
}

.level-node.completed .level-status {
    color: rgba(16, 185, 129, 0.9);
    font-weight: 700;
}

.level-icon {
    width: 26px;
    height: 26px;
    fill: currentColor;
    filter: drop-shadow(0 0 8px rgba(74, 85, 104, 0.4));
}

.level-node.locked .level-icon {
    color: rgba(160, 174, 192, 0.9);
    filter: drop-shadow(0 0 8px rgba(74, 85, 104, 0.4));
    animation: lockedIconPulse 2.8s ease-in-out infinite;
}

@keyframes lockedIconPulse {
    0%, 100% { opacity: 0.85; }
    50% { opacity: 0.95; }
}

.level-node.completed .level-icon {
    color: rgba(16, 185, 129, 0.9);
    filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.5));
}

/* Subtle circuit-pattern overlay (locked only) */
.level-node.locked::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 22px 22px, rgba(113, 128, 150, 0.6) 0 2px, transparent 3px),
        radial-gradient(circle at 58px 58px, rgba(113, 128, 150, 0.6) 0 2px, transparent 3px);
    opacity: 0.1;
    pointer-events: none;
    mix-blend-mode: screen;
    animation: lockedPatternPulse 2.8s ease-in-out infinite;
}

@keyframes lockedPatternPulse {
    0%, 100% { opacity: 0.05; }
    50% { opacity: 0.08; }
}

.level-connector {
    width: 40px;
    height: 3px;
    background: rgba(100, 100, 110, 0.3);
    transition: all var(--transition-base) ease;
    position: relative;
}

.level-connector.active {
    background: linear-gradient(90deg, var(--color-accent-cyan), var(--color-accent-purple));
    box-shadow: 0 0 8px rgba(0, 242, 255, 0.4);
}

.level-connector::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--color-accent-cyan), var(--color-accent-purple));
    transition: width var(--transition-slow) ease;
}

.level-connector.active::before {
    width: 100%;
    animation: flow-connector 2s ease-in-out infinite;
}

@keyframes flow-connector {
    0%, 100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

.level-connector-vertical {
    width: 3px;
    height: 30px;
    background: rgba(100, 100, 110, 0.3);
    transition: all var(--transition-base) ease;
    position: relative;
    display: none; /* remove vertical lines on level screen */
}

.level-connector-vertical.active {
    background: linear-gradient(180deg, var(--color-accent-cyan), var(--color-accent-purple));
    box-shadow: 0 0 8px rgba(0, 242, 255, 0.4);
}

.level-connector-vertical::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    height: 0;
    background: linear-gradient(180deg, var(--color-accent-cyan), var(--color-accent-purple));
    transition: height var(--transition-slow) ease;
}

.level-connector-vertical.active::before {
    height: 100%;
    animation: flow-connector-vertical 2s ease-in-out infinite;
}

@keyframes flow-connector-vertical {
    0%, 100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

/* ============================================
   BOARD WRAPPER + SOLUTION OVERLAY
   ============================================ */
.board-wrapper {
    position: relative;
    display: inline-block;
}

.solution-overlay {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translate(-50%, -120%); /* sit clearly above the board */
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--transition-slow) ease, visibility var(--transition-slow) ease, transform var(--transition-slow) ease;
    z-index: calc(var(--z-overlay) + 1);
    background: transparent;
}

.solution-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.solution-overlay .btn {
    pointer-events: auto;
    z-index: calc(var(--z-overlay) + 2);
    animation: fadeIn 0.5s ease-in-out;
    margin-top: 0;
}

/* ============================================
   SHARED OVERLAY BASE (_Overlay)
   ============================================ */
.overlay-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: var(--color-bg-overlay); /* 70% black */
    backdrop-filter: var(--blur-overlay);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--spacing-md);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--transition-slow) ease, visibility var(--transition-slow) ease;
    z-index: var(--z-overlay);
}

.overlay-backdrop.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.overlay-card {
    background: var(--color-bg-card);
    border-radius: clamp(10px, 2vw, 16px);
    border: 1.5px solid var(--overlay-border-color);
    box-shadow:
        0 0 30px var(--overlay-shadow-color),
        0 18px 45px rgba(0, 0, 0, 0.85);
    width: min(90vw, 480px);
    padding: clamp(20px, 4vw, 32px);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.overlay-header-title {
    font-family: var(--font-display);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em; /* ~1.5–2.5px */
    margin-bottom: 0.5rem;
    white-space: nowrap; /* keep heading in one line */
}

.overlay-header-title.win-title {
    color: #ffffff;
    font-size: clamp(1.6rem, 3.2vw, 2.75rem); /* smaller + responsive */
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.3), var(--shadow-title);
}

.overlay-header-title.game-over-title {
    color: #ff5252; /* redAccent-like */
    font-size: clamp(1.5rem, 3vw, 2.6rem); /* smaller + responsive */
    text-shadow: 0 0 20px #ff4444, 0 0 40px rgba(255, 68, 68, 0.5);
    animation: pulse-game-over 2.2s ease-in-out infinite;
}

.overlay-header-subtitle {
    color: var(--color-text-secondary);
    font-size: clamp(0.8rem, 1.1vw + 0.65rem, 1.125rem); /* ~12–18px */
    margin-bottom: clamp(16px, 3vw, 24px);
}

/* Stars row for win overlay */
.win-stars {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: clamp(10px, 2vw, 16px);
    margin-bottom: clamp(18px, 3.5vw, 28px);
}

.win-star {
    font-size: clamp(2rem, 3.3vw, 3rem); /* ~32–48px */
    line-height: 1;
    filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.8));
}

.win-star.earned {
    color: #FFC107; /* amber */
    text-shadow:
        0 0 10px rgba(255, 193, 7, 0.8),
        0 0 20px rgba(255, 193, 7, 0.6);
}

.win-star.missing {
    color: #424242;
    text-shadow: none;
}

.overlay-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-top: clamp(8px, 2vw, 16px);
    align-items: center; /* center button(s) inside popup */
}

.overlay-actions-dual {
    flex-direction: row;
}

.overlay-actions-dual .btn-large {
    max-width: none;
}

/* Make NEXT LEVEL label smaller and on a single line */
.overlay-btn-next {
    font-size: clamp(0.7rem, 0.9vw + 0.55rem, 0.95rem);
    white-space: nowrap;
    padding-inline: 28px;
}

/* Last level: collapse to single full-width HOME button */
#win-overlay[data-last-level="true"] .overlay-actions-dual {
    flex-direction: column;
}

#win-overlay[data-last-level="true"] .overlay-btn-next {
    display: none;
}

/* Specific overlay z-index layering */
#win-overlay.overlay-backdrop {
    z-index: var(--z-overlay);
}

#game-over-overlay.overlay-backdrop {
    z-index: calc(var(--z-overlay) + 1);
}

#daily-puzzle-win-overlay.overlay-backdrop {
    z-index: calc(var(--z-overlay) + 2);
}

/* Game over pulse */
@keyframes pulse-game-over {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.9;
        transform: scale(1.05);
    }
}


/* ============================================
   ANIMATIONS
   ============================================ */
.fade-in {
    animation: fadeIn 1s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* ============================================
   DESKTOP (≥1025px) - Base Styles
   ============================================ */
@media screen and (min-width: 1025px) {
    #game-container {
        padding: var(--spacing-md);
    }
}

/* ============================================
   TABLET LANDSCAPE (769px-1024px)
   ============================================ */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    :root {
        --font-size-3xl: 2.5rem;
        --font-size-5xl: 4rem;
        --spacing-lg: 1.75rem;
    }
    
    #game-container {
        padding: var(--spacing-sm);
    }
    
    .ui-layer {
        padding: var(--spacing-xs) var(--spacing-sm);
    }
    
    .level-display,
    .moves-needed-display {
        font-size: var(--font-size-sm);
        height: 42px;
        padding: 0 var(--spacing-sm);
    }
    
    .moves-needed-display {
        min-width: 85px;
        font-size: var(--font-size-xs);
    }
    
    .btn-icon {
        width: 42px;
        height: 42px;
        min-width: 42px;
        min-height: 42px;
    }
    
    .btn-icon svg {
        width: 23px;
        height: 23px;
    }
    
    .win-title,
    .game-over-title {
        font-size: var(--font-size-4xl);
    }
    
    .btn-large {
        font-size: var(--font-size-lg);
        padding: 14px 40px;
    }
}

/* ============================================
   TABLET PORTRAIT (641px-768px)
   ============================================ */
@media screen and (min-width: 641px) and (max-width: 768px) {
    :root {
        --font-size-3xl: 2rem;
        --font-size-5xl: 3rem;
        --spacing-lg: 1.5rem;
        --spacing-md: 1.25rem;
    }
    
    #game-container {
        padding: var(--spacing-xs) var(--spacing-sm);
    }
    
    .ui-layer {
        padding: var(--spacing-xs);
    }
    
    .ui-header-left,
    .ui-header-right {
        gap: var(--spacing-xs);
    }
    
    .level-display,
    .moves-needed-display {
        font-size: var(--font-size-xs);
        height: 40px;
        padding: 0 var(--spacing-xs);
        letter-spacing: 0.5px;
    }
    
    .moves-needed-display {
        min-width: 80px;
        font-size: 0.7rem;
    }
    
    .btn-icon {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }
    
    .btn-icon svg {
        width: 22px;
        height: 22px;
    }
    
    .logo-subtitle {
        font-size: var(--font-size-xs);
    }
    
    .win-title,
    .game-over-title {
        font-size: var(--font-size-3xl);
    }
    
    .btn-large {
        font-size: var(--font-size-base);
        padding: 12px 32px;
        letter-spacing: 1.5px;
    }
}

/* ============================================
   LEVEL SELECTION RESPONSIVE
   ============================================ */
@media screen and (max-width: 768px) {
    .level-selection-modal {
        padding: var(--spacing-md);
        max-width: 95%;
    }
    
    .level-selection-title {
        font-size: var(--font-size-xl);
    }
    
    .level-node {
        width: 50px;
        height: 50px;
    }
    
    .level-number {
        font-size: var(--font-size-sm);
    }
    
    .level-status {
        font-size: var(--font-size-xs);
    }
    
    .level-connector {
        width: 30px;
    }
    
    .level-connector-vertical {
        height: 20px;
    }
}

@media screen and (max-width: 480px) {
    .level-selection-modal {
        padding: var(--spacing-sm);
        max-width: 98%;
    }
    
    .level-selection-header {
        margin-bottom: 0;
        padding-bottom: var(--spacing-sm);
    }
    
    .level-selection-title {
        font-size: var(--font-size-lg);
    }
    
    .level-node {
        width: 45px;
        height: 45px;
    }
    
    .level-number {
        font-size: var(--font-size-xs);
    }
    
    .level-status {
        font-size: 0.65rem;
    }
    
    .level-connector {
        width: 25px;
        height: 2px;
    }
    
    .level-connector-vertical {
        height: 15px;
        width: 2px;
    }
    
    .level-path-container {
        gap: var(--spacing-sm);
        padding: var(--spacing-sm) 0;
    }
    
    .level-path-row {
        gap: 4px;
    }
}

/* ============================================
   MOBILE (≤640px)
   ============================================ */
@media screen and (max-width: 640px) {
    :root {
        --font-size-3xl: 1.75rem;
        --font-size-5xl: 2.5rem;
        --spacing-lg: 1.25rem;
        --spacing-md: 1rem;
    }
    
    #game-container {
        padding: var(--spacing-xs);
    }
    
    .ui-layer {
        padding: var(--spacing-xs);
    }
    
    .ui-header-left,
    .ui-header-right {
        gap: var(--spacing-xs);
    }
    
    .level-display,
    .moves-needed-display {
        font-size: var(--font-size-xs);
        height: 38px;
        padding: 0 10px;
        letter-spacing: 0.5px;
    }
    
    .moves-needed-display {
        min-width: 75px;
        font-size: 0.65rem;
    }
    
    .btn-icon {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
    }
    
    .btn-icon svg {
        width: 21px;
        height: 21px;
    }
    
    .logo-subtitle {
        font-size: var(--font-size-xs);
        letter-spacing: 1.5px;
    }
    
    .win-title,
    .game-over-title {
        font-size: var(--font-size-2xl);
    }
    
    .btn {
        font-size: var(--font-size-xs);
        padding: 9px 18px;
    }
    
    .btn-large {
        font-size: var(--font-size-sm);
        padding: 11px 28px;
        letter-spacing: 1px;
    }

    /* Level selection: 4-column grid on mobile */
    .level-selection-content {
        display: flex;
        justify-content: center;
    }

    .level-path-container {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, auto));
        justify-content: center;
        gap: var(--spacing-sm);
        padding: var(--spacing-sm) 0;
    }

    /* Flatten row wrappers so cards flow directly in the grid */
    .level-path-row {
        display: contents;
    }

    /* Make level cards larger on mobile */
    .level-node {
        width: 75px;
        height: 75px;
        border-radius: 18px;
    }

    .level-number {
        font-size: var(--font-size-base);
    }

    .level-status {
        font-size: var(--font-size-sm);
    }

    .level-icon {
        width: 30px;
        height: 30px;
    }
    
    /* Reduce shadow complexity on mobile for better performance */
    canvas {
        box-shadow: 
            0 0 30px rgba(0, 242, 255, 0.12),
            0 4px 20px rgba(0, 0, 0, 0.4),
            0 1px 4px rgba(0, 0, 0, 0.3);
    }
}

/* ============================================
   SMALL MOBILE (≤480px)
   ============================================ */
@media screen and (max-width: 480px) {
    :root {
        --font-size-3xl: 1.5rem;
        --font-size-5xl: 2rem;
        --spacing-lg: 1rem;
        --spacing-md: 0.875rem;
        --spacing-sm: 0.75rem;
    }
    
    html {
        font-size: 15px;
    }
    
    #game-container {
        padding: var(--spacing-xs);
    }
    
    .ui-layer {
        padding: var(--spacing-xs);
    }
    
    .ui-header {
        gap: var(--spacing-xs);
    }
    
    .ui-header-left,
    .ui-header-right {
        gap: 4px;
    }
    
    .level-display,
    .moves-needed-display {
        font-size: 0.7rem;
        height: 36px;
        padding: 0 8px;
        letter-spacing: 0.3px;
    }
    
    .moves-needed-display {
        min-width: 70px;
        font-size: 0.6rem;
    }
    
    .btn-icon {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
    }
    
    .btn-icon svg {
        width: 20px;
        height: 20px;
    }
    
    .logo-container {
        padding-bottom: 0;
        margin-bottom: 0;
    }
    
    .logo-subtitle {
        font-size: 0.65rem;
        letter-spacing: 1px;
    }
    
    .win-title,
    .game-over-title {
        font-size: var(--font-size-2xl);
        letter-spacing: 0.05em;
        margin-bottom: var(--spacing-xs);
    }
    
    .btn {
        font-size: var(--font-size-xs);
        padding: 8px 16px;
        border-radius: var(--radius-sm);
    }
    
    .btn-large {
        font-size: var(--font-size-xs);
        padding: 10px 24px;
        letter-spacing: 0.5px;
    }
    
    canvas {
        border-radius: var(--radius-sm);
    }
}

/* ============================================
   LANDSCAPE MOBILE (orientation: landscape)
   ============================================ */
@media screen and (orientation: landscape) and (max-height: 640px) {
    :root {
        --spacing-lg: 1rem;
        --spacing-md: 0.75rem;
    }
    
    #game-container {
        padding: var(--spacing-xs);
        justify-content: center;
    }
    
    .ui-layer {
        padding: var(--spacing-xs) var(--spacing-sm);
    }
    
    .level-display,
    .moves-needed-display {
        height: 36px;
        font-size: var(--font-size-xs);
        padding: 0 8px;
    }
    
    .moves-needed-display {
        min-width: 70px;
        font-size: 0.65rem;
    }
    
    .btn-icon {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
    }
    
    .btn-icon svg {
        width: 20px;
        height: 20px;
    }
    
    .logo-container {
        padding-bottom: 0;
        margin-bottom: 0;
    }
    
    .logo-subtitle {
        font-size: var(--font-size-xs);
    }
    
    .win-title,
    .game-over-title {
        font-size: var(--font-size-xl);
        margin-bottom: var(--spacing-xs);
    }
    
    .btn-large {
        font-size: var(--font-size-xs);
        padding: 8px 20px;
    }
    
    /* Compress canvas padding for landscape */
    canvas {
        max-height: 85vh;
    }
}

/* Additional landscape optimization for very small heights */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .ui-layer {
        padding: 4px var(--spacing-xs);
    }
    
    .level-display,
    .moves-needed-display {
        height: 32px;
        font-size: 0.65rem;
        padding: 0 6px;
    }
    
    .moves-needed-display {
        min-width: 65px;
        font-size: 0.55rem;
    }
    
    .btn-icon {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }
    
    .btn-icon svg {
        width: 18px;
        height: 18px;
    }
    
    .logo-subtitle {
        font-size: 0.65rem;
    }
    
    .win-title,
    .game-over-title {
        font-size: var(--font-size-lg);
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}