/* GRAVITON - Cosmic Design System */

:root {
    --bg: #050508;
    --bg-card: rgba(255,255,255,0.03);
    --bg-card-hover: rgba(255,255,255,0.06);
    --border: rgba(255,255,255,0.08);
    --text: #fff;
    --text-dim: rgba(255,255,255,0.5);
    --text-muted: rgba(255,255,255,0.3);
    --accent: #a855f7;
    --accent-glow: rgba(168,85,247,0.4);
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --font: 'Space Grotesk', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 40px;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* === STARFIELD === */
.starfield {
    position: fixed; inset: 0;
    pointer-events: none;
    z-index: 0;
    background: 
        radial-gradient(ellipse at 30% 20%, rgba(168,85,247,0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(59,130,246,0.06) 0%, transparent 50%),
        var(--bg);
}

.star {
    position: absolute;
    background: #fff;
    border-radius: 50%;
    animation: drift linear infinite;
}

.star.layer-0 { opacity: 0.4; }
.star.layer-1 { opacity: 0.6; }
.star.layer-2 { opacity: 0.9; box-shadow: 0 0 4px #fff; }

@keyframes drift {
    from { transform: translateY(0); }
    to { transform: translateY(100vh); }
}

/* === LAYOUT === */
main {
    position: relative;
    width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1;
    padding: var(--space-md);
}

/* === CANVAS === */
#gameCanvas {
    border-radius: var(--radius-lg);
    background: radial-gradient(ellipse at center, rgba(15,10,25,0.9) 0%, rgba(5,5,8,0.98) 100%);
    box-shadow: 0 0 0 1px var(--border), 0 0 80px rgba(168,85,247,0.1), inset 0 0 80px rgba(0,0,0,0.5);
    cursor: crosshair;
    max-width: 100%;
    max-height: 75vh;
    touch-action: none;
}

/* === HUD === */
#hud {
    position: absolute;
    top: var(--space-md);
    left: 50%;
    transform: translateX(-50%);
    display: none;
    z-index: 10;
}

#hud .hud-group {
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-sm);
    background: rgba(0,0,0,0.6);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    backdrop-filter: blur(12px);
}

.hud-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    min-width: 80px;
}

.hud-label {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.hud-val {
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.hud-val.chain { color: var(--success); }
.hud-val.time { color: var(--accent); }

/* === VOLUME === */
.volume-wrap {
    position: fixed;
    top: var(--space-md);
    left: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    z-index: 100;
}

#volume-icon { font-size: 16px; cursor: pointer; user-select: none; }

#volume-slider {
    width: 60px; height: 4px;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    cursor: pointer;
}

#volume-slider::-webkit-slider-thumb {
    appearance: none;
    width: 14px; height: 14px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--accent-glow);
}

#volume-slider::-moz-range-thumb {
    width: 14px; height: 14px;
    background: var(--accent);
    border-radius: 50%;
    border: none;
}

/* === SCREENS === */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(5,5,8,0.92);
    backdrop-filter: blur(20px);
    z-index: 50;
    padding: var(--space-md);
    overflow-y: auto;
}

.screen-content {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--space-lg);
    padding: var(--space-md) 0;
}

#start-screen { display: flex; }
#gameover-screen { display: none; }
#gameover-screen.visible { display: flex; }
#gameover-step2 { display: none; }

/* === LOGO === */
.logo-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
}

.logo {
    font-family: var(--font);
    font-size: clamp(36px, 10vw, 64px);
    font-weight: 700;
    letter-spacing: -1px;
    background: linear-gradient(135deg, #fff 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* === INFO GRID === */
.info-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    width: 100%;
}

.info-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm);
}

.info-card, .leaderboard-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
}

.info-card h2, .leaderboard-card h2 {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: var(--space-sm);
    text-align: center;
}

.info-card p {
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-dim);
    text-align: center;
}

.info-card em {
    color: var(--success);
    font-style: normal;
    font-weight: 600;
}

/* Controls */
.controls-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.controls-list li {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-dim);
}

.controls-list .key {
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 700;
    padding: 2px 6px;
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--accent);
}

.desktop-only { display: flex; }
.mobile-only { display: none; }

@media (hover: none) and (pointer: coarse) {
    .desktop-only { display: none; }
    .mobile-only { display: flex; }
}

/* === LEADERBOARDS === */
.leaderboards-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm);
    width: 100%;
}

.leaderboard-card h2 {
    text-align: center;
    margin-bottom: var(--space-sm);
}

#leaderboard-desktop,
#leaderboard-mobile {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 200px;
    overflow-y: auto;
}

@media (max-width: 480px) {
    .leaderboards-row {
        grid-template-columns: 1fr;
    }
}

.lb-entry {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 6px 10px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 12px;
}

.lb-entry.top-1 { background: rgba(255,215,0,0.1); }
.lb-entry.top-2 { background: rgba(192,192,192,0.08); }
.lb-entry.top-3 { background: rgba(205,127,50,0.08); }

.lb-rank {
    font-family: var(--font-mono);
    font-weight: 700;
    width: 20px;
    color: var(--text-muted);
    font-size: 11px;
}

.top-1 .lb-rank { color: #ffd700; }
.top-2 .lb-rank { color: #c0c0c0; }
.top-3 .lb-rank { color: #cd7f32; }

.lb-name {
    flex: 1;
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--text);
    letter-spacing: 1px;
    font-size: 11px;
}

.lb-device {
    font-size: 12px;
    opacity: 0.6;
}

.lb-score {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--accent);
    font-size: 11px;
}

.lb-empty {
    padding: var(--space-md);
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}

.loading {
    display: flex;
    justify-content: center;
    padding: var(--space-md);
}

.spinner {
    width: 18px; height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 1px;
    padding: var(--space-md) var(--space-xl);
    border-radius: var(--radius-full);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--accent-glow);
}

.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--bg-card-hover);
    color: var(--text);
}

.btn-row {
    display: flex;
    gap: var(--space-md);
}

/* === GAME OVER === */
.go-title {
    font-size: clamp(28px, 8vw, 48px);
    font-weight: 700;
    letter-spacing: -1px;
    color: var(--text);
}

.stats-row {
    display: flex;
    gap: var(--space-md);
    justify-content: center;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    min-width: 80px;
}

.stat-val {
    font-family: var(--font-mono);
    font-size: 26px;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Name Input */
.name-input {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
}

.name-input label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--text-muted);
}

#player-name {
    font-family: var(--font-mono);
    font-size: 32px;
    font-weight: 700;
    text-align: center;
    width: 160px;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 6px;
    outline: none;
    transition: all 0.2s;
}

#player-name:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

#player-name::placeholder {
    color: var(--text-muted);
}

#player-name.shake {
    animation: shake 0.4s ease;
    border-color: var(--danger);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

/* Rank */
.rank-reveal {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-lg) var(--space-xl);
    background: linear-gradient(135deg, rgba(168,85,247,0.15) 0%, rgba(59,130,246,0.1) 100%);
    border: 1px solid var(--accent);
    border-radius: var(--radius-lg);
}

.rank-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--text-dim);
}

.rank-num {
    font-family: var(--font-mono);
    font-size: 56px;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
}

.rank-score {
    font-size: 13px;
    color: var(--text-dim);
}

.rank-score b {
    color: var(--text);
}

/* === COMBO POPUP === */
.combo-popup {
    position: fixed;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    z-index: 100;
    animation: popUp 0.8s ease-out forwards;
    transform: translate(-50%, -50%);
}

.combo-multi {
    font-family: var(--font-mono);
    font-size: 32px;
    font-weight: 700;
    color: var(--success);
    text-shadow: 0 0 20px rgba(34,197,94,0.8);
}

.combo-points {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 600;
    color: var(--accent);
}

@keyframes popUp {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(0.5); }
    30% { transform: translate(-50%, -50%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -100%) scale(1); }
}

/* Mobile mode indicator */
.mobile-mode-indicator {
    display: none;
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 16px;
    border-radius: var(--radius-full);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 2px;
    pointer-events: none;
    z-index: 50;
}

.mobile-mode-indicator.attract {
    display: block;
    background: rgba(34,197,94,0.2);
    border: 1px solid var(--success);
    color: var(--success);
}

.mobile-mode-indicator.repel {
    display: block;
    background: rgba(239,68,68,0.2);
    border: 1px solid var(--danger);
    color: var(--danger);
}

/* === RESPONSIVE === */
@media (max-width: 480px) {
    .screen-content { gap: var(--space-md); }
    .info-row { grid-template-columns: 1fr; }
    .stats-row { gap: var(--space-sm); }
    .stat { min-width: 70px; padding: var(--space-sm); }
    .stat-val { font-size: 22px; }
    .hud-stat { min-width: 60px; padding: var(--space-xs) var(--space-sm); }
    .hud-val { font-size: 18px; }
    .volume-wrap { top: auto; bottom: var(--space-md); }
    .rank-num { font-size: 42px; }
    #player-name { font-size: 26px; width: 140px; }
}

@media (hover: none) {
    #gameCanvas { cursor: none; }
}

@media (hover: hover) {
    .mobile-mode-indicator { display: none !important; }
}