/* ============================================
   PUZZLEFORGE — Design System
   Premium Dark Theme · Gold/Amber Accents
   ============================================ */

/* ==================== IMPORTS ==================== */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700;800&family=Outfit:wght@400;500;600;700;800;900&display=swap');

/* ==================== CSS VARIABLES ==================== */
:root {
    /* Colors */
    --bg-deep: #0a0a0f;
    --bg-surface: #12121a;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-glass: rgba(255, 179, 71, 0.06);
    --border-glass: rgba(255, 179, 71, 0.12);

    /* Gold/Amber accent palette */
    --gold-primary: #FFB347;
    --gold-bright: #FFD700;
    --gold-deep: #FF8C00;
    --gold-glow: rgba(255, 179, 71, 0.4);
    --gold-subtle: rgba(255, 179, 71, 0.15);

    /* Status colors */
    --green: #4ADE80;
    --green-glow: rgba(74, 222, 128, 0.3);
    --red: #FF4757;
    --red-glow: rgba(255, 71, 87, 0.3);
    --cyan: #22D3EE;
    --cyan-glow: rgba(34, 211, 238, 0.3);
    --purple: #A78BFA;

    /* Text */
    --text-primary: #F8F8F2;
    --text-secondary: rgba(248, 248, 242, 0.6);
    --text-muted: rgba(248, 248, 242, 0.35);

    /* Fonts */
    --font-display: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --tutorial-title: var(--gold-bright);

    /* Spacing */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    /* Transitions */
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ==================== SUNFORGE (CHEERY) THEME VARIABLES ==================== */
:root[data-theme="sunforge"] {
    --bg-deep: #FFF8EE;
    --bg-surface: #FFFAEE;
    --bg-card: rgba(0, 0, 0, 0.03);
    --bg-glass: rgba(255, 255, 255, 0.7);
    --border-glass: rgba(0, 0, 0, 0.05);

    /* Status colors */
    --green: #3DDC84;
    --green-glow: rgba(61, 220, 132, 0.3);
    --red: #FF4757;
    --red-glow: rgba(255, 71, 87, 0.3);
    --cyan: #0284C7;
    --cyan-glow: rgba(2, 132, 199, 0.3);
    --purple: #8B5CF6;

    --gold-deep: #D2691E;

    /* brownish yellow: same as How to Play in settings */
    --gold-bright: #FFB347;
    --tutorial-title: #FFB347;
    --text-primary: #3E2723;
    --text-secondary: rgba(62, 39, 35, 0.75);
    --text-muted: rgba(46, 46, 46, 0.55);
}

/* ==================== RESET & BASE ==================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: var(--font-display);
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: pan-y; /* Allow vertical scroll, let JS handle horizontal swipes */
}

body {
    position: relative;
}

/* ==================== BACKGROUND CANVAS ==================== */
#bg-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0.5;
}

/* ==================== SCREENS ==================== */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1;
    padding: calc(var(--safe-top) + 10px) 16px calc(var(--safe-bottom) + 10px);
    transition: opacity 0.3s var(--ease-out-expo);
    overflow-y: auto; /* Allow the screen container itself to overflow if its content is centered but tall */
}

.screen.game-screen {
    justify-content: flex-start; /* HUD at top, content below */
    overflow: hidden; /* Scroll handled by .game-scroll-area */
    display: none;
    flex-direction: column;
    height: 100vh; /* Force viewport height */
}

.screen.game-screen.active {
    display: flex;
}

.screen.active {
    display: flex;
}

/* ==================== GLASS PANELS ==================== */
.glass-panel {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: 20px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 24px;
    width: 100%;
    max-width: 420px;
    transition: top 0.4s var(--ease-out-expo), left 0.4s var(--ease-out-expo), transform 0.4s var(--ease-out-expo), opacity 0.4s var(--ease-out-expo);
}

/* ==================== MAIN MENU ==================== */
.menu-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 28px 20px;
    max-height: 90vh;
    overflow-y: auto;
}

.game-title {
    font-size: clamp(1.8rem, 10vw, 2.8rem);
    font-weight: 900;
    letter-spacing: 2px;
    line-height: 1.1;
    margin-bottom: 2px;
    text-align: center;
    word-wrap: normal;
}

.title-puzzle {
    color: var(--gold-bright);
    text-shadow: 0 0 30px var(--gold-glow), 0 0 60px rgba(255, 215, 0, 0.2);
}

.title-forge {
    color: var(--gold-deep);
    text-shadow: 0 0 30px rgba(255, 140, 0, 0.4);
}

.tagline {
    font-size: 0.85rem;
    color: var(--text-secondary);
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 8px;
    text-align: center;
}

/* ==================== MODE CARDS ==================== */
.mode-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
}

.mode-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 10px;
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.3s var(--ease-out-expo);
    position: relative;
    overflow: hidden;
    font-family: var(--font-display);
    color: var(--text-primary);
    text-align: center;
}

.mode-card:active {
    transform: scale(0.97);
}

.mode-card:not(.mode-locked):hover {
    border-color: var(--gold-primary);
    background: rgba(255, 179, 71, 0.08);
    box-shadow: 0 0 20px rgba(255, 179, 71, 0.1);
}

.mode-card.mode-locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.mode-card.mode-locked:active {
    transform: none;
}

.mode-icon {
    font-size: 1.5rem;
    min-width: 40px;
    text-align: center;
}

.mode-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.mode-name {
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
}

.mode-desc {
    font-size: 0.6rem;
    color: var(--text-secondary);
    line-height: 1.2;
}

.mode-status {
    font-size: 0.6rem;
    font-family: var(--font-mono);
    color: var(--gold-primary);
    text-align: center;
    width: 100%;
}

.mode-lock-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100%;
}

.lock-icon {
    font-size: 1.2rem;
}

.lock-progress {
    font-size: 0.6rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.lock-bar {
    width: 50px;
    height: 3px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    overflow: hidden;
}

.lock-bar-fill {
    height: 100%;
    background: var(--gold-primary);
    border-radius: 2px;
    transition: width 0.5s var(--ease-out-expo);
}

/* ==================== BUTTONS ==================== */
.neon-btn {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    padding: 14px 32px;
    border: 2px solid var(--gold-primary);
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(255, 179, 71, 0.15), rgba(255, 140, 0, 0.08));
    color: var(--gold-bright);
    cursor: pointer;
    transition: all 0.25s var(--ease-out-expo);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
    width: 100%;
}

.neon-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 215, 0, 0.15), transparent);
    transition: left 0.6s;
}

.neon-btn:hover::before {
    left: 100%;
}

.neon-btn:active {
    transform: scale(0.96);
    box-shadow: 0 0 25px var(--gold-glow);
}

.play-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 16px 32px;
    font-size: 1.1rem;
    animation: pulse-glow 2s ease-in-out infinite;
    flex-shrink: 0;
}

.btn-main {
    font-size: 1.1rem;
}

.btn-sub {
    font-size: 0.6rem;
    color: var(--text-secondary);
    letter-spacing: 2px;
}

@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 0 10px rgba(255, 179, 71, 0.2);
    }

    50% {
        box-shadow: 0 0 25px rgba(255, 179, 71, 0.4), 0 0 50px rgba(255, 179, 71, 0.1);
    }
}

/* ==================== MENU NAV ==================== */
.menu-nav {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 8px;
}

.nav-icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-primary);
}

.nav-icon-btn:active {
    transform: scale(0.92);
    background: rgba(255, 179, 71, 0.1);
    border-color: var(--gold-primary);
}

.menu-footer {
    font-size: 0.6rem;
    color: var(--text-muted);
    letter-spacing: 2px;
    margin-top: 4px;
}

/* ==================== GAME SCREEN ==================== */
.game-screen {
    justify-content: flex-start;
    padding-top: calc(var(--safe-top) + 8px);
    gap: 6px;
}

.game-hud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 420px;
    padding: 0 44px 0 4px;
    gap: 4px;
    /* Right padding prevents overlap with absolute pause btn */
}

.hud-left,
.hud-right {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.hud-left {
    align-items: flex-start;
}

.hud-right {
    align-items: flex-end;
}

.hud-label {
    font-size: 0.55rem;
    color: var(--text-muted);
    letter-spacing: 2px;
    text-transform: uppercase;
    font-family: var(--font-mono);
}

.hud-value {
    font-size: clamp(1rem, 5vw, 1.3rem);
    font-weight: 800;
    font-family: var(--font-mono);
    color: var(--gold-bright);
}

.level-badge {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: clamp(0.65rem, 3.5vw, 0.75rem);
    color: var(--gold-primary);
    letter-spacing: 1px;
    padding: 4px 10px;
    background: rgba(255, 179, 71, 0.1);
    border: 1px solid rgba(255, 179, 71, 0.2);
    border-radius: 20px;
}

/* Scrollable Game Area */
.game-scroll-area {
    width: 100%;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 80px; /* More room at the bottom */
    -webkit-overflow-scrolling: touch; 
    touch-action: pan-y; /* Crucial: Allow native scroll events */
    position: relative;
}

/* Redesigned Spotlight */
#tutorial-mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    transition: mask-image 0.5s ease;
    mask-repeat: no-repeat;
    -webkit-mask-repeat: no-repeat;
}

/* Tutorial Overlay */
.tutorial-box-container {
    z-index: 5001;
}

#tutorial-box {
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    border: 2px solid var(--gold-primary);
    position: absolute;
    transform: translate(-50%, -50%);
    transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
    background: var(--bg-surface);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-radius: 16px;
    z-index: 5005;
}

#tutorial-mask {
    transition: opacity 0.5s ease; /* Transition opacity instead if mask-image transitions are flaky */
}

#tutorial-title {
    color: var(--tutorial-title) !important;
}

.tutorial-pulse {
    position: absolute;
    width: 60px;
    height: 60px;
    border: 3px solid var(--gold-bright);
    border-radius: 50%;
    animation: tutorial-pulse 1.5s infinite;
    pointer-events: none;
    z-index: 5002;
    display: none;
}

@keyframes tutorial-pulse {
    0% { transform: scale(0.8); opacity: 1; }
    100% { transform: scale(1.5); opacity: 0; }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Timer bar */
.timer-container {
    width: 100%;
    max-width: 420px;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
    width: calc(100% - 40px);
    /* Leave room for pause btn */
    margin-right: 40px;
}

.timer-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--gold-deep), var(--gold-bright));
    border-radius: 2px;
    transition: width 0.1s linear, background-color 0.3s;
}

.timer-bar.warning {
    background: linear-gradient(90deg, var(--red), #FF6B6B);
}

/* Pause button */
.game-pause-btn {
    position: absolute;
    top: calc(var(--safe-top) + 10px);
    right: 14px;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.game-pause-btn:active {
    transform: scale(0.9);
    background: rgba(255, 179, 71, 0.1);
}

/* ==================== PUZZLE BOARD ==================== */
.puzzle-container {
    position: relative;
    width: 100%;
    max-width: 380px;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 4px auto;
}

.puzzle-board {
    position: relative;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.02);
    border: 2px dashed rgba(255, 179, 71, 0.15);
    border-radius: 12px;
    overflow: hidden;
}

.puzzle-slot {
    position: absolute;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(255, 255, 255, 0.015);
    transition: background 0.3s;
}

.puzzle-slot.occupied {
    border-color: transparent;
    background: transparent;
}

.puzzle-slot.highlight {
    background: rgba(255, 179, 71, 0.12);
    border-color: rgba(255, 179, 71, 0.3);
}

/* ==================== PUZZLE PIECES ==================== */
.piece-tray {
    width: 100%;
    max-width: 540px;
    min-height: 120px;
    padding: 24px 16px;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 40px;
    margin-left: auto;
    margin-right: auto;
}

.piece-tray-label {
    position: absolute;
    top: -18px;
    left: 14px;
    font-size: 0.55rem;
    color: var(--text-muted);
    letter-spacing: 2px;
    font-family: var(--font-mono);
    text-transform: uppercase;
}

.puzzle-piece {
    position: absolute;
    cursor: grab;
    border-radius: 4px;
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.15s var(--ease-bounce);
    z-index: 5;
    touch-action: pan-y;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.puzzle-piece:hover {
    box-shadow: 0 4px 16px rgba(255, 179, 71, 0.3);
    z-index: 20;
}

.puzzle-piece.dragging {
    cursor: grabbing;
    z-index: 100;
    box-shadow: 0 8px 30px rgba(255, 179, 71, 0.4), 0 0 15px var(--gold-glow);
    transform: scale(1.08);
    transition: box-shadow 0.15s, transform 0s;
}

.puzzle-piece.placed {
    cursor: default;
    z-index: 2;
    box-shadow: none;
    border-radius: 0;
    pointer-events: none;
}

.puzzle-piece.snapping {
    transition: left 0.3s var(--ease-bounce), top 0.3s var(--ease-bounce), transform 0.3s var(--ease-bounce), box-shadow 0.3s;
    transform: scale(1);
}

.puzzle-piece.wrong {
    animation: shake-piece 0.4s ease;
}

.puzzle-piece.decoy {
    border: 2px solid transparent;
}

.puzzle-piece.decoy.revealed {
    border-color: var(--red);
    opacity: 0.4;
    pointer-events: none;
}

.puzzle-piece canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Blur mode piece overlay */
.piece-blur-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    background: rgba(10, 10, 15, 0.5);
    transition: opacity 0.6s var(--ease-out-expo);
    pointer-events: none;
}

.piece-blur-overlay.cleared {
    opacity: 0;
}

@keyframes shake-piece {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-6px);
    }

    50% {
        transform: translateX(6px);
    }

    75% {
        transform: translateX(-4px);
    }
}

/* ==================== PREVIEW IMAGE ==================== */
.preview-container {
    position: relative;
    width: 100%;
    max-width: 380px;
}

.preview-toggle {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-img {
    width: 100%;
    border-radius: 10px;
    opacity: 0.6;
    transition: opacity 0.3s;
}

.preview-img.hidden {
    display: none;
}

/* Toggle visibility is managed by JS in mode start() functions */

/* ==================== PROGRESS BAR ==================== */
.progress-bar-container {
    width: 100%;
    max-width: 420px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 44px 0 4px;
    /* Maintain safe zone alignment */
}

.progress-bar {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--gold-deep), var(--gold-bright));
    border-radius: 3px;
    transition: width 0.4s var(--ease-out-expo);
}

.progress-text {
    font-size: 0.65rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    min-width: 40px;
    text-align: right;
}

/* ==================== LEVEL COMPLETE SCREEN ==================== */
.complete-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 28px 24px;
    text-align: center;
}

.complete-title {
    font-size: 1.6rem;
    font-weight: 900;
    color: var(--gold-bright);
    text-shadow: 0 0 20px var(--gold-glow);
    letter-spacing: 2px;
}

.complete-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.stars-display {
    display: flex;
    gap: 8px;
    font-size: 2rem;
}

.star {
    opacity: 0.2;
    transition: all 0.4s var(--ease-bounce);
    transform: scale(0.7);
}

.star.earned {
    opacity: 1;
    transform: scale(1);
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.6));
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
}

.stat-item {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 0.55rem;
    color: var(--text-muted);
    letter-spacing: 2px;
    text-transform: uppercase;
    font-family: var(--font-mono);
}

.stat-value {
    font-size: 1.3rem;
    font-weight: 800;
    font-family: var(--font-mono);
    color: var(--gold-bright);
}

.complete-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.sub-action-btn {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.8rem;
    padding: 10px 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.sub-action-btn:active {
    transform: scale(0.96);
    background: rgba(255, 179, 71, 0.08);
    border-color: var(--gold-primary);
    color: var(--gold-primary);
}

/* ==================== OVERLAYS ==================== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

.overlay.hidden {
    display: none;
}

/* ==================== SETTINGS ==================== */
.settings-panel {
    max-height: 85vh;
    overflow-y: auto;
}

.back-btn {
    font-size: 1.4rem;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: all 0.2s;
    font-family: var(--font-display);
}

.back-btn:active {
    background: rgba(255, 255, 255, 0.08);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.panel-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 1px;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch .slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    transition: all 0.3s;
}

.toggle-switch .slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: all 0.3s var(--ease-bounce);
}

.toggle-switch input:checked+.slider {
    background: var(--gold-primary);
}

.toggle-switch input:checked+.slider::before {
    transform: translateX(20px);
}

.setting-footer {
    text-align: center;
    padding-top: 16px;
    margin-top: 8px;
}

.version-id {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--text-muted);
}

.dev-info {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ==================== LEVEL SELECT ==================== */
.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    width: 100%;
    max-height: 60vh;
    overflow-y: auto;
    padding: 4px;
}

.level-cell {
    aspect-ratio: 1;
    border-radius: 10px;
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.level-cell.completed {
    border-color: rgba(255, 179, 71, 0.3);
    color: var(--gold-primary);
}

.level-cell.current {
    border-color: var(--gold-primary);
    background: rgba(255, 179, 71, 0.1);
    color: var(--gold-bright);
    box-shadow: 0 0 12px rgba(255, 179, 71, 0.2);
}

.level-cell.locked {
    opacity: 0.3;
    cursor: not-allowed;
}

.level-cell:active:not(.locked) {
    transform: scale(0.92);
}

.level-stars {
    font-size: 0.5rem;
    letter-spacing: 1px;
}

/* ==================== SNAP CELEBRATION ==================== */
@keyframes snap-celebrate {
    0% {
        transform: scale(1);
    }

    30% {
        transform: scale(1.05);
    }

    60% {
        transform: scale(0.98);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes complete-burst {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    50% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.snap-celebrate {
    animation: snap-celebrate 0.3s var(--ease-bounce);
}

/* Legacy Toast Removed - Replaced by Premium System at bottom of file */

/* ==================== MASTERY SCREEN ==================== */
.mastery-panel {
    border: 2px solid var(--gold-primary) !important;
    background: radial-gradient(circle at top, rgba(255, 179, 71, 0.15), var(--bg-glass)) !important;
    box-shadow: 0 0 50px rgba(255, 179, 71, 0.2);
}

.mastery-badge {
    font-size: 4rem;
    margin-bottom: 10px;
    filter: drop-shadow(0 0 20px var(--gold-primary));
    animation: float-badge 3s ease-in-out infinite;
}

@keyframes float-badge {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-10px) rotate(5deg); }
}

/* ==================== PARTICLE EFFECTS ==================== */
.particle {
    position: fixed;
    pointer-events: none;
    z-index: 250;
    border-radius: 50%;
    animation: particle-fly 1s var(--ease-out-expo) forwards;
}

@keyframes particle-fly {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(var(--dx), var(--dy)) scale(0);
    }
}

/* ==================== RESPONSIVE ==================== */
@media (max-height: 650px) {
    .game-title {
        font-size: 2.2rem;
    }

    .mode-card {
        padding: 10px 14px;
    }

    .tagline {
        font-size: 0.75rem;
        margin-bottom: 4px;
    }

    .puzzle-container {
        max-width: 320px;
    }

    .piece-tray {
        min-height: 70px;
        max-height: none;
    }
}

@media (max-height: 550px) {
    .menu-panel {
        padding: 16px 16px;
        gap: 10px;
    }

    .game-title {
        font-size: 1.8rem;
    }

    .play-btn {
        padding: 12px 24px;
    }
}

@media (min-width: 768px) {
    .puzzle-container {
        max-width: 450px;
    }

    .piece-tray {
        max-width: 480px;
        max-height: none;
    }
}

/* ==================== UTILITIES ==================== */
.hidden {
    display: none !important;
}

.no-select {
    user-select: none;
    -webkit-user-select: none;
}

/* ==================== SUNFORGE (CHEERY) THEME OVERRIDES ==================== */
:root[data-theme="sunforge"] {
    --bg-deep: #FFF9F0;
    --bg-surface: #FFF9F0;
    --bg-card: #FFFFFF;
    --bg-card-zen: #E8F8F1;
    --bg-card-classic: #E8F2FF;
    --bg-card-chaos: #FFF0E8;
    --bg-card-blur: #F3EEFF;
    --accent-primary: #FF8C00;
    --accent-gold: #FFD000;
    --accent-success: #3DDC84;
    --text-primary: #2C2C2C;
    --text-secondary: #7A5C3E;
    --text-muted: #B0A090;
    --danger: #FF4444;
    --shadow-warm: rgba(255,160,0,0.15);
}

:root[data-theme="sunforge"] .title-puzzle {
    color: var(--accent-primary);
    text-shadow: 2px 2px 4px var(--shadow-warm);
}
:root[data-theme="sunforge"] .title-forge {
    color: var(--text-primary);
    text-shadow: 2px 2px 4px var(--shadow-warm);
}
:root[data-theme="sunforge"] .tagline {
    color: var(--text-secondary);
}
:root[data-theme="sunforge"] .mode-name {
    font-weight: 800;
    font-size: 1.05rem;
}
:root[data-theme="sunforge"] .mode-desc {
    color: var(--text-secondary);
}
:root[data-theme="sunforge"] .glass-panel {
    border: none;
    box-shadow: 0 10px 40px rgba(0,0,0,0.06);
    background: rgba(255, 255, 255, 0.85);
}
:root[data-theme="sunforge"] #play-btn {
    background: var(--accent-gold);
    border: none;
    color: var(--text-primary);
    box-shadow: 0 4px 15px var(--shadow-warm);
    border-radius: 50px;
    transition: transform 0.1s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.1s;
}
:root[data-theme="sunforge"] #play-btn:active {
    transform: scale(0.95);
}
:root[data-theme="sunforge"] #play-btn::before {
    display: none;
}
:root[data-theme="sunforge"] #play-btn .btn-sub {
    color: var(--text-secondary);
}
:root[data-theme="sunforge"] .mode-card {
    border: none;
    background: var(--bg-card);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    background-image: linear-gradient(to bottom, rgba(255,255,255,0.4), rgba(255,255,255,0));
}
:root[data-theme="sunforge"] #mode-zen {
    background-color: var(--bg-card-zen);
}
:root[data-theme="sunforge"] #mode-classic {
    background-color: var(--bg-card-classic);
}
:root[data-theme="sunforge"] #mode-chaos {
    background-color: var(--bg-card-chaos);
}
:root[data-theme="sunforge"] #mode-blur {
    background-color: var(--bg-card-blur);
}
:root[data-theme="sunforge"] .mode-card:not(.mode-locked):hover {
    filter: brightness(0.98);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.08);
}
:root[data-theme="sunforge"] .mode-card:not(.mode-locked):active {
    background-image: linear-gradient(to bottom, rgba(255,255,255,0.8), rgba(255,255,255,0.4));
    transform: scale(0.97);
}
:root[data-theme="sunforge"] .puzzle-board {
    background: #FFFFFF;
    border: 2px solid rgba(255, 160, 0, 0.2);
    box-shadow: inset 0 0 15px rgba(255, 255, 255, 0.8), 0 4px 20px rgba(0, 0, 0, 0.05);
}
:root[data-theme="sunforge"] .puzzle-slot {
    border: 1px solid rgba(0, 0, 0, 0.04);
}
:root[data-theme="sunforge"] .piece-tray {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}
:root[data-theme="sunforge"] .nav-icon-btn,
:root[data-theme="sunforge"] .game-pause-btn {
    background: #FFFFFF;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    color: var(--text-primary);
}
:root[data-theme="sunforge"] .timer-container,
:root[data-theme="sunforge"] .progress-bar {
    background: rgba(0, 0, 0, 0.06);
}
:root[data-theme="sunforge"] .stat-item {
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.04);
    color: var(--text-primary);
}
:root[data-theme="sunforge"] .stat-label {
    color: var(--text-muted);
}
:root[data-theme="sunforge"] .stat-value {
    color: var(--accent-primary);
}
:root[data-theme="sunforge"] #bg-canvas {
    opacity: 0.15;
}
:root[data-theme="sunforge"] .menu-panel {
    animation: fade-in-bloom 1s ease-out forwards;
}

@keyframes fade-in-bloom {
    0% {
        opacity: 0;
        transform: scale(0.95);
        filter: blur(10px) brightness(1.5);
    }
    100% {
        opacity: 1;
        transform: scale(1);
        filter: blur(0px) brightness(1);
    }
}

/* Micro-Animations */
.snap-ripple {
    position: absolute;
    pointer-events: none;
    border: 3px solid var(--accent-gold, #FFD000);
    border-radius: 10px;
    z-index: 100;
    animation: snap-ripple-anim 0.3s ease-out forwards;
}

@keyframes snap-ripple-anim {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* Toast Notifications - Refined for premium look and proper alignment */
.toast {
    position: fixed;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(18, 18, 26, 0.95);
    color: var(--text-secondary); /* Matches tagline color as requested */
    padding: 10px 22px;
    border-radius: 12px;
    font-size: 0.72rem; /* Reduced font size for elegance */
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: 500;
    z-index: 10000;
    pointer-events: none;
    opacity: 0;
    transition: all 0.5s var(--ease-out-expo);
    text-align: center;
    max-width: 80%; /* Proper wrapping */
    width: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    border: 1px solid var(--border-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Tutorial Alignment Fix */
#tutorial-box {
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    border: 2px solid var(--gold-primary);
    position: absolute;
    top: 50% !important; /* Force center unless overridden by script */
    left: 50% !important;
    transform: translate(-50%, -50%); /* Robust centering */
    transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
    width: 90%;
    max-width: 340px;
}

:root[data-theme="sunforge"] .toast {
    background: rgba(255, 255, 255, 0.95);
    color: var(--text-secondary);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

:root[data-theme="sunforge"] .star.earned {
    color: var(--accent-gold);
    text-shadow: 0 0 10px rgba(255, 208, 0, 0.8);
    animation: star-fly-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes star-fly-in {
    0% { transform: translateY(30px) scale(0.5); opacity: 0; }
    100% { transform: translateY(0) scale(1.2); opacity: 1; text-shadow: 0 0 20px rgba(255,208,0,1); }
}

/* ==================== v1.2.0: ZEN GRID PICKER ==================== */
.zen-grid-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: all 0.3s var(--ease-out-expo);
}

.zen-grid-btn.active {
    border-color: var(--gold-bright) !important;
    color: var(--gold-bright) !important;
    background: var(--gold-subtle);
    transform: scale(1.05);
}

/* ==================== v1.2.0: CHAOS — DECOY PULSE ==================== */
@keyframes decoy-shimmer {
    0%, 100% { box-shadow: none; }
    25% { box-shadow: 0 0 8px 2px rgba(255, 71, 87, 0.3); }
    50% { box-shadow: 0 0 12px 4px rgba(255, 71, 87, 0.5); }
    75% { box-shadow: 0 0 8px 2px rgba(255, 71, 87, 0.3); }
}

.puzzle-piece.decoy-pulse {
    animation: decoy-shimmer 1s ease-in-out 2;
}

/* ==================== v1.2.0: CHAOS — STREAK PULSE ==================== */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

#game-streak {
    transition: all 0.3s ease;
    font-weight: 700;
    letter-spacing: 1px;
}

/* ==================== v1.2.0: BLUR — PEEK SYSTEM ==================== */
.piece-blur-overlay {
    transition: backdrop-filter 0.5s ease, -webkit-backdrop-filter 0.5s ease, opacity 0.3s ease;
}

.piece-blur-overlay.peeking {
    backdrop-filter: blur(0px) !important;
    -webkit-backdrop-filter: blur(0px) !important;
    background: rgba(0, 0, 0, 0.05) !important;
    border: 1px solid var(--cyan);
    box-shadow: 0 0 8px var(--cyan-glow);
}

.piece-blur-overlay.cleared {
    opacity: 0;
    pointer-events: none;
}

/* ==================== v1.2.0: BLUR — PEEK TOKEN HUD ==================== */
#game-peek-tokens {
    font-weight: 600;
    letter-spacing: 1px;
    transition: all 0.3s ease;
}

/* ==================== v1.2.0: BLUR — MEMORY FLASH ==================== */
.memory-flash-overlay {
    animation: memory-pulse 1s ease-in-out;
}

@keyframes memory-pulse {
    0% { opacity: 0; }
    20% { opacity: 0.85; }
    80% { opacity: 0.85; }
    100% { opacity: 0.85; }
}