/* Readernaut baseline
   ------------------------------------------------------------------
   Self-contained stylesheet: reset + tokens + element defaults.
   Include on its own — does not depend on reset.css or main.css.

   1. Tokens
   2. Reset
   3. Document
   4. Typography
   5. Links
   6. Media
   7. Tables
   8. Forms
   9. Buttons
   10. Interactive elements
   11. Utilities
   ------------------------------------------------------------------ */

/* 1. Tokens
   ------------------------------------------------------------------ */

:root {
  color-scheme: light dark;

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --text-xs: 0.75rem;    /* 12px */
  --text-sm: 0.8125rem;  /* 13px */
  --text-base: 0.875rem; /* 14px */
  --text-lg: 1rem;       /* 16px */
  --text-xl: 1.25rem;    /* 20px */
  --text-2xl: 1.5rem;    /* 24px */

  --leading-tight: 1.2;
  --leading-normal: 1.5;

  /* Space (4px scale) */
  --space-1: 0.25rem;  /*  4px */
  --space-2: 0.5rem;   /*  8px */
  --space-3: 0.75rem;  /* 12px */
  --space-4: 1rem;     /* 16px */
  --space-6: 1.5rem;   /* 24px */
  --space-8: 2rem;     /* 32px */
  --space-12: 3rem;    /* 48px */

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-full: 999px;

  /* Color */
  --color-bg: #fff;
  --color-surface: #f5f5f1;
  --color-border: #e4e4df;
  --color-border-strong: #c9c9c2;
  --color-text: #1a1a1a;
  --color-text-muted: #777;
  --color-text-faint: #aaa;
  --color-accent: #1a1a1a;
  --color-accent-contrast: #fff;
  --color-danger: #b3261e;
  --color-success: #2e7d32;
  --color-focus: #4c7dd0;

  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1b1b19;
    --color-surface: #262624;
    --color-border: #3a3a37;
    --color-border-strong: #55554f;
    --color-text: #ececea;
    --color-text-muted: #9c9c96;
    --color-text-faint: #6e6e68;
    --color-accent: #ececea;
    --color-accent-contrast: #1b1b19;
    --color-danger: #e5766f;
    --color-success: #7cc47f;
    --color-focus: #7ba3e6;

    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  }
}

/* 2. Reset
   ------------------------------------------------------------------ */

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

* {
  margin: 0;
}

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

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

/* 3. Document
   ------------------------------------------------------------------ */

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 400;
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

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

::selection {
  background: color-mix(in srgb, var(--color-focus) 25%, transparent);
}

/* 4. Typography
   ------------------------------------------------------------------ */

h1,
h2,
h3,
h4,
h5,
h6 {
  line-height: var(--leading-tight);
  text-wrap: balance;
}

h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
}

h2 {
  font-size: var(--text-xl);
  font-weight: 600;
}

h3 {
  font-size: var(--text-lg);
  font-weight: 600;
}

h4 {
  font-size: var(--text-base);
  font-weight: 600;
}

h5,
h6 {
  font-size: var(--text-sm);
  font-weight: 600;
}

h6 {
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

p,
ul,
ol,
dl,
blockquote,
pre,
table,
figure,
hr {
  margin-block: var(--space-4);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin-block: var(--space-6) var(--space-4);
}

ul,
ol {
  padding-inline-start: var(--space-6);
}

li {
  margin-block: var(--space-1);
}

li > ul,
li > ol {
  margin-block: var(--space-1);
}

dt {
  font-weight: 600;
}

dd {
  margin-inline-start: 0;
  margin-block-end: var(--space-2);
  color: var(--color-text-muted);
}

blockquote {
  padding-inline-start: var(--space-4);
  max-inline-size: 65ch;
  border-inline-start: 2px solid var(--color-border-strong);
  color: var(--color-text-muted);
}

blockquote cite {
  display: block;
  margin-block-start: var(--space-2);
  font-size: var(--text-sm);
  font-style: normal;
}

hr {
  border: none;
  border-block-start: 1px solid var(--color-border);
}

strong,
b {
  font-weight: 600;
}

small {
  font-size: var(--text-xs);
}

mark {
  background: color-mix(in srgb, var(--color-focus) 20%, transparent);
  color: inherit;
  border-radius: 2px;
  padding-inline: 2px;
}

abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}

code,
kbd,
samp,
pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

code,
samp {
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  padding: 1px 4px;
}

kbd {
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  font-size: var(--text-xs);
  box-shadow: inset 0 -1px 0 var(--color-border-strong);
}

pre {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  line-height: var(--leading-normal);
}

pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

/* 5. Links
   ------------------------------------------------------------------ */

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--color-border-strong);
  text-underline-offset: 2px;
}

a:hover {
  text-decoration-color: currentColor;
}

/* Navigation and headings carry their own affordance */
nav a,
h1 a,
h2 a,
h3 a {
  text-decoration: none;
}

/* 6. Media
   ------------------------------------------------------------------ */

figure figcaption {
  margin-block-start: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

audio {
  width: 100%;
}

/* 7. Tables
   ------------------------------------------------------------------ */

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

caption {
  margin-block-end: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: left;
}

th,
td {
  padding: var(--space-2) var(--space-3);
  padding-inline-start: 0;
  border-block-end: 1px solid var(--color-border);
  vertical-align: top;
}

th {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
}

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

/* 8. Forms
   ------------------------------------------------------------------ */

form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  align-items: flex-start;
}

/* Keep the fieldset's default display: flex/grid here breaks the
   legend's in-border rendering in Safari. Spacing comes from margins. */
fieldset {
  align-self: stretch;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  min-inline-size: 0;
}

fieldset > * + * {
  margin-block-start: var(--space-4);
}

fieldset > legend + * {
  margin-block-start: 0;
}

legend {
  padding-inline: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

label {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 500;
}

label.inline {
  flex-direction: row;
  align-items: center;
}

input:where([type="text"], [type="email"], [type="password"], [type="search"],
  [type="url"], [type="tel"], [type="number"], [type="date"], [type="time"],
  [type="datetime-local"]),
textarea,
select {
  padding: var(--space-2) var(--space-3);
  font-weight: 400;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  min-inline-size: 0;
}

textarea {
  resize: vertical;
  min-block-size: 5rem;
}

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

input:hover,
textarea:hover,
select:hover {
  border-color: var(--color-border-strong);
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline-offset: 0;
}

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

input[type="file"] {
  font-weight: 400;
  color: var(--color-text-muted);
}

input[type="file"]::file-selector-button {
  margin-inline-end: var(--space-3);
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-weight: 500;
  color: var(--color-text);
  background: var(--color-surface);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  background: color-mix(in srgb, var(--color-surface) 80%, var(--color-border-strong));
}

input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.5;
  cursor: default;
}

input[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--color-danger);
}

label .hint {
  font-weight: 400;
  color: var(--color-text-muted);
}

label .error {
  margin: 0;
}

progress,
meter {
  accent-color: var(--color-accent);
}

/* 9. Buttons
   ------------------------------------------------------------------ */

button,
.button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-weight: 500;
  background: var(--color-surface);
  color: inherit;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.button:hover {
  background: color-mix(in srgb, var(--color-surface) 80%, var(--color-border-strong));
}

button.primary,
button[type="submit"],
.button.primary {
  background: var(--color-accent);
  color: var(--color-accent-contrast);
}

button.primary:hover,
button[type="submit"]:hover,
.button.primary:hover {
  background: color-mix(in srgb, var(--color-accent) 85%, var(--color-bg));
}

button.danger,
.button.danger {
  background: var(--color-danger);
  color: #fff;
}

button.link,
.button.link {
  padding: 0;
  background: none;
  border-radius: 0;
  font-weight: inherit;
}

button:disabled,
.button:disabled {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

/* 10. Interactive elements
   ------------------------------------------------------------------ */

details {
  margin-block: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
}

summary {
  font-weight: 500;
  cursor: pointer;
}

details[open] summary {
  margin-block-end: var(--space-2);
}

dialog {
  margin: auto; /* the universal margin reset removes the UA centering */
  padding: var(--space-6);
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-inline-size: 32rem;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.3);
}

/* Padding, not child margins, sets the dialog's edges */
dialog > :first-child {
  margin-block-start: 0;
}

dialog > :last-child {
  margin-block-end: 0;
}

/* 11. Utilities
   ------------------------------------------------------------------ */

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

.error {
  color: var(--color-danger);
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Horizontal row of items, baseline-aligned */
.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: baseline;
}

/* Readable measure for long-form content */
.prose {
  max-inline-size: 65ch;
}
