:root {
    --bg: #0f172a;
    --bg-2: #111c33;
    --card: #1e293b;
    --line: #334155;
    --text: #f8fafc;
    --muted: #94a3b8;
    --red: #e31837;
    --red-2: #be123c;
    --good: #166534;
    --good-ink: #bbf7d0;
    --bad: #991b1b;
    --bad-ink: #fecaca;
    --gold: #fde047;
    --blue: #38bdf8;
    --shadow: 0 16px 40px rgba(2, 6, 23, .35);
    --safe-top: env(safe-area-inset-top);
    --safe-bot: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
    font-family: Barlow, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.35;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}
a { color: var(--blue); }

#screen-library, #screen-setup, #screen-court { display: none; }
#screen-library.on, #screen-setup.on { display: block; }
#screen-court.on {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}
body.court-open { overflow: hidden; overscroll-behavior: none; background: #0b1220; }

.wrap { width: min(920px, 100%); margin: 0 auto; padding: calc(18px + var(--safe-top)) 16px 48px; }
.brand { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 18px; flex-wrap: wrap; }
.brand > div:first-child { flex: 1 1 16rem; min-width: 0; }
.brand h1, .wrap > h1 { margin: 0 0 8px; font-size: 2rem; letter-spacing: -0.03em; line-height: 1.05; }
.eyebrow { color: var(--gold); font-weight: 800; letter-spacing: .14em; text-transform: uppercase; font-size: .72rem; margin: 0 0 6px; }
.lede { color: var(--muted); margin: 8px 0 0; max-width: 38rem; }
.account { text-align: left; color: var(--muted); font-size: .92rem; overflow-wrap: anywhere; }
@media (min-width: 720px) { .account { text-align: right; margin-left: auto; } }
.account a { font-weight: 800; }

.actions { display: grid; gap: 10px; margin: 18px 0; }
@media (min-width: 720px) { .actions { grid-template-columns: 1.3fr .7fr; } }

.btn {
    border: 0;
    border-radius: 14px;
    min-height: 52px;
    padding: 12px 14px;
    font-weight: 800;
    background: var(--card);
    color: var(--text);
    text-align: left;
}
.btn strong { display: block; font-size: 1.05rem; }
.btn span { display: block; color: var(--muted); font-weight: 600; font-size: .9rem; margin-top: 2px; white-space: normal; }
.btn.primary { background: var(--red); color: white; }
.btn.primary span { color: rgba(255,255,255,.82); }
.btn.ghost { background: transparent; border: 1px solid var(--line); text-align: center; }
.btn.danger { background: #3f1218; color: #fecaca; }
.btn.full { width: 100%; text-align: center; }
.btn:active { transform: translateY(1px); }

.card-list { display: grid; gap: 10px; }
.lib-head { font-size: 1.15rem; margin: 14px 0 0; }
.lib-hint { margin: 2px 0 4px; }
.card {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    background: var(--card);
    border: 1px solid #243044;
    border-radius: 16px;
    padding: 8px;
    box-shadow: var(--shadow);
}
.card-open {
    background: transparent;
    border: 0;
    color: inherit;
    text-align: left;
    padding: 8px;
    min-width: 0;
}
.card-kicker { color: var(--gold); font-size: .75rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.card-title { font-size: 1.15rem; font-weight: 800; margin-top: 3px; }
.card-score { font-family: "Barlow Condensed", Barlow, sans-serif; font-size: 1.7rem; letter-spacing: .02em; margin-top: 2px; }
.card-meta { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.live-dot { color: #fb7185; font-weight: 800; }
.card-side { display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.card-side button, .text-btn {
    background: transparent;
    border: 0;
    color: var(--muted);
    font-weight: 700;
    padding: 8px;
}
.empty {
    border: 1px dashed var(--line);
    border-radius: 16px;
    padding: 22px 16px;
    color: var(--muted);
}
.footer-links { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 28px; font-size: .92rem; font-weight: 700; }
.banner {
    background: #172033;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    color: var(--muted);
    margin-bottom: 12px;
}

.back-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
h2 { margin: 0 0 8px; font-size: 1.6rem; }
.stack { display: grid; gap: 10px; }
.pick, .list-row {
    width: 100%;
    text-align: left;
    background: var(--card);
    color: var(--text);
    border: 1px solid #243044;
    border-radius: 14px;
    padding: 12px;
    min-height: 64px;
}
.pick.on { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.list-row small, .pick small { display: block; color: var(--muted); font-weight: 600; margin-top: 3px; }
.status-pill {
    display: inline-block;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
    background: #334155;
    color: white;
}
.status-pill.progress { background: var(--red); }
.status-pill.complete { background: #166534; }
.search {
    width: 100%;
    background: #0b1220;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    margin: 8px 0 12px;
}
.field { display: grid; gap: 4px; margin-bottom: 10px; }
.field span, .check { font-size: .78rem; font-weight: 800; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.grid-2 { display: grid; gap: 10px; }
@media (min-width: 700px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
input, select, textarea {
    width: 100%;
    background: #0b1220;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
}
textarea { min-height: 74px; resize: vertical; }
.rule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.hint { color: var(--muted); font-size: .88rem; margin: 4px 0 12px; }
.check { display: flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: 1rem; color: var(--text); font-weight: 700; margin: 8px 0; }
.check input { width: auto; }
.partner { display: none; }
.is-doubles .partner { display: block; }
.seg { display: flex; background: #0b1220; padding: 4px; border-radius: 12px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted); border-radius: 10px; min-height: 42px; font-weight: 800; }
.seg button.on { background: white; color: #0f172a; }

.topbar, .scorebug { padding-left: 12px; padding-right: 12px; }
.topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: calc(8px + var(--safe-top));
}
.topbar .grow { flex: 1; min-width: 0; }
.icon-btn, .tab, .ptt-toggle, .mark, .star, .side-name {
    touch-action: manipulation;
    user-select: none;
}
.icon-btn {
    background: #1e293b;
    color: white;
    border: 0;
    border-radius: 999px;
    min-height: 40px;
    padding: 0 12px;
    font-weight: 800;
}
.wide-only { display: none; }
.top-event { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-state { color: var(--muted); font-size: .78rem; font-weight: 700; }

.scorebug { padding-top: 2px; padding-bottom: 4px; }
.bug {
    display: grid;
    grid-template-columns: minmax(0,1fr) auto minmax(0,1fr);
    gap: 6px;
    align-items: center;
}
.side-name {
    background: transparent;
    border: 0;
    color: white;
    padding: 4px;
    min-width: 0;
}
.side-name.right { text-align: right; }
.side-name .who { display: block; font-weight: 800; font-size: .95rem; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-name .meta { display: block; color: var(--muted); font-size: .7rem; font-weight: 700; min-height: 0; }
.side-name.serving .meta { color: var(--gold); }
.nums { display: flex; align-items: center; gap: 8px; }
.big {
    font-family: "Barlow Condensed", Barlow, sans-serif;
    font-size: clamp(1.7rem, 6vw, 2.15rem);
    line-height: .85;
    font-weight: 800;
    min-width: 1.2ch;
    text-align: center;
}
.game-no { color: var(--gold); font-weight: 800; letter-spacing: .06em; font-size: .85rem; }
.score-meta { display: flex; flex-wrap: wrap; gap: 2px 12px; }
.games-line, .rule-line { color: var(--muted); font-size: .75rem; font-weight: 700; margin: 0; }
.games-line { color: var(--text); }
.point-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }
.point-row button {
    min-height: 36px;
    border: 0;
    border-radius: 12px;
    font-weight: 800;
    background: #1d4ed8;
    color: white;
}
.point-row .live-pill {
    grid-column: 1 / -1;
    background: #172033;
    color: var(--gold);
    border-radius: 10px;
    padding: 6px 10px;
    font-weight: 800;
    font-size: .85rem;
}
.court-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chart-wrap { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 0 12px 12px; }
.notes-pane, .summary-pane { display: none; min-height: 0; }
.notes-pane { flex-direction: column; }
.summary-pane { overflow: auto; padding: 0 12px 12px; }
#screen-court.tab-notes .chart-wrap { display: none; }
#screen-court.tab-notes .notes-pane { display: flex; flex: 1; }
#screen-court.tab-summary .chart-wrap { display: none; }
#screen-court.tab-summary .summary-pane { display: block; flex: 1; }

.chart-tools { position: sticky; top: 0; z-index: 2; background: #0b1220; padding-top: 2px; }
.chart-wrap.is-dual .side-switch,
.chart-wrap.is-solo .side-switch { display: none; }
.filters, .tally, .side-switch, .chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; }
.chip, .filters button, .tally button, .side-switch button {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    border-radius: 999px;
    padding: 8px 12px;
    font-weight: 800;
    white-space: nowrap;
}
.chip { background: #172033; }
.filters button.on, .tally button.on, .side-switch button.on { background: white; color: #0f172a; border-color: white; }
.shot-head { font-weight: 800; margin: 2px 0 4px; font-size: .92rem; }
.shot-group { margin: 6px 0 2px; color: var(--gold); font-size: .68rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.shot-group.serve { color: #7dd3fc; }
.shot-group.play { color: #fbbf24; }
.shot.serve { background: #15283f; box-shadow: inset 3px 0 0 #38bdf8; }
.shot.play { background: #2c2414; box-shadow: inset 3px 0 0 #f59e0b; }
.shot {
    display: grid;
    grid-template-columns: 36px minmax(0,1fr) 58px 58px;
    gap: 6px;
    align-items: center;
    background: var(--card);
    border-radius: 14px;
    padding: 6px;
    margin-bottom: 8px;
}
.star { width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; color: #64748b; font-size: 1.2rem; }
.star.on { color: var(--gold); }
.shot-name { font-weight: 800; min-width: 0; }
.shot-stat { color: var(--muted); font-size: .8rem; font-weight: 700; }
.shot-stat:empty { display: none; }
.mark { height: 58px; border: 0; border-radius: 12px; font-size: 1.6rem; font-weight: 800; }
.mark.good { background: var(--good); color: var(--good-ink); }
.mark.bad { background: var(--bad); color: var(--bad-ink); }
.mark:active { transform: scale(.96); }
.add-shot { display: flex; gap: 8px; margin: 8px 0 18px; }
.add-shot input { flex: 1; }
.add-shot button { border: 0; border-radius: 12px; background: white; color: #0f172a; font-weight: 800; padding: 0 14px; }
.shot-cols { display: grid; gap: 8px; }
.empty-watch { color: var(--muted); padding: 8px 0 16px; }

.note-list { flex: 1; overflow: auto; overscroll-behavior: contain; padding: 0 12px; }
.note {
    border-left: 3px solid #475569;
    padding: 8px 8px 8px 10px;
    margin: 0 0 8px;
    background: #121a2b;
    border-radius: 0 12px 12px 0;
}
.note.umpire { border-left-color: var(--gold); }
.note.voice { border-left-color: var(--red); }
.note-top { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .75rem; font-weight: 800; }
.note-text { margin-top: 3px; white-space: pre-wrap; }
.note audio { width: 100%; margin-top: 6px; height: 36px; }
.note-compose { padding: 8px 12px 0; }
.dock {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    align-items: stretch;
    padding: 8px 10px calc(8px + var(--safe-bot));
    background: #0b1220;
    border-top: 1px solid #243044;
    overscroll-behavior: none;
}
.dock .ptt { grid-column: 1 / 3; }
.tab { flex: 1; background: transparent; color: var(--muted); border: 0; font-weight: 800; min-height: 52px; border-radius: 12px; }
.tab.on { color: white; background: #1e293b; }
.ptt, .ptt-toggle { border: 0; border-radius: 14px; font-weight: 800; min-height: 52px; }
.ptt {
    flex: 1.4;
    background: var(--red);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
.ptt.hot { background: #7f1d1d; }
.ptt-toggle { background: #1e293b; color: white; padding: 0 12px; }

#toast {
    position: fixed;
    left: 50%;
    bottom: calc(148px + var(--safe-bot));
    transform: translateX(-50%);
    z-index: 70;
    background: white;
    color: #0f172a;
    border-radius: 999px;
    padding: 8px 8px 8px 14px;
    display: flex;
    gap: 8px;
    align-items: center;
    font-weight: 800;
    box-shadow: var(--shadow);
    max-width: calc(100% - 24px);
}
#toast button { border: 0; background: #0f172a; color: white; border-radius: 999px; padding: 8px 12px; font-weight: 800; }
#recbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 80;
    background: var(--red);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: calc(10px + var(--safe-top)) 12px 10px;
    font-weight: 800;
}
#recbar button { border: 0; background: white; color: var(--red); border-radius: 999px; padding: 8px 12px; font-weight: 800; }

#sheet {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(2, 6, 23, .72);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}
.panel {
    background: #f8fafc;
    color: #0f172a;
    width: min(680px, 100%);
    max-height: min(92dvh, 920px);
    overflow: auto;
    border-radius: 18px 18px 0 0;
    padding: 16px 16px calc(18px + var(--safe-bot));
}
.panel h3 { margin: 0 0 12px; }
.panel .field span, .panel .hint, .panel .check { color: #334155; }
.panel .check { color: #0f172a; text-transform: none; letter-spacing: 0; font-size: 1rem; }
.send-list { display: grid; gap: 8px; max-height: min(42vh, 380px); overflow: auto; margin: 8px 0 12px; }
.send-item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: start; color: #0f172a; font-weight: 700; }
.send-item small { display: block; color: #64748b; font-size: .78rem; }
.send-item input { margin-top: 4px; }
.share-link { width: 100%; margin-bottom: 8px; }
.report h1 { margin: 0 0 8px; font-size: 1.8rem; line-height: 1.1; }
.report .note { margin-top: 8px; }
.report audio { width: 100%; margin-top: 6px; }
.panel input, .panel select, .panel textarea { background: white; color: #0f172a; border-color: #cbd5e1; }
.panel .btn.ghost { color: #0f172a; }
.sheet-actions { display: grid; gap: 8px; margin-top: 12px; }
.sum-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.sum-table th, .sum-table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid #243044; }
.summary-pane .sum-table th, .summary-pane .sum-table td { border-bottom-color: #243044; }
.panel .sum-table th, .panel .sum-table td { border-bottom-color: #e2e8f0; }
.who-mine { color: var(--gold); font-weight: 800; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }

@media (min-width: 800px) {
    #sheet { align-items: center; padding: 24px; }
    .panel { border-radius: 18px; }
}
@media (min-width: 1000px) {
    .wide-only { display: inline-block; }
    #toast { bottom: calc(84px + var(--safe-bot)); }
    .dock { grid-template-columns: 1fr auto; }
    .dock .tab { display: none; }
    .dock .ptt { grid-column: auto; }
    .court-main { display: grid; grid-template-columns: minmax(0, 1fr) 240px; }
    .note-compose textarea { min-height: 48px; }
    #screen-court .chart-wrap { display: block !important; }
    #screen-court .notes-pane { display: flex !important; border-left: 1px solid #243044; }
    #screen-court .summary-pane { display: none !important; }
}
@media (min-width: 768px) {
    .chart-tools { display: flex; align-items: center; gap: 8px; }
    .chart-tools .filters,
    .chart-tools .tally { flex: 0 1 auto; padding-bottom: 2px; }
    .chart-tools .filters { flex: 1 1 auto; }
    .filters button, .tally button, .side-switch button { padding: 4px 8px; font-size: .8rem; }
    .shot-cols.dual { grid-template-columns: 1fr 1fr; gap: 8px 12px; align-items: start; }
    .shot-cols.solo section,
    .shot-cols.dual section { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 6px; align-content: start; }
    .shot-cols.solo .shot-head,
    .shot-cols.solo .shot-group,
    .shot-cols.solo .empty-watch,
    .shot-cols.dual .shot-head,
    .shot-cols.dual .shot-group,
    .shot-cols.dual .empty-watch { grid-column: 1 / -1; }
    .shot-cols.solo .shot-group,
    .shot-cols.dual .shot-group { margin: 2px 0 0; }
    .shot {
        grid-template-columns: 22px minmax(0, 1fr) 34px 34px;
        gap: 4px;
        padding: 1px 2px;
        margin: 0;
        border-radius: 8px;
    }
    .shot > div { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
    .shot-name { flex: 1 1 auto; font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .shot-stat { flex: 0 0 auto; font-size: .68rem; white-space: nowrap; }
    .star { width: 22px; height: 22px; font-size: .95rem; }
    .mark { height: 30px; border-radius: 8px; font-size: 1rem; }
    .add-shot { grid-column: 1 / -1; margin: 6px 0 8px; }
}

@media print {
    body * { visibility: hidden; }
    #sheet, #sheet * { visibility: visible; }
    #sheet { position: static; background: white; }
    .panel { max-height: none; box-shadow: none; }
}
