/**
 * Spatial Match - Game Styles
 * Modern, clean styling for 3D block puzzle game
 */

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #151520;
    --bg-tertiary: #1e1e2e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-primary: #6366f1;
    --accent-secondary: #818cf8;
    --border-color: #2a2a3a;
    --shadow: rgba(0, 0, 0, 0.5);
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    height: 100%;
}

/* Header */
.site-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky; /* Sticky header, but allows absolute children */
    top: 0;
    z-index: 100;
}

.site-header h1 {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 600;
}

.site-header h1 svg {
    width: 24px;
    height: 24px;
    color: var(--accent);
}

.site-header h1 .header-logo {
    width: 40px;
    height: 40px;
    display: block;
    flex-shrink: 0;
}

.header-tagline {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin-left: 0.5rem;
}

.header-stats {
    display: flex;
    gap: 2rem;
    align-items: center;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--accent);
}

.game-mode-badge {
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 0.25rem 0.75rem;
}

.game-mode-badge .stat-value {
    color: var(--accent);
    font-size: 0.875rem;
}

/* Timer Visual Feedback */
#timerDisplay.timer-safe .stat-value {
    color: var(--success);
}

#timerDisplay.timer-warning .stat-value {
    color: var(--warning);
}

#timerDisplay.timer-danger .stat-value {
    color: #ff6b35; /* Orange */
}

#timerDisplay.timer-critical .stat-value {
    color: var(--error);
    animation: timerPulse 1s ease-in-out infinite;
}

@keyframes timerPulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* App Container */
.app-container {
    display: flex;
    height: calc(100vh - 73px);
    gap: 0;
}

/* Canvas Area */
.canvas-area {
    flex: 1;
    position: relative;
    background: var(--bg-primary);
    overflow: hidden;
}

#canvas-container {
    width: 100%;
    height: 100%;
}

.game-overlay {
    position: fixed; /* Changed from absolute to fixed for proper mobile centering */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    display: none; /* Hidden by default, shown when game over */
    align-items: center;
    justify-content: center;
    z-index: 99999; /* Highest z-index to appear above everything */
}

.overlay-content {
    background: rgba(0, 0, 0, 0.9);
    padding: 2rem 3rem;
    border-radius: 12px;
    text-align: center;
    max-width: 400px;
    width: 90%; /* Mobile-friendly width */
    margin: 0 auto; /* Center horizontally */
    pointer-events: auto;
}

.overlay-content h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--accent);
}

.overlay-content p {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

/* Mobile Rotate Button */
.mobile-rotate-btn {
    display: none; /* Hidden on desktop, shown on mobile */
    position: fixed;
    bottom: 100px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: var(--bg-secondary);
    border: 2px solid var(--accent);
    border-radius: 50%;
    color: var(--accent);
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1000;
    box-shadow: 0 4px 12px var(--shadow);
    transition: all 0.2s ease;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.mobile-rotate-btn:active {
    transform: scale(0.95);
    background: var(--bg-tertiary);
}

.mobile-rotate-btn .rotate-icon {
    display: inline-block;
    transition: transform 0.3s ease;
}

.mobile-rotate-btn:active .rotate-icon {
    transform: rotate(-90deg);
}

/* Mobile Settings Button - In header, aligned with logo */
.mobile-settings-btn-header {
    display: none; /* Hidden on desktop, shown on mobile via media query */
    position: fixed; /* Fixed to screen, not header */
    top: 1rem; /* Same line as logo (header padding) */
    right: 1rem; /* Right side of screen */
    width: 40px;
    height: 40px;
    background: transparent;
    border: 2px solid var(--accent);
    border-radius: 50%;
    color: var(--accent);
    font-size: 1.1rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s ease;
    padding: 0;
    margin: 0;
    z-index: 101; /* Above header z-index: 100 */
}

.mobile-settings-btn-header:hover,
.mobile-settings-btn-header:active {
    background: var(--bg-tertiary);
    transform: scale(1.1);
}

.mobile-settings-btn-header .settings-icon {
    display: inline-block;
    transition: transform 0.3s ease;
}

.mobile-settings-btn-header:active .settings-icon {
    transform: scale(1.2);
}

/* Mobile Movement Controls - Cross Shape */
.mobile-movement-controls {
    display: none; /* Hidden on desktop, shown on mobile via media query */
    position: fixed;
    bottom: 100px;
    right: 20px;
    z-index: 1000;
    -webkit-tap-highlight-color: transparent;
}

.mobile-move-btn {
    width: 50px;
    height: 50px;
    background: var(--bg-secondary);
    border: 2px solid var(--accent);
    border-radius: 50%;
    color: var(--accent);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 4px 12px var(--shadow);
}

.mobile-move-btn:active {
    transform: scale(0.95);
    background: var(--accent);
    color: var(--bg-primary);
}

.mobile-move-btn span {
    display: block;
    line-height: 1;
}

/* Position buttons in cross shape - Base styles */
.mobile-move-up {
    grid-column: 2 !important;
    grid-row: 1 !important;
}

.mobile-move-left {
    grid-column: 1 !important;
    grid-row: 2 !important;
}

.mobile-move-down {
    grid-column: 2 !important;
    grid-row: 3 !important;
}

.mobile-move-right {
    grid-column: 3 !important;
    grid-row: 2 !important;
}

.mobile-move-row {
    display: none; /* Hide the row wrapper, using grid instead */
}

/* Combo Panel */
.combo-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    min-width: 200px;
    max-width: 250px;
    box-shadow: 0 4px 12px var(--shadow);
    z-index: 50;
    backdrop-filter: blur(10px);
}

.combo-header {
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.matches-found {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.875rem;
}

.matches-found-label {
    color: var(--text-secondary);
}

.matches-found-value {
    color: var(--accent);
    font-weight: 600;
}

.combo-header h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.top-combo {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.top-combo-label {
    color: var(--text-secondary);
}

.top-combo-value {
    color: var(--accent);
    font-weight: 700;
    font-size: 1.1rem;
}

.combo-history {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.combo-empty {
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: center;
    padding: 1rem 0;
    font-style: italic;
}

.combo-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 4px;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.combo-item:hover {
    background: var(--border-color);
}

.combo-item.combo-top {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), var(--bg-tertiary));
    border: 1px solid var(--accent);
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.3);
}

.combo-move {
    color: var(--text-secondary);
}

.combo-score {
    color: var(--accent);
    font-weight: 600;
}

.combo-item.combo-top .combo-score {
    color: #fbbf24;
    font-weight: 700;
}

.combo-history::-webkit-scrollbar {
    width: 4px;
}

.combo-history::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 2px;
}

.combo-history::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.combo-history::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Right Panel */
.right-panel {
    width: 320px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    padding: 1.5rem;
    overflow-y: auto;
    overflow-x: hidden;
}

.panel-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.panel-section:last-child {
    border-bottom: none;
}

/* Collapsible Panel Section */
.panel-section-collapsible {
    position: relative;
}

.panel-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    transition: background-color 0.2s ease;
}

.panel-section-header h2 {
    margin: 0;
    flex: 1;
}

.panel-toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 32px;
    -webkit-tap-highlight-color: transparent;
}

.panel-toggle-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.panel-toggle-btn:active {
    transform: scale(0.95);
}

.toggle-icon {
    font-size: 0.75rem;
    transition: transform 0.3s ease;
    display: inline-block;
}

.panel-section-collapsible.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.panel-section-content {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    max-height: 1000px;
    opacity: 1;
}

.panel-section-collapsible.collapsed .panel-section-content {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
}

/* Power-Up Popout Panel */
.power-up-popout {
    position: fixed;
    top: 100px;
    right: 20px;
    width: 280px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    transition: all 0.3s ease;
    user-select: none;
}

/* Override desktop positioning for mobile */
.mobile-mode .power-up-popout {
    right: 0 !important;
    left: auto !important;
}

.power-up-popout.docked {
    position: fixed;
    top: auto;
    right: 20px;
    bottom: 20px;
}

.power-up-popout.dragging {
    transition: none;
    cursor: grabbing;
}

.power-up-popout.minimized {
    height: auto;
}

.power-up-popout.minimized .power-up-popout-content {
    display: none;
}

.power-up-popout-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    border-radius: 12px 12px 0 0;
    cursor: grab;
}

.power-up-popout-header:active {
    cursor: grabbing;
}

.power-up-popout-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.power-up-popout-controls {
    display: flex;
    gap: 0.5rem;
}

.power-up-dock-btn,
.power-up-minimize-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: all 0.2s ease;
    font-size: 1rem;
    line-height: 1;
}

.power-up-dock-btn:hover,
.power-up-minimize-btn:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.power-up-popout.docked .power-up-dock-btn .dock-icon {
    opacity: 1;
}

.power-up-popout:not(.docked) .power-up-dock-btn .dock-icon {
    opacity: 0.7;
}

.power-up-popout-content {
    padding: 1rem;
    max-height: 500px;
    overflow-y: auto;
}

.power-up-popout-content::-webkit-scrollbar {
    width: 6px;
}

.power-up-popout-content::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.power-up-popout-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.power-up-popout-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.power-up-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-top: 1rem;
}

.power-up-button {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 80px;
    opacity: 1;
}

.power-up-button:hover:not(.disabled) {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.1);
    transform: translateY(-2px);
}

.power-up-button.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.power-up-button.active {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.2);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
    animation: powerUpPulse 2s ease-in-out infinite;
}

@keyframes powerUpPulse {
    0%, 100% {
        box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
    }
    50% {
        box-shadow: 0 0 20px rgba(99, 102, 241, 0.8);
    }
}

.power-up-icon {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.power-up-name {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.power-up-charges {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    background: var(--accent);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.125rem 0.375rem;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
}

.power-up-button.disabled .power-up-charges {
    background: var(--text-secondary);
}

.power-up-button.active .power-up-charges {
    background: var(--success);
    animation: chargePulse 1s ease-in-out infinite;
}

@keyframes chargePulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* Power-Up Timers */
.power-up-timers {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 0;
}

.power-up-timer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 6px;
    font-size: 0.75rem;
}

.power-up-timer-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.power-up-timer-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.power-up-timer-name {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.7rem;
}

.power-up-timer-bar-container {
    width: 100%;
    height: 4px;
    background: var(--bg-primary);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.power-up-timer-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover));
    border-radius: 2px;
    transition: width 0.1s linear;
    position: relative;
}

.power-up-timer-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

.power-up-timer-time {
    color: var(--text-secondary);
    font-size: 0.65rem;
    white-space: nowrap;
    min-width: 35px;
    text-align: right;
}

.power-up-timer.warning .power-up-timer-bar {
    background: linear-gradient(90deg, var(--warning), #ff6b6b);
}

.power-up-timer.critical .power-up-timer-bar {
    background: linear-gradient(90deg, var(--error), #ff4444);
    animation: pulseCritical 0.5s ease-in-out infinite;
}

@keyframes pulseCritical {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

.panel-section h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* Game Info */
.game-info {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.info-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.info-row span:last-child {
    color: var(--text-primary);
    font-weight: 600;
}

/* Buttons */
.control-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
    border-color: var(--accent);
}

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

/* Controls */
.control-select {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

.control-select:hover {
    border-color: var(--accent);
}

.control-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 1rem;
}

.control-row label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    min-width: 100px;
}

.control-slider {
    flex: 1;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.control-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.control-slider::-webkit-slider-thumb:hover {
    background: var(--accent-hover);
}

.control-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.control-slider::-moz-range-thumb:hover {
    background: var(--accent-hover);
}

.control-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent);
}

/* Instructions */
.instructions {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.instructions p {
    margin-bottom: 0.75rem;
}

.instructions ul {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.instructions li {
    margin-bottom: 0.5rem;
}

.instructions strong {
    color: var(--text-primary);
}

/* Scrollbar Styling */
.right-panel::-webkit-scrollbar {
    width: 8px;
}

.right-panel::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.right-panel::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.right-panel::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

/* Floating Score Popup */
.floating-score {
    position: absolute;
    pointer-events: none;
    font-size: 2rem;
    font-weight: bold;
    color: #10b981;
    text-shadow: 0 0 10px rgba(16, 185, 129, 0.8), 0 2px 4px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: none;
}

.floating-score.animate {
    animation: scoreFloat 1.5s ease-out forwards;
}

@keyframes scoreFloat {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    20% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.2);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -120%) scale(0.8);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .right-panel {
        width: 100%;
        max-height: 40vh;
    }
    
    .canvas-area {
        height: 60vh;
    }

    .header-stats {
        gap: 1rem;
    }

    .stat-value {
        font-size: 1rem;
    }
}

/* Settings Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-modal-content {
    background: var(--bg-secondary);
    border: 2px solid var(--accent-primary);
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--bg-tertiary);
}

.modal-header h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.modal-close:hover {
    background-color: var(--bg-tertiary);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    padding: 1.5rem;
    border-top: 1px solid var(--bg-tertiary);
}

.settings-body {
    display: flex;
    gap: 2rem;
    min-height: 500px;
}

.settings-tabs {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: 200px;
    flex-shrink: 0;
    border-right: 2px solid var(--bg-tertiary);
    padding-right: 1.5rem;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    text-align: left;
    border-left: 3px solid transparent;
    transition: all 0.2s;
    border-radius: 4px;
    margin-left: -3px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.tab-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
}

.tab-btn.active {
    color: var(--accent-primary);
    border-left-color: var(--accent-primary);
    background-color: var(--bg-tertiary);
}

.tab-label {
    flex: 1;
}

.tab-badge {
    font-size: 0.75rem;
    opacity: 0.5;
    transition: opacity 0.2s;
    line-height: 1;
}

.tab-btn:hover .tab-badge {
    opacity: 0.8;
}

.tab-btn.active .tab-badge {
    opacity: 0.7;
}

.global-badge {
    color: var(--accent-primary);
}

.local-badge {
    color: var(--text-secondary);
}

.settings-content {
    flex: 1;
    min-height: 400px;
    overflow-y: auto;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.tab-panel h3 {
    color: var(--text-primary);
    margin-top: 0;
    margin-bottom: 1.5rem;
    font-size: 1.2rem;
}

.setting-group {
    margin-bottom: 1.5rem;
}

.setting-group label {
    display: block;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.setting-group label span {
    color: var(--accent-primary);
    font-weight: bold;
    margin-left: 0.5rem;
}

.setting-slider {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
    pointer-events: auto;
    margin: 10px 0;
}

.setting-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.setting-slider::-moz-range-track {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.setting-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: #ffffff;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
    border: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3), 0 2px 6px rgba(255, 255, 255, 0.4);
    position: relative;
    z-index: 1;
}

.setting-slider::-webkit-slider-thumb:hover {
    background: #f0f0f0;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5), 0 3px 8px rgba(255, 255, 255, 0.5);
}

.setting-slider::-webkit-slider-thumb:active {
    background: #e0e0e0;
}

.setting-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #ffffff;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3), 0 2px 6px rgba(255, 255, 255, 0.4);
    transition: background 0.2s;
    position: relative;
    z-index: 1;
}

.setting-slider::-moz-range-thumb:hover {
    background: #f0f0f0;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5), 0 3px 8px rgba(255, 255, 255, 0.5);
}

.setting-slider::-moz-range-thumb:active {
    background: #e0e0e0;
}

@media (max-width: 768px) {
    .settings-modal-content {
        width: 95%;
        max-height: 95vh;
    }
    
    .settings-body {
        flex-direction: column;
        gap: 1rem;
    }
    
    .settings-tabs {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
        border-right: none;
        border-bottom: 2px solid var(--bg-tertiary);
        padding-right: 0;
        padding-bottom: 1rem;
        margin-bottom: 0;
    }
    
    .tab-btn {
        white-space: nowrap;
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
        border-left: none;
        border-bottom: 3px solid transparent;
        margin-left: 0;
        margin-bottom: -3px;
    }
    
    .tab-btn.active {
        border-left: none;
        border-bottom-color: var(--accent-primary);
    }
}

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

/* Controls */
.control-select {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

.control-select:hover {
    border-color: var(--accent);
}

.control-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 1rem;
}

.control-row label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    min-width: 100px;
}

.control-slider {
    flex: 1;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.control-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.control-slider::-webkit-slider-thumb:hover {
    background: var(--accent-hover);
}

.control-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.control-slider::-moz-range-thumb:hover {
    background: var(--accent-hover);
}

.control-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent);
}

/* Instructions */
.instructions {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.instructions p {
    margin-bottom: 0.75rem;
}

.instructions ul {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.instructions li {
    margin-bottom: 0.5rem;
}

.instructions strong {
    color: var(--text-primary);
}

/* Scrollbar Styling */
.right-panel::-webkit-scrollbar {
    width: 8px;
}

.right-panel::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.right-panel::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.right-panel::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

/* Floating Score Popup */
.floating-score {
    position: absolute;
    pointer-events: none;
    font-size: 2rem;
    font-weight: bold;
    color: #10b981;
    text-shadow: 0 0 10px rgba(16, 185, 129, 0.8), 0 2px 4px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: none;
}

.floating-score.animate {
    animation: scoreFloat 1.5s ease-out forwards;
}

@keyframes scoreFloat {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    20% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.2);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -120%) scale(0.8);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .right-panel {
        width: 100%;
        max-height: 40vh;
    }
    
    .canvas-area {
        height: 60vh;
    }

    .header-stats {
        gap: 1rem;
    }

    .stat-value {
        font-size: 1rem;
    }
}

/* Settings Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-modal-content {
    background: var(--bg-secondary);
    border: 2px solid var(--accent-primary);
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--bg-tertiary);
}

.modal-header h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.modal-close:hover {
    background-color: var(--bg-tertiary);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    padding: 1.5rem;
    border-top: 1px solid var(--bg-tertiary);
}

.settings-body {
    display: flex;
    gap: 2rem;
    min-height: 500px;
}

.settings-tabs {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: 200px;
    flex-shrink: 0;
    border-right: 2px solid var(--bg-tertiary);
    padding-right: 1.5rem;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    text-align: left;
    border-left: 3px solid transparent;
    transition: all 0.2s;
    border-radius: 4px;
    margin-left: -3px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.tab-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
}

.tab-btn.active {
    color: var(--accent-primary);
    border-left-color: var(--accent-primary);
    background-color: var(--bg-tertiary);
}

.tab-label {
    flex: 1;
}

.tab-badge {
    font-size: 0.75rem;
    opacity: 0.5;
    transition: opacity 0.2s;
    line-height: 1;
}

.tab-btn:hover .tab-badge {
    opacity: 0.8;
}

.tab-btn.active .tab-badge {
    opacity: 0.7;
}

.global-badge {
    color: var(--accent-primary);
}

.local-badge {
    color: var(--text-secondary);
}

.settings-content {
    flex: 1;
    min-height: 400px;
    overflow-y: auto;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.tab-panel h3 {
    color: var(--text-primary);
    margin-top: 0;
    margin-bottom: 1.5rem;
    font-size: 1.2rem;
}

.setting-group {
    margin-bottom: 1.5rem;
}

.setting-group label {
    display: block;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.setting-group label span {
    color: var(--accent-primary);
    font-weight: bold;
    margin-left: 0.5rem;
}

.setting-slider {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
    margin: 10px 0;
}

.setting-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: grab;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    border: 2px solid var(--bg-secondary);
}

.setting-slider::-webkit-slider-thumb:hover {
    background: var(--accent-secondary);
    transform: scale(1.1);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
}

.setting-slider::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.2);
}

.setting-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: grab;
    border: 2px solid var(--bg-secondary);
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.setting-slider::-moz-range-thumb:hover {
    background: var(--accent-secondary);
    transform: scale(1.1);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
}

.setting-slider::-moz-range-thumb:active {
    cursor: grabbing;
    transform: scale(1.2);
}

.setting-slider::-ms-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: grab;
    border: 2px solid var(--bg-secondary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

@media (max-width: 768px) {
    .settings-modal-content {
        width: 95%;
        max-height: 95vh;
    }
    
    .settings-body {
        flex-direction: column;
        gap: 1rem;
    }
    
    .settings-tabs {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
        border-right: none;
        border-bottom: 2px solid var(--bg-tertiary);
        padding-right: 0;
        padding-bottom: 1rem;
        margin-bottom: 0;
    }
    
    .tab-btn {
        white-space: nowrap;
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
        border-left: none;
        border-bottom: 3px solid transparent;
        margin-left: 0;
        margin-bottom: -3px;
    }
    
    .tab-btn.active {
        border-left: none;
        border-bottom-color: var(--accent-primary);
    }
}


/* Leaderboard Styles */
.leaderboard-modal-content {
    max-width: 900px;
    max-height: 90vh;
}

.leaderboard-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.leaderboard-filters {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.leaderboard-filters label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.leaderboard-filters select {
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
}

.leaderboard-stats {
    display: flex;
    gap: 2rem;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.leaderboard-table-container {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
}

.leaderboard-table thead {
    position: sticky;
    top: 0;
    background: var(--bg-tertiary);
    z-index: 10;
}

.leaderboard-table th {
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
    background: var(--bg-tertiary);
}

.leaderboard-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.leaderboard-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.leaderboard-table tbody tr.leaderboard-gold {
    background: rgba(255, 215, 0, 0.1);
    border-left: 3px solid #ffd700;
}

.leaderboard-table tbody tr.leaderboard-silver {
    background: rgba(192, 192, 192, 0.1);
    border-left: 3px solid #c0c0c0;
}

.leaderboard-table tbody tr.leaderboard-bronze {
    background: rgba(205, 127, 50, 0.1);
    border-left: 3px solid #cd7f32;
}

.leaderboard-loading,
.leaderboard-empty,
.leaderboard-error {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.leaderboard-error {
    color: var(--error);
}

/* Leaderboard Mobile Styles */
@media (max-width: 768px) {
    .leaderboard-modal-content {
        max-width: 100% !important;
        width: 95% !important;
        max-height: 95vh !important;
        margin: 2.5vh auto !important;
    }
    
    .leaderboard-body {
        gap: 1rem !important;
    }
    
    .leaderboard-filters {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
    }
    
    .leaderboard-filters label {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }
    
    .leaderboard-filters select {
        width: 100% !important;
        padding: 0.75rem !important;
    }
    
    .leaderboard-stats {
        flex-direction: column !important;
        gap: 1rem !important;
        padding: 1rem !important;
    }
    
    .leaderboard-table-container {
        max-height: 50vh !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .leaderboard-table {
        min-width: 600px !important; /* Allow horizontal scroll on very small screens */
        font-size: 0.875rem !important;
    }
    
    .leaderboard-table th,
    .leaderboard-table td {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.875rem !important;
    }
    
    .leaderboard-table th {
        font-size: 0.8rem !important;
        font-weight: 600 !important;
    }
    
    /* Hide less important columns on very small screens */
    @media (max-width: 480px) {
        .leaderboard-table th:nth-child(3),
        .leaderboard-table td:nth-child(3) {
            display: none; /* Hide date column on very small screens */
        }
    }
}

/* Footer */
.site-footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 1rem 2rem;
    margin-top: auto;
    position: sticky;
    bottom: 0;
    z-index: 100;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.footer-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.footer-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.made-by {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 400;
    display: block;
}

.footer-separator {
    color: var(--text-secondary);
    font-size: 0.875rem;
    opacity: 0.5;
}

.technologies {
    color: var(--text-secondary);
    font-size: 0.875rem;
    opacity: 0.8;
}

.buymeacoffee-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    transition: color 0.2s, transform 0.2s, opacity 0.2s;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.buymeacoffee-link:hover {
    color: var(--text-primary);
    opacity: 1;
    transform: translateY(-1px);
    background: var(--bg-tertiary);
}

.buymeacoffee-link:active {
    transform: translateY(0);
}

/* Mobile Optimizations - Enhanced */
@media (max-width: 768px) {
    /* Show mobile settings button in header on mobile */
    .mobile-settings-btn-header {
        display: flex !important;
    }
    
    /* Prevent scrolling and zoom on mobile */
    html, body {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
        touch-action: none !important; /* Prevent zoom, pan, and other gestures */
        -webkit-overflow-scrolling: none !important;
        overscroll-behavior: none !important;
    }
    
    /* Prevent double-tap zoom */
    * {
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
        -webkit-touch-callout: none !important;
        -webkit-user-select: none !important;
        user-select: none !important;
    }
    
    /* Allow text selection in specific areas if needed */
    input, textarea, select {
        -webkit-user-select: text !important;
        user-select: text !important;
        touch-action: auto !important;
    }
    
    /* Show mobile rotate button on mobile */
    .mobile-rotate-btn {
        display: flex;
    }
    
    /* Show mobile movement controls on mobile - Cross Shape */
    .mobile-movement-controls {
        display: grid !important;
        grid-template-columns: 50px 50px 50px !important;
        grid-template-rows: 50px 50px 50px !important;
        gap: 0.25rem !important;
        width: 150px !important;
        height: 150px !important;
        place-items: center !important;
    }
    
    /* Force cross shape positioning in mobile mode */
    .mobile-mode .mobile-move-up {
        grid-column: 2 !important;
        grid-row: 1 !important;
    }
    
    .mobile-mode .mobile-move-left {
        grid-column: 1 !important;
        grid-row: 2 !important;
    }
    
    .mobile-mode .mobile-move-down {
        grid-column: 2 !important;
        grid-row: 3 !important;
    }
    
    .mobile-mode .mobile-move-right {
        grid-column: 3 !important;
        grid-row: 2 !important;
    }
    
    /* Mobile Button Bar - Fixed at bottom */
    .mobile-button-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 80px;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        display: flex;
        justify-content: space-around;
        align-items: center;
        padding: 0.5rem;
        z-index: 1000;
        box-shadow: 0 -4px 12px var(--shadow);
    }
    
    .mobile-bar-btn {
        flex: 1;
        max-width: 80px;
        height: 60px;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        color: var(--text-primary);
        font-size: 1.5rem;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
        -webkit-tap-highlight-color: transparent;
        margin: 0 0.25rem;
    }
    
    .mobile-bar-btn:active {
        transform: scale(0.95);
        background: var(--accent);
        border-color: var(--accent);
    }
    
    .mobile-bar-icon {
        display: block;
    }
    
    /* Mobile Power-Ups Column - Fixed to right edge */
    .mobile-mode .mobile-power-ups-column {
        position: fixed !important;
        right: 0 !important;
        left: auto !important;
        top: 110px !important; /* Positioned below header stats, avoiding TIME display */
        bottom: 80px !important;
        transform: none !important;
        width: 70px !important; /* Slightly wider to accommodate labels */
        height: auto !important;
        max-height: none !important;
        border-left: 1px solid var(--border-color) !important;
        border-right: none !important;
        border-top: none !important;
        border-bottom: none !important;
        border-radius: 0 !important;
        box-shadow: -4px 0 12px var(--shadow) !important;
        background: var(--bg-secondary) !important;
        z-index: 999 !important;
    }
    
    .mobile-mode .mobile-power-ups-column .power-up-popout-header {
        display: none !important; /* Hide header on mobile */
    }
    
    .mobile-mode .mobile-power-ups-column .power-up-popout-content {
        padding: 0.5rem 0.25rem !important;
        height: 100% !important;
        max-height: none !important;
        overflow-y: auto !important;
        display: block !important;
    }
    
    .mobile-mode .mobile-power-ups-column .power-up-grid,
    .mobile-mode .mobile-power-ups-column-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
        margin-top: 0 !important;
        width: 100% !important;
    }
    
    .mobile-mode .mobile-power-ups-column-grid .power-up-button {
        width: 100% !important;
        min-height: 60px !important;
        padding: 0.5rem 0.25rem !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 0.25rem !important;
        display: flex !important;
        background: var(--bg-tertiary) !important;
        border: 1px solid var(--border-color) !important;
        border-radius: 8px !important;
        position: relative !important;
    }
    
    .mobile-mode .mobile-power-ups-column-grid .power-up-icon {
        font-size: 1.5rem !important;
        margin-bottom: 0 !important;
        flex-shrink: 0 !important;
    }
    
    .mobile-mode .mobile-power-ups-column-grid .power-up-name {
        display: block !important; /* Show labels under icons */
        font-size: 0.6rem !important;
        margin-top: 0.25rem !important;
        text-align: center !important;
        line-height: 1.2 !important;
    }
    
    .mobile-mode .mobile-power-ups-column-grid .power-up-charges {
        position: absolute !important;
        top: 4px !important;
        right: 4px !important;
        margin: 0 !important;
        font-size: 0.65rem !important;
        padding: 0.15rem 0.3rem !important;
        min-width: 18px !important;
        background: var(--accent) !important;
        color: var(--bg-primary) !important;
        border-radius: 10px !important;
    }
    
    /* Hide right panel on mobile */
    .mobile-mode .right-panel {
        display: none !important;
    }
    
    /* Canvas area maximization */
    .mobile-mode .canvas-area {
        width: calc(100% - 70px) !important; /* Account for power-ups sidebar on right */
        margin-left: 0 !important;
        margin-right: 70px !important; /* Push canvas to the left of sidebar */
        height: calc(100vh - 73px - 80px) !important; /* Viewport minus header minus button bar */
    }
    
    .mobile-mode .app-container {
        height: calc(100vh - 73px) !important;
    }
    
    /* Game Overlay - Mobile Fixes */
    .game-overlay {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 99999 !important; /* Highest z-index */
    }
    
    .overlay-content {
        width: 85% !important;
        max-width: 400px !important;
        padding: 1.5rem 2rem !important;
        margin: 0 auto !important;
    }
    
    .overlay-content h2 {
        font-size: 1.25rem !important;
    }
    
    .overlay-content p {
        font-size: 0.9rem !important;
        margin-bottom: 1rem !important;
    }
    /* Header - Mobile Layout */
    .site-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 0.75rem 1rem;
        gap: 0.75rem;
    }
    
    .site-header h1 {
        font-size: 1.25rem;
        width: 100%;
    }
    
    .site-header h1 .header-logo {
        width: 32px;
        height: 32px;
    }
    
    /* Mobile settings button - align with logo line */
    .mobile-settings-btn-header {
        top: 0.75rem !important; /* Match header padding */
        right: 1rem !important; /* Right side of screen */
    }
    
    .header-tagline {
        font-size: 0.75rem;
        margin-left: 0.25rem;
    }
    
    .header-stats {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 0.5rem;
        justify-content: space-between;
    }
    
    .stat-item {
        gap: 0.125rem;
    }
    
    .stat-label {
        font-size: 0.65rem;
    }
    
    .stat-value {
        font-size: 0.9rem;
    }
    
    /* App Container - Stack vertically */
    .app-container {
        flex-direction: column;
        height: calc(100vh - 120px);
    }
    
    .canvas-area {
        height: 50vh;
        min-height: 300px;
    }
    
    .right-panel {
        width: 100%;
        max-height: 50vh;
        border-left: none;
        border-top: 1px solid var(--border-color);
        padding: 1rem;
        overflow-y: auto;
    }
    
    .panel-section {
        margin-bottom: 1rem;
        padding-bottom: 1rem;
    }
    
    .panel-section h2 {
        font-size: 1rem;
    }
    
    /* Power-Ups - Smaller on mobile */
    .power-up-popout {
        width: 200px;
        top: 80px;
        right: 10px;
        max-width: calc(100vw - 20px);
    }
    
    .power-up-popout-header {
        padding: 0.5rem 0.75rem;
    }
    
    .power-up-popout-header h2 {
        font-size: 0.875rem;
    }
    
    .power-up-popout-content {
        padding: 0.75rem;
        max-height: 300px;
    }
    
    .power-up-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        margin-top: 0.5rem;
    }
    
    .power-up-button {
        padding: 0.5rem;
        min-height: 60px;
        border-width: 1px;
    }
    
    .power-up-icon {
        font-size: 1.1rem;
        margin-bottom: 0.125rem;
    }
    
    .power-up-name {
        font-size: 0.65rem;
        margin-bottom: 0.125rem;
    }
    
    .power-up-charges {
        font-size: 0.65rem;
        padding: 0.1rem 0.25rem;
        min-width: 16px;
        top: 0.125rem;
        right: 0.125rem;
    }
    
    /* Move History (Combo Panel) - Smaller on mobile */
    .combo-panel {
        top: 10px;
        left: 10px;
        min-width: 150px;
        max-width: 180px;
        padding: 0.75rem;
        font-size: 0.8rem;
    }
    
    .combo-header {
        margin-bottom: 0.5rem;
        padding-bottom: 0.5rem;
    }
    
    .combo-header h3 {
        font-size: 0.8rem;
        margin-bottom: 0.25rem;
    }
    
    .top-combo {
        font-size: 0.75rem;
    }
    
    .top-combo-value {
        font-size: 0.95rem;
    }
    
    .combo-history {
        max-height: 200px;
        gap: 0.375rem;
    }
    
    .combo-item {
        padding: 0.375rem;
        font-size: 0.75rem;
    }
    
    .combo-empty {
        font-size: 0.75rem;
        padding: 0.75rem 0;
    }
    
    /* Control Buttons - Stack on mobile */
    .control-buttons {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .btn {
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
    }
    
    /* Game Info - Compact */
    .game-info {
        font-size: 0.875rem;
    }
    
    .info-row {
        font-size: 0.875rem;
        padding: 0.25rem 0;
    }
    
    /* Collapsible sections on mobile */
    .panel-section-collapsible {
        margin-bottom: 0.5rem;
    }
    
    .panel-section-header {
        padding: 0.75rem;
        background: var(--bg-tertiary);
        border-radius: 8px;
        margin-bottom: 0;
        touch-action: manipulation;
    }
    
    .panel-section-header h2 {
        font-size: 0.95rem;
        margin: 0;
    }
    
    .panel-toggle-btn {
        min-width: 36px;
        min-height: 36px;
        padding: 0.5rem;
    }
    
    .toggle-icon {
        font-size: 0.875rem;
    }
    
    .panel-section-content {
        padding: 0.75rem;
        margin-top: 0.5rem;
    }
    
    .panel-section-collapsible.collapsed {
        padding-bottom: 0.5rem;
        border-bottom: 1px solid var(--border-color);
    }
    
    .panel-section-collapsible.collapsed .panel-section-header {
        margin-bottom: 0;
    }
    
    /* Swipe indicator for mobile */
    .panel-section-header::after {
        content: '⇅';
        position: absolute;
        right: 2.5rem;
        font-size: 0.75rem;
        color: var(--text-secondary);
        opacity: 0.5;
        transition: opacity 0.2s;
    }
    
    .panel-section-header:active::after {
        opacity: 1;
    }
    
    /* Visual feedback for swipe */
    .panel-section-header.swiping {
        background: var(--bg-primary);
    }
}
