html, body {
    height: 100vh;
    overflow: hidden;
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text);
}

header {
    margin-bottom: 0 !important;
}

.app-body {
    flex: 1 !important;
    min-height: 0 !important;
}

main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    align-items: center;
    justify-content: center;
}

.container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: 1rem;
    box-sizing: border-box;
}

/* Snake Game Layout */
.snake-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 90%;
    margin: 0 auto;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    gap: 1rem;
    animation: fadeIn 0.5s ease-out;
}

.score-board {
    display: flex;
    justify-content: space-between;
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 0.75rem 1.25rem;
    box-sizing: border-box;
    flex-shrink: 0;
    margin-bottom: 0;
}

.score-stat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-weight: 700;
}

.score-stat .label {
    opacity: 0.6;
    font-size: 0.8rem;
}

.score-stat .value {
    font-size: 1.25rem;
    color: var(--primary);
    text-shadow: 0 0 8px var(--primary);
}

.board-relative-wrapper {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.1);
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    box-sizing: border-box;
}

.game-grid {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    transition: all 0.3s ease;
}

@media (max-width: 768px) {
    .app-body {
        padding: 0.75rem !important;
    }
    .mobile-dpad {
        margin-top: 0.5rem !important;
    }
}

.grid-row {
    display: flex;
    flex: 1;
}

.grid-cell {
    flex: 1;
    height: 100%;
    border: 1px solid rgba(255, 255, 255, 0.02);
    transition: background-color 0.05s ease;
}

/* Game Entities */
.snake-head {
    background-color: var(--primary);
    border-radius: 4px;
    box-shadow: 0 0 10px var(--primary);
    position: relative;
}

.snake-body {
    background-color: var(--primary);
    opacity: 0.8;
    border-radius: 3px;
}

.food {
    background-color: #ef4444;
    border-radius: 50%;
    box-shadow: 0 0 12px #ef4444;
    animation: pulse 1s infinite alternate;
}

.gold-food {
    background-color: #ffd700 !important;
    box-shadow: 0 0 18px #ffd700, 0 0 8px #ffd700 !important;
    animation: goldPulse 0.5s infinite alternate !important;
}

@keyframes goldPulse {
    from {
        transform: scale(0.9);
        box-shadow: 0 0 8px #ffd700;
    }
    to {
        transform: scale(1.15);
        box-shadow: 0 0 22px #ffd700;
    }
}

.gold-timer-container {
    height: 4px;
    width: 100%;
    background: rgba(0, 0, 0, 0.4);
    position: absolute;
    top: 0;
    left: 0;
    z-index: 5;
    border-radius: 4px 4px 0 0;
    overflow: hidden;
}

.gold-timer-bar {
    height: 100%;
    background: linear-gradient(90deg, #ffd700, #ff8c00);
    width: 100%;
    animation: shrinkBar 5s linear forwards;
    box-shadow: 0 0 8px #ffd700;
}

@keyframes shrinkBar {
    from { width: 100%; }
    to { width: 0%; }
}

/* Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    padding: 2rem;
    text-align: center;
    box-sizing: border-box;
}

.overlay h2 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: 0.2rem;
    margin: 0 0 1.5rem 0;
    color: #fff;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.gameover-overlay h2 {
    color: #ef4444;
    text-shadow: 0 0 15px rgba(239, 68, 68, 0.5);
}

.score-summary {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    opacity: 0.9;
}

/* Buttons and Inputs */
button.btn-start, button.btn-restart, button.btn-resume, button.btn-submit {
    background-color: var(--primary);
    color: #fff;
    border: none;
    padding: 0.75rem 2rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 14px 0 rgba(0, 0, 0, 0.4);
    transition: all 0.2s ease;
    font-family: 'JetBrains Mono', monospace;
}

button.btn-start:hover, button.btn-restart:hover, button.btn-resume:hover, button.btn-submit:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px 0 rgba(0, 0, 0, 0.5), 0 0 10px var(--primary);
}

button.btn-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.submit-score-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 250px;
    margin-bottom: 1.5rem;
}

.name-input {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 1rem;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

.name-input:focus {
    border-color: var(--primary);
}

/* Leaderboard Sidebar */
.leaderboard-panel {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 0.75rem 1.5rem;
    box-sizing: border-box;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .leaderboard-panel {
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.75rem;
    }
}

.leaderboard-panel h3 {
    margin: 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    letter-spacing: 0.1rem;
    opacity: 0.8;
    text-align: left;
    flex-shrink: 0;
}

.leaderboard-list {
    display: flex;
    flex-direction: row;
    gap: 1.5rem;
    flex: 1;
    justify-content: flex-end;
    align-items: center;
}

@media (max-width: 768px) {
    .leaderboard-list {
        justify-content: center;
        width: 100%;
    }
}

.leaderboard-ol {
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: row;
    gap: 1.5rem;
    list-style: none;
}

@media (max-width: 768px) {
    .leaderboard-ol {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
        width: 100%;
    }
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    font-family: 'JetBrains Mono', monospace;
}

@media (max-width: 768px) {
    .leaderboard-item {
        width: 100%;
        justify-content: space-between;
    }
}

.leaderboard-item .leader-name {
    font-weight: 500;
}

.leaderboard-item .leader-score {
    color: var(--primary);
    font-weight: 700;
}

.leaderboard-empty {
    text-align: center;
    opacity: 0.5;
    font-size: 0.9rem;
    padding: 0.25rem 0;
    width: 100%;
}

/* On-screen controls */
.mobile-dpad {
    display: none;
    flex-direction: column;
    align-items: center;
    margin-top: 1.5rem;
}

@media (max-width: 1024px) {
    .mobile-dpad {
        display: flex;
    }
}

.dpad-row {
    display: flex;
    justify-content: center;
}

.dpad-row.middle {
    gap: 2.5rem;
    margin: 0.5rem 0;
}

.dpad-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    user-select: none;
    transition: background 0.1s;
}

.dpad-btn:active {
    background: var(--primary);
}

.dpad-center {
    width: 50px;
    height: 50px;
}

/* Keyframe animations */
@keyframes pulse {
    from {
        transform: scale(0.9);
        box-shadow: 0 0 8px #ef4444;
    }
    to {
        transform: scale(1.1);
        box-shadow: 0 0 16px #ef4444;
    }
}

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