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

:root {
    --green: #00d4aa;
    --green-bright: #40ffcc;
    --blue: #4a9eff;
    --blue-bright: #7ab8ff;
    --bg-dark: #0f0f1a;
    --bg-mid: #1a1a2e;
    --bg-light: #2a2a3e;
    --food: #ff4757;
}

body {
    font-family: 'Fira Code', monospace;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-mid) 50%, #16213e 100%);
    min-height: 100vh;
    color: #fff;
    overflow-x: hidden;
}

#game-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    padding: 10px;
}

#header {
    padding: 15px 20px;
    background: rgba(26, 26, 46, 0.95);
    border-radius: 16px;
    margin-bottom: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
}

.title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.4rem;
    font-weight: 900;
    text-align: center;
    background: linear-gradient(90deg, var(--green), var(--blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 2px;
    letter-spacing: 1px;
}

.subtitle {
    text-align: center;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 3px;
    margin-bottom: 15px;
}

.score-panel {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

.snake-score {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.snake-avatar {
    font-size: 1.8rem;
    filter: drop-shadow(0 0 8px currentColor);
}

.score-info {
    display: flex;
    flex-direction: column;
}

.score-info.right {
    text-align: right;
}

.snake-score .label {
    font-size: 0.6rem;
    letter-spacing: 2px;
    opacity: 0.7;
}

.snake-a .label { color: var(--green); }
.snake-b .label { color: var(--blue); }

.snake-score .score {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    font-weight: 900;
    line-height: 1;
}

.snake-a .score {
    color: var(--green);
    text-shadow: 0 0 20px rgba(0, 212, 170, 0.6);
}

.snake-b .score {
    color: var(--blue);
    text-shadow: 0 0 20px rgba(74, 158, 255, 0.6);
}

.score-pop {
    animation: scorePop 0.3s ease;
}

@keyframes scorePop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.leader-indicator {
    min-width: 50px;
    text-align: center;
}

.vs-text {
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.3);
}

.crown {
    font-size: 1.6rem;
    animation: crownBounce 1s ease infinite;
}

.crown.green { filter: drop-shadow(0 0 10px var(--green)); }
.crown.blue { filter: drop-shadow(0 0 10px var(--blue)); }

@keyframes crownBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

#main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    min-height: 350px;
    padding: 10px;
}

#canvas {
    border-radius: 12px;
    box-shadow: 
        0 0 40px rgba(0, 212, 170, 0.15),
        0 0 40px rgba(74, 158, 255, 0.15),
        inset 0 0 60px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

#game-over {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(10, 10, 20, 0.92);
    border-radius: 12px;
    z-index: 10;
    animation: fadeIn 0.4s ease;
}

#game-over.hidden {
    display: none;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.game-over-content {
    text-align: center;
    padding: 30px;
}

.trophy {
    font-size: 4rem;
    animation: trophySpin 2s ease infinite;
}

@keyframes trophySpin {
    0%, 100% { transform: rotate(-5deg) scale(1); }
    50% { transform: rotate(5deg) scale(1.1); }
}

.game-over-content h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.8rem;
    margin: 15px 0;
    animation: pulse 1.5s ease infinite;
}

.game-over-content h2.green-win { color: var(--green); text-shadow: 0 0 30px rgba(0, 212, 170, 0.5); }
.game-over-content h2.blue-win { color: var(--blue); text-shadow: 0 0 30px rgba(74, 158, 255, 0.5); }
.game-over-content h2.tie { color: #fff; }

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

.game-over-content p {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 20px;
}

.hint {
    font-size: 0.7rem !important;
    color: rgba(255, 255, 255, 0.4) !important;
    margin-top: 10px !important;
}

#controls {
    padding: 15px;
    background: rgba(26, 26, 46, 0.95);
    border-radius: 16px;
    margin-top: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    align-items: flex-start;
    backdrop-filter: blur(10px);
}

.control-section {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.primary-controls {
    flex-direction: row;
}

.settings {
    align-items: center;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
}

.control-group label {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 2px;
}

.primary-btn, .secondary-btn, #restart-btn {
    padding: 12px 28px;
    border: none;
    border-radius: 10px;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.25s ease;
    letter-spacing: 1px;
}

.primary-btn {
    background: linear-gradient(135deg, var(--green), #00a882);
    color: var(--bg-dark);
    box-shadow: 0 4px 20px rgba(0, 212, 170, 0.4);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(0, 212, 170, 0.6);
}

.primary-btn.paused {
    background: linear-gradient(135deg, #ff8c42, #ff6b35);
    box-shadow: 0 4px 20px rgba(255, 107, 53, 0.4);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

#restart-btn {
    background: linear-gradient(135deg, var(--blue), #3a7ecc);
    color: #fff;
    box-shadow: 0 4px 20px rgba(74, 158, 255, 0.4);
}

#restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(74, 158, 255, 0.6);
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

input[type="range"] {
    width: 80px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: linear-gradient(135deg, var(--green), var(--blue));
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 212, 170, 0.4);
    transition: transform 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

#speed-label {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.6);
    min-width: 40px;
}

select {
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: #fff;
    font-family: 'Fira Code', monospace;
    font-size: 0.8rem;
    cursor: pointer;
}

select option {
    background: var(--bg-mid);
    color: #fff;
}

.toggle-group {
    flex-direction: row;
}

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

.toggle-container input {
    display: none;
}

.toggle-slider {
    width: 40px;
    height: 22px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 11px;
    position: relative;
    transition: background 0.3s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
}

.toggle-container input:checked + .toggle-slider {
    background: linear-gradient(90deg, var(--green), var(--blue));
}

.toggle-container input:checked + .toggle-slider::after {
    transform: translateX(18px);
}

.toggle-label {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
}

.stats-panel {
    background: rgba(0, 0, 0, 0.25);
    padding: 15px 20px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.stats-panel h3 {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 12px;
    letter-spacing: 2px;
    text-align: center;
}

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

.stat-item {
    text-align: center;
}

.stat-value {
    display: block;
    font-family: 'Orbitron', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
}

.stat-item.green .stat-value { color: var(--green); }
.stat-item.blue .stat-value { color: var(--blue); }

.stat-label {
    font-size: 0.55rem;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 1px;
}

.algo-info {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: rgba(74, 158, 255, 0.08);
    padding: 12px 15px;
    border-radius: 10px;
    border: 1px solid rgba(74, 158, 255, 0.15);
    max-width: 280px;
}

.algo-icon {
    font-size: 1.4rem;
}

.algo-info p {
    font-size: 0.65rem;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.6);
}

#footer {
    text-align: center;
    padding: 15px;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

#footer a {
    color: var(--green);
    text-decoration: none;
    transition: color 0.2s ease;
    font-weight: 600;
}

#footer a:hover {
    color: var(--green-bright);
}

.celebration {
    background: linear-gradient(90deg, var(--green), var(--blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 600;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    #game-container {
        padding: 8px;
    }
    
    #header {
        padding: 12px 15px;
    }
    
    .title {
        font-size: 1rem;
    }
    
    .subtitle {
        font-size: 0.55rem;
        margin-bottom: 10px;
    }
    
    .score-panel {
        gap: 10px;
    }
    
    .snake-score {
        padding: 6px 10px;
        gap: 8px;
    }
    
    .snake-avatar {
        font-size: 1.3rem;
    }
    
    .snake-score .score {
        font-size: 1.5rem;
    }
    
    .snake-score .label {
        font-size: 0.5rem;
    }
    
    #controls {
        padding: 12px;
        gap: 12px;
    }
    
    .primary-btn, .secondary-btn {
        padding: 10px 20px;
        font-size: 0.75rem;
    }
    
    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .algo-info {
        display: none;
    }
    
    .game-over-content h2 {
        font-size: 1.4rem;
    }
    
    .trophy {
        font-size: 3rem;
    }
}

@media (max-width: 400px) {
    .snake-score .label {
        display: none;
    }
    
    .stats-panel {
        width: 100%;
    }
    
    .settings {
        width: 100%;
        justify-content: space-around;
    }
}