:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f9;
  --text: #0f1b2b;
  --muted: #5b6b80;
  --line: #d9e2ee;
  --accent: #0b5cad;
  --accent-soft: #e2eefb;
  --on-accent: #ffffff;
  --good: #11845b;
  --good-soft: #e1f5ec;
  --warn: #b4441b;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(15 27 43 / 6%), 0 4px 16px rgb(15 27 43 / 6%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1724;
    --surface: #122235;
    --surface-2: #182b42;
    --text: #e7eef7;
    --muted: #93a6bd;
    --line: #24384f;
    --accent: #4aa3ff;
    --accent-soft: #15314f;
    --on-accent: #06121f;
    --good: #45cf96;
    --good-soft: #123829;
    --warn: #ff9a73;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1724;
  --surface: #122235;
  --surface-2: #182b42;
  --text: #e7eef7;
  --muted: #93a6bd;
  --line: #24384f;
  --accent: #4aa3ff;
  --accent-soft: #15314f;
  --on-accent: #06121f;
  --good: #45cf96;
  --good-soft: #123829;
  --warn: #ff9a73;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.warn { color: var(--warn); }
.good { color: var(--good); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.num { text-align: right; }

/* ---------- header */
#header { padding-top: 20px; display: grid; gap: 14px; grid-template-columns: 1fr auto; align-items: center; }
.brand { display: flex; gap: 10px; align-items: center; }
.logo { position: relative; display: block; width: 54px; aspect-ratio: 28 / 20; flex: none; overflow: hidden; border-radius: 18% / 25%; background: var(--accent); color: var(--on-accent); }
.logo-wave { position: absolute; left: -39.29%; top: 0; width: 285.71%; height: 100%; }
.logo-head { position: absolute; left: 24.3%; top: 19%; width: 15.7%; aspect-ratio: 1; border-radius: 50%; background: var(--on-accent); }
@media (max-width: 480px) { .logo { width: 44px; } }
.brand h1 { font-size: 22px; letter-spacing: -0.02em; }
.tagline { color: var(--muted); font-size: 13px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.tabs { grid-column: 1 / -1; display: flex; gap: 4px; align-items: center; border-bottom: 1px solid var(--line); }
.tabs [role=tab] {
  background: none; border: 0; padding: 10px 12px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600;
}
.tabs [aria-selected=true] { color: var(--text); border-color: var(--accent); }
.count { background: var(--surface-2); border-radius: 99px; padding: 0 7px; font-size: 12px; margin-left: 2px; }
.spacer { flex: 1; }

@media (max-width: 720px) {
  #header { grid-template-columns: 1fr; }
  .toolbar { justify-content: stretch; }
  .toolbar > * { flex: 1 1 auto; }
  .toolbar .select { flex-basis: 100%; }
  .tabs .muted { display: none; }
}

/* ---------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 10px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); font-weight: 600; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn svg { width: 18px; height: 18px; }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.select select, .fields input, .paste input {
  min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  padding: 0 10px; width: 100%;
}
.select select { padding-right: 28px; }
.link { background: none; border: 0; text-decoration: none; color: var(--accent); cursor: pointer; padding: 6px 0; font-weight: 600; }
.link.danger { color: var(--warn); }
.icon { background: var(--surface-2); border: 0; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; flex: none; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; border-radius: 8px; padding: 6px 10px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg.small button { padding: 4px 8px; font-size: 12px; }
.seg [aria-pressed=true] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- main */
#main { padding-top: 18px; padding-bottom: 24px; min-height: 50vh; }
.empty { text-align: center; padding: 48px 16px; display: grid; gap: 10px; justify-items: center; }
.empty svg { width: 140px; }
.empty h2 { font-size: 20px; }

.deck { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
  display: grid; gap: 12px; cursor: pointer; border: 1px solid transparent; align-content: start;
}
.card:hover { border-color: var(--line); }
.card.loading { opacity: 0.7; }
.card.has-error { border-color: var(--warn); }
.card-head { display: flex; justify-content: space-between; gap: 8px; }
.card h3 { font-size: 17px; }
.tag { font-size: 11px; font-weight: 700; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; align-self: start; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; display: grid; }
.stat b { font-size: 22px; line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.good { background: var(--good-soft); }
.stat.good b { color: var(--good); }
.latest { display: grid; gap: 2px; }
.pool { font-size: 12px; color: var(--muted); }
.time { font-weight: 700; font-variant-numeric: tabular-nums; }
.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }
.chip {
  font-size: 12px; background: var(--accent-soft); border-radius: 8px; padding: 4px 9px;
  display: flex; justify-content: space-between; align-items: baseline; gap: 6px; white-space: nowrap; min-width: 0;
}
.chip > span { overflow: hidden; text-overflow: ellipsis; }
.chip small { color: var(--muted); }

/* ---------- rankings */
.rank-controls { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.rank-controls .select { display: grid; gap: 4px; font-size: 13px; color: var(--muted); min-width: 240px; }
.ranking { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.ranking li {
  display: grid; grid-template-columns: 36px 1fr auto 1fr 64px; gap: 10px; align-items: center;
  padding: 10px 14px; border-top: 1px solid var(--line); cursor: pointer;
}
.ranking li:first-child { border-top: 0; }
.ranking .who { display: grid; }
.ranking .time { font-size: 17px; }
.ranking .gap { text-align: right; }
.pos { font-weight: 700; color: var(--muted); text-align: center; }
.ranking li:first-child .pos { color: var(--accent); }
@media (max-width: 640px) {
  .ranking li { grid-template-columns: 28px 1fr auto; }
  .ranking .when { grid-column: 2 / -1; grid-row: 2; }
  .ranking .gap { display: none; }
}

/* ---------- dialogs */
.dialog {
  border: 0; padding: 0; background: var(--surface); color: var(--text); border-radius: 18px;
  width: min(760px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
}
.dialog::backdrop { background: rgb(8 18 30 / 55%); }
.sheet { padding: 18px; display: grid; gap: 14px; }
.small-sheet { max-width: 420px; }
.sheet-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.sheet-head h2 { font-size: 20px; }
.sheet-tools { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.sheet-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-top: 6px; border-top: 1px solid var(--line); }
@media (max-width: 640px) {
  .dialog { width: 100vw; max-width: 100vw; max-height: 92dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .sheet { padding: 16px 14px calc(16px + env(safe-area-inset-bottom)); }
}

.events { width: 100%; border-collapse: collapse; }
.events th { font-size: 12px; color: var(--muted); font-weight: 600; text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.events th.num { text-align: right; }
.events td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.events td small { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }
.events td small.good { color: var(--good); }
.events tr.ev { cursor: pointer; }
.events tr.pb td:first-child { box-shadow: inset 3px 0 0 var(--good); }
.chev { display: inline-block; width: 14px; color: var(--muted); transition: transform 0.15s; }
tr.open .chev { transform: rotate(90deg); }
.badge { font-size: 10px; font-weight: 700; color: var(--good); background: var(--good-soft); padding: 1px 6px; border-radius: 99px; vertical-align: 1px; white-space: nowrap; }
.events > tbody > tr.detail > td { background: var(--surface-2); padding: 12px; }
@media (max-width: 520px) { .hide-sm { display: none; } }

.event-detail { display: grid; gap: 10px; }
.detail-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.top { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.top li { display: grid; grid-template-columns: 24px 72px 1fr auto; gap: 8px; align-items: baseline; background: var(--surface); border-radius: 8px; padding: 6px 8px; }

.chart { width: 100%; height: auto; background: var(--surface); border-radius: 10px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { font-size: 11px; fill: var(--muted); }
.chart .best { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .dot { fill: var(--muted); opacity: 0.6; }
.chart .dot.pb { fill: var(--accent); opacity: 1; }

/* ---------- add dialog */
.fields { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.fields label, .paste label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.fields .wide { grid-column: 1 / -1; }
.hits { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 45dvh; overflow: auto; }
.hits li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; }
.hits li > span { display: grid; }
.paste { border-top: 1px solid var(--line); padding-top: 12px; }
.row { display: flex; gap: 8px; }
.row.end { justify-content: flex-end; }

/* ---------- footer */
#footer { padding-top: 12px; padding-bottom: 32px; display: grid; gap: 10px; justify-items: center; text-align: center; border-top: 1px solid var(--line); }
.lang { display: flex; gap: 4px; }
.support { margin: 6px 0 0; text-wrap: balance; }
.support .cup { width: 18px; height: 18px; vertical-align: -3px; margin-right: 6px; color: var(--muted); }
.support a { white-space: nowrap; }
.foot-links { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.rank-controls .select.compact { min-width: 0; }
.lang button { border: 0; background: none; padding: 4px 8px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.lang [aria-pressed=true] { background: var(--surface-2); color: var(--text); font-weight: 600; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0;
  transition: 0.2s; pointer-events: none; z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- card actions, collapse, trash */
.card-actions { display: flex; gap: 2px; align-items: start; flex: none; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 9px;
  background: none; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn[data-remove]:hover { color: var(--warn); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn[data-collapse] svg { transition: transform 0.15s; }
.icon-btn[aria-expanded=false] svg { transform: rotate(-90deg); }
.card.collapsed { gap: 4px; padding-bottom: 12px; }
.card.collapsed .card-head p { display: none; }
.deck-tools { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: -6px 0 10px; }
.muted-link { color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.muted-link svg { width: 16px; height: 16px; }
.btn.danger { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn svg { width: 16px; height: 16px; }
.empty .muted-link { margin-top: 8px; }
#toast { display: flex; align-items: center; gap: 14px; pointer-events: none; }
#toast.show { pointer-events: auto; }
#toast button { background: none; border: 0; color: var(--accent-soft); font-weight: 700; cursor: pointer; padding: 4px 2px; text-decoration: underline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #toast button { color: var(--accent); }
}
:root[data-theme="dark"] #toast button { color: var(--accent); }
#toast { width: max-content; max-width: calc(100vw - 32px); }
.hits li > span.row { display: flex; flex: none; }

.version { font-size: 11px; color: var(--muted); opacity: 0.8; margin-top: -4px; font-variant-numeric: tabular-nums; }

/* ---------- sorting and drag */
.deck { align-items: start; }
.deck-tools-left { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.deck-tools .select select { min-height: 36px; font-size: 14px; width: auto; }
.drag-hint { margin: -4px 0 10px; }
.drag-handle { cursor: grab; touch-action: none; }
.drag-handle:active { cursor: grabbing; }
.card.dragging { opacity: 0.65; outline: 2px dashed var(--accent); outline-offset: 2px; }
body:has(.card.dragging) { user-select: none; -webkit-user-select: none; }
.deck-tools { align-items: flex-start; }
.deck-tools > .muted-link { min-height: 36px; }

/* ---------- v0.8: best events, improvement, meets, seasons, compare */
.chip { display: grid; gap: 1px; padding: 6px 9px; white-space: normal; }
.chip-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.chip-meta small { color: var(--muted); }
.best-block { display: grid; }
.improve { display: grid; gap: 1px; }
.pool { font-size: 12px; color: var(--muted); }
.sheet-tabs { margin: -4px 0 0; }
.badge.neutral { color: var(--muted); background: var(--surface-2); }
.meets { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.meet { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; }
.meet-head { display: grid; }
.meet-swims { width: 100%; border-collapse: collapse; }
.meet-swims td { padding: 5px 0; border-top: 1px solid var(--line); vertical-align: baseline; }
.meet-swims tr:first-child td { border-top: 0; }
.meet-swims td.num { padding-left: 10px; white-space: nowrap; }
.meet-swims tr.pb td:nth-child(2) b { color: var(--good); }
.tag-cell { width: 1%; }
.seasons { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seasons th { font-size: 12px; color: var(--muted); font-weight: 600; text-align: left; padding: 6px 10px; background: var(--accent-soft); }
.seasons th.num { text-align: right; }
.seasons td { padding: 6px 10px; border-top: 1px solid var(--line); }
.rank-note { margin: -6px 0 12px; }
.compare-pick { display: grid; gap: 8px; margin-bottom: 14px; }
.pick-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pick { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px; cursor: pointer; font-weight: 600; color: var(--muted); }
.pick[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pick:disabled { opacity: 0.45; cursor: default; }
.rank-controls .spacer { flex: 1; }
.table-scroll { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.compare { width: 100%; border-collapse: collapse; }
.compare th, .compare td { padding: 9px 12px; border-top: 1px solid var(--line); white-space: nowrap; }
.compare thead th { border-top: 0; font-size: 13px; color: var(--muted); font-weight: 700; text-align: left; }
.compare thead th.num { text-align: right; }
.compare tbody th { font-weight: 600; text-align: left; position: sticky; left: 0; background: var(--surface); }
.compare td small { display: block; font-size: 11px; color: var(--muted); }
.compare td.fastest b { color: var(--good); }
.compare td.fastest { background: var(--good-soft); }
.chip { justify-content: stretch; }
.events td small { white-space: nowrap; }

/* ---------- qualifying times */
.q { display: inline-flex; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 99px; white-space: nowrap; vertical-align: 1px; }
.q-smA { background: #f4d47a; color: #4a3500; }
.q-smB { background: #dfe4ea; color: #2d3a48; }
.q-usm { background: #cfe3ff; color: #0b3f86; }
.q-paraA { background: #e3d4ff; color: #3d1d82; }
.q-paraB { background: #efe6ff; color: #4d3485; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .q-smA { background: #6b5317; color: #ffe39a; }
  :root:not([data-theme="light"]) .q-smB { background: #3a4757; color: #e3e9f0; }
  :root:not([data-theme="light"]) .q-usm { background: #173c6b; color: #bcd9ff; }
  :root:not([data-theme="light"]) .q-paraA { background: #3d2a6b; color: #ddd0ff; }
  :root:not([data-theme="light"]) .q-paraB { background: #33284f; color: #d2c6f0; }
}
:root[data-theme="dark"] .q-smA { background: #6b5317; color: #ffe39a; }
:root[data-theme="dark"] .q-smB { background: #3a4757; color: #e3e9f0; }
:root[data-theme="dark"] .q-usm { background: #173c6b; color: #bcd9ff; }
:root[data-theme="dark"] .q-paraA { background: #3d2a6b; color: #ddd0ff; }
:root[data-theme="dark"] .q-paraB { background: #33284f; color: #d2c6f0; }
.qual-block { display: grid; gap: 4px; }
.qchips { display: flex; flex-wrap: wrap; gap: 6px; }
.qchips .q { font-size: 12px; padding: 3px 9px; }
.qchips .q b { font-weight: 800; }
.events td .q { margin-left: 2px; }
.qnext { display: block; font-size: 11px; color: var(--muted); font-weight: 400; margin: 2px 0 0 14px; }
.para-set { border-top: 1px solid var(--line); padding-top: 10px; }
.para-set summary { cursor: pointer; font-weight: 600; }
.para-set .row { flex-wrap: wrap; margin-top: 6px; }
.para-set .select { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.qual-controls { flex-wrap: wrap; align-items: center; }
.qual-table td.who-cell { white-space: normal; min-width: 180px; }
.small-pick { font-size: 12px; padding: 3px 9px; margin: 2px 4px 2px 0; display: inline-flex; gap: 6px; align-items: center; }
.qual-source { margin-top: 12px; display: grid; gap: 4px; }
.tabs { overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs [role=tab] { flex: none; white-space: nowrap; }
@media (max-width: 520px) { .tabs [role=tab] { padding: 10px 9px; } }

.rank-box:empty { display: none; }
.rank-line { display: grid; gap: 1px; min-height: 56px; align-content: center; background: var(--surface); border-radius: 10px; padding: 8px 12px; border-left: 3px solid var(--accent); }
.rank-num { font-weight: 800; font-size: 16px; }

/* ---------- profile, form, prognosis, head to head */
.profile { display: grid; grid-template-columns: minmax(180px, 240px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 560px) { .profile { grid-template-columns: 1fr; } .profile-radar { max-width: 260px; margin: 0 auto; } }
.radar { width: 100%; height: auto; overflow: visible; }
.radar-ring { fill: none; stroke: var(--line); stroke-width: 1; }
.radar-area { fill: var(--accent); fill-opacity: 0.22; stroke: var(--accent); stroke-width: 2; }
.radar-label { font-size: 10px; fill: var(--muted); }
.profile-facts { display: grid; gap: 10px; }
.bars { display: grid; gap: 5px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 36px; gap: 8px; align-items: center; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.form-head { display: grid; gap: 2px; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); border-left: 3px solid var(--muted); }
.form-top, .form-good { border-left-color: var(--good); }
.form-top b, .form-good b { color: var(--good); }
.form-low { border-left-color: var(--warn); }
.form-list li { grid-template-columns: 78px 1fr auto 64px; }
.prog { margin: 0; padding: 6px 12px; background: var(--surface); border-radius: 10px; }
.h2h { margin-top: 18px; display: grid; gap: 8px; }
.h2h-hint { margin-top: 12px; }
.h2h-score { display: flex; gap: 10px; align-items: baseline; font-size: 20px; margin-bottom: 8px; }
.h2h-race { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; background: var(--surface); border-radius: 10px; padding: 8px 12px; }
.h2h-race > span:first-child { grid-column: 1 / -1; }

.nowrap, .pool { white-space: nowrap; }
.form-list li { grid-template-columns: 62px 1fr auto 58px; }

/* ---------- sync */
.sync-pill { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); background: var(--surface); color: var(--good); border-radius: 99px; padding: 3px 10px; font-size: 12px; font-weight: 700; cursor: pointer; margin-right: 8px; flex: none; }
.sync-pill.bad { color: var(--warn); }
.sync-pill svg { width: 14px; height: 14px; }
.sync-sheet { gap: 12px; }
.qr { width: 180px; margin: 0 auto; background: #fff; padding: 6px; border-radius: 10px; }
.qr:empty { display: none; }
.qr svg { width: 100%; height: auto; display: block; }
.sync-link { flex: 1; min-width: 0; min-height: 36px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); padding: 0 10px; font-size: 12px; }
.row.wrap { flex-wrap: wrap; gap: 6px 16px; }
@media (max-width: 640px) { .hide-sm { display: none; } }
.dialog:has(.small-sheet) { width: min(460px, calc(100vw - 32px)); }
.small-sheet { max-width: none; }
@media (max-width: 640px) { .dialog:has(.small-sheet) { width: 100vw; } }

.fields .check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.fields .check input { width: 18px; height: 18px; }
.hits-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.hits + .more { margin-top: 8px; }

/* ---------- new since last visit */
.card.has-new { border-color: var(--good); box-shadow: 0 0 0 1px var(--good), var(--shadow); }
.new-tag { display: inline-block; font-size: 11px; font-weight: 800; color: #fff; background: var(--good); border-radius: 99px; padding: 2px 8px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .new-tag { color: #06121f; }
}
:root[data-theme="dark"] .new-tag { color: #06121f; }
.new-block { display: grid; gap: 3px; background: var(--good-soft); border-radius: 10px; padding: 8px 10px; }
.new-banner { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--good-soft); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-weight: 600; }
.new-block .new-tag { justify-self: start; }

/* ---------- personal goals */
.goal-edit { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; background: var(--surface); border-radius: 10px; padding: 6px 10px; }
.goal-edit label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; }
.goal-edit input { min-height: 34px; width: 120px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 8px; font-variant-numeric: tabular-nums; }
.goal-status { align-self: center; }
.goal-ok { color: var(--good); font-weight: 700; }
.gbadge { display: inline-flex; font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--text); white-space: nowrap; vertical-align: 1px; }
.gbadge.ok { background: var(--good-soft); color: var(--good); }
.goal-card { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.goal-card .gbadge { font-size: 12px; padding: 3px 9px; }
.chart .goal-line { stroke: var(--good); stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart .goal-label { fill: var(--good); font-weight: 700; }

.detail-tools { gap: 8px; }
.top.recent li { grid-template-columns: 4px 96px 1fr auto; }
.top .time.is-pb { color: var(--accent); }
.top .time small { font-weight: 500; font-size: 11px; }

/* ---------- import from list */
.import-cta { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.import-sheet textarea { width: 100%; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); padding: 10px; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); resize: vertical; }
.import-tools { align-items: center; }
.import-list { max-height: 55dvh; overflow: auto; display: grid; gap: 10px; }
.igroup { display: grid; gap: 4px; background: var(--surface-2); border-radius: 12px; padding: 8px 10px; }
.igroup-head { display: flex; gap: 8px; align-items: center; padding: 2px 0 4px; border-bottom: 1px solid var(--line); }
.irow { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; padding: 4px 0; cursor: pointer; }
.irow.off { opacity: 0.7; cursor: default; }
.iname { display: grid; }
.iright { text-align: right; }
.ok-match { color: var(--good); }
.ipick { max-width: 220px; min-height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.import-foot { position: sticky; bottom: 0; background: var(--surface); padding-top: 8px; border-top: 1px solid var(--line); }
.row.wrap { flex-wrap: wrap; }

.parts { display: grid; gap: 8px; }
.parts .check { display: flex; gap: 8px; align-items: center; }
.deck-tools-left { row-gap: 6px; }

/* meet result lists */
.meet-link { all: unset; cursor: pointer; color: inherit; border-bottom: 1px dotted var(--muted); }
.meet-link:hover, .meet-link:focus-visible { color: var(--accent); border-bottom-color: var(--accent); }
.meet-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.meet-link.strong { font-weight: 600; justify-self: start; }
.meet-link.plain { border-bottom-color: transparent; }
.meet-link.plain:hover { border-bottom-color: var(--accent); }
.top li .meet-link { color: var(--muted); }
.meet-me { margin: 0; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); }
.meet-list { width: 100%; border-collapse: collapse; }
.meet-list td { padding: 6px 0; border-top: 1px solid var(--line); vertical-align: baseline; }
.meet-list tr:first-child td { border-top: 0; }
.meet-list td small { display: block; }
.meet-list td.num { white-space: nowrap; text-align: right; padding-left: 10px; }
.meet-list td.place { width: 2.2em; text-align: left; padding-left: 0; color: var(--muted); }
.meet-list tr.mine td:nth-child(2) { font-weight: 600; }
.meet-list tr.me td { color: var(--accent); font-weight: 600; }

/* home button */
button.brand { all: unset; display: flex; align-items: center; gap: 10px; cursor: pointer; border-radius: 10px; }
button.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

/* help boxes */
.help { margin: 0 0 12px; font-size: 14px; }
.help summary { cursor: pointer; color: var(--muted); list-style: none; display: inline-flex; align-items: center; gap: 6px; }
.help summary::-webkit-details-marker { display: none; }
.help-i { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid currentColor; font: italic 600 12px/1 Georgia, serif; }
.help[open] summary { color: var(--text, inherit); }
.help-body { margin-top: 8px; padding: 10px 12px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.help-body p { margin: 0 0 6px; line-height: 1.45; }
.help-body p:last-child { margin: 0; }

/* about */
.about section h3 { font-size: 15px; margin: 4px 0 4px; }
.about section p { margin: 0 0 6px; line-height: 1.45; }
.glossary { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; }
.glossary dt { font-weight: 600; }
.glossary dd { margin: 0; }
@media (max-width: 560px) { .glossary { grid-template-columns: 1fr; gap: 0; } .glossary dd { margin-bottom: 8px; } }

/* toplist with both pools */
.rank-both tbody tr { cursor: pointer; }
.rank-both td small { display: block; }
.rank-both .pos { width: 2em; color: var(--muted); }
.rank-both tbody tr:first-child .pos { color: var(--accent); }
.sort-head { all: unset; cursor: pointer; display: inline-grid; justify-items: end; text-align: right; font-weight: 600; }
.sort-head small { font-weight: 400; color: var(--muted); }
.sort-head[aria-pressed="true"] { color: var(--accent); }
.sort-head:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* qualifying overview */
.qual-done { display: grid; gap: 12px; }
.qual-done.packed { display: flex; align-items: flex-start; }
.qual-col { flex: 1 1 0; min-width: 0; display: grid; gap: 12px; align-content: start; }
.qd-card { min-width: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; display: grid; gap: 8px; align-content: start; }
.qd-name { all: unset; cursor: pointer; }
.qd-name:hover b { color: var(--accent); }
.qd-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.qd-table td { padding: 5px 0; border-top: 1px solid var(--line); vertical-align: baseline; }
.qd-table tr:first-child td { border-top: 0; }
.qd-table td.num { padding: 5px 10px; white-space: nowrap; text-align: right; }
.qd-badges { text-align: right; }
.rank-both td:nth-child(2) { white-space: normal; }
@media (max-width: 560px) {
  .rank-both th, .rank-both td { padding: 8px 4px; }
  .rank-both .pos { padding-left: 10px; width: 1.4em; }
  .sort-head small { display: none; }
}
.qd-table thead th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 0 2px; text-transform: uppercase; letter-spacing: 0.04em; }
.qd-table tbody tr:first-child td { border-top: 0; }
.rank-both thead th.num { text-align: right; }
.rank-both th.num, .rank-both td.num { width: 7.5em; }
.qd-table thead th.num { text-transform: none; letter-spacing: 0; text-align: right; padding-left: 10px; padding-right: 10px; }
.qd-table td small { display: block; font-size: 11px; }
.qd-badges { white-space: nowrap; }
.qd-std { display: flex; justify-content: flex-end; align-items: center; gap: 8px; line-height: 1.8; }
.qd-std .q { min-width: 5em; justify-content: center; }
.qd-lim { min-width: 4.4em; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.qd-next-row td { border-top: 0 !important; padding: 0 0 6px !important; text-align: right; }
.qd-next { font-size: 12px; color: var(--muted); }
.qd-table tr:has(+ .qd-next-row) td { padding-bottom: 1px; }
.qd-near thead th.qd-pool { color: var(--accent); }
.qd-table thead th.qd-pool { white-space: nowrap; }
.card-head .remove-btn, .remove-btn { margin-right: 10px; opacity: 0.7; }
.remove-btn:hover { opacity: 1; color: var(--warn); }
.near-pick { border-style: dashed; background: transparent; }
.near-pick .muted { font-size: 11px; }
.near-txt { font-size: 11px; font-weight: 600; }
.rank-both td { vertical-align: top; }
.rank-both td.num b { line-height: 22px; }
.rank-both td.gapc, .rank-both th.gapc { width: 3.6em; padding-left: 4px; text-align: left; font-size: 12px; line-height: 22px; font-variant-numeric: tabular-nums; }
.rank-both td small { font-size: 11px; }
@media (max-width: 560px) {
  .rank-both td.gapc, .rank-both th.gapc { width: 3.2em; padding-left: 2px; padding-right: 6px; font-size: 11px; }
  .rank-both .club-part { display: none; }
  .rank-both td:nth-child(2) b { font-size: 14px; }
  .rank-both th.num, .rank-both td.num { width: auto; padding-right: 4px; }
  .rank-both td small { font-size: 10px; }
}

/* import from a meet */
.meet-pick { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 50dvh; overflow: auto; }
.meet-pick button { all: unset; box-sizing: border-box; width: 100%; cursor: pointer; display: grid; gap: 2px; padding: 9px 12px; border-radius: 10px; background: var(--surface-2); }
.meet-pick button:hover, .meet-pick button:focus-visible { outline: 2px solid var(--accent); }
#meetSearchForm input { flex: 1; min-width: 0; }
.period-sheet { display: inline-flex; align-items: center; gap: 8px; }
.period-sheet select { max-width: 100%; width: auto; padding-right: 32px; }

.theme { display: inline-flex; gap: 2px; }
.bulk-all { padding: 4px 2px; }
.bulk-list { max-height: 55dvh; overflow: auto; }
.who-cell .who-item { display: flex; flex-direction: column; align-items: flex-start; margin: 2px 0 6px; }
.who-cell .who-item .small-pick { margin: 0; }
.who-cell .who-item .qd-next { margin: 2px 0 0 4px; white-space: nowrap; }
/* keep the first column's heading in place when a wide table scrolls sideways, like the row headings */
.compare:not(.rank-both) thead th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 2; }
.compare:not(.rank-both) tbody th { z-index: 1; }
/* while a dialog is open the page behind it stays still (no scroll chaining on phones) */
html:has(dialog[open]), body:has(dialog[open]) { overflow: hidden; }
.dialog, .import-list, .meet-pick, .bulk-list { overscroll-behavior: contain; }
/* wide tables scroll sideways only: keep that sideways, but let up/down scrolling reach the page */
.table-scroll { overscroll-behavior-x: contain; overscroll-behavior-y: auto; }

/* "compare with" pill and its menu */
.metric-wrap { position: relative; display: inline-block; }
.metric-pill { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 2px; padding: 2px 9px; border: 1px solid var(--line); border-radius: 99px; font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; background: var(--surface); }
.metric-pill:hover, .metric-pill[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
.metric-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.metric-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 240px; display: grid; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 28px rgb(0 0 0 / 18%); text-align: left; }
.metric-menu button { all: unset; cursor: pointer; display: grid; grid-template-columns: 16px auto 1fr; gap: 6px; align-items: baseline; padding: 8px 10px; border-radius: 8px; font-size: 14px; white-space: normal; }
.metric-menu button:hover, .metric-menu button:focus-visible { background: var(--surface-2); }
.metric-menu button[aria-checked="true"] b { color: var(--accent); }
.mm-check { color: var(--accent); font-weight: 700; }
.metric-row { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-left: auto; }
.events th.metric-th { text-align: right; }
.events td.metric-td { font-size: 13px; color: var(--muted); white-space: nowrap; }
@media (max-width: 560px) {
  .metric-pill { padding: 2px 7px; font-size: 11px; }
  .events td.metric-td { font-size: 12px; }
}
.mm-note { display: block; padding: 6px 10px 4px; border-top: 1px solid var(--line); margin-top: 2px; line-height: 1.4; }
.near-control { display: inline-flex; align-items: center; gap: 6px; }
.metric-menu { min-width: 220px; }
.qual-table th .metric-wrap { margin-left: 4px; }
.near-control .metric-menu { left: 0; right: auto; }

/* latest meet on the cards */
.recent-meet { display: grid; gap: 4px; }
.rm-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.rm-swims { display: grid; gap: 2px; }
.rm-swim { display: flex; gap: 6px; align-items: baseline; font-size: 14px; }
.rm-swim > span:first-child { min-width: 7.5em; }
.rm-swim .badge { font-size: 10px; }
.para-suggest { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.para-suggest p { grid-column: 1 / -1; margin: 0; }
.para-lookup { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 8px; }
.import-para { display: flex; gap: 6px; align-items: center; margin: 4px 0; }
.iname .q { margin-left: 4px; vertical-align: 1px; }
.compare-best th, .compare-best td { border-top: 2px solid var(--line); }
.rank-controls .near-control .metric-menu { left: 0; right: auto; }

/* ---------- the open event: its row stays at the top while its details scroll under it */
.events tr.ev.open td { position: sticky; top: 0; z-index: 4; background: var(--accent-soft); box-shadow: 0 1px 0 var(--line); }
.events tr.ev.open td:first-child { box-shadow: inset 3px 0 0 var(--accent), 0 1px 0 var(--line); color: var(--accent); font-weight: 600; }
.events > tbody > tr.detail > td { box-shadow: inset 3px 0 0 var(--accent); }
.event-detail { gap: 8px; }
.top-legend { margin: -2px 0 0; }

/* ---------- row highlight under the mouse, in every list and table (not on touch screens, where it would stick) */
:root { --hover: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
@media (hover: hover) {
  .events tr.ev:not(.open):hover td,
  .top li:hover,
  .seasons tbody tr:hover td,
  .meet-swims tr:hover td,
  .meet-list tr:hover td,
  .qd-table tbody tr:hover td,
  .compare tbody tr:hover td, .compare tbody tr:hover th,
  .ranking li:hover,
  .hits li:hover { background: var(--hover); }
  .compare tbody tr:hover td.fastest { background: color-mix(in srgb, var(--good) 22%, var(--surface)); }
}
.more-row { margin-top: 14px; }
/* larger screens: the difference to the PB on the same line as the time */
@media (min-width: 600px) {
  #eventDetail .top li { grid-template-columns: 24px 128px 1fr auto; }
  #eventDetail .top.recent li { grid-template-columns: 4px 128px 1fr auto; }
  #eventDetail .top .time { white-space: nowrap; }
  #eventDetail .top .time small { display: inline; margin-left: 4px; }
}

/* ---------- the logo's wave flows and the swimmer bobs while data is loading */
@keyframes logo-flow { to { transform: translateX(-20%); } }
@keyframes logo-bob { 50% { transform: translateY(55%); } }
@media (prefers-reduced-motion: no-preference) {
  html.loading .logo-wave { will-change: transform; animation: logo-flow 1.1s linear infinite; }
  html.loading .logo-head { will-change: transform; animation: logo-bob 1.1s ease-in-out infinite; }
}

/* ---------- event names: the arrow hangs in the margin, so a name on two lines stays aligned */
.events td.ev-name { position: relative; padding-left: 24px; }
.events td.ev-name .chev { position: absolute; left: 6px; }
.seg[hidden] { display: none; }

/* ---------- top list: no wider than it is easy to read across */
.ranking, .table-scroll:has(> .rank-both) { max-width: 860px; }
.row.end:has(+ .ranking), .row.end:has(+ .table-scroll > .rank-both) { max-width: 860px; }

/* ---------- phones: a lower header, and the tools above the cards on tidy rows */
.add-short { display: none; }
@media (max-width: 720px) {
  #header { grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px 8px; padding-top: 14px; }
  #header > .brand, #header > .tabs { min-width: 0; }
  .brand .tagline { overflow-wrap: anywhere; line-height: 1.25; }
  .toolbar { display: contents; }
  .toolbar #refresh { grid-column: 2; grid-row: 1; padding: 0 12px; }
  .toolbar #refresh span { display: none; }
  .toolbar #add { grid-column: 3; grid-row: 1; }
  .add-long { display: none; }
  .add-short { display: inline; }
  .toolbar .select { grid-column: 1 / -1; grid-row: 2; }
}
/* too narrow for the title and both buttons on one row: title on its own row, buttons below */
@media (max-width: 355px) {
  #header > .brand { grid-column: 1 / -1; grid-row: 1; }
  .toolbar #add { grid-column: 1; grid-row: 2; }
  .toolbar #refresh { grid-column: 2 / 4; grid-row: 2; }
  .toolbar .select { grid-row: 3; }
}
@media (max-width: 560px) {
  .deck-tools { flex-wrap: wrap; gap: 2px 14px; align-items: center; }
  .deck-tools-left { display: contents; }
  .deck-tools .select { flex: 1 1 55%; min-width: 0; order: 1; }
  .deck-tools .select select { width: 100%; }
  .deck-tools > .muted-link { order: 2; flex: none; }
  .deck-tools-left > button.link { order: 3; min-height: 36px; font-size: 14px; }
  .events th, .events td { padding-left: 5px; padding-right: 5px; }
  .events td.ev-name { padding-left: 22px; }
}

/* qualifying overview on narrow screens: the table must fit inside its card */
@media (max-width: 520px) {
  .qd-badges { white-space: normal; }
  .qd-table thead th.qd-pool { white-space: normal; }
}
@media (max-width: 340px) {
  .qd-std { flex-wrap: wrap; gap: 2px 6px; }
}
/* the pill and the limit stack when the card is narrow for its text size (larger text needs a wider card) */
.qd-card { container-type: inline-size; }
@container (max-width: 20em) {
  .qd-std { flex-wrap: wrap; gap: 2px 6px; }
}
@media (max-width: 400px) {
  .qd-card { padding: 12px 10px; }
  .qd-table { font-size: 13px; }
  .qd-table td.num { padding: 5px 0 5px 8px; }
  .qd-table thead th.num { padding-left: 8px; padding-right: 0; }
  .qd-table thead th { letter-spacing: 0; }
  .qd-lim { font-size: 12px; }
}
