/* CSS Variables */
:root {
    --bg-primary: #000000;
    --bg-secondary: #111111;
    --bg-card: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #888888;
    --accent: #3b82f6;
    --danger: #ef4444;
    --success: #22c55e;
    --ball: #ff4444;
}

/* Base */
* {
    box-sizing: border-box;
}

body {
    font-family:
        system-ui,
        -apple-system,
        sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* Utility Classes */
.text-secondary {
    color: var(--text-secondary);
}
.text-accent {
    color: var(--accent);
}
.text-danger {
    color: var(--danger);
}
.text-success {
    color: var(--success);
}
.bg-secondary {
    background: var(--bg-secondary);
}
.bg-card {
    background: var(--bg-card);
}

/* Components */
.card {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid #2a2a2a;
}

.btn {
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    outline: none;
}

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

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

.btn-primary:hover:not(:disabled) {
    background: #2563eb;
}

.btn-secondary {
    background: #333;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #444;
}

.btn-lg {
    padding: 16px 32px;
    font-size: 1.125rem;
}

.input {
    background: #222;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 12px 16px;
    color: white;
    outline: none;
    transition: border-color 0.2s;
}

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

.input::placeholder {
    color: #666;
}

.domain-suffix {
    background: #222;
    border: 1px solid #333;
    border-left: none;
    border-radius: 0 8px 8px 0;
    padding: 0 10px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    align-self: stretch;
}

.input-with-suffix {
    display: flex;
    border-radius: 8px;
}

.input-with-suffix .input {
    border-color: transparent;
    background: #222;
}

.input-with-suffix .input:focus {
    border-color: transparent;
}

.input-with-suffix .domain-suffix {
    border-color: transparent;
}

.input-with-suffix {
    background: #222;
    border: 1px solid #333;
    transition: border-color 0.2s;
}

.input-with-suffix:focus-within {
    border-color: var(--accent);
}

/* Navigation */
.nav-btn {
    display: block;
    width: 100%;
    padding: 12px 16px;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-btn:hover {
    background: #222;
    color: white;
}

.nav-btn.active {
    background: var(--accent);
    color: white;
}

/* Screens */
.screen {
    display: none;
    position: fixed;
    inset: 0;
}

.screen.active {
    display: block;
}

/* Panels */
.panel {
    display: none;
}

.panel.active {
    display: block;
}

/* Leaderboard */
.leaderboard-tab {
    padding: 8px 16px;
    background: #222;
    border: none;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.leaderboard-tab:hover {
    background: #333;
    color: white;
}

.leaderboard-tab.active {
    background: var(--accent);
    color: white;
}

/* Auth tabs */
.auth-tab {
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    background: transparent;
    border-left: none;
    border-right: none;
    border-top: none;
    cursor: pointer;
}

.auth-tab:hover {
    color: var(--text-primary);
}

.auth-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.leaderboard-row {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
}

.leaderboard-row:hover {
    background: #222;
    cursor: pointer;
}

.leaderboard-rank {
    width: 32px;
    text-align: center;
    font-weight: bold;
    color: var(--text-secondary);
}

.leaderboard-rank.gold {
    color: #ffd700;
}
.leaderboard-rank.silver {
    color: #c0c0c0;
}
.leaderboard-rank.bronze {
    color: #cd7f32;
}

/* Chat */
.chat-message {
    display: flex;
    gap: 8px;
    font-size: 0.875rem;
}

.chat-avatar {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 6px;
}

.chat-username {
    font-weight: 600;
    cursor: pointer;
}

.chat-username:hover {
    text-decoration: underline;
}

.chat-content {
    color: var(--text-secondary);
    word-break: break-word;
}

.chat-time {
    color: #555;
    font-size: 0.75rem;
}

/* Game Canvas */
.game-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--bg-primary);
}

#game-canvas {
    border: 2px solid #333;
    border-radius: 8px;
    background: #0a0a0a;
}

/* Game HUD */
.game-hud {
    position: absolute;
    inset: 0;
    pointer-events: none;
    padding: 20px;
}

.hud-top-left {
    position: absolute;
    top: 20px;
    left: 20px;
}

.hud-top-center {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.25rem;
}

.hud-top-right {
    position: absolute;
    top: 8px;
    right: 20px;
}

.hud-bottom-center {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
}

/* Game Overlays */
.game-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10;
}

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

@keyframes countdown-pulse {
    0% {
        transform: scale(1.5);
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Screen Shake Animation */
@keyframes shake {
    0%,
    100% {
        transform: translateX(0);
    }
    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-5px);
    }
    20%,
    40%,
    60%,
    80% {
        transform: translateX(5px);
    }
}

.shake {
    animation: shake 0.25s ease-in-out;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
}

.modal-content {
    position: relative;
    z-index: 1;
}

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    background: var(--bg-card);
    border: 1px solid #333;
    animation: toast-in 0.3s ease-out;
    max-width: 300px;
}

.toast.info {
    border-color: var(--accent);
}

.toast.success {
    border-color: var(--success);
}

.toast.error {
    border-color: var(--danger);
}

@keyframes toast-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toast-out {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.toast.removing {
    animation: toast-out 0.3s ease-out forwards;
}

/* Player List Item */
.player-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #222;
    border-radius: 8px;
}

.player-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.player-name {
    flex: 1;
}

/* Ready Players */
.ready-player {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #1a1a1a;
    border-radius: 6px;
}

.ready-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #444;
}

/* Live game preview */
.preview-canvas-container {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: #0a0a0a;
}

#preview-canvas {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 8px;
}

.live-dot {
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    animation: live-pulse 1.5s ease-in-out infinite;
}

@keyframes live-pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Spectate mode overlay controls */
.spectate-controls {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    z-index: 50;
    background: rgba(0, 0, 0, 0.8);
    padding: 12px 20px;
    border-radius: 12px;
    border: 1px solid #333;
}

/* HUD Scores */
#hud-scores {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.75rem;
}

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

.hud-score-medal {
    width: 16px;
    font-weight: bold;
    text-align: center;
}

.hud-score-medal.gold {
    color: #ffd700;
}

.hud-score-medal.silver {
    color: #c0c0c0;
}

.hud-score-medal.bronze {
    color: #cd7f32;
}

.hud-score-name {
    color: var(--text-primary);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hud-score-value {
    font-weight: bold;
    min-width: 16px;
    text-align: right;
    margin-left: auto;
}

/* Tiebreaker styling */
#hud-round.tiebreaker {
    font-size: 1.25rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 4px;
    background: linear-gradient(90deg, #f59e0b, #ef4444, #f59e0b);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: tiebreaker-glow 2s linear infinite;
    text-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
}

@keyframes tiebreaker-glow {
    0% { background-position: 0% center; }
    100% { background-position: 200% center; }
}

/* Round scores in overlay */
.round-scores {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 300px;
    margin: 0 auto;
}

.round-score-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

.round-score-row.winner {
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid var(--accent);
}

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

.round-score-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.round-score-value {
    font-weight: bold;
    font-size: 1.25rem;
}

/* Responsive */
@media (max-width: 1024px) {
    #chat-panel {
        display: none;
    }
}

@media (max-width: 768px) {
    .game-container {
        padding: 10px;
    }

    #game-canvas {
        max-width: 100%;
        height: auto;
    }
}

/* Color Picker */
.color-picker-popup {
    background: var(--bg-card);
    border: 1px solid #333;
    border-radius: 12px;
    padding: 12px;
    z-index: 150;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.color-option {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.color-option:hover {
    transform: scale(1.15);
    border-color: white;
}

.color-option.active {
    border-color: white;
    box-shadow: 0 0 0 2px var(--accent);
}
