:root {
    --bg: #0B0D10;
    --panel: #14171C;
    --panel-alt: #1A1E24;
    --row-alt: #191D23;
    --border: #262B33;
    --flame: #FF5A1F;
    --flame-dim: rgba(255, 90, 31, .16);
    --amber: #FFB020;
    --cold: #3AA0FF;
    --text: #F2F4F7;
    --muted: #8A93A0;
    --muted-2: #5B6270;
    --good: #3ED598;
    --danger: #FF4D5E;
}

[data-theme="light"] {
    --bg: #F4F5F7;
    --panel: #FFFFFF;
    --panel-alt: #F0F1F3;
    --row-alt: #FAFBFC;
    --border: #E1E4E9;
    --text: #14171C;
    --muted: #5B6270;
    --muted-2: #8A93A0;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, sans-serif;
    height: 100%;
    overflow: hidden;
}

.mono {
    font-family: 'JetBrains Mono', monospace;
}

.display {
    font-family: 'Oswald', sans-serif;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: radial-gradient(700px 420px at 8% -8%, rgba(255, 90, 31, .10), transparent 60%),
    radial-gradient(600px 380px at 105% 8%, rgba(58, 160, 255, .07), transparent 60%);
}

.app {
    position: relative;
    z-index: 1;
    max-width: 1720px;
    margin: 0 auto;
    padding: 14px 20px;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

header.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 0 0 auto;
    background: linear-gradient(180deg, var(--panel-alt), var(--panel));
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 18px;
    margin-bottom: 16px;
}

.crest {
    overflow: hidden;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: conic-gradient(from 220deg, var(--flame), var(--amber), var(--flame));
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    box-shadow: 0 0 0 3px var(--flame-dim);
}

.crest span {
    font-size: 18px;
}

.crest img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.title-block {
    min-width: 0;
}

.title-block h1 {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-family: 'Oswald', sans-serif;
    font-weight: 600;
    font-size: 19px;
    margin: 0;
    letter-spacing: .2px;
}

.title-block .discipline {
    color: var(--muted);
    font-size: 13px;
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--flame-dim);
    color: var(--flame);
    border: 1px solid rgba(255, 90, 31, .4);
    padding: 3px 9px 3px 7px;
    border-radius: 100px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    flex: 0 0 auto;
}

.live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--flame);
    box-shadow: 0 0 0 0 rgba(255, 90, 31, .6);
    animation: pulse 1.6s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 90, 31, .55);
    }
    70% {
        box-shadow: 0 0 0 7px rgba(255, 90, 31, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 90, 31, 0);
    }
}

.top-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}

.meta-col {
    text-align: right;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.5;
}

.meta-col b {
    color: var(--text);
    font-weight: 600;
}

.weather {
    display: flex;
    align-items: center;
    gap: 8px;
    border-left: 1px solid var(--border);
    padding-left: 16px;
    font-family: 'JetBrains Mono', monospace;
}

.weather .temp {
    font-size: 18px;
    font-weight: 700;
    color: var(--cold);
}

.weather .wcity {
    font-size: 11px;
    color: var(--muted-2);
    display: block;
}

.refresh-ring {
    position: relative;
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    border-left: 1px solid var(--border);
    padding-left: 16px;
    margin-left: 2px;
}

.refresh-ring svg {
    transform: rotate(-90deg);
    width: 34px;
    height: 34px;
}

.refresh-ring circle.track {
    fill: none;
    stroke: var(--border);
    stroke-width: 3;
}

.refresh-ring circle.bar {
    fill: none;
    stroke: var(--flame);
    stroke-width: 3;
    stroke-linecap: round;
    transition: stroke-dashoffset .3s linear;
}

.refresh-ring .rlabel {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: var(--muted);
}

.demo-banner {
    display: none;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    background: rgba(255, 176, 32, .10);
    border: 1px solid rgba(255, 176, 32, .35);
    color: var(--amber);
    border-radius: 10px;
    padding: 8px 14px;
    font-size: 12.5px;
    margin-bottom: 14px;
}

.demo-banner.show {
    display: flex;
}

.grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns:1fr 1fr;
    grid-template-rows:1.4fr 1fr;
    grid-template-areas:"heats best" "heats bottom";
    gap: 16px;
}

.panel-heats {
    grid-area: heats;
}

.panel-best {
    grid-area: best;
}

.panel-row-bottom {
    grid-area: bottom;
    display: grid;
    grid-template-columns:1fr 1fr;
    gap: 16px;
    min-height: 0;
}

.panel-row-bottom .panel {
    min-height: 0;
}

@media (max-width: 980px) {
    html, body {
        overflow: auto;
    }

    .app {
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .grid {
        display: flex;
        flex-direction: column;
        flex: none;
        height: auto;
        gap: 16px;
    }

    .panel-row-bottom {
        grid-template-columns:1fr;
    }

    .panel {
        flex: none !important;
    }

    .table-wrap {
        flex: none !important;
        max-height: 50vh;
    }
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--border);
}

.panel-head h2 {
    font-family: 'Oswald', sans-serif;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: .04em;
    text-transform: uppercase;
    margin: 0;
    color: var(--text);
}

.panel-head h2 .accent {
    color: var(--flame);
}

.updated-tag {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--muted-2);
}

.tabs {
    display: flex;
    gap: 2px;
    padding: 8px 12px 0;
}

.tab {
    padding: 8px 14px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    cursor: pointer;
    user-select: none;
    font-family: 'Inter', sans-serif;
    letter-spacing: .02em;
}

.tab.active {
    color: var(--text);
    border-bottom-color: var(--flame);
}

.tab:hover {
    color: var(--text);
}

.table-wrap {
    overflow: auto;
    flex: 1;
    min-height: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--panel-alt);
    text-align: left;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

tbody tr.heat-group-alt{background:var(--row-alt);}
tbody tr.heat-group-alt:hover{background:var(--panel-alt);}
.heat-cell[rowspan]{
  border-right:10px solid var(--border);
  font-weight:700;
  font-size:15px;
  color:var(--text);   /* замість приглушеного var(--muted), яким пофарбовані звичайні .heat-cell */
}
tbody tr.heat-group-start td{
  border-top:10px solid var(--flame-dim);
}

tbody tr.flip-move {
    transition: transform .5s cubic-bezier(.2, .7, .3, 1);
}

tbody tr.flash {
    animation: flash-row 1.1s ease;
}

@keyframes flash-row {
    0% {
        background: rgba(255, 90, 31, .22);
    }
    100% {
        background: transparent;
    }
}

.heat-cell {
    color: var(--muted);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    vertical-align: middle;
    text-align: center;
}

.team-name {
    font-weight: 600;
}

.roster {
    color: var(--muted);
    font-size: 11.5px;
    line-height: 1.5;
    margin-top: 2px;
}

.roster .rk {
    color: var(--muted-2);
    margin-right: 4px;
}

.time {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

.time.best {
    color: var(--amber);
}

.time.zero {
    color: var(--muted-2);
    font-weight: 400;
}

.corr::after {
    content: " \00B9";
    color: var(--cold);
    font-size: 10px;
    vertical-align: super;
}

.rank-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}

.rank-pill.r1 {
    background: rgba(255, 176, 32, .18);
    color: var(--amber);
}

.rank-pill.r2 {
    background: rgba(242, 244, 247, .12);
    color: #DADFE5;
}

.rank-pill.r3 {
    background: rgba(255, 90, 31, .16);
    color: var(--flame);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.foot-note {
    padding: 9px 16px;
    font-size: 10.5px;
    color: var(--muted-2);
    border-top: 1px solid var(--border);
}

.empty {
    padding: 24px 16px;
    color: var(--muted-2);
    font-size: 12.5px;
    text-align: center;
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    color: var(--text);
    font-size: 14px;
}

.discipline-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: transparent;
    border: none;
    outline: none;
    color: var(--muted);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    cursor: pointer;
    padding: 0 14px 0 0;
}

.discipline-select option {
    background: var(--panel);
    color: var(--text);
}

.finalists-panel {
    flex: 0 0 auto;
    border-top: 1px solid var(--border);
    padding: 10px 16px;
}

.finalists-head {
    font-family: 'Oswald', sans-serif;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--flame);
    margin-bottom: 6px;
}

.finalists-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}

.finalists-table td {
    padding: 5px 6px;
    border-bottom: 1px solid var(--border);
}

.finalists-table tr:last-child td {
    border-bottom: none;
}

/* WebKit (Chrome, Edge, Safari) */
.table-wrap::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.table-wrap::-webkit-scrollbar-track {
    background: transparent;
}

.table-wrap::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 100px;
    border: 2px solid var(--panel);
    background-clip: padding-box;
}

.table-wrap::-webkit-scrollbar-thumb:hover {
    background: var(--flame);
    background-clip: padding-box;
}

/* Firefox */
.table-wrap {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.ctx-menu{
  position:fixed; z-index:60; background:var(--panel-alt); border:1px solid var(--border);
  border-radius:8px; box-shadow:0 8px 24px rgba(0,0,0,.45); overflow:hidden; min-width:190px;
}
.ctx-item{padding:9px 14px; font-size:12.5px; color:var(--text); cursor:pointer;}
.ctx-item:hover{background:var(--flame-dim); color:var(--flame);}
.ctx-cell{cursor:context-menu;}