:root {
    --bg: #0b1020;
    --bg-elevated: #151c2e;
    --bg-nav: #101627;
    --text: #f5f7fb;
    --muted: #9aa6b8;
    --line: #2a3550;
    --team-a: #3d9dff;
    --team-a-soft: rgba(61, 157, 255, 0.16);
    --team-b: #ff6b5a;
    --team-b-soft: rgba(255, 107, 90, 0.16);
    --success: #3dd68c;
    --warn: #f5c542;
    --danger: #ff5d6c;
    --tap: 52px;
}

* { box-sizing: border-box; }

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, sans-serif;
}

body {
    min-height: 100vh;
    padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--team-a); }

.app-nav {
    background: var(--bg-nav);
    border-bottom: 1px solid var(--line);
    padding: calc(0.65rem + env(safe-area-inset-top)) 0 0.65rem;
}

.app-nav .brand {
    color: var(--text);
    font-weight: 700;
    text-decoration: none;
    font-size: 1.05rem;
}

.nav-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.nav-actions form { margin: 0; }

.nav-actions .btn-secondary-action {
    width: auto;
    min-width: 0;
    min-height: 40px;
    padding: 0 0.8rem;
}

.page {
    max-width: 720px;
    margin: 0 auto;
    padding: 1rem 0.9rem 2rem;
}

.flash {
    border: 0;
    border-radius: 14px;
    padding: 0.85rem 1rem;
    margin-bottom: 0.9rem;
    font-weight: 600;
}

.flash-success { background: rgba(61, 214, 140, 0.16); color: var(--success); }
.flash-error { background: rgba(255, 93, 108, 0.16); color: #ffb3bb; }

.game-banner {
    text-align: center;
    font-size: clamp(2.2rem, 10vw, 3.4rem);
    font-weight: 800;
    letter-spacing: 0.04em;
    margin: 0 0 0.8rem;
}

.play-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
    align-items: stretch;
}

.bid-slot { min-height: 0; }

.bid-box {
    margin-top: 0.55rem;
    padding: 0.55rem;
    border-radius: 14px;
    background: #0e1424;
}

.bid-box .bid-stepper { margin: 0.35rem 0 0; }

.winner-panel {
    margin-top: 0.9rem;
}

.winner-panel h2 {
    text-align: center;
    font-size: 1.15rem;
    margin-bottom: 0.6rem;
}

.score-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
}

.team-card {
    background: var(--bg-elevated);
    border-radius: 18px;
    padding: 0.75rem 0.65rem 0.7rem;
    height: 100%;
    border: 2px solid transparent;
    display: flex;
    flex-direction: column;
}

.team-card.team-a { border-color: var(--team-a); background: linear-gradient(180deg, var(--team-a-soft), var(--bg-elevated) 42%); }
.team-card.team-b { border-color: var(--team-b); background: linear-gradient(180deg, var(--team-b-soft), var(--bg-elevated) 42%); }
.team-card.leading { box-shadow: inset 0 0 0 2px #fff; }

.team-kicker {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 700;
}

.team-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.45rem;
}

.team-main { min-width: 0; flex: 1; }

.name-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-height: 40px;
}

.team-name {
    font-size: 1.15rem;
    font-weight: 800;
    margin: 0;
    line-height: 1.1;
    overflow-wrap: anywhere;
}

.inline-bid {
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    gap: 4px;
    width: 100%;
    margin-top: 0.55rem;
}

.inline-bid button,
.bid-figure {
    height: 44px;
    border-radius: 10px;
    border: 2px solid var(--line);
    background: #0e1424;
    color: var(--text);
    font-weight: 800;
    text-align: center;
    padding: 0;
    font-size: 1.15rem;
}

.bid-figure { width: 100%; }

.btn-score {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 64px;
    margin-top: 0.85rem;
    border: 0;
    border-radius: 16px;
    background: #ffd15c;
    color: #1a1404;
    font-size: 1.3rem;
    font-weight: 800;
    box-shadow: 0 5px 0 #c89612;
    cursor: pointer;
}

.btn-score:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 #c89612;
}

.team-score {
    font-size: 2.7rem;
    font-weight: 800;
    line-height: 0.9;
    font-variant-numeric: tabular-nums;
    min-width: 2.2ch;
    text-align: right;
    flex: 0 0 auto;
}

.role-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    margin-top: auto;
    padding-top: 0.45rem;
    border-radius: 12px;
    border: 2px solid var(--line);
    background: #0e1424;
    color: var(--text);
    font-weight: 800;
    font-size: 0.95rem;
}

.team-a .btn-check:checked + .role-chip {
    border-color: var(--team-a);
    background: var(--team-a-soft);
    color: #d6ebff;
}

.team-b .btn-check:checked + .role-chip {
    border-color: var(--team-b);
    background: var(--team-b-soft);
    color: #ffd4ce;
}

.team-a .team-score { color: var(--team-a); }
.team-b .team-score { color: var(--team-b); }

.team-players {
    margin: 0.45rem 0 0;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.35;
}

.meta-bar {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0.85rem 0 1rem;
    background: var(--bg-elevated);
    border-radius: 14px;
    padding: 0.7rem 0.8rem;
    font-size: 0.92rem;
}

.meta-bar strong { display: block; font-size: 1.05rem; }
.meta-bar span { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.turn-value { color: var(--warn); }

.winner-banner {
    background: var(--warn);
    color: #1b1403;
    border-radius: 16px;
    padding: 1rem;
    text-align: center;
    font-size: 1.35rem;
    font-weight: 800;
    margin-bottom: 0.9rem;
}

.round-panel {
    background: var(--bg-elevated);
    border-radius: 18px;
    padding: 1rem;
    margin-bottom: 0.9rem;
}

.round-panel h2 {
    font-size: 1.05rem;
    margin: 0 0 0.8rem;
}

.choice-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
}

.choice-grid.results { margin-top: 0.55rem; }

.btn-choice {
    min-height: var(--tap);
    border-radius: 14px;
    font-weight: 700;
    border: 2px solid var(--line);
    background: #0e1424;
    color: var(--text);
    width: 100%;
}

.btn-check:checked + .btn-choice-a,
.btn-choice-a.active {
    border-color: var(--team-a);
    background: var(--team-a-soft);
    color: #d6ebff;
}

.btn-check:checked + .btn-choice-b,
.btn-choice-b.active {
    border-color: var(--team-b);
    background: var(--team-b-soft);
    color: #ffd4ce;
}

.btn-check:checked + .btn-choice-made {
    border-color: var(--success);
    background: rgba(61, 214, 140, 0.16);
    color: var(--success);
}

.btn-check:checked + .btn-choice-failed {
    border-color: var(--danger);
    background: rgba(255, 93, 108, 0.16);
    color: #ffb3bb;
}

.bid-stepper {
    display: grid;
    grid-template-columns: var(--tap) 1fr var(--tap);
    gap: 0.5rem;
    margin: 0.7rem 0;
}

.bid-stepper input {
    min-height: var(--tap);
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    background: #0e1424;
    color: var(--text);
    border: 2px solid var(--line);
    border-radius: 14px;
}

.bid-stepper button {
    min-height: var(--tap);
    border-radius: 14px;
    font-size: 1.6rem;
    font-weight: 700;
    border: 2px solid var(--line);
    background: #0e1424;
    color: var(--text);
}

.btn-submit {
    min-height: 56px;
    width: 100%;
    border: 0;
    border-radius: 16px;
    background: #f5f7fb;
    color: #0b1020;
    font-size: 1.15rem;
    font-weight: 800;
}

.btn-submit:disabled { opacity: 0.45; }

.action-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
    margin-bottom: 0.9rem;
}

.btn-secondary-action {
    min-height: var(--tap);
    border-radius: 14px;
    border: 2px solid var(--line);
    background: transparent;
    color: var(--text);
    font-weight: 700;
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.btn-secondary-action.warn { border-color: var(--warn); color: var(--warn); }
.btn-secondary-action.danger { border-color: var(--danger); color: #ffb3bb; }
.btn-secondary-action:disabled { opacity: 0.4; }

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}

.history-toolbar {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-shrink: 0;
}

.game-check input {
    width: 1.2rem;
    height: 1.2rem;
    accent-color: var(--team-a);
}

.bulk-confirm-box,
.bulk-delete-box {
    margin-bottom: 0.9rem;
    padding: 0.75rem;
    border-radius: 12px;
    background: rgba(255, 93, 108, 0.08);
    border: 1px solid rgba(255, 93, 108, 0.28);
}

.bulk-confirm-text {
    margin: 0 0 0.7rem;
    font-weight: 700;
}

.bulk-confirm-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.bulk-delete-box .btn-history { margin-top: 0.55rem; width: auto; min-width: 8rem; }

.history-actions {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    align-items: stretch;
    min-width: 5.75rem;
}

.btn-history {
    min-height: 36px;
    width: 100%;
    padding: 0 0.7rem;
    border: 0;
    border-radius: 10px;
    background: #f5f7fb;
    color: #0b1020;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.btn-history.ghost {
    width: auto;
    background: transparent;
    border: 1.5px solid var(--line);
    color: var(--text);
}

.btn-history.danger {
    background: transparent;
    border: 1.5px solid var(--danger);
    color: #ffb3bb;
}

.btn-history:disabled,
.btn-icon-delete:disabled { opacity: 0.45; cursor: default; }

.btn-icon-delete {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1.5px solid var(--danger);
    background: transparent;
    color: #ffb3bb;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
}

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

.game-check {
    display: none;
    align-items: center;
    justify-content: center;
    margin: 0;
}

.game-list.is-selecting .game-check { display: flex; }

.game-list.is-selecting .game-list-item {
    grid-template-columns: auto minmax(0, 1fr) auto;
}

.delete-hint {
    margin: 0.45rem 0 0;
    color: var(--muted);
    font-size: 0.8rem;
}

.history-card, .setup-card, .list-card {
    background: var(--bg-elevated);
    border-radius: 18px;
    padding: 1rem;
}

.history-list { display: grid; gap: 0.55rem; }

.history-item {
    display: grid;
    grid-template-columns: 2.2rem 1fr auto;
    gap: 0.55rem;
    padding: 0.7rem;
    border-radius: 12px;
    background: #0e1424;
    align-items: center;
}

.history-item .num { font-weight: 800; color: var(--muted); font-size: 1.05rem; }
.history-item .detail { font-size: 0.95rem; }
.history-item .pts { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; font-size: 1rem; }

.auth-card h1 { font-weight: 800; }
.auth-card .btn-score { margin-top: 1rem; }
.remember {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--muted);
    font-weight: 600;
}
.remember input { width: 1.15rem; height: 1.15rem; }

.form-label { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.form-control, .form-select {
    min-height: var(--tap);
    background: #0e1424;
    color: var(--text);
    border: 2px solid var(--line);
    border-radius: 12px;
}
.form-control:focus, .form-select:focus {
    background: #0e1424;
    color: var(--text);
    border-color: var(--team-a);
    box-shadow: none;
}

.game-list { display: grid; gap: 0.7rem; }
.game-list-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.65rem 0.7rem;
    align-items: center;
    background: #0e1424;
    border-radius: 14px;
    padding: 0.75rem 0.8rem;
}
.game-list-meta { min-width: 0; }
.game-list-item h2 { font-size: 1.05rem; margin: 0 0 0.2rem; }
.game-list-item .score-line { margin: 0 0 0.2rem; }
.game-list-item .status-line { margin: 0; font-size: 0.9rem; }

@media (max-width: 480px) {
    .page { padding: 0.65rem 0.5rem 1.25rem; }
    .play-grid { gap: 0.45rem; }
    .game-banner { font-size: 1.85rem; margin-bottom: 0.5rem; }
    .team-card { padding: 0.6rem 0.5rem 0.55rem; border-radius: 14px; }
    .team-name { font-size: 1rem; }
    .team-score { font-size: 1.85rem; }
    .team-players { font-size: 0.72rem; }
    .team-kicker { font-size: 0.62rem; }
    .role-chip { min-height: 44px; font-size: 0.78rem; }
    .history-item { grid-template-columns: 1.4rem 1fr; }
    .history-item .pts { grid-column: 2; text-align: left; }
}

@media (min-width: 768px) {
    .page { padding-top: 1.5rem; }
    .team-score { font-size: 3rem; }
}
