/*
 * Look and feel. The app is used on the pitch, often under floodlights, by coaches who glance at it
 * between drills. So: club colours from the jersey (red and black stripes), a condensed typeface for
 * names and scores that reads like a stadium scoreboard, and big targets for the plus button.
 */

@font-face {
  font-family: 'Archivo';
  src: url('/fonts/archivo-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #edf0ed;
  --surface: #ffffff;
  --surface-2: #e2e7e3;
  --ink: #111a15;
  --muted: #5b6a62;
  --line: #d3dbd5;
  --club: #d21f34;
  --jersey: #1c1c1c;
  --up: #1d9a52;
  --up-press: #157a40;
  --negative-on-photo: #ff8f9b;
  --focus: #1d9a52;
  --backdrop: rgb(6 10 8 / 0.55);

  --page: 1120px;
  --gutter: 16px;
  --radius-card: 18px;
  --radius-control: 12px;
  --card-min: 150px;
  --gap: 12px;
  --tap: 52px;

  --stripes: repeating-linear-gradient(90deg, var(--club) 0 14.2857%, var(--jersey) 14.2857% 28.5714%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b120f;
    --surface: #141d19;
    --surface-2: #1e2924;
    --ink: #ecf2ee;
    --muted: #8fa097;
    --line: #26322c;
    --club: #ee3a4e;
    --jersey: #050505;
    --up: #22a65a;
    --up-press: #1a8748;
    --focus: #4fd486;
    --backdrop: rgb(0 0 0 / 0.65);
  }
}

body[data-density='small'] { --card-min: 104px; --gap: 8px; --tap: 46px; }
body[data-density='large'] { --card-min: 200px; --gap: 14px; --tap: 60px; }

/* --------------------------------------------------------------------- base */
* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: 'Archivo', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 1rem;
  font-weight: 420;
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; opacity: 0.4; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.icon { width: 22px; height: 22px; flex: none; }

/* ------------------------------------------------------------------ top bar */
#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(env(safe-area-inset-top) + 12px) max(var(--gutter), calc((100% - var(--page)) / 2)) 10px;
  background:
    var(--stripes) top / 100% 4px no-repeat,
    color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
#topbar:empty { display: none; }

.bar-row { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.bar-title { flex: 1; min-width: 0; }
.bar-title strong {
  display: block;
  font-stretch: 75%;
  font-weight: 760;
  font-size: 1.375rem;
  line-height: 1.1;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-sub { display: flex; align-items: center; gap: 10px; margin-top: 2px; font-size: 0.8125rem; color: var(--muted); }

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line);
  color: var(--ink);
}
.icon-btn:active { background: var(--surface-2); }

.trainer-slot { flex: none; display: flex; }
.trainer-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--club);
  color: #fff;
  font-stretch: 75%;
  font-weight: 800;
  font-size: 1.125rem;
}
.trainer-btn.unset { background: var(--surface-2); color: var(--muted); }
.trainer-btn .icon { width: 20px; height: 20px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #e0a100; box-shadow: 0 0 0 3px color-mix(in srgb, #e0a100 25%, transparent); }
.status.online .dot { background: var(--up); box-shadow: 0 0 0 3px color-mix(in srgb, var(--up) 25%, transparent); }

/* The tools row folds to zero height (grid row 1fr → 0fr) so the cards get the room. The wrapper
   reaches out to the screen edge because the filter row scrolls edge to edge. */
.tools {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.22s ease, opacity 0.18s ease;
}
.tools-inner { min-height: 0; overflow: hidden; margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter); }
.tools.collapsed { grid-template-rows: 0fr; opacity: 0; }
#topbar:has(.tools.collapsed) { padding-bottom: 8px; }
.controls { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.controls .count { margin-left: auto; color: var(--muted); font-size: 0.875rem; font-weight: 560; }

.segmented { flex: none; display: flex; padding: 3px; border-radius: 11px; background: var(--surface-2); }
.segmented button {
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 620;
}
.segmented button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }

.tool-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
}
.tool-btn .icon { width: 19px; height: 19px; }

/* -------------------------------------------------------------------- timer */
/* The shared countdown sits at the end of every top bar, read like a scoreboard clock. The line
   along the bottom shrinks with the remaining time; timer.js sets --progress through the CSSOM. */
.timer-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 6px 6px 9px 14px;
  border-radius: 14px;
  background: var(--surface-2);
  overflow: hidden;
}
.timer-main { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.timer-time {
  font-size: 2.125rem;
  font-stretch: 62%;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.timer-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.875rem; font-weight: 620; }
.timer-btn {
  flex: none;
  display: grid;
  place-items: center;
  min-width: 44px;
  height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.0625rem;
  font-weight: 750;
}
.timer-btn[hidden] { display: none; }
.timer-btn .icon { width: 20px; height: 20px; }
.timer-btn:active { transform: scale(0.96); }
.timer-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: var(--ink);
  transform-origin: left;
  transform: scaleX(var(--progress, 1));
  transition: transform 0.25s linear;
}
.timer-bar.paused .timer-time { color: var(--muted); }
.timer-bar.ending .timer-time { color: var(--club); }
.timer-bar.ending .timer-progress { background: var(--club); }
.timer-bar.done { background: var(--club); color: #fff; animation: timer-done 0.7s ease-in-out infinite alternate; }
.timer-bar.done .timer-label { color: rgb(255 255 255 / 0.85); }
.timer-bar.done .timer-btn { background: rgb(255 255 255 / 0.2); color: #fff; }
@keyframes timer-done { from { filter: brightness(0.9); } to { filter: brightness(1.2); } }

.timer-dialog { display: flex; flex-direction: column; gap: 16px; }
.timer-presets { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.timer-preset {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 76px;
  border: 0;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--ink);
}
.timer-preset strong { font-size: 2rem; font-stretch: 62%; font-weight: 800; line-height: 1; }
.timer-preset span { color: var(--muted); font-size: 0.75rem; font-weight: 620; }
.timer-preset:active { transform: scale(0.96); }
.timer-custom { display: flex; align-items: flex-end; gap: 8px; }
.timer-custom label { display: flex; flex-direction: column; gap: 6px; width: 5.5em; font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.timer-custom input { text-align: center; font-size: 1.25rem; font-weight: 700; }
.timer-colon { padding-bottom: 10px; font-size: 1.5rem; font-weight: 800; }
.timer-custom .btn { flex: 1; min-height: 48px; }

/* --------------------------------------------------------------------- bibs */
/* Bib colours come from the settings; bibs.js sets --bib and --bib-ink on every marked element.
   The swatch carries a thin ring so white and neon bibs stay visible on a light background. */
.swatch {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bib, transparent);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.18);
}
:not([data-bib]) > .swatch { box-shadow: inset 0 0 0 2px var(--line); }
.bib-chip[aria-pressed='true'] .swatch { box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.25), 0 0 0 2px var(--bg); }

.bib-filter { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 10px calc(-1 * var(--gutter)) 0; padding: 0 var(--gutter) 2px; }
.bib-filter::-webkit-scrollbar { display: none; }
.bib-filter[hidden] { display: none; }
/* The picker stays at the top of the dialog while the list scrolls, so switching colour is one tap. */
.bib-picker {
  position: sticky;
  top: -8px;
  z-index: 1;
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 -20px;
  padding: 8px 20px 10px;
  background: var(--bg);
}
.bib-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 620;
  white-space: nowrap;
}
.bib-chip[aria-pressed='true'] { background: var(--ink); color: var(--bg); }
/* In the filter row a colour is just its dot. */
.bib-chip.swatch-only { width: 34px; justify-content: center; padding: 0; }
.bib-chip.swatch-only .swatch { width: 18px; height: 18px; }

.bib-choice { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 6px; }
.bib-choice .bib-chip { height: 44px; padding: 0 16px; font-size: 1rem; }
.media { cursor: pointer; }
.bib-row { width: 100%; border: 0; background: transparent; color: inherit; text-align: left; font: inherit; }
.bib-row:disabled { opacity: 0.6; }
.bib-tag {
  flex: none;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bib);
  color: var(--bib-ink);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.15);
  font-size: 0.8125rem;
  font-weight: 700;
}

.settings-section { display: flex; flex-direction: column; gap: 12px; }
.settings-section h2 { margin: 6px 2px 0; font-stretch: 75%; font-weight: 800; font-size: 1.75rem; line-height: 1.1; }
.settings-section .inline-form { flex-wrap: wrap; margin: 4px 0 0; align-items: center; }
.settings-section .inline-form .btn { flex: 1 0 100%; }
.inline-form input.color-input { flex: none; }
input.color-input {
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}
input.color-input::-webkit-color-swatch-wrapper { padding: 0; }
input.color-input::-webkit-color-swatch { border: 0; border-radius: 50%; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.2); }
input.color-input::-moz-color-swatch { border: 0; border-radius: 50%; }

/* The bib shows as a corner flag at the top left, big enough to spot across the grid without
   covering the face. A thin dark edge along the diagonal keeps white bibs visible on light photos;
   the rank badge sits on top of it. */
.card[data-bib]::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  width: min(34%, 56px);
  aspect-ratio: 1;
  background: linear-gradient(
    135deg,
    var(--bib) calc(50% - 1px),
    rgb(0 0 0 / 0.35) calc(50% - 1px),
    rgb(0 0 0 / 0.35) 50%,
    transparent 50%
  );
  pointer-events: none;
}

.group-head {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 2px 0;
  font-stretch: 75%;
  font-weight: 800;
  font-size: 1.25rem;
}
.group-head:first-child { margin-top: 0; }
.group-head .swatch { width: 16px; height: 16px; }
.group-head .count { color: var(--muted); font-weight: 650; }

/* --------------------------------------------------------------------- view */
#view {
  max-width: calc(var(--page) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 14px max(var(--gutter), env(safe-area-inset-right)) calc(112px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
}

/* -------------------------------------------------------------- player cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--card-min), 1fr)); gap: var(--gap); }

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: 0 0 0 1px var(--line);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.card.flash-up { animation: flash-up 0.7s ease-out; }
.card.flash-down { animation: flash-down 0.7s ease-out; }
@keyframes flash-up { 0%, 30% { box-shadow: 0 0 0 3px var(--up); } 100% { box-shadow: 0 0 0 1px var(--line); } }
@keyframes flash-down { 0%, 30% { box-shadow: 0 0 0 3px var(--club); } 100% { box-shadow: 0 0 0 1px var(--line); } }

.media { position: relative; aspect-ratio: 1 / 1; background: var(--surface-2); }
.media::after {
  content: '';
  position: absolute;
  inset: 42% 0 0;
  background: linear-gradient(to top, rgb(0 0 0 / 0.8), rgb(0 0 0 / 0.35) 55%, rgb(0 0 0 / 0));
  pointer-events: none;
}
.photo { position: absolute; inset: 0; display: grid; place-items: center; overflow: hidden; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.photo.placeholder, .avatar.placeholder { background: var(--stripes); }
.initials {
  display: grid;
  place-items: center;
  width: 46%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #fff;
  color: var(--club);
  font-stretch: 75%;
  font-weight: 800;
  font-size: 2rem;
  line-height: 1;
}
body[data-density='small'] .initials { font-size: 1.5rem; }
.photo.placeholder .initials { margin-bottom: 24%; }

.rank {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  display: grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #fff;
  font-stretch: 75%;
  font-weight: 800;
  font-size: 1rem;
  line-height: 1;
}
.rank.first { background: var(--club); }
.rank:empty { display: none; }
body[data-density='small'] .rank { top: 6px; left: 6px; min-width: 24px; height: 24px; padding: 0 6px; font-size: 0.875rem; }

.info {
  position: absolute;
  inset: auto 0 0;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 6px;
  padding: 0 12px 9px;
  color: #fff;
}
.name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-stretch: 75%;
  font-weight: 700;
  font-size: 1.125rem;
  line-height: 1.15;
  text-shadow: 0 1px 2px rgb(0 0 0 / 0.45);
}
.points {
  flex: none;
  font-stretch: 62%;
  font-weight: 820;
  font-size: 3rem;
  line-height: 0.8;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  transform-origin: 100% 100%;
  text-shadow: 0 1px 3px rgb(0 0 0 / 0.35);
}
.points.negative { color: var(--negative-on-photo); }
.points.bump { animation: bump 0.3s ease-out; }
@keyframes bump { 40% { transform: scale(1.3); } }
body[data-density='small'] .info { padding: 0 8px 7px; gap: 4px; }
body[data-density='small'] .name { font-size: 0.9375rem; }
body[data-density='small'] .points { font-size: 2.25rem; }
body[data-density='large'] .name { font-size: 1.375rem; }
body[data-density='large'] .points { font-size: 3.75rem; }

.buttons { display: grid; grid-template-columns: 1fr 2fr; gap: 6px; padding: 6px; }
.buttons button {
  display: grid;
  place-items: center;
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 12px;
  transition: transform 0.08s ease-out, background-color 0.08s;
}
.buttons .icon { width: 26px; height: 26px; stroke-width: 2.75; }
.buttons .minus { background: var(--surface-2); color: var(--muted); }
.buttons .minus:active { background: var(--club); color: #fff; }
.buttons .plus { background: var(--up); color: #fff; }
.buttons .plus:active { background: var(--up-press); transform: scale(0.96); }
body[data-density='small'] .buttons { gap: 4px; padding: 4px; }
body[data-density='small'] .buttons button { border-radius: 10px; }
body[data-density='small'] .buttons .icon { width: 22px; height: 22px; }
.grid.closed .buttons { display: none; }

/* ------------------------------------------------------------ empty and login */
.empty, .login { max-width: 440px; margin: 10vh auto 0; }
.mark { display: block; width: 64px; height: 64px; margin-bottom: 22px; }
.empty h2, .login h2 {
  margin: 0 0 10px;
  font-stretch: 75%;
  font-weight: 800;
  font-size: 2.375rem;
  line-height: 1.02;
  letter-spacing: -0.01em;
}
.empty p { margin: 0 0 28px; max-width: 36ch; color: var(--muted); font-size: 1.0625rem; }
.login .form { gap: 14px; }
.login .mark { margin-bottom: 8px; }

.loading { padding: 64px 16px; text-align: center; color: var(--muted); }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 650;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn .icon { width: 20px; height: 20px; }
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.danger { background: var(--club); color: #fff; }
.btn.large { min-height: 56px; padding: 0 26px; font-size: 1.0625rem; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 0.875rem; }
.btn.small .icon { width: 16px; height: 16px; }

/* -------------------------------------------------------------------- lists */
.list {
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: 0 0 0 1px var(--line);
  overflow: hidden;
}
.list > li + li { border-top: 1px solid var(--line); }
.list > li.hint { padding: 16px; }

.row { display: flex; align-items: center; gap: 14px; min-height: 64px; padding: 10px 14px; }
.row.dim { opacity: 0.45; }
.row .grow { flex: 1; min-width: 0; }
.row strong { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.row .sub, .sub { display: block; color: var(--muted); font-size: 0.875rem; }
button.row { width: 100%; border: 0; background: transparent; text-align: left; color: inherit; }
button.row:active { background: var(--surface-2); }

.avatar {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar .initials { width: 62%; font-size: 1rem; }
.avatar input[type='file'] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.avatar .badge {
  position: absolute;
  right: 3px;
  bottom: 3px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.6);
  color: #fff;
  pointer-events: none;
}
.avatar .badge .icon { width: 13px; height: 13px; stroke-width: 2.4; }
.list .avatar:has(.badge) { width: 56px; height: 56px; }

.delta {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 36px;
  border-radius: 10px;
  font-stretch: 75%;
  font-weight: 800;
  font-size: 1.125rem;
}
.delta.up { background: color-mix(in srgb, var(--up) 16%, transparent); color: var(--up); }
.delta.down { background: color-mix(in srgb, var(--club) 14%, transparent); color: var(--club); }

/* -------------------------------------------------------------------- forms */
input[type='text'], input[type='password'], input[type='date'], input[type='number'], textarea {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink);
  font-size: 1rem;
}
input[type='text']:focus-visible, input[type='password']:focus-visible, input[type='date']:focus-visible, input[type='number']:focus-visible, textarea:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--focus);
}
textarea { min-height: 150px; padding: 12px 14px; resize: vertical; line-height: 1.5; }

.row input.name-input {
  min-height: 40px;
  margin-left: -8px;
  padding: 0 8px;
  background: transparent;
  box-shadow: none;
  font-weight: 650;
  font-size: 1.0625rem;
}
.row input.name-input:hover { background: var(--surface-2); }
.row input.name-input:focus-visible { background: var(--surface); box-shadow: inset 0 0 0 2px var(--focus); }

input.switch {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 48px;
  height: 28px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background-color 0.15s;
}
input.switch::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
  transition: transform 0.15s;
}
input.switch:checked { background: var(--up); }
input.switch:checked::before { transform: translateX(20px); }
input.switch:disabled { opacity: 0.6; }
.switch-label { display: flex; align-items: center; gap: 10px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.875rem; font-weight: 600; color: var(--muted); }
.inline-form { display: flex; gap: 8px; margin-bottom: 14px; }
.inline-form input { flex: 1; min-width: 0; }
.hint { margin: 0; color: var(--muted); font-size: 0.9375rem; }
.page-hint { margin: 2px 2px 14px; }

details.team {
  margin-top: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: 0 0 0 1px var(--line);
}
details.team summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  font-weight: 650;
  list-style: none;
  cursor: pointer;
}
details.team summary::-webkit-details-marker { display: none; }
details.team summary .icon { color: var(--muted); transition: transform 0.2s; }
details.team[open] summary .icon { transform: rotate(90deg); }
details.team .form { padding-bottom: 16px; }
main > details.team:only-child { margin-top: 0; }
.chips-plain { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-plain:empty { display: none; }
.tag { padding: 3px 10px; border-radius: 999px; background: var(--surface-2); font-size: 0.875rem; font-weight: 550; }

/* ------------------------------------------------------------------ banner */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 14px 16px;
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line);
}
.banner strong { font-weight: 700; }

/* ------------------------------------------------------------------ history */
.date-block { flex: none; width: 44px; text-align: center; line-height: 1; }
.date-block .day { display: block; font-stretch: 62%; font-weight: 800; font-size: 2rem; font-variant-numeric: tabular-nums; }
.date-block .month { display: block; margin-top: 3px; color: var(--muted); font-size: 0.75rem; font-weight: 650; }
.chev { display: grid; color: var(--muted); }
.live-tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--up) 16%, transparent);
  color: var(--up);
  font-size: 0.75rem;
  font-weight: 700;
  vertical-align: 2px;
}
.summary-head { margin: 6px 2px 18px; }
.summary-head h2 { margin: 0 0 4px; font-stretch: 75%; font-weight: 800; font-size: 2.125rem; line-height: 1.05; }
.summary-head .hint { display: flex; align-items: center; gap: 8px; }
.session-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.rank-row .place { flex: none; width: 30px; text-align: center; font-stretch: 62%; font-weight: 800; font-size: 1.75rem; color: var(--muted); }
.rank-row.top .place { color: var(--club); }
.rank-row .score { flex: none; font-stretch: 62%; font-weight: 820; font-size: 2.25rem; line-height: 1; font-variant-numeric: tabular-nums; }
.rank-row .score.negative { color: var(--club); }

/* ------------------------------------------------------------------ dialogs */
dialog {
  position: fixed;
  inset: auto 0 0;
  width: 100%;
  max-width: 560px;
  max-height: min(90dvh, 780px);
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 -10px 40px rgb(0 0 0 / 0.25);
}
dialog[open] { display: flex; flex-direction: column; animation: sheet-in 0.3s cubic-bezier(0.2, 0.9, 0.25, 1); }
dialog::backdrop { background: var(--backdrop); }
@keyframes sheet-in { from { transform: translateY(48px); opacity: 0; } }

@media (min-width: 700px) {
  dialog { inset: 0; height: fit-content; max-height: 84vh; margin: auto; border-radius: 24px; box-shadow: 0 20px 60px rgb(0 0 0 / 0.3); }
  dialog[open] { animation-name: pop-in; animation-duration: 0.2s; }
  @keyframes pop-in { from { transform: scale(0.96); opacity: 0; } }
}

.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 20px 8px; }
.dialog-head h2 { margin: 0; font-stretch: 75%; font-weight: 800; font-size: 1.625rem; line-height: 1.1; }
.close-btn { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: var(--surface-2); color: var(--muted); }
.close-btn .icon { width: 20px; height: 20px; }
.dialog-body { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding: 8px 20px 18px; }
/* Without this a list (overflow: hidden) shrinks to the visible height and clips its rows, so the
   body has nothing left to scroll; that broke scrolling in long dialogs on phones. */
.dialog-body > * { flex-shrink: 0; }
.dialog-body .inline-form { margin: 0; }
.dialog-foot { display: flex; gap: 10px; padding: 12px 20px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.dialog-foot .btn { flex: 1; }

.menu-group { display: flex; flex-direction: column; gap: 8px; }
.menu-group h3 { margin: 0 4px; font-size: 0.875rem; font-weight: 650; color: var(--muted); }
.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 60px;
  padding: 8px 16px;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}
.menu-item:active { background: var(--surface-2); }
.menu-item > .icon { color: var(--muted); }
.menu-item .label { display: block; font-weight: 650; }
.menu-item.danger, .menu-item.danger > .icon { color: var(--club); }

/* -------------------------------------------------------------------- toast */
#toast {
  position: fixed;
  inset: auto 0 calc(16px + env(safe-area-inset-bottom));
  z-index: 40;
  display: flex;
  justify-content: center;
  padding: 0 var(--gutter);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 460px;
  min-height: 52px;
  padding: 6px 6px 6px 18px;
  border-radius: 16px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 620;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.3);
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}
.toast button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg) 18%, transparent);
  color: var(--bg);
  font-weight: 700;
}
.toast button .icon { width: 18px; height: 18px; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

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