:root {
    --primary: #4a90e2;
    --secondary: #7b68ee;
    --accent: #ff6b6b;
    --bg-1: #0f0f1a;
    --bg-2: #1a1a2e;
    --surface: rgba(255,255,255,0.06);
    --surface-border: rgba(255,255,255,0.08);
    --text: #e8e8f0;
    --text-muted: #8888aa;
    --bubble-size: 58px;
    --gap: 7px;
    --gold: #ffd700;
}

.light-mode {
    --bg-1: #e8edf2;
    --bg-2: #f5f7fa;
    --surface: rgba(0,0,0,0.04);
    --surface-border: rgba(0,0,0,0.08);
    --text: #1a202c;
    --text-muted: #718096;
    --primary: #3182ce;
    --secondary: #805ad5;
}

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

html, body, #root {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'DM Sans', sans-serif;
    background: linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 50%, var(--bg-1) 100%);
    color: var(--text);
    transition: background 0.5s ease, color 0.4s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Header */
.header-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--surface-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 0.5rem 1rem;
    transition: background 0.4s, border-color 0.4s;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.app-title {
    font-family: 'Space Mono', monospace;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.stats-row {
    display: flex;
    gap: 0.5rem;
}

.stat-pill {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 12px;
    padding: 0.25rem 0.65rem;
    text-align: center;
    min-width: 60px;
    transition: transform 0.2s, background 0.3s;
}

.stat-pill.pulse {
    animation: statPulse 0.3s ease;
}

@keyframes statPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

.stat-value {
    font-family: 'Space Mono', monospace;
    font-size: 1.05rem;
    font-weight: 700;
    display: block;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.58rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    display: block;
}

.controls-row {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.ctrl-btn {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    color: var(--text);
    border-radius: 10px;
    padding: 0.35rem 0.65rem;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.ctrl-btn:hover {
    background: rgba(74, 144, 226, 0.15);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.ctrl-btn:active {
    transform: translateY(0) scale(0.97);
}

.ctrl-btn.mp-btn {
    background: rgba(123, 104, 238, 0.15);
    border-color: var(--secondary);
}

.ctrl-btn.mp-btn:hover {
    background: rgba(123, 104, 238, 0.25);
}

.ctrl-btn.mp-active {
    background: rgba(123, 104, 238, 0.3);
    border-color: var(--secondary);
    box-shadow: 0 0 12px rgba(123, 104, 238, 0.3);
}

/* Bubble Grid */
.bubble-grid-wrapper {
    padding-top: 80px;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.bubble-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    gap: var(--gap);
    padding: 1rem;
    max-width: 1200px;
    transition: opacity 0.3s;
}

/* Bubble */
.bubble {
    width: var(--bubble-size);
    height: var(--bubble-size);
    border-radius: 50%;
    cursor: pointer;
    position: relative;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.3s ease;
    flex-shrink: 0;
}

.bubble-inner {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
}

/* Unpopped bubble */
.bubble.unpopped .bubble-inner {
    background: radial-gradient(ellipse at 35% 30%, rgba(180, 200, 255, 0.4) 0%, rgba(100, 140, 220, 0.15) 40%, rgba(60, 80, 160, 0.1) 100%);
    box-shadow:
        inset 0 -3px 6px rgba(0,0,0,0.1),
        inset 0 2px 4px rgba(255,255,255,0.2),
        0 2px 8px rgba(74, 144, 226, 0.15),
        0 0 0 1px rgba(255,255,255,0.08);
}

.light-mode .bubble.unpopped .bubble-inner {
    background: radial-gradient(ellipse at 35% 30%, rgba(255, 255, 255, 0.8) 0%, rgba(200, 220, 255, 0.4) 40%, rgba(180, 200, 240, 0.25) 100%);
    box-shadow:
        inset 0 -3px 6px rgba(0,0,0,0.06),
        inset 0 2px 4px rgba(255,255,255,0.6),
        0 2px 8px rgba(0,0,0,0.08),
        0 0 0 1px rgba(0,0,0,0.04);
}

/* Highlight spot */
.bubble.unpopped .bubble-inner::before {
    content: '';
    position: absolute;
    top: 15%;
    left: 22%;
    width: 30%;
    height: 22%;
    background: radial-gradient(ellipse, rgba(255,255,255,0.5) 0%, transparent 100%);
    border-radius: 50%;
    transform: rotate(-20deg);
}

.bubble.unpopped:hover {
    transform: scale(1.1);
    z-index: 2;
}

.bubble.unpopped:active {
    transform: scale(0.92);
}

/* Special bubble */
.bubble.special .bubble-inner {
    background: radial-gradient(ellipse at 35% 30%, rgba(255, 230, 100, 0.5) 0%, rgba(255, 200, 50, 0.25) 40%, rgba(200, 150, 30, 0.15) 100%);
    box-shadow:
        inset 0 -3px 6px rgba(0,0,0,0.1),
        inset 0 2px 4px rgba(255,255,200,0.3),
        0 0 16px rgba(255, 215, 0, 0.25),
        0 0 0 1px rgba(255, 215, 0, 0.15);
    animation: shimmer 2s ease-in-out infinite;
}

@keyframes shimmer {
    0%, 100% { box-shadow: inset 0 -3px 6px rgba(0,0,0,0.1), inset 0 2px 4px rgba(255,255,200,0.3), 0 0 16px rgba(255,215,0,0.2), 0 0 0 1px rgba(255,215,0,0.1); }
    50% { box-shadow: inset 0 -3px 6px rgba(0,0,0,0.1), inset 0 2px 4px rgba(255,255,200,0.4), 0 0 28px rgba(255,215,0,0.4), 0 0 0 1px rgba(255,215,0,0.25); }
}

/* Popped bubble */
.bubble.popped .bubble-inner {
    background: var(--surface);
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.15);
    transform: scale(0.85);
    opacity: 0.4;
}

.bubble.popped {
    cursor: default;
}

.bubble.popped .bubble-inner::before {
    display: none;
}

/* Popped by other player ring */
.bubble.popped-remote .bubble-inner {
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.15);
    transform: scale(0.85);
    opacity: 0.5;
}

.bubble .pop-ring {
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2.5px solid transparent;
    pointer-events: none;
    transition: border-color 0.3s;
}

/* Combo Indicator */
.combo-float {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 200;
    pointer-events: none;
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    text-align: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.combo-float.visible {
    opacity: 1;
    animation: comboPop 0.3s ease;
}

@keyframes comboPop {
    0% { transform: translate(-50%, -50%) scale(0.5); }
    60% { transform: translate(-50%, -50%) scale(1.15); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

/* Achievement Toast */
.achievement-toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(120px);
    z-index: 300;
    background: var(--surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--surface-border);
    border-radius: 16px;
    padding: 0.8rem 1.5rem;
    text-align: center;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s;
    opacity: 0;
    max-width: 90vw;
}

.achievement-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.achievement-toast h3 {
    font-family: 'Space Mono', monospace;
    font-size: 0.85rem;
    margin-bottom: 0.15rem;
    color: var(--gold);
}

.achievement-toast p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Sound Toggle */
.sound-btn {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 150;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--surface-border);
    background: var(--surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.sound-btn:hover {
    transform: scale(1.1);
    background: rgba(74, 144, 226, 0.15);
}

/* Particles */
.particle {
    position: fixed;
    pointer-events: none;
    z-index: 150;
    border-radius: 50%;
    animation: particleFly 0.6s ease-out forwards;
}

@keyframes particleFly {
    0% { opacity: 1; transform: translate(0, 0) scale(1); }
    100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0); }
}

.particle.star {
    border-radius: 0;
    background: none !important;
}

/* Footer */
.remix-footer {
    position: fixed;
    bottom: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    font-size: 0.65rem;
    opacity: 0.3;
}

.remix-footer a {
    color: var(--text-muted);
    text-decoration: none;
}

.remix-footer a:hover {
    opacity: 1;
    color: var(--primary);
}

/* Multiplayer Modal / Overlay */
.mp-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.mp-modal {
    background: var(--bg-2);
    border: 1px solid var(--surface-border);
    border-radius: 20px;
    padding: 2rem;
    max-width: 420px;
    width: 90vw;
    text-align: center;
    animation: modalSlideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.mp-modal h2 {
    font-family: 'Space Mono', monospace;
    font-size: 1.3rem;
    margin-bottom: 0.3rem;
}

.mp-modal p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 1.2rem;
}

.mp-modal input {
    width: 100%;
    padding: 0.7rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--surface-border);
    background: var(--surface);
    color: var(--text);
    font-family: 'Space Mono', monospace;
    font-size: 1rem;
    text-align: center;
    outline: none;
    margin-bottom: 0.8rem;
    transition: border-color 0.2s;
}

.mp-modal input:focus {
    border-color: var(--secondary);
}

.mp-modal input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.mp-modal .btn-row {
    display: flex;
    gap: 0.6rem;
    margin-top: 0.5rem;
}

.mp-modal .btn-row button {
    flex: 1;
    padding: 0.65rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--surface-border);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.mp-modal .btn-primary {
    background: var(--secondary);
    color: #fff;
    border-color: var(--secondary);
}

.mp-modal .btn-primary:hover {
    filter: brightness(1.15);
    transform: translateY(-1px);
}

.mp-modal .btn-secondary {
    background: var(--surface);
    color: var(--text);
}

.mp-modal .btn-secondary:hover {
    background: rgba(255,255,255,0.1);
    transform: translateY(-1px);
}

.mp-modal .btn-cancel {
    background: transparent;
    color: var(--text-muted);
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    margin-top: 0.8rem;
}

.mp-modal .btn-cancel:hover {
    color: var(--accent);
}

/* Player list sidebar */
.player-sidebar {
    position: fixed;
    top: 80px;
    right: 0.5rem;
    z-index: 90;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

.player-tag {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--surface);
    backdrop-filter: blur(10px);
    border: 1px solid var(--surface-border);
    border-radius: 10px;
    padding: 0.3rem 0.6rem;
    font-size: 0.7rem;
    font-family: 'Space Mono', monospace;
    white-space: nowrap;
    animation: fadeIn 0.3s ease;
}

.player-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.player-score {
    color: var(--text-muted);
    font-size: 0.6rem;
    margin-left: auto;
}

.player-tag.you {
    border-color: var(--secondary);
}

/* Room code display */
.room-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(123, 104, 238, 0.15);
    border: 1px solid rgba(123, 104, 238, 0.3);
    border-radius: 8px;
    padding: 0.2rem 0.5rem;
    font-family: 'Space Mono', monospace;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--secondary);
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.2s;
}

.room-badge:hover {
    background: rgba(123, 104, 238, 0.25);
}

.room-badge .copy-hint {
    font-size: 0.55rem;
    font-weight: 400;
    color: var(--text-muted);
    letter-spacing: 0;
}

/* Remote pop flash */
@keyframes remotePop {
    0% { transform: scale(1.2); opacity: 0.8; }
    100% { transform: scale(0.85); opacity: 0.5; }
}

.bubble.remote-pop-anim .bubble-inner {
    animation: remotePop 0.3s ease forwards;
}

/* Color picker in modal */
.color-picker-row {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.selected {
    border-color: #fff;
    box-shadow: 0 0 12px rgba(255,255,255,0.3);
    transform: scale(1.15);
}

/* Sync indicator */
.sync-indicator {
    position: fixed;
    top: 0.4rem;
    right: 0.5rem;
    z-index: 200;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.6rem;
    color: var(--text-muted);
    opacity: 0.6;
}

.sync-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    animation: syncPulse 2s ease infinite;
}

.sync-dot.disconnected {
    background: var(--accent);
    animation: none;
}

@keyframes syncPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Mobile adjustments */
@media (max-width: 640px) {
    :root {
        --bubble-size: 50px;
        --gap: 5px;
    }

    .header-inner {
        justify-content: center;
        gap: 0.4rem;
    }

    .app-title {
        font-size: 0.85rem;
        width: 100%;
        text-align: center;
    }

    .stats-row {
        gap: 0.35rem;
    }

    .stat-pill {
        min-width: 50px;
        padding: 0.2rem 0.4rem;
    }

    .stat-value {
        font-size: 0.9rem;
    }

    .ctrl-btn {
        font-size: 0.65rem;
        padding: 0.3rem 0.5rem;
    }

    .bubble-grid-wrapper {
        padding-top: 130px;
    }

    .player-sidebar {
        top: 130px;
    }

    .mp-modal {
        padding: 1.5rem;
    }
}

@media (max-width: 380px) {
    :root {
        --bubble-size: 44px;
    }
}