:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --border: #dde3ee;
    --text: #1a2233;
    --muted: #5d6b82;
    --accent: #2b5fd0;
    --accent-ink: #ffffff;
    --gold: #b8860b;
    --silver: #6b7280;
    --bronze: #a05a2c;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(20, 30, 60, .05), 0 8px 24px rgba(20, 30, 60, .06);
    --maxw: 960px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f141c;
        --surface: #172131;
        --border: #26334a;
        --text: #e8edf6;
        --muted: #9fb0c7;
        --accent: #6fa0ff;
        --accent-ink: #0f141c;
        --gold: #e2b53c;
        --silver: #b6c0cf;
        --bronze: #d38a54;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px rgba(0, 0, 0, .35);
    }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app-loading { padding: 3rem; text-align: center; color: var(--muted); }

.page { min-height: 100vh; display: flex; flex-direction: column; }

/* --- top bar --- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .5rem 1rem;
    padding: .75rem clamp(1rem, 4vw, 2rem);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand { font-weight: 700; letter-spacing: -.01em; }
.brand span { color: var(--muted); font-weight: 500; }

.topbar nav { display: flex; gap: .35rem; }

.navlink {
    text-decoration: none;
    color: var(--muted);
    padding: .4rem .8rem;
    border-radius: 999px;
    font-size: .92rem;
    font-weight: 500;
}
.navlink:hover { color: var(--text); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.navlink.active { color: var(--accent-ink); background: var(--accent); }

.year-select {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .85rem;
    color: var(--muted);
    font-weight: 500;
}
.year-select select {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: .3rem .7rem;
    cursor: pointer;
}

/* --- content --- */
.content {
    flex: 1;
    width: 100%;
    max-width: var(--maxw);
    margin: 0 auto;
    padding: clamp(1.25rem, 4vw, 2.5rem) clamp(1rem, 4vw, 2rem);
}

h1 { font-size: clamp(1.4rem, 3.5vw, 1.9rem); margin: 0 0 .35rem; letter-spacing: -.02em; }
.lede { color: var(--muted); margin: 0 0 1.5rem; max-width: 60ch; }

/* --- search form --- */
.search {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem;
    margin-bottom: 1.5rem;
}

.fields { display: flex; flex-wrap: wrap; gap: .9rem; align-items: end; }

.fields label {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    font-size: .82rem;
    font-weight: 600;
    color: var(--muted);
    flex: 1 1 200px;
}

.fields input, .fields select {
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .6rem .7rem;
    width: 100%;
}
.fields input:focus, .fields select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.fields button {
    font: inherit;
    font-weight: 600;
    color: var(--accent-ink);
    background: var(--accent);
    border: none;
    border-radius: 8px;
    padding: .62rem 1.4rem;
    cursor: pointer;
    flex: 0 0 auto;
    min-height: 2.6rem;
}
.fields button:hover:not(:disabled) { filter: brightness(1.06); }
.fields button:disabled { opacity: .5; cursor: not-allowed; }

.count { color: var(--muted); font-size: .88rem; margin: 0 0 .6rem; }
.empty, .error, .loading { color: var(--muted); }
.error { color: #c0392b; }

/* --- results table --- */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

table.results { border-collapse: collapse; width: 100%; font-size: .92rem; }
table.results th, table.results td { text-align: left; padding: .7rem .9rem; }
table.results thead th {
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.results tbody tr + tr td { border-top: 1px solid var(--border); }
table.results tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }

.muted { color: var(--muted); }

.place {
    display: inline-block;
    font-weight: 700;
    font-size: .78rem;
    padding: .12rem .5rem;
    border-radius: 999px;
    color: #fff;
}
.place-1st { background: var(--gold); }
.place-2nd { background: var(--silver); }
.place-3rd { background: var(--bronze); }

.footer {
    text-align: center;
    color: var(--muted);
    font-size: .82rem;
    padding: 1.5rem 1rem 2rem;
}

/* --- responsive: stack the table into cards on narrow screens --- */
@media (max-width: 560px) {
    table.results thead { display: none; }
    table.results, table.results tbody, table.results tr, table.results td { display: block; width: 100%; }
    table.results tr { padding: .5rem 0; }
    table.results tbody tr + tr { border-top: 1px solid var(--border); }
    table.results td { border: none !important; padding: .25rem .9rem; display: flex; justify-content: space-between; gap: 1rem; }
    table.results td::before {
        content: attr(data-label);
        font-size: .74rem;
        text-transform: uppercase;
        letter-spacing: .05em;
        color: var(--muted);
        font-weight: 600;
    }
}

/* --- staff roster --- */
.tag-staff {
    font-size: .6em;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 700;
    color: var(--accent-ink);
    background: var(--accent);
    padding: .12rem .45rem;
    border-radius: 999px;
}

.fields button.ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}

.pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .6rem;
    margin: 0 0 1rem;
}
.pager-btns { display: flex; align-items: center; gap: .5rem; }
.pager-btns button {
    font: inherit;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .35rem .7rem;
    cursor: pointer;
}
.pager-btns button:disabled { opacity: .4; cursor: not-allowed; }
.page-ind { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }

.roster-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.1rem;
    margin-bottom: 1rem;
}
.roster-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: .4rem 1rem;
    margin-bottom: .6rem;
}
.roster-head .name { font-weight: 700; font-size: 1.05rem; }
.roster-head .age {
    margin-left: .5rem;
    font-size: .78rem;
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: .05rem .5rem;
}
.roster-head .meta {
    display: flex;
    flex-wrap: wrap;
    gap: .3rem 1rem;
    color: var(--muted);
    font-size: .84rem;
}
.roster-head .entry-count { font-weight: 600; color: var(--accent); }

table.results tr.unscheduled td { color: var(--muted); }
table.results tr.unscheduled td[data-label="Date"] { color: #c0842b; font-weight: 600; }

/* Blazor error toast */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #ffefc2;
    color: #533f03;
    padding: .7rem 1.2rem;
    box-shadow: 0 -1px 6px rgba(0, 0, 0, .1);
}
#blazor-error-ui .dismiss { cursor: pointer; float: right; }

/* Per-entry additional info (piece + category details) in results/roster tables. */
.entry-details { display: flex; flex-direction: column; gap: .15rem; font-size: .85rem; }
.entry-detail .dl { color: var(--muted); font-weight: 600; margin-right: .3rem; }

/* Group heading when a name matches more than one contestant. */
.group-head { font-size: 1rem; font-weight: 600; margin: 1.25rem 0 .4rem; color: var(--muted); }
