:root {
    --bg-dark: #090b10;
    --bg-surface: rgba(18, 22, 33, 0.75);
    --bg-surface-elevated: rgba(28, 34, 51, 0.85);
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(255, 255, 255, 0.18);
    
    --accent-cyan: #00f2fe;
    --accent-purple: #9d4edd;
    --accent-pink: #ff007f;
    --accent-gold: #ffbe0b;
    --accent-green: #06d6a0;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    --shadow-soft: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 25px rgba(0, 242, 254, 0.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(circle at 15% 15%, rgba(157, 78, 221, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 85% 85%, rgba(0, 242, 254, 0.12) 0%, transparent 45%),
        radial-gradient(circle at 50% 50%, rgba(255, 0, 127, 0.06) 0%, transparent 60%);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow-x: hidden;
}

/* App Container */
.game-app {
    width: 100%;
    max-width: 580px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 4px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-logo {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 242, 254, 0.35);
}

.brand-logo svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}

.brand-text h1 {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    background: linear-gradient(90deg, #fff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-text span {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent-cyan);
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(12px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.icon-btn:hover {
    color: var(--text-primary);
    background: var(--bg-surface-elevated);
    border-color: var(--border-highlight);
    transform: translateY(-1px);
}

.icon-btn:active {
    transform: translateY(1px);
}

.icon-btn.active {
    color: var(--accent-cyan);
    border-color: rgba(0, 242, 254, 0.4);
    box-shadow: 0 0 12px rgba(0, 242, 254, 0.2);
}

/* Dashboard / Stats Cards */
.stats-dashboard {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
    gap: 10px;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
    transition: border-color 0.2s;
}

.stat-card:hover {
    border-color: var(--border-highlight);
}

.stat-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 2px;
}

.stat-value {
    font-size: 1.45rem;
    font-weight: 800;
    color: #ffffff;
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.streak-badge {
    font-size: 0.7rem;
    font-weight: 700;
    color: #ff9800;
    background: rgba(255, 152, 0, 0.15);
    padding: 1px 6px;
    border-radius: var(--radius-full);
}

/* Next Balls Preview Card */
.preview-card {
    align-items: center;
}

.preview-container {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 4px;
    min-height: 28px;
}

.preview-orb {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    position: relative;
    box-shadow: inset -2px -3px 6px rgba(0, 0, 0, 0.4), 0 3px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.preview-orb::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 4px;
    width: 7px;
    height: 5px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.75);
    filter: blur(0.6px);
}

/* Main Board Container */
.board-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft), inset 0 1px 1px rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(24px);
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: var(--radius-md);
    cursor: pointer;
    touch-action: none;
}

/* Floating Combo Indicator */
.combo-banner {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    background: linear-gradient(135deg, #ff007f, #ff758c);
    color: white;
    padding: 4px 14px;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 16px rgba(255, 0, 127, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 10;
}

.combo-banner.show {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

/* Footer / Action Toolbar */
.action-toolbar {
    display: flex;
    gap: 10px;
}

.action-btn {
    flex: 1;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    backdrop-filter: blur(16px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.action-btn:hover:not(:disabled) {
    background: var(--bg-surface-elevated);
    border-color: var(--border-highlight);
    transform: translateY(-1px);
}

.action-btn:active:not(:disabled) {
    transform: translateY(1px);
}

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

.action-btn.primary {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    border: none;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3);
}

.action-btn.primary:hover {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.45);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #151924;
    border: 1px solid var(--border-highlight);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 440px;
    padding: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    transform: translateY(20px) scale(0.96);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-content {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.modal-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    color: var(--text-primary);
}

/* Leaderboard list */
.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
    max-height: 280px;
    overflow-y: auto;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.leaderboard-item.rank-1 {
    background: rgba(255, 190, 11, 0.12);
    border-color: rgba(255, 190, 11, 0.3);
}

.leaderboard-item.current {
    background: rgba(0, 242, 254, 0.15);
    border-color: rgba(0, 242, 254, 0.4);
}

.rank-num {
    font-weight: 800;
    width: 24px;
    color: var(--text-secondary);
}

.player-name {
    flex: 1;
    font-weight: 600;
    margin-left: 8px;
}

.player-score {
    font-weight: 800;
    color: var(--accent-cyan);
}

/* Instructions */
.help-section {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.55;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.help-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.help-icon {
    font-size: 1.1rem;
    line-height: 1.4;
}

/* Footer note */
.app-footer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}
