:root {
    --bg-1: #08150e;
    --bg-2: #0f2a1a;
    --felt: #123c24;
    --card-bg: rgba(255, 255, 255, 0.045);
    --card-border: rgba(255, 255, 255, 0.09);
    --gold: #e0b84d;
    --gold-soft: #f2d789;
    --text: #f4f6f2;
    --muted: #a9c2b1;
    --danger: #e2554b;

    --c-2: #3aa0e0;
    --c-4: #35c2a0;
    --c-8: #e0a23a;
    --c-16: #e2554b;

    --radius: 16px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

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

html, body {
    height: 100%;
}

body {
    font-family: 'Poppins', 'Segoe UI', sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 20% -10%, rgba(224, 184, 77, 0.08), transparent 45%),
        radial-gradient(circle at 100% 0%, rgba(53, 194, 160, 0.08), transparent 40%),
        linear-gradient(160deg, var(--bg-1), var(--bg-2) 60%, var(--bg-1));
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: contain;
}

.hidden {
    display: none !important;
}

/* ===== SETUP SCREEN ===== */

.screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

.setup-card {
    width: 100%;
    max-width: 460px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    padding: 32px 26px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.logo {
    text-align: center;
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 0.5px;
}

.logo span {
    color: var(--gold-soft);
}

.subtitle {
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
    margin-top: 6px;
    margin-bottom: 28px;
}

.field-group {
    margin-bottom: 22px;
}

.field-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 10px;
}

.score-presets {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

.preset-btn {
    padding: 12px 0;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.preset-btn:hover {
    border-color: var(--gold);
}

.preset-btn.active {
    background: linear-gradient(135deg, var(--gold), #b9862a);
    color: #1a1204;
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(224, 184, 77, 0.35);
}

.custom-score-input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s ease;
}

.custom-score-input::placeholder {
    color: var(--muted);
}

.custom-score-input:focus {
    border-color: var(--gold);
}

.name-inputs {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.name-input {
    width: 100%;
    padding: 13px 16px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s ease;
}

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

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

.btn-primary {
    width: 100%;
    padding: 15px 0;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--gold), #b9862a);
    color: #1a1204;
    font-size: 1.02rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(224, 184, 77, 0.28);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn-primary:active {
    transform: scale(0.98);
    box-shadow: 0 4px 12px rgba(224, 184, 77, 0.25);
}

/* ===== GAME SCREEN ===== */

#game-screen.screen {
    display: block;
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
    max-width: 620px;
    margin: 0 auto;
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding: 0 4px;
}

.start-badge {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--card-border);
    padding: 8px 14px;
    border-radius: 999px;
}

.start-badge span {
    color: var(--gold-soft);
    font-weight: 700;
}

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

.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
}

.icon-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.icon-btn:not(:disabled):hover {
    border-color: var(--gold);
    color: var(--gold-soft);
}

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

.players {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.player-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 16px;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.player-card.winner-card {
    border-color: var(--gold);
    box-shadow: 0 0 0 1px var(--gold-soft), 0 8px 24px rgba(224, 184, 77, 0.25);
}

.player-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 10px;
}

.player-name {
    font-weight: 600;
    font-size: 1.02rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-status {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--gold-soft);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.player-score {
    font-size: 2.1rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    transition: color 0.2s ease;
}

.player-score.low {
    color: var(--gold-soft);
}

.point-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 14px;
}

.pt-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 4px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    color: #fff;
    font-family: inherit;
    transition: transform 0.08s ease, filter 0.12s ease;
}

.pt-btn:active {
    transform: scale(0.94);
}

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

.pt-btn[data-value="2"] { background: linear-gradient(145deg, var(--c-2), #2678a3); }
.pt-btn[data-value="4"] { background: linear-gradient(145deg, var(--c-4), #279074); }
.pt-btn[data-value="8"] { background: linear-gradient(145deg, var(--c-8), #a97423); }
.pt-btn[data-value="16"] { background: linear-gradient(145deg, var(--c-16), #a83b32); }

.pt-value {
    font-size: 1.2rem;
    font-weight: 800;
}

/* ===== GAME OVER MODAL ===== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(4, 10, 6, 0.72);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
    animation: fadeIn 0.2s ease;
}

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

.modal-card {
    width: 100%;
    max-width: 400px;
    background: linear-gradient(160deg, #14311f, #0c2115);
    border: 1px solid var(--card-border);
    border-radius: 22px;
    padding: 30px 26px;
    box-shadow: var(--shadow);
    text-align: center;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.modal-subtitle {
    color: var(--muted);
    font-size: 0.92rem;
    margin-bottom: 22px;
}

.final-scores {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
    text-align: left;
}

.final-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--card-border);
    font-size: 0.92rem;
}

.final-row.is-winner {
    border-color: rgba(224, 184, 77, 0.6);
    background: rgba(224, 184, 77, 0.1);
}

.final-rank {
    color: var(--gold-soft);
    font-weight: 700;
    margin-right: 8px;
}

.final-name {
    flex: 1;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.final-score {
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

/* ===== RESPONSIVE (tablet / desktop) ===== */

@media (min-width: 640px) {
    #game-screen.screen {
        padding-top: 32px;
    }

    .player-card {
        padding: 18px 20px;
    }

    .player-score {
        font-size: 2.4rem;
    }

    .pt-btn {
        padding: 12px 4px;
    }

    .pt-value {
        font-size: 1.15rem;
    }
}

@media (min-width: 860px) {
    .players {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}
