/* d-pill base. Copy into the project. Paste the direction override after this file. */

:root {
  color-scheme: light;
  --hue: 215;
  --chroma-neutral: 0.008;

  --bg: oklch(0.985 var(--chroma-neutral) var(--hue));
  --bg-subtle: oklch(0.965 var(--chroma-neutral) var(--hue));
  --surface: oklch(0.995 0.004 var(--hue));
  --ink: oklch(0.27 0.018 var(--hue));
  --ink-muted: oklch(0.46 0.016 var(--hue));
  --line: oklch(0.86 0.01 var(--hue));
  --line-strong: oklch(0.62 0.016 var(--hue));

  --accent: oklch(0.47 0.12 var(--hue));
  --accent-ink: oklch(0.985 0.005 var(--hue));
  --accent-soft: oklch(0.94 0.025 var(--hue));
  --focus: var(--accent);

  --danger: oklch(0.47 0.15 25);
  --danger-ink: oklch(0.985 0.005 25);
  --danger-soft: oklch(0.95 0.02 25);
  --ok: oklch(0.42 0.09 155);
  --warn: oklch(0.45 0.09 70);

  --font-display: "Instrument Sans", "Avenir Next", "Segoe UI", sans-serif;
  --font-text: "Instrument Sans", "Avenir Next", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-md: 0.9375rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
  --text-2xl: 2.25rem;
  --text-3xl: 3.5rem;
  --leading-display: 1.05;
  --leading-ui: 1.35;
  --leading-body: 1.55;
  --tracking-display: -0.02em;
  --tracking-caps: 0.06em;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;
  --space-9: 6rem;
  --space-10: 8rem;

  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;
  --radius-full: 999px;

  --border: 1px solid var(--line);
  --border-strong: 1px solid var(--line-strong);
  --shadow-overlay: 0 16px 40px oklch(0.25 0.02 var(--hue) / 0.16);

  --dur-1: 120ms;
  --dur-2: 180ms;
  --dur-3: 240ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.7, 0, 0.84, 0);

  --z-sticky: 10;
  --z-dropdown: 20;
  --z-drawer: 40;
  --z-dialog: 50;
  --z-toast: 60;

  --measure: 68ch;
  --page: 72rem;
  --control-h: 2.25rem;
  --header-h: 3.5rem;
  --section-pad: var(--space-8);
  --row-pad: var(--space-3);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: oklch(0.17 0.008 var(--hue));
  --bg-subtle: oklch(0.21 0.01 var(--hue));
  --surface: oklch(0.2 0.01 var(--hue));
  --ink: oklch(0.93 0.008 var(--hue));
  --ink-muted: oklch(0.74 0.014 var(--hue));
  --line: oklch(0.32 0.01 var(--hue));
  --line-strong: oklch(0.55 0.014 var(--hue));
  --accent: oklch(0.78 0.12 var(--hue));
  --accent-ink: oklch(0.18 0.02 var(--hue));
  --accent-soft: oklch(0.28 0.03 var(--hue));
  --danger: oklch(0.74 0.12 25);
  --danger-ink: oklch(0.18 0.03 25);
  --danger-soft: oklch(0.28 0.04 25);
  --ok: oklch(0.78 0.09 155);
  --warn: oklch(0.82 0.09 75);
  --shadow-overlay: 0 16px 40px oklch(0.05 0.01 var(--hue) / 0.55);
}

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

html {
  text-size-adjust: 100%;
  hanging-punctuation: first last;
  background: var(--bg);
  scroll-padding-top: calc(var(--header-h) + var(--space-4));
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-width: thin;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: var(--text-md);
  line-height: var(--leading-body);
  letter-spacing: 0;
  font-synthesis: none;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
}

/* Outline is cleared on :focus only because :focus-visible draws it back. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

::selection { background: var(--accent-soft); color: var(--ink); }

img, svg, video { display: block; max-width: 100%; }
img { border-radius: var(--radius); }

h1, h2, h3, h4, p, figure, blockquote { margin: 0; }
h1, h2, h3, h4 { scroll-margin-top: calc(var(--header-h) + var(--space-4)); }


h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: var(--tracking-display);
  line-height: var(--leading-display);
  text-wrap: balance;
}

h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); font-weight: 600; letter-spacing: 0; }
p { text-wrap: pretty; widows: 2; orphans: 2; }

.display {
  font-size: clamp(2.75rem, 6vw, 4.75rem);
  line-height: 1.02;
}

.lede {
  max-width: 36ch;
  font-size: var(--text-lg);
  line-height: var(--leading-ui);
  color: var(--ink);
}

.quiet { color: var(--ink-muted); font-size: var(--text-sm); line-height: var(--leading-ui); }

.caps {
  font-family: var(--font-text);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--ink-muted);
}

.num { font-variant-numeric: tabular-nums; }
.mono, code, kbd, pre { font-family: var(--font-mono); }
code, kbd { font-size: 0.92em; }

pre {
  background: var(--bg-subtle);
  padding: var(--space-4);
  overflow: auto;
  border-radius: var(--radius);
  line-height: 1.5;
  font-size: var(--text-sm);
}

blockquote {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  line-height: 1.25;
  letter-spacing: var(--tracking-display);
  max-width: 28ch;
}

figcaption, blockquote footer {
  font-family: var(--font-text);
  font-size: var(--text-sm);
  font-style: normal;
  letter-spacing: 0;
  color: var(--ink-muted);
}

a {
  color: inherit;
  text-underline-offset: 0.18em;
  text-decoration-skip-ink: auto;
}
button, a, summary { -webkit-tap-highlight-color: transparent; }
:where(p, li, blockquote, figcaption) a {
  text-decoration: underline;
  text-decoration-thickness: 1px;
}

hr { border: 0; border-top: var(--border); margin: 0; width: 100%; }

.skip {
  position: absolute;
  left: var(--space-4);
  top: var(--space-2);
  transform: translateY(-150%);
  background: var(--ink);
  color: var(--bg);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  z-index: var(--z-toast);
  text-decoration: none;
}
.skip:focus { transform: none; }

.shell { min-height: 100dvh; display: grid; grid-template-columns: 14rem 1fr; }
.frame { width: min(var(--page), calc(100% - var(--space-8))); margin-inline: auto; }
.work { min-width: 0; padding: var(--space-5); }
.measure { max-width: var(--measure); }
.section { padding-block: var(--section-pad); }

.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack.tight { gap: var(--space-2); }
.stack.loose { gap: var(--space-8); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.cluster.between { justify-content: space-between; width: 100%; }
.cluster.end { justify-content: flex-end; }

.split {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: var(--space-8);
  align-items: center;
}
.split > * { min-width: 0; }

.topbar, .nav-side {
  background: var(--bg);
  z-index: var(--z-sticky);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  padding-inline: var(--space-5);
  border-bottom: var(--border);
  position: sticky;
  top: 0;
}
.wordmark { font-weight: 600; letter-spacing: -0.02em; text-decoration: none; }
.nav-links { display: flex; gap: var(--space-4); align-items: center; }
.nav-links a { text-decoration: none; color: var(--ink-muted); }
.nav-links a:hover { color: var(--ink); }
nav a[aria-current="page"] {
  color: var(--ink);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--accent);
}
.nav-menu { display: none; }

.nav-side {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-3);
  border-right: var(--border);
}
.nav-side a {
  text-decoration: none;
  color: var(--ink-muted);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
}
.nav-side a:hover { color: var(--ink); background: var(--bg-subtle); }
.nav-side a[aria-current="page"] {
  box-shadow: none;
  background: var(--accent-soft);
  color: var(--ink);
}

.rows { list-style: none; margin: 0; padding: 0; }
.rows > li {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: var(--space-4);
  align-items: center;
  min-height: var(--control-h);
  padding-block: var(--row-pad);
  border-top: var(--border);
}
.rows > li:last-child { border-bottom: var(--border); }
.rows.interactive > li { cursor: pointer; }
.rows.interactive > li:hover { background: var(--bg-subtle); }

.measure :where(ul, ol) {
  margin: 0;
  padding-inline-start: 1.15em;
  display: grid;
  gap: var(--space-2);
}

button, .btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--control-h);
  padding-inline: var(--space-3);
  border-radius: var(--radius);
  border: var(--border-strong);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}
button:hover, .btn:hover { background: var(--bg-subtle); }
:is(button, .btn).primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
:is(button, .btn).primary:hover { background: color-mix(in oklch, var(--accent) 92%, black); }
:is(button, .btn).ink {
  background: var(--ink);
  color: var(--bg);
  border-color: transparent;
}
:is(button, .btn).ink:hover { background: color-mix(in oklch, var(--ink) 88%, var(--bg)); }
:is(button, .btn).danger {
  background: var(--danger);
  color: var(--danger-ink);
  border-color: transparent;
}
:is(button, .btn).danger:hover { background: color-mix(in oklch, var(--danger) 90%, black); }
:is(button, .btn).ghost { border-color: transparent; background: transparent; }
:is(button, .btn).ghost:hover { background: var(--bg-subtle); }
:is(button, .btn).icon { width: var(--control-h); padding-inline: 0; }
button svg, .icon svg { width: 1.25rem; height: 1.25rem; }
button:active, .btn:active { background: color-mix(in oklch, var(--ink) 8%, transparent); }
:is(button, .btn).primary:active { background: color-mix(in oklch, var(--accent) 82%, black); }
:is(button, .btn).ink:active { background: color-mix(in oklch, var(--ink) 80%, var(--bg)); }
:is(button, .btn).danger:active { background: color-mix(in oklch, var(--danger) 82%, black); }
button:disabled, button[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; align-items: stretch; gap: var(--space-1); }
.field > span, .field > label { font-size: var(--text-sm); font-weight: 500; line-height: var(--leading-ui); }
.hint { color: var(--ink-muted); font-size: var(--text-sm); }
.error { color: var(--danger); font-size: var(--text-sm); }

input, select, textarea {
  width: 100%;
  height: var(--control-h);
  padding-inline: var(--space-3);
  border: var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  caret-color: var(--accent);
  font: inherit;
  font-size: var(--text-md);
}
textarea { height: auto; min-height: 6.5rem; padding-block: var(--space-2); resize: vertical; }
::placeholder { color: var(--ink-muted); opacity: 1; }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] {
  border-color: var(--danger);
}
input[type="checkbox"], input[type="radio"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
  padding: 0;
}
label.choice {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-h);
}

table { border-collapse: collapse; width: 100%; }
th, td {
  text-align: start;
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border);
  vertical-align: baseline;
}
th {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink-muted);
}
td.num, th.num { text-align: end; }

dialog {
  width: min(28rem, calc(100vw - var(--space-6)));
  margin: auto;
  padding: var(--space-5);
  border: var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-overlay);
  overscroll-behavior: contain;
}
dialog.wide { width: min(40rem, calc(100vw - var(--space-6))); }
dialog::backdrop { background: oklch(0.2 0.01 var(--hue) / 0.45); }
dialog h2 { font-size: var(--text-lg); }

details.menu { position: relative; }
details.menu > summary {
  list-style: none;
  cursor: pointer;
  height: var(--control-h);
  display: inline-flex;
  align-items: center;
}
details.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-1));
  z-index: var(--z-dropdown);
  min-width: 12rem;
  display: grid;
  gap: calc(var(--space-1) / 2);
  padding: var(--space-2);
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-overlay);
}
.menu-panel a, .menu-panel button {
  justify-content: flex-start;
  width: 100%;
  border: 0;
  background: transparent;
  padding-inline: var(--space-3);
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.menu-panel a:hover, .menu-panel button:hover { background: var(--bg-subtle); }
.menu-panel button.danger { color: var(--danger); background: transparent; }
.menu-panel button.danger:hover { background: var(--danger-soft); color: var(--danger); }
details[open] .menu-panel { animation: rise var(--dur-2) var(--ease-out); }

@keyframes rise {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

.banner {
  padding: var(--space-3) var(--space-4);
  background: var(--accent-soft);
  color: var(--ink);
  font-size: var(--text-sm);
}
.banner.danger { background: var(--danger-soft); }

.toasts {
  position: fixed;
  z-index: var(--z-toast);
  right: var(--space-5);
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.toast {
  background: var(--ink);
  color: var(--bg);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
}

button, .btn, a, input, select, textarea, summary {
  transition:
    background var(--dur-1) var(--ease-out),
    color var(--dur-1) var(--ease-out),
    border-color var(--dur-1) var(--ease-out);
}

/* iOS zooms focused inputs under 16px. Coarse pointers also need a 44px target. */
@media (pointer: coarse) {
  :root { --control-h: 2.75rem; }
  input, select, textarea { font-size: 1rem; }
}

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .nav-side {
    flex-direction: row;
    overflow: auto;
    border-right: 0;
    border-bottom: var(--border);
    position: sticky;
    top: 0;
  }
  .split { grid-template-columns: 1fr; gap: var(--space-5); }
  .frame { width: min(var(--page), calc(100% - var(--space-6))); }
  .section { padding-block: min(var(--section-pad), var(--space-8)); }
  .rows > li { grid-template-columns: 1fr auto; }
  .nav-links { display: none; }
  .nav-menu { display: inline-flex; }
  .display { font-size: clamp(2.25rem, 11vw, 3.25rem); }
}

html[data-theme="dark"] :is(button, .btn).primary:hover {
  background: color-mix(in oklch, var(--accent) 88%, white);
}
html[data-theme="dark"] :is(button, .btn).danger:hover {
  background: color-mix(in oklch, var(--danger) 88%, white);
}

@media (prefers-contrast: more) {
  :root {
    --ink-muted: var(--ink);
    --line: var(--line-strong);
    --line-strong: var(--ink);
  }
}

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