:root {
    --blue: #1f7fe0;
    --blue-dark: #1f5fa8;
    --yellow: #ffd43b;
    --orange: #ff8c1a;
    --pink: #ff4f79;
    --green: #2fb56a;
    --red: #d93a3a;
    --ink: #1d2b3a;
    --muted: #6a7a8c;
    --card: #ffffff;
    --radius: 16px;
    --font: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
    --app-footer-h: 2.4rem;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background: linear-gradient(180deg, #bfe6ff 0%, #e8f7ff 60%, #fff8d6 100%) fixed;
    min-height: 100%;
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

a { color: var(--blue-dark); }
h1, h2 { margin: 0; }
h2 { font-size: 1.05rem; display: flex; align-items: center; gap: .4rem; }
code { font-family: Consolas, 'Cascadia Mono', monospace; font-size: .85em; }

.page {
    padding: 16px;
    max-width: 1800px;
    margin: 0 auto;
    width: 100%;
    flex: 1 0 auto;
}
/* Race view: explicit viewport height so the canvas is large at 100% zoom.
   Podium/results scroll inside .race-main; footer stays on screen. */
body:has(.race-layout) {
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
}
.page:has(.race-layout) {
    flex: none;
    width: 100%;
    max-width: none;
    height: calc(100vh - var(--app-footer-h));
    height: calc(100dvh - var(--app-footer-h));
    display: flex;
    flex-direction: column;
    padding: 10px 16px 0;
    overflow: hidden;
    box-sizing: border-box;
}
.boot { padding: 4rem; text-align: center; font-size: 1.3rem; color: var(--blue-dark); }

.icon { flex: none; vertical-align: -0.15em; }

.app-footer {
    flex: none;
    height: var(--app-footer-h);
    box-sizing: border-box;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .2rem;
    color: var(--muted);
    font-size: .8rem;
    text-align: center;
}
.app-footer a {
    color: var(--blue-dark);
    font-weight: bold;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.app-footer a:hover,
.app-footer a:focus-visible {
    color: var(--blue);
}
.external-link-icon {
    width: .8em;
    height: .8em;
    margin-left: .15em;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.5;
    vertical-align: .05em;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 4px 0 rgba(31, 95, 168, .15), 0 8px 24px rgba(31, 95, 168, .08);
}
.card.narrow { max-width: 480px; margin: 4rem auto; text-align: center; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.bad { color: var(--red); font-weight: bold; }
.warn { color: #a86500; margin: .3rem 0 0; }

/* ---------- inputs & buttons ---------- */

input, textarea {
    font: inherit;
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #cfe3f5;
    border-radius: 12px;
    background: #fbfdff;
    color: var(--ink);
}
input:focus, textarea:focus { outline: none; border-color: var(--blue); }
textarea { resize: vertical; font-family: Consolas, 'Cascadia Mono', monospace; font-size: .9rem; }
input[type=range] { padding: 0; accent-color: var(--orange); }

.btn {
    font: inherit;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: 10px 18px;
    border: none;
    border-radius: 999px;
    background: var(--blue);
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    box-shadow: 0 4px 0 var(--blue-dark);
    transition: transform .08s;
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 var(--blue-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.big { font-size: 1.2rem; padding: 14px 28px; width: 100%; }
.btn.small { font-size: .8rem; padding: 5px 12px; box-shadow: 0 2px 0 var(--blue-dark); }
.btn.ghost { background: #e7f2fd; color: var(--blue-dark); box-shadow: 0 2px 0 #c3dcf3; }
.btn.start {
    font-size: 2rem;
    padding: 18px 48px;
    background: var(--orange);
    box-shadow: 0 6px 0 #c95f00, 0 10px 30px rgba(0,0,0,.25);
    letter-spacing: .05em;
}

.icon-btn {
    border: none;
    background: #eef5fc;
    color: var(--blue-dark);
    border-radius: 8px;
    padding: 4px 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font: inherit;
    font-size: .8rem;
}
.icon-btn:hover { background: #dcebfa; }

.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.field > label { font-weight: bold; font-size: .9rem; }
.label-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.link-row { display: flex; gap: 8px; align-items: center; }
.link-row input { font-size: .85rem; }

.segmented { display: inline-flex; background: #e7f2fd; border-radius: 999px; padding: 3px; }
.segmented button {
    font: inherit;
    font-size: .85rem;
    border: none;
    background: none;
    padding: 5px 12px;
    border-radius: 999px;
    cursor: pointer;
    color: var(--blue-dark);
}
.segmented button.active { background: var(--blue); color: #fff; }

.counter { display: flex; justify-content: space-between; font-size: 1.05rem; }

/* ---------- create page ---------- */

.create { max-width: 1040px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.names-management { display: grid; grid-template-columns: minmax(0, 1fr) minmax(250px, .42fr); gap: 16px; align-items: stretch; }
.names-entry { min-width: 0; }
.bulk-names { margin: -4px 0 10px; padding: 10px 12px; border: 1px solid #dcebf8; border-radius: 12px; background: #f7fbff; }
.bulk-fields { display: flex; align-items: end; gap: 8px; }
.bulk-fields .field { flex: 1; margin: 0; }
.bulk-amount { max-width: 130px; }
.bulk-add { flex: none; margin-bottom: 1px; }
.bulk-names .hint { margin: 6px 0 0; }
.bulk-names .bad { margin: 6px 0 0; }
.bulk-summary { min-width: 0; max-height: 390px; overflow: hidden; display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border: 1px solid #dcebf8; border-radius: 12px; background: #f7fbff; font-size: .82rem; }
.summary-heading { display: flex; justify-content: space-between; gap: 8px; }
.bulk-summary .hint { margin: 0; }
.name-summary-list { list-style: none; margin: 2px 0 0; padding: 0; overflow-y: auto; min-height: 0; }
.name-summary-list li { display: flex; align-items: center; gap: 6px; padding: 5px 4px; border-radius: 7px; }
.name-summary-list li:nth-child(odd) { background: #edf6fd; }
.summary-name { flex: 1; min-width: 0; overflow-wrap: anywhere; color: var(--blue-dark); }
.remove-name { flex: none; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font: bold 1.1rem/1 sans-serif; cursor: pointer; }
.remove-name:hover, .remove-name:focus-visible { background: #dcebfa; color: var(--red); }
.remove-name:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.hero { text-align: center; padding: 16px 0 4px; }
.hero h1 { font-size: 2.6rem; color: var(--blue-dark); text-shadow: 0 3px 0 var(--yellow); }
.hero p { margin: .3rem 0 0; color: var(--muted); }
.links h2 { margin-bottom: 12px; }

/* ---------- race page ---------- */

.race-layout {
    display: flex;
    gap: 16px;
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}
.race-main {
    flex: 0 0 calc(85% - 8px);
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: auto;
}
.sidebar {
    flex: 0 0 calc(15% - 8px);
    min-width: 200px;
    max-width: 300px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: auto;
}

.race-header { flex: none; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.race-header h1 { font-size: 1.35rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home { font-weight: bold; text-decoration: none; background: var(--yellow); padding: 4px 12px; border-radius: 999px; color: var(--ink); }

.pill { padding: 4px 12px; border-radius: 999px; font-weight: bold; font-size: .85rem; background: #e7f2fd; color: var(--blue-dark); }
.pill.starting { background: #fff1d6; color: #a86500; }
.pill.running { background: var(--pink); color: #fff; }
.pill.finished { background: var(--green); color: #fff; }

.stage {
    position: relative;
    flex: 1 1 auto;
    /* Keep the river large at 100% zoom even when waiting links / results sit below. */
    min-height: max(280px, 58vh);
    border-radius: 20px;
    overflow: hidden;
    border: 4px solid #fff;
    box-shadow: 0 6px 0 rgba(31, 95, 168, .25);
}
.stage canvas { display: block; width: 100%; height: 100%; }

.overlay { position: absolute; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; pointer-events: none; }
.overlay > * { pointer-events: auto; }
.overlay.center { top: 0; bottom: 0; justify-content: center; }
.overlay.top { top: 16px; }

.bubble {
    margin: 0;
    background: rgba(255, 255, 255, .92);
    padding: 10px 20px;
    border-radius: 999px;
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--blue-dark);
    box-shadow: 0 4px 0 rgba(0,0,0,.12);
}

.winner-banner {
    background: var(--yellow);
    border: 4px solid #fff;
    border-radius: 20px;
    padding: 10px 32px;
    text-align: center;
    display: flex;
    flex-direction: column;
    box-shadow: 0 6px 0 #d99a00, 0 12px 30px rgba(0,0,0,.2);
    animation: pop .5s cubic-bezier(.2, 1.6, .4, 1);
}
.winner-banner strong { font-size: 2rem; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.podium { display: flex; justify-content: center; align-items: flex-end; gap: 10px; padding-top: 8px; }
.podium .step { display: flex; flex-direction: column; align-items: center; gap: 6px; width: min(200px, 30%); }
.podium .name { font-weight: bold; text-align: center; overflow-wrap: anywhere; }
.podium .block {
    width: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 8px;
    font-size: 1.6rem;
    font-weight: bold;
    color: #fff;
    border-radius: 12px 12px 0 0;
}
.podium .place-1 .block { height: 110px; background: #ffb800; }
.podium .place-2 .block { height: 80px; background: #9fb2c4; }
.podium .place-3 .block { height: 60px; background: #d98a52; }
.replay-row { display: flex; justify-content: center; }

.results-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.results-head input { max-width: 260px; }
.results-list { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow: auto; }
.results-list li { display: grid; grid-template-columns: 70px 1fr auto; gap: 10px; padding: 6px 8px; border-radius: 8px; }
.results-list li:nth-child(odd) { background: #f4f9fe; }
.results-list li.winner { background: #fff3c4; font-weight: bold; }
.results-list .place { color: var(--blue-dark); font-weight: bold; }
.results-list .name { overflow-wrap: anywhere; }
.raw-data { display: flex; flex-direction: column; gap: 10px; }
.raw-data-block {
  margin: 0; max-height: 420px; overflow: auto; white-space: pre-wrap;
  overflow-wrap: anywhere; padding: 12px; border-radius: 8px;
  background: #f4f9fe; color: var(--ink); font: .8rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
}

/* ---------- sidebar ---------- */

.viewers { display: flex; align-items: center; gap: .4rem; font-size: .95rem; padding: 12px 14px; }
.sound-toggle {
    display: flex; align-items: center; gap: .4rem;
    font: inherit; font-size: .9rem; color: var(--ink);
    border: none; cursor: pointer; padding: 10px 14px; text-align: left;
}
.sound-toggle[aria-pressed="false"] { color: var(--muted); }
.brand-duck { width: 1.1em; height: 1.1em; vertical-align: -0.15em; }
.hero .brand-duck { width: 1.2em; height: 1.2em; margin-right: .2em; }
.fair-card { display: flex; flex-direction: column; gap: 10px; font-size: .88rem; }
.fair-card .field { margin: 0; }
.fair-card .field-label {
    display: flex;
    align-items: center;
    gap: .3rem;
}
.fair-card .value { overflow-wrap: anywhere; }
.fair-info {
    position: relative;
    display: inline-flex;
    flex: none;
}
.info-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 2px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--blue-dark);
    cursor: help;
}
.info-trigger:hover,
.info-trigger:focus-visible {
    background: #dcebfa;
}
.info-trigger:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 1px;
}
.fair-tooltip {
    position: absolute;
    z-index: 20;
    top: calc(100% + 6px);
    right: 0;
    width: min(270px, calc(100vw - 32px));
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--ink);
    color: #fff;
    font-size: .78rem;
    font-weight: normal;
    line-height: 1.35;
    text-transform: none;
    letter-spacing: normal;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .12s ease, visibility .12s ease;
}
.fair-info:hover .fair-tooltip,
.fair-info:focus-within .fair-tooltip {
    opacity: 1;
    visibility: visible;
}
.fair-badge {
    display: flex; align-items: center; gap: .4rem;
    background: #fff; border-radius: 999px; padding: 8px 14px; font-weight: bold; font-size: .85rem; color: var(--blue-dark);
    box-shadow: 0 3px 0 rgba(31, 95, 168, .15);
}
.hash { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; max-width: 100%; }
.hash code { overflow-wrap: anywhere; }

.verdict {
    display: flex; align-items: center; gap: .5rem;
    font-size: 1.15rem; font-weight: bold; padding: 10px 12px; border-radius: 12px;
}
.verdict.ok { background: #dff7e9; color: #16804a; }
.verdict.bad { background: #fde3e3; color: var(--red); }
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.checks li.ok .icon { color: var(--green); }
.checks li.bad .icon { color: var(--red); }
.tip { color: var(--muted); font-size: .8rem; margin: 6px 0 0; }
.hint { color: var(--muted); font-size: .8rem; }
.hint.ok { color: #16804a; }
.hint.bad { color: var(--red); }
.fair-card .field > label, .fair-card .field-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.fair-card .value.secret { display: flex; align-items: center; gap: .3rem; font-weight: bold; color: var(--blue-dark); }
.fair-card .value.pending { color: var(--muted); font-style: italic; }
.fair-card .value.winner { font-size: 1.05rem; color: var(--ink); overflow-wrap: anywhere; }
.fair-card .fair-badge { box-shadow: none; background: #e7f2fd; padding: 6px 12px; }
.fair-cta {
    display: block; text-align: center; font-weight: bold; text-decoration: none;
    background: #e7f2fd; color: var(--blue-dark); border-radius: 12px; padding: 9px 10px;
}
.fair-cta:hover { background: #d5e8fb; }

@media (max-width: 1000px) {
    .fair-tooltip { left: 0; right: auto; }
}

/* ---------- private host link ---------- */

.secret-link { display: flex; flex-direction: column; gap: 6px; }
.secret-link .link-row { flex-wrap: wrap; }
.secret-link input { flex: 1 1 220px; }
.secret-link input.masked { filter: blur(3px); user-select: none; pointer-events: none; color: var(--muted); }
.secret-note { display: flex; align-items: center; gap: .35rem; margin: 0; font-size: .82rem; color: #8a5a00; }

/* ---------- fairness page ---------- */

.fair-page { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; padding-bottom: 32px; }
.fair-nav .back {
    display: inline-flex; align-items: center; gap: .35rem; font-weight: bold; text-decoration: none;
    background: var(--yellow); color: var(--ink); padding: 6px 14px; border-radius: 999px;
}
.fair-hero h1 { display: flex; align-items: center; gap: .5rem; font-size: 2rem; color: var(--blue-dark); }
.fair-hero p { font-size: 1.05rem; line-height: 1.5; margin: .6rem 0 0; }
.fair-race { color: var(--muted); }
.fair-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.fair-steps > li { display: flex; gap: 14px; align-items: flex-start; }
.fair-steps h2 { font-size: 1.15rem; margin-bottom: .3rem; }
.fair-steps p, .fair-steps .plain { line-height: 1.55; margin: .4rem 0 0; }
.fair-steps .plain { padding-left: 1.2rem; display: flex; flex-direction: column; gap: 4px; }
.fair-steps .num {
    flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
    background: var(--blue); color: #fff; font-weight: bold; font-size: 1.1rem;
}
.fair-note { display: flex; align-items: center; gap: .5rem; margin: 0; background: #fff8e1; }

.calc { display: flex; flex-direction: column; gap: 14px; }
.calc h2 { font-size: 1.35rem; }
.calc > p { margin: 0; }
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; }
.calc-grid .span-2 { grid-column: 1 / -1; }
.calc-grid .hint { margin-top: -2px; }
.calc-grid .round { max-width: 180px; }
.calc-errors { list-style: none; margin: 0; padding: 10px 12px; border-radius: 12px; background: #fde3e3; color: var(--red); display: flex; flex-direction: column; gap: 4px; }
.calc-errors li { display: flex; align-items: center; gap: .35rem; }
.calc-result { display: flex; flex-direction: column; gap: 12px; }
.calc-winner {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px;
    background: #fff3c4; border-radius: 14px;
}
.calc-winner strong { font-size: 1.8rem; overflow-wrap: anywhere; text-align: center; }
.calc-steps { margin: 0; padding-left: 1.4rem; display: flex; flex-direction: column; gap: 10px; }
.calc-steps li { display: flex; flex-direction: column; gap: 3px; overflow-wrap: anywhere; }
.calc-steps li > span { color: var(--muted); font-size: .9rem; }

@media (max-width: 700px) {
    .calc-grid { grid-template-columns: 1fr; }
    .names-management { grid-template-columns: 1fr; }
    .bulk-summary { max-height: 300px; }
    .bulk-fields { align-items: stretch; flex-wrap: wrap; }
    .bulk-amount { max-width: none; }
    .bulk-add { width: 100%; }
}

@media (max-width: 1000px) {
    body:has(.race-layout) {
        overflow: auto;
        height: auto;
        min-height: 100dvh;
    }
    .page:has(.race-layout) {
        flex: 1 0 auto;
        height: auto;
        overflow: visible;
        padding: 12px 12px 0;
    }
    .race-layout {
        flex-direction: column;
        flex: none;
        min-height: auto;
        align-items: stretch;
        overflow: visible;
    }
    .race-main, .sidebar {
        flex: 1 1 auto;
        width: 100%;
        max-width: none;
        min-width: 0;
        overflow: visible;
    }
    .stage {
        flex: none;
        height: min(62dvh, 520px);
        min-height: 240px;
    }
    .app-footer {
        height: auto;
        padding: 8px 12px 12px;
    }
}

#blazor-error-ui {
    background: #fff3c4;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
