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

:root {
    --bg: #0a0c12;
    --bg2: #10131c;
    --surface: rgba(255, 255, 255, 0.04);
    --surface2: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.08);
    --text: #e4e7ef;
    --text-muted: #6b7080;
    --accent: #f43f5e;
    --accent-glow: rgba(244, 63, 94, 0.15);
    --green: #22c55e;
    --green-glow: rgba(34, 197, 94, 0.15);
    --blue: #38bdf8;
    --yellow: #fbbf24;
    --radius: 14px;
    --radius-sm: 10px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-user-select: none;
    user-select: none;
}

.app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.screen {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* ===== SETUP ===== */
#setupScreen {
    overflow-y: auto;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}

.setup-card {
    width: 100%;
    max-width: 440px;
}

.logo {
    text-align: center;
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 32px;
    letter-spacing: -0.5px;
}

.setup-section {
    margin-bottom: 24px;
}

.setup-section > label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

/* Btn group */
.btn-group {
    display: flex;
    gap: 6px;
}

.btn-group button {
    flex: 1;
    padding: 12px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-group button:hover {
    background: var(--surface2);
    color: var(--text);
}

.btn-group button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 2px 12px var(--accent-glow);
}

/* Player list */
.player-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.player-input-row {
    display: flex;
    gap: 8px;
}

.player-name-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

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

.player-name-input::placeholder {
    color: var(--text-muted);
}

.btn-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: var(--surface2);
    color: var(--text);
}

.btn-secondary {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-primary {
    width: 100%;
    padding: 16px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    margin-top: 12px;
    transition: all 0.15s;
    box-shadow: 0 4px 20px var(--accent-glow);
}

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

.btn-primary:active {
    transform: translateY(0);
}

/* ===== GAME SCREEN ===== */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg2);
    flex-shrink: 0;
}

.game-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.game-info .sep {
    margin: 0 6px;
    opacity: 0.4;
}

/* Scoreboard */
.scoreboard {
    display: flex;
    gap: 2px;
    padding: 8px;
    flex-shrink: 0;
    overflow-x: auto;
}

.player-col {
    flex: 1;
    min-width: 100px;
    text-align: center;
    padding: 12px 8px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.player-col.active {
    border-color: var(--accent);
    background: rgba(244, 63, 94, 0.06);
}

.player-col .p-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-col.active .p-name {
    color: var(--accent);
}

.player-col .p-score {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1.1;
}

.player-col .p-legs {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.player-col .p-avg {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Turn info */
.turn-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    flex-shrink: 0;
}

.turn-info #currentPlayerName {
    font-weight: 700;
    color: var(--accent);
}

.darts-left, .round-score {
    color: var(--text-muted);
}

.darts-left strong, .round-score strong {
    color: var(--text);
}

/* ===== BOARD INPUT ===== */
.input-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 8px;
    overflow: hidden;
    min-height: 0;
}

.multiplier-row {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.mult-btn {
    flex: 1;
    padding: 10px 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.mult-btn:hover {
    background: var(--surface2);
}

.mult-btn.active {
    color: #fff;
}

.mult-btn.active[data-mult="1"] {
    background: var(--blue);
    border-color: var(--blue);
}

.mult-btn.active[data-mult="2"] {
    background: var(--green);
    border-color: var(--green);
}

.mult-btn.active[data-mult="3"] {
    background: var(--accent);
    border-color: var(--accent);
}

.board-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    flex: 1;
    min-height: 0;
}

.board-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.1s;
    min-height: 0;
}

.board-btn:hover {
    background: var(--surface2);
    border-color: rgba(255, 255, 255, 0.15);
}

.board-btn:active {
    transform: scale(0.95);
    background: var(--accent-glow);
}

.bull-btn {
    font-size: 0.9rem;
}

.board-btn.last-hit {
    animation: hitFlash 0.3s ease;
}

@keyframes hitFlash {
    0% { background: var(--accent); }
    100% { background: var(--surface); }
}

/* ===== NUMPAD INPUT ===== */
.numpad-display {
    text-align: center;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    flex-shrink: 0;
}

#numpadValue {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -1px;
}

.numpad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    flex: 1;
    min-height: 0;
}

.numpad-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1.3rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.1s;
    min-height: 0;
}

.numpad-btn:hover {
    background: var(--surface2);
}

.numpad-btn:active {
    transform: scale(0.95);
}

.numpad-clear {
    background: rgba(251, 191, 36, 0.1);
    border-color: rgba(251, 191, 36, 0.2);
    color: var(--yellow);
}

.numpad-ok {
    background: rgba(34, 197, 94, 0.1);
    border-color: rgba(34, 197, 94, 0.2);
    color: var(--green);
}

/* ===== OVERLAYS ===== */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 24px;
}

.winner-card, .menu-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px 32px;
    text-align: center;
    width: 100%;
    max-width: 380px;
}

.winner-emoji {
    font-size: 3rem;
    margin-bottom: 12px;
}

.winner-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.winner-card p {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 16px;
}

#winnerStats, #matchStats {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-bottom: 24px;
    line-height: 1.8;
}

.winner-actions {
    display: flex;
    gap: 10px;
}

.winner-actions .btn-primary,
.winner-actions .btn-secondary {
    margin-top: 0;
}

.winner-actions .btn-secondary {
    padding: 16px;
    border-style: solid;
}

.menu-card h2 {
    font-size: 1.2rem;
    margin-bottom: 20px;
}

.btn-menu {
    width: 100%;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 8px;
    transition: all 0.15s;
}

.btn-menu:hover {
    background: var(--surface2);
}

.btn-menu:last-child {
    margin-bottom: 0;
}

.btn-danger {
    color: var(--accent);
    border-color: rgba(244, 63, 94, 0.2);
}

.btn-danger:hover {
    background: var(--accent-glow);
}

/* ===== BUST FLASH ===== */
.bust-flash {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--accent);
    color: #fff;
    padding: 16px 40px;
    border-radius: var(--radius);
    font-size: 1.3rem;
    font-weight: 800;
    z-index: 150;
    animation: bustAnim 1s ease forwards;
    pointer-events: none;
}

@keyframes bustAnim {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    70% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
}

/* ===== CHECKOUT HINT ===== */
.checkout-hint {
    text-align: center;
    padding: 6px 12px;
    font-size: 0.78rem;
    color: var(--green);
    background: var(--green-glow);
    border-radius: var(--radius-sm);
    margin: 4px 8px 0;
    flex-shrink: 0;
    font-weight: 500;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 600px) {
    .scoreboard {
        justify-content: center;
    }

    .player-col {
        max-width: 180px;
    }

    .board-grid {
        max-width: 420px;
        margin: 0 auto;
    }

    .numpad-grid {
        max-width: 320px;
        margin: 0 auto;
    }

    .multiplier-row {
        max-width: 420px;
        margin: 0 auto 8px;
    }

    .numpad-display {
        max-width: 320px;
        margin: 0 auto 8px;
    }
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }
