/* Theme matched against a live render of the real EGOI 2025 scoreboard
 * (scoreboard.egoi2025.de). Its defining trait: the WHOLE row is tinted by
 * medal tier as flat, uniform pill capsules (name + every score cell share
 * one solid color) — there is no per-value gradient. Rank and Total sit on
 * plain page background as bold black text, not inside a pill. */
:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --ink: #14161c;
  --ink-soft: #5a6072;
  --muted: #8a8fa3;
  --border: #e2dfe7;
  --border-strong: #d3cdd9;

  --rose: #e6bec8;          /* EGOI header background, sampled rgb(230,190,200) */
  --rose-deep: #d9a7b5;
  --rose-ink: #5c2740;
  --accent: #c85a7c;
  --accent-deep: #b0466a;
  --chart-blue: #3562c9;    /* task-detail modal's score/place-over-time charts */

  --gold: #e9c979;          /* sampled rgb(233,201,121) */
  --silver: #d3d3d3;        /* sampled rgb(211,211,211) */
  --bronze: #e6bf99;        /* mixColor([205,127,50], white, .5) */
  --none-a: #f4f5f8;        /* no-medal zebra (neutral, page has no reference row to sample) */
  --none-b: #ffffff;
  --blank: #e4e4fb;         /* cellColors.none — no-submission override, any tier */

  --row-h: 38px;
  --gap: 5px;
  font-synthesis: none;

  /* Every independently-scrolling side panel (.board/.cboard, .feed,
   * .sidebar) caps itself to exactly the viewport's leftover vertical space
   * so NONE of them ever forces the outer page itself to scroll — measured,
   * not guessed: header(40) + controls(68) + main's own padding-top(14) +
   * padding-bottom(60) = 182px of fixed chrome above/below the panel row.
   * Get this number wrong (even by a few px) and the whole page grows a
   * second, redundant scrollbar alongside each panel's own one. */
  --panel-max-h: calc(100vh - 182px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Helvetica, Arial, "Liberation Sans", sans-serif;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
}
/* Real EGOI's own stylesheet: body{font-size:20px;font-family:sans-serif},
 * with monospace applied ONLY to clock/timestamp strings (contest timer, log
 * entry times) — never the whole board. We use 17px base (vs their 20px)
 * since our data has full contestant names, not 2-letter initials, and would
 * overflow the fixed-width name column at full size. */
.mono-time { font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace; }
a { color: var(--accent-deep); text-decoration: none; }
a:hover { text-decoration: underline; }
.spacer { flex: 1; }

/* ---- top header: plain black-on-white like the real EGOI board (rose is
 * reserved for table header rows / announce banners, never the page chrome) ---- */
header {
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  gap: 16px;
  padding: 10px 24px 6px;
  background: #fff;
  color: var(--ink);
  position: sticky;
  top: 0;
  z-index: 20;
}
header > * { flex-shrink: 0; white-space: nowrap; }
header h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: 0; }
header .sub { color: var(--ink-soft); font-size: 14px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.dot.live { background: #2fae63; box-shadow: 0 0 0 0 rgba(47,174,99,.6); animation: pulse 1.8s infinite; }
.dot.replay { background: var(--accent); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(47,174,99,.5); }
  70% { box-shadow: 0 0 0 7px rgba(47,174,99,0); }
  100% { box-shadow: 0 0 0 0 rgba(47,174,99,0); }
}

/* ---- replay control bar: a tick-mark ruler timeline, like EGOI's day/time
 * scrubber, instead of a generic rounded slider pill ---- */
.controls {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 4px 24px 14px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 40px;   /* = header's real rendered height, measured — must match or
                  this bar and the header overlap/gap when scrolled */
  z-index: 15;
}
button.ctl {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 11px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
  min-width: 38px;
}
button.ctl:hover { background: #f5f5f5; border-color: var(--ink-soft); }
button.ctl.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
button.ctl.primary:hover { background: #000; }
button.ctl:disabled { opacity: .4; cursor: default; }

.timeline-wrap { flex: 1; display: flex; flex-direction: column; gap: 2px; padding-top: 6px; }
.timeline-row { display: flex; align-items: center; gap: 10px; }

/* Real ruler ticks (built in JS from actual contest-clock boundaries — 10min
 * minor, contest-start/end tallest) sit under the range input, which is made
 * fully transparent so only its thumb + our own tick marks show. This
 * replaces a generic evenly-spaced CSS tick pattern that had no relationship
 * to real time.
 *
 * .ruler is inset by --thumb-r (half the range input's thumb width) on each
 * side, NOT left:0/right:0 — a native range thumb's center travels from
 * thumb-radius to (trackWidth - thumb-radius), never reaching the track's
 * true 0%/100% edges, so ticks positioned at plain 0%-100% of the full
 * track would drift away from the thumb at both ends. Insetting the tick
 * container by the same radius makes tick left:X% match the thumb's actual
 * position at that X, so the thumb sits exactly on the start/end ticks. */
.ruler-track { position: relative; height: 26px; --thumb-r: 7.5px; }
.ruler { position: absolute; left: var(--thumb-r); right: var(--thumb-r); top: 6px; height: 14px; pointer-events: none; }
.ruler::before {
  content: ''; position: absolute; left: 0; right: 0; top: 6px; height: 1px; background: var(--ink-soft);
}
.tick { position: absolute; top: 0; width: 1px; background: var(--ink-soft); }
.tick.minor { height: 6px; top: 3px; }
.tick.hour { height: 10px; top: 1px; width: 1.5px; background: var(--ink); }
.tick.edge { height: 20px; top: -3px; width: 3px; background: var(--ink); }

input[type=range].timeline {
  position: absolute; left: 0; right: 0; top: 0;
  width: 100%;
  -webkit-appearance: none; appearance: none;
  height: 26px;
  outline: none; cursor: pointer;
  background: transparent;
  /* Without this, a touch-drag starting on the thumb can get hijacked by the
   * browser as a page pan/scroll gesture instead of moving the slider —
   * easy to trigger here since the page is deliberately non-responsive
   * (see index.html) and viewed pinch-zoomed/panned on mobile. */
  touch-action: none;
}
input[type=range].timeline::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: #6b6b6b; border: 2px solid #fff; box-shadow: 0 0 0 1.5px var(--ink);
  margin-top: 3px;
}
input[type=range].timeline::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%;
  background: #6b6b6b; border: 2px solid #fff; box-shadow: 0 0 0 1.5px var(--ink);
}
input[type=range].timeline::-moz-range-track { background: transparent; }

/* Touch devices: a 15px thumb is too small to reliably grab with a finger.
 * Sized via `pointer: coarse` (true for touchscreens, false for mouse/
 * trackpad) rather than a viewport-width breakpoint, since this page has no
 * viewport meta tag and can be viewed zoomed to any width on any device —
 * pointer type is what actually determines whether a bigger target is
 * needed, not screen size. --thumb-r must grow to match (see the .ruler
 * comment above) or the tick-alignment fix drifts on touch. */
@media (pointer: coarse) {
  .ruler-track { --thumb-r: 13px; }
  input[type=range].timeline::-webkit-slider-thumb {
    width: 26px; height: 26px; margin-top: -2px;
  }
  input[type=range].timeline::-moz-range-thumb { width: 26px; height: 26px; }
}
.time-label { font-variant-numeric: tabular-nums; color: var(--ink-soft); font-size: 12px; min-width: 128px; }
.time-label b { color: var(--ink); font-weight: 700; }
select.speed, .clock {
  background: #fff; color: var(--ink);
  border: 1px solid var(--border-strong); border-radius: 6px;
  padding: 5px 7px; font-size: 12.5px; font-weight: 600;
}
.clock { font-variant-numeric: tabular-nums; color: var(--ink-soft); }

/* ---- scoreboard: measured pixel-for-pixel off a live render of the real
 * EGOI board (config: rowHeight 30, rowVSpacing 10, nameCellWidth 365,
 * scoreCellWidth 40, totalCellWidth 60, rankCellWidth 35, cellHSpacing 13,
 * leftBar.width 310, rightBar.width 260). EGOI's board is a fixed-width
 * canvas layout, NOT a fluid one — columns don't stretch to fill the
 * viewport, so we replicate that with fixed px widths instead of fr/flex. */
main { padding: 14px 0 60px; }
.layout { display: flex; align-items: flex-start; padding: 0 14px; }
/* Its own independent scroll region (like .feed below), separate from the
 * rest of the page — sidebar/header stay put while the board scrolls
 * internally, whether by mouse wheel or the 'k' auto-scroll (common.js). */
.board {
  position: sticky; top: 108px;   /* = header(40) + controls(68), measured */
  flex: none; width: max-content;
  max-height: var(--panel-max-h);
  overflow: auto;
  overscroll-behavior: contain;   /* don't chain scroll to the page once the board hits an edge */
}

/* ---- left filter sidebar (leftBar, 310px) ---- */
.sidebar {
  width: 310px; flex: none;
  padding: 5px 12px;
  font-size: 15px;
  color: var(--ink);
  position: sticky; top: 108px;
  max-height: var(--panel-max-h);
  overflow-y: auto;
  overflow-x: hidden;   /* explicit — CSS forces overflow-x to auto too (and it
                           was JUST wide enough to trigger it) if left as the
                           default 'visible' while overflow-y is set */
  overscroll-behavior: contain;
}
.sidebar h3 { font-size: 15px; margin: 10px 0 4px; font-weight: 700; }
.sidebar .filter-row { display: flex; align-items: center; gap: 7px; padding: 1px 0; }
.sidebar .filter-row input { margin: 0; }
.country-list { max-height: 380px; overflow-y: auto; margin-top: 2px; }
.country-row { display: flex; align-items: center; gap: 7px; padding: 2px 0; font-size: 14px; }
.country-row input { margin: 0; }
.country-row.dimmed { opacity: .4; }

/* ---- score distribution (EGOI's UI.overview canvas): one thin bar per
 * contestant, in rank order, width = total/maxTotal, colored by medal tier.
 * A compact "minimap" of how scores taper off across the whole field. */
.overview { width: 290px; }
.overview-bar {
  height: 4px; margin-bottom: 1px; border-radius: 1px;
  background: var(--tier, var(--none-a));
  cursor: pointer;
  transition: filter .15s;
}
.overview-bar:hover { filter: brightness(0.85); }

/* ---- score feed (EGOI-style log panel, rightBar 260px) ---- */
.feed {
  width: 260px; flex: none;
  margin-left: 6px;
  position: sticky; top: 108px;   /* = header(40) + controls(68), measured */
  overflow: hidden;
  max-height: var(--panel-max-h);
  display: flex; flex-direction: column;
}
.feed-head {
  padding: 4px 4px 2px; font-weight: 700; font-size: 13px; color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}
.feed-count {
  background: var(--rose); color: var(--rose-ink);
  border-radius: 999px; padding: 1px 9px; font-size: 11px; font-weight: 700;
}
.feed-sub { padding: 0 4px 6px; color: var(--muted); font-size: 10.5px; }
.feed-list { overflow-y: auto; padding: 2px; display: flex; flex-direction: column; gap: 3px; }
.feed-empty { color: var(--muted); font-size: 12.5px; padding: 16px; text-align: center; }
/* Each entry is colored by the resulting SCORE of that change (red->green),
 * same semantics as EGOI's log.{zero,full}ScoreColor — a submissions log
 * colors by what the submission scored, not by rank/medal. */
.ev {
  display: grid;
  grid-template-columns: 50px 1fr 16px 26px 30px;
  align-items: center; gap: 6px;
  padding: 5px 7px; border-radius: 5px;
  font-size: 13px; font-weight: 700; color: var(--ink);
  animation: evIn .3s ease;
}
@keyframes evIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.ev-time { font-variant-numeric: tabular-nums; font-size: 11.5px; font-weight: 700; opacity: .75; }
.ev-team { display: flex; align-items: center; gap: 4px; min-width: 0; }
.ev-task { text-align: center; font-weight: 800; }
.ev-score { font-variant-numeric: tabular-nums; text-align: right; }
.ev-delta { font-variant-numeric: tabular-nums; text-align: right; font-size: 11.5px; }

/* Fixed pixel grid matching EGOI's canvas spec: 35 / 365 / 40xN / 60. Column
 * GAPS are matched to pixel measurements taken directly off a real render,
 * not the nominal "cellHSpacing:13" constant in EGOI's source — that value
 * doesn't match how it actually renders (measured ~3px between adjacent
 * cells, ~9px at group boundaries: after Contestant, and before Total). */
.board-head, .row {
  display: grid;
  grid-template-columns: 35px 365px var(--task-cols) 66px;
  align-items: stretch;
  column-gap: 3px;
  width: max-content;
}
.cell.task.first-task, .th-task.first-task { margin-left: 6px; }   /* 3+6=9: gap after Contestant */
.board-head {
  position: sticky;
  top: 0;   /* sticks to the top of .board's OWN scroll box now that .board
               scrolls independently, not the top of the whole page */
  z-index: 10;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
  height: 36px;
  /* Opaque, covering the full bounding box (not just the header cells) —
   * otherwise rows scrolled underneath peek through the small gaps between
   * header cells once .board scrolls independently instead of the page. */
  background: var(--bg);
}
/* Each header label is its own rounded block (matching the row cells below),
 * not one continuous bar — same rose color, but with the same 3px/9px gaps
 * the grid already applies between cells. */
.board-head > div {
  padding: 0 8px; display: flex; align-items: center;
  background: var(--rose); border-radius: 4px;
}
.board-head .th-task { flex-direction: column; align-items: center; justify-content: center; padding: 0 2px; }
.board-head .th-task .tname { font-size: 20px; font-weight: 800; line-height: 1.1; }
.th-center { justify-content: center; }
.th-total { margin-left: 6px; }   /* matches .cell.sum's margin so header/row Total line up */

/* Column sort (click a problem/total header to reorder the board by it) —
 * purely visual row reordering, shared class names so both the single-day
 * and combined boards get the same affordance/styling for free. */
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { filter: brightness(0.93); }
.sort-active { background: var(--rose-deep); color: var(--rose-ink); }

.rows { position: relative; }
.row {
  position: absolute;
  left: 0; right: 0;
  height: 30px;
  background: transparent;
  margin-bottom: 10px;
  transition: transform .6s cubic-bezier(.22,.61,.36,1), box-shadow .3s;
  will-change: transform;
  --tier: var(--none-a);
}
.row.none:nth-child(odd) { --tier: var(--none-b); }
.row.gold { --tier: var(--gold); }
.row.silver { --tier: var(--silver); }
.row.bronze { --tier: var(--bronze); }
.row.moved .team-pill, .row.moved .chip { box-shadow: 0 0 0 2px var(--accent); }
.row.filtered-out { opacity: .12; }

.cell { display: flex; align-items: center; overflow: hidden; }
.cell.rank {
  justify-content: center; font-weight: 800; font-variant-numeric: tabular-nums;
  font-size: 15px; color: var(--ink); background: var(--tier); border-radius: 4px;
}

.cell.team { padding: 0; }
.team-pill {
  height: 100%; width: 100%;
  background: var(--tier);
  border-radius: 4px;
  display: flex; align-items: center; gap: 6px;
  padding: 0 10px;
  overflow: hidden;
}
.team-pill .name {
  display: inline-flex; align-items: center; gap: 5px; min-width: 0;
  font-weight: 400; font-size: 14px; color: var(--ink);
}
/* Shared by every flag+text row (board name, log entry, country filter):
 * the flag sits in a flex row so it centers against the text's line box
 * (vertical-align tricks on inline content don't center reliably); the
 * truncation itself moves to this inner span since text-overflow:ellipsis
 * doesn't work directly on a flex container with an image sibling. */
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.team-pill .tid { color: var(--ink-soft); font-size: 10.5px; font-variant-numeric: tabular-nums; flex: none; }
/* Real flag <img> assets (27x20), not emoji — see flagFor() in app.js. */
.flag { height: 14px; width: auto; line-height: 1; flex: none; vertical-align: middle; border-radius: 1px; }

/* Flat, uniform pill per row-tier — matches the real EGOI board: score
 * value has no color meaning of its own, only rank/medal tier does. A
 * missing submission still gets its own override tint (cellColors.none). */
.cell.task { justify-content: stretch; padding: 0; }
.chip {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 400;   /* EGOI's own source only bolds rank/total/headers, not per-cell scores */
  color: var(--ink);
  background: var(--tier);
}
.chip.blank { background: var(--blank); color: #9a9fc9; }
.chip:not(.blank) { cursor: pointer; }
.chip:not(.blank):hover { filter: brightness(0.93); }
.ev.clickable { cursor: pointer; }
.ev.clickable:hover { filter: brightness(0.97); }

.cell.sum {
  justify-content: center; background: var(--tier); border-radius: 4px;
  margin-left: 6px;   /* contestHSkip: extra gap before the Total column */
  cursor: pointer;
}
.cell.sum:hover { filter: brightness(0.95); }
.sum .total { font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; color: var(--ink); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #fff; border: 1px solid var(--border-strong);
  padding: 9px 16px; border-radius: 10px; font-size: 13px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(30,34,48,.18); opacity: 0; transition: opacity .3s;
  pointer-events: none; z-index: 30; color: var(--ink);
}
.toast.show { opacity: 1; }

/* ---- score feed: green delta shown when a submission raised the score ---- */
.delta-up { color: #1f9d55; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---- task detail modal: click a score cell or feed row to see a
 * contestant's full submission history for that task, like
 * https://boi2026.cses.fi/scores/ ---- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(20, 22, 30, .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal {
  background: #fff; border-radius: 10px; padding: 24px 28px;
  max-width: 640px; width: 100%; max-height: 84vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3); position: relative;
}
.modal-close {
  position: absolute; top: 12px; right: 14px; background: none; border: none;
  font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px;
}
.modal-close:hover { color: var(--ink); }
.modal-name { margin: 0 0 6px; font-size: 19px; font-weight: 800; color: var(--ink); }
.modal-country { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); font-size: 13.5px; margin-bottom: 14px; }
.modal-country .flag { height: 12px; }
.modal-task-name { font-size: 15px; font-weight: 700; margin: 0 0 10px; color: var(--ink); }
.modal-subtable, .modal-subs-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.modal-subtable th, .modal-subtable td,
.modal-subs-table th, .modal-subs-table td {
  border: 1px solid var(--border); padding: 5px 8px; text-align: center; font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.modal-subtable th, .modal-subs-table th { background: var(--rose); font-weight: 700; }
.modal-subtable td:first-child, .modal-subs-table td:first-child { text-align: left; font-weight: 700; }
.modal-subs-head { font-weight: 700; margin-bottom: 8px; color: var(--ink); }
.modal-subs-table tr:last-child td { background: var(--tier); }

/* ---- task-detail modal: score/place-over-time charts (common.js's
 * buildProgressChart/buildRankChart) — plain inline SVG, step function
 * since scores (and therefore place) only change at discrete submission
 * events. Score chart: blue. Place chart: the original accent/rose color
 * (kept distinct from score's blue), with the tie-group band shaded in. */
.modal-chart-head { font-weight: 700; margin-bottom: 6px; color: var(--ink); font-size: 13px; }
.modal-chart { width: 100%; height: auto; display: block; margin-bottom: 16px; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis-label { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart-line { fill: none; stroke: var(--chart-blue); stroke-width: 2; }
.chart-dot { fill: var(--chart-blue); }
.rank-line { fill: none; stroke: var(--accent-deep); stroke-width: 2; }
.chart-band { fill: var(--accent); fill-opacity: .18; stroke: none; }
.chart-divider { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3,3; }
