/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-color: #1a1a2e;
    --bg-secondary: #16213e;
    --primary-color: #4ade80;
    --secondary-color: #3b82f6;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --text-color: #ffffff;
    --text-muted: #9ca3af;
    --border-radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    overflow: hidden;
    touch-action: none;
    user-select: none;
}

/* Screens */
.screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.screen.active {
    display: flex;
}

/* Loading Screen */
#loading-screen {
    background: linear-gradient(135deg, var(--bg-color), var(--bg-secondary));
}

.loading-content {
    text-align: center;
}

.snake-logo {
    font-size: 80px;
    animation: bounce 1s infinite;
}

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

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--bg-secondary);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Menu Screen */
.menu-content {
    padding: 20px;
    width: 100%;
    max-width: 400px;
}

.menu-content h1 {
    text-align: center;
    font-size: 28px;
    margin-bottom: 30px;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 15px;
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: var(--border-radius);
    margin-bottom: 30px;
}

.avatar {
    width: 50px;
    height: 50px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.player-details {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.player-name {
    font-weight: bold;
    font-size: 16px;
}

.player-league {
    color: var(--text-muted);
    font-size: 14px;
}

.player-balance {
    font-size: 18px;
    font-weight: bold;
    color: var(--warning-color);
}

/* Buttons */
.btn {
    display: block;
    width: 100%;
    padding: 15px 25px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 10px;
}

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

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

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

.btn-danger {
    background: var(--danger-color);
    color: var(--text-color);
}

.btn-large {
    padding: 20px 30px;
    font-size: 18px;
}

/* Lobby Screen */
.lobby-content {
    padding: 20px;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.lobby-info {
    display: flex;
    justify-content: space-around;
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: var(--border-radius);
    margin: 20px 0;
}

.players-list {
    margin: 20px 0;
}

.player-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 8px;
}

.player-item .player-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
}

.tail-config {
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: var(--border-radius);
    margin: 20px 0;
}

.tail-slots {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 10px;
}

.tail-slot {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px dashed var(--text-muted);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.tail-slot.filled {
    border-style: solid;
    border-color: var(--primary-color);
}

/* Game Screen */
#game-screen {
    background: #0a0a0a;
}

.game-hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px 15px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
    z-index: 10;
}

.hud-left .timer {
    font-size: 24px;
    font-weight: bold;
    color: var(--warning-color);
}

.hud-center .score {
    font-size: 28px;
    font-weight: bold;
    color: var(--primary-color);
}

.mini-leaderboard {
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
}

.mini-leaderboard-item {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
}

.mini-leaderboard-item .color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

#game-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Mobile Controls */
.mobile-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    z-index: 20;
    opacity: 0.7;
}

.control-row {
    display: flex;
    gap: 60px;
}

.control-btn {
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    color: white;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.1s;
}

.control-btn:active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.95);
}

/* Results Screen */
.results-content {
    padding: 20px;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.results-content h2 {
    margin-bottom: 20px;
}

.results-list {
    margin: 20px 0;
}

.result-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 8px;
}

.result-item.winner {
    border: 2px solid var(--warning-color);
    background: rgba(245, 158, 11, 0.1);
}

.result-position {
    font-size: 24px;
    width: 40px;
}

.result-player {
    flex: 1;
    text-align: left;
}

.result-player .name {
    font-weight: bold;
}

.result-score {
    font-size: 20px;
    font-weight: bold;
    color: var(--primary-color);
}

.your-rewards {
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: var(--border-radius);
    margin: 20px 0;
}

.rewards-items {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 10px;
}

.reward-item {
    padding: 8px 12px;
    background: rgba(74, 222, 128, 0.2);
    border-radius: 8px;
    font-size: 18px;
}

/* Countdown Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.overlay.hidden {
    display: none;
}

.countdown-number {
    font-size: 120px;
    font-weight: bold;
    color: var(--primary-color);
    animation: countdownPulse 1s ease-in-out;
}

@keyframes countdownPulse {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

/* Responsive */
@media (max-width: 400px) {
    .menu-content h1 {
        font-size: 24px;
    }

    .control-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }

    .control-row {
        gap: 40px;
    }
}

/* Telegram Theme Integration */
body.tg-dark {
    --bg-color: var(--tg-theme-bg-color, #1a1a2e);
    --bg-secondary: var(--tg-theme-secondary-bg-color, #16213e);
    --text-color: var(--tg-theme-text-color, #ffffff);
}
