/* ==============================================
   HEXIFY - Apple-Style Design System
   Clean, Modern, Minimalist
   ============================================== */

/* Apple-like Font: Inter as SF Pro alternative */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ==============================================
   CSS VARIABLES - Design Tokens
   ============================================== */
:root {
    /* Colors - Apple-inspired neutral palette */
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-elevated: rgba(255, 255, 255, 0.72);
    --bg-blur: rgba(255, 255, 255, 0.8);

    /* Text Colors */
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-tertiary: #86868b;

    /* Accent Colors - Vibrant but refined */
    --accent-blue: #0071e3;
    --accent-green: #34c759;
    --accent-orange: #ff9500;
    --accent-pink: #ff2d55;
    --accent-purple: #af52de;
    --accent-teal: #5ac8fa;

    /* Shadows - Subtle, layered */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.04), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.06), 0 5px 10px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.08), 0 10px 20px rgba(0, 0, 0, 0.04);

    /* Border Radius - Apple's signature curves */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;
    --radius-2xl: 28px;
    --radius-full: 9999px;

    /* Transitions - Smooth, subtle */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 500ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* ==============================================
   BASE STYLES
   ============================================== */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    padding: 0;
    background: var(--bg-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-primary);
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
}

/* Canvas Touch Optimization */
canvas {
    touch-action: none !important;
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
}

/* Base Button Reset */
button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* ==============================================
   UI LAYER - Game HUD
   ============================================== */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 16px;
    box-sizing: border-box;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility 0s 0.25s;
    z-index: 10;
}

#ui-layer.visible {
    opacity: 1;
    visibility: visible;
    transition: opacity var(--transition-base), visibility 0s 0s;
}

/* ==============================================
   HEADER - Score & Power-ups
   ============================================== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
    pointer-events: auto;
    gap: 8px;
}

.score-box {
    background: var(--bg-blur);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    padding: 12px 20px;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(255, 255, 255, 0.6);
    text-align: center;
    min-width: 80px;
    transition: transform var(--transition-fast);
}

.score-box:active {
    transform: scale(0.98);
}

.label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.score-box.pulse {
    animation: scorePulse 0.4s ease-out;
}

@keyframes scorePulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.08);
        box-shadow: var(--shadow-lg);
    }

    100% {
        transform: scale(1);
    }
}

/* ==============================================
   POWER-UP BAR - Apple-Style Controls
   ============================================== */
.powerup-bar {
    display: flex;
    flex-direction: row;
    gap: 6px;
    pointer-events: auto;
    background: var(--bg-blur);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    padding: 8px;
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(255, 255, 255, 0.6);
}

.powerup-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.powerup-label {
    font-size: 0.55rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    opacity: 0.7;
    transition: opacity var(--transition-fast);
}

.powerup-wrapper:hover .powerup-label,
.powerup-wrapper:active .powerup-label {
    opacity: 1;
}

.powerup-btn {
    position: relative;
    width: 44px;
    height: 44px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    pointer-events: auto;
    transition: all var(--transition-fast);
    border: 1px solid rgba(0, 0, 0, 0.04);
    overflow: visible;
}

.powerup-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.powerup-btn:active {
    transform: scale(0.95);
}

.powerup-btn .icon {
    font-size: 1.2rem;
    user-select: none;
    transition: transform var(--transition-fast);
}

.powerup-btn .count {
    position: absolute;
    bottom: -4px;
    right: -4px;
    background: var(--text-primary);
    color: white;
    font-size: 0.65rem;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: var(--radius-full);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    box-shadow: var(--shadow-sm);
    border: 2px solid var(--bg-secondary);
}

.powerup-btn .tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background: rgba(30, 30, 35, 0.95);
    color: #ffffff;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition-fast);
    z-index: 200;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.powerup-btn:hover .tooltip {
    opacity: 1;
    transform: translateX(-50%) translateY(-4px);
}

/* Power-up Active States */
.powerup-btn.hammer.active,
.powerup-btn.swap.active {
    background: var(--accent-pink);
    box-shadow: 0 0 0 3px rgba(255, 45, 85, 0.3), var(--shadow-md);
}

.powerup-btn.hammer.active .icon,
.powerup-btn.swap.active .icon {
    filter: brightness(0) invert(1);
    animation: gentlePulse 1.5s ease-in-out infinite;
}

.powerup-btn.disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

@keyframes gentlePulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

/* ==============================================
   PAUSE BUTTON
   ============================================== */
.pause-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    background: var(--bg-blur);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-radius: var(--radius-full);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(255, 255, 255, 0.6);
    transition: all var(--transition-fast);
    font-size: 1.2rem;
    z-index: 50;
    opacity: 0;
    visibility: hidden;
}

#ui-layer.visible .pause-btn {
    opacity: 1;
    visibility: visible;
}

.pause-btn:hover {
    transform: scale(1.08);
    box-shadow: var(--shadow-lg);
}

.pause-btn:active {
    transform: scale(0.95);
}

/* ==============================================
   MODALS - Apple Sheet Style
   ============================================== */
#pause-modal,
#game-over-modal,
#how-to-play-modal,
#level-intro-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
}

#pause-modal.active,
#game-over-modal.active,
#how-to-play-modal.active,
#level-intro-modal.active {
    opacity: 1;
    pointer-events: auto;
}

.pause-card,
.modal-content,
.help-card,
.intro-card {
    background: var(--bg-secondary);
    padding: 32px;
    border-radius: var(--radius-2xl);
    text-align: center;
    box-shadow: var(--shadow-xl);
    animation: modalSlideUp 0.4s var(--transition-spring);
    max-width: 340px;
    width: 85%;
}

@keyframes modalSlideUp {
    0% {
        transform: translateY(20px) scale(0.95);
        opacity: 0;
    }

    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.pause-card h2,
.modal-content h2,
.help-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 24px 0;
}

.pause-btn-row,
.modal-btn-row,
.intro-btn-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pause-menu-btn,
.btn,
.intro-btn,
.help-close-btn {
    padding: 14px 28px;
    border-radius: var(--radius-lg);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
}

.pause-menu-btn.resume,
.btn:not(.btn-secondary),
.intro-btn:not(.cancel-btn),
.help-close-btn {
    background: var(--accent-blue);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 113, 227, 0.3);
}

.pause-menu-btn.resume:hover,
.btn:not(.btn-secondary):hover,
.intro-btn:not(.cancel-btn):hover,
.help-close-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 16px rgba(0, 113, 227, 0.4);
}

.pause-menu-btn.menu,
.btn-secondary,
.intro-btn.cancel-btn {
    background: var(--bg-primary);
    color: var(--text-secondary);
}

.pause-menu-btn.menu:hover,
.btn-secondary:hover,
.intro-btn.cancel-btn:hover {
    background: #e8e8ed;
}

/* ==============================================
   START SCREEN - Hero Landing
   ============================================== */
#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(30px) saturate(150%);
    -webkit-backdrop-filter: blur(30px) saturate(150%);
    transition: opacity var(--transition-slow), visibility var(--transition-slow);
    z-index: 20;
    padding: 20px;
    box-sizing: border-box;
}

#start-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.logo-container {
    text-align: center;
    margin-bottom: 40px;
    animation: floatGentle 6s ease-in-out infinite;
}

h1 {
    font-size: 3.5rem;
    font-weight: 800;
    margin: 0;
    line-height: 1;
    background: linear-gradient(135deg, #FF3CAC 0%, #784BA0 50%, #2B86C5 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -1px;
}

.slogan {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin: 8px 0 20px 0;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.best-score-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-secondary);
    padding: 8px 18px;
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-md);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

@keyframes floatGentle {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

/* ==============================================
   MODE SELECTION - App Icons Style
   ============================================== */
.mode-selection {
    display: flex;
    gap: 32px;
    margin-bottom: 32px;
}

.menu-btn-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    transition: transform var(--transition-spring);
}

.menu-btn-group:hover {
    transform: translateY(-6px);
}

.menu-btn-group:active {
    transform: scale(0.95);
}

.play-btn-large {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-xl);
    background: var(--bg-secondary);
    border: none;
    box-shadow: var(--shadow-lg);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.play-btn-large::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.4) 0%, transparent 50%);
    border-radius: inherit;
}

.endless-btn {
    background: linear-gradient(145deg, #FF9500 0%, #FF2D55 100%) !important;
}

.campaign-btn {
    background: linear-gradient(145deg, #5AC8FA 0%, #AF52DE 100%) !important;
}

.btn-icon {
    font-size: 2rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
    position: relative;
    z-index: 1;
}

.mode-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.mode-desc {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    text-align: center;
    max-width: 90px;
    line-height: 1.3;
}

/* ==============================================
   HOW TO PLAY - Onboarding
   ============================================== */
.how-to-play-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--bg-blur);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-full);
    cursor: pointer;
    margin-bottom: 24px;
    transition: all var(--transition-fast);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.how-to-play-hint:hover {
    background: var(--bg-secondary);
    transform: scale(1.03);
    box-shadow: var(--shadow-md);
}

.hint-icon {
    font-size: 1.1rem;
}

.hint-text {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* How to Play Modal Content */
.help-content {
    text-align: left;
    margin-bottom: 24px;
}

.help-step {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
    padding: 14px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.help-step:hover {
    transform: translateX(4px);
    background: var(--bg-secondary);
}

.step-num {
    width: 28px;
    height: 28px;
    background: var(--accent-blue);
    border-radius: var(--radius-full);
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.step-text {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 500;
    line-height: 1.35;
}

.help-tip {
    margin-top: 16px;
    padding: 14px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    color: var(--text-primary);
    border: 1px solid var(--accent-orange);
}

/* ==============================================
   SETTINGS ROW
   ============================================== */
.settings-row {
    position: absolute;
    bottom: 32px;
    display: flex;
    gap: 12px;
    padding: 8px;
    background: var(--bg-blur);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-radius: var(--radius-full);
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: var(--shadow-md);
}

.sound-toggle {
    width: 40px;
    height: 40px;
    background: var(--bg-secondary);
    border-radius: var(--radius-full);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    border: none;
    box-shadow: var(--shadow-sm);
}

.sound-toggle:hover {
    transform: scale(1.1);
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
}

.sound-toggle:active {
    transform: scale(0.95);
}

.sound-toggle.muted {
    opacity: 0.5;
    background: var(--bg-primary);
}

.setting-icon {
    font-size: 1.2rem;
}

/* ==============================================
   MISSION BOX
   ============================================== */
.mission-box {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: var(--bg-blur);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(255, 255, 255, 0.6);
    text-align: left;
    min-width: 140px;
    max-width: 180px;
    z-index: 50;
}

.mission-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    color: var(--text-tertiary);
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.mission-text {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.85rem;
    line-height: 1.3;
}

.mission-progress-bg {
    width: 100%;
    height: 4px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-full);
    margin-top: 8px;
    overflow: hidden;
}

.mission-progress-bar {
    width: 0%;
    height: 100%;
    background: var(--accent-pink);
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
}

/* ==============================================
   LEVEL UP MESSAGE
   ============================================== */
#level-up-msg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: var(--bg-secondary);
    padding: 32px 48px;
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
    text-align: center;
    pointer-events: none;
    opacity: 0;
    z-index: 100;
    transition: all var(--transition-spring);
    border: 3px solid var(--accent-orange);
}

#level-up-msg.active {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    pointer-events: auto;
    cursor: pointer;
}

#level-up-msg h2 {
    margin: 0;
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, #FF9500 0%, #FF2D55 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#level-up-msg p {
    margin: 8px 0 0 0;
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ==============================================
   LEVEL SELECT SCREEN
   ============================================== */
#level-select-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(30px) saturate(150%);
    -webkit-backdrop-filter: blur(30px) saturate(150%);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 80px;
    overflow-y: auto;
    z-index: 25;
    transition: opacity var(--transition-base);
}

#level-select-screen.hidden {
    display: none;
    opacity: 0;
}

.level-map-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    max-width: 360px;
    padding: 20px;
    padding-bottom: 100px;
}

.level-node {
    width: 70px;
    height: 70px;
    border-radius: var(--radius-xl);
    background: var(--bg-blur);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.6);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    cursor: pointer;
    position: relative;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-fast);
}

.level-node.locked {
    filter: grayscale(1);
    opacity: 0.5;
    pointer-events: none;
}

.level-node.locked::after {
    content: '🔒';
    font-size: 1rem;
    position: absolute;
}

.level-node.unlocked:hover {
    transform: scale(1.08);
    box-shadow: var(--shadow-lg);
}

.level-node.completed {
    background: linear-gradient(145deg, #34C759 0%, #30D158 100%);
    color: white;
    border-color: transparent;
}

.level-stars {
    display: flex;
    gap: 2px;
    font-size: 0.65rem;
    margin-top: -2px;
}

.back-btn {
    position: absolute;
    top: 24px;
    left: 24px;
    background: var(--bg-blur);
    backdrop-filter: blur(20px);
    border: none;
    padding: 10px 18px;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-fast);
    color: var(--text-primary);
    z-index: 30;
}

.back-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
}

/* ==============================================
   LEVEL INTRO CARD
   ============================================== */
.intro-card {
    max-width: 320px;
}

.intro-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.intro-desc {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.4;
}

.goal-list {
    text-align: left;
    background: var(--bg-primary);
    padding: 16px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
}

.goal-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.goal-item:last-child {
    margin-bottom: 0;
}

/* ==============================================
   STACK TOOLTIP
   ============================================== */
#stack-tooltip {
    position: fixed;
    background: rgba(30, 30, 35, 0.95);
    color: #ffffff;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
    z-index: 1000;
    max-width: 180px;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

#stack-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

#stack-tooltip .tooltip-title {
    font-weight: 700;
    margin-bottom: 4px;
}

#stack-tooltip .tooltip-colors {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    margin-top: 6px;
}

#stack-tooltip .color-badge {
    display: flex;
    align-items: center;
    gap: 3px;
    background: rgba(255, 255, 255, 0.15);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
}

#stack-tooltip .color-dot {
    width: 10px;
    height: 10px;
    border-radius: var(--radius-full);
}

/* ==============================================
   GAME INFO BAR (Campaign HUD)
   ============================================== */
.game-info-bar {
    position: absolute;
    top: 90px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 16px;
    pointer-events: none;
    z-index: 10;
}

.info-pill {
    background: var(--bg-blur);
    backdrop-filter: blur(20px);
    padding: 8px 16px;
    border-radius: var(--radius-full);
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.85rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 6px;
}

.moves-danger {
    color: var(--accent-pink);
    animation: dangerPulse 0.8s ease-in-out infinite;
}

@keyframes dangerPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

/* ==============================================
   MOBILE RESPONSIVE
   ============================================== */
@media (max-width: 600px) {
    .header {
        padding: 4px;
    }

    .score-box {
        padding: 8px 14px;
        min-width: 65px;
    }

    .label {
        font-size: 0.55rem;
    }

    .value {
        font-size: 1.2rem;
    }

    .powerup-bar {
        padding: 6px;
        gap: 4px;
    }

    .powerup-btn {
        width: 38px;
        height: 38px;
    }

    .powerup-btn .icon {
        font-size: 1rem;
    }

    .powerup-btn .count {
        min-width: 14px;
        height: 14px;
        font-size: 0.55rem;
    }

    .powerup-btn .tooltip {
        display: none !important;
    }

    .powerup-label {
        display: none;
    }

    h1 {
        font-size: 2.8rem;
    }

    .slogan {
        font-size: 0.85rem;
        letter-spacing: 1.5px;
    }

    .logo-container {
        margin-bottom: 30px;
    }

    .mode-selection {
        gap: 24px;
        margin-bottom: 24px;
    }

    .play-btn-large {
        width: 72px;
        height: 72px;
    }

    .btn-icon {
        font-size: 1.7rem;
    }

    .mode-desc {
        display: none;
    }

    .how-to-play-hint {
        padding: 8px 16px;
        margin-bottom: 20px;
    }

    .hint-text {
        font-size: 0.8rem;
    }

    .settings-row {
        bottom: 24px;
        gap: 8px;
        padding: 6px;
    }

    .sound-toggle {
        width: 36px;
        height: 36px;
    }

    .setting-icon {
        font-size: 1rem;
    }

    .mission-box {
        top: 80px;
        left: 12px;
        bottom: auto;
        padding: 8px 12px;
        min-width: auto;
        max-width: 130px;
    }

    .mission-label {
        font-size: 0.5rem;
    }

    .mission-text {
        font-size: 0.75rem;
    }

    .game-info-bar {
        top: 80px;
        gap: 10px;
    }

    .info-pill {
        padding: 6px 12px;
        font-size: 0.75rem;
    }

    .pause-card,
    .modal-content,
    .help-card {
        padding: 24px;
    }

    .pause-card h2,
    .modal-content h2,
    .help-card h2 {
        font-size: 1.3rem;
    }

    .help-step {
        padding: 10px;
        margin-bottom: 8px;
    }

    .step-num {
        width: 24px;
        height: 24px;
        font-size: 0.75rem;
    }

    .step-text {
        font-size: 0.8rem;
    }

    .level-map-container {
        grid-template-columns: repeat(3, 1fr);
        gap: 16px;
    }

    .level-node {
        width: 65px;
        height: 65px;
    }
}

@media (max-width: 380px) {
    h1 {
        font-size: 2.2rem;
    }

    .score-box {
        padding: 6px 10px;
        min-width: 55px;
    }

    .value {
        font-size: 1rem;
    }

    .powerup-btn {
        width: 34px;
        height: 34px;
    }

    .play-btn-large {
        width: 64px;
        height: 64px;
    }

    .mode-selection {
        gap: 18px;
    }

    .settings-row {
        bottom: 16px;
        transform: scale(0.9);
    }

    .how-to-play-hint {
        padding: 6px 12px;
    }
}

/* ==============================================
   ANIMATIONS - Utility Classes
   ============================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes popIn {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Shuffle/Undo animations */
.powerup-btn.shuffle.shuffling .icon {
    animation: spinOnce 0.5s ease-out;
}

.powerup-btn.undo.undoing .icon {
    animation: spinBack 0.4s ease-out;
}

@keyframes spinOnce {
    0% {
        transform: rotate(0deg) scale(1);
    }

    50% {
        transform: rotate(180deg) scale(1.2);
    }

    100% {
        transform: rotate(360deg) scale(1);
    }
}

@keyframes spinBack {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(-360deg);
    }
}

/* Swap highlight effect */
.swap-highlight {
    animation: swapGlow 0.8s ease-in-out infinite;
}

@keyframes swapGlow {

    0%,
    100% {
        filter: drop-shadow(0 0 4px var(--accent-teal));
    }

    50% {
        filter: drop-shadow(0 0 12px var(--accent-teal));
    }
}

/* ==============================================
   HINT BUTTON
   ============================================== */
.powerup-btn.hint {
    background: linear-gradient(145deg, #FFD700 0%, #FFA500 100%);
}

.powerup-btn.hint .icon {
    filter: none;
}

.powerup-btn.hint:hover {
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
}

/* ==============================================
   STATISTICS MODAL
   ============================================== */
#stats-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
}

#stats-modal.active {
    opacity: 1;
    pointer-events: auto;
}

.stats-card {
    background: var(--bg-secondary);
    padding: 28px;
    border-radius: var(--radius-2xl);
    text-align: center;
    box-shadow: var(--shadow-xl);
    animation: modalSlideUp 0.4s var(--transition-spring);
    max-width: 340px;
    width: 90%;
}

.stats-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 20px 0;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.stat-item {
    background: var(--bg-primary);
    padding: 16px 12px;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: transform var(--transition-fast);
}

.stat-item:hover {
    transform: scale(1.03);
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.stats-btn-row {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn-small {
    padding: 10px 20px !important;
    font-size: 0.85rem !important;
}

/* ==============================================
   PREVIEW HIGHLIGHT (during drag)
   ============================================== */
@keyframes previewPulse {

    0%,
    100% {
        opacity: 0.4;
    }

    50% {
        opacity: 0.6;
    }
}

/* ==============================================
   HINT HIGHLIGHT ANIMATION
   ============================================== */
@keyframes hintGlow {

    0%,
    100% {
        filter: drop-shadow(0 0 8px rgba(100, 255, 150, 0.6));
    }

    50% {
        filter: drop-shadow(0 0 20px rgba(100, 255, 150, 0.9));
    }
}

.hint-highlight {
    animation: hintGlow 1s ease-in-out infinite;
}

/* ==============================================
   AUDIO SETTINGS MODAL
   ============================================== */
#settings-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
}

#settings-modal.active {
    opacity: 1;
    pointer-events: auto;
}

.settings-card {
    background: var(--bg-secondary);
    padding: 28px;
    border-radius: var(--radius-2xl);
    text-align: center;
    box-shadow: var(--shadow-xl);
    animation: modalSlideUp 0.4s var(--transition-spring);
    max-width: 320px;
    width: 90%;
}

.settings-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 24px 0;
}

.settings-content {
    margin-bottom: 24px;
}

.volume-control {
    margin-bottom: 20px;
}

.volume-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.volume-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.volume-value {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.85rem;
    min-width: 40px;
    text-align: right;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--bg-primary);
    outline: none;
    cursor: pointer;
    /* Fix touch/click interaction */
    touch-action: auto;
    pointer-events: auto;
    position: relative;
    z-index: 10;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-full);
    background: var(--accent-blue);
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: transform var(--transition-fast);
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.volume-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-full);
    background: var(--accent-blue);
    cursor: pointer;
    border: none;
    box-shadow: var(--shadow-md);
}

/* Settings Options (Theme, Colorblind) */
.settings-divider {
    height: 1px;
    background: rgba(0, 0, 0, 0.1);
    margin: 16px 0;
}

.settings-option-row {
    margin-bottom: 10px;
}

.setting-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.setting-option:hover {
    background: var(--bg-secondary);
    transform: translateX(4px);
}

.setting-option:active {
    transform: scale(0.98);
}

.setting-option-icon {
    font-size: 1.2rem;
}

.setting-option-text {
    flex: 1;
    text-align: left;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.setting-option-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-blue);
    padding: 4px 10px;
    background: rgba(0, 113, 227, 0.1);
    border-radius: var(--radius-sm);
}

.setting-option-toggle {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
}

.setting-option-toggle.active {
    background: var(--accent-green);
    color: white;
}

/* ==============================================
   LEVEL PROGRESS BAR
   ============================================== */
.level-progress-box {
    position: absolute;
    top: 80px;
    right: 20px;
    background: var(--bg-blur);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(255, 255, 255, 0.6);
    min-width: 120px;
    pointer-events: auto;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base);
}

#ui-layer.visible .level-progress-box {
    opacity: 1;
    visibility: visible;
}

.level-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.level-progress-label {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.level-progress-score {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.level-progress-bg {
    width: 100%;
    height: 6px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.level-progress-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--accent-orange) 0%, var(--accent-pink) 100%);
    border-radius: var(--radius-full);
    transition: width 0.4s ease-out;
}

/* ==============================================
   NO MOVES WARNING
   ============================================== */
.no-moves-warning {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a5a 100%);
    color: white;
    padding: 14px 24px;
    border-radius: var(--radius-xl);
    box-shadow: 0 8px 24px rgba(255, 100, 100, 0.4);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition-base);
    z-index: 80;
}

.no-moves-warning.visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    animation: warningPulse 0.8s ease-in-out infinite;
}

.warning-icon {
    font-size: 1.3rem;
}

.warning-text {
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

@keyframes warningPulse {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
    }

    50% {
        transform: translate(-50%, -50%) scale(1.03);
    }
}

/* Hide level progress in campaign mode */
.level-progress-box.hidden {
    display: none;
}

/* ==============================================
   LEVEL PAGINATION
   ============================================== */
.level-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 15px;
    padding-bottom: 20px;
}

.page-btn {
    background: var(--bg-secondary);
    border: none;
    font-size: 1.5rem;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-fast);
    /* Ensure interaction works reliably */
    touch-action: auto;
    pointer-events: auto;
}

.page-btn:hover:not(:disabled) {
    transform: scale(1.1);
    background: var(--bg-panel);
}

.page-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.page-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.page-indicator {
    font-weight: 700;
    color: var(--text-secondary);
    font-size: 1rem;
    min-width: 80px;
    text-align: center;
    background: rgba(0, 0, 0, 0.05);
    /* very light bg */
    padding: 6px 12px;
    border-radius: var(--radius-full);
}

/* ==============================================
   LEVEL SELECT SCREEN - LAYOUT FIXES
   ============================================== */
#level-select-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
    padding-bottom: 40px;
    /* More bottom padding */
    overflow-y: hidden;
}

#level-select-screen.hidden {
    display: none !important;
}

.level-map-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    /* Slightly tighter gap */
    max-width: 360px;
    /* Slightly narrower */
    width: 100%;
    margin-bottom: 10px;
    /* Reduced margin */
}

.level-node {
    aspect-ratio: 1/1;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 16px;
    /* Slightly smaller radius */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-weight: 800;
    font-size: 1.1rem;
    /* Slightly smaller font */
    color: var(--text-tertiary);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    position: relative;
    user-select: none;
}

.level-node.unlocked {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
}

.level-node.unlocked:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: var(--shadow-lg);
    z-index: 10;
}

.level-node.completed {
    background: var(--accent-green);
    color: white;
}

.level-node.locked {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(0, 0, 0, 0.05);
}

.level-node.locked::after {
    content: '🔒';
    font-size: 1rem;
    position: absolute;
    opacity: 0.5;
}

.level-stars {
    font-size: 0.6rem;
    margin-top: 2px;
}

.back-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    background: transparent;
    border: none;
    font-weight: 700;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 10px;
    z-index: 100;
}

.back-btn:hover {
    color: var(--text-primary);
    transform: translateX(-5px);
}