/* ---------------------------------------------------------------------------
   components.css — the shared component library.

   Every class here is theme-agnostic: it reads --c-*, --r-*, --sh-*, --bw and
   --btn-translate from tokens.css, so the brutal face arrives for free. A
   feature screen should reach for these before inventing anything, and should
   put anything genuinely its own in its own stylesheet.

   Naming: .c-<block>[__<element>][--<modifier>].
--------------------------------------------------------------------------- */

/* =========================================================================
   BUTTONS
   ========================================================================= */
.c-btn {
  --btn-h: var(--tap);
  --btn-pad: var(--sp-5);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--btn-h);
  min-width: var(--btn-h);
  padding-inline: var(--btn-pad);
  border-radius: var(--r-btn);
  border: var(--bw) solid transparent;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-normal);
  text-transform: var(--caps-transform);
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  transition:
    transform var(--d-1) var(--e-out),
    box-shadow var(--d-1) var(--e-out),
    background-color var(--d-2) var(--e-out),
    border-color var(--d-2) var(--e-out),
    color var(--d-2) var(--e-out),
    opacity var(--d-2) var(--e-out);
}
.c-btn > svg { width: 20px; height: 20px; }
.c-btn:disabled, .c-btn[aria-disabled="true"] { opacity: 0.42; pointer-events: none; }

/* The press: studio sinks a little, brutal falls into its own hard shadow. */
.c-btn:active:not(:disabled) {
  transform: translate(var(--btn-translate), var(--btn-translate)) scale(0.985);
  box-shadow: var(--sh-press);
}

.c-btn--primary {
  background: var(--c-accent);
  color: var(--c-accent-ink);
  border-color: var(--c-accent-line);
  box-shadow: var(--sh-accent);
}
.c-btn--primary:hover:not(:disabled) { background: var(--c-accent-deep); }

.c-btn--secondary {
  background: var(--c-surface);
  color: var(--c-ink);
  border: var(--card-border);
  box-shadow: var(--sh-1);
}
.c-btn--secondary:hover:not(:disabled) { background: var(--c-surface-2); }

.c-btn--soft {
  background: var(--c-accent-soft);
  color: var(--c-accent-deep);
  border-color: transparent;
}
.c-btn--soft:hover:not(:disabled) { background: var(--c-accent-line); }

.c-btn--ghost {
  background: transparent;
  color: var(--c-ink-2);
}
.c-btn--ghost:hover:not(:disabled) { background: var(--c-surface-sunken); color: var(--c-ink); }

.c-btn--danger {
  background: var(--c-danger-soft);
  color: var(--c-danger);
  border: var(--bw) solid color-mix(in srgb, var(--c-danger) 30%, transparent);
}
/* --c-accent-ink, not #fff: --c-danger is a light coral in both dark themes,
   and white on it lands near 2.6:1 — under AA, on a destructive control. */
.c-btn--danger:hover:not(:disabled) { background: var(--c-danger); color: var(--c-accent-ink); }

.c-btn--block { width: 100%; }
.c-btn--sm { --btn-h: 34px; --btn-pad: var(--sp-3); font-size: var(--fs-sm); }
.c-btn--sm > svg { width: 16px; height: 16px; }

/* Icon buttons keep a 44px hit area even when the glyph is 20px. */
.c-btn--icon {
  --btn-pad: 0;
  width: var(--tap);
  height: var(--tap);
  border-radius: var(--r-pill);
  color: var(--c-ink-2);
}
.c-btn--icon:hover:not(:disabled) { background: var(--c-surface-sunken); color: var(--c-ink); }
.c-btn--icon.is-active { color: var(--c-accent); background: var(--c-accent-softer); }

/* The transport buttons on the timer: a big round primary flanked by two
   quieter satellites. */
.c-btn--round {
  --btn-pad: 0;
  width: 56px; height: 56px;
  border-radius: var(--r-pill);
}
.c-btn--round.c-btn--hero { width: 76px; height: 76px; }
.c-btn--round.c-btn--hero > svg { width: 30px; height: 30px; }

.c-fab {
  /* Fixed, not absolute: every screen is its own scroll container, and an
     absolutely positioned FAB scrolls away with the list under it. */
  position: fixed;
  right: max(var(--gutter), var(--sa-r));
  bottom: calc(var(--nav-total) + var(--sp-4));
  z-index: var(--z-sticky);
  width: 56px; height: 56px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-pill);
  background: var(--c-accent);
  color: var(--c-accent-ink);
  border: var(--bw) solid var(--c-accent-line);
  box-shadow: var(--sh-accent), var(--sh-2);
  transition: transform var(--d-2) var(--e-spring), box-shadow var(--d-2) var(--e-out);
}
.c-fab > svg { width: 26px; height: 26px; }
.c-fab:hover { transform: scale(1.05); }
.c-fab:active { transform: translate(var(--btn-translate), var(--btn-translate)) scale(0.96); box-shadow: var(--sh-press); }
@media (min-width: 900px) { .c-fab { bottom: var(--sp-6); } }

.c-btn-group { display: flex; gap: var(--sp-2); }
.c-btn-group--fill > .c-btn { flex: 1 1 0; }

/* =========================================================================
   CARDS & SURFACES
   ========================================================================= */
.c-card {
  position: relative;
  background: var(--c-surface);
  border: var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--sh-card);
  padding: var(--sp-4);
  /* What a .bleed-x child may escape — the card's own padding. */
  --bleed-s: var(--sp-4);
  --bleed-e: var(--sp-4);
}
.c-card--flush { padding: 0; overflow: hidden; }
.c-card--quiet { background: var(--c-surface-2); box-shadow: none; }
.c-card--hero { padding: var(--sp-6) var(--sp-5); border-radius: var(--r-xl); --bleed-s: var(--sp-5); --bleed-e: var(--sp-5); }
.c-card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.c-card__title { font-size: var(--fs-lg); font-weight: var(--fw-bold); letter-spacing: var(--ls-tight); }
.c-card__action { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--c-accent); }

.c-section { display: flex; flex-direction: column; gap: var(--sp-3); }
.c-section__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); }
.c-section__title { font-size: var(--fs-lg); font-weight: var(--fw-bold); letter-spacing: var(--ls-tight); }

.c-divider { height: var(--bw); background: var(--c-line); border: 0; margin: var(--sp-2) 0; }

/* Small labelled figure — "46.2 h / total focus". Used across home and report. */
.c-stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.c-stat__value {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-tight);
  line-height: 1.1;
}
.c-stat__label { font-size: var(--fs-xs); color: var(--c-ink-3); }
.c-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: var(--sp-4);
}

/* =========================================================================
   LIST ROWS
   A row is a <button> or <a> when it navigates and a <div> when it does not;
   the class does not care, so both stay accessible.
   ========================================================================= */
.c-list { display: flex; flex-direction: column; gap: var(--sp-2); }

.c-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 56px;
  padding: var(--sp-3) var(--sp-4);
  text-align: start;
  background: var(--c-surface);
  border: var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--sh-card);
  color: var(--c-ink);
  transition: background var(--d-2) var(--e-out), transform var(--d-1) var(--e-out), box-shadow var(--d-1) var(--e-out);
}
button.c-row:hover, a.c-row:hover { background: var(--c-surface-2); text-decoration: none; }
button.c-row:active { transform: translate(var(--btn-translate), var(--btn-translate)) scale(0.995); box-shadow: var(--sh-press); }
.c-row--quiet { background: transparent; border-color: transparent; box-shadow: none; }
.c-row.is-selected { border-color: var(--c-accent); background: var(--c-accent-softer); }
.c-row.is-done .c-row__title { text-decoration: line-through; color: var(--c-ink-3); }

.c-row__lead { flex: none; display: flex; align-items: center; justify-content: center; }
.c-row__body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.c-row__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-row__meta { font-size: var(--fs-xs); color: var(--c-ink-3); display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.c-row__trail { flex: none; display: flex; align-items: center; gap: var(--sp-1); color: var(--c-ink-3); }

/* The square coloured badge that carries a project icon. */
.c-tile {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-md);
  background: var(--c-accent-soft);
  color: var(--c-accent-deep);
  border: var(--bw) solid transparent;
  flex: none;
}
.c-tile > svg { width: 20px; height: 20px; }
.c-tile--solid { background: var(--c-accent); color: var(--c-accent-ink); border-color: var(--c-accent-line); }
.c-tile--sm { width: 30px; height: 30px; border-radius: var(--r-sm); }
.c-tile--sm > svg { width: 16px; height: 16px; }
.c-tile--lg { width: 52px; height: 52px; border-radius: var(--r-lg); }
.c-tile--lg > svg { width: 26px; height: 26px; }

/* =========================================================================
   CHIPS & TAGS
   ========================================================================= */
.c-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  min-height: 28px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-pill);
  border: var(--bw) solid var(--c-line);
  background: var(--c-surface-2);
  color: var(--c-ink-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  transition: background var(--d-2) var(--e-out), color var(--d-2) var(--e-out), border-color var(--d-2) var(--e-out);
}
.c-chip > svg { width: 14px; height: 14px; }
button.c-chip { min-height: var(--tap); padding-inline: var(--sp-4); }
button.c-chip:hover { background: var(--c-surface-sunken); color: var(--c-ink); }
.c-chip.is-active,
.c-chip[aria-pressed="true"] {
  background: var(--c-accent);
  border-color: var(--c-accent-line);
  color: var(--c-accent-ink);
}
.c-chip__dot { width: 8px; height: 8px; border-radius: var(--r-pill); background: currentColor; flex: none; }
.c-chip-set { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.c-chip-set--scroll { flex-wrap: nowrap; overflow-x: auto; padding-block: 2px; }

/* =========================================================================
   SEGMENTED TABS  (Active / Completed, Weekly / Monthly)
   Built as role="tablist"; the sliding thumb is a pseudo-free absolute div so
   it can animate with transform alone.
   ========================================================================= */
.c-seg {
  position: relative;
  display: flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--r-pill);
  background: var(--c-surface-sunken);
  border: var(--bw) solid var(--c-line);
  isolation: isolate;
}
.c-seg__thumb {
  position: absolute;
  z-index: -1;
  top: 3px; bottom: 3px; left: 0;
  border-radius: var(--r-pill);
  background: var(--c-accent);
  border: var(--bw) solid var(--c-accent-line);
  box-shadow: var(--sh-1);
  transition: transform var(--d-3) var(--e-out), width var(--d-3) var(--e-out);
}
.c-seg__btn {
  flex: 1 1 0;
  min-height: var(--tap);
  padding-inline: var(--sp-3);
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--c-ink-2);
  text-transform: var(--caps-transform);
  transition: color var(--d-2) var(--e-out);
}
.c-seg__btn[aria-selected="true"] { color: var(--c-accent-ink); }

/* =========================================================================
   FORM CONTROLS
   ========================================================================= */
.c-field { display: flex; flex-direction: column; gap: var(--sp-2); }
.c-field__label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--c-ink-2);
  text-transform: var(--caps-transform);
  letter-spacing: var(--ls-normal);
}
.c-field__hint { font-size: var(--fs-xs); color: var(--c-ink-3); }

.c-input, .c-textarea, .c-select {
  width: 100%;
  min-height: var(--tap);
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface);
  border: var(--field-border);
  border-radius: var(--r-field);
  color: var(--c-ink);
  font-size: var(--fs-md);
  transition: border-color var(--d-2) var(--e-out), box-shadow var(--d-2) var(--e-out), background var(--d-2) var(--e-out);
}
.c-input:hover, .c-textarea:hover, .c-select:hover { border-color: var(--c-ink-3); }
.c-input:focus-visible, .c-textarea:focus-visible, .c-select:focus-visible {
  border-color: var(--c-accent);
  outline: 2px solid var(--c-ring);
  outline-offset: 1px;
}
.c-textarea { min-height: 92px; resize: vertical; line-height: var(--lh-body); }
.c-select {
  appearance: none; -webkit-appearance: none;
  padding-inline-end: var(--sp-8);
  /* The caret is drawn with a gradient pair rather than an inline SVG data URI
     so it inherits currentColor and needs no per-theme asset. */
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 20px) calc(50% + 1px),
    calc(100% - 15px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
[dir="rtl"] .c-select { padding-inline-end: var(--sp-4); padding-inline-start: var(--sp-8); }

/* Stepper: minus / value / plus. The value is a live region so a screen reader
   hears the new number, not the whole row. */
.c-stepper {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 3px;
  border-radius: var(--r-pill);
  background: var(--c-surface-sunken);
  border: var(--bw) solid var(--c-line);
}
.c-stepper__btn {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-pill);
  background: var(--c-surface);
  border: var(--bw) solid var(--c-line);
  color: var(--c-ink);
  transition: background var(--d-2) var(--e-out), transform var(--d-1) var(--e-out);
}
.c-stepper__btn > svg { width: 18px; height: 18px; }
.c-stepper__btn:hover:not(:disabled) { background: var(--c-accent-soft); color: var(--c-accent-deep); }
.c-stepper__btn:active:not(:disabled) { transform: scale(0.92); }
.c-stepper__btn:disabled { opacity: 0.35; }
.c-stepper__value {
  min-width: 3.25rem;
  text-align: center;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
}

/* Switch. A real <button role="switch"> underneath. */
.c-switch {
  position: relative;
  flex: none;
  width: 50px; height: 30px;
  border-radius: var(--r-pill);
  background: var(--c-track);
  border: var(--bw) solid var(--c-line);
  transition: background var(--d-2) var(--e-out), border-color var(--d-2) var(--e-out);
}
.c-switch::after {
  content: "";
  position: absolute;
  top: 50%; left: 3px;
  width: 22px; height: 22px;
  margin-top: -11px;
  border-radius: var(--r-pill);
  background: var(--c-surface);
  box-shadow: var(--sh-1);
  transition: transform var(--d-2) var(--e-spring);
}
.c-switch[aria-checked="true"] { background: var(--c-accent); border-color: var(--c-accent-line); }
.c-switch[aria-checked="true"]::after { transform: translateX(20px); }
.c-switch:disabled { opacity: 0.4; }
/* The switch itself is 30px tall; the row it sits in supplies the 44px target. */
.c-switch-row { display: flex; align-items: center; gap: var(--sp-4); min-height: var(--tap); width: 100%; }

/* Slider. Range inputs need per-engine pseudo-elements; there is no shorthand. */
.c-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%;
  height: var(--tap);
  background: transparent;
  cursor: pointer;
}
.c-slider::-webkit-slider-runnable-track {
  height: 6px; border-radius: var(--r-pill);
  background: linear-gradient(to right, var(--c-accent) var(--fill, 50%), var(--c-track) var(--fill, 50%));
}
.c-slider::-moz-range-track { height: 6px; border-radius: var(--r-pill); background: var(--c-track); }
.c-slider::-moz-range-progress { height: 6px; border-radius: var(--r-pill); background: var(--c-accent); }
.c-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; margin-top: -8px;
  border-radius: var(--r-pill);
  background: var(--c-surface);
  border: 2px solid var(--c-accent);
  box-shadow: var(--sh-1);
  transition: transform var(--d-1) var(--e-out);
}
.c-slider::-moz-range-thumb {
  width: 22px; height: 22px;
  border-radius: var(--r-pill);
  background: var(--c-surface);
  border: 2px solid var(--c-accent);
  box-shadow: var(--sh-1);
}
.c-slider:active::-webkit-slider-thumb { transform: scale(1.15); }

/* Colour swatch picker, used by projects, tags and the accent setting. */
.c-swatches { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.c-swatch {
  width: var(--tap); height: var(--tap);
  border-radius: var(--r-pill);
  border: 2px solid transparent;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform var(--d-1) var(--e-spring);
}
.c-swatch::before {
  content: "";
  width: 26px; height: 26px;
  border-radius: var(--r-pill);
  background: var(--swatch, var(--c-accent));
  box-shadow: var(--sh-1);
}
.c-swatch[aria-pressed="true"] { border-color: var(--c-ink); }
.c-swatch:hover { transform: scale(1.08); }

/* =========================================================================
   PROGRESS — rings and bars
   The ring is one SVG with two circles; the JS only ever writes
   --ring-progress (0..1). stroke-dashoffset is not composited, but at one
   write per second on a single element that is cheaper than any alternative.
   ========================================================================= */
.c-ring { position: relative; display: inline-grid; place-items: center; }
.c-ring__svg { transform: rotate(-90deg); overflow: visible; }
.c-ring__track { fill: none; stroke: var(--c-track); }
.c-ring__value {
  fill: none;
  stroke: var(--c-accent);
  stroke-linecap: round;
  stroke-dasharray: var(--ring-circumference, 100);
  stroke-dashoffset: calc(var(--ring-circumference, 100) * (1 - var(--ring-progress, 0)));
  transition: stroke-dashoffset var(--d-3) linear, stroke var(--d-3) var(--e-out);
}
.c-ring[data-kind="short"] .c-ring__value,
.c-ring[data-kind="long"] .c-ring__value { stroke: var(--c-break); }
.c-ring[data-kind="long"] .c-ring__value { stroke: var(--c-long); }
.c-ring__center {
  position: absolute;
  inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-1);
  text-align: center;
  pointer-events: none;
}

.c-bar {
  position: relative;
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--c-track);
  overflow: hidden;
}
.c-bar__fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform: scaleX(var(--bar-progress, 0));
  background: var(--c-accent);
  border-radius: inherit;
  transition: transform var(--d-3) var(--e-out);
}
[dir="rtl"] .c-bar__fill { transform-origin: right center; }
.c-bar--tall { height: 12px; }

/* The row of dots under the timer: one per pomodoro in the current cycle. */
.c-dots { display: inline-flex; gap: var(--sp-2); align-items: center; }
.c-dot {
  width: 8px; height: 8px;
  border-radius: var(--r-pill);
  background: var(--c-track);
  transition: background var(--d-2) var(--e-out), transform var(--d-2) var(--e-spring);
}
.c-dot.is-done { background: var(--c-accent); }
.c-dot.is-current { background: var(--c-accent); transform: scale(1.5); }

/* =========================================================================
   AVATAR — an emoji or generated initials on a hue; never an image file.
   ========================================================================= */
.c-avatar {
  flex: none;
  width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-pill);
  background: var(--avatar-bg, var(--c-accent-soft));
  color: var(--avatar-ink, var(--c-accent-deep));
  border: var(--bw) solid var(--c-line);
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  letter-spacing: 0;
  overflow: hidden;
  user-select: none;
}
.c-avatar--lg { width: 84px; height: 84px; font-size: var(--fs-3xl); }

/* =========================================================================
   BOTTOM NAV / SIDE RAIL
   Same markup at every width; the rail is a media query, not a second widget.
   ========================================================================= */
.c-nav {
  display: flex;
  align-items: stretch;
  height: var(--nav-total);
  padding-bottom: var(--sa-b);
  padding-inline: max(var(--sp-1), var(--sa-l)) max(var(--sp-1), var(--sa-r));
  background: color-mix(in srgb, var(--c-surface) 92%, transparent);
  backdrop-filter: saturate(1.5) blur(16px);
  -webkit-backdrop-filter: saturate(1.5) blur(16px);
  border-top: var(--bw) solid var(--c-line);
}
.c-nav__btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: var(--tap);
  padding: var(--sp-1);
  color: var(--c-ink-3);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  position: relative;
  transition: color var(--d-2) var(--e-out);
}
.c-nav__btn > svg { width: 22px; height: 22px; transition: transform var(--d-2) var(--e-spring); }
.c-nav__btn:hover { color: var(--c-ink-2); }
.c-nav__btn[aria-current="page"] { color: var(--c-accent); }
.c-nav__btn[aria-current="page"] > svg { transform: translateY(-1px) scale(1.06); }
/* The active pill sits behind the icon and is the one thing that moves. */
.c-nav__btn::before {
  content: "";
  position: absolute;
  top: 4px;
  width: 40px; height: 26px;
  border-radius: var(--r-pill);
  background: var(--c-accent-softer);
  opacity: 0;
  transform: scale(0.7);
  transition: opacity var(--d-2) var(--e-out), transform var(--d-2) var(--e-spring);
}
.c-nav__btn[aria-current="page"]::before { opacity: 1; transform: scale(1); }
.c-nav__label { position: relative; }

@media (min-width: 900px) {
  .c-nav {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: var(--sp-1);
    height: 100%;
    padding: calc(var(--sa-t) + var(--sp-4)) var(--sp-3) calc(var(--sa-b) + var(--sp-4));
    border-top: 0;
    border-inline-end: var(--bw) solid var(--c-line);
  }
  .c-nav__brand {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3) var(--sp-5);
    font-weight: var(--fw-black);
    letter-spacing: var(--ls-tight);
    font-size: var(--fs-lg);
  }
  .c-nav__btn {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--sp-3);
    min-height: var(--tap);
    padding-inline: var(--sp-3);
    border-radius: var(--r-md);
    font-size: var(--fs-md);
  }
  .c-nav__btn::before { inset: 0; top: 0; width: auto; height: auto; border-radius: var(--r-md); }
}
@media (max-width: 899px) { .c-nav__brand { display: none; } }

/* =========================================================================
   BOTTOM SHEET
   One element for both breakpoints: a sheet on a phone, a centred dialog on a
   desktop. It is a real <dialog> so Escape and the top layer come for free —
   and `alert`/`confirm` are unavailable in this sandbox anyway.
   ========================================================================= */
.c-sheet, .c-modal {
  padding: 0;
  border: 0;
  background: transparent;
  max-width: none;
  max-height: none;
  color: var(--c-ink);
  overflow: visible;
}
.c-sheet::backdrop, .c-modal::backdrop {
  background: var(--c-scrim);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fx-fade-in var(--d-2) var(--e-out);
}
/* Dragging the sheet down thins the scrim by the same fraction, so the panel
   and the dark behind it read as one object under the finger. ::backdrop
   inherits custom properties from the dialog it belongs to; where a browser
   has not caught up the fallback is 1 and the scrim just holds still. */
.c-sheet::backdrop {
  background: color-mix(in srgb, var(--c-scrim) calc(var(--sheet-progress, 1) * 100%), transparent);
}
.c-sheet {
  width: 100%;
  max-width: 100%;
  margin: auto 0 0;
  inset-inline: 0;
}
.c-sheet__panel {
  width: 100%;
  max-width: var(--page-max);
  margin-inline: auto;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
  border: var(--card-border);
  border-bottom: 0;
  border-start-start-radius: var(--r-sheet);
  border-start-end-radius: var(--r-sheet);
  box-shadow: var(--sh-4);
  padding-bottom: var(--sa-b);
  animation: fx-sheet-up var(--d-3) var(--e-out);
  /* The gesture writes transform every frame; the entry animation must not be
     fighting it for the same property. */
  will-change: auto;
}
.c-sheet__panel.is-dragging {
  animation: none;
  will-change: transform;
}
/* The two drag handles. touch-action is the load-bearing line: without it the
   browser claims the vertical swipe for scrolling (or for pull-to-refresh) and
   the panel never sees a single pointermove. */
.c-sheet__grip, .c-sheet__head { touch-action: none; }
.c-sheet__grip {
  position: relative;
  flex: none;
  width: 40px; height: 4px;
  margin: var(--sp-3) auto var(--sp-1);
  border-radius: var(--r-pill);
  background: var(--c-line-strong);
  cursor: grab;
}
.c-sheet__panel.is-dragging .c-sheet__grip { cursor: grabbing; }
/* 4px is a hairline to aim at. The bar stays a hairline; the target around it
   is a comfortable one. */
.c-sheet__grip::before {
  content: '';
  position: absolute;
  inset: -14px -48px;
}
.c-sheet__head, .c-modal__head {
  flex: none;
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
}
/* The close button is inside the header, so it has to opt back out of the
   header's touch-action or a tap on it can be swallowed by the gesture. */
.c-sheet__head > .c-btn { touch-action: manipulation; }
.c-sheet__title, .c-modal__title {
  flex: 1 1 auto;
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-tight);
}
.c-sheet__body, .c-modal__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--sp-4) var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-4);
  --bleed-s: var(--sp-4);
  --bleed-e: var(--sp-4);
}
.c-sheet__foot, .c-modal__foot {
  flex: none;
  display: flex; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
  border-top: var(--bw) solid var(--c-line);
}
.c-sheet__foot > .c-btn, .c-modal__foot > .c-btn { flex: 1 1 0; }

.c-modal { margin: auto; width: min(100% - var(--sp-8), 26rem); }
.c-modal__panel {
  display: flex; flex-direction: column;
  background: var(--c-surface);
  border: var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--sh-4);
  max-height: 84vh;
  animation: fx-pop-in var(--d-2) var(--e-spring);
}
.c-modal__text { padding: 0 var(--sp-4) var(--sp-2); color: var(--c-ink-2); }

@media (min-width: 700px) {
  /* Above the phone the sheet stops being a sheet. */
  .c-sheet { margin: auto; width: min(100% - var(--sp-8), 30rem); }
  .c-sheet__panel {
    border-radius: var(--r-card);
    border-bottom: var(--card-border);
    padding-bottom: 0;
    animation: fx-pop-in var(--d-2) var(--e-spring);
    max-height: 82vh;
  }
  .c-sheet__grip { display: none; }
  /* No drag up here, so give the header its scrolling behaviour back. */
  .c-sheet__head { touch-action: auto; }
}

/* =========================================================================
   TOASTS — bottom on a phone (above the tab bar), top-right on a desktop.
   ========================================================================= */
.c-toasts {
  position: fixed;
  z-index: var(--z-toast);
  left: max(var(--gutter), var(--sa-l));
  right: max(var(--gutter), var(--sa-r));
  bottom: calc(var(--nav-total) + var(--sp-3));
  display: flex;
  flex-direction: column-reverse;
  gap: var(--sp-2);
  pointer-events: none;
}
.c-toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: var(--sp-3);
  max-width: var(--page-max);
  margin-inline: auto;
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--c-ink);
  color: var(--c-ink-inv);
  border: var(--bw) solid var(--c-ink);
  box-shadow: var(--sh-3);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  animation: fx-toast-in var(--d-3) var(--e-out);
}
.c-toast > svg { width: 18px; height: 18px; flex: none; }
.c-toast__text { flex: 1 1 auto; min-width: 0; }
.c-toast__action { font-weight: var(--fw-bold); color: var(--c-accent-lift); text-decoration: underline; }
.c-toast--ok > svg { color: var(--c-ok); }
.c-toast--error > svg { color: var(--c-danger); }
.c-toast--info > svg { color: var(--c-info); }
.c-toast.is-leaving { animation: fx-toast-out var(--d-2) var(--e-in) forwards; }

@media (min-width: 900px) {
  .c-toasts { top: calc(var(--sa-t) + var(--sp-4)); bottom: auto; left: auto; right: var(--sp-6); flex-direction: column; width: 22rem; }
}

/* =========================================================================
   EMPTY STATES & SKELETONS
   ========================================================================= */
.c-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-9) var(--sp-4);
  text-align: center;
  color: var(--c-ink-3);
}
.c-empty__art { color: var(--c-line-strong); }
.c-empty__art > svg { width: 64px; height: 64px; }
.c-empty__title { font-size: var(--fs-lg); font-weight: var(--fw-bold); color: var(--c-ink); }
.c-empty__text { font-size: var(--fs-sm); max-width: 26ch; }

/* =========================================================================
   MISC ATOMS
   ========================================================================= */
.c-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px;
  padding-inline: 6px;
  border-radius: var(--r-pill);
  background: var(--c-accent);
  color: var(--c-accent-ink);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
}
.c-badge--quiet { background: var(--c-surface-sunken); color: var(--c-ink-2); }

.c-kbd {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  padding: 2px 6px;
  border-radius: var(--r-xs);
  border: var(--bw) solid var(--c-line-strong);
  background: var(--c-surface-2);
  color: var(--c-ink-2);
}

.c-meta-dot { width: 3px; height: 3px; border-radius: var(--r-pill); background: currentColor; opacity: 0.5; }

