/*
 * base.css - Memorial base stylesheet (mobile-first).
 *
 * THEME TOKENS (CSS custom properties, defined on :root / <html>)
 *   --bg           page background
 *   --fg           primary text
 *   --muted        secondary text, captions, hints
 *   --accent       links, primary buttons, focus accents
 *   --accent-fg    text drawn on top of --accent
 *   --card         card / surface background
 *   --border       hairlines, input borders, card outlines
 *   --focus        focus ring colour
 *   --radius       corner radius for cards, inputs, buttons
 *   --radius-pill  corner radius for chips
 *   --font-serif   headings and display text
 *   --font-sans    body and UI text
 *   --space-1 .. --space-8   spacing scale (0.25rem .. 4rem)
 *   --max-width    container width at desktop widths
 *
 * THEMING
 *   Light values are the default. Dark values apply when the OS asks for
 *   dark (prefers-color-scheme) unless <html data-theme="light">, and always
 *   when <html data-theme="dark">.
 *
 *   Runtime overrides: the server emits a block after this file such as
 *     <style>:root{ --accent: #8a5a2b; --font-serif: "Lora", serif; }</style>
 *   generated from site_settings.theme. Every token rule in this file is
 *   wrapped in :where(), which gives it zero specificity, so a plain :root
 *   block placed after this stylesheet wins for both light and dark modes.
 *   Override only the tokens you need; anything omitted keeps the default.
 */

/* ---------- Tokens: light (default) ---------- */
:where(:root) {
  --bg: #faf6f0;
  --fg: #3b3129;
  --muted: #7a6b5d;
  --accent: #a0673c;
  --accent-fg: #fffaf4;
  --card: #fffdf9;
  --border: #e6dccf;
  --focus: #a0673c;
  --radius: 0.75rem;
  --radius-pill: 999px;
  --font-serif: "Cormorant Garamond", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --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;
  --max-width: 60rem;
  --shadow: 0 1px 2px rgb(59 49 41 / 0.06), 0 4px 16px rgb(59 49 41 / 0.05);
  color-scheme: light;
}

/* ---------- Tokens: dark (OS preference, unless forced light) ---------- */
@media (prefers-color-scheme: dark) {
  :where(:root:not([data-theme="light"])) {
    --bg: #1d1915;
    --fg: #efe6d9;
    --muted: #a89a8a;
    --accent: #d8a86f;
    --accent-fg: #1d1915;
    --card: #26201b;
    --border: #3a322a;
    --focus: #e8b97f;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.25);
    color-scheme: dark;
  }
}

/* ---------- Tokens: dark (explicit toggle) ---------- */
:where(:root[data-theme="dark"]) {
  --bg: #1d1915;
  --fg: #efe6d9;
  --muted: #a89a8a;
  --accent: #d8a86f;
  --accent-fg: #1d1915;
  --card: #26201b;
  --border: #3a322a;
  --focus: #e8b97f;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.25);
  color-scheme: dark;
}

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

* {
  margin: 0;
}

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

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

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

button {
  cursor: pointer;
}

a {
  color: var(--accent);
  text-underline-offset: 0.2em;
}

[hidden] {
  display: none !important;
}

/* ---------- Typography ---------- */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-serif);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.01em;
  color: var(--fg);
  text-wrap: balance;
}

h1 { font-size: 2.25rem; margin-bottom: var(--space-4); }
h2 { font-size: 1.75rem; margin-bottom: var(--space-3); }
h3 { font-size: 1.375rem; margin-bottom: var(--space-2); }
h4 { font-size: 1.125rem; margin-bottom: var(--space-2); }

p,
ul,
ol,
blockquote,
figure,
table {
  margin-bottom: var(--space-4);
}

p {
  text-wrap: pretty;
}

blockquote {
  padding-left: var(--space-4);
  border-left: 2px solid var(--border);
  color: var(--muted);
  font-family: var(--font-serif);
  font-size: 1.125rem;
  font-style: italic;
}

small,
.small {
  font-size: 0.875rem;
  color: var(--muted);
}

code,
kbd,
pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--space-6) 0;
}

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: 1rem; /* 16px gutter on phones */
}

.stack > * + * {
  margin-top: var(--space-4);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-5);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-fg);
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.btn:hover {
  filter: brightness(1.06);
}

.btn:active {
  filter: brightness(0.96);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}

.btn-secondary {
  background: transparent;
  color: var(--fg);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
}

.btn-block {
  width: 100%;
}

/* ---------- Form fields ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.field > label,
label {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--fg);
}

.field-hint {
  font-size: 0.875rem;
  color: var(--muted);
}

.field-error {
  font-size: 0.875rem;
  color: #b3412e;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
select,
textarea {
  width: 100%;
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--fg);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

textarea {
  min-height: 6rem;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

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

[aria-invalid="true"] {
  border-color: #b3412e;
}

/* ---------- Card ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}

.card > :last-child {
  margin-bottom: 0;
}

.card-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  margin-bottom: var(--space-2);
}

/* ---------- Chip ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.25rem var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--card);
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.4;
  white-space: nowrap;
}

button.chip {
  min-height: 2.25rem;
  cursor: pointer;
}

button.chip[aria-pressed="true"],
.chip.is-active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Accessibility helpers ---------- */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

:focus {
  outline: none;
}

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

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-3);
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: var(--radius);
  transform: translateY(-200%);
}

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

/* ---------- Motion ---------- */
@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;
  }
}

/* ---------- Wider screens ---------- */
@media (min-width: 40rem) {
  .container {
    padding-inline: var(--space-5);
  }

  h1 { font-size: 2.75rem; }
  h2 { font-size: 2rem; }

  .card {
    padding: var(--space-6);
  }
}

@media (min-width: 64rem) {
  h1 { font-size: 3.25rem; }
}
