/*
 * ESS - TV screen styling (area scores cycle).
 *
 * Designed for full-screen display on a TV (1080p+). Dark theme, large type,
 * smooth fades between areas. Sizing leans on viewport units so it scales with
 * the screen instead of a fixed pixel grid.
 */

:root {
    /* Font unit. Type is sized in multiples of --fs (e.g. font-size: calc(2.6 * var(--fs)))
     * instead of raw vh. Half of it is viewport-relative (vh) so the screens still scale
     * with the TV resolution; the other half is pinned to rem so browser zoom (Ctrl +/-)
     * actually changes the text size — plain vh ignores zoom entirely. Calibrated so
     * 1 unit ≈ 1vh at 1080p/100% zoom, i.e. the default look is unchanged. */
    --fs: calc(0.5vh + 0.34rem);

    /* Dark theme (default). The light theme below only overrides these vars, so any
     * screen using layout::tv gets both themes for free via ?theme=light. */
    --tv-bg-top: #0b1622;
    --tv-bg-bottom: #16263b;
    --tv-card-bg: rgba(255, 255, 255, 0.04);
    --tv-card-border: rgba(255, 255, 255, 0.10);
    --tv-card-bg-empty: rgba(255, 255, 255, 0.02);
    --tv-text: #e8eef7;
    --tv-text-muted: #8aa0bd;
    --tv-accent: #3b82f6;
    --tv-accent-soft: rgba(59, 130, 246, 0.18);
    --tv-good: #22c55e;
    --tv-bad: #f87171;
    --tv-warn: #f59e0b;
    --tv-head: #0f2236;
    --tv-header-bg: rgba(0, 0, 0, 0.25);
    --tv-progress-track: rgba(255, 255, 255, 0.06);
    --tv-strong: #ffffff;
    --tv-time-text: #ffffff;
    --tv-dot-idle: rgba(255, 255, 255, 0.20);
    --tv-shadow: rgba(0, 0, 0, 0.25);
    --tv-badge-bg: rgba(255, 255, 255, 0.10);
    --tv-badge-cat-bg: rgba(255, 255, 255, 0.16);
}

/* Light theme — activated by ?theme=light (layout::tv adds .theme-light to <html>). */
html.theme-light {
    --tv-bg-top: #eef2f8;
    --tv-bg-bottom: #d8e1ee;
    --tv-card-bg: rgba(255, 255, 255, 0.92);
    --tv-card-border: rgba(15, 23, 42, 0.12);
    --tv-card-bg-empty: rgba(15, 23, 42, 0.03);
    --tv-text: #1e293b;
    --tv-text-muted: #5b6b82;
    --tv-accent: #2563eb;
    --tv-accent-soft: rgba(37, 99, 235, 0.14);
    --tv-good: #15803d;
    --tv-bad: #dc2626;
    --tv-warn: #b45309;
    --tv-head: #e7edf6;
    --tv-header-bg: rgba(255, 255, 255, 0.78);
    --tv-progress-track: rgba(15, 23, 42, 0.10);
    --tv-strong: #0f172a;
    --tv-time-text: #0f172a;
    --tv-dot-idle: rgba(15, 23, 42, 0.22);
    --tv-shadow: rgba(15, 23, 42, 0.15);
    --tv-badge-bg: rgba(15, 23, 42, 0.07);
    --tv-badge-cat-bg: rgba(15, 23, 42, 0.10);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
}

.tv-body {
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--tv-text);
    background: linear-gradient(160deg, var(--tv-bg-top) 0%, var(--tv-bg-bottom) 100%);
    background-attachment: fixed;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---- Header ---- */
.tv-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 1.5vw;
    padding: 1.2vh 2.2vw;
    background: var(--tv-header-bg);
    border-bottom: 1px solid var(--tv-card-border);
}

.tv-header .tv-brand img {
    height: 5.2vh;
    display: block;
}

.tv-header .tv-match {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.tv-header .tv-match-name {
    font-size: calc(2.6 * var(--fs));
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tv-header .tv-area-name {
    font-size: calc(3.4 * var(--fs));
    font-weight: 800;
    letter-spacing: 0.02em;
    color: var(--tv-strong);
}

.tv-header .tv-area-name .tv-area-label {
    color: var(--tv-accent);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: calc(1.8 * var(--fs));
    font-weight: 700;
    margin-right: 0.6vw;
    vertical-align: middle;
}

.tv-header .tv-spacer {
    flex: 1 1 auto;
}

.tv-header .tv-clock {
    font-size: calc(3.2 * var(--fs));
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--tv-text);
}

/* Area pager dots */
.tv-dots {
    display: flex;
    gap: 0.7vw;
    align-items: center;
}

.tv-dot {
    width: 1.4vh;
    height: 1.4vh;
    border-radius: 50%;
    background: var(--tv-dot-idle);
    transition: background 0.3s ease, transform 0.3s ease;
}

.tv-dot.active {
    background: var(--tv-accent);
    transform: scale(1.35);
}

/* Progress / countdown bar under the header */
.tv-progress {
    flex: 0 0 auto;
    height: 0.5vh;
    background: var(--tv-progress-track);
    overflow: hidden;
}

.tv-progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--tv-accent), #60a5fa);
}

/* ---- Stage area / cycling panels ---- */
.tv-stage {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
}

.tv-area-panel {
    position: absolute;
    inset: 0;
    padding: 2vh 2.2vw;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.6s ease;
    overflow: auto;
}

.tv-area-panel.active {
    opacity: 1;
    visibility: visible;
}

.tv-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(30vw, 1fr));
    gap: 1.6vh 1.6vw;
    align-content: start;
    height: 100%;
}

/* ---- Stage card ---- */
.tv-card {
    background: var(--tv-card-bg);
    border: 1px solid var(--tv-card-border);
    border-radius: 1.2vh;
    padding: 1.4vh 1.4vw;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0.6vh 1.6vh var(--tv-shadow);
    backdrop-filter: blur(2px);
}

.tv-card.empty {
    background: var(--tv-card-bg-empty);
    justify-content: center;
    align-items: center;
}

.tv-card-head {
    display: flex;
    align-items: baseline;
    gap: 0.8vw;
    margin-bottom: 1vh;
}

.tv-card-stage {
    font-size: calc(2.6 * var(--fs));
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tv-card-time {
    margin-left: auto;
    font-size: calc(1.8 * var(--fs));
    color: var(--tv-text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.tv-shooter {
    display: flex;
    align-items: baseline;
    gap: 0.6vw;
    margin-bottom: 1vh;
    flex-wrap: wrap;
}

.tv-shooter-id {
    font-size: calc(2.2 * var(--fs));
    font-weight: 700;
    color: var(--tv-accent);
}

.tv-shooter-name {
    font-size: calc(2.2 * var(--fs));
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1 1 auto;
    min-width: 0;
}

.tv-badges {
    display: flex;
    gap: 0.4vw;
    flex-wrap: wrap;
    margin-bottom: 2px;
}

.tv-badge {
    font-size: calc(1.6 * var(--fs));
    font-weight: 700;
    padding: 0.2vh 0.7vw;
    border-radius: 0.6vh;
    line-height: 1.4;
    background: var(--tv-badge-bg);
    color: var(--tv-text);
    white-space: nowrap;
}

.tv-badge.div {
    background: var(--tv-accent);
    color: #fff;
}

.tv-badge.cat {
    background: var(--tv-badge-cat-bg);
}

.tv-badge.squad {
    background: var(--tv-accent-soft);
    color: var(--tv-accent);
}

/* ---- Score table ---- */
.tv-score {
    margin-top: auto;
    width: 100%;
    border-collapse: collapse;
    text-align: center;
    table-layout: fixed;
}

.tv-score th {
    font-size: calc(1.5 * var(--fs));
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--tv-text-muted);
    background: var(--tv-head);
    padding: 0.6vh 0.2vw;
    border: 1px solid var(--tv-card-border);
}

.tv-score td {
    font-size: calc(2.6 * var(--fs));
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    padding: 0.8vh 0.2vw;
    border: 1px solid var(--tv-card-border);
}

/* The six hit columns hold one or two digits; Time and HF are much wider, so
 * give them extra room (fixed layout otherwise splits all columns equally and
 * the Hit Factor leaks past its cell). */
.tv-score th.time,
.tv-score td.time,
.tv-score th.hf,
.tv-score td.hf {
    width: 22%;
}

.tv-score td.hf {
    color: var(--tv-good);
    background: rgba(34, 197, 94, 0.10);
}

.tv-score td.time {
    color: var(--tv-time-text);
    background: var(--tv-accent-soft);
}

.tv-empty-text {
    font-size: calc(2.6 * var(--fs));
    font-weight: 700;
    color: var(--tv-text-muted);
}

.tv-empty-text .fa {
    margin-right: 0.6vw;
}

/* ============================================================================
 * Shared components for the other external screens (results boards, stage
 * detail, verify kiosk, portal). Everything is themeable through the vars at
 * the top, so all of these work in both the dark and light themes.
 * ========================================================================== */

/* Header: back link for the portal drill-down screens, so visitors navigate with a
 * plain GET link instead of the browser's back button (which re-prompts to resend). */
.tv-back {
    display: inline-flex;
    align-items: center;
    gap: 0.5vw;
    flex: 0 0 auto;
    font-size: calc(1.7 * var(--fs));
    font-weight: 700;
    padding: 0.7vh 1.2vw;
    border-radius: 0.7vh;
    background: var(--tv-badge-bg);
    color: var(--tv-text);
    text-decoration: none;
    border: 1px solid var(--tv-card-border);
    white-space: nowrap;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.tv-back:hover,
.tv-back:focus {
    color: var(--tv-text);
    text-decoration: none;
    background: var(--tv-badge-cat-bg);
}

/* Header: a smaller uppercase sub-label next to the match name (e.g. "Results"). */
.tv-header .tv-screen-sub {
    font-size: calc(1.7 * var(--fs));
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.10em;
    color: var(--tv-accent);
}

/* Countdown ring (jquery.countdown360 draws a <canvas>) lives in the header. */
.tv-countdown {
    display: flex;
    align-items: center;
}

.tv-countdown canvas {
    display: block;
}

/* Scrollable content region for the non-cycling screens (the cycling area
 * screen uses .tv-stage / .tv-area-panel instead). */
.tv-content {
    flex: 1 1 auto;
    overflow: auto;
    padding: 2vh 2.2vw;
}

.tv-screen-title {
    font-size: calc(3.2 * var(--fs));
    font-weight: 800;
    text-align: center;
    margin: 0 0 1.6vh;
}

.tv-section-title {
    font-size: calc(2.6 * var(--fs));
    font-weight: 800;
    color: var(--tv-strong);
    margin: 1.8vh 0 0.8vh;
    padding-bottom: 0.4vh;
    border-bottom: 0.3vh solid var(--tv-accent);
    display: inline-block;
}

.tv-section-sub {
    font-size: calc(1.9 * var(--fs));
    font-weight: 700;
    color: var(--tv-text-muted);
    margin: 0.6vh 0;
}

/* Centered "nothing to show yet" message. */
.tv-empty-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: calc(3.4 * var(--fs));
    font-weight: 700;
    color: var(--tv-text-muted);
}

/* ---- Grouping toolbar (Overall / Category / Class / Stage / Team) ---- */
.tv-toolbar {
    display: flex;
    justify-content: flex-end;
    gap: 0.6vw;
    flex-wrap: wrap;
    margin-bottom: 1.2vh;
}

.tv-btn {
    font-size: calc(1.7 * var(--fs));
    font-weight: 700;
    padding: 0.7vh 1.3vw;
    border-radius: 0.7vh;
    background: var(--tv-badge-bg);
    color: var(--tv-text);
    text-decoration: none;
    border: 1px solid var(--tv-card-border);
    white-space: nowrap;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.tv-btn:hover,
.tv-btn:focus {
    color: var(--tv-text);
    text-decoration: none;
    background: var(--tv-badge-cat-bg);
}

.tv-btn.active {
    background: var(--tv-accent);
    color: #fff;
    border-color: var(--tv-accent);
}

/* Filter toggle set apart from the grouping pills in the carousel toolbar. */
.tv-btn--filter {
    margin-left: 1.6vw;
}

/* ---- Leaderboard / results table ---- */
.tv-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.6vh;
    background: var(--tv-card-bg);
    border: 1px solid var(--tv-card-border);
    border-radius: 1vh;
    overflow: hidden;
}

.tv-table thead th {
    font-size: calc(1.5 * var(--fs));
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--tv-text-muted);
    background: var(--tv-head);
    padding: 0.8vh 0.8vw;
    text-align: left;
    white-space: nowrap;
}

.tv-table tbody td {
    font-size: calc(1.9 * var(--fs));
    font-weight: 600;
    padding: 0.65vh 0.8vw;
    border-top: 1px solid var(--tv-card-border);
    font-variant-numeric: tabular-nums;
}

.tv-table tbody tr:nth-child(even) td {
    background: var(--tv-card-bg-empty);
}

.tv-table .num {
    text-align: center;
}

.tv-table .place {
    text-align: center;
    font-weight: 800;
    color: var(--tv-accent);
    width: 4vw;
}

.tv-table .hf {
    color: var(--tv-good);
    font-weight: 800;
}

.tv-table tr.dq td {
    color: var(--tv-bad);
    font-weight: 700;
}

/* Top-3 medal accents on the place column. */
.tv-table tr.rank-1 .place { color: #f5c518; }
.tv-table tr.rank-2 .place { color: #c7ccd1; }
.tv-table tr.rank-3 .place { color: #cd7f32; }

/* ---- Stage detail (single shooter + squad verify) ---- */
.tv-detail-name {
    font-size: calc(3 * var(--fs));
    font-weight: 800;
    margin: 0 0 0.4vh;
}

.tv-detail-meta {
    display: flex;
    gap: 1.4vw;
    flex-wrap: wrap;
    font-size: calc(1.9 * var(--fs));
    color: var(--tv-text-muted);
    margin-bottom: 1.4vh;
}

.tv-detail-meta b {
    color: var(--tv-text);
}

.tv-stats {
    display: flex;
    gap: 1vw;
    flex-wrap: wrap;
    margin-bottom: 1.6vh;
}

.tv-stat {
    flex: 1 1 0;
    min-width: 7vw;
    background: var(--tv-card-bg);
    border: 1px solid var(--tv-card-border);
    border-radius: 1vh;
    padding: 1vh 1vw;
    text-align: center;
}

.tv-stat .lbl {
    font-size: calc(1.4 * var(--fs));
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--tv-text-muted);
}

.tv-stat .val {
    font-size: calc(4 * var(--fs));
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.tv-stat.good .val { color: var(--tv-good); }
.tv-stat.accent { background: var(--tv-accent-soft); }

.tv-deck {
    text-align: right;
    color: var(--tv-text-muted);
    font-size: calc(1.8 * var(--fs));
    margin-bottom: 0.8vh;
}

.tv-deck b { color: var(--tv-text); }

/* Squad status grid */
.tv-squad {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(20vw, 1fr));
    gap: 0.8vh 0.8vw;
}

.tv-squad-item {
    border: 1px solid var(--tv-card-border);
    border-left: 0.5vw solid var(--tv-card-border);
    border-radius: 0.7vh;
    padding: 0.7vh 0.9vw;
    background: var(--tv-card-bg);
    font-size: calc(1.7 * var(--fs));
}

.tv-squad-item.done    { border-left-color: var(--tv-good); }
.tv-squad-item.pending { border-left-color: var(--tv-accent); }
.tv-squad-item.dq      { border-left-color: var(--tv-bad); }
.tv-squad-item.absent  { border-left-color: var(--tv-warn); }

.tv-squad-item .nm { font-weight: 700; }
.tv-squad-item .dt { color: var(--tv-text-muted); font-size: calc(1.4 * var(--fs)); }

.tv-banner {
    margin: 5vh auto 0;
    max-width: 30vw;
    display: block;
}

.tv-banner img {
    width: 100%;
    border-radius: 1vh;
}

/* ---- Verify kiosk (search + print) ---- */
.tv-search {
    display: flex;
    gap: 0.8vw;
    max-width: 60vw;
    margin: 2vh auto 1.6vh;
}

.tv-search input[type="text"] {
    flex: 1 1 auto;
    font-size: calc(2.4 * var(--fs));
    padding: 1vh 1.2vw;
    border-radius: 0.8vh;
    border: 1px solid var(--tv-card-border);
    background: var(--tv-card-bg);
    color: var(--tv-text);
}

.tv-search input[type="text"]::placeholder { color: var(--tv-text-muted); }

.tv-search .tv-btn {
    font-size: calc(2.2 * var(--fs));
    display: inline-flex;
    align-items: center;
    gap: 0.4vw;
}

.tv-alert {
    max-width: 60vw;
    margin: 1vh auto;
    padding: 1vh 1.4vw;
    border-radius: 0.8vh;
    font-size: calc(1.9 * var(--fs));
    background: var(--tv-accent-soft);
    color: var(--tv-text);
    border: 1px solid var(--tv-card-border);
}

.tv-alert.danger {
    background: rgba(248, 113, 113, 0.14);
    border-color: var(--tv-bad);
    color: var(--tv-bad);
}

/* ---- Pager / per-page links ---- */
.tv-pager {
    text-align: center;
    margin-top: 1.2vh;
    color: var(--tv-text-muted);
    font-size: calc(1.7 * var(--fs));
}

.tv-pager a {
    color: var(--tv-text-muted);
    margin: 0 0.4vw;
    text-decoration: none;
}

.tv-pager a:hover { color: var(--tv-accent); }

/* ---- Compact stage picker pinned to the bottom (stage top hit factors) ---- */
.tv-stage-picker {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5vw;
    padding: 0.8vh 2.2vw;
    background: var(--tv-header-bg);
    border-top: 1px solid var(--tv-card-border);
}

/* Force the following items onto a new line within the wrapping flex picker. */
.tv-stage-picker .break {
    flex-basis: 100%;
    height: 0;
}

/* Top-of-content variant: border below instead of above, used as a filter bar. */
.tv-stage-picker--top {
    border-top: 0;
    border-bottom: 1px solid var(--tv-card-border);
    background: transparent;
    margin-bottom: 1.6vh;
    padding-left: 0;
    padding-right: 0;
}

.tv-stage-picker .sep {
    font-size: calc(1.4 * var(--fs));
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--tv-text-muted);
    margin-right: 0.3vw;
}

/* Extra leading space when a separator follows other controls on the same row. */
.tv-stage-picker .sep--gap {
    margin-left: 1.6vw;
}

.tv-stage-picker a {
    font-size: calc(1.5 * var(--fs));
    font-weight: 700;
    min-width: 2.4vw;
    text-align: center;
    padding: 0.4vh 0.8vw;
    border-radius: 0.6vh;
    background: var(--tv-badge-bg);
    color: var(--tv-text);
    text-decoration: none;
    border: 1px solid var(--tv-card-border);
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.tv-stage-picker a:hover,
.tv-stage-picker a:focus {
    background: var(--tv-badge-cat-bg);
    color: var(--tv-text);
    text-decoration: none;
}

.tv-stage-picker a.active {
    background: var(--tv-accent);
    color: #fff;
    border-color: var(--tv-accent);
}

/* ---- Portal list / link cards ---- */
.tv-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(28vw, 1fr));
    gap: 1.4vh 1.4vw;
}

.tv-link-card {
    display: block;
    background: var(--tv-card-bg);
    border: 1px solid var(--tv-card-border);
    border-radius: 1.2vh;
    padding: 1.6vh 1.6vw;
    color: var(--tv-text);
    text-decoration: none;
    box-shadow: 0 0.6vh 1.6vh var(--tv-shadow);
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.tv-link-card:hover {
    color: var(--tv-text);
    text-decoration: none;
    transform: translateY(-0.4vh);
    border-color: var(--tv-accent);
}

.tv-link-card .tv-link-title {
    font-size: calc(2.4 * var(--fs));
    font-weight: 800;
    margin-bottom: 0.4vh;
}

.tv-link-card .tv-link-desc {
    font-size: calc(1.7 * var(--fs));
    color: var(--tv-text-muted);
}

/* The portal pages are interactive, so allow normal text selection/scrolling
 * the passive boards suppress. */
.tv-scroll {
    overflow: auto;
}

/* ---- Print (verify kiosk): force a clean white slip regardless of theme. ---- */
@media print {
    html, body, .tv-body {
        background: #fff !important;
        color: #000 !important;
        height: auto !important;
        overflow: visible !important;
        display: block !important;
    }

    .tv-header,
    .tv-search,
    .tv-countdown,
    .d-print-none {
        display: none !important;
    }

    .tv-content { overflow: visible !important; }

    .tv-table { background: #fff !important; border-color: #999 !important; }
    .tv-table thead th { color: #000 !important; background: #eee !important; }
    .tv-table tbody td { color: #000 !important; border-color: #ccc !important; }
}
