/* ============================================================
   APPY — base
   Reset, typing defaults, and the shared control vocabulary.
   ============================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--t-md);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
p,
figure,
blockquote,
ol,
ul {
  margin: 0;
}

ol,
ul {
  padding: 0;
}

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

/* Icons are inline drawings: give every one a size and a stroke so a button
   never inherits the SVG default canvas (300x150) or a black fill. Specific
   places (theme button, reader tools, search field) can still override. */
svg {
  display: block;
  flex: none;
  width: 1em;
  height: 1em;
  max-width: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

a {
  color: inherit;
  text-decoration-color: color-mix(in srgb, var(--clay) 45%, transparent);
  text-underline-offset: 0.18em;
}

a:hover {
  text-decoration-color: var(--clay);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

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

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 1px;
}

[hidden] {
  display: none !important;
}

/* ---------- skipping and announcers ---------- */

.skip-link {
  position: fixed;
  top: 0;
  left: 50%;
  z-index: 200;
  transform: translate(-50%, -120%);
  padding: 0.6rem 1rem;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  font-size: var(--t-sm);
  text-decoration: none;
  transition: transform var(--fast) var(--ease);
}

.skip-link:focus-visible {
  transform: translate(-50%, 0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- the small-caps label ---------- */

.label {
  margin: 0;
  color: var(--muted);
  font-family: var(--sans);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.label.is-accent {
  color: var(--clay);
}

.dim {
  color: var(--muted);
}

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

/* ---------- headings ---------- */

.display {
  font-family: var(--serif);
  font-weight: 400;
  line-height: 1.06;
  letter-spacing: -0.022em;
  text-wrap: balance;
}

h1.display {
  font-size: var(--t-3xl);
}

h2.display {
  font-size: var(--t-2xl);
  letter-spacing: -0.018em;
}

h3.display {
  font-size: var(--t-xl);
  letter-spacing: -0.01em;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-family: var(--sans);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.eyebrow::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

/* ---------- buttons ---------- */

.btn {
  --btn-bg: transparent;
  --btn-fg: var(--ink);
  --btn-bd: var(--rule);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--btn-bd);
  border-radius: var(--r-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-family: var(--sans);
  font-size: var(--t-sm);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
    color var(--fast) var(--ease), transform var(--fast) var(--ease);
}

.btn:hover {
  border-color: var(--ink-2);
}

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

.btn--primary {
  --btn-bg: var(--ink);
  --btn-fg: var(--paper);
  --btn-bd: var(--ink);
}

.btn--primary:hover {
  --btn-bg: var(--clay);
  --btn-bd: var(--clay);
  --btn-fg: #fff8f0;
}

.btn--ghost {
  --btn-bd: transparent;
  --btn-fg: var(--muted);
}

.btn--ghost:hover {
  --btn-bg: var(--surface-3);
  --btn-bd: transparent;
  --btn-fg: var(--ink);
}

.btn--danger {
  --btn-fg: var(--danger);
  --btn-bd: color-mix(in srgb, var(--danger) 35%, var(--rule));
}

.btn--danger:hover {
  --btn-bg: var(--danger-wash);
  --btn-bd: var(--danger);
}

.btn--sm {
  min-height: 2rem;
  padding: 0.3rem 0.65rem;
  font-size: var(--t-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.btn--wide {
  width: 100%;
}

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

/* A text link that behaves like a control. */
.linkish {
  padding: 0;
  border: 0;
  background: none;
  color: var(--clay);
  font-family: var(--sans);
  font-size: var(--t-sm);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--clay) 40%, transparent);
  text-underline-offset: 0.2em;
  cursor: pointer;
}

.linkish:hover {
  text-decoration-color: var(--clay);
}

/* Square icon button, 40px hit area. */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--muted);
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}

.icon-btn:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.icon-btn[aria-pressed="true"] {
  background: var(--surface-3);
  color: var(--ink);
}

.icon-btn svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- fields ---------- */

.field {
  display: block;
  min-width: 0;
}

.field > .label {
  margin-bottom: 0.4rem;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--t-sm);
  line-height: 1.5;
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: color-mix(in srgb, var(--rule) 40%, var(--muted));
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--clay);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--clay) 14%, transparent);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--faint);
}

.select {
  appearance: none;
  padding-right: 2rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 1.1rem) 1.05rem, calc(100% - 0.75rem) 1.05rem;
  background-size: 0.35rem 0.35rem, 0.35rem 0.35rem;
  background-repeat: no-repeat;
}

/* ---------- chips & tags ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--sans);
  font-size: var(--t-xs);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.chip--dot::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--chip-dot, var(--clay));
}

/* ---------- dividers ---------- */

.rule {
  height: 1px;
  border: 0;
  margin: var(--s-5) 0;
  background: var(--rule);
}

/* ---------- tables of things ---------- */

.stack {
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.spacer {
  flex: 1;
}

/* ---------- motion primitives ---------- */

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

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  @keyframes rise-in {
    from,
    to {
      opacity: 1;
      transform: none;
    }
  }
}
