/* Windows 11 inspired dark theme with a pastel palette. */
:root {
  color-scheme: dark;
  --bg: #1c1c1f;
  --surface: #2a2a2e;
  --surface-alt: #232326;
  --border: #3a3a40;
  --text: #ececf1;
  --muted: #9a9aa3;
  --accent: #a8c7fa;          /* pastel blue */
  --accent-text: #11203a;
  --ok: #b5e3c4;              /* pastel green: more wins, complete day */
  --yellow: #f3e3a1;          /* pastel yellow: tied, day in progress */
  --error: #f5b3b3;           /* pastel red: more losses, errors */
  --gold: #e8cf86;            /* podium 1st, finished tournament */
  --silver: #c9ced8;          /* podium 2nd, finished tournament */
  --bronze: #e0b08c;          /* podium 3rd, finished tournament */
  --lilac: #cdb8f0;
  --radius: 8px;
  /* The only font of the app (Windows 11). Outside Windows, the generic sans-serif. */
  --font: "Segoe UI Variable", sans-serif;
  /* Type ramp (Windows 11 / Fluent): the only sizes and weights of the app. */
  --fs-caption: 12px;      --lh-caption: 16px;      /* labels, headers, details, legends */
  --fs-body: 14px;         --lh-body: 20px;         /* text and data */
  --fs-body-large: 18px;   --lh-body-large: 24px;   /* highlighted data */
  --fs-subtitle: 20px;     --lh-subtitle: 28px;     /* section titles, tournament status */
  --fs-title: 28px;        --lh-title: 36px;        /* podium places and names */
  --fw-regular: 400;
  --fw-semibold: 600;
}

* { box-sizing: border-box; }
/* Elements with their own display (grid, flex) must still hide. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: var(--fw-regular) var(--fs-body)/var(--lh-body) var(--font);
  /* One design at every size: no automatic switch between the Text and Display cuts. */
  font-optical-sizing: none;
  font-variation-settings: "opsz" 10.5;
}

/* Form controls and chart text use the same font as the page. */
button, input, select, dialog, svg text { font-family: var(--font); }

a { color: var(--accent); }

/* ---------- Navbar ---------- */
.navbar {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  column-gap: 24px;
  padding: 0 24px;
  min-height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
/* Solution name: subtitle size, the largest text of the bar. */
.navbar-title {
  display: flex;
  align-items: center;
  font-size: var(--fs-subtitle);
  line-height: var(--lh-subtitle);
  font-weight: var(--fw-semibold);
  letter-spacing: .04em;
  color: var(--accent);
  text-decoration: none;
}
.navbar-tools { display: flex; align-items: center; gap: 16px; margin-left: auto; padding: 8px 0; }
.navbar-tournament { flex-direction: row; align-items: center; gap: 8px; }
.navbar-version { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--muted); }

/* Tabs (Windows 11 top NavigationView): pastel pill under the active one. */
.navbar-tabs { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
.navbar-tabs li { display: flex; }
.tab {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 14px;
  margin: 8px 0;
  border-radius: 4px;
  color: var(--muted);
  text-decoration: none;
}
.tab:hover { background: #333338; color: var(--text); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab[aria-current="page"] { color: var(--text); font-weight: var(--fw-semibold); }
.tab[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 20px;
  height: 3px;
  margin-left: -10px;
  border-radius: 2px;
  background: var(--accent);
}

/* Narrow screens: the tabs move to a second row. */
@media (max-width: 760px) {
  .navbar-tabs { order: 1; width: 100%; border-top: 1px solid var(--border); }
}

/* ---------- Page ---------- */
.view, .app-message { max-width: 900px; margin: 0 auto; padding: 0 24px; }
.app-message { padding-top: 20px; }
.view { padding-top: 20px; padding-bottom: 24px; }
#view-home { max-width: 1040px; }
.app-message:empty { display: none; }

section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
h2 { margin: 0 0 12px; font-size: var(--fs-subtitle); line-height: var(--lh-subtitle); font-weight: var(--fw-semibold); }
.muted { color: var(--muted); }

/* ---------- Forms ---------- */
form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
label { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--muted); }
/* Controls inside a label keep the body size. */
label input, label select { font-size: var(--fs-body); line-height: var(--lh-body); }
input, select {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-bottom-color: #55555d;
  border-radius: 4px;
  background: var(--surface-alt);
  color: var(--text);
}
input:focus, select:focus { outline: none; border-bottom: 2px solid var(--accent); }
input:disabled, select:disabled { opacity: .45; }

/* A single style for every text button (the one of «Abrir lista»): pastel accent fill. */
button {
  font: inherit;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}
button:hover:not(:disabled) { background: #bcd4fb; border-color: #bcd4fb; }
button:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: not-allowed; }

.message { min-height: var(--lh-body); margin: 10px 0 0; }
.message.ok { color: var(--ok); }
.message.error { color: var(--error); }
.message.warning { color: var(--yellow); }
#rikishi-list-message:empty, #rikishi-message:empty, #bout-list-message:empty, #bout-message:empty { display: none; }
#rikishi-list-message, #bout-list-message { margin: 4px 0 8px; }

/* ---------- Tables ---------- */
/* Fixed row heights, so that the scroll box shows exactly MAX_ROWS (20) data rows. */
:root {
  --table-head-height: 32px;
  --table-row-height: 40px;   /* fits the 30 px icon buttons */
  --table-max-rows: 20;
}
.table-scroll {
  max-height: calc(var(--table-head-height) + var(--table-max-rows) * var(--table-row-height));
  overflow-y: auto;
}
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 0 8px; border-bottom: 1px solid var(--border); }
th {
  height: var(--table-head-height);
  font-size: var(--fs-caption);
  line-height: var(--lh-caption);
  color: var(--muted);
  font-weight: var(--fw-semibold);
  /* The header stays visible while the rows scroll. */
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
}
/* Sortable headers: they look like the header text; the active one shows its direction. */
th button.sort {
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;   /* the font is inherited from the header, as in every button */
}
th button.sort:hover:not(:disabled) { background: transparent; color: var(--text); }
/* Every sortable header shows its control: ↕ while inactive, ▲ or ▼ on the active one. */
th button.sort::after { content: "↕"; display: inline-block; width: 1.2em; text-align: right; opacity: .6; }
th[aria-sort] button.sort::after { opacity: 1; }
th[aria-sort="ascending"] button.sort, th[aria-sort="descending"] button.sort { color: var(--text); }
th[aria-sort="ascending"] button.sort::after { content: "▲"; text-align: right; }
th[aria-sort="descending"] button.sort::after { content: "▼"; text-align: right; }
td { height: var(--table-row-height); }
td.actions { text-align: right; white-space: nowrap; }
tr.editing td { background: color-mix(in srgb, var(--accent) 14%, transparent); }
td.empty { color: var(--muted); }
td.winner { font-weight: var(--fw-semibold); }
/* Win ○ (green ring) and loss ● (red dot), 50 % larger than the text (scaled, so that the
   type ramp is kept). The progress chart draws the same symbols. */
.mark, .mark-win, .mark-loss { display: inline-block; transform: scale(1.5); }
.mark { width: 1.6em; color: var(--error); }
td.winner .mark { color: var(--ok); }
.mark-win { color: var(--ok); margin: 0 4px; }
.mark-loss { color: var(--error); margin: 0 4px; }
.legend { color: var(--muted); font-size: var(--fs-caption); line-height: var(--lh-caption); margin: 8px 0 0; }

button.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  margin-left: 4px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
button.icon svg {
  width: 18px; height: 18px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
button.icon:hover:not(:disabled), button.icon:focus-visible { border-color: var(--border); background: transparent; color: var(--text); }
button.icon.delete:hover, button.icon.delete:focus-visible { color: var(--error); }

.counter { font-weight: var(--fw-regular); color: var(--muted); font-size: var(--fs-body); line-height: var(--lh-body); }
.section-header { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.section-header h2 { margin: 0; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
/* A section heading with its controls placed outside a panel, right above it. */
.view-toolbar { margin: 4px 0 12px; align-items: flex-end; }
#rikishi-list-message, #rikishi-message, #bout-list-message, #bout-message { margin: 0 0 8px; }

/* ---------- Home: tournament card ---------- */
#home-message:empty { display: none; }
#home-message { margin: 0 0 16px; }
#tournament-card { padding: 18px 20px; }
.overline {
  margin: 0 0 6px;
  font-size: var(--fs-caption);
  line-height: var(--lh-caption);
  font-weight: var(--fw-semibold);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.tournament-day { font-size: var(--fs-subtitle); line-height: var(--lh-subtitle); font-weight: var(--fw-semibold); margin: 0; }
.tournament-detail { color: var(--muted); font-size: var(--fs-caption); line-height: var(--lh-caption); margin: 2px 0 12px; }
.day-bar { display: grid; grid-template-columns: repeat(15, 1fr); gap: 3px; }
.day-bar span { height: 8px; border-radius: 2px; background: var(--border); }
.day-bar span.complete { background: var(--ok); }
.day-bar span.in-progress { background: var(--yellow); }

/* ---------- Home: podium (2nd left, 1st centre and highest, 3rd right) ---------- */
.podium {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
  gap: 12px;
  max-width: 760px;
  margin: 0 auto;
}
.podium-column { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.podium-column.place-1 { grid-column: 2; }
.podium-column.place-2 { grid-column: 1; grid-row: 1; }
.podium-column.place-3 { grid-column: 3; grid-row: 1; }
/* Names inside the step, against its top edge. */
.podium-names {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: center;
}
/* Names in white, with the title style, so they stand out over the muted step. */
.podium-name {
  color: var(--text);
  font-size: var(--fs-title);
  line-height: var(--lh-title);
  font-weight: var(--fw-semibold);
  overflow-wrap: anywhere;
}
/* Steps without background: only their outline. Names at the top, the place at the bottom. */
.podium-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 0;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--muted);
}
.podium-place { font-size: var(--fs-title); line-height: var(--lh-title); font-weight: var(--fw-semibold); }
/* --podium-height (set by the view) fits the longest list of names; 2nd and 3rd stay lower. */
.place-1 .podium-step { height: var(--podium-height, 140px); }
.place-2 .podium-step { height: calc(var(--podium-height, 140px) - 36px); }
.place-3 .podium-step { height: calc(var(--podium-height, 140px) - 64px); }
.podium-note { margin: 12px 0 0; text-align: center; font-size: var(--fs-caption); line-height: var(--lh-caption); }
.podium-note:empty { display: none; }
/* Finished tournament: a subtle gold, silver and bronze tint on each step. */
.podium.finished .podium-step { color: var(--text); }
.podium.finished .place-1 .podium-step {
  background: color-mix(in srgb, var(--gold) 16%, transparent);
  border-color: color-mix(in srgb, var(--gold) 45%, transparent);
}
.podium.finished .place-2 .podium-step {
  background: color-mix(in srgb, var(--silver) 14%, transparent);
  border-color: color-mix(in srgb, var(--silver) 40%, transparent);
}
.podium.finished .place-3 .podium-step {
  background: color-mix(in srgb, var(--bronze) 14%, transparent);
  border-color: color-mix(in srgb, var(--bronze) 40%, transparent);
}

/* ---------- Home: rikishi cards and balance panels ---------- */
.balance-panel { border-top: 4px solid var(--border); }
.balance-panel.positivo { border-top-color: var(--ok); }
.balance-panel.igualado { border-top-color: var(--yellow); }
.balance-panel.negativo { border-top-color: var(--error); }
.panel-empty { margin: 0; color: var(--muted); }
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}
.card-name { display: block; font-weight: var(--fw-semibold); }
.card-rank { display: block; font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--muted); }
.card-balance {
  font-size: var(--fs-body-large);
  line-height: var(--lh-body-large);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.card-balance .dash { color: var(--muted); font-weight: var(--fw-regular); margin: 0 2px; }
/* The balance takes the colour of its panel. */
.positivo .card-balance { color: var(--ok); }
.igualado .card-balance { color: var(--yellow); }
.negativo .card-balance { color: var(--error); }

/* ---------- Home: progress chart ---------- */
.chart svg { display: block; }
.chart-grid line { stroke: var(--border); stroke-width: 1; }
.chart-axis text { fill: var(--muted); font-size: var(--fs-caption); }
.chart-series { outline: none; cursor: default; }
.chart-background { fill: transparent; }
.chart-series:hover .chart-background,
.chart-series:focus-visible .chart-background { fill: color-mix(in srgb, var(--text) 6%, transparent); }
.chart-zero { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-line { fill: none; stroke: var(--muted); stroke-width: 1.5; }
/* First position: a line twice as thick. */
.chart-series.first .chart-line { stroke-width: 3; }
/* Same symbols as the bouts table: win ○ green ring, loss ● red dot. */
.chart-dot.win { fill: var(--surface); stroke: var(--ok); stroke-width: 2; }
.chart-dot.loss { fill: var(--error); stroke: var(--surface); stroke-width: 1; }
.chart-name { fill: var(--text); font-size: var(--fs-body); }
.chart-total { fill: var(--text); font-size: var(--fs-body); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.chart-tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgb(0 0 0 / .4);
}
.chart-tooltip b { display: block; font-weight: var(--fw-semibold); }
.chart-tooltip span { color: var(--muted); }

/* ---------- Dialog ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 20px 24px;
  min-width: 320px;
  box-shadow: 0 16px 40px rgb(0 0 0 / .5);
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog form { flex-direction: column; align-items: stretch; }
dialog h2 { margin-bottom: 4px; }
dialog label input, dialog label select { width: 100%; }
#rikishi-dialog { width: 360px; }
#bout-dialog { width: 690px; }
#bout-day-notice:empty, #bout-pair-notice:empty, #bout-dialog-message:empty, #rikishi-dialog-message:empty { display: none; }
#bout-pair-notice, #bout-day-notice, #bout-dialog-message { margin: 0; }

/* Bout dialog: rikishi still without a bout that day, as clickable chips. */
.pending { display: flex; flex-direction: column; gap: 4px; }
.pending-title, .field-label { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
/* Chips and winner choices: outlined until chosen (the filled style marks the choice). */
button.chip, button.choice { background: transparent; border-color: var(--border); color: var(--text); }
button.chip { padding: 2px 8px; font-size: var(--fs-caption); line-height: var(--lh-caption); }
button.chip.juryo { color: var(--muted); }
button.chip:hover:not(:disabled), button.choice:hover:not(:disabled) { background: var(--surface-alt); border-color: var(--accent); }

/* Winner: two buttons with the names of A and B; the chosen one is filled and marked with ○. */
.winner-field { display: flex; flex-direction: column; gap: 4px; }
.winner-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
button.choice { padding: 8px 12px; }
button.choice[aria-checked="true"], button.choice[aria-checked="true"]:hover:not(:disabled) {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}
button.choice .mark-win { color: inherit; margin: 0 8px 0 0; }
#bout-delete { margin-right: auto; }
.hint { margin: 0; font-size: var(--fs-caption); line-height: var(--lh-caption); }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; }
