/* Kanaliiga Dota 2 — Season 16
   Palette carries over the league's existing sheet: charcoal ground, amber accent.
   Lower division is marked in slate blue so the two tracks read apart at a glance.

   Layout is one fixture per row: team names lead, everything else sits quiet
   beneath them. Separation comes from whitespace and a single hairline rather
   than from boxes — panels, the week bar and the seam between divisions were
   all removed deliberately. Two type roles only: Barlow Condensed for the
   masthead, week headings and team names; IBM Plex Sans for everything else. */

:root {
  color-scheme: light;
  --wrap:      940px;
  --ground:    #f4f4f2;
  --panel:     #ffffff;
  --panel-2:   #ececea;
  --line:      #d9d9d4;
  --line-soft: #e7e7e3;
  --text:      #1b1d20;
  --muted:     #6b6f77;
  --amber:     #b56a00;
  --amber-dim: #f0e2cc;
  --slate:     #3d6389;
  --slate-dim: #dbe4ee;
  --good:      #2f7a4a;
  --bad:       #c0392b;
  --shadow:    0 1px 2px rgba(20, 22, 26, .07), 0 6px 18px rgba(20, 22, 26, .05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ground:    #131519;
    --panel:     #1b1e24;
    --panel-2:   #22262d;
    --line:      #303540;
    --line-soft: #262a32;
    --text:      #e9ebef;
    --muted:     #8f97a4;
    --amber:     #f0930f;
    --amber-dim: #3a2c12;
    --slate:     #7ba3cc;
    --slate-dim: #1e2937;
    --good:      #57b981;
    --bad:       #e2645a;
    --shadow:    0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .28);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ground:    #131519;
  --panel:     #1b1e24;
  --panel-2:   #22262d;
  --line:      #303540;
  --line-soft: #262a32;
  --text:      #e9ebef;
  --muted:     #8f97a4;
  --amber:     #f0930f;
  --amber-dim: #3a2c12;
  --slate:     #7ba3cc;
  --slate-dim: #1e2937;
  --good:      #57b981;
  --bad:       #e2645a;
  --shadow:    0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: 400 15px/1.55 "IBM Plex Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Barlow Condensed is reserved for the masthead, week headings and team names.
   Dialog and section headings stay in IBM Plex so the page has two voices. */
h1, .cond {
  font-family: "Barlow Condensed", "IBM Plex Sans", sans-serif;
  letter-spacing: .01em;
  text-wrap: balance;
}

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

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--ground);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-inner {
  max-width: var(--wrap); margin: 0 auto; padding: 16px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 5px; height: 36px; border-radius: 3px;
  background: linear-gradient(var(--amber), var(--slate));
}
.brand h1 {
  margin: 0; font-size: 27px; font-weight: 700; line-height: 1.05;
  text-transform: uppercase; letter-spacing: .03em;
}
.season { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

.session { display: flex; align-items: center; gap: 12px; }
/* The link to the other page sits just before the session controls. */
.nav-link { margin-left: auto; }
/* On a phone the title and the controls don't fit side by side: the page
   link stays on the title's row, and the controls take a row beneath. */
@media (max-width: 600px) {
  .topbar-inner { flex-wrap: wrap; row-gap: 12px; }
  .session { width: 100%; }
}
.session-state { font-size: 12px; color: var(--muted); }
.session-state.live { color: var(--good); font-weight: 600; }

/* A reader's preference, sitting with the session controls because that is
   where the page's switches live. Quiet by default: it is not an action. */
.results-toggle {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted); cursor: pointer; user-select: none;
}
.results-toggle:hover { color: var(--text); }
.results-toggle input {
  width: 14px; height: 14px; margin: 0; cursor: pointer; accent-color: var(--amber);
}
.results-toggle input:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

.btn {
  font: 600 13.5px/1 "IBM Plex Sans", sans-serif;
  padding: 9px 15px; border-radius: 7px;
  border: 1px solid var(--line); background: transparent; color: var(--text);
  cursor: pointer;
  /* Some buttons are links (the page switches), which browsers underline. */
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.btn-primary { background: var(--amber); border-color: var(--amber); color: #14161a; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-quiet { background: transparent; }

/* ---------- layout ---------- */

main { max-width: var(--wrap); margin: 0 auto; padding: 34px 20px 8px; }
.loading { color: var(--muted); }

.week { margin-bottom: 52px; }
.week:not([open]) { margin-bottom: 18px; }

/* The week heading sits on the page itself — no bar, no panel. It is also the
   toggle: a <summary>, so the keyboard and screen readers get it for free. */
.week-head {
  display: flex; align-items: baseline; gap: 14px;
  padding: 0 0 4px; margin-bottom: 22px;
  border-bottom: 1px solid var(--line);
  list-style: none; cursor: pointer;
}
.week:not([open]) > .week-head { margin-bottom: 0; }
.week-head::-webkit-details-marker { display: none; }
.week-head::before {
  content: "";
  align-self: center;
  width: 7px; height: 7px; flex: none;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform .15s;
}
.week[open] > .week-head::before { transform: rotate(45deg) translate(-2px, -2px); }
.week-head:focus-visible { outline: 2px solid var(--amber); outline-offset: 4px; }
.week-no {
  font-family: "Barlow Condensed", sans-serif;
  font-size: 30px; font-weight: 700; line-height: 1.1;
  text-transform: uppercase; letter-spacing: .04em;
}
.week-dates { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.week-live {
  margin-left: auto; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .09em;
  color: var(--good);
}

.division { margin-bottom: 26px; }
.division:last-child { margin-bottom: 0; }
.division-label {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .11em;
  padding: 0 0 10px;
}
.division.upper .division-label { color: var(--amber); }
.division.lower .division-label { color: var(--slate); }

/* ---------- one fixture per row ---------- */

/* Division colour lives on a left edge rather than around a box. The edge only
   lights up once a match has a score, so a glance down the column shows how
   much of the week has actually been played. */
.fixture { padding: 13px 0 14px 15px; border-left: 2px solid var(--line-soft); }
.fixture + .fixture { border-top: 1px solid var(--line-soft); }
.division.upper .fixture.played { border-left-color: var(--amber); }
.division.lower .fixture.played { border-left-color: var(--slate); }

.fx-teams {
  font-family: "Barlow Condensed", sans-serif;
  font-size: 21px; font-weight: 600; line-height: 1.2;
  display: flex; align-items: baseline; flex-wrap: wrap;
}
/* Break between the two teams, never inside a team's name. */
.fx-teams .t  { white-space: nowrap; }
.fx-teams .vs { color: var(--muted); font-weight: 500; padding: 0 8px; font-size: 16px; }

/* A score renders only when one exists; an unplayed match shows nothing here.
   An empty pill read as a clickable control in review. */
.fx-teams .score {
  margin-left: auto; padding-left: 14px;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.division.upper .fx-teams .score { color: var(--amber); }
.division.lower .fx-teams .score { color: var(--slate); }

/* "See results" is on by default, so the class names the state that needs a
   rule: results hidden. It hides the score and nothing else — the left edge
   stays lit, so a week still shows how much of it has been played without
   saying how it went. It is a CSS switch rather than a re-render because
   toggling must never tear down a row a captain has open for editing — and the
   edit inputs keep showing the real score, since you cannot set a value you
   cannot see. */
body.spoilers-off .fx-teams .score { display: none; }

/* Reading view: the meta line, and — signed in — the Edit button beside it.
   A signed-in row is identical to a reader's until Edit is clicked, so what
   you see while editing is what everyone else sees. */
.fx-read { display: flex; align-items: baseline; gap: 12px; }
.fx-read .fx-meta { flex: 1 1 auto; }

.fx-meta {
  margin-top: 4px; font-size: 13px; color: var(--muted);
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 9px;
  font-variant-numeric: tabular-nums;
}
.fx-meta .sep { color: var(--line); }
.fx-meta a { color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--line); }
.fx-meta a:hover { color: var(--text); }
.fx-meta .unset { color: var(--line); }

.byline { font-size: 12.5px; color: var(--muted); font-style: italic; padding: 2px 0 0; margin: 0; }

/* ---------- editable fields ---------- */

/* Edit carries the same amber as Save so it's obvious where editing starts,
   but only on the row you're pointing at — 43 amber buttons at rest would
   fight the division labels and scores for the same colour. */
.btn-edit {
  flex: 0 0 auto;
  padding: 4px 12px; font-size: 12px; border-radius: 6px;
  background: var(--amber); border-color: var(--amber); color: #14161a;
  font-weight: 600;
  /* Edit sits directly under the score, which is right-aligned too — without
     this they read as one stacked block. */
  margin-top: 5px;
  opacity: 0; transition: opacity .12s ease;
}
.fixture:hover .btn-edit,
.btn-edit:focus-visible { opacity: 1; }
.btn-edit:hover { filter: brightness(1.08); border-color: var(--amber); }
/* Touch screens have no hover, so never hide the only way in. */
@media (hover: none) { .btn-edit { opacity: 1; } }

.fx-saved {
  flex: 0 0 auto; font-size: 12px; font-weight: 600; color: var(--good);
}

/* Signed in, the quiet meta line is replaced by the inputs that set it. They
   wrap rather than scroll, so narrow screens stack them instead of clipping. */
.fx-edit {
  margin-top: 7px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
}
.fx-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.btn-save, .btn-cancel { padding: 6px 14px; font-size: 12.5px; }
.btn-save[disabled] { opacity: .65; cursor: default; }
/* Same treatment as the inputs: a transparent button on the row's own tint has
   no visible edge, so Cancel gets the --panel fill and a full-strength border. */
.btn-cancel {
  color: var(--muted);
  background: var(--panel);
  border-color: var(--line);
}
.btn-cancel:hover { color: var(--text); border-color: var(--muted); }

/* An open row is worth marking — it holds work the server hasn't seen yet.
   Rows are flush right when reading, so the highlight needs its own right
   padding, or Cancel butts against the edge of the tint. */
.fixture.editing {
  background: var(--panel-2);
  padding-right: 14px;
  border-radius: 0 7px 7px 0;
}
/* Inputs sit on the row's own highlight, so they need to be a shade apart from
   it and carry a full-strength border — a --line-soft edge on --panel-2 is
   almost invisible in dark mode. */
.field {
  min-width: 0; font: inherit; font-size: 13px;
  font-variant-numeric: tabular-nums;
  padding: 5px 7px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
.field-date   { width: 152px; }
.field-time   { width: 104px; }
.field-stream { flex: 1 1 180px; min-width: 150px; }

/* Score is two one-digit boxes with a dash between: 2 – 1. */
.score-pair { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.field-score {
  width: 34px; padding: 5px 0; text-align: center;
  font-weight: 600;
}
.score-dash { color: var(--muted); font-weight: 600; user-select: none; }
.field:hover { border-color: var(--muted); }
.field:focus { outline: none; border-color: var(--amber); }
.field.saving { border-color: var(--muted); }
.field.saved  { border-color: var(--good); }
.field.failed { border-color: var(--bad); }
input.field::-webkit-calendar-picker-indicator { opacity: .5; cursor: pointer; }

/* The change history is deliberately not surfaced in the UI. It is still
   recorded in full in the `audit` table — see the audit trail in src/db.js. */

/* ---------- dialog and toast ---------- */

.dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 22px;
  background: var(--panel); color: var(--text); max-width: 380px; width: calc(100% - 32px);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(8, 9, 11, .55); }
.dialog h2 { margin: 0 0 6px; font-size: 19px; font-weight: 600; }
.dialog-help { margin: 0 0 16px; font-size: 13px; color: var(--muted); }
.dialog label {
  display: block; font-size: 11.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .07em; margin: 12px 0 4px;
}
.dialog input {
  width: 100%; font: inherit; padding: 9px 10px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--ground); color: var(--text);
}
.dialog input:focus { outline: 2px solid var(--amber); outline-offset: 1px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.form-error { color: var(--bad); font-size: 13px; margin: 12px 0 0; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
  padding: 9px 15px; border-radius: 8px; font-size: 13.5px; z-index: 40;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
