/* Trükivõistlus — kirjutamiskiiruse test ja võistlus */

:root {
    --tv-accent: #2f6fde;
    --tv-accent-ink: #1f56b8;
    --tv-accent-soft: rgba(47, 111, 222, 0.12);
    --tv-on-accent: #ffffff;
    --tv-ok: #1f8a4c;
    --tv-bad: #c62839;
    --tv-bad-soft: rgba(198, 40, 57, 0.14);
    --tv-gold: #b7791f;
    --tv-silver: #6b7280;
    --tv-bronze: #9a5b2c;
    --tv-radius-s: 8px;
    --tv-radius-m: 12px;
    --tv-radius-l: 16px;
    --tv-shadow-1: 0 1px 2px rgba(17, 17, 26, .06), 0 4px 12px rgba(17, 17, 26, .08);
}
[data-theme="dark"] {
    --tv-accent: #6ea1ff;
    --tv-accent-ink: #9cc0ff;
    --tv-accent-soft: rgba(110, 161, 255, 0.16);
    --tv-on-accent: #0b1020;
    --tv-ok: #5fcf8e;
    --tv-bad: #f07a86;
    --tv-bad-soft: rgba(240, 122, 134, 0.2);
    --tv-gold: #f2c14e;
    --tv-silver: #c3c8d2;
    --tv-bronze: #e09a63;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --tv-accent: #6ea1ff;
        --tv-accent-ink: #9cc0ff;
        --tv-accent-soft: rgba(110, 161, 255, 0.16);
        --tv-on-accent: #0b1020;
        --tv-ok: #5fcf8e;
        --tv-bad: #f07a86;
        --tv-bad-soft: rgba(240, 122, 134, 0.2);
        --tv-gold: #f2c14e;
        --tv-silver: #c3c8d2;
        --tv-bronze: #e09a63;
    }
}

.tv-wrap { max-width: 960px; margin: 0 auto; }
.tv-wrap-wide { max-width: 1200px; }
.tv-gap { gap: 8px; }
.tv-note { color: var(--text-secondary); }
.tv-hint { font-size: 0.875rem; color: var(--text-muted); margin-top: 8px; }
.tv-label { display: block; font-weight: 600; font-size: 0.875rem; color: var(--text-primary); margin-bottom: 4px; }
.tv-h2 { font-size: 1.25rem; font-weight: 700; color: var(--text-primary); letter-spacing: -0.01em; }
.tv-center { text-align: center; }
.tv-center-text { text-align: center; }
.tv-loading { color: var(--text-secondary); text-align: center; padding: 24px 0; }

/* ── Päis ─────────────────────────────────────────────────────────────── */
.tv-head { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 16px; margin-bottom: 24px; }
.tv-badge {
    width: 56px; height: 56px; border-radius: 14px; flex: 0 0 auto;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--tv-accent-soft); color: var(--tv-accent-ink); font-size: 1.5rem;
}
.tv-head-titles { flex: 1 1 240px; min-width: 0; }
.tv-eyebrow { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.tv-eyebrow a { color: var(--tv-accent-ink); text-decoration: none; }
.tv-eyebrow a:hover { text-decoration: underline; }
.tv-title {
    font-size: clamp(1.35rem, 2.6vw, 1.75rem); font-weight: 700; letter-spacing: -0.01em;
    color: var(--text-primary); line-height: 1.2; overflow-wrap: anywhere;
}
.tv-sub { color: var(--text-secondary); margin-top: 4px; }
.tv-head-actions { margin-bottom: 0 !important; }

/* ── Paneelid ─────────────────────────────────────────────────────────── */
.tv-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-light, var(--border-color));
    border-radius: var(--tv-radius-l);
    box-shadow: var(--tv-shadow-1);
    padding: 24px;
    margin-bottom: 24px;
}
.tv-empty { text-align: center; max-width: 560px; margin: 48px auto; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.tv-pill {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 12px; border-radius: 999px;
    background: var(--bg-secondary); border: 1px solid var(--border-light, var(--border-color));
    color: var(--text-primary); font-weight: 600; font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
}

/* ── Nupud ────────────────────────────────────────────────────────────── */
.button.tv-cta {
    background: var(--tv-accent); border-color: transparent; color: var(--tv-on-accent);
    font-weight: 600; border-radius: var(--tv-radius-s);
}
.button.tv-cta:hover, .button.tv-cta:focus-visible { filter: brightness(1.06); color: var(--tv-on-accent); }
.button.tv-cta[disabled] { opacity: 0.5; }
.tv-icon-btn { min-width: 40px; min-height: 40px; border-radius: var(--tv-radius-s); }

/* Lüliti (kestus, tekst): nupud eraldi, et kitsal ekraanil murduks puhtalt reale */
.tv-seg {
    display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px;
    border: 1px solid var(--border-color); border-radius: 10px;
    background: var(--bg-card);
}
.tv-seg-btn {
    appearance: none; border: 0; background: transparent; cursor: pointer;
    padding: 6px 12px; min-height: 36px; border-radius: 7px;
    font: inherit; font-size: 0.875rem; font-weight: 600; white-space: nowrap;
    color: var(--text-secondary);
    transition: background-color 150ms, color 150ms;
}
.tv-seg-btn[aria-pressed="true"] { background: var(--tv-accent-soft); color: var(--tv-accent-ink); }
@media (hover: hover) {
    .tv-seg-btn:hover:not([aria-pressed="true"]) { background: var(--bg-hover); color: var(--text-primary); }
}

/* ── Kirjutamise ala ──────────────────────────────────────────────────── */
.tv-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 16px; }
.tv-lang { margin-left: auto; }

.tv-words {
    --tv-line: calc(1.6em + 6px);
    position: relative;
    font-size: 1.5rem;
    height: calc(3 * var(--tv-line) + 16px);
    overflow: hidden;
    padding: 8px 12px;
    border-radius: var(--tv-radius-m);
    background: var(--bg-secondary);
    border: 1px solid var(--border-light, var(--border-color));
    color: var(--text-primary);
    cursor: text;
    user-select: none;
}
.tv-words-inner { position: relative; transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1); }
.tv-w {
    display: inline-block;
    line-height: 1.6;
    margin: 0 4px 6px 0;
    padding: 0 4px;
    border-radius: 6px;
}
.tv-w.is-cur { background: var(--tv-accent-soft); box-shadow: inset 0 -2px 0 var(--tv-accent); }
.tv-w.is-cur.is-bad { background: var(--tv-bad-soft); box-shadow: inset 0 -2px 0 var(--tv-bad); }
.tv-w.is-ok { color: var(--tv-ok); }
.tv-w.is-wrong { color: var(--tv-bad); text-decoration: line-through; text-decoration-thickness: 2px; }

.tv-inputrow { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.tv-input.input { flex: 1 1 auto; min-width: 0; font-size: 1.25rem; height: 3rem; border-radius: var(--tv-radius-s); }
.tv-timer {
    flex: 0 0 auto; min-width: 4.5rem; text-align: center;
    padding: 8px 12px; border-radius: 999px;
    background: var(--bg-secondary); border: 1px solid var(--border-light, var(--border-color));
    font-weight: 700; font-size: 1.25rem; font-variant-numeric: tabular-nums; color: var(--text-primary);
}
.tv-timer.is-low { color: var(--tv-bad); border-color: var(--tv-bad); }
.tv-test.is-over .tv-words { opacity: 0.6; }

/* Telefoni märkus ainult puuteseadmel */
.tv-touch-note { display: none; }
@media (hover: none) and (pointer: coarse) {
    .tv-touch-note { display: block; }
}

/* ── Tulemus ──────────────────────────────────────────────────────────── */
.tv-result { text-align: center; margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--border-light, var(--border-color)); }
#tvpResult .tv-result { margin-top: 0; padding-top: 0; border-top: 0; }
.tv-result-main { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-bottom: 16px; }
.tv-result-wpm {
    font-size: clamp(2.5rem, 7vw, 3.5rem); font-weight: 700; line-height: 1;
    color: var(--tv-accent-ink); font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
    animation: tv-pop 280ms cubic-bezier(0, 0, 0.2, 1);
}
.tv-result-unit { color: var(--text-secondary); font-weight: 600; }
.tv-result-cpm { color: var(--text-muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.tv-sources { font-style: italic; }
.tv-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 12px; margin: 0 auto 16px; max-width: 640px; }
.tv-stat {
    display: flex; flex-direction: column; gap: 4px; padding: 12px;
    border-radius: var(--tv-radius-m); background: var(--bg-secondary);
}
.tv-stat-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.tv-stat-value { font-size: 1.5rem; font-weight: 700; white-space: nowrap; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.tv-stat-value.tv-ok { color: var(--tv-ok); }
.tv-stat-value.tv-bad { color: var(--tv-bad); }
.tv-new-best { color: var(--tv-gold); font-weight: 600; }
.tv-rank-line { font-weight: 700; font-size: 1.25rem; color: var(--text-primary); margin-bottom: 8px; }
@keyframes tv-pop { 0% { transform: scale(0.92); opacity: 0; } 60% { transform: scale(1.06); opacity: 1; } 100% { transform: scale(1); } }

/* ── Avalehe võistluskaart ───────────────────────────────────────────── */
.tv-host-cta { display: flex; flex-wrap: wrap; align-items: center; gap: 16px 24px; }
.tv-host-cta-text { flex: 1 1 320px; }
.tv-host-cta > .buttons { margin-bottom: 0; }
.tv-myraces { flex: 1 1 100%; border-top: 1px solid var(--border-light, var(--border-color)); padding-top: 16px; }
.tv-race-list { list-style: none; margin: 0; padding: 0; }
.tv-race-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.tv-race-row + .tv-race-row { border-top: 1px solid var(--border-light, var(--border-color)); }
.tv-race-link {
    flex: 1 1 auto; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px;
    padding: 8px; border-radius: var(--tv-radius-s); color: var(--text-primary); text-decoration: none;
}
.tv-race-link:hover { background: var(--bg-hover); }
.tv-race-title { font-weight: 600; overflow-wrap: anywhere; }
.tv-race-meta { font-size: 0.875rem; color: var(--text-muted); }

/* ── Korraldaja vaade ─────────────────────────────────────────────────── */
.tv-host { display: grid; grid-template-columns: minmax(240px, 300px) 1fr; gap: 24px; align-items: start; }
.tv-host .tv-panel { margin-bottom: 0; }
.tv-join { text-align: center; }
.tv-join-step { font-size: 0.875rem; color: var(--text-secondary); font-weight: 600; }
.tv-join-host { font-size: 1.5rem; font-weight: 700; color: var(--tv-accent-ink); margin-bottom: 8px; overflow-wrap: anywhere; }
.tv-join-code {
    font-size: clamp(2.25rem, 4vw, 3rem); font-weight: 700; letter-spacing: 0.04em;
    font-variant-numeric: tabular-nums; color: var(--text-primary); line-height: 1.1; margin-bottom: 16px;
}
.tv-join-qr {
    display: block; margin: 0 auto 12px; width: 160px; height: 160px;
    background: #fff; padding: 8px; border-radius: var(--tv-radius-m);
}
.tv-stage-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 16px; }
.tv-pill-timer { margin-left: auto; font-size: 1.25rem; padding: 6px 16px; }
.tv-pill-timer.is-low { color: var(--tv-bad); border-color: var(--tv-bad); }

.tv-settings {
    display: flex; flex-wrap: wrap; align-items: flex-start; gap: 16px 24px;
    padding: 16px; margin-top: 16px;
    border-radius: var(--tv-radius-m); background: var(--bg-secondary);
}
.tv-field { min-width: 0; flex: 0 1 auto; }
.tv-settings .tv-field:first-child { flex: 1 1 220px; }
.tv-settings #tvhCustomField { flex: 1 1 100%; }

.tv-countdown {
    text-align: center; font-size: clamp(4rem, 14vw, 7rem); font-weight: 700; line-height: 1;
    color: var(--tv-accent-ink); font-variant-numeric: tabular-nums; padding: 16px 0;
}
.tv-test .tv-countdown { padding: 0 0 16px; font-size: clamp(3rem, 10vw, 5rem); }

.tv-empty-note { color: var(--text-muted); text-align: center; padding: 16px 0; }
.tv-stage-actions { margin-top: 16px; margin-bottom: 0 !important; }

/* Nimekiri: ooteajal nimed, voorus ribad ja kiirus, lõpus edetabel */
.tv-board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tv-row {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px;
    padding: 8px 12px; border-radius: var(--tv-radius-m);
    background: var(--bg-secondary); border: 1px solid transparent;
}
.tv-row .tv-rank { display: none; }
.tv-board.is-live .tv-row { grid-template-columns: 2.5rem minmax(6rem, 14rem) minmax(0, 1fr) 6rem 3.5rem auto; }
.tv-board.is-live .tv-rank { display: inline-flex; }
.tv-board.is-live.is-done .tv-row { grid-template-columns: 2.5rem minmax(6rem, 14rem) minmax(0, 1fr) 6rem 6rem 3.5rem auto; }
#tvpBoard .tv-row { grid-template-columns: 2.5rem minmax(0, 1fr) auto; }
.tv-row.is-me { border-color: var(--tv-accent); background: var(--tv-accent-soft); }
.tv-row.is-hidden-name .tv-name { color: var(--text-muted); font-style: italic; }
.tv-rank {
    align-items: center; justify-content: center; width: 2rem; height: 2rem; border-radius: 999px;
    font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-secondary);
}
.tv-rank.is-medal { color: #fff; }
.tv-rank.is-medal-1 { background: var(--tv-gold); }
.tv-rank.is-medal-2 { background: var(--tv-silver); }
.tv-rank.is-medal-3 { background: var(--tv-bronze); }
[data-theme="dark"] .tv-rank.is-medal { color: #111; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tv-rank.is-medal { color: #111; } }
.tv-name { font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-bar { height: 10px; border-radius: 999px; background: var(--bg-card); overflow: hidden; }
.tv-bar-fill { display: block; height: 100%; border-radius: 999px; background: var(--tv-accent); transition: width 600ms cubic-bezier(0.4, 0, 0.2, 1); }
.tv-wpm { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tv-wpm strong { font-size: 1.25rem; color: var(--text-primary); }
.tv-wpm small { color: var(--text-muted); font-size: 0.75rem; }
.tv-cpm { text-align: right; color: var(--text-secondary); font-size: 0.875rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tv-acc { text-align: right; color: var(--text-muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.tv-row-acts { display: inline-flex; gap: 4px; }
#tvpBoard.tv-anim .tv-row { animation: tv-rise 250ms cubic-bezier(0, 0, 0.2, 1) backwards; animation-delay: calc(var(--i, 0) * 40ms); }
@keyframes tv-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Osaleja ooteekraan */
.tv-wait-icon { display: inline-flex; font-size: 2rem; color: var(--tv-accent-ink); margin-bottom: 8px; }
.tv-wait-text { font-size: 1.25rem; font-weight: 600; color: var(--text-primary); }
.tv-join-form { max-width: 480px; margin: 16px auto 0; text-align: left; }
.tv-board-title { margin: 24px 0 12px; }

/* Täisekraan (projektor) */
.tv-wrap:fullscreen { max-width: none; background: var(--bg-primary); padding: 24px 32px; overflow: auto; }
.tv-wrap:fullscreen .tv-row { padding: 12px 16px; }
.tv-wrap:fullscreen .tv-name { font-size: 1.25rem; }
.tv-wrap:fullscreen .tv-wpm strong { font-size: 1.5rem; }

/* ── Kitsas ekraan ────────────────────────────────────────────────────── */
@media (max-width: 860px) {
    .tv-host { grid-template-columns: 1fr; }
    .tv-board.is-live .tv-row { grid-template-columns: 2.5rem minmax(0, 1fr) auto auto; }
    .tv-board.is-live .tv-bar { grid-column: 2 / -1; grid-row: 2; }
    .tv-board.is-live .tv-acc, .tv-board.is-live .tv-cpm { display: none; }
    .tv-board.is-live.is-done .tv-row { grid-template-columns: 2.5rem minmax(0, 1fr) auto auto; }
}
@media (max-width: 600px) {
    .tv-panel { padding: 16px; }
    .tv-words { font-size: 1.2rem; }
    .tv-lang { margin-left: 0; }
    .tv-input.input { font-size: 1.1rem; }
    .tv-stat { padding: 8px; }
    .tv-stat-value { font-size: 1.25rem; }
}

/* ── Rajavõistlus: osaleja märk, rajad, oma rada ──────────────────────── */
.tv-mark {
    --mark: #6b7280;
    display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
    width: 36px; height: 36px; border-radius: 999px;
    background: var(--mark); color: #fff; font-size: 1rem;
    box-shadow: 0 0 0 2px var(--bg-card);
}
.tv-mark.is-small { width: 24px; height: 24px; font-size: 0.75rem; box-shadow: none; }
.tv-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
#tvpMe { gap: 8px; padding-left: 4px; }
.tv-field-wide { flex: 1 1 100% !important; }
.tv-seg-btn .icon { vertical-align: -2px; }

.tv-track {
    position: relative; display: block; height: 44px; min-width: 0;
    border-radius: 999px; background: var(--bg-card);
    border: 1px dashed var(--border-color);
}
.tv-runner {
    position: absolute; top: 50%; left: calc(4px + var(--p) * (100% - 44px - var(--ms)));   /* lõpus jääb lipule ruumi */
    transform: translateY(-50%);
    transition: left 1400ms linear;
    display: inline-flex;
}
.tv-goal { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.tv-lane.is-finished .tv-track { border-style: solid; border-color: transparent; }
.tv-board.is-lanes .tv-row { grid-template-columns: 2.5rem minmax(6rem, 10rem) minmax(0, 1fr) 5.5rem auto; }
.tv-board.is-lanes .tv-row-acts .button { min-width: 32px; min-height: 32px; height: 32px; padding: 0 6px; }
.tv-board.is-lanes .tv-rank { display: inline-flex; }
.tv-name-slot, .tv-acts-slot { min-width: 0; }
.tv-lane-res { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.tv-lane-res strong { font-size: 1.25rem; color: var(--text-primary); }
.tv-lane-res small { display: block; font-size: 0.75rem; color: var(--text-muted); }
.tv-wrap:fullscreen .tv-track { height: 52px; }

.tv-mylane { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.tv-mylane .tv-track { flex: 1 1 auto; }
.tv-place { min-width: 6.5rem; justify-content: center; font-size: 1rem; }
.tv-place:empty { visibility: hidden; }

/* Vale sõna rajavõistlusel: väli raputab end (õrn, ±5 px, 2 võnget) */
.tv-input.tv-shake { animation: tv-shake 400ms cubic-bezier(0.4, 0, 0.2, 1); }
@keyframes tv-shake {
    0%, 100% { transform: none; }
    0%, 80% { border-color: var(--tv-bad); }
    20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); }
}

@media (max-width: 860px) {
    /* Kitsal ekraanil: rida 1 = koht, nimi, tulemus; rida 2 = rada + nupud (nimi jääb loetavaks) */
    .tv-board.is-lanes .tv-row { grid-template-columns: 2.5rem minmax(0, 1fr) auto; }
    .tv-board.is-lanes .tv-track { grid-column: 1 / 3; grid-row: 2; }
    .tv-board.is-lanes .tv-acts-slot { grid-column: 3; grid-row: 2; }
}

/* Admini testrobotid */
.tv-bot-ico { color: var(--text-muted); font-size: 0.8em; }
.tv-bots { margin-top: 12px; margin-bottom: 0 !important; opacity: 0.7; }
.tv-bots:hover, .tv-bots:focus-within { opacity: 1; }

/* Üle 12 raja: kompaktne rida (projektorile mahub ~2x rohkem) */
.tv-board.is-lanes.is-crowded { gap: 4px; }
.tv-board.is-lanes.is-crowded .tv-row { padding: 2px 12px; }
.tv-board.is-lanes.is-crowded .tv-track { height: 30px; }
.tv-board.is-lanes.is-crowded .tv-runner .tv-mark { width: 26px; height: 26px; font-size: 0.8rem; }
.tv-board.is-lanes.is-crowded .tv-row-acts .button { min-height: 30px; min-width: 30px; height: 30px; }
.tv-board.is-lanes.is-crowded .tv-lane-res strong { font-size: 1rem; }

/* Elav nimekiri: ajavõistlusel tm/min ainult tulemustes; ridade ümberjärjestust animeerib JS (FLIP) */
.tv-board.is-live:not(.is-done) .tv-cpm { display: none; }
.tv-board.is-live:not(.is-done) .tv-row { grid-template-columns: 2.5rem minmax(6rem, 14rem) minmax(0, 1fr) 6rem 3.5rem auto; }
.tv-row { will-change: transform; }
.tv-row.is-overflow { display: none; }
.tv-more {
    display: block; margin: 8px auto 0; padding: 8px 16px; min-height: 40px;
    appearance: none; border: 0; border-radius: 8px; background: transparent; cursor: pointer;
    font: inherit; font-weight: 600; color: var(--text-secondary);
    transition: background-color 150ms, color 150ms;
}
.tv-more.is-hidden { display: none; }
@media (hover: hover) { .tv-more:hover { background: var(--bg-hover); color: var(--text-primary); } }
.tv-stage-race { display: none; }

/* ── Suur seis (projektor): ainult edenemine ───────────────────────────── */
.tv-wrap.is-stage .tv-head,
.tv-wrap.is-stage .tv-join,
.tv-wrap.is-stage .tv-settings,
.tv-wrap.is-stage .tv-stage-actions,
.tv-wrap.is-stage .tv-bots,
.tv-wrap.is-stage .tv-acts-slot,
.tv-wrap.is-stage .tv-row-acts,
.tv-wrap.is-stage #tvhStageTitle,
.tv-wrap.is-stage #tvhCount { display: none !important; }
.tv-wrap.is-stage { max-width: none; }
.tv-wrap.is-stage .tv-host { display: block; }
.tv-wrap.is-stage .tv-stage { background: transparent; border: 0; box-shadow: none; padding: 0; }
.tv-wrap.is-stage .tv-stage-race {
    display: block; flex: 1 1 auto; min-width: 0;
    font-size: clamp(1.5rem, 2.6vw, 2.25rem); font-weight: 700; letter-spacing: -0.01em; color: var(--text-primary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tv-wrap.is-stage .tv-pill-timer { font-size: clamp(1.5rem, 2.6vw, 2.25rem); padding: 8px 20px; margin-left: 0; }
.tv-wrap.is-stage .tv-stage-head { margin-bottom: 24px; }
.tv-wrap.is-stage .tv-countdown { font-size: clamp(6rem, 22vw, 14rem); }
.tv-wrap.is-stage .tv-name { font-size: 1.5rem; }
.tv-wrap.is-stage .tv-mark.is-small { width: 30px; height: 30px; font-size: 0.9rem; }
.tv-wrap.is-stage .tv-wpm strong, .tv-wrap.is-stage .tv-lane-res strong { font-size: 1.75rem; }
.tv-wrap.is-stage .tv-rank { width: 2.5rem; height: 2.5rem; font-size: 1.25rem; }
.tv-wrap.is-stage .tv-track { height: 56px; }
.tv-wrap.is-stage .tv-runner .tv-mark { width: 48px; height: 48px; font-size: 1.35rem; }
.tv-wrap.is-stage .tv-bar { height: 18px; }
.tv-wrap.is-stage .tv-board.is-crowded .tv-name { font-size: 1.15rem; }
.tv-wrap.is-stage .tv-board.is-crowded .tv-track { height: 36px; }
.tv-wrap.is-stage .tv-board.is-crowded .tv-runner .tv-mark { width: 32px; height: 32px; font-size: 0.95rem; }
.tv-wrap.is-stage .tv-board.is-crowded .tv-wpm strong,
.tv-wrap.is-stage .tv-board.is-crowded .tv-lane-res strong { font-size: 1.25rem; }
html.tv-stage-open { overflow: hidden; }
/* „Näita kõiki": vaade keritav, päis (nimi + taimer + Tavavaade) kleepub üles */
html.tv-stage-open.tv-stage-scroll { overflow: auto; }
.tv-wrap.is-stage .tv-stage-head {
    position: sticky; top: 0; z-index: 5;
    background: var(--bg-primary); padding: 12px 0; margin-top: -12px;
}
/* Täisekraanis kerib .tv-wrap ise: ülemine täidis päisesse, muidu paistaks read päise kohal läbi */
.tv-wrap.is-stage:fullscreen { padding-top: 0; }
.tv-wrap.is-stage:fullscreen .tv-stage-head { margin-top: 0; padding-top: 24px; }
html.tv-stage-open .tv-section { padding-top: 24px; }
@media (min-width: 861px) {
    .tv-wrap.is-stage .tv-board.is-lanes .tv-row { grid-template-columns: 3rem minmax(10rem, 18rem) minmax(0, 1fr) 8rem; }
    .tv-wrap.is-stage .tv-board.is-live .tv-row { grid-template-columns: 3rem minmax(10rem, 18rem) minmax(0, 1fr) 8rem 4.5rem; }
    .tv-wrap.is-stage .tv-board.is-live.is-done .tv-row { grid-template-columns: 3rem minmax(10rem, 18rem) minmax(0, 1fr) 8rem 7rem 4.5rem; }
}

/* ── Läbitud rajaosa osaleja märgi toonis + riba täide sama värviga ──── */
.tv-track { --p: 0; --ms: 36px; overflow: hidden; }
/* Läbitud osa: algab raja algusest ja lõpeb TÄPSELT märgi keskel (sama valem, mis märgil
   + pool märgi laiust), parem serv terav — märk katab selle pooleldi. */
.tv-track::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0;
    width: calc(4px + var(--ms) / 2 + var(--p) * (100% - 44px - var(--ms)));
    background: color-mix(in srgb, var(--mark, var(--tv-accent)) 32%, transparent);
    border-radius: 999px 0 0 999px;
    transition: width 1400ms linear;
}
.tv-lane.is-finished .tv-track::before { width: 100%; border-radius: inherit; }
.tv-board.is-lanes.is-crowded .tv-track { --ms: 26px; }
.tv-wrap.is-stage .tv-track { --ms: 48px; }
.tv-wrap.is-stage .tv-board.is-crowded .tv-track { --ms: 32px; }
.tv-row .tv-bar-fill { background: var(--mark, var(--tv-accent)); }

/* ── Kohtade muutus: tõusja libiseb teiste kohal, langeja alt ──────────── */
.tv-board .tv-row { position: relative; transition: transform 800ms cubic-bezier(0.65, 0, 0.35, 1), scale 300ms, box-shadow 300ms; }
.tv-row.is-rising { z-index: 2; scale: 1.015; box-shadow: 0 8px 24px rgba(17, 17, 26, 0.18); }
.tv-row.is-falling { z-index: 1; }
.tv-delta {
    position: absolute; left: 4px; bottom: 2px;
    display: inline-flex; align-items: center; gap: 1px;
    font-size: 0.75rem; font-weight: 700; font-variant-numeric: tabular-nums;
    opacity: 0; transition: opacity 200ms; pointer-events: none;
}
.tv-delta.is-up { color: var(--tv-ok); opacity: 1; }
.tv-delta.is-down { color: var(--tv-bad); opacity: 1; }
.tv-row.is-entering { animation: tv-enter 450ms cubic-bezier(0, 0, 0.2, 1); }
@keyframes tv-enter { from { opacity: 0; translate: 0 16px; } to { opacity: 1; translate: 0 0; } }
.tv-row.is-new-leader { animation: tv-leader 1400ms cubic-bezier(0, 0, 0.2, 1); }
@keyframes tv-leader {
    0% { box-shadow: 0 0 0 0 var(--tv-gold); }
    25% { box-shadow: 0 0 0 4px var(--tv-gold); }
    100% { box-shadow: 0 0 0 0 transparent; }
}

/* ── Tavavaade voo ajal: liitumispaneel kitsaks (QR peidus), rajad laiemaks ── */
#tvHost[data-phase="countdown"], #tvHost[data-phase="running"] { grid-template-columns: minmax(180px, 210px) 1fr; }
#tvHost[data-phase="countdown"] .tv-join-qr, #tvHost[data-phase="running"] .tv-join-qr,
#tvHost[data-phase="countdown"] .tv-join .buttons, #tvHost[data-phase="running"] .tv-join .buttons,
#tvHost[data-phase="countdown"] .tv-join .tv-hint, #tvHost[data-phase="running"] .tv-join .tv-hint { display: none; }
#tvHost[data-phase="running"] .tv-join-code { font-size: 1.75rem; }
@media (max-width: 860px) {
    #tvHost[data-phase="countdown"], #tvHost[data-phase="running"] { grid-template-columns: 1fr; }
}

/* Tulemus saab fookuse programmiliselt (tabindex=-1, et kiire tühik ei vajutaks nuppu) — rõngast pole vaja */
.tv-result:focus, .tv-result:focus-visible { outline: none; }
