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

:root{
    --bg-background-color: #0f0f0f;
    --bg-fill-color: #fdfdfd;
    --text-primary-color: #f5f5f5;
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 40px;
    --space-3xl: 48px;
    --border-primary-color: #333333;
    --border-radius-xs: 4px;
    --border-radius-sm: 8px;
    --border-radius-md: 12px;
    --border-radius-lg: 16px;
    --border-radius-xl: 20px;
    --border-radius-2xl: 24px;
}

html, body {
    height: 100%;
    width: 100%;
    background-color: var(--bg-background-color);
    color: var(--text-primary-color);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: none;
    touch-action: none;
}

main, section {
    width: 100%;
    height: 100%;
}

section {
    padding: var(--space-2xl);
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: var(--space-lg);
}

section .infos {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-sm);
}

.infos-left, .infos-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.info {
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border-primary-color);
    border-radius: var(--border-radius-sm);
}

.board {
    border: 1px solid var(--border-primary-color);
    border-radius: var(--border-radius-md);
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    background: #0a0a1a;
    touch-action: none;
}

#game-canvas {
    display: block;
    image-rendering: pixelated;
    touch-action: none;
}

#fps-counter {
    color: #22c55e;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    font-weight: 600;
    user-select: none;
    pointer-events: none;
    white-space: nowrap;
}

#top-right {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

#settings-btn, #pause-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--border-primary-color);
    border-radius: var(--border-radius-sm);
    color: #ccc;
    font-size: 16px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s, color 0.15s;
    touch-action: manipulation;
}

#settings-btn:hover, #pause-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

#settings-btn:active, #pause-btn:active {
    background: rgba(255, 255, 255, 0.18);
}

#pause-btn.hidden {
    display: none;
}

#settings-panel {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

#settings-panel.hidden {
    display: none;
}

.settings-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.settings-modal {
    position: relative;
    background: #1a1a2e;
    border: 1px solid var(--border-primary-color);
    border-radius: 16px;
    width: 90%;
    max-width: 360px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px 12px;
    font-size: 16px;
    font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

#settings-close {
    background: none;
    border: none;
    color: #888;
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.15s;
}

#settings-close:hover {
    color: #fff;
}

.settings-body {
    padding: 12px 20px 20px;
}

.setting-group {
    margin-top: 16px;
}

.setting-group:first-child {
    margin-top: 0;
}

.setting-label {
    font-size: 12px;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 10px;
}

.fps-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.fps-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #bbb;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 0;
    cursor: pointer;
    transition: all 0.12s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.fps-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.fps-btn.selected {
    background: rgba(34, 197, 94, 0.15);
    border-color: rgba(34, 197, 94, 0.4);
    color: #22c55e;
}

.custom-fps-row {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

#custom-fps-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    color: #fff;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    padding: 8px 10px;
    outline: none;
    min-width: 0;
}

#custom-fps-input:focus {
    border-color: rgba(34, 197, 94, 0.5);
}

#custom-fps-input::placeholder {
    color: #555;
}

#custom-fps-input::-webkit-inner-spin-button,
#custom-fps-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#custom-fps-input[type=number] {
    -moz-appearance: textfield;
}

#apply-custom {
    background: rgba(34, 197, 94, 0.2);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 8px;
    color: #22c55e;
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    font-weight: 700;
    padding: 8px 14px;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    touch-action: manipulation;
}

#apply-custom:hover {
    background: rgba(34, 197, 94, 0.35);
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.toggle-row span:first-child {
    font-size: 14px;
    color: #ccc;
}

.toggle-row input {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 40px;
    height: 22px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 11px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: #888;
    border-radius: 50%;
    transition: all 0.2s;
}

.toggle-row input:checked + .toggle-slider {
    background: rgba(34, 197, 94, 0.35);
}

.toggle-row input:checked + .toggle-slider::after {
    left: 21px;
    background: #22c55e;
}

#pause-overlay {
    position: fixed;
    inset: 0;
    z-index: 150;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

#pause-overlay.hidden {
    display: none;
}

.pause-text {
    font-size: 48px;
    font-weight: 800;
    color: #fff;
    letter-spacing: 8px;
    opacity: 0.7;
}

.pause-hint {
    margin-top: 12px;
    font-size: 14px;
    color: #888;
    animation: pulse 1.5s ease-in-out infinite;
}

#game-over-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.82);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-radius: var(--border-radius-md);
    cursor: pointer;
    touch-action: manipulation;
}

#game-over-overlay.visible {
    display: flex;
}

#game-over-overlay h1 {
    font-size: 42px;
    font-weight: 800;
    color: #ef4444;
    letter-spacing: 4px;
    text-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
}

#game-over-overlay p {
    font-size: 20px;
    color: #e5e5e5;
}

#game-over-overlay #final-score {
    color: #fbbf24;
    font-weight: 700;
    font-size: 24px;
}

#restart-hint {
    font-size: 14px !important;
    color: #888 !important;
    margin-top: var(--space-sm);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

#countdown-overlay {
    position: fixed;
    inset: 0;
    z-index: 149;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    pointer-events: none;
}

#countdown-overlay.hidden {
    display: none;
}

.countdown-text {
    font-size: 120px;
    font-weight: 900;
    color: #22c55e;
    text-shadow: 0 0 40px rgba(34, 197, 94, 0.5), 0 0 80px rgba(34, 197, 94, 0.25);
    animation: cd-pop 0.65s ease-out;
    user-select: none;
}

@keyframes cd-pop {
    0% { transform: scale(2.5); opacity: 0; }
    60% { opacity: 1; }
    100% { transform: scale(1); opacity: 0.7; }
}

.board.shake {
    animation: shake 0.4s ease-out;
}

@keyframes shake {
    0%, 100% { transform: translate(0, 0); }
    10% { transform: translate(-6px, 4px); }
    20% { transform: translate(6px, -4px); }
    30% { transform: translate(-4px, -6px); }
    40% { transform: translate(4px, 6px); }
    50% { transform: translate(-6px, 2px); }
    60% { transform: translate(6px, 2px); }
    70% { transform: translate(-3px, -5px); }
    80% { transform: translate(3px, 5px); }
    90% { transform: translate(-4px, -2px); }
}

@media (max-width: 600px) {
    section {
        padding: var(--space-sm);
        gap: var(--space-sm);
    }
    section .infos {
        flex-wrap: wrap;
        gap: var(--space-xs);
    }
    .infos .info {
        padding: 3px 8px;
    }
    .info h3 {
        font-size: 10px;
    }
    .info span {
        font-size: 13px;
    }
    #game-over-overlay h1 {
        font-size: 28px;
    }
    #fps-counter {
        font-size: 11px;
    }
    #settings-btn, #pause-btn {
        width: 28px;
        height: 28px;
        min-width: 28px;
        font-size: 14px;
    }
    .infos-left, .infos-right {
        gap: var(--space-xs);
    }
    .settings-modal {
        width: 94%;
        max-width: 320px;
    }
    .pause-text {
        font-size: 36px;
        letter-spacing: 6px;
    }
    .countdown-text {
        font-size: 80px;
    }
}