/* Variabili di Tema */
:root {
    --bg-color-light: #f0f0f0;
    --text-color-light: #000000;
    --bg-color-dark: #000000;
    --text-color-dark: #ffffff;
    --accent-color: #ff6b6b;
    --button-color-light: #ff6b6b;
    --button-color-dark: #444;
    --pattern-color-light: rgba(0, 0, 0, 0.15);
    --pattern-color-dark: rgba(255, 255, 255, 0.15);
    --board-size: min(95vw, 95vh, 500px); /* Dimensione massima del campo di gioco */
}

/* Theme Classes */
body.light {
    --bg-color: var(--bg-color-light);
    --text-color: var(--text-color-light);
    --button-bg: var(--button-color-light);
    --pattern-color: var(--pattern-color-light);
}

body.dark {
    --bg-color: var(--bg-color-dark);
    --text-color: var(--text-color-dark);
    --button-bg: var(--button-color-dark);
    --pattern-color: var(--pattern-color-dark);
}

/* Base Styles */
body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: "Consolas", monospace;
    transition: background-color 0.3s, color 0.3s;
    min-height: 100vh;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40"><rect width="20" height="20" fill="%23FFFFFF" opacity="0.15"/><rect x="20" y="20" width="20" height="20" fill="%23FFFFFF" opacity="0.15"/></svg>');
    background-size: 80px 80px;
    overflow-x: hidden; /* Previene lo scroll orizzontale */
}

/* Header e Titolo */
header {
    width: 100%;
    text-align: center;
    padding: min(20px, 4vw) 0;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: min(20px, 4vw);
}

.container-title {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-title {
    font-family: "Press Start 2P", cursive;
    font-size: clamp(16px, 4vw, 28px);
    color: #ffffff;
    text-shadow: 2px 2px 0 #000000, 4px 4px 0 #000000;
    background-color: #000000;
    padding: clamp(6px, 2vw, 20px);
    border: 2px solid #ffffff;
    margin: 0;
    text-align: center;
    white-space: nowrap;
}

/* Game Container e Board */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: min(20px, 4vw);
    width: 100%;
    max-width: var(--board-size);
    margin: 0 auto;
    padding: min(20px, 4vw);
    box-sizing: border-box;
}

.game-board {
    width: var(--board-size);
    height: var(--board-size);
    aspect-ratio: 1;
    border: min(3px, 0.6vw) solid var(--text-color);
    background-color: #000000;
    background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%),
                      linear-gradient(-45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%),
                      linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.05) 75%),
                      linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.05) 75%);
    background-size: 40px 40px;
    background-position: 0 0, 0 20px, 20px -20px, -20px 0px;
    box-sizing: border-box;
}

/* Score e Reset */
.score-text {
    font-family: "Consolas", monospace;
    font-size: clamp(40px, 10vw, 100px);
    margin: min(20px, 4vw) 0;
    color: var(--text-color);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.reset-btn {
    font-family: "Consolas", monospace;
    font-size: clamp(18px, 4vw, 28px);
    padding: clamp(8px, 2vw, 15px) clamp(20px, 4vw, 30px);
    border: 1px solid var(--text-color);
    border-radius: 15px;
    cursor: pointer;
    background: var(--button-bg);
    color: var(--text-color);
    transition: transform 0.2s;
}

.reset-btn:hover {
    transform: translateY(-2px);
}

.reset-btn:active {
    transform: translateY(1px);
}

/* Touch Controls */
.controls {
    position: fixed;
    bottom: min(20px, 4vw);
    display: flex;
    flex-direction: column;
    gap: min(10px, 2vw);
    z-index: 100;
}

.left-controls {
    left: min(20px, 4vw);
}

.right-controls {
    right: min(20px, 4vw);
}

.touch-zone {
    width: clamp(35px, 8vw, 50px);
    height: clamp(60px, 15vw, 80px);
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid var(--text-color);
    border-radius: 10px;
    touch-action: none;
}

.touch-zone:active {
    background: rgba(255, 255, 255, 0.4);
}

/* Theme Toggle */
.theme-toggle {
    position: static;
    margin-top: min(10px, 2vw);
}

.switch {
    position: relative;
    display: inline-block;
    width: clamp(40px, 8vw, 60px);
    height: clamp(24px, 5vw, 34px);
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #2196F3;
    transition: 0.4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: calc(clamp(24px, 5vw, 34px) - 8px);
    width: calc(clamp(24px, 5vw, 34px) - 8px);
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

/* Switch Icons */
.switch .sun-icon,
.switch .moon-icon {
    position: absolute;
    width: min(18px, 3.6vw);
    height: min(18px, 3.6vw);
    top: 50%;
    transform: translateY(-50%);
    z-index: 1;
    fill: white;
}

.switch .sun-icon {
    left: min(8px, 1.6vw);
}

.switch .moon-icon {
    right: min(8px, 1.6vw);
    display: none;
}

input:checked + .slider {
    background-color: #192834;
}

input:checked + .slider:before {
    transform: translateX(calc(clamp(40px, 8vw, 60px) - clamp(24px, 5vw, 34px) + 4px));
}

input:checked ~ .sun-icon {
    display: none;
}

input:checked ~ .moon-icon {
    display: block;
}

/* Landscape Mode */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        flex-direction: row;
        justify-content: space-between;
        padding: min(10px, 2vw);
    }

    .theme-toggle {
        margin: 0 min(10px, 2vw) 0 0;
    }

    .game-container {
        margin: min(5px, 1vw) auto;
    }

    .score-text {
        font-size: clamp(30px, 8vw, 40px);
        margin: min(5px, 1vw) 0;
    }

    .controls {
        bottom: 50%;
        transform: translateY(50%);
    }
}