/* ==========================================================================
   Piste: one small design system.
   Light, calm surfaces; indigo for actions; emerald means "done / won";
   amber means "in progress"; gold is saved for the champion.
   ========================================================================== */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f1f4fa;
  --line: #e3e8f2;
  --line-strong: #c9d1e3;

  --text: #141b2d;
  --text-2: #3b4660;
  --muted: #66728c;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eceeff;
  --primary-ink: #3730a3;

  --success: #059669;
  --success-soft: #e6f7f0;
  --success-ink: #046c4e;

  --warn: #d98a00;
  --warn-soft: #fff4dc;
  --warn-ink: #8a5a00;

  --danger: #dc2626;
  --danger-soft: #fdecec;
  --danger-ink: #a11d1d;

  --gold: #f5b301;
  --gold-soft: #fff8e1;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 27, 45, 0.05), 0 6px 20px rgba(20, 27, 45, 0.05);
  --ring: 0 0 0 3px rgba(79, 70, 229, 0.28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
[id] { scroll-margin-top: 84px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; min-height: 100vh;
}
body > main { flex: 1 0 auto; width: 100%; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
main.wrap { padding-top: 28px; padding-bottom: 72px; }

a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }

h1 { font-size: 1.85rem; line-height: 1.2; letter-spacing: -0.02em; font-weight: 750; margin: 0 0 4px; }
h2 { font-size: 1.15rem; line-height: 1.3; letter-spacing: -0.01em; font-weight: 700; margin: 0 0 12px; }
h3 { font-size: 0.95rem; font-weight: 700; margin: 20px 0 8px; color: var(--text-2); }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: 0.88em; overflow-wrap: anywhere; }
small { font-size: 0.82em; }
.muted { color: var(--muted); }
.block { display: block; }
.hint { color: var(--muted); font-size: 0.92rem; margin: 0 0 14px; max-width: 70ch; }
.meta { color: var(--muted); margin: 0; }
.count { color: var(--muted); font-weight: 500; font-size: 0.88rem; margin-left: 6px; }

/* ---------- header and footer ---------- */
header.site {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
}
header.site .wrap { display: flex; align-items: center; gap: 28px; min-height: 64px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 800; font-size: 1.2rem; letter-spacing: -0.02em; }
.brand:hover { color: var(--text); }
.logo {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; font-weight: 800; font-size: 1rem;
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.35);
}
header.site nav { display: flex; gap: 4px; flex: 1; }
header.site nav a {
  color: var(--text-2); text-decoration: none; font-weight: 600; font-size: 0.95rem;
  padding: 8px 12px; border-radius: 10px;
}
header.site nav a:hover { background: var(--surface-2); color: var(--text); }
header.site nav a.active { background: var(--primary-soft); color: var(--primary-ink); }
header.site .account { display: flex; gap: 12px; align-items: center; }
header.site .account form { margin: 0; }
header.site .account > a:not(.btn) { color: var(--text-2); font-weight: 600; text-decoration: none; }
header.site .who { color: var(--muted); font-size: 0.9rem; }
.linklike { background: none; border: 0; padding: 0; color: var(--text-2); font: inherit; font-weight: 600; cursor: pointer; }
.linklike:hover { color: var(--primary); text-decoration: underline; }

footer.site-foot { border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 0.88rem; }
footer.site-foot .wrap { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 18px; padding-bottom: 18px; }
footer.site-foot a { color: var(--muted); }

/* ---------- layout pieces ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.narrow { max-width: 460px; margin: 16px auto; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card > h2:first-child, .card > .pool-head:first-child h2 { margin-top: 0; }

.group { margin-bottom: 28px; }
.group > h2 { margin-bottom: 14px; }

.empty { color: var(--muted); font-style: italic; margin: 6px 0; }
.empty-state {
  text-align: center; padding: 44px 20px; background: var(--surface); border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius); color: var(--text-2);
}
.empty-state h2 { margin-bottom: 6px; }
.empty-state p { margin: 4px auto 12px; max-width: 46ch; color: var(--muted); }

.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin: 0 0 16px; border: 1px solid; font-weight: 500; }
.flash.ok { background: var(--success-soft); color: var(--success-ink); border-color: #b7e8d3; }
.flash.bad { background: var(--danger-soft); color: var(--danger-ink); border-color: #f4c2c2; }

/* ---------- buttons ---------- */
.btn, input[type=submit] {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; cursor: pointer; text-decoration: none;
  background: var(--surface); color: var(--text); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); font: inherit; font-weight: 600; line-height: 1;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s, transform 0.05s;
}
.btn:hover, input[type=submit]:hover { background: var(--surface-2); border-color: #b5bfd6; color: var(--text); }
.btn:active, input[type=submit]:active { transform: translateY(1px); }
.btn:focus-visible, input[type=submit]:focus-visible { box-shadow: var(--ring); }
.btn.primary, input[type=submit].primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(79, 70, 229, 0.35); }
.btn.primary:hover, input[type=submit].primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
form .btn.primary + .btn, form input[type=submit].primary + input { margin-left: 6px; }
.btn.danger { color: var(--danger-ink); border-color: #f1b8b8; background: var(--surface); }
.btn.danger:hover { background: var(--danger-soft); border-color: #e99; }
.btn.small, input[type=submit].small { min-height: 32px; padding: 0 12px; font-size: 0.88rem; }
.btn.raised { position: relative; z-index: 2; }
button.btn { font: inherit; font-weight: 600; }
form.button_to { margin: 0; display: inline-block; }
.card form.button_to + form.button_to { margin-left: 6px; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 16px; align-items: flex-start; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.92rem; color: var(--text-2); }
.form .row { display: flex; gap: 16px; flex-wrap: wrap; }
.form .row label { flex: 1 1 180px; }
.form label > input, .form label > select { width: 100%; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  font: inherit; color: var(--text); padding: 9px 12px; min-height: 40px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input::placeholder, textarea::placeholder { color: #98a2b8; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
textarea { width: 100%; max-width: 680px; line-height: 1.5; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- stepper (desk) ---------- */
.stepper { display: flex; list-style: none; padding: 0; margin: 0 0 18px; gap: 0; counter-reset: none; }
.stepper li { flex: 1; display: flex; align-items: center; gap: 10px; position: relative; color: var(--muted); font-weight: 600; font-size: 0.9rem; min-width: 0; }
.stepper li:not(:last-child)::after { content: ""; flex: 1; height: 2px; background: var(--line); margin: 0 12px; border-radius: 2px; }
.stepper li.past:not(:last-child)::after { background: var(--success); }
.stepper .dot { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 2px solid var(--line-strong); font-size: 0.82rem; font-weight: 700; }
.stepper li.current { color: var(--primary-ink); }
.stepper li.current .dot { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 0 0 4px var(--primary-soft); }
.stepper li.past { color: var(--success-ink); }
.stepper li.past .dot { background: var(--success); border-color: var(--success); color: #fff; }
.stepper .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- "what to do next" box ---------- */
.next-step {
  background: linear-gradient(135deg, var(--primary-soft), #fff 70%);
  border: 1px solid #d9dcff; border-left: 5px solid var(--primary);
  border-radius: var(--radius); padding: 18px 22px; margin-bottom: 20px;
}
.next-step h2 { margin: 2px 0 6px; font-size: 1.3rem; }
.next-step p { margin: 0 0 10px; color: var(--text-2); max-width: 75ch; }
.next-step .ns-kicker { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.74rem; font-weight: 700; color: var(--primary-ink); margin: 0; }
.next-step .ns-count { color: var(--text); font-size: 0.95rem; margin: 8px 0 0; }
.next-step .btn { margin-top: 2px; }

.progress { height: 8px; background: #dfe3f4; border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.progress span { display: block; height: 100%; background: var(--primary); border-radius: inherit; transition: width 0.4s ease; }
.progress.complete span { background: var(--success); }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; background: var(--surface-2); color: var(--text-2); }
.badge.stage-setup { background: #eef1f7; color: #4a566f; }
.badge.stage-pools { background: var(--warn-soft); color: var(--warn-ink); }
.badge.stage-de { background: var(--primary-soft); color: var(--primary-ink); }
.badge.stage-done { background: var(--success-soft); color: var(--success-ink); }

.live-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(217, 138, 0, 0.5); } 70% { box-shadow: 0 0 0 8px rgba(217, 138, 0, 0); } 100% { box-shadow: 0 0 0 0 rgba(217, 138, 0, 0); } }
.stage-de .live-dot { animation-name: pulse-blue; }
@keyframes pulse-blue { 0% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.5); } 70% { box-shadow: 0 0 0 8px rgba(79, 70, 229, 0); } 100% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0); } }
.live-line { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; color: var(--warn-ink); font-weight: 600; font-size: 0.92rem; }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } html { scroll-behavior: auto; } }

.rating { display: inline-block; min-width: 1.7em; padding: 1px 7px; border-radius: 6px; background: #eef1f7; color: #4a566f; font-size: 0.82rem; font-weight: 700; text-align: center; }
input.tiny { width: 4.5em; }
tr.new-slot td { border-top: 2px solid #e5e7eb; }
@media print { header.site, footer.site-foot, .actions, nav { display: none !important; } }
pre.mail-body { white-space: pre-wrap; background: #f6f7fb; padding: 12px; border-radius: 8px; margin: 8px 0; overflow-wrap: anywhere; }
.offline-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: #7c2d12; color: #fff; padding: 10px 16px; text-align: center; font-weight: 600; }
form.queued { outline: 2px dashed #b45309; outline-offset: 2px; }
.checkin-cell { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; }
.checkin-cell form { margin: 0; }
table.checkins .btn { min-height: 38px; }
table.checkins tr.withdrawn td { opacity: 0.6; }
.card input[type=search] { width: 100%; max-width: 420px; margin-bottom: 10px; }
tr[hidden] { display: none; }
.card.ready { border-color: #86d6b0; background: #f3fcf8; }
.card-chip { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; }
.card-yellow { background: #fff3b0; color: #6b5800; }
.card-red { background: #fecdcd; color: #8a1c1c; }
.card-black { background: #1f2937; color: #fff; }
.waiver { border: 1px solid #e5e7eb; border-radius: 10px; padding: 12px 14px; background: #fafbff; display: grid; gap: 8px; }
.waiver-text { max-height: 180px; overflow: auto; font-size: 0.92rem; }
.rating-other { background: #eef1f7; color: #4a566f; }
.rating-A { background: #fff1cf; color: #7a4a00; }
.rating-B { background: var(--primary-soft); color: var(--primary-ink); }
.rating-C { background: var(--success-soft); color: var(--success-ink); }

/* ---------- event cards ---------- */
.event-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.event-card {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 18px 16px; box-shadow: var(--shadow); transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
  border-top: 4px solid var(--line-strong);
}
.event-card:hover { transform: translateY(-2px); border-color: #b9c2e8; box-shadow: 0 2px 4px rgba(20, 27, 45, 0.06), 0 12px 28px rgba(20, 27, 45, 0.09); }
.event-card.stage-pools { border-top-color: var(--warn); }
.event-card.stage-de { border-top-color: var(--primary); }
.event-card.stage-done { border-top-color: var(--success); }
.ec-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.ec-date { color: var(--muted); font-size: 0.85rem; }
.event-card h3 { margin: 0 0 4px; font-size: 1.1rem; color: var(--text); }
.event-card h3 a { color: inherit; text-decoration: none; }
.event-card h3 a.stretched::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.ec-meta { margin: 0 0 10px; color: var(--muted); font-size: 0.92rem; }
.ec-foot { margin: 0; font-weight: 600; font-size: 0.92rem; color: var(--text-2); min-height: 32px; display: flex; align-items: center; }

/* ---------- tournaments ---------- */
.event-tabs { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 0 0 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.event-tabs .tab { display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line-strong); color: var(--text-2); font-weight: 600; font-size: 0.9rem; text-decoration: none; }
.event-tabs .tab:hover { background: var(--primary-soft); border-color: #b9c0f5; color: var(--primary-ink); }
.event-tabs .tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.event-tabs .tab.home { background: transparent; border-color: transparent; color: var(--muted); padding-left: 4px; }
.event-tabs .tab.home:hover { background: transparent; color: var(--primary); }
.tab-dot { width: 9px; height: 9px; border-radius: 50%; background: #c3cbe0; display: inline-block; flex: none; }
.tab-dot.stage-pools { background: var(--warn); }
.tab-dot.stage-de { background: var(--primary); }
.tab-dot.stage-done { background: var(--success); }
.event-tabs .tab.active .tab-dot { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6); }

.tournament-card { border-top-width: 4px; background: linear-gradient(180deg, #fff, #fbfbff); }
.tournament-card.phase-live { border-top-color: var(--warn); }
.tournament-card.phase-done { border-top-color: var(--success); }
.tournament-card.phase-setup { border-top-color: var(--primary); }
.tournament-card::before { content: ""; position: absolute; left: 10px; right: 10px; bottom: -6px; height: 6px; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); background: var(--surface); }
.t-events { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--text-2); }
.t-events li { display: flex; align-items: center; gap: 8px; }
.t-events .more { color: var(--muted); padding-left: 17px; }
.badge.tphase-setup { background: var(--primary-soft); color: var(--primary-ink); }
.badge.tphase-live { background: var(--warn-soft); color: var(--warn-ink); }
.badge.tphase-done { background: var(--success-soft); color: var(--success-ink); }
.live-line.calm { color: var(--muted); font-weight: 500; }
.checks { border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 8px 14px 12px; margin: 0; width: 100%; }
.checks legend { font-weight: 700; font-size: 0.9rem; color: var(--text-2); padding: 0 6px; }
.form label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; padding: 6px 0; cursor: pointer; }
.check input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--primary); }
.tv-event { display: inline-block; margin-right: 14px; padding: 2px 16px; border-radius: 999px; background: #1e2a52; color: #a5b4fc; font-size: 0.6em; font-weight: 700; vertical-align: middle; }
.tv-event-line { margin: 0 0 6px; color: #a5b4fc; font-size: 1.5rem; font-weight: 700; }
.tv .pool-slide .tv-event-line { margin-bottom: 12px; }

/* ---------- FencingTimeLive-style lists and breadcrumbs ---------- */
.crumbs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 14px; font-size: 0.9rem; color: var(--muted); }
.crumbs a { color: var(--primary); text-decoration: none; font-weight: 600; }
.crumbs a:hover { text-decoration: underline; }
.crumbs [aria-current] { color: var(--text-2); font-weight: 600; }
.card.flush { padding: 0; overflow: hidden; }
.table.list th, .table.list td { padding: 14px 16px; }
.table.list thead th { background: var(--surface-2); border-bottom: 1px solid var(--line); }
.table.list tbody tr:hover td { background: #f7f8ff; }
.table.list a.rowname { font-weight: 700; font-size: 1.04rem; color: var(--primary-ink); text-decoration: none; }
.table.list a.rowname:hover { color: var(--primary); text-decoration: underline; }
.table.list td small.block { margin-top: 2px; }
.nowrap { white-space: nowrap; }
/* the home page lists share column widths so the groups line up */
.table.list.index { table-layout: fixed; }
.table.list.index th:nth-child(1) { width: 19%; }
.table.list.index th:nth-child(2) { width: 27%; }
.table.list.index th:nth-child(3) { width: 21%; }
.table.list.index th:nth-child(4) { width: 20%; }
.table.list.index th:nth-child(5) { width: 13%; }
.table.list td.actions { display: table-cell; white-space: nowrap; }
.table.list td.actions .btn + .btn, .table.list td.actions form.button_to + .btn { margin-left: 6px; }
.table.list td.actions > * { vertical-align: middle; }

/* ---------- accounts ---------- */
.narrow.wide { max-width: 760px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 18px 0; }
.choice { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.choice h2 { margin: 0; }
.choice p { margin: 0 0 6px; color: var(--text-2); }
.claim { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.claim h2 { margin: 0 0 4px; }
.claim .meta { margin: 0; }
.badge.state-pending { background: var(--warn-soft); color: var(--warn-ink); }
.badge.state-confirmed { background: var(--success-soft); color: var(--success-ink); }
.badge.state-declined { background: var(--danger-soft); color: var(--danger-ink); }
.check.locked { opacity: 0.6; cursor: not-allowed; }
details.pw { width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 14px; }
details.pw summary { cursor: pointer; font-weight: 600; color: var(--text-2); }
details.pw label { margin-top: 12px; }
.danger-zone { border-color: #f1b8b8; }
@media (max-width: 760px) { .choices { grid-template-columns: 1fr; } }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: center; vertical-align: middle; }
.table th { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; white-space: nowrap; background: transparent; }
.table td:first-child, .table th:first-child { text-align: left; }
.table .left, .table th.left { text-align: left; }
.table .right { text-align: right; }
.table tbody tr:hover td { background: #fafbfe; }
.table tbody tr:last-child td { border-bottom: 0; }
.table td { font-variant-numeric: tabular-nums; }
.table button, .table input[type=submit] { margin: 0; }
tr.cut td { background: var(--surface-2); color: var(--muted); }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.exports { color: var(--muted); font-size: 0.92rem; margin: -6px 0 16px; }
.table .actions { justify-content: flex-end; }

/* ---------- pools ---------- */
.pool-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.pool-head h2 { margin-bottom: 0; }
.pool-status { font-size: 0.85rem; font-weight: 700; color: var(--warn-ink); background: var(--warn-soft); padding: 3px 12px; border-radius: 999px; }
.pool-status.complete { color: var(--success-ink); background: var(--success-soft); }
.pool .progress { margin: 10px 0 14px; }
table.sheet td.diag { background: repeating-linear-gradient(45deg, #f1f4fa, #f1f4fa 4px, #e6ebf5 4px, #e6ebf5 8px); }
table.sheet td.cell { min-width: 46px; }
table.sheet td.win { font-weight: 700; color: var(--success-ink); background: #f3fbf7; }
table.sheet td:nth-child(2) { white-space: nowrap; }
table.sheet .fname { font-weight: 600; }
table.sheet .place { color: var(--primary-ink); }
.legend { color: var(--muted); font-size: 0.85rem; margin: 10px 0 0; max-width: 90ch; }
.legend strong { color: var(--text-2); }
.win-sample { font-weight: 700; color: var(--success-ink); }

ol.bouts { list-style: none; padding: 0; margin: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
li.bout { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: #fff; }
li.bout:last-child { border-bottom: 0; }
li.bout.scored { background: #fafdfb; }
li.bout.next { background: var(--primary-soft); box-shadow: inset 4px 0 0 var(--primary); }
.bout-no { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-size: 0.82rem; font-weight: 700; }
li.bout.scored .bout-no { background: var(--success); color: #fff; }
li.bout.next .bout-no { background: var(--primary); color: #fff; }
.bout-form { flex: 1; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; min-width: 0; }
.bout-form .name { flex: 1 1 130px; min-width: 110px; font-weight: 500; }
.bout-form .name.right { text-align: right; }
.bout-form .name.won { font-weight: 700; color: var(--success-ink); }
.score { width: 64px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.dash { color: var(--muted); font-size: 0.85rem; }

/* ---------- champion ---------- */
.champion { text-align: center; background: linear-gradient(180deg, var(--gold-soft), #fff 80%); border-color: #f3dc9a; }
.champion .label { margin: 0; color: var(--warn-ink); text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.78rem; font-weight: 800; }
.champion h2 { font-size: 2.1rem; margin: 6px 0 12px; letter-spacing: -0.02em; }
.champion h2::before { content: "🏆 "; }

/* ---------- jump links ---------- */
.jump { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 18px; }
.jump span { color: var(--muted); font-size: 0.85rem; font-weight: 600; margin-right: 2px; }
.jump a { padding: 6px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line-strong); color: var(--text-2); font-weight: 600; font-size: 0.88rem; text-decoration: none; }
.jump a:hover { background: var(--primary-soft); border-color: #b9c0f5; color: var(--primary-ink); }

/* ---------- the bracket ----------
   One grid. Round k is column k. A bout in round k spans 2^(k+1) rows, so it sits
   centred between the two bouts that feed it, and the connector lines meet there. */
.bracket-scroll { overflow-x: auto; padding: 4px 2px 14px; }
.bracket {
  --unit: 34px; --gap: 34px; --line: #c3cbe0;
  display: grid;
  grid-template-columns: repeat(var(--rounds), 276px);
  grid-template-rows: auto repeat(var(--rows), var(--unit));
  column-gap: var(--gap);
  width: max-content;
}
.bhead { grid-row: 1; text-align: center; font-size: 0.76rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding-bottom: 10px; }
.bcell { position: relative; display: flex; align-items: center; }
.bcell.pair-top::after, .bcell.pair-bottom::after { content: ""; position: absolute; right: calc(var(--gap) / -2); width: calc(var(--gap) / 2); border: 0 solid var(--line); border-right-width: 2px; }
.bcell.pair-top::after { top: 50%; bottom: 0; border-top-width: 2px; }
.bcell.pair-bottom::after { top: 0; bottom: 50%; border-bottom-width: 2px; }
.bcell.has-feeder::before { content: ""; position: absolute; left: calc(var(--gap) / -2); width: calc(var(--gap) / 2); top: 50%; border-top: 2px solid var(--line); }

.bcard { width: 100%; background: #fff; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; display: flex; align-items: stretch; box-shadow: 0 1px 2px rgba(20, 27, 45, 0.06); }
.bcard.ready { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.22); }
.bcard.final { border: 2px solid var(--gold); box-shadow: 0 4px 14px rgba(245, 179, 1, 0.25); }
.bcard .bsides { flex: 1; min-width: 0; }
.bside { display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 9px; border-left: 4px solid transparent; }
.bside + .bside { border-top: 1px solid var(--line); }
.bside .seed { width: 20px; text-align: right; color: var(--muted); font-size: 0.76rem; font-variant-numeric: tabular-nums; }
.bside .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.92rem; }
.bside .pts { min-width: 1.6em; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.bside.won { border-left-color: var(--success); background: var(--success-soft); }
.bside.won .name, .bside.won .pts { font-weight: 700; color: var(--success-ink); }
.bside.lost .name, .bside.lost .pts, .bside.lost .seed { color: #9aa5bc; }
.bside.tbd .tbd-label { color: #9aa5bc; font-style: italic; font-size: 0.84rem; padding-left: 28px; }
.bcard.bye { border-style: dashed; background: #fafbfd; box-shadow: none; }
.bcard.bye .bside { border-left-color: #cbd5e1; background: transparent; }
.bcard.bye .bside .name, .bcard.bye .bside .seed { color: var(--text-2); }
.bye-tag { color: var(--muted); font-size: 0.76rem; font-style: italic; }
.bside input.score { width: 44px; height: 24px; min-height: 24px; padding: 0 4px; font-size: 0.9rem; border-radius: 6px; }
.bsave { border: 0; border-left: 1px solid var(--line); background: var(--primary-soft); color: var(--primary-ink); width: 36px; font-size: 1.1rem; font-weight: 800; cursor: pointer; transition: background 0.12s, color 0.12s; }
.bsave:hover { background: var(--primary); color: #fff; }

/* ---------- live display (TV) ---------- */
body.tv { background: #0a0f1f; color: #eef1fb; overflow: hidden; height: 100vh; }
.tv-frame { height: 100vh; display: flex; flex-direction: column; padding: 22px 36px; }
.tv-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid #1c2542; padding-bottom: 14px; }
.tv-head h1 { font-size: 2.6rem; margin: 0; letter-spacing: -0.02em; }
.tv-head p { margin: 2px 0 0; color: #98a5c8; font-size: 1.3rem; }
.tv-clock { font-size: 2.4rem; font-weight: 700; color: #98a5c8; font-variant-numeric: tabular-nums; }
.tv-slides { flex: 1; min-height: 0; position: relative; }
.tv-slides .slide { height: 100%; padding-top: 18px; overflow: hidden; }
.tv-slides .slide[hidden] { display: none; }
.tv .slide h2 { font-size: 2.2rem; margin: 0 0 18px; color: #fff; }
.tv .big { font-size: 2.6rem; margin: 0 0 18px; }
.tv-names { columns: 3; list-style: none; padding: 0; font-size: 1.5rem; line-height: 1.7; }
.tv-names small { color: #7d8bb0; }
.tv-table { border-collapse: collapse; font-size: 2.2rem; width: 100%; }
.tv-table td { padding: 10px 16px; border-bottom: 1px solid #1c2542; }
.tv-table .place { width: 90px; font-weight: 800; color: #fbbf24; }
.tv-table .club { color: #7d8bb0; font-size: 1.5rem; }
.tv-table .num { text-align: right; font-variant-numeric: tabular-nums; color: #98a5c8; }
.champion-slide { text-align: center; padding-top: 6vh; }
.champion-slide .label { text-transform: uppercase; letter-spacing: 0.2em; color: #fbbf24; font-size: 1.5rem; }
.tv .champion-slide h2 { font-size: 6rem; margin: 10px 0 30px; line-height: 1.1; }
.champion-slide .runner { font-size: 2.4rem; color: #98a5c8; margin: 8px 0; }
.tv .bracket-slide .fit { zoom: 1; width: max-content; }
.tv .bracket { --line: #34416a; }
.tv .bcard { background: #121a33; border-color: #2a3560; color: #eef1fb; box-shadow: none; }
.tv .bcard.final { border-color: #fbbf24; }
.tv .bside.won { background: #0f3a2b; }
.tv .bside.won .name, .tv .bside.won .pts { color: #6ee7a8; }
.tv .bside + .bside { border-top-color: #222c52; }
.tv .bside.lost .name, .tv .bside.lost .pts, .tv .bside.lost .seed { color: #5b6a93; }
.tv .bcard.bye { background: #0e1429; }
.tv .bhead { color: #98a5c8; }
.tv .pool-slide .card { background: #121a33; border-color: #2a3560; color: #eef1fb; box-shadow: none; }
.tv .pool-slide .legend, .tv .pool-slide .progress { display: none; }
.tv .pool-slide .pool-status { display: none; }
.tv .pool-slide .table th { color: #98a5c8; }
.tv .pool-slide .table th, .tv .pool-slide .table td { border-bottom-color: #222c52; font-size: 1.15rem; }
.tv .pool-slide .table tbody tr:hover td { background: transparent; }
.tv .pool-slide table.sheet td.diag { background: repeating-linear-gradient(45deg, #182244, #182244 4px, #1e2a52 4px, #1e2a52 8px); }
.tv .pool-slide table.sheet td.win { color: #6ee7a8; background: transparent; }
.tv .pool-slide table.sheet .place { color: #fbbf24; }

/* ---------- print ---------- */
body.printable { background: #fff; }
.print-bar { display: flex; gap: 8px; margin: 12px 0; }
.page-break { break-before: page; }
@media print {
  header.site, footer.site-foot, .noprint, .print-bar, .jump, .exports { display: none !important; }
  body { background: #fff; }
  main.wrap { padding: 0; }
  .card { box-shadow: none; border: none; padding: 0; break-inside: avoid; }
  .bracket-scroll { overflow: visible; }
  .bracket { --unit: 28px; }
  .progress, .legend { display: none; }
}

/* ---------- phones and tablets (scorers use these) ---------- */
@media (max-width: 760px) {
  .table.list.stack { table-layout: auto; }
  .table.list.stack thead { display: none; }
  .table.list.stack, .table.list.stack tbody { display: block; }
  .table.list.stack tr { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); align-items: start; }
  .table.list.stack tbody tr:last-child { border-bottom: 0; }
  .table.list.stack td { display: block; padding: 0; border: 0; text-align: left; width: auto; background: transparent !important; }
  .table.list.stack td.c-name { grid-column: 1; grid-row: 1; }
  .table.list.stack td.c-status { grid-column: 2; grid-row: 1; text-align: right; }
  .table.list.stack td.c-date { grid-column: 1 / -1; grid-row: 2; color: var(--muted); font-size: 0.9rem; }
  .table.list.stack td.c-where { grid-column: 1 / -1; grid-row: 3; color: var(--muted); font-size: 0.9rem; }
  .table.list.stack td.c-where:empty { display: none; }
  .table.list.stack td.c-events { grid-column: 1 / -1; grid-row: 4; }
  .table.list.stack td.c-weapon, .table.list.stack td.c-entries { grid-column: 1 / -1; grid-row: 2; color: var(--muted); font-size: 0.9rem; }
  .table.list.stack td.c-entries { grid-row: 3; }
  .table.list.stack td.c-entries::after { content: " entries"; }
  .table.list.stack td.c-actions { grid-column: 1 / -1; grid-row: 5; text-align: left; padding-top: 4px; }
  .table.list.stack td.c-status .badge { white-space: nowrap; }
  .table.list th, .table.list td { padding: 12px; }
  header.site { position: static; }
  [id] { scroll-margin-top: 12px; }
  main.wrap { padding-top: 18px; }
  header.site .wrap { gap: 8px 14px; padding-top: 10px; padding-bottom: 10px; }
  header.site nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  header.site .who { display: none; }
  h1 { font-size: 1.5rem; }
  .card { padding: 16px; }
  .next-step { padding: 16px; }
  .stepper .lbl { display: none; }
  .stepper li.current .lbl { display: inline; }
  .stepper li:not(:last-child)::after { margin: 0 6px; }
  .event-grid { grid-template-columns: 1fr; }

  /* scoring rows: names on top, big score boxes underneath */
  li.bout { align-items: flex-start; padding: 12px; }
  .bout-form { gap: 8px; }
  .bout-form .name { flex: 1 1 100%; min-width: 0; text-align: left !important; }
  .bout-form .name.right { order: 1; }
  .bout-form input.score { order: 2; width: 72px; min-height: 48px; font-size: 1.15rem; }
  .bout-form .dash { order: 2; }
  .bout-form .name:not(.right) { order: 3; }
  .bout-form .btn { order: 4; min-height: 48px; margin-left: auto; padding: 0 22px; }
  .bside input.score { width: 54px; height: 28px; }
  .champion h2 { font-size: 1.6rem; }
}

/* Admin testing switch */
.testbar { background: #1e1b4b; color: #fff; font-size: 14px; }
.testbar .wrap { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; padding-top: 8px; padding-bottom: 8px; }
.testbar-actions { display: flex; gap: 12px; align-items: center; }
.testbar form { margin: 0; }
.testbar button.linklike { color: #c7d2fe; }
.testbar button.linklike:disabled { color: #818cf8; text-decoration: none; cursor: default; }
header.site details.switcher { position: relative; }
header.site details.switcher summary { cursor: pointer; color: var(--text-2); font-weight: 600; list-style: none; }
header.site details.switcher > div { position: absolute; right: 0; top: 28px; z-index: 5; background: #fff; border: 1px solid var(--border, #e5e7eb); border-radius: var(--radius-sm); padding: 8px 12px; display: grid; gap: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.12); white-space: nowrap; }
ul.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
/* Admin testing switch */
.testbar { background: #1e1b4b; color: #fff; font-size: 14px; }
.testbar .wrap { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; padding-top: 8px; padding-bottom: 8px; }
.testbar-actions { display: flex; gap: 12px; align-items: center; }
.testbar form { margin: 0; }
.testbar button.linklike { color: #c7d2fe; }
.testbar button.linklike:disabled { color: #818cf8; text-decoration: none; cursor: default; }
header.site details.switcher { position: relative; }
header.site details.switcher summary { cursor: pointer; color: var(--text-2); font-weight: 600; list-style: none; }
header.site details.switcher > div { position: absolute; right: 0; top: 28px; z-index: 5; background: #fff; border: 1px solid var(--border, #e5e7eb); border-radius: var(--radius-sm); padding: 8px 12px; display: grid; gap: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.12); white-space: nowrap; }
ul.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }

/* sign-up: fencer or organiser, as two cards */
.role-choice { border: 0; padding: 0; margin: 0; width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.role-choice legend { font-weight: 700; font-size: 0.92rem; color: var(--text-2); padding: 0; margin-bottom: 8px; }
.form .role-choice label.role { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; font-weight: 400; font-size: 0.88rem; color: var(--muted); }
.form .role-choice label.role strong { font-size: 1rem; color: var(--text); }
.form .role-choice label.role:hover { border-color: var(--primary); }
.form .role-choice label.role:has(input:checked) { border-color: var(--primary); background: #eef2ff; box-shadow: inset 0 0 0 1px var(--primary); }
.form .role-choice label.role:has(input:focus-visible) { box-shadow: var(--ring); }
.form .role-choice label.role > input { position: absolute; opacity: 0; width: 1px; height: 1px; }
@media (max-width: 520px) { .role-choice { grid-template-columns: 1fr; } }

.badge.registered { background: #dcfce7; color: #166534; }

/* sign-up: wider so the paired fields sit side by side and the form stays short */
.narrow.signup { max-width: 600px; }
.narrow.signup .form .row { width: 100%; }
.narrow.signup .form .row label { flex: 1 1 220px; min-width: 0; }
/* the form centres its children to their own width; stretch the single-field rows to the full card */
.narrow.signup .form > label { align-self: stretch; }

/* online registration card: title and status on the left, the switch on the right */
.reg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px 20px; flex-wrap: wrap; }
.reg-head h2 { margin: 0 0 4px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.reg-head .hint { margin: 0; max-width: 62ch; }
.reg-head form { margin: 0; }
.reg-card h3 { margin: 18px 0 8px; font-size: 1rem; }

/* printable pool sheets (desk side): blank grid to fill in by hand */
.sheet-meta { display: flex; flex-wrap: wrap; gap: 6px 28px; margin: 6px 0 14px; color: var(--text-2); }
.sheet-meta .blank { display: inline-block; min-width: 9em; border-bottom: 1px solid #000; height: 1.2em; vertical-align: bottom; }
table.blank-sheet { width: 100%; border-collapse: collapse; }
table.blank-sheet th, table.blank-sheet td { border: 1px solid #222; padding: 4px 6px; text-align: center; }
table.blank-sheet td.cell { height: 46px; min-width: 46px; }
table.blank-sheet td.name { text-align: left; white-space: nowrap; font-weight: 600; }
table.blank-sheet td.name small { font-weight: 400; color: #555; }
table.blank-sheet td.diag { position: relative; padding: 0; background: #eee; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
table.blank-sheet td.diag svg.cross { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
table.blank-sheet td.diag svg.cross line { stroke: #000; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
table.blank-sheet.bouts td { height: 38px; }
table.blank-sheet.bouts td.write { width: 70px; }
@media print { table.blank-sheet th, table.blank-sheet td { border-color: #000; } .sheet-page { break-after: page; } .sheet-page:last-child { break-after: auto; } }

.sheet-bar { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; }
.sheet-bar .btn { margin-left: auto; }

/* the name box is the organization's name for an organiser, the person's name for a fencer */
.narrow.signup .for-organizer { display: none; }
.narrow.signup form:not(:has(input[type=radio])) .for-organizer, .narrow.signup form:has(input[type=radio][value=organizer]:checked) .for-organizer { display: inline; }
.narrow.signup form:has(input[type=radio][value=organizer]:checked) .for-fencer { display: none; }
/* organisers run clubs, they don't pick one: hide the club box when Organiser is chosen */
.narrow.signup form:has(input[type=radio][value=organizer]:checked) .club-field { display: none; }

/* search and sort bar above the tournament lists */
.list-search { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; margin: 0 0 16px; }
.list-search input[type=search] { flex: 1 1 260px; max-width: 420px; margin: 0; }
.list-search .sort-by { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; font-weight: 600; color: var(--text-2); }
.list-search select { margin: 0; }
.list-search .results-count { font-size: 0.9rem; }

/* sections of an event page: Pools, Pool results, Bracket ... as separate tabs */
.section-tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line-strong); margin: 0 0 16px; -webkit-overflow-scrolling: touch; }
.section-tabs .stab { flex: none; padding: 10px 16px; font-weight: 600; font-size: 0.95rem; color: var(--text-2); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.section-tabs .stab:hover { color: var(--primary-ink); background: var(--primary-soft); }
.section-tabs .stab.active { color: var(--primary); border-bottom-color: var(--primary); }
