:root {
  --red: #dc0000;
  --red-deep: #8f0000;
  --red-glow: rgb(220 0 0 / 0.16);
  --ink: #0a0a0a;
  --surface: #141414;
  --surface-2: #1d1d1d;
  --line: #2c2c2c;
  --text: #f4f4f4;
  --muted: #a3a3a3;
  --ok: #3ccf7a;
  --warn: #f2b632;
  --font-display: "Oswald", "Arial Narrow", sans-serif;
  --font-body: "Raleway", system-ui, sans-serif;
  --radius-s: 4px;
  --radius-m: 10px;
  --gutter: clamp(16px, 3vw, 32px);
  --fast: 150ms;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font: 400 15px/1.45 var(--font-body);
  min-height: 100dvh;
  background-image: radial-gradient(1200px 400px at 85% -10%, var(--red-glow), transparent 70%);
  background-attachment: fixed;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--muted); }
.error { color: #ff6b6b; min-height: 1.4em; }
.empty { color: var(--muted); padding: 32px 0; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 10px var(--gutter);
  background: rgb(10 10 10 / 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar__brand img { display: block; height: 30px; width: auto; }
.nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav__link {
  font: 500 14px/1 var(--font-display); text-transform: uppercase; letter-spacing: 0.06em;
  text-decoration: none; color: var(--muted); padding: 10px 12px; border-radius: var(--radius-s);
  white-space: nowrap; transition: color var(--fast), background var(--fast);
}
.nav__link:hover { color: var(--text); background: var(--surface-2); }
.nav__link[aria-current="page"] { color: var(--text); box-shadow: inset 0 -2px 0 var(--red); }
.user { display: flex; gap: 12px; align-items: center; font-size: 13px; color: var(--muted); white-space: nowrap; }
.is-logged-out .topbar, .is-logged-out .fab { display: none; }

.main { padding: 20px var(--gutter) 120px; max-width: 1480px; margin: 0 auto; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--surface-2);
  font: 600 14px/1 var(--font-display); text-transform: uppercase; letter-spacing: 0.06em;
  text-decoration: none; cursor: pointer;
  transition: transform var(--fast) var(--ease), background var(--fast), border-color var(--fast);
}
.btn:hover { border-color: #4a4a4a; }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn--primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn--primary:hover { background: #f00000; border-color: #f00000; }
.btn--ghost { background: transparent; }
.btn--danger { color: #ff7070; border-color: #5a1a1a; }
.btn--small { min-height: 36px; padding: 0 12px; font-size: 12px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.linkish { background: none; border: 0; padding: 0; color: var(--text); text-decoration: underline; text-decoration-color: var(--red); text-underline-offset: 3px; cursor: pointer; text-align: left; }
.file-btn { cursor: pointer; }
.fab {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 20;
  min-height: 56px; padding: 0 24px; border-radius: 999px; border: 0;
  background: var(--red); color: #fff; cursor: pointer;
  font: 600 16px/1 var(--font-display); text-transform: uppercase; letter-spacing: 0.08em;
  box-shadow: 0 10px 30px rgb(220 0 0 / 0.35), 0 2px 6px rgb(0 0 0 / 0.5);
  transition: transform var(--fast) var(--ease);
}
.fab span { font-size: 22px; margin-right: 4px; }
.fab:hover { transform: translateY(-2px); }

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); letter-spacing: 0.02em; }
.field--grow { flex: 1 1 220px; }
.field--wide { grid-column: 1 / -1; }
.field input, .field select, .field textarea {
  min-height: 44px; padding: 10px 12px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--ink); color: var(--text); font-size: 16px;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--red); outline: none; box-shadow: 0 0 0 3px var(--red-glow); }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 18px; }
.segmented { display: flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.segmented__btn {
  min-height: 44px; padding: 0 14px; border: 0; background: transparent; cursor: pointer;
  font: 500 14px/1 var(--font-display); text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
}
.segmented__btn + .segmented__btn { border-left: 1px solid var(--line); }
.segmented__btn[aria-pressed="true"] { background: var(--red); color: #fff; }

/* Group headings */
.group-title {
  font: 700 clamp(28px, 4vw, 44px)/1 var(--font-display); text-transform: uppercase; letter-spacing: 0.02em;
  margin: 36px 0 4px; padding-bottom: 8px; border-bottom: 2px solid var(--red);
}

/* Divisions: Smoothcomp-style stacked division tables */
.toolbar { display: grid; gap: 12px; margin-bottom: 18px; }
.toolbar__row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; }
.toolbar__row .field { margin: 0; }
.sport-tabs .segmented__btn { min-width: 110px; }
.sport-tabs small { font: 500 12px/1 var(--font-body); opacity: 0.75; }
.sport-summary { margin: 0; color: var(--muted); font-size: 14px; }
.warn-text { color: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: transparent; cursor: pointer;
  font: 500 13px/1 var(--font-display); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.chip-btn:hover { border-color: #4a4a4a; color: var(--text); }
.chip-btn[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--ink); }
.chip-btn small { font: 500 11px/1 var(--font-body); opacity: 0.7; }
.chips-divider { width: 1px; height: 28px; background: var(--line); }

.panels { display: grid; gap: 18px; }
.panel-div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; }
.panel-div--alone { border-color: #5b4513; }
.panel-div__head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 14px 18px;
  border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.panel-div__toggle {
  flex: 1 1 320px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 0; background: none; padding: 0; text-align: left; cursor: pointer; min-height: 32px;
}
.panel-div__path { font-size: 17px; color: var(--muted); }
.panel-div__path b { color: var(--text); font-size: 19px; }
.chevron { color: var(--muted); font-size: 14px; }
.badge {
  font: 600 11px/1 var(--font-display); text-transform: uppercase; letter-spacing: 0.08em;
  padding: 6px 8px; border-radius: 3px; background: var(--ink); border: 1px solid var(--line); white-space: nowrap;
}
.badge--alone { color: var(--warn); border-color: #5b4513; }
.badge--belt { background: var(--red); border-color: var(--red); color: #fff; }
.table-wrap--flush { border: 0; border-radius: 0; }
.div-table { table-layout: fixed; }
.div-table th, .div-table td { white-space: normal; vertical-align: middle; overflow-wrap: anywhere; }
.div-table thead th:nth-child(1) { width: 26%; }
.div-table thead th:nth-child(2) { width: 12%; }
.div-table thead th:nth-child(3) { width: 24%; }
.div-table thead th:nth-child(4) { width: 10%; }
.div-table thead th:nth-child(6) { width: 84px; }
.div-table tbody th { font-weight: 400; }
.div-table tr.is-pending { opacity: 0.6; }
.name-link { border: 0; background: none; padding: 0; cursor: pointer; font-weight: 700; font-size: 15px; color: var(--text); text-align: left; }
.name-link:hover { color: #ff4d4d; text-decoration: underline; }
.flag { font-size: 15px; }
.col-born b { display: block; }
.col-born small { color: var(--muted); font-size: 12px; }
.col-record { font-variant-numeric: tabular-nums; }
.col-notes { min-width: 160px; }
.col-notes .chip { display: inline-block; margin: 2px 4px 2px 0; }
.col-edit { text-align: right; width: 1%; }
.chip { font-size: 11.5px; padding: 3px 8px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.chip--rule { background: var(--warn); border-color: var(--warn); color: #1a1200; }
.tag { font-style: normal; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--warn); margin-left: 8px; }
.panel-div__foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 18px; font-size: 14px; color: var(--muted); }
.panel-div__foot span { font: 600 15px/1 var(--font-display); color: var(--text); }

/* Sheet (add / edit) */
.sheet {
  width: min(720px, 100vw); max-height: 92dvh; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-m);
  background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgb(0 0 0 / 0.7);
}
.sheet::backdrop { background: rgb(0 0 0 / 0.7); backdrop-filter: blur(2px); }
.sheet[open] { animation: rise 220ms var(--ease); }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet__head { position: sticky; top: 0; z-index: 1; background: var(--surface); padding: 16px 56px 12px 20px; border-bottom: 1px solid var(--line); }
.sheet__head h2 { margin: 0; font: 700 24px/1.1 var(--font-display); text-transform: uppercase; }
.sheet__sub { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.sheet__close { position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; border: 0; background: none; font-size: 28px; cursor: pointer; color: var(--muted); }
.sheet__form { padding: 16px 20px 24px; }
.sheet__form.is-busy { opacity: 0.6; pointer-events: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.age-hint { margin: -4px 0 0; font-size: 12px; color: var(--warn); min-height: 1em; }
.sheet__actions {
  position: sticky; bottom: 0; display: flex; flex-wrap: wrap; gap: 10px;
  margin: 20px -20px 0; padding: 12px 20px; background: var(--surface); border-top: 1px solid var(--line);
}
.sheet__actions .btn--primary { flex: 1 1 160px; }
.warnings { list-style: none; margin: 0; padding: 12px 20px 0; display: flex; flex-wrap: wrap; gap: 6px; }
.warnings__item { font-size: 12px; padding: 5px 8px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.warnings__item--age_mismatch, .warnings__item--weight_off_ladder, .warnings__item--weight_gap, .warnings__item--same_club_only {
  color: #1a1200; background: var(--warn); border-color: var(--warn);
}
.sheet__history { margin-top: 10px; }
.history { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.history li { padding: 3px 0; }
.history b { color: var(--text); }
.history--wide { max-width: 900px; }

/* Club view & tables */
.club-summary { color: var(--muted); margin: 8px 0; }
.club-contacts { font-size: 13px; color: var(--muted); word-break: break-word; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-m); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table thead th { font: 500 12px/1 var(--font-display); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); background: var(--surface); }
.pill { font-size: 12px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); }
.pill--ok { color: var(--ok); border-color: #1d5a37; }
.pill--bad { color: #ff7070; border-color: #5a1a1a; }
.pill--warn { color: var(--warn); border-color: #5b4513; }
.pill--muted { color: var(--muted); }

/* Tools */
.panel { margin-bottom: 28px; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list__row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row-actions { margin-left: auto; display: flex; gap: 8px; }
.diff { margin: 16px 0; }
.diff h3 { font: 600 16px/1 var(--font-display); text-transform: uppercase; letter-spacing: 0.06em; margin: 0 0 8px; }
.diff--removed h3 { color: #ff7070; }
.diff--new h3, .diff--returning h3 { color: var(--ok); }
.diff--moved h3 { color: var(--warn); }
.diff ul { list-style: none; margin: 0; padding: 0; }
.check { display: flex; gap: 10px; align-items: center; padding: 8px 0; min-height: 44px; border-bottom: 1px solid var(--line); cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--red); }

/* Login */
.login { max-width: 360px; margin: 12vh auto 0; display: flex; flex-direction: column; gap: 14px; }
.login__logo { width: 240px; height: auto; margin-bottom: 8px; }
.login__title { margin: 0 0 8px; font: 600 22px/1 var(--font-display); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

/* Toasts */
.toast-host { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); }
.toast { padding: 12px 16px; border-radius: var(--radius-s); background: #f4f4f4; color: #0a0a0a; font-weight: 500; box-shadow: 0 8px 24px rgb(0 0 0 / 0.5); animation: rise 200ms var(--ease); }
.toast--error { background: var(--red); color: #fff; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
  .nav { order: 3; flex-basis: 100%; }
  .user { margin-left: auto; }
  .grid2 { grid-template-columns: 1fr; }
  .sheet { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; }
  .segmented { width: 100%; }
  .segmented__btn { flex: 1; padding: 0 6px; }
  .filters > .field:not(.field--grow) { flex: 1 1 40%; }
}

@media (max-width: 760px) {
  .sport-tabs { width: 100%; }
  .sport-tabs .segmented__btn { min-width: 0; }
  .toolbar__row .field { flex: 1 1 45%; }
  .chips-divider { display: none; }
  .div-table { table-layout: auto; }
  .div-table thead { display: none; }
  .div-table tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .div-table th, .div-table td { display: block; padding: 0; border: 0; }
  .div-table tbody th { grid-column: 1; }
  .div-table .col-edit { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
  .div-table .col-born { display: flex; gap: 8px; align-items: baseline; }
  .div-table .col-born b { display: inline; }
  .div-table td:not(.col-edit) { grid-column: 1; font-size: 13px; }
  .div-table .col-record:before { content: "Record "; color: var(--muted); }
  .div-table .col-notes:empty { display: none; }
  .panel-div__path { font-size: 14px; }
  .panel-div__path b { font-size: 17px; }
}
}

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