/* Reset, type and the shared components (DESIGN.md "Components"). Colours and fonts come
   from tokens.css only. */

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

* {
  margin: 0;
}

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

/* Page to page: the browser cross-fades same-origin navigations, and the sidebar, marked
   with its own view-transition-name in layout.css, stays still. */
@view-transition {
  navigation: auto;
}

::view-transition-old(root) {
  animation: vt-out var(--dur) var(--ease-out) both;
}

::view-transition-new(root) {
  animation: vt-in var(--dur-slow) var(--ease-out) both;
}

@keyframes vt-out {
  to {
    opacity: 0;
    transform: translateY(-6px);
  }
}

@keyframes vt-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

body {
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background: var(--bg);
}


::selection {
  background: var(--accent-solid);
  color: var(--on-accent);
}

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

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

img {
  height: auto;
}

a {
  color: inherit;
  text-decoration: none;
}

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

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

ul,
ol {
  padding: 0;
  list-style: none;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: var(--pill);
}
::-webkit-scrollbar-thumb:hover {
  background-color: var(--line-strong);
}

/* ---------- Layout helpers ---------- */

.wrap {
  width: min(100% - (var(--gutter) * 2), var(--max));
  margin-inline: auto;
}

.section {
  position: relative;
  padding-block: var(--section);
}

.section--tight {
  padding-block: clamp(2rem, 4vw, 3.5rem);
}

.stack {
  display: grid;
  gap: 1.25rem;
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

/* ---------- Type ---------- */

.eyebrow {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  font-weight: 400;
  color: var(--muted);
}

.h1 {
  font-size: var(--step-5);
  font-weight: 800;
  letter-spacing: -0.035em;
}

.h2 {
  font-size: var(--step-4);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.h3 {
  font-size: var(--step-2);
}

.lede {
  max-width: 62ch;
  font-size: var(--step-1);
  line-height: 1.55;
  color: var(--text-2);
}

.mono {
  font-family: var(--font-mono);
  font-size: var(--step--1);
}

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

.dew {
  color: var(--text);
}

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

.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.4rem;
  padding: 0 0.35rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: var(--step--2);
  line-height: 1.5;
  color: var(--muted);
}

.page-hero {
  position: relative;
  padding-top: clamp(2.5rem, 6vw, 5rem);
  padding-bottom: clamp(1.5rem, 3vw, 2.5rem);
}

.page-title {
  max-width: 20ch;
  font-size: var(--step-4);
  font-weight: 800;
  letter-spacing: -0.035em;
}

.page-hero .lede {
  margin-top: 1rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.2rem;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--muted);
  transition: color var(--dur) var(--ease-out);
}

.back-link:hover {
  color: var(--accent);
}

.link-arrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--accent);
}

.link-arrow svg {
  transition: transform var(--dur) var(--ease-out);
}

.link-arrow:hover svg {
  transform: translateX(4px);
}

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

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.5rem;
  padding: 0.55rem 1.05rem;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: var(--surface);
  color: var(--text);
  font-size: var(--step-0);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition:
    transform var(--dur-fast) var(--ease-out),
    background-color var(--dur) var(--ease-out),
    border-color var(--dur) var(--ease-out),
    box-shadow var(--dur) var(--ease-out),
    color var(--dur) var(--ease-out);
}

.btn:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.btn:active {
  transform: scale(0.97);
}

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

.btn--primary,
.btn--leaf {
  border-color: transparent;
  background: var(--brand);
  color: var(--on-brand);
  box-shadow: var(--glow);
}

.btn--primary:hover,
.btn--leaf:hover {
  border-color: transparent;
  background: var(--brand-hover);
}

.btn--ghost {
  background: transparent;
  box-shadow: none;
}

.btn--danger {
  border-color: var(--danger-edge);
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: none;
}

.btn--danger:hover {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.btn--solid-danger {
  border-color: transparent;
  background: var(--danger-solid);
  color: var(--on-accent);
}

.btn--sm {
  min-height: 2rem;
  padding: 0.35rem 0.8rem;
  font-size: var(--step--1);
}

.btn--icon {
  width: 2.25rem;
  min-height: 2.25rem;
  padding: 0;
  border-radius: var(--radius-sm);
}

.btn svg {
  flex: none;
  transition: transform var(--dur) var(--ease-out);
}

/* A button whose request is running: htmx marks it with .htmx-request, forms with aria-busy. */
.btn.htmx-request,
.btn[aria-busy='true'] {
  color: transparent;
  pointer-events: none;
}

.btn.htmx-request::after,
.btn[aria-busy='true']::after {
  content: '';
  position: absolute;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  border-top-color: var(--text);
  animation: spin 0.7s linear infinite;
}

.btn--primary.htmx-request::after,
.btn--leaf.htmx-request::after,
.btn--primary[aria-busy='true']::after,
.btn--leaf[aria-busy='true']::after {
  border-color: var(--line-strong);
  border-top-color: var(--on-brand);
}

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

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

.tag,
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.65rem;
  border-radius: var(--pill);
  background: var(--surface-2);
  font-size: var(--step--1);
  font-weight: 600;
  line-height: 1.5;
  color: var(--text-2);
}

/* A status dot that glows: <span class="status status--ok">Active</span>. */
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0.6rem;
  border-radius: var(--pill);
  background: var(--surface-2);
  font-size: var(--step--1);
  font-weight: 600;
  line-height: 1.5;
  color: var(--text-2);
}

.status::before,
.tag::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}

.status--ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.status--warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.status--danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.status--accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.status--sky {
  background: var(--sky-soft);
  color: var(--sky);
}

/* A count: filled violet with a ring, readable at a glance. */
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.4rem;
  border-radius: var(--pill);
  background: var(--accent-strong);
  box-shadow: var(--badge-ring);
  color: var(--on-accent);
  font-size: var(--step--2);
  font-weight: 700;
  line-height: 1;
}

/* ---------- Surfaces ---------- */

.card {
  border: 1px solid var(--surface-edge);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: var(--surface-2);
}

.segmented > * {
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 600;
  transition: background-color var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
}

.segmented > [aria-current='page'],
.segmented > [aria-selected='true'],
.segmented > .is-on {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

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

.input,
.field input:not([type='checkbox']):not([type='radio']),
.field select,
.field textarea {
  width: 100%;
  min-height: 2.6rem;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--text);
  transition: border-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}

.input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 0;
  border-color: var(--accent-edge);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  transition: border-color var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}

.search:focus-within {
  border-color: var(--accent-edge);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

/* A filter that can be added: dashed until it holds a value. */
.filter {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: var(--step--1);
  transition: border-color var(--dur) var(--ease-out), background-color var(--dur) var(--ease-out);
}

.filter:hover,
.filter.is-on {
  border-color: var(--accent-solid);
  background: var(--accent-soft);
  color: var(--accent);
}

input[type='checkbox'],
input[type='radio'] {
  accent-color: var(--accent-solid);
}

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

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  padding: 0.65rem 0.75rem;
  font-family: var(--font-mono);
  font-size: var(--step--2);
  font-weight: 400;
  text-align: left;
  text-transform: uppercase;
  color: var(--muted);
}

.table td {
  padding: 0.7rem 0.75rem;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}

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

.table tbody tr:hover,
.table tbody tr.is-selected {
  background: var(--accent-soft);
}

/* Rows that arrive or change after a request slide in. */
.table tbody tr.htmx-added,
.swap-in {
  animation: row-in var(--dur-slow) var(--ease-out) both;
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ---------- Toasts ---------- */

.toasts {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 120;
  display: grid;
  gap: 0.6rem;
  width: min(24rem, calc(100vw - 2.5rem));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--raised);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toast-in var(--dur-slow) var(--ease-spring) both;
}

.toast::before {
  content: '';
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

.toast--error::before {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
}

.toast.is-leaving {
  animation: toast-out var(--dur) var(--ease-out) both;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(16px);
  }
}

/* ---------- Dialogs ---------- */

.modal {
  width: min(28rem, calc(100vw - 2rem));
  margin: auto;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--raised);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.modal::backdrop {
  background: var(--scrim);
  backdrop-filter: blur(4px);
}

.modal[open] {
  animation: modal-in var(--dur-slow) var(--ease-spring) both;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
}

/* ---------- Loading ---------- */

.skeleton {
  border-radius: var(--radius-xs);
  background: linear-gradient(90deg, var(--skeleton) 0%, var(--skeleton-shine) 50%, var(--skeleton) 100%);
  background-size: 200% 100%;
  animation: shine 1.4s linear infinite;
}

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

/* Content that enters as it scrolls into view (js/reveal.js adds .is-visible). Without
   script the content shows: the class that hides it is set by the script itself. */
.reveal-ready [data-reveal] {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity var(--dur-slow) var(--ease-out), transform var(--dur-slow) var(--ease-out);
}

.reveal-ready [data-reveal].is-visible {
  opacity: 1;
  transform: none;
}

/* ---------- Accessibility ---------- */

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 200;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--accent-strong);
  color: var(--on-accent);
  font-weight: 700;
  transform: translateY(-200%);
  transition: transform var(--dur) var(--ease-out);
}

.skip-link:focus {
  transform: none;
}

.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;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }

  .reveal-ready [data-reveal] {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Prose: journal articles and legal pages ---------- */

.prose {
  max-width: 68ch;
  color: var(--text-2);
}

.prose > * + * {
  margin-top: 1.25em;
}

.prose h2 {
  margin-top: 2.2em;
  font-size: var(--step-2);
  color: var(--text);
}

.prose h2 + * {
  margin-top: 0.75em;
}

.prose strong {
  color: var(--text);
  font-weight: 700;
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent-edge);
  text-underline-offset: 3px;
}

.prose a:hover {
  text-decoration-color: var(--accent);
}

.prose ul {
  display: grid;
  gap: 0.5em;
  padding-left: 1.1em;
  list-style: disc;
}

.prose li::marker {
  color: var(--accent-solid);
}

.prose blockquote {
  padding-left: 1.1rem;
  border-left: 2px solid var(--accent-solid);
  color: var(--text-2);
  font-size: var(--step-1);
}

.prose code {
  padding: 0.15em 0.4em;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 0.88em;
}

/* A skin (ADR-0027): the 128 x 128 PNG drawn twice its size, pixels kept sharp, over a check
   pattern so transparent pixels show. Account profile page and the reports queue. */
.skin {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin: 1rem 0;
}

.skin__figure[hidden] {
  display: none;
}

.skin__figure {
  margin: 0;
  display: grid;
  gap: 0.4rem;
  justify-items: start;
}

.skin__figure figcaption {
  font-family: var(--font-mono);
  font-size: var(--step--2);
  text-transform: uppercase;
  color: var(--muted);
}

.skin__image {
  width: 256px;
  height: 256px;
  max-width: 100%;
  image-rendering: pixelated;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xs);
  background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface-3) 0 50%) 0 0 / 16px 16px;
}

.skin__image--small {
  width: 128px;
  height: 128px;
}

.skin__empty {
  width: 256px;
  max-width: 100%;
  margin: 0;
}
