:root {
    --bg: #f4f1ea;
    --surface: #ffffff;
    --text: #1d1d1b;
    --muted: #6b6a66;
    --accent: #14532d;
    --accent-text: #ffffff;
    --border: #d9d5cb;
    --selected: #dcefe2;
    --red: #b42318;
    --vul: #fde2df;
    --warn: #9a3412;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121412;
        --surface: #1c1f1c;
        --text: #ecebe6;
        --muted: #a3a29c;
        --accent: #3f9c62;
        --accent-text: #08130c;
        --border: #343832;
        --selected: #23412e;
        --red: #ff7a6b;
        --vul: #4a2420;
        --warn: #fdba74;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 17px;
    line-height: 1.4;
    -webkit-text-size-adjust: 100%;
}

.shell { max-width: 560px; margin: 0 auto; padding: 16px 16px 48px; }

h1 { font-size: 1.7rem; margin: 0.2rem 0 0.6rem; }
h2 { font-size: 1.15rem; margin: 1.2rem 0 0.5rem; }
h3 { font-size: 0.95rem; margin: 0 0 0.3rem; }
h1:focus { outline: none; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 14px;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.label { margin: 0.9rem 0 0.3rem; font-weight: 600; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.75rem; color: var(--muted); margin: 0; }
.error { color: var(--red); }
.red { color: var(--red); }

button {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    min-height: 44px;
    cursor: pointer;
}
button.selected { background: var(--selected); border-color: var(--accent); font-weight: 600; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); width: 100%; margin-top: 12px; font-weight: 600; }
button.primary:disabled { opacity: 0.4; cursor: default; }
button.danger { color: var(--red); }
button.link { border: none; background: none; color: var(--accent); padding: 6px 0; min-height: auto; font-weight: 600; }
button.down { color: var(--red); }
button small { color: var(--muted); }

input {
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    min-width: 0;
}
input[type=number] { width: 5em; }

.seats { display: grid; gap: 8px; }
.seats label { display: grid; grid-template-columns: 4.5em 1fr; align-items: center; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 10px 0; }
.row.check { justify-content: flex-start; }
.row.check input { width: 22px; height: 22px; flex-shrink: 0; }

.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choices button { flex: 1 1 auto; }
.levels, .outcomes { display: grid; grid-template-columns: repeat(7, 1fr); }
.levels button, .outcomes button { padding: 10px 0; min-width: 0; }
.suit-btn { font-size: 1.4rem; }
button.wide { width: 100%; margin-top: 8px; }
.dealing { text-align: center; }
.deal-group { list-style: none; padding: 0; margin: 16px 0 4px; display: grid; gap: 8px; text-align: left; }
.deal-group li { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.deal-group .dir { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.deal-group .who { font-size: 1.1rem; color: var(--muted); }
.deal-group.single li { flex-direction: column; align-items: center; border: none; padding: 20px 0 8px; }
.deal-group.single .dir { font-size: 2.4rem; }
.ranks { display: grid; grid-template-columns: repeat(7, 1fr); margin-top: 6px; }
.ranks button { padding: 10px 0; min-width: 0; }
.link-row { display: flex; justify-content: space-between; margin-top: 6px; }
.pile-tops { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; text-align: left; }
.pile-tops li { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.pile-tops .top-card { font-size: 1.4rem; font-weight: 700; }
button.next { min-height: 88px; font-size: 1.4rem; }
.summary { display: grid; gap: 12px; margin: 8px 0 4px; }
.summary .points { display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.summary .points strong { font-size: 3rem; }
.summary .lengths { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.summary .lengths div { border: 1px solid var(--border); border-radius: 10px; padding: 8px 0; display: flex; flex-direction: column; align-items: center; }
.summary .lengths strong { font-size: 1.8rem; }
.summary .lengths span { font-size: 1.3rem; }
.declarers { display: grid; grid-template-columns: 1fr 1fr; }
.card > h2:first-child { margin-top: 0; }

.bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; color: var(--muted); }

.handover { text-align: center; padding: 32px 16px; }
.handover h1 { font-size: 2.4rem; }

.private { border: 2px solid var(--accent); }
.big { font-size: 1.4rem; font-weight: 700; margin: 0.3rem 0; }
.warn { color: var(--warn); }
.arrow-map { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.arrow-map li { display: flex; align-items: center; gap: 12px; font-size: 1.1rem; }
.arrow-map .arrow { font-size: 1.8rem; width: 1.4em; text-align: center; color: var(--accent); }

.hands { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hand { border: 1px solid var(--border); border-radius: 10px; padding: 8px; }
.suit { font-variant-numeric: tabular-nums; }
.suit span { display: inline-block; width: 1.1em; }

.table-grid {
    display: grid;
    grid-template-areas: ". n ." "w c e" ". s .";
    grid-template-columns: 1fr 1.1fr 1fr;
    gap: 6px;
    text-align: center;
}
.table-grid .seat { border: 1px solid var(--border); border-radius: 10px; padding: 8px 4px; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.table-grid .seat span { font-size: 0.75rem; color: var(--muted); }
.table-grid .seat.vul { background: var(--vul); border-color: var(--red); }
.table-grid .north { grid-area: n; }
.table-grid .east { grid-area: e; }
.table-grid .south { grid-area: s; }
.table-grid .west { grid-area: w; }
.table-grid .centre { grid-area: c; align-self: center; font-size: 0.8rem; font-weight: 600; }

.preview { margin: 14px 0 0; }

.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.totals div { border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; }
.totals span { font-size: 0.85rem; color: var(--muted); }
.totals strong { font-size: 1.6rem; }

table.scores { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.92rem; }
.scores th, .scores td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); }
.scores td:not(:nth-child(2)), .scores th:not(:nth-child(2)) { text-align: right; font-variant-numeric: tabular-nums; }
.total-line { font-weight: 600; }

.actions { display: grid; gap: 8px; }
.actions button.primary { margin-top: 0; }

/* Blazor template plumbing */
#blazor-error-ui { color-scheme: light only; background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2); box-sizing: border-box; display: none; left: 0; padding: .6rem 1.25rem .7rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }
.loading-progress { position: absolute; display: block; width: 8rem; height: 8rem; inset: 20vh 0 auto 0; margin: 0 auto; }
.loading-progress circle { fill: none; stroke: var(--border); stroke-width: .6rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child { stroke: var(--accent); stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%; transition: stroke-dasharray .05s ease-in-out; }
.loading-progress-text { position: absolute; text-align: center; font-weight: bold; inset: calc(20vh + 3.25rem) 0 auto .2rem; }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }
