/* Parchment v2 — site theme: warm paper, ink, sepia, and quiet typography.
   Tokens, base styles, and reusable components. App-specific pieces live in app.css.
   data-theme="light|dark|system", data-density="comfortable|compact". */

:root {
  color-scheme: light dark;
  --bg: light-dark(#f6f1e7, #1b1916);
  --surface: light-dark(#fffbf4, #25221e);
  --surface-subtle: light-dark(#eee7db, #211e1a);
  --surface-hover: light-dark(#f2e9dc, #302a23);
  --text: light-dark(#2b2620, #e9e2d6);
  --muted: light-dark(#706557, #b0a491);
  --border: light-dark(#dcd1bf, #443c32);
  --control-border: light-dark(#998976, #897b68);
  --accent: light-dark(#814726, #e0a37c);
  --accent-hover: light-dark(#64351b, #efb58e);
  --accent-soft: light-dark(#f0dfcf, #3a2e25);
  --on-accent: light-dark(#fffaf3, #241c16);
  --success: light-dark(#3e6345, #a6c59d);
  --success-bg: light-dark(#eaf0e5, #252f23);
  --warning: light-dark(#785713, #e3bf79);
  --warning-bg: light-dark(#f6ecd3, #352d1e);
  --error: light-dark(#a3271f, #ffaaa0);
  --error-bg: light-dark(#fae9e3, #3a2521);
  --info: light-dark(#3c6074, #a8c8dc);
  --info-bg: light-dark(#e8eef0, #232e34);
  /* Platform fonts are intentional. Override these two tokens to supply a brand font. */
  --font-reading: 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
  --font-ui: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-code: ui-monospace, 'SFMono-Regular', Consolas, monospace;
  --size-small: .875rem;
  --size-body: 1rem;
  --size-reading: 1.1875rem;
  --leading-ui: 1.5;
  --leading-reading: 1.7;
  --space-1: .25rem;
  --space-2: .5rem;
  --space-3: .75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --radius: .5rem;
  --radius-small: .25rem;
  --page-width: 72rem;
  --reading-width: 62ch;
  --control-height: 2.75rem;
  --control-pad: .625rem .875rem;
  --row-pad: 1.25rem;
  --duration: 140ms;
}

[data-theme="light"] { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }
[data-theme="system"] { color-scheme: light dark; }
[data-density="compact"] {
  --control-height: 2.5rem;
  --control-pad: .4375rem .75rem;
  --row-pad: .75rem;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: 1.5rem; }
body { margin: 0; background: var(--bg); color: var(--text); font: var(--size-body)/var(--leading-ui) var(--font-ui); }
[data-theme] { background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }
button, input, select, textarea, summary { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
button, input, select, textarea { max-width: 100%; }
img, svg { max-width: 100%; vertical-align: middle; }
h1, h2, h3, p { margin: 0; }
h1, h2 { font-family: var(--font-reading); font-weight: 400; line-height: 1.15; text-wrap: balance; }
h3 { font-size: 1rem; line-height: 1.4; font-weight: 600; }
a { color: var(--accent); text-underline-offset: .22em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); }
/* Atomic inline icons do not receive the parent link's underline. */
.link-icon { display: inline-block; text-decoration: none; }
/* Use a margin instead of underlined whitespace; buttons already use gap. */
a:not(.button) > .link-icon { margin-inline-start: .3em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
::selection { color: var(--text); background: var(--accent-soft); }
code { font: .875em var(--font-code); overflow-wrap: anywhere; }
:not(pre) > code { padding: .15em .35em; background: var(--surface-subtle); border-radius: var(--radius-small); }
pre { margin: 0; padding: 1.25rem; background: var(--surface-subtle); border-radius: var(--radius); overflow: auto; font-family: var(--font-code); }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { margin-bottom: 1rem; padding: 0; font-weight: 600; }
summary { cursor: pointer; }
small, .meta { font-size: var(--size-small); }
.muted, .meta { color: var(--muted); }
.eyebrow { font-size: .75rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.container { width: min(var(--page-width), calc(100% - 3rem)); margin-inline: auto; }
.stack { display: grid; gap: var(--space-5); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); align-items: start; gap: var(--space-6); }
.grid > *, .cluster > *, .stack > * { min-width: 0; }
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel__header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); }
.panel__body { padding: 1.5rem; }
.panel__footer { padding: 1rem 1.5rem; background: var(--surface-subtle); border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: var(--control-height); padding: var(--control-pad); border: 1px solid var(--accent); border-radius: var(--radius); background: var(--accent); color: var(--on-accent); font-weight: 600; line-height: 1.4; text-decoration: none; text-align: center; transition: background-color var(--duration), border-color var(--duration); }
.button:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.button:active:not(:disabled) { transform: translateY(1px); }
.button--secondary { background: var(--surface); border-color: var(--control-border); color: var(--text); }
.button--secondary:hover { background: var(--surface-hover); border-color: var(--accent); color: var(--text); }
.button--quiet { background: transparent; border-color: transparent; color: var(--accent); }
.button--quiet:hover { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.button--danger { background: var(--error-bg); border-color: var(--error); color: var(--error); }
.button--danger:hover { background: var(--error); border-color: var(--error); color: var(--bg); }
.button:disabled { background: var(--surface-subtle); color: var(--muted); border-color: var(--border); }
.button[aria-busy="true"] { color: var(--text); }
.spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; flex: 0 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.segmented { display: inline-flex; flex-wrap: wrap; padding: .25rem; gap: .25rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-subtle); }
.segmented button { flex: 1 1 auto; min-height: 2.25rem; padding: .375rem .75rem; background: transparent; border: 1px solid transparent; border-radius: var(--radius-small); color: var(--muted); font-size: var(--size-small); }
.segmented button:hover { color: var(--text); background: var(--surface-hover); }
.segmented button[aria-pressed="true"] { background: var(--surface); border-color: var(--border); color: var(--text); }
.badge { display: inline-flex; align-items: center; gap: .375rem; padding: .2rem .6rem; border: 1px solid var(--border); border-radius: var(--radius-small); color: var(--muted); font-size: .75rem; font-weight: 500; white-space: nowrap; }
.badge--success { background: var(--success-bg); border-color: transparent; color: var(--success); }
.badge--accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.field { display: grid; gap: .5rem; }
.field label { font-size: var(--size-small); font-weight: 600; }
.input, .select, .textarea { width: 100%; min-width: 0; min-height: var(--control-height); padding: var(--control-pad); border: 1px solid var(--control-border); border-radius: var(--radius); background: var(--bg); color: var(--text); line-height: 1.5; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--accent); }
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: 1; }
.input[aria-invalid="true"] { border-color: var(--error); }
.field__hint, .field__error { font-size: var(--size-small); color: var(--muted); }
.field__error { color: var(--error); }
.check { display: flex; gap: .75rem; align-items: flex-start; padding-block: .625rem; cursor: pointer; }
.check input { flex: 0 0 auto; width: 1.125rem; height: 1.125rem; margin: .2rem 0 0; accent-color: var(--accent); }
.check span { display: grid; gap: .25rem; }
.check strong { font-weight: 500; }
.notice { display: flex; gap: .875rem; align-items: flex-start; padding: 1rem 1.25rem; border-inline-start: 3px solid currentColor; border-radius: var(--radius-small); background: var(--info-bg); color: var(--info); font-size: var(--size-small); }
.notice strong { display: block; margin-bottom: .25rem; font-weight: 600; }
.notice--success { color: var(--success); background: var(--success-bg); }
.notice--warning { color: var(--warning); background: var(--warning-bg); }
.notice--error { color: var(--error); background: var(--error-bg); }
.notice__symbol { flex: 0 0 auto; width: 1.25rem; text-align: center; font-weight: 600; }
.prose { max-width: var(--reading-width); font: var(--size-reading)/var(--leading-reading) var(--font-reading); overflow-wrap: anywhere; }
.prose > * + * { margin-top: 1em; }
.prose h3 { font: 400 1.5rem/1.3 var(--font-reading); }
.prose blockquote { margin-inline: 0; padding-inline-start: 1.25rem; border-inline-start: 2px solid var(--accent); color: var(--muted); font-style: italic; }
.record { padding: var(--row-pad) 1.5rem; }
.record + .record { border-top: 1px solid var(--border); }
.record summary { display: flex; gap: 1rem; align-items: flex-start; list-style: none; }
.record summary::-webkit-details-marker { display: none; }
.record summary::after { content: '+'; margin-left: auto; color: var(--accent); font-size: 1.25rem; line-height: 1.2; }
.record[open] summary::after { content: '−'; }
.record__content { flex: 1; min-width: 0; display: grid; gap: .375rem; }
.record__title { font-weight: 500; overflow-wrap: anywhere; }
.record__meta { display: flex; flex-wrap: wrap; gap: .375rem .75rem; color: var(--muted); font-size: var(--size-small); }
.record__body { margin-top: 1rem; max-width: 65ch; color: var(--muted); font-size: var(--size-small); }
.empty { padding: 2.5rem 1.5rem; text-align: center; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: var(--size-small); }
.table th, .table td { padding: .875rem 1rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { background: var(--surface-subtle); color: var(--muted); font-weight: 500; }
.table tr:last-child td { border-bottom: 0; }
.skip-link { position: absolute; top: -6rem; left: 1rem; z-index: 10; background: var(--surface); padding: .75rem 1rem; }
.skip-link:focus { top: 1rem; }

@media (max-width: 44rem) {
  .container { width: calc(100% - 2rem); }
  .panel__body, .panel__header { padding: 1.25rem; }
  .panel__footer, .record { padding-inline: 1.25rem; }
}
@media (pointer: coarse) {
  :root, [data-density="compact"] { --control-height: 2.75rem; }
  .segmented button { min-height: 2.75rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .button:active:not(:disabled) { transform: none; }
}
@media (forced-colors: active) {
  .button, .input, .select, .textarea, .segmented, .badge { border-color: ButtonText; }
  .segmented button[aria-pressed="true"] { border-color: Highlight; }
  :focus-visible { outline-color: Highlight; }
}
