/* Cribbage League. Colors are tokens; dark mode redefines them below. */
:root {
    --bg: #f4f0e6;
    --surface: #fffdf8;
    --surface-2: #f3eee2;
    --ink: #1e2a24;
    --muted: #6a6f66;
    --line: #e3dccb;
    --felt: #1f5240;
    --felt-2: #2b6b54;
    --felt-ink: #f6f2e8;
    --wood: #a0703f;
    --win: #1d7a4c;
    --win-bg: #e1f1e7;
    --loss: #b3402e;
    --loss-bg: #f8e4df;
    --close: #9a6512;
    --close-bg: #f8ecd4;
    --skunk-bg: #23262a;
    --skunk-ink: #f6f6f2;
    --focus: #2f7dd1;
    --shadow: 0 1px 2px rgba(40, 32, 16, .06), 0 4px 16px rgba(40, 32, 16, .05);
    --radius: 12px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111613;
        --surface: #182019;
        --surface-2: #1f2921;
        --ink: #e9e5da;
        --muted: #9aa196;
        --line: #2c372f;
        --felt: #173f31;
        --felt-2: #2f7a5c;
        --felt-ink: #eef0e8;
        --wood: #c99460;
        --win: #5cc995;
        --win-bg: #1c3a2b;
        --loss: #ec8a76;
        --loss-bg: #42231e;
        --close: #e6b35a;
        --close-bg: #3d3018;
        --skunk-bg: #e9e5da;
        --skunk-ink: #15181a;
        --focus: #6aa8ee;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3);
        color-scheme: dark;
    }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
h1:focus { outline: none; }

a { color: var(--felt-2); text-decoration: none; }
a:hover { text-decoration: underline; }
@media (prefers-color-scheme: dark) { a { color: var(--win); } }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.win-text { color: var(--win); }
.loss-text { color: var(--loss); }
.close-text { color: var(--close); }

/* ---------- header / footer ---------- */

.site-header {
    background: var(--felt);
    color: var(--felt-ink);
    box-shadow: inset 0 -3px 0 var(--wood);
}

.site-header-inner {
    max-width: 1320px;
    margin: 0 auto;
    padding: 12px 16px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
    flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--felt-ink); }
.brand:hover { text-decoration: none; }
.brand-name { font-size: 1.2rem; font-weight: 700; letter-spacing: .01em; }
.brand-mark { width: 40px; height: 24px; flex: none; }
.brand-mark rect { fill: var(--wood); }
.brand-mark .holes circle { fill: rgba(0, 0, 0, .35); }
.brand-mark .peg { fill: #e44b3a; }
.brand-mark .peg-2 { fill: #f3efe4; }

.admin-nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.admin-nav a, .nav-button {
    color: var(--felt-ink);
    padding: 6px 10px;
    border-radius: 8px;
    font: inherit;
    font-size: .92rem;
    opacity: .85;
}
.admin-nav a:hover, .nav-button:hover { opacity: 1; text-decoration: none; background: rgba(255, 255, 255, .1); }
.admin-nav a.active { opacity: 1; background: rgba(255, 255, 255, .16); }
.logout-form { margin: 0; }
.nav-button { background: none; border: 0; cursor: pointer; }

.site-main { flex: 1; width: 100%; max-width: 1320px; margin: 0 auto; padding: 20px 16px 32px; }

.site-footer { text-align: center; padding: 12px 16px 24px; font-size: .82rem; }
.site-footer a { color: var(--muted); }

/* ---------- cards / buttons / badges ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    min-width: 0;
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-title { margin-bottom: 12px; }
.narrow-card { max-width: 420px; margin: 24px auto; }
.narrow-card h1 { margin-bottom: 8px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    font: inherit;
    font-weight: 600;
    font-size: .9rem;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: .84rem; }
.btn-primary { background: var(--felt-2); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--felt); }
.btn-outline { background: transparent; color: var(--ink); border-color: var(--line); text-transform: uppercase; letter-spacing: .06em; font-size: .78rem; }
.btn-outline:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger-ghost { background: transparent; color: var(--loss); }
.btn-danger-ghost:hover { background: var(--loss-bg); }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); text-decoration: none; }
.icon-btn.is-disabled { opacity: .3; cursor: default; }

.badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 700;
    letter-spacing: .02em;
    white-space: nowrap;
    vertical-align: middle;
}
.badge.win { background: var(--win-bg); color: var(--win); }
.badge.loss { background: var(--loss-bg); color: var(--loss); }
.badge.close { background: var(--close-bg); color: var(--close); }
.badge.skunk { background: var(--skunk-bg); color: var(--skunk-ink); }
.badge.active { background: var(--win-bg); color: var(--win); }
.badge.inactive { background: var(--surface-2); color: var(--muted); }

.empty { color: var(--muted); padding: 16px 0; margin: 0; }
.notice { background: var(--close-bg); color: var(--ink); border-radius: 8px; padding: 10px 14px; }
.form-error { color: var(--loss); background: var(--loss-bg); border-radius: 8px; padding: 8px 12px; margin: 12px 0 0; }
.form-ok { color: var(--win); background: var(--win-bg); border-radius: 8px; padding: 8px 12px; margin: 12px 0 0; }
.form-error-inline { color: var(--loss); font-size: .84rem; font-weight: 600; }
.validation-message { color: var(--loss); font-size: .84rem; margin-top: -6px; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }

.data-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.data-table th {
    text-align: left;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 8px 8px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.data-table td { padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.num { text-align: right !important; }

.standings .rank { color: var(--muted); width: 1%; }
.standings .name-col { position: sticky; left: 0; background: var(--surface); z-index: 1; font-weight: 600; min-width: 140px; }
.standings tbody tr:hover .name-col { background: var(--surface-2); }
.standings th.name-col { background: var(--surface); }
.standings .pts { font-weight: 800; color: var(--ink); background: var(--surface-2); }
.standings th.pts { color: var(--ink); }
.standings .ext { color: var(--muted); }
.standings .ext.win-text { color: var(--win); }
.standings .ext.loss-text { color: var(--loss); }
.standings .ext-first { border-left: 2px solid var(--line); }
.standings tbody tr:nth-child(-n+3) .rank { color: var(--wood); font-weight: 800; }

/* Phones: tighten so the collapsed table (through PTS) fits without scrolling. */
@media (max-width: 520px) {
    .card { padding: 14px 12px; }
    .data-table th, .data-table td { padding: 7px 4px; }
    .standings .name-col { min-width: 0; }
}

.legend { color: var(--muted); font-size: .78rem; margin: 12px 0 0; line-height: 1.7; }
.legend b { color: var(--ink); font-weight: 700; }

/* ---------- public page ---------- */

.home-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.75fr) minmax(300px, 1fr);
    gap: 20px;
    align-items: start;
}
.side-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.side-col .card + .card { margin-top: 0; }

@media (max-width: 980px) {
    .home-grid { grid-template-columns: minmax(0, 1fr); }
}

.calendar { user-select: none; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-title { font-weight: 700; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: .72rem; font-weight: 700; color: var(--muted); padding: 2px 0 4px; }
.cal-day {
    position: relative;
    aspect-ratio: 1 / .86;
    min-height: 34px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: .9rem;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}
.cal-day:hover { background: var(--surface-2); }
.cal-day.has-matches { font-weight: 700; background: var(--win-bg); }
.cal-day.is-today { box-shadow: inset 0 0 0 2px var(--wood); }
.cal-day.is-selected { background: var(--felt-2); color: #fff; }
.cal-peg {
    position: absolute;
    left: 50%;
    bottom: 5px;
    width: 6px;
    height: 6px;
    margin-left: -3px;
    border-radius: 50%;
    background: var(--loss);
}
.cal-day.is-selected .cal-peg { background: #fff; }

.night-head h2 { flex: 1; text-align: center; font-size: 1rem; }

.round-title {
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--wood);
    margin: 14px 0 6px;
}
.round-title:first-of-type { margin-top: 0; }

.match-list { list-style: none; margin: 0; padding: 0; }
.match-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    column-gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid var(--line);
}
.match-row:last-child { border-bottom: 0; }
.m-name { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-left { text-align: right; }
.m-name.is-winner { font-weight: 700; }
.m-score {
    display: flex;
    gap: 6px;
    justify-content: center;
    min-width: 76px;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}
.m-score .is-winner { color: var(--win); font-weight: 800; }
.m-dash { color: var(--line); }
.m-tags { grid-column: 1 / -1; display: flex; gap: 6px; justify-content: center; margin-top: 3px; }

/* ---------- player dialog ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(10, 14, 12, .55);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 5vh 16px;
    overflow-y: auto;
}
.modal {
    width: 100%;
    max-width: 780px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
    padding: 20px;
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.modal-head h2 { font-size: 1.35rem; }
.modal-head p { margin: 2px 0 0; }
@media (max-width: 600px) {
    .modal-backdrop { padding: 0; }
    .modal { border-radius: 0; min-height: 100%; }
}

.record-strip { display: flex; gap: 12px; margin-bottom: 14px; }
.record-big {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface-2);
    border-radius: 10px;
    padding: 10px 14px;
}
.record-big .value { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.record-big .label { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* Nine stats: always 3 x 3 so no tile is orphaned; tighter type on phones. */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 0 0 18px;
}
@media (max-width: 520px) {
    .modal { padding: 16px 12px; }
    .stat-grid { gap: 6px; }
    .stat-grid div { padding: 6px 8px; }
    .stat-grid dt { font-size: .7rem; line-height: 1.25; }
}
.stat-grid div { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.stat-grid dt { font-size: .74rem; color: var(--muted); }
.stat-grid dd { margin: 0; font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.section-title { margin-bottom: 6px; }
.player-matches .score-cell { font-weight: 600; }

/* ---------- admin ---------- */

.admin-page { max-width: 1100px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 0; }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 16px; }
.two-col .card + .card { margin-top: 0; }

input, select {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    min-height: 36px;
    padding: 4px 10px;
    max-width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }

.stack-form { display: flex; flex-direction: column; gap: 12px; }
.stack-form label { display: flex; flex-direction: column; gap: 4px; font-size: .86rem; font-weight: 600; }
.stack-form button { align-self: flex-start; }

.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { display: flex; flex-direction: column; gap: 4px; font-size: .86rem; font-weight: 600; flex: 1 1 180px; }

.date-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.date-bar label { font-weight: 600; font-size: .9rem; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: .84rem;
    cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip.is-active { background: var(--felt-2); border-color: var(--felt-2); color: #fff; }
.chip-count { font-size: .74rem; opacity: .7; font-variant-numeric: tabular-nums; }

.night-title { font-size: 1.05rem; font-weight: 700; margin: 4px 0 12px; }

.round-card .card-head { margin-bottom: 6px; }
.entry-table { width: 100%; border-collapse: collapse; }
.entry-table th {
    text-align: left;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 6px;
    white-space: nowrap;
}
.entry-table td { padding: 5px 6px; vertical-align: middle; }
.entry-table select { width: 100%; min-width: 170px; }
.entry-table .score-input { width: 78px; text-align: right; font-variant-numeric: tabular-nums; }
.entry-table .vs { color: var(--muted); font-size: .8rem; text-align: center; padding: 0 2px; }
.entry-table .result-cell { min-width: 190px; }
.entry-table .result-cell > * + * { margin-left: 4px; }
.entry-table .draft-row td { background: var(--surface-2); }
.entry-table .draft-row td:first-child { border-radius: 8px 0 0 8px; }
.entry-table .draft-row td:last-child { border-radius: 0 8px 8px 0; }
.entry-table .is-dirty td { background: var(--close-bg); }

.actions { text-align: right; white-space: nowrap; }
.actions-col { width: 1%; }
.error-row td { color: var(--loss); font-size: .86rem; font-weight: 600; padding: 0 6px 8px !important; border-bottom: 0; }
.players-table input { width: 100%; min-width: 120px; }
.is-inactive td { color: var(--muted); }

/* ---------- Blazor plumbing ---------- */

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem 1rem 1rem 1.25rem;
    color: white;
}
.blazor-error-boundary::after { content: "An error has occurred."; }
