/* CSS Variables for theming */
:root {
    --bg-primary: #1a1a2e;
    --bg-board: #16213e;
    --grid-line: #0f3460;
    --snake-head: #00ff88;
    --snake-body: #00cc6a;
    --food: #ff6b6b;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent: #00ff88;
    --danger: #ff6b6b;
    --overlay-bg: rgba(26, 26, 46, 0.95);
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

/* Game Container */
.game-container {
    position: relative;
    width: 100%;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}

/* Screens */
.screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    animation: fadeIn 0.3s ease-in-out;
}

.screen.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Game Title */
.game-title {
    font-size: 48px;
    font-weight: bold;
    letter-spacing: 2px;
    margin-bottom: 40px;
    text-align: center;
}

/* Buttons */
.btn {
    padding: 12px 32px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 18px;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    outline: none;
    margin: 8px;
}

.btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

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

.btn-primary:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.4);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 2px solid var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-secondary:active {
    transform: scale(0.98);
}

.btn-icon {
    background: transparent;
    border: 2px solid var(--text-secondary);
    color: var(--text-primary);
    font-size: 24px;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 8px;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent);
    transform: scale(1.05);
}

.start-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Pause Button */
.btn-pause {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    transition: transform 0.2s;
}

.btn-pause:hover {
    transform: scale(1.1);
}

.btn-pause:focus {
    outline: 2px solid var(--accent);
    border-radius: 4px;
}

/* Controls Hint */
.controls-hint {
    margin-top: 40px;
    text-align: center;
}

.controls-divider {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 12px 0;
}

.controls-text {
    font-size: 16px;
    color: var(--text-secondary);
    margin: 8px 0;
}

.playing-controls {
    margin-top: 16px;
    font-size: 14px;
    color: var(--text-secondary);
    opacity: 1;
    transition: opacity 0.5s ease;
}

.playing-controls.fade-out {
    opacity: 0;
}

/* High Score Display */
.high-score-display {
    margin-top: 24px;
    font-size: 18px;
    color: var(--text-secondary);
}

/* Score Bar */
.score-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 400px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--bg-board);
    border-radius: 8px;
}

.score-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.score-label {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 600;
}

.score-value {
    font-size: 24px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: var(--accent);
    min-width: 60px;
}

.score-value.animate {
    animation: scorePulse 0.3s ease;
}

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

/* Game Board */
.game-board-container {
    border: 2px solid var(--grid-line);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

#game-board {
    display: block;
    background: var(--bg-board);
}

/* Overlays */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: fadeIn 0.3s ease-in-out;
}

.overlay.hidden {
    display: none;
}

/* Modal */
.modal {
    background: var(--bg-board);
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
    animation: modalSlideIn 0.3s ease-out;
    max-width: 320px;
    width: 90%;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-title {
    font-size: 36px;
    font-weight: bold;
    margin-bottom: 24px;
    letter-spacing: 2px;
}

.gameover-title {
    color: var(--danger);
}

.score-display {
    margin-bottom: 24px;
}

.final-score {
    font-size: 24px;
    margin: 12px 0;
}

.best-score {
    font-size: 18px;
    color: var(--text-secondary);
    margin: 8px 0;
}

.new-record {
    font-size: 20px;
    color: var(--accent);
    font-weight: bold;
    margin-top: 12px;
    animation: pulse 1s ease-in-out infinite;
}

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

.hidden {
    display: none !important;
}

/* ==========================================
   SETTINGS SCREEN STYLES
   ========================================== */

.settings-header {
    display: flex;
    align-items: center;
    width: 100%;
    margin-bottom: 24px;
    gap: 12px;
}

.btn-back {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 28px;
    cursor: pointer;
    padding: 8px;
    transition: all 0.2s ease;
}

.btn-back:hover {
    color: var(--accent);
    transform: translateX(-3px);
}

.btn-back:focus {
    outline: 2px solid var(--accent);
    border-radius: 4px;
}

.settings-title {
    font-size: 28px;
    font-weight: bold;
    letter-spacing: 1px;
}

.settings-content {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.setting-group {
    background: var(--bg-board);
    border-radius: 12px;
    padding: 16px;
}

.setting-label {
    display: block;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

/* Radio Options */
.setting-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.speed-options,
.grid-options,
.sensitivity-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.sensitivity-options {
    grid-template-columns: repeat(3, 1fr);
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.radio-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

.radio-option:has(input:checked) {
    border-color: var(--accent);
    background: rgba(0, 255, 136, 0.1);
}

.radio-option input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.radio-option input[type="radio"]:checked {
    border-color: var(--accent);
    background: var(--accent);
    box-shadow: inset 0 0 0 3px var(--bg-board);
}

.radio-option input[type="radio"]:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.radio-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.radio-hint {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: auto;
}

/* Color Options */
.color-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.color-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.color-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

.color-option:has(input:checked) {
    border-color: var(--accent);
    background: rgba(0, 255, 136, 0.1);
}

.color-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: all 0.2s ease;
}

.color-option:hover .color-swatch,
.color-option:has(input:checked) .color-swatch {
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.color-label {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Toggle Switch */
.setting-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.toggle-hint {
    font-size: 13px;
    color: var(--text-secondary);
    flex: 1;
}

.toggle-switch {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.toggle-switch input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.toggle-slider {
    position: relative;
    width: 50px;
    height: 26px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 26px;
    transition: all 0.3s ease;
    border: 2px solid var(--text-secondary);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: all 0.3s ease;
}

.toggle-switch input:checked + .toggle-slider {
    background: rgba(0, 255, 136, 0.3);
    border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(24px);
    background: var(--accent);
}

.toggle-switch input:focus + .toggle-slider {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.toggle-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 30px;
    text-align: center;
}

.toggle-switch input:checked ~ .toggle-label {
    color: var(--accent);
}

/* Settings Footer */
.settings-footer {
    margin-top: 24px;
    text-align: center;
}

.settings-note {
    font-size: 12px;
    color: var(--text-secondary);
    opacity: 0.7;
}

/* ==========================================
   END SETTINGS SCREEN STYLES
   ========================================== */

/* Responsive Design */
@media (max-width: 480px) {
    .game-container {
        padding: 16px;
    }
    
    .game-title {
        font-size: 36px;
        margin-bottom: 30px;
    }
    
    .btn {
        padding: 10px 24px;
        font-size: 16px;
    }
    
    .game-board-container {
        width: calc(100vw - 32px);
        max-width: 400px;
    }
    
    #game-board {
        width: 100%;
        height: auto;
        aspect-ratio: 1;
    }
    
    .score-bar {
        padding: 10px 12px;
    }
    
    .score-value {
        font-size: 20px;
        min-width: 50px;
    }
    
    .modal {
        padding: 30px 24px;
    }
    
    .modal-title {
        font-size: 28px;
    }
    
    /* Settings responsive */
    .settings-title {
        font-size: 24px;
    }
    
    .speed-options,
    .grid-options {
        grid-template-columns: 1fr 1fr;
    }
    
    .color-options {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .radio-option {
        padding: 8px 10px;
    }
    
    .radio-label {
        font-size: 13px;
    }
    
    .radio-hint {
        display: none;
    }
}

/* Accessibility: Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Virtual Joystick Controls */
.touch-controls {
    display: none;
    margin-top: 20px;
    justify-content: center;
    align-items: center;
}

.joystick-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.joystick-base {
    width: 140px;
    height: 140px;
    background: radial-gradient(circle, var(--bg-board) 0%, rgba(22, 33, 62, 0.8) 100%);
    border: 2px solid var(--accent);
    border-radius: 50%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 
        0 0 20px rgba(0, 255, 136, 0.2),
        inset 0 0 30px rgba(0, 0, 0, 0.3);
    opacity: 0.9;
    transition: opacity 0.2s ease, box-shadow 0.2s ease;
}

.joystick-base.active {
    opacity: 1;
    box-shadow: 
        0 0 30px rgba(0, 255, 136, 0.4),
        inset 0 0 30px rgba(0, 0, 0, 0.3);
}

.joystick-base::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 1px dashed rgba(0, 255, 136, 0.3);
}

.joystick-thumb {
    width: 56px;
    height: 56px;
    background: radial-gradient(circle, var(--accent) 0%, #00cc6a 100%);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 
        0 4px 15px rgba(0, 0, 0, 0.4),
        0 0 10px rgba(0, 255, 136, 0.3);
    transition: box-shadow 0.15s ease;
    pointer-events: none;
}

.joystick-thumb.active {
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(0, 255, 136, 0.5);
    transform: translate(-50%, -50%) scale(1.05);
}

/* Direction indicator arrows */
.joystick-direction {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.joystick-direction.active {
    opacity: 1;
}

.joystick-direction::before,
.joystick-direction::after {
    content: '';
    position: absolute;
    background: var(--accent);
    border-radius: 2px;
    transition: all 0.15s ease;
}

/* Up arrow */
.joystick-direction.dir-up::before {
    width: 4px;
    height: 20px;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
}

.joystick-direction.dir-up::after {
    width: 12px;
    height: 12px;
    top: 8px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    background: transparent;
    border-left: 3px solid var(--accent);
    border-top: 3px solid var(--accent);
    margin-left: -6px;
}

/* Down arrow */
.joystick-direction.dir-down::before {
    width: 4px;
    height: 20px;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
}

.joystick-direction.dir-down::after {
    width: 12px;
    height: 12px;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%) rotate(225deg);
    background: transparent;
    border-left: 3px solid var(--accent);
    border-top: 3px solid var(--accent);
    margin-left: -6px;
    margin-bottom: -6px;
}

/* Left arrow */
.joystick-direction.dir-left::before {
    width: 20px;
    height: 4px;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
}

.joystick-direction.dir-left::after {
    width: 12px;
    height: 12px;
    left: 8px;
    top: 50%;
    transform: translateY(-50%) rotate(-45deg);
    background: transparent;
    border-left: 3px solid var(--accent);
    border-bottom: 3px solid var(--accent);
    margin-top: -6px;
}

/* Right arrow */
.joystick-direction.dir-right::before {
    width: 20px;
    height: 4px;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
}

.joystick-direction.dir-right::after {
    width: 12px;
    height: 12px;
    right: 8px;
    top: 50%;
    transform: translateY(-50%) rotate(135deg);
    background: transparent;
    border-left: 3px solid var(--accent);
    border-bottom: 3px solid var(--accent);
    margin-top: -6px;
    margin-right: -6px;
}

.setting-note {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
    text-align: center;
}

/* Hide joystick settings on non-touch devices */
@media (hover: hover) and (pointer: fine) {
    .joystick-setting {
        display: none;
    }
}

/* Direction indicators on joystick base */
.joystick-base::after {
    content: '↑↓←→';
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    color: rgba(0, 255, 136, 0.25);
    letter-spacing: 2px;
    pointer-events: none;
}

.touch-pause-btn {
    display: none;
    margin-top: 16px;
    padding: 12px 32px;
    background: transparent;
    border: 2px solid var(--text-secondary);
    color: var(--text-primary);
    font-size: 16px;
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.touch-pause-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

/* Show touch controls on touch devices */
@media (hover: none) and (pointer: coarse) {
    .touch-controls {
        display: flex;
    }
    
    .touch-pause-btn {
        display: block;
    }
    
    .playing-controls {
        display: none;
    }
    
    .btn-pause {
        display: none;
    }
}

/* Mobile joystick responsive */
@media (max-width: 480px) and (hover: none) {
    .joystick-base {
        width: 120px;
        height: 120px;
    }
    
    .joystick-thumb {
        width: 48px;
        height: 48px;
    }
}
