/* Dize — shared design tokens (same palette as the app: parchment, ink, forest, gold). */
:root {
  --bg: #faf7f2;
  --surface: #f2ede4;
  --muted: #e8e2d8;
  --elevated: #ffffff;
  --ink: #1a1610;
  --ink-2: #655a50;
  --ink-3: #9e9289;
  --border: #d4cbbc;
  --divider: #ede7dd;
  --accent: #2a4a3c;
  --on-accent: #faf7f2;
  --gold: #b5702a;
  --crimson: #9b2e2e;
  --success: #3d6b5a;
  --shadow: 0 1px 2px rgba(26, 22, 16, 0.06), 0 8px 24px rgba(26, 22, 16, 0.08);
  --shadow-lg: 0 2px 6px rgba(26, 22, 16, 0.08), 0 24px 60px rgba(26, 22, 16, 0.16);
  --grain-opacity: 0.05;
  --serif: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --sans: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'DM Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --radius: 6px;
  --radius-lg: 14px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f0d0b;
    --surface: #1e1b17;
    --muted: #171410;
    --elevated: #252220;
    --ink: #f0ebe3;
    --ink-2: #a09080;
    --ink-3: #6b6055;
    --border: #2e2b27;
    --divider: #26221e;
    --accent: #4a7a68;
    --on-accent: #0f0d0b;
    --gold: #c98b3f;
    --crimson: #f2b8b5;
    --success: #5a9a84;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.5), 0 24px 60px rgba(0, 0, 0, 0.55);
    --grain-opacity: 0.07;
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #0f0d0b;
  --surface: #1e1b17;
  --muted: #171410;
  --elevated: #252220;
  --ink: #f0ebe3;
  --ink-2: #a09080;
  --ink-3: #6b6055;
  --border: #2e2b27;
  --divider: #26221e;
  --accent: #4a7a68;
  --on-accent: #0f0d0b;
  --gold: #c98b3f;
  --crimson: #f2b8b5;
  --success: #5a9a84;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.5), 0 24px 60px rgba(0, 0, 0, 0.55);
  --grain-opacity: 0.07;
  color-scheme: dark;
}

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

/* `hidden` must win over any display rule set by a component class. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background-color 0.4s var(--ease), color 0.4s var(--ease);
}

/* Paper grain over everything, like the app's parchment. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

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

a {
  color: inherit;
}

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

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

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

h1,
h2,
h3,
h4 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0;
  font-variation-settings: 'opsz' 96;
}

p {
  margin: 0;
}

.eyebrow {
  font: 500 12px/1.4 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

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

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

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

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

.btn {
  --btn-bg: var(--accent);
  --btn-fg: var(--on-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 500;
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease), background 0.25s;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn:active {
  transform: translateY(0);
}

.btn[disabled],
.btn[aria-disabled='true'] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-fg: var(--ink);
  border-color: var(--border);
}

.btn--ghost:hover {
  background: var(--surface);
}

.btn--gold {
  --btn-bg: var(--gold);
  --btn-fg: #faf7f2;
}

.btn--sm {
  min-height: 38px;
  padding: 0 14px;
  font-size: 14px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  transition: background 0.2s;
}

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

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

.field {
  display: grid;
  gap: 6px;
}

.field label,
.field .label {
  font: 500 12px/1.4 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--elevated);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.5;
}

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

/* ---------- toast ---------- */

.toast-host {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  z-index: 200;
  width: min(92vw, 420px);
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--bg);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  animation: toast-in 0.35s var(--ease);
}

.toast--error {
  background: var(--crimson);
  color: #fff;
}

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

/* ---------- book covers (same generated palette idea as the app) ---------- */

.cover {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 2px 4px 4px 2px;
  overflow: hidden;
  background: var(--cover-bg, #2a4a3c);
  color: var(--cover-fg, #faf7f2);
  box-shadow: inset 4px 0 0 rgba(0, 0, 0, 0.18), var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10% 9%;
  font-family: var(--serif);
}

.cover img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover__title {
  font-size: clamp(9px, 1.1em, 18px);
  font-weight: 600;
  line-height: 1.1;
  overflow-wrap: anywhere;
  hyphens: auto;
}

.cover__author {
  font: 500 0.6em/1.2 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.8;
}

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