/* ==========================================================================
   Tichu Score — styles
   ========================================================================== */
:root {
    --bg:        #0b1120;
    --bg-2:      #0f172a;
    --panel:     #111c34;
    --panel-2:   #16233f;
    --line:      #223154;
    --line-soft: #1a2740;
    --text:      #e6ecf7;
    --muted:     #8ea0c2;
    --muted-2:   #5f739a;
    --primary:   #ef4444;
    --primary-d: #b91c1c;
    --teamA:     #38bdf8;
    --teamB:     #fb923c;
    --good:      #34d399;
    --bad:       #f87171;
    --gold:      #fbbf24;
    --radius:    14px;
    --radius-sm: 10px;
    --shadow:    0 10px 30px rgba(0,0,0,.35);
    --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    background: radial-gradient(1200px 800px at 80% -10%, #16233f 0%, var(--bg) 55%);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
button { font-family: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ buttons */
.btn {
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 11px 16px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    background: var(--panel-2);
    transition: transform .05s ease, background .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(180deg, var(--primary), var(--primary-d)); border-color: var(--primary-d); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted-2); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-lg { padding: 15px 20px; font-size: 17px; }

/* --------------------------------------------------------------------- gate */
.gate {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px;
}
.gate-card {
    width: 100%;
    max-width: 400px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 32px 28px;
    box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 26px; }
.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 60px; height: 60px;
    border-radius: 16px;
    background: linear-gradient(180deg, var(--primary), var(--primary-d));
    font-size: 30px; font-weight: 700; color: #fff;
    box-shadow: 0 8px 20px rgba(239,68,68,.35);
    margin-bottom: 14px;
}
.brand-mark.small { width: 30px; height: 30px; font-size: 16px; border-radius: 9px; margin: 0; box-shadow: none; }
.brand h1 { font-size: 26px; }
.tagline { color: var(--muted); margin: 6px 0 0; font-size: 14px; }
#auth-form { display: grid; gap: 16px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
input[type=text], input[type=password], input[type=number] {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 16px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(239,68,68,.15); }
.pw-field { position: relative; }
.pw-field input { padding-right: 62px; }
.pw-toggle {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--muted); font-size: 13px; font-weight: 700;
    padding: 6px 8px; cursor: pointer;
}
.pw-toggle:hover { color: var(--text); }
.gate-hint { text-align: center; color: var(--muted-2); font-size: 12.5px; margin: 2px 0 0; }
.gate-error { color: var(--bad); font-size: 13.5px; text-align: center; margin: 0; min-height: 1em; }

/* ---------------------------------------------------------------------- app */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line);
    background: rgba(15,23,42,.75);
    backdrop-filter: blur(8px);
    position: sticky; top: 0; z-index: 20;
}
.topbar-brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; }
.topbar-group { display: flex; align-items: center; gap: 12px; }
.group-label { color: var(--muted); font-size: 14px; font-weight: 600; }

.split { flex: 1; display: flex; min-height: 0; }
.panel { flex: 1 1 0; min-width: 0; overflow-y: auto; overflow-x: hidden; padding: 20px; }
.panel-score { border-right: 1px solid var(--line); }
.panel-stats { background: rgba(11,17,32,.4); }

/* ------------------------------------------------------------ score panel */
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted-2); margin-bottom: 10px; }
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }

/* Game header / scoreboard */
.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; align-items: stretch; gap: 12px; }
.team-score {
    border-radius: var(--radius-sm);
    padding: 14px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    text-align: center;
}
.team-score.teamA { border-top: 3px solid var(--teamA); }
.team-score.teamB { border-top: 3px solid var(--teamB); }
.team-score.win { box-shadow: 0 0 0 2px var(--gold) inset; }
.team-names { font-size: 13.5px; color: var(--muted); font-weight: 600; line-height: 1.35; min-height: 2.6em; }
.team-total { font-size: 34px; font-weight: 800; margin-top: 6px; letter-spacing: -.02em; }
.teamA .team-total { color: var(--teamA); }
.teamB .team-total { color: var(--teamB); }
.vs { display: grid; place-items: center; color: var(--muted-2); font-weight: 700; font-size: 13px; }
.progress { height: 6px; background: var(--line-soft); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; border-radius: 99px; }
.game-meta { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.pill { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.pill.gold { color: #1b1300; background: var(--gold); border-color: var(--gold); }

/* Ledger */
.ledger { margin-top: 4px; }
.ledger-row {
    display: grid;
    grid-template-columns: 26px 1fr 1fr;
    gap: 8px;
    align-items: center;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-soft);
    margin-bottom: 7px;
    background: var(--panel);
    font-variant-numeric: tabular-nums;
}
.ledger-row.head { background: transparent; border: none; color: var(--muted-2); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding-bottom: 2px; }
.lr-n { color: var(--muted-2); font-size: 12px; text-align: center; }
.lr-a, .lr-b { text-align: center; font-weight: 600; }
.lr-run { font-size: 12px; color: var(--muted); }
.lr-delta { font-size: 15px; }
.lr-delta.pos { color: var(--good); }
.lr-delta.neg { color: var(--bad); }
.empty-note { color: var(--muted-2); font-size: 14px; text-align: center; padding: 22px 0; }

/* Input form */
.hand-form { display: grid; gap: 16px; }
.base-input { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: end; }
.base-field span.lbl { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.base-field.teamA span.lbl { color: var(--teamA); }
.base-field.teamB span.lbl { color: var(--teamB); }
.base-field input { text-align: center; font-size: 22px; font-weight: 700; }
.base-field select {
    width: 100%; text-align: center; text-align-last: center;
    font-size: 20px; font-weight: 700; padding: 10px 6px;
    background: var(--bg-2); border: 1px solid var(--line);
    border-radius: var(--radius-sm); color: var(--text); appearance: none;
}
.base-field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(239,68,68,.15); outline: none; }
.base-field select:disabled { background: var(--bg); color: var(--muted); opacity: 1; }
.base-field .readonly { background: var(--bg); color: var(--muted); }
.dash { display: grid; place-items: center; color: var(--muted-2); font-weight: 700; padding-bottom: 12px; }

.dv-toggle { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--muted); }
.switch { position: relative; width: 42px; height: 24px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: background .15s ease; }
.switch .track::before { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: transform .15s ease; }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* Player grid: first-out + tichu toggles */
.players-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.player-cell {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px;
    background: var(--panel-2);
    display: grid;
    gap: 8px;
}
.player-cell .pname { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.team-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.team-dot.A { background: var(--teamA); }
.team-dot.B { background: var(--teamB); }
.fo-btn {
    border: 1px solid var(--line);
    background: var(--bg-2);
    color: var(--muted);
    border-radius: 8px;
    padding: 8px;
    font-size: 12.5px;
    font-weight: 700;
}
.fo-btn.active { background: var(--good); color: #052e21; border-color: var(--good); }
.bet-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.bet-btn {
    border: 1px solid var(--line);
    background: var(--bg-2);
    color: var(--muted);
    border-radius: 8px;
    padding: 8px 4px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .03em;
}
.bet-btn.tichu.active { background: var(--gold); color: #241a00; border-color: var(--gold); }
.bet-btn.grand.active { background: var(--primary); color: #fff; border-color: var(--primary-d); }

.form-actions { display: flex; gap: 10px; }
.form-actions .btn { flex: 1; }

/* ------------------------------------------------------------- stats panel */
.tabs-row {
    display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.import-inline { flex: 0 0 auto; margin-bottom: 10px; white-space: nowrap; }
.stats-filter { flex: 0 0 auto; margin-bottom: 10px; white-space: nowrap; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
.stats-filter.is-set { color: var(--primary); border-color: var(--primary-d); }

/* date-range filter modal */
.filt-opts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filt-opt {
    flex: 1 1 auto; padding: 10px 14px; border-radius: 99px;
    background: var(--bg-2); border: 1px solid var(--line); color: var(--muted);
    font-size: 13.5px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.filt-opt.active { background: var(--primary); color: #fff; border-color: var(--primary-d); }
.filt-custom { display: flex; gap: 12px; margin-bottom: 14px; }
.filt-custom label { flex: 1; display: grid; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.filt-custom input {
    padding: 9px 10px; background: var(--bg-2); border: 1px solid var(--line);
    border-radius: var(--radius-sm); color: var(--text); font-size: 14px;
}
.tabs {
    display: flex;
    flex: 1;
    min-width: 0;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 10px;
    scrollbar-width: thin;
}
.tab {
    flex: 0 0 auto;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--muted);
    border-radius: 99px;
    padding: 8px 14px;
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary-d); }
.tab.add { font-weight: 800; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat-box {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    min-width: 0;
}
.stat-box.full { grid-column: 1 / -1; }
.stat-box h4 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-2); margin-bottom: 8px; }
.big-stat { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.big-stat small { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.chart-wrap { position: relative; height: 172px; min-width: 0; }
.chart-wrap.tall { height: 190px; }

/* who's-best-with-whom list (replaces the synergy matrix) */
.syn-list { display: grid; gap: 7px; }
.syn-row { display: grid; grid-template-columns: 20px 1fr 64px 42px 34px; align-items: center; gap: 8px; font-size: 13px; }
.syn-rank { color: var(--muted-2); font-weight: 700; text-align: center; font-size: 12px; }
.syn-pair { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.syn-bar { height: 7px; background: var(--line-soft); border-radius: 99px; overflow: hidden; }
.syn-bar > span { display: block; height: 100%; background: var(--good); border-radius: 99px; }
.syn-rate { font-weight: 800; text-align: right; }
.syn-rate.good { color: var(--good); }
.syn-rate.bad { color: var(--bad); }
.syn-wl { color: var(--muted-2); font-size: 11px; text-align: right; }

/* stat-box header with an inline segmented control */
.box-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.box-head h4 { margin: 0; }
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 99px; padding: 2px; }
.seg button { border: none; background: none; color: var(--muted); font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 99px; cursor: pointer; }
.seg button.active { background: var(--primary); color: #fff; }

/* swap modal group headings */
.swap-group { text-align: left; margin: 6px 0 6px; font-weight: 600; }

.mini-list { display: grid; gap: 8px; }
.mini-row { display: flex; align-items: center; justify-content: space-between; font-size: 14px; }
.mini-row .lbl { color: var(--muted); }
.mini-row .val { font-weight: 800; font-variant-numeric: tabular-nums; }
.mini-row .val.good { color: var(--good); }
.mini-row .val.bad { color: var(--bad); }

.dist-bar { display: flex; height: 26px; border-radius: 8px; overflow: hidden; margin-top: 8px; background: var(--line-soft); }
.dist-bar > span { display: grid; place-items: center; font-size: 11px; font-weight: 800; color: #06121f; }

/* Player creation form */
.add-form { display: grid; gap: 14px; max-width: 360px; }
.player-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px; padding: 5px 12px; font-size: 13px; color: var(--muted); }

/* -------------------------------------------------------- session setup */
.setup { max-width: 460px; }
.lineup-list { display: grid; gap: 8px; margin: 10px 0; }
.lineup-pick { display: grid; grid-template-columns: 26px 1fr; align-items: center; gap: 10px; }
.lineup-pick .seat { color: var(--muted-2); font-weight: 700; font-size: 13px; }
.lineup-pick select {
    width: 100%; padding: 11px 12px; background: var(--bg-2);
    border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--text); font-size: 15px;
}
.pairings { display: grid; gap: 6px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.pairings .pg { display: flex; gap: 8px; align-items: center; }
.pairings .gno { color: var(--muted-2); font-weight: 700; width: 52px; }

/* ------------------------------------------------------------------ modal */
.modal-root {
    position: fixed; inset: 0;
    background: rgba(3,7,18,.72);
    display: grid; place-items: center;
    padding: 24px; z-index: 60;
    backdrop-filter: blur(3px);
}
.modal {
    width: 100%; max-width: 420px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 26px;
    box-shadow: var(--shadow);
    text-align: center;
    animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal .trophy { font-size: 44px; }
.modal h2 { font-size: 22px; margin: 10px 0 6px; }
.modal p { color: var(--muted); margin: 0 0 18px; font-size: 14.5px; }
.modal .modal-actions { display: flex; gap: 10px; }
.modal .modal-actions .btn { flex: 1; }

/* ------------------------------------------------------------------ toast */
.toast {
    position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
    background: var(--panel-2); border: 1px solid var(--line);
    color: var(--text); padding: 12px 18px; border-radius: 99px;
    font-size: 14px; font-weight: 600; z-index: 80;
    box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}
.toast.err { border-color: var(--bad); color: #fecaca; }

/* ===================== NEW: condensed scorepad layout ==================== */
.section-title.mb { margin-bottom: 10px; }

.dv-toggle.tiny { font-size: 12.5px; gap: 8px; }
.switch.sm { width: 34px; height: 20px; }
.switch.sm .track::before { width: 14px; height: 14px; }
.switch.sm input:checked + .track::before { transform: translateX(14px); }

.hint-line { font-size: 12px; color: var(--muted-2); margin: 8px 0 0; }
.hint-line.tie { color: var(--gold); font-weight: 700; }

/* whole left panel = two columns: thin ledger | everything else */
.score-2col { display: flex; gap: 12px; align-items: flex-start; }
.main-col { flex: 1; min-width: 0; display: grid; gap: 12px; }
.main-col .game-meta { margin: 0; }
.main-col .hand-form { display: grid; gap: 12px; }

/* middle-left arrow that opens the past-hands drawer (mobile only) */
.ledger-toggle { display: none; }

.score-body { display: flex; gap: 12px; align-items: flex-start; }
.ledger-col { flex: 0 0 118px; width: 118px; }
.ledger-head, .lrow { display: grid; grid-template-columns: 18px 1fr 1fr; gap: 4px; align-items: center; }
.ledger-head { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); padding: 0 6px 6px; text-align: center; }
.ledger { display: grid; gap: 4px; max-height: 78vh; overflow-y: auto; padding-right: 2px; }
.lrow {
    width: 100%; text-align: center;
    background: var(--panel); border: 1px solid var(--line-soft);
    border-radius: 8px; padding: 5px 6px; cursor: pointer;
    font-variant-numeric: tabular-nums; transition: border-color .12s ease, background .12s ease;
}
.lrow:hover { border-color: var(--muted-2); background: var(--panel-2); }
.lr-n { color: var(--muted-2); font-size: 11px; }
.lr-cell { display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.lr-cell b { font-size: 13px; font-weight: 700; }
.lr-cell i { font-size: 10px; color: var(--muted); font-style: normal; }
.lr-cell b.pos { color: var(--good); }
.lr-cell b.neg { color: var(--bad); }
.dv-dot { color: var(--gold); font-weight: 900; margin-left: 2px; }

.entry-col { flex: 1; min-width: 0; }
.entry-col .hand-form { display: grid; gap: 12px; }
.complete-box { text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.complete-box .trophy.sm { font-size: 34px; }
.complete-box h3 { margin: 6px 0 2px; }
.complete-box .btn { margin-top: 12px; }

.empty-note.sm { padding: 14px 6px; font-size: 12.5px; }
.players-grid .bet-btn { padding: 7px 2px; font-size: 11px; }

/* team groups with score beside the names (bottom of the left panel) */
.players-grid.team-layout { grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; }
.team-group {
    display: grid; gap: 8px;
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius-sm); padding: 9px;
}
.team-group.teamA { border-top: 3px solid var(--teamA); }
.team-group.teamB { border-top: 3px solid var(--teamB); }
.tg-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.tg-name { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tg-score { font-size: 46px; line-height: 1; font-weight: 900; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.teamA .tg-score { color: var(--teamA); }
.teamB .tg-score { color: var(--teamB); }
.pname { width: 100%; display: flex; align-items: center; gap: 6px; }
.pname .pn-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swap-btn {
    flex: 0 0 auto; width: 22px; height: 22px; display: grid; place-items: center;
    background: var(--bg-2); border: 1px solid var(--line); border-radius: 6px;
    color: var(--muted-2); font-size: 12px; cursor: pointer; line-height: 1;
}
.swap-btn:hover { color: var(--primary); border-color: var(--primary); }

/* swap modal */
.swap-list { display: grid; gap: 8px; margin-bottom: 12px; }
.swap-opt {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--panel-2); border: 1px solid var(--line);
    border-radius: 10px; padding: 12px 14px; color: var(--text); font-weight: 600; font-size: 15px;
}
.swap-opt:hover { border-color: var(--primary); }
.swap-tag { font-size: 11px; color: var(--muted-2); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.swap-warn {
    background: rgba(248,113,113,.12); border: 1px solid var(--bad); color: #fecaca;
    padding: 10px 12px; border-radius: 10px; font-size: 13px; margin: 0 0 12px; text-align: left;
}

/* previous games button + modal */
.prev-games-btn { width: 100%; margin-bottom: 8px; padding: 6px 4px; font-size: 12px; }

/* wide modal with a persistent (sticky) header and its own scroll body */
.modal.modal-wide {
    max-width: 820px; padding: 0; text-align: left;
    display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
    position: sticky; top: 0; z-index: 2;
    display: flex; align-items: center; gap: 12px;
    padding: 14px 18px; border-bottom: 1px solid var(--line);
    background: var(--panel);
}
.modal-head .modal-title { margin: 0; flex: 1; font-size: 18px; }
.modal-head .mh-right { display: flex; align-items: center; gap: 8px; }
.modal-x {
    flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px;
    background: var(--bg-2); border: 1px solid var(--line); color: var(--muted);
    font-size: 15px; line-height: 1; cursor: pointer;
}
.modal-x:hover { color: var(--text); border-color: var(--muted-2); }
.mh-back {
    flex: 0 0 auto; background: var(--bg-2); border: 1px solid var(--line);
    color: var(--muted); border-radius: 9px; padding: 7px 12px;
    font-size: 13px; font-weight: 700; cursor: pointer;
}
.mh-back:hover { color: var(--text); border-color: var(--muted-2); }
.modal-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 16px 18px 20px; }

/* condensed, clickable game tiles */
.hist-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }
.hist-tile {
    display: grid; gap: 4px; text-align: left;
    background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
    padding: 12px; cursor: pointer; color: var(--text);
    transition: border-color .12s, transform .12s;
}
.hist-tile:hover { border-color: var(--primary-d); transform: translateY(-1px); }
.ht-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 2px; }
.ht-date { font-size: 11px; color: var(--muted-2); }
.ht-hands { font-size: 10px; color: var(--muted-2); background: var(--bg-2); border-radius: 99px; padding: 2px 7px; white-space: nowrap; }
.ht-team { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ht-team.win { color: var(--gold); }
.ht-score { margin-top: 4px; font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; display: flex; align-items: baseline; gap: 6px; }
.ht-score i { color: var(--muted-2); font-style: normal; font-weight: 600; }
.ht-score b.win { color: var(--gold); }

/* single-game detail view */
.hd-summary { margin-bottom: 14px; }
.hd-match { display: flex; align-items: center; justify-content: center; gap: 12px; text-align: center; flex-wrap: wrap; }
.hd-match .ht-team { font-size: 15px; white-space: normal; }
.hd-vs { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.hd-date { text-align: center; font-size: 11px; color: var(--muted-2); margin-top: 4px; }
.hd-table { display: grid; gap: 2px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 14px; }
.hd-row { display: grid; grid-template-columns: 24px 1fr 1fr; gap: 6px; font-size: 12px; padding: 3px 0; font-variant-numeric: tabular-nums; }
.hd-row.head { color: var(--muted-2); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
.hd-row i { color: var(--muted); font-style: normal; font-size: 10px; }
.hd-row .pos { color: var(--good); }
.hd-row .neg { color: var(--bad); }
.hd-del { width: 100%; }

/* player tab header (profile controls) */
.player-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.ph-name { font-size: 20px; font-weight: 800; }
.ph-actions { display: flex; align-items: center; gap: 12px; }
.ph-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.btn.danger { color: #fecaca; border-color: rgba(248,113,113,.4); }
.btn.danger:hover { color: #fff; background: var(--primary-d); border-color: var(--primary-d); }
.grid-2x2 .stat-box { min-height: 74px; }

/* --------------------------------------------------- modal (form variant) */
.modal { max-height: calc(100dvh - 40px); overflow-y: auto; }
.modal-form { max-width: 480px; text-align: left; }
.modal-title { font-size: 18px; margin-bottom: 12px; }
.modal-form .hand-form { display: grid; gap: 12px; }
.modal-form .form-actions { display: flex; gap: 10px; margin-top: 2px; }
.modal-form .form-actions .btn { flex: 1; }
.import-help { text-align: left; line-height: 1.6; }
.import-help code { background: var(--bg-2); padding: 2px 6px; border-radius: 6px; font-size: 12px; }
.import-samples { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.file-input { display: block; width: 100%; margin-bottom: 10px; color: var(--muted); font-size: 13px; }
.csv-text {
    width: 100%; background: var(--bg-2); border: 1px solid var(--line);
    border-radius: var(--radius-sm); color: var(--text); padding: 10px 12px;
    font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; resize: vertical;
}

/* ----------------------------------------------------- player manager */
.pm-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.pm-count { font-size: 12px; font-weight: 800; padding: 3px 10px; border-radius: 99px; }
.pm-count.ok { background: rgba(52,211,153,.15); color: var(--good); }
.pm-count.warn { background: rgba(251,191,36,.15); color: var(--gold); }
.pm-list { display: grid; gap: 8px; margin-bottom: 12px; }
.pm-row { display: flex; align-items: center; gap: 10px; }
.pm-name { flex: 1; font-weight: 600; font-size: 15px; }
.pm-name.benched { color: var(--muted-2); }
.pm-bench {
    flex: 0 0 auto; padding: 5px 12px; border-radius: 99px;
    background: var(--bg-2); border: 1px solid var(--line); color: var(--muted);
    font-size: 12px; font-weight: 700; line-height: 1; cursor: pointer;
}
.pm-bench:hover { color: var(--gold); border-color: var(--gold); }
.pm-add { display: flex; gap: 8px; }
.pm-add input {
    flex: 1; padding: 10px 12px; background: var(--bg-2); border: 1px solid var(--line);
    border-radius: var(--radius-sm); color: var(--text); font-size: 15px;
}
.pm-add .btn { flex: 0 0 auto; }

/* ----------------------------------------------------- stats toolbar */
.stats-toolbar { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 10px; }

/* --------------------------------------------------------- bottom nav */
.bottom-nav { display: none; }

/* ============================== RESPONSIVE ============================== */
@media (max-width: 860px) {
    .split { display: block; }
    .panel { border: none !important; padding: 14px 12px 96px; }
    /* Toggle views on mobile */
    body[data-view="score"] .panel-stats { display: none; }
    body[data-view="stats"] .panel-score { display: none; }

    /* Past hands become a slide-in drawer with a middle-left arrow tab. */
    .ledger-toggle {
        display: grid; place-items: center;
        position: fixed; left: 0; top: 50%; transform: translateY(-50%);
        width: 26px; height: 54px; z-index: 36;
        background: var(--panel-2); color: var(--muted);
        border: 1px solid var(--line); border-left: none;
        border-radius: 0 12px 12px 0; box-shadow: 2px 0 8px rgba(0,0,0,.25);
        font-size: 16px; cursor: pointer;
        transition: left .2s ease;
    }
    .ledger-toggle .lt-ico { transition: transform .2s ease; line-height: 1; }
    .ledger-col {
        position: fixed; top: 54px; bottom: 66px; left: 0;
        width: 150px; z-index: 35;
        background: var(--bg-2); border-right: 1px solid var(--line);
        padding: 12px 10px; overflow-y: auto;
        transform: translateX(-100%); transition: transform .2s ease;
    }
    .ledger { max-height: none; }
    .score-2col.ledger-open .ledger-col { transform: translateX(0); box-shadow: 6px 0 22px rgba(0,0,0,.45); }
    .score-2col.ledger-open .ledger-toggle { left: 150px; }
    .score-2col.ledger-open .ledger-toggle .lt-ico { transform: rotate(180deg); }

    .bottom-nav {
        display: flex;
        position: fixed; left: 0; right: 0; bottom: 0;
        background: rgba(15,23,42,.92);
        backdrop-filter: blur(10px);
        border-top: 1px solid var(--line);
        padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
        z-index: 40;
    }
    .bn-item {
        flex: 1;
        display: grid; gap: 3px; justify-items: center;
        background: none; border: none; color: var(--muted-2);
        font-size: 11.5px; font-weight: 700; padding: 6px;
    }
    .bn-item .bn-ico { font-size: 20px; line-height: 1; }
    .bn-item.is-active { color: var(--primary); }
    .stat-grid { grid-template-columns: 1fr; }

    /* ----------------------------------------- slightly larger mobile text */
    .btn { font-size: 16px; }
    .btn-sm { font-size: 14px; }
    .group-label { font-size: 15px; }
    .pill { font-size: 13px; }
    .team-names { font-size: 14.5px; }
    .team-total { font-size: 36px; }
    .base-field input { font-size: 23px; }
    .base-field select { font-size: 21px; }
    .dv-toggle { font-size: 14.5px; }
    .player-cell .pname { font-size: 15px; }
    .fo-btn { font-size: 13.5px; }
    .bet-btn { font-size: 13px; }
    .pm-name { font-size: 16px; }
    .ledger-head { font-size: 11px; }
    .lr-n { font-size: 12px; }
    .lr-cell b { font-size: 14px; }
    .lr-cell i { font-size: 11px; }
    .big-stat { font-size: 27px; }
    .big-stat small { font-size: 14px; }
    .stat-sub { font-size: 13px; }
    .mini-row { font-size: 15px; }
    .chip { font-size: 14px; }
    .tg-name { font-size: 13px; }
    .tg-score { font-size: 48px; }
}
@media (min-width: 861px) {
    body[data-view] .panel-score,
    body[data-view] .panel-stats { display: block; }

    /* --------------------------------------------------- full-screen mode */
    body.fs-mode .panel-stats { display: none; }
    body.fs-mode .panel-score { border-right: none; }
    body.fs-mode .main-col { max-width: 780px; margin: 0 auto; width: 100%; }
    body.fs-mode .ledger-col { flex: 0 0 260px; width: 260px; }
    body.fs-mode .ledger { max-height: calc(100dvh - 210px); }
    body.fs-mode .ledger-head { font-size: 12px; padding-bottom: 8px; }
    body.fs-mode .lrow { padding: 9px 10px; }
    body.fs-mode .lr-n { font-size: 13px; }
    body.fs-mode .lr-cell b { font-size: 17px; }
    body.fs-mode .lr-cell i { font-size: 12px; }
}
@media (max-width: 860px) {
    #fullscreen-toggle { display: none; }
}
