/* Swapdeck design system.
   Spacing: 8px base (4 for hairline gaps). Radii: 6px controls, 10px panels. One elevation (popovers/dialogs).
   Type scale: 12 / 13 / 15 / 18 / 24 / 32 / 44 and nothing in between. The condensed display face needs
   `font-stretch: 87%`; a `font:` shorthand resets it, so every rule that sets `font: … var(--display)` re-declares it
   (or use the `.display` utility).

   Colour carries meaning only:
   - Signal yellow: the primary action, the current item (active nav/tab, selected row or option) and the progress of a
     running swap. Nothing else. Where yellow is the only cue on a light surface it is paired with an ink edge.
   - Ink / neutral (sunken): counts, tags, the Low grade, priority stars, avatar rings, warnings without a number.
   - Note blue: information.
   - Green / red: performance (a number went up or down, a grade) and status (success / danger). */

:root {
  --paper: #edf1f2;
  --surface: #fbfcfc;
  --sunken: #e2e8ea;
  --ink: #10262e;
  --ink-2: #48606a;
  --ink-3: #566b73;
  --line: #cbd5d8;
  --line-strong: #73868d;
  --signal: #f2b90f;
  --signal-ink: #1c1a05;
  --signal-soft: #fbeeba;
  --good: #17714a;
  --good-soft: #dcefe5;
  --bad: #b03a27;
  --bad-soft: #f6dfda;
  --note: #2f6f8f;
  --note-soft: #dcebf1;
  --focus: #0b6bcb;
  --focus-on-dark: #6cb6ff;
  --on-good: #ffffff;
  --on-bad: #ffffff;
  --bar: #10262e;
  --bar-ink: #e8eff1;
  --bar-ink-2: #b5c5ca;
  --bar-chip: #2b4650;

  --r1: 6px;
  --r2: 10px;
  --s1: 4px;
  --s2: 8px;
  --s3: 16px;
  --s4: 24px;
  --s5: 32px;
  --s6: 48px;
  --s7: 64px;

  --content: 1180px;
  --control-h: 36px;

  --display: "Bahnschrift", "DIN Alternate", "Avenir Next Condensed", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --pop: 0 12px 32px rgba(16, 38, 46, 0.18);
  --bar-h: 56px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #0c1c22;
  --surface: #13272f;
  --sunken: #0a161b;
  --ink: #e8eff1;
  --ink-2: #a9bcc2;
  --ink-3: #8fa4ab;
  --line: #264049;
  --line-strong: #56767f;
  --signal: #f2b90f;
  --signal-ink: #1c1a05;
  --signal-soft: #3a3210;
  --good: #46b983;
  --good-soft: #15382b;
  --bad: #e8735e;
  --bad-soft: #43201a;
  --note: #6db3d4;
  --note-soft: #153441;
  --focus: #6cb6ff;
  --on-good: #06231a;
  --on-bad: #2a0b06;
  --bar: #071318;
  --pop: 0 12px 32px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--line-strong) transparent; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--body);
  font-variant-numeric: tabular-nums;
  min-height: 100vh;
}

body.has-modal { overflow: hidden; }

h1, h2, h3, h4 {
  font-family: var(--display);
  font-stretch: 87%;
  font-weight: 600;
  line-height: 1.15;
  margin: 0;
  letter-spacing: 0.005em;
}
h1 { font-size: 32px; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }
h4 { font-size: 15px; }

p { margin: 0 0 var(--s3); max-width: 70ch; }
p:last-child { margin-bottom: 0; }

a { color: inherit; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }

img { max-width: 100%; display: block; }

.icon { flex: none; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.display, .num { font-family: var(--display); font-stretch: 87%; font-weight: 600; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1 1 auto; min-width: 0; }
.hidden, [hidden] { display: none !important; }

/* Visually hidden, still read by screen readers. Needs a positioned ancestor inside scroll containers (see .table-wrap). */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
/* Skip links become visible when focused. */
a.sr-only:focus, button.sr-only:focus {
  position: fixed;
  top: var(--s2);
  left: var(--s2);
  z-index: 300;
  width: auto;
  height: auto;
  margin: 0;
  padding: var(--s2) 12px;
  clip: auto;
  clip-path: none;
  white-space: normal;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--ink);
  border-radius: var(--r1);
  font-weight: 600;
  text-decoration: none;
}
/* A visually hidden file input or checkbox hands its focus ring to the label that stands in for it. */
input.sr-only:focus-visible + label,
input.sr-only:focus-visible + .btn,
label.btn:focus-within,
label.icon-btn:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r1); }
/* Containers that only receive focus from scripts (page outlet, dialogs, re-rendered regions) show no ring. */
[tabindex="-1"]:focus { outline: none; }
/* The default ring is too dark on the ink-coloured bars. */
.topbar :focus-visible, .auth-side :focus-visible, .site-head :focus-visible, .hero :focus-visible { outline-color: var(--focus-on-dark); }

.row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.stack-sm { display: flex; flex-direction: column; gap: var(--s2); }
.grid { display: grid; gap: var(--s3); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

/* ---------- Top bar ---------- */

/* The bar's content shares the page column: same max width and the same gutters as .page. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--bar-h);
  background: var(--bar);
  color: var(--bar-ink);
  display: flex;
  align-items: stretch;
  padding: 0 max(var(--s3), calc((100% - var(--content)) / 2 + var(--s4)));
  gap: var(--s3);
}
:root[data-theme="dark"] .topbar { border-bottom: 1px solid var(--line); }

.brand {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font: 600 18px/1 var(--display);
  font-stretch: 87%;
  text-decoration: none;
  color: inherit;
  padding-right: var(--s2);
}
.brand-mark { width: 26px; height: 26px; }

.nav { display: flex; align-items: stretch; gap: 2px; flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  color: var(--bar-ink-2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  border-top: 3px solid transparent;
}
/* Nine labelled destinations fit the content column without their icons; the icons stay in the mobile tab bar. */
.nav a .icon { display: none; }
.nav a:hover { color: #fff; }
.nav a[aria-current="page"] { color: #fff; border-bottom-color: var(--signal); }
.nav a:focus-visible { outline-offset: -3px; }

/* Counts are ink on neutral with an ink edge; yellow is reserved (see the rule at the top). */
.count {
  flex: none;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--ink);
  border-radius: var(--r2);
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.topbar .count { background: var(--bar-ink); border-color: var(--bar-ink); color: #10262e; }

.topbar-tools { display: flex; align-items: center; gap: var(--s1); }
.topbar .icon-btn { color: var(--bar-ink-2); }
.topbar .icon-btn:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.topbar .avatar { background: var(--bar-chip); color: var(--bar-ink); }
.user-btn {
  display: flex;
  align-items: center;
  gap: var(--s2);
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 4px 6px;
  border-radius: var(--r1);
  cursor: pointer;
  max-width: 220px;
}
.user-btn:hover { background: rgba(255, 255, 255, 0.1); }
.user-btn span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tabbar { display: none; }

/* ---------- Page scaffold ---------- */

/* One content column. Every page title starts on the same left edge:
   .page-narrow keeps the column and narrows its children; .page-wide (tables that need the room) keeps the left edge
   and grows to the right only. */
.outlet { min-height: calc(100vh - var(--bar-h)); }
.page { max-width: var(--content); margin: 0 auto; padding: var(--s5) var(--s4) var(--s7); }
.page-wide { max-width: 1440px; margin-left: max(0px, calc((100% - var(--content)) / 2)); margin-right: 0; }
.page-narrow > * { max-width: 760px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s4); }
.page-sub { color: var(--ink-2); margin: var(--s1) 0 0; }
.page-actions { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }
.page-body { display: flex; flex-direction: column; gap: var(--s4); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 4px; min-height: 24px; color: var(--ink-2); text-decoration: none; font-size: 13px; margin-bottom: var(--s3); }
.back-link:hover { color: var(--ink); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r2); padding: var(--s4); }
.panel-flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-pad { padding: var(--s4); }
.divider { height: 1px; background: var(--line); border: 0; margin: var(--s3) 0; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r1);
  background: var(--surface);
  color: var(--ink);
  font: 600 13px/1 var(--body);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  position: relative;
}
.btn:hover:not(:disabled) { border-color: var(--ink); }
/* Disabled is a flat neutral, not a faded copy: faded yellow dropped below readable contrast. */
.btn:disabled { cursor: not-allowed; }
.btn:disabled:not(.is-busy) { background: var(--sunken); border-color: var(--line); color: var(--ink-2); }
.btn-primary { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.btn-primary:hover:not(:disabled) { border-color: var(--signal-ink); }
:root[data-theme="dark"] .btn-primary:hover:not(:disabled) { border-color: #fff; }
.btn-solid { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-danger:hover:not(:disabled) { background: var(--bad); border-color: var(--bad); color: var(--on-bad); }
.btn-good { color: var(--good); border-color: var(--good); }
.btn-good:hover:not(:disabled) { background: var(--good); border-color: var(--good); color: var(--on-good); }
.btn-ghost { border-color: transparent; background: none; }
.btn-ghost:hover:not(:disabled) { background: var(--sunken); border-color: transparent; }
.btn-ghost:disabled:not(.is-busy) { background: none; border-color: transparent; }
.btn-sm { height: 30px; padding: 0 10px; }
.btn-block { width: 100%; }
.btn.is-busy { color: transparent !important; cursor: progress; }
.btn.is-busy::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid var(--ink-3);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn-primary.is-busy::after { border-color: var(--signal-ink); border-top-color: transparent; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--r1);
  background: none;
  color: var(--ink-2);
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--sunken); color: var(--ink); }
.icon-btn:disabled { color: var(--ink-3); cursor: not-allowed; }
/* "On" toggles (priority star and the like) are ink, filled; never yellow. */
.icon-btn.is-on { color: var(--ink); }
.icon-btn.is-danger:hover:not(:disabled) { color: var(--bad); }
.link-btn { background: none; border: 0; padding: 0; min-height: 24px; font: inherit; color: inherit; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; cursor: pointer; }
.link-btn:hover { text-decoration-color: currentColor; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-size: 13px; font-weight: 600; color: var(--ink); }
.help { font-size: 13px; color: var(--ink-2); margin: 0; display: block; }
.input, textarea.input, select.input {
  width: 100%;
  height: var(--control-h);
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r1);
  background: var(--surface);
  color: var(--ink);
  font: 15px/1.4 var(--body);
}
textarea.input { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; scrollbar-width: thin; }
.input::placeholder { color: var(--ink-3); opacity: 1; }
.input:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.input[aria-invalid="true"] { border-color: var(--bad); border-width: 2px; }
.field-error { color: var(--bad); font-size: 13px; font-weight: 500; margin: 0; }
.search { position: relative; }
.search .icon { position: absolute; left: 10px; top: 9px; color: var(--ink-3); pointer-events: none; }
.search .input { padding-left: 34px; }

input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--ink); }
:root[data-theme="dark"] input[type="checkbox"], :root[data-theme="dark"] input[type="radio"] { accent-color: var(--signal); }
.check { display: flex; align-items: flex-start; gap: 10px; min-height: 24px; cursor: pointer; }
.check input { margin: 2px 0 0; flex: none; }
.check-label { display: block; font-weight: 500; }
.form { display: flex; flex-direction: column; gap: var(--s3); }
.form-actions { display: flex; gap: var(--s2); justify-content: flex-end; flex-wrap: wrap; }

.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r1); overflow: hidden; background: var(--surface); }
.segmented button { border: 0; background: none; color: var(--ink-2); font: 600 13px/1 var(--body); padding: 0 12px; height: 30px; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--line-strong); }
.segmented button.is-active { background: var(--ink); color: var(--paper); }
.segmented button:focus-visible { outline-offset: -2px; }

/* ---------- Chips, badges ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r1);
  background: var(--surface);
  color: var(--ink);
  font: 500 13px/1 var(--body);
  white-space: nowrap;
}
button.chip { cursor: pointer; }
button.chip:hover { border-color: var(--ink); }
.chip.is-active { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip.is-partial { border-style: dashed; border-color: var(--ink); }
.chip.is-mine { border-color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); }
.chip-count { font-size: 12px; color: var(--ink-3); }
.chip.is-active .chip-count { color: inherit; opacity: 0.75; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--r1);
  font-size: 12px;
  font-weight: 600;
  background: var(--sunken);
  color: var(--ink-2);
  white-space: nowrap;
}
/* Kept for the modules that still ask for it: an emphasised tag is ink, not yellow. */
.tag-signal, .tag-ink { background: var(--ink); color: var(--paper); }
.tag-good { background: var(--good-soft); color: var(--good); }
.tag-bad { background: var(--bad-soft); color: var(--bad); }
.tag-note { background: var(--note-soft); color: var(--note); }
.tag-outline { background: none; border: 1px solid var(--line-strong); }

.pop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 30px;
  height: 22px;
  padding: 0 6px;
  border-radius: var(--r1);
  font: 600 13px/1 var(--display);
  font-stretch: 87%;
  background: var(--sunken);
  color: var(--ink-2);
  border-left: 3px solid var(--line-strong);
}
.pop-mid { border-left-color: var(--note); color: var(--ink); }
.pop-warm { border-left-color: var(--ink); color: var(--ink); }
.pop-hot { border-left-color: var(--bad); color: var(--ink); }
.trend-up { color: var(--good); }
.trend-down { color: var(--bad); }
.trend-flat { color: var(--ink-3); }

.grade { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; border-radius: var(--r1); font: 600 13px/1 var(--display); font-stretch: 87%; letter-spacing: 0.02em; white-space: nowrap; cursor: default; }
.grade-top { background: var(--good); color: var(--on-good); }
.grade-high { background: var(--good-soft); color: var(--good); }
.grade-avg { background: var(--note-soft); color: var(--note); }
.grade-low { background: var(--sunken); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); }
.grade-stop { background: var(--bad); color: var(--on-bad); }
.grade-wait { background: var(--sunken); color: var(--ink-2); }

.verified { display: inline-flex; color: var(--note); vertical-align: -3px; margin-left: 4px; }
.user-name { font-weight: 600; }

/* ---------- Avatars, covers, tracks ---------- */

.avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--display);
  font-stretch: 87%;
  font-weight: 600;
  -webkit-user-select: none;
  user-select: none;
}
:root[data-theme="dark"] .avatar { background: var(--line-strong); color: #fff; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar-ring { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }
.avatar-dot { position: absolute; right: -1px; bottom: -1px; width: 28%; height: 28%; min-width: 8px; min-height: 8px; border-radius: 50%; background: var(--good); border: 2px solid var(--surface); }
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar + .avatar { margin-left: -8px; box-shadow: 0 0 0 2px var(--surface); }
.avatar-more { font-size: 12px; color: var(--ink-2); margin-left: 6px; align-self: center; }

.cover { display: inline-flex; align-items: center; justify-content: center; flex: none; border-radius: var(--r1); background: var(--sunken); color: var(--ink-3); overflow: hidden; }
.cover img { width: 100%; height: 100%; object-fit: cover; }

.track { display: flex; align-items: center; gap: 12px; min-width: 0; }
.track-text { display: flex; flex-direction: column; min-width: 0; }
.track-title { font-weight: 600; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.track-title:hover { text-decoration: underline; }
.track-artists { color: var(--ink-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Tables ---------- */

/* Positioned so that visually hidden header labels stay inside the scroll container instead of widening the page. */
.table-wrap { position: relative; overflow-x: auto; scrollbar-width: thin; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
  background: var(--surface);
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr.is-clickable:hover td { background: var(--sunken); }
/* --ink-3 only reaches 4.5:1 on --surface; on tinted rows the quiet text steps up to --ink-2. */
.table tbody tr.is-current td { background: var(--signal-soft); --ink-3: var(--ink-2); }
.table .col-num { width: 44px; color: var(--ink-3); text-align: right; }
.table .col-tight { width: 1%; white-space: nowrap; }
.table th.right, .table td.right { text-align: right; }
.table-sticky th { position: sticky; top: var(--bar-h); z-index: 2; }
.sort-btn { background: none; border: 0; min-height: 24px; font: inherit; color: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; padding: 0; }
.sort-btn.is-active { color: var(--ink); }

/* ---------- Stat tiles ---------- */

/* Labels reserve two lines and sit on their lower edge, so the numbers of a row share one baseline. */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border: 1px solid var(--line); border-radius: var(--r2); background: var(--surface); overflow: hidden; }
.stat { display: flex; flex-direction: column; padding: var(--s3) var(--s4); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; }
.stat-label { font-size: 13px; line-height: 1.5; color: var(--ink-2); }
.stat > .stat-label { display: flex; align-items: flex-end; min-height: 39px; }
.stat-value { font: 600 32px/1.1 var(--display); font-stretch: 87%; margin-top: 2px; }
.stat-hint { font-size: 13px; color: var(--ink-2); margin-top: 2px; }

.pills { display: flex; gap: var(--s2); flex-wrap: wrap; }
.pill { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--r1); min-width: 72px; }
.pill-label { font-size: 12px; color: var(--ink-2); }
.pill-value { font: 600 15px/1 var(--display); font-stretch: 87%; }

/* ---------- Notices, empty, loading ---------- */

.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px var(--s3); border-radius: var(--r1); background: var(--note-soft); color: var(--ink); border-left: 3px solid var(--note); font-size: 13px; }
.notice .icon { margin-top: 1px; color: var(--note); }
.notice-warn { background: var(--sunken); border-left-color: var(--ink); }
.notice-warn .icon { color: var(--ink); }
.notice-error { background: var(--bad-soft); border-left-color: var(--bad); }
.notice-error .icon { color: var(--bad); }
.notice-success { background: var(--good-soft); border-left-color: var(--good); }
.notice-success .icon { color: var(--good); }
.notice p { margin: 0 0 4px; }

.empty { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s2); padding: var(--s6) var(--s4); border: 1px dashed var(--line-strong); border-radius: var(--r2); }
.empty-icon { color: var(--ink-3); }
.empty p { color: var(--ink-2); margin: 0 0 var(--s2); }

.loading { display: flex; align-items: center; gap: 10px; color: var(--ink-2); padding: var(--s4) 0; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line-strong); border-top-color: var(--ink); border-radius: 50%; animation: spin 0.7s linear infinite; flex: none; }
.skeleton { display: flex; flex-direction: column; gap: 12px; padding: var(--s2) 0; }
.skeleton-row { height: 44px; border-radius: var(--r1); background: linear-gradient(90deg, var(--sunken) 25%, var(--line) 37%, var(--sunken) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
.skeleton-row:nth-child(3n) { width: 82%; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Dialogs, menus, toasts ---------- */

.backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(8, 20, 25, 0.62); display: flex; align-items: flex-start; justify-content: center; padding: 6vh var(--s3) var(--s3); overflow-y: auto; }
.modal { width: 100%; max-width: 560px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r2); box-shadow: var(--pop); display: flex; flex-direction: column; max-height: 88vh; }
.modal-sm { max-width: 440px; }
.modal-lg { max-width: 860px; }
.modal-xl { max-width: 1080px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: var(--s4); overflow-y: auto; display: flex; flex-direction: column; gap: var(--s3); scrollbar-width: thin; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s3) var(--s4); border-top: 1px solid var(--line); flex-wrap: wrap; }
.bullets { margin: 0; padding-left: 20px; color: var(--ink-2); }
.bullets li { margin-bottom: 4px; }

.menu { position: absolute; z-index: 120; min-width: 200px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r2); box-shadow: var(--pop); padding: 6px; display: flex; flex-direction: column; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 32px; padding: 8px 10px; border: 0; border-radius: var(--r1); background: none; color: var(--ink); font: 500 13px/1.2 var(--body); text-align: left; cursor: pointer; }
.menu button:hover:not(:disabled), .menu button:focus-visible { background: var(--sunken); }
.menu button:disabled { color: var(--ink-3); cursor: not-allowed; }
.menu button.is-danger { color: var(--bad); }

/* One permanent live region; it never blocks the page, the toasts inside it take clicks. */
.toasts { position: fixed; z-index: 200; left: 50%; bottom: var(--s4); transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--s2); align-items: center; width: min(92vw, 480px); pointer-events: none; }
.toast { display: flex; align-items: flex-start; gap: 10px; max-width: 100%; background: var(--ink); color: var(--paper); padding: 10px 12px 10px 14px; border-radius: var(--r1); box-shadow: var(--pop); font-size: 13px; font-weight: 500; border-left: 3px solid var(--line-strong); pointer-events: auto; }
.toast > .icon { margin-top: 1px; }
.toast-text { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.toast-action { flex: none; min-height: 24px; background: none; border: 0; padding: 0 2px; font: inherit; font-weight: 700; color: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.toast .icon-btn { width: 24px; height: 24px; margin: -2px -4px -2px 0; color: inherit; }
.toast .icon-btn:hover:not(:disabled) { background: rgba(127, 146, 153, 0.35); color: inherit; }
.toast :focus-visible { outline-color: var(--focus-on-dark); }
:root[data-theme="dark"] .toast { background: #e8eff1; color: #10262e; }
:root[data-theme="dark"] .toast :focus-visible { outline-color: #0b6bcb; }
.toast-success { border-left-color: var(--good); }
.toast-error { border-left-color: var(--bad); }

/* ---------- Charts ---------- */

/* The SVG is drawn at the container's pixel width (see lineChart), so label sizes below are real pixels. */
.chart { position: relative; min-width: 0; }
.chart-svg { width: 100%; display: block; touch-action: pan-y; border-radius: var(--r1); }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-label { fill: var(--ink-2); font: 12px var(--body); }
.chart-line { fill: none; stroke-width: 2; stroke: var(--ink); }
.chart-line.is-dashed { stroke-dasharray: 5 4; }
.chart-cursor { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-bar { fill: var(--line-strong); }
.chart-line.tone-ink { stroke: var(--ink); }
.chart-line.tone-signal { stroke: var(--signal); }
.chart-line.tone-good { stroke: var(--good); }
.chart-line.tone-bad { stroke: var(--bad); }
.chart-line.tone-note { stroke: var(--note); }
.chart-line.tone-muted { stroke: var(--ink-3); }
.chart-bar.tone-signal { fill: var(--signal); }
.chart-bar.tone-note { fill: var(--note); }
.chart-bar.tone-good { fill: var(--good); }
.chart-legend { display: flex; gap: var(--s3); flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 14px; height: 3px; background: var(--ink); }
.swatch.tone-signal { background: var(--signal); }
.swatch.tone-good { background: var(--good); }
.swatch.tone-bad { background: var(--bad); }
.swatch.tone-note { background: var(--note); }
.swatch.tone-muted { background: var(--ink-3); }
.swatch.is-dashed { background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px); color: var(--ink-2); }
.chart-readout { min-height: 18px; display: flex; gap: var(--s3); flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.chart-empty { padding: var(--s3) 0; font-size: 13px; }

/* ---------- Lists used across modules ---------- */

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: var(--s3); padding: 12px var(--s3); border-bottom: 1px solid var(--line); min-width: 0; }
.list-item:last-child { border-bottom: 0; }
button.list-item { width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
button.list-item:hover:not(:disabled), a.list-item:hover { background: var(--sunken); }
button.list-item:disabled { color: var(--ink-3); cursor: not-allowed; }
.list-item.is-selected { background: var(--signal-soft); box-shadow: inset 3px 0 0 var(--ink); --ink-3: var(--ink-2); }
.scroll-y { overflow-y: auto; max-height: 52vh; border: 1px solid var(--line); border-radius: var(--r1); scrollbar-width: thin; }

.tabs { display: flex; gap: var(--s3); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button, .tabs a { background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 2px; font: 600 13px/1 var(--body); color: var(--ink-2); cursor: pointer; white-space: nowrap; text-decoration: none; }
.tabs .is-active { color: var(--ink); border-bottom-color: var(--signal); }
.tabs button:focus-visible, .tabs a:focus-visible { outline-offset: -2px; }

.steps { display: flex; gap: var(--s2); list-style: none; margin: 0; padding: 0; font-size: 13px; color: var(--ink-2); }
.steps li { display: flex; align-items: center; gap: 6px; }
.steps li + li::before { content: ""; width: 20px; height: 1px; background: var(--line-strong); }
.steps .is-active { color: var(--ink); font-weight: 600; }
.steps .is-done { color: var(--good); }

/* Progress of a running swap: yellow fill closed by an ink edge, so the amount reads without colour. */
.meter { height: 8px; border-radius: var(--r1); background: var(--sunken); box-shadow: inset 0 0 0 1px var(--line-strong); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--signal); border-right: 2px solid var(--ink); }

.banner { display: flex; align-items: center; justify-content: center; gap: var(--s2) var(--s3); flex-wrap: wrap; padding: 10px var(--s3); background: var(--note-soft); color: var(--ink); border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 500; }
.banner .btn { height: 30px; }

.kbd { font: 12px/1 ui-monospace, SFMono-Regular, Consolas, monospace; padding: 3px 6px; border: 1px solid var(--line-strong); border-radius: var(--r1); background: var(--sunken); }
.code-list { font: 13px/1.9 ui-monospace, SFMono-Regular, Consolas, monospace; columns: 2; padding: var(--s3); background: var(--sunken); border-radius: var(--r1); margin: 0; list-style: none; }

/* ---------- Auth layout ---------- */

.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
.auth-side { background: var(--bar); color: var(--bar-ink); padding: var(--s6); display: flex; flex-direction: column; justify-content: space-between; gap: var(--s5); }
:root[data-theme="dark"] .auth-side { border-right: 1px solid var(--line); }
.auth-side h2 { font-size: 32px; max-width: 16ch; }
.auth-side p { color: var(--bar-ink-2); max-width: 40ch; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: var(--s5) var(--s4); }
.auth-card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: var(--s4); }
.auth-card h1 { font-size: 32px; }
.auth-foot { font-size: 13px; color: var(--ink-2); display: flex; gap: var(--s3); flex-wrap: wrap; }
.or { display: flex; align-items: center; gap: var(--s3); color: var(--ink-2); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Signature element: a swap rendered as two sides around a spine that tracks time. */
.deck { display: grid; grid-template-columns: minmax(0, 1fr) 132px minmax(0, 1fr); align-items: center; gap: var(--s3); }
.deck-side { min-width: 0; }
.deck-side.is-theirs .track { flex-direction: row-reverse; text-align: right; }
.deck-spine { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.deck-spine .meter { width: 100%; }
.deck-days { font: 600 15px/1 var(--display); font-stretch: 87%; }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .nav a { padding: 0 8px; }
  .user-btn span.name { display: none; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  :root { --bar-h: 52px; }
  .nav { display: none; }
  .topbar { justify-content: space-between; }
  .tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a, .tabbar button { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 6px; font: 500 12px/1.2 var(--body); color: var(--ink-2); text-decoration: none; background: none; border: 0; border-top: 3px solid transparent; cursor: pointer; }
  .tabbar a[aria-current="page"] { color: var(--ink); border-top-color: var(--signal); }
  .tabbar a:focus-visible, .tabbar button:focus-visible { outline-offset: -3px; }
  .tabbar .count { position: absolute; top: 4px; left: 54%; }
  .outlet { padding-bottom: 68px; }
  .page { padding: var(--s4) var(--s3) var(--s6); }
  .page-wide { margin-left: 0; }
  h1 { font-size: 24px; }
  h2 { font-size: 18px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  /* Signed-out screens keep the brand (and the way back to the home page) as a slim bar. */
  .auth { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .auth-side { padding: 0 var(--s3); height: var(--bar-h); flex-direction: row; align-items: center; }
  .auth-side > :not(.brand) { display: none; }
  .auth-main { align-items: flex-start; }
  .stat-value { font-size: 24px; }
  .stat { padding: 12px var(--s3); }
  .panel { padding: var(--s3); }
  .panel-flush { padding: 0; }
  .deck { grid-template-columns: minmax(0, 1fr); }
  .deck-side.is-theirs .track { flex-direction: row; text-align: left; }
  .backdrop { padding: var(--s2); align-items: flex-end; }
  .modal { max-height: 94vh; max-height: 94dvh; }
  .toasts { bottom: 84px; }
  .hide-mobile { display: none !important; }
  .code-list { columns: 1; }
  /* 16px stops iOS Safari from zooming the page when a field takes focus. */
  .input, textarea.input, select.input { font-size: 16px; }
  /* Touch targets. */
  .icon-btn { width: 36px; height: 36px; }
  .toast .icon-btn { width: 36px; height: 36px; margin: -8px -8px -8px 0; }
  .btn-sm, .banner .btn, .segmented button { height: 36px; }
  .chip { height: 32px; }
  input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; }
  .check input { margin-top: 0; }
  .menu button { min-height: 40px; }
  .link-btn, .sort-btn, .back-link { min-height: 32px; }
}

@media (min-width: 861px) {
  .only-mobile { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
