/**
 * Sporetag's components: one shared layer for the app, the sign-in pages and
 * the marketing site. Built only from the tokens in site.css (spacing, type,
 * control heights, radii, elevation, tones, motion). Area files (app-*.css)
 * arrange these; they do not restyle them.
 *
 *   page head and tabs     .app-page-head  .tabs .tab .tab-count
 *   cards                  .card .card-head .card-title .card-sub .card-actions .card-section
 *   buttons                .btn + .btn-sm|.btn-lg + .btn-primary|.btn-accent|.btn-secondary|.btn-quiet|.btn-danger|.btn-danger-solid  .btn-icon  .icon-button
 *   fields                 .field .field-label .field-input .field-hint .field-error .field-check .switch
 *   choices                .segmented .segment (2 or 3 options)  .chips .chip (filters)
 *   status                 .pill (+ -ok|-warn|-danger|-accent|-info, .pill-dot)  .badge  .checklist
 *   tables                 .table-wrap .table .num .table-empty
 *   feedback               .notice (+ -ok|-warn|-error)  .toast  .empty  .skeleton
 *   overlays               .dialog  .menu-list .menu-row  .cmdk  .kbd
 *   numbers                .stat .stat-label .stat-value .stat-note
 */

/* ---------------- app and sign-in sizes ----------------
   The app is a tool: 36px controls and 14px text in them. Sign-in pages
   use the 44px step. Every control on a phone is 44px, and fields are 16px
   so iOS does not zoom. */

body.app {
  --btn-h-sm: var(--ctl-h-sm);
  --btn-h-md: var(--ctl-h-md);
  --btn-h-lg: var(--ctl-h-lg);
  --btn-fs-sm: var(--fs-13);
  --btn-fs-md: var(--fs-14);
  --btn-fs-lg: var(--fs-15);
  --btn-px-sm: 10px;
  --btn-px-md: 14px;
  --btn-px-lg: 18px;
  --field-h: var(--ctl-h-md);
  --field-fs: var(--fs-14);
  --seg-h: var(--ctl-h-md);
}

.auth {
  --field-h: var(--ctl-h-lg);
  --btn-h-md: var(--ctl-h-lg);
  --btn-h-lg: var(--ctl-h-lg);
}

@media (max-width: 720px) {
  body.app,
  .auth {
    --btn-h-sm: var(--ctl-h-lg);
    --btn-h-md: var(--ctl-h-lg);
    --btn-h-lg: var(--ctl-h-lg);
    --field-h: var(--ctl-h-lg);
    --field-fs: var(--fs-16);
    --seg-h: var(--ctl-h-lg);
  }
}

/* ---------------- page transitions ----------------
   Same-origin page loads cross-fade where the browser supports it
   (progressive: nothing happens elsewhere). The header and the side nav keep
   their own names, so only the page under them changes. */

@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }
}

::view-transition-group(root) {
  animation-duration: var(--dur-2);
  animation-timing-function: var(--ease-out);
}

.app-header {
  view-transition-name: app-header;
}

.app-nav {
  view-transition-name: app-nav;
}

/* ---------------- page head ----------------
   appHead() in src/layout.ts: the title, one line under it, actions right. */

.app-page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3) var(--space-4);
  margin-bottom: var(--space-6);
}

.app-page-head h1 {
  font-size: var(--type-display);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: var(--track-title);
}

.app-page-head .app-page-sub {
  margin-top: var(--space-1);
  font-size: var(--type-body);
  color: var(--text-dim);
}

.app-page-head > .row {
  gap: var(--space-2);
}

/* A short trail above a title: "Links / spring-sale". */
.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  margin-bottom: var(--space-2);
  font-size: var(--type-small);
  color: var(--text-faint);
}

.crumbs a {
  color: var(--text-dim);
}

.app-section + .app-section {
  margin-top: var(--space-8);
}

/* A heading over a group of cards inside a page. */
.app-section-title,
.section-label {
  margin-bottom: var(--space-3);
  font-size: var(--type-heading);
  font-weight: var(--weight-title);
  line-height: var(--lh-snug);
}

@media (max-width: 860px) {
  .app-page-head h1 {
    font-size: var(--fs-24);
  }
}

/* ---------------- tabs ----------------
   Underlined tabs for a page's sections (appTabs). A count rides after the word. */

.tabs {
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

/* On a phone the row scrolls; its edges fade so a cut-off word reads as "more".
   The app's section row under the header does the same. */
@media (max-width: 860px) {
  .app-nav {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
  }
}

@media (max-width: 720px) {
  .tabs {
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 20px), transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 20px), transparent 100%);
  }
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--ctl-h-lg);
  padding: 0 var(--space-3);
  margin-bottom: -1px;
  font-size: var(--type-ui);
  font-weight: var(--weight-medium);
  color: var(--text-dim);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color var(--dur-1) ease, border-color var(--dur-2) var(--ease-out);
}

.tab:hover {
  color: var(--text);
  text-decoration: none;
}

.tab[aria-current='page'],
.tab[aria-selected='true'] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab:focus-visible {
  outline-offset: -4px;
}

.tab-count,
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: var(--fs-11);
  font-weight: var(--weight-strong);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  /* 6.1:1 light, 6.9:1 dark: --bg-active would drop under 4.5. */
  background: var(--bg-tint);
  box-shadow: inset 0 0 0 1px var(--line);
  border-radius: var(--r-pill);
}

.tab[aria-current='page'] .tab-count,
.badge-accent {
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------------- buttons ----------------
   `.btn` plus at most one size and one look.
     size   .btn-sm   (default)   .btn-lg
     look   .btn-primary (green, the one main action)   .btn-secondary (default)
            .btn-accent (blue)   .btn-quiet   .btn-danger   .btn-danger-solid
     shape  .btn-icon (square)   .btn-block (full width)
   Every look changes only six colors. */

.btn {
  --btn-bg: var(--bg-raised);
  --btn-fg: var(--text);
  --btn-line: var(--line-control);
  --btn-bg-hover: var(--bg-hover);
  --btn-fg-hover: var(--btn-fg);
  --btn-line-hover: var(--line-strong);
  --btn-h: var(--btn-h-md);
  --btn-fs: var(--btn-fs-md);
  --btn-px: var(--btn-px-md);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  min-height: var(--btn-h);
  margin: 0;
  padding: 0 var(--btn-px);
  font: inherit;
  font-size: var(--btn-fs);
  font-weight: var(--weight-strong);
  line-height: 1.2;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-line);
  border-radius: var(--btn-radius);
  box-shadow: var(--btn-shadow, none);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition:
    background-color var(--dur-1) ease,
    border-color var(--dur-1) ease,
    color var(--dur-1) ease,
    transform var(--dur-1) ease;
}

.btn:hover {
  color: var(--btn-fg-hover);
  background: var(--btn-bg-hover);
  border-color: var(--btn-line-hover);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn:disabled:hover,
.btn[aria-disabled='true']:hover {
  color: var(--btn-fg);
  background: var(--btn-bg);
  border-color: var(--btn-line);
}

/* Working: the words stay, a small ring turns before them. */
.btn[aria-busy='true'] {
  cursor: progress;
}

.btn[aria-busy='true']::before {
  content: '';
  width: 0.95em;
  height: 0.95em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: ui-spin 0.7s linear infinite;
}

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

.btn svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
}

.btn-sm {
  --btn-h: var(--btn-h-sm);
  --btn-fs: var(--btn-fs-sm);
  --btn-px: var(--btn-px-sm);
}

.btn-sm svg {
  width: 15px;
  height: 15px;
}

.btn-lg {
  --btn-h: var(--btn-h-lg);
  --btn-fs: var(--btn-fs-lg);
  --btn-px: var(--btn-px-lg);
}

.btn-primary,
.btn-cta {
  --btn-bg: var(--cta);
  --btn-fg: var(--cta-ink);
  --btn-line: transparent;
  --btn-bg-hover: var(--cta-hover);
  --btn-line-hover: transparent;
  --btn-shadow: var(--elev-1);
}

.btn-accent {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-ink);
  --btn-line: transparent;
  --btn-bg-hover: var(--accent-hover);
  --btn-line-hover: transparent;
  --btn-shadow: var(--elev-1);
}

.btn-secondary {
  --btn-bg: var(--bg-raised);
  --btn-fg: var(--text);
  --btn-line: var(--line-control);
  --btn-shadow: var(--elev-1);
}

.btn-quiet {
  --btn-bg: transparent;
  --btn-fg: var(--text-dim);
  --btn-line: transparent;
  --btn-bg-hover: var(--bg-hover);
  --btn-fg-hover: var(--text);
  --btn-line-hover: transparent;
  font-weight: var(--weight-medium);
}

.btn-danger {
  --btn-bg: transparent;
  --btn-fg: var(--danger-fg);
  --btn-line: color-mix(in srgb, var(--danger) 45%, transparent);
  --btn-bg-hover: var(--danger-bg);
  --btn-fg-hover: var(--danger-text);
  --btn-line-hover: var(--danger-line);
}

.btn-danger-solid {
  --btn-bg: var(--danger);
  --btn-fg: var(--danger-ink);
  --btn-line: transparent;
  --btn-bg-hover: var(--danger-hover);
  --btn-fg-hover: var(--danger-ink);
  --btn-line-hover: transparent;
}

.btn-icon {
  flex: 0 0 auto;
  width: var(--btn-h);
  padding: 0;
}

.btn-block {
  display: flex;
  width: 100%;
}

/* A borderless square button: the theme toggle, the menu, a close. */
.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: var(--ctl-h-md);
  height: var(--ctl-h-md);
  padding: 0;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur-1) ease, color var(--dur-1) ease;
}

@media (hover: hover) {
  .icon-button:hover {
    color: var(--text);
    background: color-mix(in srgb, var(--text) 6%, transparent);
  }
}

.icon-button:active {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 10%, transparent);
}

.icon-button svg {
  width: 17px;
  height: 17px;
}

@media (max-width: 720px) {
  .icon-button {
    width: var(--ctl-h-lg);
    height: var(--ctl-h-lg);
  }
}

/* The theme button shows where a click goes: the sun while dark, the moon
   while light. Chosen from <html> so the first paint is right. */
.theme-toggle .theme-icon-sun {
  display: none;
}

:root[data-theme='dark'] .theme-toggle .theme-icon-sun {
  display: inline;
}

:root[data-theme='dark'] .theme-toggle .theme-icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .theme-icon-sun {
    display: inline;
  }
  :root:not([data-theme]) .theme-toggle .theme-icon-moon {
    display: none;
  }
}

/* ---------------- segmented control ----------------
   For two or three choices that switch a view. A sunken track with the
   chosen one raised on it, the same everywhere (and in the dashboard).
   <div class="segmented" role="tablist"><button class="segment" role="tab" aria-selected="true">..</button></div>
   Links work too: <a class="segment" aria-current="page">. So do radios:
   <label><input type="radio" class="visually-hidden"><span class="segment">..</span></label>. */

.segmented {
  --seg-h: var(--ctl-h-md);
  display: inline-flex;
  gap: 2px;
  max-width: 100%;
  min-height: var(--seg-h);
  padding: 3px;
  background: var(--bg-tint);
  border: 1px solid var(--line);
  border-radius: calc(var(--r-md) + 2px);
}

.segment {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 0 0 auto;
  min-height: calc(var(--seg-h) - 8px);
  margin: 0;
  padding: 0 var(--space-3);
  font: inherit;
  font-size: var(--fs-13);
  font-weight: var(--weight-strong);
  line-height: 1.2;
  white-space: nowrap;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--dur-2) var(--ease-out), color var(--dur-1) ease, box-shadow var(--dur-2) ease;
}

.segment:hover {
  color: var(--text);
  text-decoration: none;
}

.segment[aria-selected='true'],
.segment[aria-current='page'],
.segment[aria-checked='true'],
.segment[aria-pressed='true'],
input:checked + .segment,
.segment:has(input:checked) {
  color: var(--text);
  background: var(--bg-raised);
  border-color: var(--line);
  box-shadow: var(--elev-1);
}

input:focus-visible + .segment,
.segment:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.segment .count,
.segment .pill {
  margin-left: 2px;
}

@media (max-width: 480px) {
  .segmented {
    display: flex;
    width: 100%;
  }
  .segment {
    flex: 1 1 0;
    min-width: 0;
    padding-inline: var(--space-2);
  }
}

/* ---------------- form fields ----------------
   field() in src/ui.ts writes:
   <div class="field">
     <label class="field-label" for="x">Email</label>
     <input class="field-input" id="x">
     <p class="field-hint">..</p>   <p class="field-error">..</p>
   </div> */

.form {
  display: grid;
  gap: var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  margin: 0;
}

.field-label {
  font-size: var(--type-small);
  font-weight: var(--weight-medium);
  line-height: var(--lh-snug);
  color: var(--text);
}

.field-optional {
  font-weight: 400;
  color: var(--text-faint);
}

.field-hint {
  font-size: var(--type-small);
  line-height: 1.45;
  color: var(--text-dim);
}

.field-input {
  width: 100%;
  min-height: var(--field-h);
  margin: 0;
  padding: 6px var(--field-px);
  font: inherit;
  font-size: var(--field-fs);
  line-height: var(--lh-snug);
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--line-strong);
  border-radius: var(--field-radius);
  transition: border-color var(--dur-1) ease, box-shadow var(--dur-2) ease;
}

textarea.field-input {
  min-height: calc(var(--field-h) * 2.4);
  padding-block: var(--space-2);
  resize: vertical;
}

select.field-input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: calc(var(--field-px) + 22px);
  background-image: var(--select-chevron);
  background-repeat: no-repeat;
  background-position: right var(--field-px) center;
  background-size: 14px 14px;
  cursor: pointer;
}

/* A file picker: the button looks like a secondary button, the name stays one line. */
input[type='file'].field-input {
  display: flex;
  align-items: center;
  padding: 3px;
  font-size: var(--fs-13);
  color: var(--text-dim);
  text-overflow: ellipsis;
  cursor: pointer;
}

input[type='file']::file-selector-button {
  min-height: calc(var(--field-h) - 8px);
  margin-right: var(--space-3);
  padding: 0 var(--space-3);
  font: inherit;
  font-size: var(--fs-13);
  font-weight: var(--weight-strong);
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--line-control);
  border-radius: var(--r-sm);
  box-shadow: var(--elev-1);
  cursor: pointer;
}

input[type='file']::file-selector-button:hover {
  background: var(--bg-hover);
}

.field-input::placeholder {
  color: var(--text-faint);
  opacity: 1;
}

.field-input:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--line-strong) 60%, var(--text-dim));
}

.field-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.field-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.field-input[aria-invalid='true'] {
  border-color: var(--danger);
}

.field-input[aria-invalid='true']:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 25%, transparent);
}

.field-error {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: var(--type-small);
  line-height: 1.4;
  font-weight: var(--weight-medium);
  color: var(--danger-fg);
}

/* A mark before the words, so the error is not told by color alone. */
.field-error::before {
  content: '!';
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 1.25em;
  height: 1.25em;
  margin-top: 0.05em;
  font-size: 0.85em;
  font-weight: 700;
  line-height: 1;
  color: var(--bg-raised);
  background: var(--danger-fg);
  border-radius: 50%;
}

.field-check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  font-size: var(--type-ui);
  line-height: 1.4;
  cursor: pointer;
}

.field-check input {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.field-row {
  display: flex;
  gap: var(--space-2);
  align-items: stretch;
}

.field-row > .field-input {
  flex: 1 1 auto;
  min-width: 0;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

@media (max-width: 480px) {
  .form-actions .btn {
    flex: 1 1 100%;
  }
}

/* A toggle for one setting that turns on or off at once.
   <label class="switch"><input type="checkbox" role="switch"> Words</label> */
.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--ctl-h-sm);
  font-size: var(--type-ui);
  cursor: pointer;
}

.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: 0 0 auto;
  width: 36px;
  height: 22px;
  margin: 0;
  background: var(--line-strong);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background-color var(--dur-2) ease;
}

.switch input::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform var(--dur-2) var(--ease-out);
}

.switch input:checked {
  background: var(--accent);
}

.switch input:checked::before {
  transform: translateX(14px);
}

.switch input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.switch input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------------- cards ----------------
   <section class="card">
     <div class="card-head"><div><h2 class="card-title">..</h2><p class="card-sub">..</p></div><div class="card-actions">..</div></div>
     ..
   </section> */

.card {
  min-width: 0;
  padding: var(--space-5);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.card-raised {
  background: var(--bg-raised);
  box-shadow: var(--elev-2);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
}

.card-head > :first-child {
  min-width: 0;
}

.card-title {
  font-size: var(--type-heading);
  font-weight: var(--weight-title);
  line-height: var(--lh-snug);
}

.card-sub {
  margin-top: var(--space-1);
  font-size: var(--type-small);
  line-height: 1.45;
  color: var(--text-dim);
}

/* Older cards stack a title and its line in a .stack: keep them one unit,
   as cardHead() does, instead of a full gap apart. */
.stack > .card-title + .muted,
.stack > .card-title + .card-sub,
.stack > .card-title + p:not([class]),
.stack > .row-between:has(> .card-title) + .muted,
.stack > .row-between:has(> .card-title) + p:not([class]) {
  margin-top: calc(var(--space-1) - var(--space-4));
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* Parts of one card, split by a hairline. */
.card-section + .card-section {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--line);
}

/* A card that is one big link. */
a.card-link {
  display: block;
  color: inherit;
  transition: border-color var(--dur-1) ease, box-shadow var(--dur-2) ease;
}

a.card-link:hover {
  border-color: var(--line-strong);
  box-shadow: var(--elev-1);
  text-decoration: none;
}

@media (max-width: 480px) {
  .card {
    padding: var(--space-4);
  }
}

/* ---------------- big numbers ----------------
   <div class="stat"><p class="stat-label">Visitors</p><p class="stat-value">1,147</p><p class="stat-note">last 7 days</p></div> */

.stat {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}

.stat-label {
  font-family: var(--mono);
  font-size: var(--type-label);
  font-weight: var(--weight-medium);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-faint);
}

.stat-value {
  font-size: var(--fs-28);
  font-weight: var(--weight-title);
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.stat-note {
  font-size: var(--type-small);
  color: var(--text-dim);
}

.num,
.tabular {
  font-variant-numeric: tabular-nums;
}

/* ---------------- chips, pills and badges ---------------- */

/* A filter chip: one choice in a row of many. Two or three choices that
   switch a view are a .segmented instead. */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--ctl-h-sm);
  padding: 0 var(--space-3);
  font: inherit;
  font-size: var(--fs-13);
  font-weight: var(--weight-medium);
  color: var(--text-dim);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur-1) ease, border-color var(--dur-1) ease, color var(--dur-1) ease;
}

.chip:hover {
  color: var(--text);
  border-color: var(--line-strong);
  text-decoration: none;
}

.chip[aria-pressed='true'],
.chip[aria-current='true'],
.chip[aria-current='page'] {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.chip .count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: var(--fs-11);
  font-weight: var(--weight-strong);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  /* 6.1:1 light, 6.9:1 dark: --bg-active would drop under 4.5. */
  background: var(--bg-tint);
  box-shadow: inset 0 0 0 1px var(--line);
  border-radius: var(--r-pill);
}

.chip[aria-pressed='true'] .count,
.chip[aria-current='page'] .count,
.chip[aria-current='true'] .count {
  /* On the raised ground the blue holds 5.9:1 light, 6.5:1 dark. */
  color: var(--accent);
  background: var(--bg-raised);
  box-shadow: none;
}

@media (max-width: 720px) {
  .chip {
    min-height: var(--ctl-h-lg);
    padding-inline: 14px;
  }
}

/* A status: small, soft, the same shape everywhere.
   Tones: (none) neutral, -ok, -warn, -danger, -accent, -info. */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 0 var(--space-2);
  font-family: var(--sans);
  font-size: var(--type-caption);
  font-weight: var(--weight-medium);
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-dim);
  background: var(--bg-tint);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  white-space: nowrap;
  vertical-align: middle;
}

.pill-ok {
  color: var(--success-fg);
  border-color: var(--success-line);
  background: var(--success-bg);
}

.pill-warn {
  color: var(--warning-fg);
  border-color: var(--warning-line);
  background: var(--warning-bg);
}

.pill-danger {
  color: var(--danger-text);
  border-color: var(--danger-line);
  background: var(--danger-bg);
}

.pill-accent,
.pill-info {
  color: var(--accent);
  border-color: var(--info-line);
  background: var(--accent-soft);
}

/* A live dot before a pill's words. */
.pill-dot::before {
  content: '';
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ---------------- checklist ----------------
   Steps with a progress bar: the setup checklist on /app (src/activation.ts).
   <section class="card checklist"><div class="checklist-head">..</div><div class="checklist-bar"><span style="width: 40%"></span></div>
     <ol class="checklist-steps"><li class="checklist-step is-done|is-next"><span class="checklist-mark"></span><div><p class="checklist-label">..</p><p class="checklist-why">..</p></div>(button)</li></ol>
   </section> */

.checklist {
  display: grid;
  gap: var(--space-3);
}

.checklist-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.checklist-head .muted {
  margin: 2px 0 0;
}

.checklist-bar {
  height: 6px;
  overflow: hidden;
  background: var(--bg-tint);
  border-radius: var(--r-pill);
}

.checklist-bar span {
  display: block;
  height: 100%;
  background: var(--success);
  border-radius: inherit;
  transition: width var(--dur-4) var(--ease-out);
}

.checklist-steps {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.checklist-step {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--ctl-h-lg);
  padding: 6px 0;
}

.checklist-step + .checklist-step {
  border-top: 1px solid var(--line);
}

.checklist-mark {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
}

.checklist-step.is-done .checklist-mark {
  color: var(--success-fg);
  background: var(--success-bg);
  border-color: var(--success-line);
}

.checklist-step.is-next .checklist-mark {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 4px var(--bg-raised), inset 0 0 0 11px var(--accent);
}

.checklist-step.is-done .checklist-label {
  color: var(--text-faint);
}

.checklist-step.is-next .checklist-label {
  font-weight: var(--weight-strong);
}

.checklist-why {
  margin: 2px 0 0;
  font-size: var(--type-small);
  color: var(--text-dim);
}

/* On a phone the next step's button goes under its words. */
@media (max-width: 520px) {
  .checklist-step.is-next {
    grid-template-columns: 22px minmax(0, 1fr);
  }
  .checklist-step.is-next .btn {
    grid-column: 2;
    justify-self: start;
  }
}

/* ---------------- notices ----------------
   notice() in src/ui.ts. A line that stays on the page. Things that just
   happened (saved, failed to save) are toasts instead. */

.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) 14px;
  font-size: var(--type-ui);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.notice > .notice-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  margin-top: 2px;
}

.notice > .notice-icon svg {
  width: 16px;
  height: 16px;
}

.notice-info > .notice-icon {
  color: var(--accent);
}

.notice-ok {
  color: var(--success-fg);
  background: var(--success-bg);
  border-color: var(--success-line);
}

.notice-warn {
  color: var(--warning-fg);
  background: var(--warning-bg);
  border-color: var(--warning-line);
}

.notice-error {
  color: var(--danger-text);
  background: var(--danger-bg);
  border-color: var(--danger-line);
}

.notice .btn {
  margin-left: auto;
}

/* ---------------- toasts ----------------
   window.sporetag.toast('Saved') in public/static/ui.js. One region, bottom
   right on a desk and bottom center on a phone. Polite for saves, assertive
   for errors. */

.toast-region {
  position: fixed;
  right: var(--space-6);
  bottom: var(--space-6);
  z-index: 300;
  display: grid;
  justify-items: end;
  gap: var(--space-2);
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 100%;
  min-height: var(--ctl-h-lg);
  padding: var(--space-2) var(--space-2) var(--space-2) 14px;
  font-size: var(--type-ui);
  line-height: 1.4;
  color: var(--bg);
  background: var(--text);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-3);
  pointer-events: auto;
  animation: ui-toast-in var(--dur-3) var(--ease-out);
}

.toast[data-leaving] {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity var(--dur-2) ease, transform var(--dur-2) ease;
}

.toast-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: #ffffff;
  background: var(--success);
}

.toast-error .toast-icon {
  background: var(--danger);
}

.toast-info .toast-icon {
  color: var(--accent-ink);
  background: var(--accent);
}

.toast-icon svg {
  width: 12px;
  height: 12px;
}

.toast-text {
  flex: 1 1 auto;
  min-width: 0;
}

.toast .icon-button {
  width: 32px;
  height: 32px;
  color: color-mix(in srgb, var(--bg) 70%, transparent);
}

.toast .icon-button:hover {
  color: var(--bg);
  background: color-mix(in srgb, var(--bg) 14%, transparent);
}

@keyframes ui-toast-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@media (max-width: 720px) {
  .toast-region {
    right: 50%;
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
    justify-items: center;
    transform: translateX(50%);
  }
}

/* ---------------- tables ----------------
   Numbers right-aligned in tabular figures (.num). The head sticks when the
   wrap scrolls (.table-wrap-tall). Rows light up under the pointer. */

.table-wrap {
  /* Positioned, so a visually-hidden label in a wide row scrolls with the table
     instead of widening the page (admin links and billing at 390px). */
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-panel);
}

.table-wrap-tall {
  max-height: min(70vh, 720px);
  overflow-y: auto;
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--type-ui);
}

.table th,
.table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 40px;
  padding-block: 0;
  font-family: var(--mono);
  font-size: var(--type-label);
  font-weight: var(--weight-medium);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
  background: var(--bg-panel);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr {
  transition: background-color var(--dur-1) ease;
}

.table tbody tr:hover td {
  background: color-mix(in srgb, var(--bg-hover) 60%, transparent);
}

.table .num,
.table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table-empty td {
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--text-dim);
}

/* ---------------- code ---------------- */

.code {
  position: relative;
  margin: 0;
  padding: 14px var(--space-4);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: var(--fs-13);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  white-space: pre;
}

.code-block {
  display: grid;
  gap: var(--space-2);
}

.code-block .row-between {
  flex-wrap: nowrap;
  font-size: var(--fs-13);
  color: var(--text-dim);
}

.code-block .row-between > .btn {
  flex: 0 0 auto;
}

/* Snippets in the app wrap instead of scrolling: one line of HTML reads whole,
   with no scroll bars at any width. Line breaks in longer code are kept. */
.code-block:not(.doc-code) .code {
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

:not(pre) > code {
  padding: 1px 5px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
}

/* A key on the keyboard. */
.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  font-family: var(--sans);
  font-size: var(--fs-11);
  font-weight: var(--weight-medium);
  line-height: 1;
  color: var(--text-dim);
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
}

/* ---------------- empty state ----------------
   emptyState() in src/ui.ts: one icon, one line, one action. */

.empty {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-10) var(--space-6);
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background-color: var(--bg-panel);
  background-image: radial-gradient(var(--site-dot) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* Inside a card: no second frame. */
.card .empty,
.empty-plain {
  padding: var(--space-8) var(--space-4);
  border: 0;
  background: none;
}

.empty-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--space-1);
  border-radius: var(--r-lg);
  color: var(--accent);
  background: var(--accent-soft);
}

.empty-mark svg {
  width: 20px;
  height: 20px;
}

.empty-title {
  font-size: var(--type-heading);
  font-weight: var(--weight-title);
  line-height: var(--lh-snug);
  color: var(--text);
}

.empty p:not(.empty-title) {
  max-width: 40ch;
  font-size: var(--type-ui);
  color: var(--text-dim);
}

.empty .btn {
  margin-top: var(--space-2);
}

/* ---------------- loading skeletons ----------------
   Grey shapes where slow numbers and lists will land, so the page does not
   jump. A soft sweep while waiting; still under reduced motion. */

.skeleton {
  display: block;
  min-height: 12px;
  color: transparent !important;
  background: linear-gradient(90deg, var(--bg-active) 0%, var(--bg-hover) 50%, var(--bg-active) 100%) 0 0 / 200% 100%;
  border-radius: var(--r-sm);
  animation: ui-shimmer 1.4s ease-in-out infinite;
  user-select: none;
}

.skeleton-line {
  height: 12px;
  margin-block: 6px;
}

.skeleton-num {
  width: 5ch;
  height: 28px;
}

.skeleton-row {
  height: 40px;
  margin-bottom: var(--space-2);
}

@keyframes ui-shimmer {
  to {
    background-position: -200% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
  }
}

/* ---------------- menus ----------------
   A dropdown is a <details data-menu> (site.js closes it on a click outside
   and on Escape, and moves with the arrow keys): its <summary> is the button,
   then .menu-list holds .menu-row items. */

.dropdown {
  position: relative;
}

.dropdown > summary {
  list-style: none;
}

.dropdown > summary::-webkit-details-marker {
  display: none;
}

.dropdown[open] > summary.btn {
  color: var(--text);
  background: var(--bg-hover);
}

/* A small mono heading over a group of rows. */
.menu-heading {
  padding: var(--space-2) 10px var(--space-1);
  font-family: var(--mono);
  font-size: var(--type-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-faint);
}

.menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  min-width: 220px;
  max-width: calc(100vw - 24px);
  padding: var(--space-1);
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-3);
  transform-origin: top right;
  animation: ui-pop var(--dur-2) var(--ease-out);
}

.menu-list-start {
  right: auto;
  left: 0;
  transform-origin: top left;
}

@keyframes ui-pop {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
}

.sheet-row,
.menu-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--ctl-h-md);
  padding: 6px 10px;
  text-align: left;
  font: inherit;
  font-size: var(--type-ui);
  line-height: 1.25;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: var(--r-md);
  cursor: pointer;
  text-decoration: none;
}

.sheet-row {
  min-height: var(--ctl-h-lg);
  font-size: var(--fs-15);
}

.menu-row svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
}

.sheet-row:hover,
.menu-row:hover,
.menu-row:focus-visible {
  background: var(--bg-hover);
  text-decoration: none;
}

.menu-row:hover svg {
  color: var(--accent);
}

.menu-row:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.menu-row-danger,
.menu-row-danger svg {
  color: var(--danger-fg);
}

.sheet-row[aria-current='page'] {
  color: var(--accent);
  font-weight: var(--weight-strong);
}

.menu-sep {
  height: 1px;
  margin: var(--space-1) var(--space-1);
  background: var(--line);
}

.menu-list form {
  margin: 0;
}

@media (max-width: 720px) {
  .menu-row {
    min-height: var(--ctl-h-lg);
    font-size: var(--fs-15);
  }
}

/* ---------------- dialogs and sheets ----------------
   A native <dialog class="dialog"> opened with showModal(): the browser
   traps focus and closes it on Escape; ui.js puts focus back where it was.
   On a phone it rises from the bottom as a sheet. */

.dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: min(86vh, 760px);
  padding: 0;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--elev-4);
  overflow: auto;
  overscroll-behavior: contain;
}

/* A yes-or-no question: narrow, the answer bottom right. */
.dialog-confirm {
  width: min(420px, calc(100vw - 32px));
}

.dialog-confirm .dialog-body p {
  color: var(--text-dim);
}

.dialog[open] {
  animation: ui-dialog-in var(--dur-3) var(--ease-out);
}

.dialog::backdrop {
  background: var(--scrim);
  animation: ui-fade var(--dur-3) ease;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) 0 var(--space-6);
}

.dialog-title {
  font-size: var(--type-title);
  font-weight: var(--weight-title);
  line-height: var(--lh-snug);
  letter-spacing: var(--track-title);
}

.dialog-head .icon-button {
  margin: -6px -6px 0 0;
}

.dialog-body {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
}

.dialog-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6) var(--space-5);
}

@keyframes ui-dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@keyframes ui-fade {
  from {
    opacity: 0;
  }
}

@media (max-width: 720px) {
  .dialog {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .dialog[open] {
    animation-name: ui-sheet-in;
  }
  .dialog-foot .btn {
    flex: 1 1 0;
  }
}

@keyframes ui-sheet-in {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

/* ---------------- command palette ----------------
   Cmd+K or Ctrl+K anywhere in the app (public/static/ui.js). */

.cmdk {
  width: min(620px, calc(100vw - 32px));
  max-height: min(72vh, 620px);
  margin: 12vh auto auto;
  padding: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--elev-4);
}

.cmdk[open] {
  display: flex;
  flex-direction: column;
  animation: ui-dialog-in var(--dur-2) var(--ease-out);
}

.cmdk::backdrop {
  background: var(--scrim);
}

.cmdk-search {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--line);
}

.cmdk-search svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  color: var(--text-faint);
}

.cmdk-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 52px;
  padding: 0;
  font: inherit;
  font-size: var(--fs-16);
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
}

.cmdk-input::placeholder {
  color: var(--text-faint);
}

.cmdk-list {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: var(--space-2);
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.cmdk-group {
  padding: var(--space-3) 10px var(--space-1);
  font-family: var(--mono);
  font-size: var(--type-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--text-faint);
}

.cmdk-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 40px;
  padding: 0 10px;
  font-size: var(--type-ui);
  color: var(--text);
  border-radius: var(--r-md);
  cursor: pointer;
}

.cmdk-item svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
}

.cmdk-item[aria-selected='true'] {
  background: var(--bg-active);
}

.cmdk-item[aria-selected='true'] svg {
  color: var(--accent);
}

.cmdk-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cmdk-hint {
  flex: 0 0 auto;
  font-size: var(--type-caption);
  color: var(--text-faint);
}

.cmdk-keys {
  display: inline-flex;
  gap: 3px;
}

.cmdk-none {
  padding: var(--space-8) var(--space-4);
  text-align: center;
  font-size: var(--type-ui);
  color: var(--text-dim);
}

.cmdk-foot {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  padding: 10px var(--space-4);
  font-size: var(--type-caption);
  color: var(--text-faint);
  border-top: 1px solid var(--line);
  background: var(--bg-panel);
}

.cmdk-foot span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* No keyboard on a touch screen: no key hints. */
@media (hover: none) {
  .cmdk-foot,
  .cmdk-item .cmdk-keys {
    display: none;
  }
}

/* The search hint in the app header: opens the palette. */
.cmdk-open {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 200px;
  height: var(--ctl-h-sm);
  padding: 0 6px 0 10px;
  font: inherit;
  font-size: var(--fs-13);
  color: var(--text-faint);
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color var(--dur-1) ease, color var(--dur-1) ease;
}

.cmdk-open:hover {
  color: var(--text-dim);
  border-color: var(--line-strong);
}

.cmdk-open svg {
  width: 15px;
  height: 15px;
}

.cmdk-open .cmdk-keys {
  margin-left: auto;
}

@media (max-width: 860px) {
  .cmdk-open {
    min-width: 0;
    width: var(--ctl-h-lg);
    height: var(--ctl-h-lg);
    padding: 0;
    justify-content: center;
    background: transparent;
    border-color: transparent;
  }
  .cmdk-open .cmdk-open-text,
  .cmdk-open .cmdk-keys {
    display: none;
  }
  .cmdk {
    margin-top: var(--space-4);
    max-height: calc(100dvh - 32px);
  }
}

/* ---------------- phone tap targets ----------------
   Links that act like buttons get a finger's height on a phone. Links inside
   running text keep their line. */
@media (max-width: 720px) {
  .site-card-foot a,
  .site-card-foot .btn {
    display: inline-flex;
    align-items: center;
    min-height: var(--ctl-h-lg);
  }
  .scs-action,
  .site-card-name,
  .link-short,
  .link-head-short > a,
  .crumbs a,
  .code-block .row-between a {
    display: inline-flex;
    align-items: center;
    min-height: var(--ctl-h-sm);
  }
}
