/* Arena theme: dark broadcast look, strictly square corners */

:root {
    --bg: #07080b;
    --panel: #0e1015;
    --panel-2: #161922;
    --line: #22262f;
    --line-2: #2f3441;
    --ink: #f5f6f8;
    --ink-2: #c5cad3;
    --muted: #7d8595;
    --accent: #ff1f2d;
    --win: #22c55e;
    --draw: #9aa3b2;
    --loss: #ef4444;
    --sq-light: #d9dee6;
    --sq-dark: #6e7a8b;
    --photo-w: 78px;
    --photo-h: 98px;
    --evalbar-w: 26px;
    --eb-white: #eef1f5;
    --eb-black: #050608;
    --display: "Barlow Condensed", "Arial Narrow", Impact, sans-serif;
    --text: Inter, system-ui, "Segoe UI", Arial, sans-serif;
    color-scheme: dark;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    border-radius: 0 !important;
}

body {
    margin: 0;
    font-family: var(--text);
    color: var(--ink);
    background-color: var(--bg);
    background-image:
        linear-gradient(rgba(255, 255, 255, .025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .025) 1px, transparent 1px);
    background-size: 48px 48px;
    -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: stretch;
    flex-wrap: wrap;
    gap: 0 28px;
    min-height: 60px;
    padding: 0 24px 0 0;
    background: rgba(7, 8, 11, .88);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
    display: grid;
    place-items: center;
    align-self: stretch;
    width: 60px;
    background: var(--accent);
    color: #fff;
    font-size: 30px;
}

.brand-text { display: flex; flex-direction: column; }
.brand-title { font: 800 22px/1 var(--display); letter-spacing: .06em; text-transform: uppercase; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* team switch: the primary choice — which team's match to follow */
.teamswitch { display: flex; align-self: center; border: 1px solid var(--line-2); }
.teamswitch button {
    padding: 8px 16px;
    border: 0;
    border-right: 1px solid var(--line-2);
    background: var(--panel-2);
    color: var(--muted);
    font: 700 15px var(--display);
    letter-spacing: .06em;
    text-transform: uppercase;
    cursor: pointer;
}

.teamswitch button:last-child { border-right: 0; }
.teamswitch button:hover { color: var(--ink); }
.teamswitch button.active { background: var(--accent); color: #fff; }
.teamswitch button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tabs { display: flex; align-items: stretch; }

.tabs button {
    padding: 0 18px;
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: var(--muted);
    font: 700 16px var(--display);
    letter-spacing: .08em;
    text-transform: uppercase;
    cursor: pointer;
}

.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); background: linear-gradient(0deg, rgba(255, 31, 45, .12), transparent); }

.controls { display: flex; align-items: center; gap: 14px; margin-left: auto; flex-wrap: wrap; padding: 10px 0; }

.field { display: flex; align-items: center; gap: 8px; font: 700 13px var(--display); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

.field select {
    appearance: none;
    padding: 8px 32px 8px 12px;
    border: 1px solid var(--line-2);
    background: var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%237d8595' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 11px center;
    color: var(--ink);
    font: 600 14px var(--text);
    cursor: pointer;
}

.field select:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.field select:disabled { opacity: .5; cursor: not-allowed; }

main { max-width: 1480px; margin: 0 auto; padding: 24px; }

/* ---------- hero scoreboard ---------- */

.hero {
    position: relative;
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--line);
    border-top: 4px solid var(--accent);
}

.hero::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(720px 260px at 22% 55%, rgba(255, 31, 45, .16), transparent 70%);
    pointer-events: none;
}

.hero > * { position: relative; z-index: 1; }

.hero-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 20px;
    border-bottom: 1px solid var(--line);
}

.chips { display: flex; gap: 8px; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border: 1px solid var(--line-2);
    background: var(--panel-2);
    font: 700 14px/1.2 var(--display);
    letter-spacing: .12em;
    text-transform: uppercase;
}

.chip.live { background: var(--accent); border-color: var(--accent); }
.chip.live::before { content: ""; width: 7px; height: 7px; background: #fff; animation: pulse 1.4s ease-in-out infinite; }

.countdown { font: 700 14px var(--display); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.countdown .cd-time { margin-left: 10px; color: var(--ink); font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: .04em; }

.hero-main { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; }

.side { display: flex; align-items: center; gap: 18px; min-width: 0; padding: 30px 28px; }
.side.home { justify-content: flex-end; }

.name {
    font: 800 48px/1 var(--display);
    letter-spacing: .01em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.code {
    flex: none;
    display: grid;
    place-items: center;
    width: 68px;
    height: 68px;
    border: 2px solid var(--line-2);
    font: 800 22px var(--display);
    letter-spacing: .08em;
}

.code:empty { visibility: hidden; }
.home .code { background: var(--accent); border-color: var(--accent); }

.score {
    display: flex;
    align-items: center;
    font: 800 112px/1 var(--display);
    font-variant-numeric: tabular-nums;
}

.score .sep {
    display: inline-block;
    width: 34px;
    height: 10px;
    margin: 0 26px;
    background: var(--accent);
    font-size: 0;
}

.sb-verdict {
    padding: 0 20px 20px;
    text-align: center;
    font: 700 17px var(--display);
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted);
}

.sb-verdict.win { color: var(--win); }
.sb-verdict.loss { color: var(--loss); }
.sb-verdict.draw { color: var(--draw); }

.hero-probs { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); }

.tile {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 14px 20px;
    border-right: 1px solid var(--line);
}

.tile:nth-child(3) { border-right: 0; }
.tile .k { font: 700 14px var(--display); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.tile .v { font: 800 44px/1 var(--display); font-variant-numeric: tabular-nums; }
.tile.win .v { color: var(--win); }
.tile.draw .v { color: var(--draw); }
.tile.lose .v { color: var(--loss); }

.hero > .wdl { height: 8px; }

.prob-note { padding: 10px 20px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

/* ---------- probability bars ---------- */

.wdl { display: flex; overflow: hidden; background: var(--panel-2); }
.wdl div { width: 0; transition: width .5s ease; }
.wdl .w { background: var(--win); }
.wdl .d { background: var(--draw); }
.wdl .l { background: var(--loss); }
.wdl.small { height: 4px; }

.status { margin: 16px 0; min-height: 1.2em; text-align: center; font-size: 14px; color: var(--muted); }
.status:empty { display: none; }

/* ---------- board cards ---------- */

.boards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }

.board-card {
    --state: var(--line-2);
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--line);
}

.board-card::before {
    content: "";
    position: absolute;
    inset: -1px -1px auto;
    height: 3px;
    background: var(--state);
    z-index: 2;
}

.board-card.is-live { --state: var(--accent); }
.board-card.is-win { --state: var(--win); }
.board-card.is-draw { --state: var(--draw); }
.board-card.is-loss { --state: var(--loss); }

.bc-top { display: grid; grid-template-columns: var(--photo-w) minmax(0, 1fr); }
.bc-bottom { display: grid; grid-template-columns: minmax(0, 1fr) var(--photo-w); border-top: 1px solid var(--line); }

.bc-photo {
    position: relative;
    display: grid;
    place-items: center;
    width: var(--photo-w);
    height: var(--photo-h);
    overflow: hidden;
    background: var(--panel-2);
}

.bc-photo img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 18%;
}

.bc-photo .initials { font: 800 28px var(--display); letter-spacing: .04em; color: var(--muted); }
.bc-photo.mine { background: linear-gradient(180deg, #3b0609, #160203); }
.bc-photo.mine .initials { color: var(--accent); }

.bc-photo::after { content: ""; position: absolute; top: 0; bottom: 0; width: 3px; }
.bc-photo.opp::after { right: 0; background: var(--line-2); }
.bc-photo.mine::after { left: 0; background: var(--accent); }

.bc-info { display: flex; flex-direction: column; justify-content: space-between; gap: 8px; min-width: 0; padding: 10px 12px; }

.bc-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.bc-no { font: 700 15px var(--display); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    background: var(--panel-2);
    color: var(--ink-2);
    font: 700 13px/1.2 var(--display);
    letter-spacing: .1em;
    text-transform: uppercase;
    white-space: nowrap;
}

.is-live .badge { background: var(--accent); color: #fff; }
.is-live .badge::before { content: ""; width: 6px; height: 6px; background: #fff; animation: pulse 1.4s ease-in-out infinite; }
.is-win .badge { background: rgba(34, 197, 94, .16); color: var(--win); }
.is-loss .badge { background: rgba(239, 68, 68, .16); color: var(--loss); }

/* the name gets a full row so it is never cut; Elo and clock share the row below */
.bc-player {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name name" "sub clock";
    align-items: center;
    gap: 4px 10px;
}

.bc-player.bottom { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "name name" "clock sub"; }
.bc-player.bottom .p-line { justify-content: flex-end; text-align: right; }
.bc-player.bottom .p-sub { text-align: right; }

.p-main { display: contents; }
.p-line { grid-area: name; display: flex; align-items: flex-start; gap: 8px; min-width: 0; }
.p-sub { grid-area: sub; }
.p-clock, .p-clock-empty { grid-area: clock; }

.piece { flex: none; width: 10px; height: 10px; margin-top: 6px; }
.piece.white { background: #f5f6f8; }
.piece.black { background: #000; box-shadow: inset 0 0 0 1px var(--muted); }

.p-name {
    min-width: 0;
    font: 700 21px/1.1 var(--display);
    letter-spacing: .02em;
    text-transform: uppercase;
    overflow-wrap: anywhere;
}

.tr-mark {
    display: inline-block;
    margin-right: 6px;
    padding: 1px 5px;
    background: var(--accent);
    color: #fff;
    font: 800 13px/1.2 var(--display);
    vertical-align: 2px;
}

.p-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.p-delta { margin-left: 8px; }
.up { color: var(--win); }
.down { color: var(--loss); }

.p-clock {
    padding: 2px 8px;
    border: 1px solid var(--line-2);
    background: var(--panel-2);
    color: var(--ink-2);
    font: 700 23px/1.1 var(--display);
    font-variant-numeric: tabular-nums;
    letter-spacing: .02em;
}

.p-clock.to-move { background: #fff; border-color: #fff; color: #000; }
.p-clock.low { border-color: var(--loss); color: var(--loss); }
.p-clock.low.to-move { background: var(--loss); color: #fff; animation: pulse 1s ease-in-out infinite; }

.bc-board { display: grid; grid-template-columns: var(--evalbar-w) minmax(0, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.bc-cb { min-width: 0; }

/* Stockfish eval bar: the team player's colour fills from the bottom, matching the board orientation */
.evalbar {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    overflow: hidden;
    background: var(--eb-black);
    box-shadow: inset -1px 0 0 var(--line-2);
}

.evalbar.bottom-black { background: var(--eb-white); }
.eb-fill { height: 50%; background: var(--eb-white); transition: height .6s ease; }
.evalbar.bottom-black .eb-fill { background: var(--eb-black); }

.evalbar::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 2px;
    margin-top: -1px;
    background: var(--accent);
    opacity: .85;
}

.eb-label {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 1;
    text-align: center;
    font: 800 12px/1 var(--display);
    letter-spacing: -.02em;
    font-variant-numeric: tabular-nums;
}

.evalbar[data-lead="bottom"] .eb-label { bottom: 5px; }
.evalbar[data-lead="top"] .eb-label { top: 5px; }
.eb-label.on-white { color: var(--eb-black); }
.eb-label.on-black { color: var(--eb-white); }

.bc-foot { display: flex; flex-direction: column; gap: 6px; padding: 8px 12px; }
.bc-stats { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bc-probs b { font: 700 15px var(--display); letter-spacing: .04em; }
.c-win { color: var(--win); }
.c-draw { color: var(--draw); }
.c-loss { color: var(--loss); }

/* chessboard.js overrides */
.board-b72b1 { border: 0 !important; }
.white-1e1d7 { background-color: var(--sq-light) !important; color: var(--sq-dark) !important; }
.black-3c85d { background-color: var(--sq-dark) !important; color: var(--sq-light) !important; }

.footer {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 1480px;
    margin: 0 auto;
    padding: 0 24px 32px;
    font: 600 13px var(--display);
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .4; }
}

@media (prefers-reduced-motion: reduce) {
    .chip.live::before, .is-live .badge::before, .p-clock.low.to-move { animation: none; }
    .wdl div, .eb-fill { transition: none; }
}

@media (max-width: 900px) {
    .name { font-size: 34px; }
    .score { font-size: 80px; }
    .score .sep { width: 24px; height: 8px; margin: 0 16px; }
    .side { padding: 22px 16px; gap: 12px; }
    .code { width: 54px; height: 54px; font-size: 18px; }
}

@media (max-width: 760px) {
    :root { --photo-w: 66px; --photo-h: 83px; --evalbar-w: 22px; }
    .topbar { position: static; padding: 0; }
    .brand { width: 100%; border-bottom: 1px solid var(--line); }
    .brand-mark { width: 48px; height: 48px; font-size: 24px; }
    .tabs { width: 100%; overflow-x: auto; border-bottom: 1px solid var(--line); }
    .tabs button { height: 44px; white-space: nowrap; }
    .controls { margin: 0; padding: 10px 14px; }
    main { padding: 14px; }
    .side { padding: 18px 10px; gap: 8px; }
    .name { font-size: 22px; }
    .code { width: 38px; height: 38px; font-size: 13px; border-width: 1px; }
    .score { font-size: 58px; }
    .score .sep { width: 16px; height: 6px; margin: 0 10px; }
    .hero-probs { grid-template-columns: repeat(3, 1fr); }
    .tile { flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; }
    .tile .k { font-size: 12px; }
    .tile .v { font-size: 30px; }
    .boards { grid-template-columns: 1fr; }
    .footer { padding: 0 14px 24px; }
}

@media (max-width: 420px) {
    .code { display: none; }
    .name { font-size: 19px; }
    .score { font-size: 48px; }
}

/* ---------- one-screen layout: everything fits the viewport on desktop, no page scroll ---------- */

@media (min-width: 1100px) and (min-height: 560px) {
    :root { --photo-w: 60px; --photo-h: 75px; }

    body {
        height: 100vh;
        height: 100dvh;
        display: grid;
        grid-template-rows: auto minmax(0, 1fr) auto;
        overflow: hidden;
    }

    .topbar { min-height: 52px; }
    .brand-mark { width: 52px; font-size: 26px; }

    main {
        width: 100%;
        min-height: 0;
        display: grid;
        grid-template-rows: auto auto minmax(0, 1fr);
        gap: 12px;
        padding: 12px 24px;
    }

    /* explicit rows: the empty status line is display:none, which would otherwise pull the boards into the auto row */
    .hero { grid-row: 1; }
    .status { grid-row: 2; margin: 0; }
    .boards { grid-row: 3; }

    .hero {
        display: grid;
        grid-template-columns: 200px minmax(0, 1fr) 340px;
        grid-template-areas:
            "top main probs"
            "top verdict probs"
            "bar bar bar";
    }

    /* the team W/D/L bar spans the whole scoreboard */
    .hero > .wdl { grid-area: bar; }

    .hero-top {
        grid-area: top;
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
        gap: 10px;
        border-bottom: 0;
        border-right: 1px solid var(--line);
    }

    .countdown .cd-time { display: block; margin: 2px 0 0; }
    .hero-main { grid-area: main; }
    .side { padding: 14px 16px 4px; gap: 14px; }
    .name { font-size: 34px; }
    .code { width: 48px; height: 48px; font-size: 17px; }
    .score { font-size: 72px; }
    .score .sep { width: 24px; height: 8px; margin: 0 18px; }
    .sb-verdict { grid-area: verdict; padding: 0 16px 12px; font-size: 15px; }

    .hero-probs { grid-area: probs; border-top: 0; border-left: 1px solid var(--line); }
    .tile { flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 8px; }
    .tile .k { font-size: 12px; }
    .tile .v { font-size: 34px; }
    .prob-note { display: none; }

    .boards {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        align-content: start;
        gap: 12px;
        min-height: 0;
        overflow: hidden;
    }

    .bc-info { padding: 6px 10px; gap: 4px; }
    .bc-no { font-size: 13px; }
    .bc-photo .initials { font-size: 22px; }
    .p-name { font-size: 18px; }
    .p-clock { font-size: 19px; }
    .bc-foot { padding: 6px 10px; gap: 4px; }

    /* app.js sets --board-size from the height left for the boards */
    .bc-board { display: flex; justify-content: center; }
    .evalbar { flex: none; width: var(--evalbar-w); }
    .bc-cb { flex: none; width: var(--board-size, 100%); }

    .footer { padding: 6px 24px; }
}
