/* Library of Alexandria — Living Edition portal
   Illuminated-archive aesthetic: deep ink, parchment, lantern gold. */

:root {
  /* Type scale */
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.2rem + 2.5vw, 3.5rem);
  --text-3xl: clamp(2.5rem, 1rem + 4vw, 5rem);

  /* Spacing */
  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.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; --space-20: 5rem; --space-24: 6rem; --space-32: 8rem;

  --radius-sm: 0.375rem; --radius-md: 0.5rem; --radius-lg: 0.75rem; --radius-xl: 1rem;
  --radius-full: 9999px;
  --transition: 220ms cubic-bezier(0.16, 1, 0.3, 1);

  --content-narrow: 680px;
  --content-default: 1000px;
  --content-wide: 1240px;

  --font-display: 'Cormorant Garamond', 'Cormorant', Georgia, serif;
  --font-body: 'Spectral', Georgia, serif;
  --font-ui: 'Work Sans', system-ui, sans-serif;
}

/* DARK (default) — deep ink archive */
:root, [data-theme='dark'] {
  --color-bg: #12100b;
  --color-surface: #1a1710;
  --color-surface-2: #211d14;
  --color-surface-offset: #16130d;
  --color-border: #38311f;
  --color-divider: #29241a;
  --color-text: #ece3d0;
  --color-text-muted: #a99d84;
  --color-text-faint: #6f664f;
  --color-text-inverse: #17140d;
  --color-gold: #d9a441;
  --color-gold-soft: #e7c079;
  --color-gold-hover: #eab850;
  --color-gold-deep: #a97a26;
  --color-gold-glow: rgba(217, 164, 65, 0.16);
  --color-ink-deep: #0c0a06;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.5);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.45);
  --shadow-lg: 0 20px 50px rgba(0,0,0,0.55);
  --shadow-gold: 0 0 40px rgba(217,164,65,0.12);
}

/* LIGHT — parchment archive */
[data-theme='light'] {
  --color-bg: #f4ecd8;
  --color-surface: #faf3e2;
  --color-surface-2: #fdf8ec;
  --color-surface-offset: #efe4c9;
  --color-border: #d8c9a4;
  --color-divider: #e3d6b8;
  --color-text: #2a2213;
  --color-text-muted: #6b5f43;
  --color-text-faint: #a3956f;
  --color-text-inverse: #faf3e2;
  --color-gold: #9a6f16;
  --color-gold-soft: #7a5810;
  --color-gold-hover: #825d0f;
  --color-gold-deep: #6a4d0d;
  --color-gold-glow: rgba(154, 111, 22, 0.12);
  --color-ink-deep: #efe4c9;
  --shadow-sm: 0 1px 2px rgba(80,60,20,0.08);
  --shadow-md: 0 8px 24px rgba(80,60,20,0.12);
  --shadow-lg: 0 20px 50px rgba(80,60,20,0.16);
  --shadow-gold: 0 0 40px rgba(154,111,22,0.10);
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  scroll-padding-top: var(--space-20);
}

body {
  min-height: 100dvh;
  line-height: 1.65;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background-color: var(--color-bg);
  background-image:
    radial-gradient(1200px 600px at 50% -10%, var(--color-gold-glow), transparent 70%);
  display: flex;
  flex-direction: column;
}

img, picture, svg { display: block; max-width: 100%; height: auto; }
ul[role='list'] { list-style: none; }
input, button, textarea, select { font: inherit; color: inherit; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.1;
  text-wrap: balance;
  letter-spacing: 0.01em;
}
p, li { text-wrap: pretty; }

a { color: var(--color-gold-soft); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--color-gold-hover); }

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

::selection { background: var(--color-gold-glow); color: var(--color-text); }
:focus-visible { outline: 2px solid var(--color-gold); outline-offset: 3px; border-radius: var(--radius-sm); }

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

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0;
}

/* ---------- Layout helpers ---------- */
.wrap { width: 100%; max-width: var(--content-wide); margin-inline: auto; padding-inline: var(--space-6); }
.wrap-narrow { max-width: var(--content-narrow); }
.wrap-default { max-width: var(--content-default); }
.eyebrow {
  font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 500;
  letter-spacing: 0.28em; text-transform: uppercase; color: var(--color-gold-soft);
}
.muted { color: var(--color-text-muted); }
.center { text-align: center; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in oklab, var(--color-bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-divider);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4); padding-block: var(--space-3);
}
.brand { display: flex; align-items: center; gap: var(--space-3); color: var(--color-text); }
.brand:hover { color: var(--color-text); }
.brand svg { color: var(--color-gold); flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 600; letter-spacing: 0.02em; }
.brand-sub { font-family: var(--font-ui); font-size: 0.68rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--color-text-faint); }

.nav { display: flex; align-items: center; gap: var(--space-6); }
.nav-links { display: flex; gap: var(--space-6); }
.nav-links a {
  font-family: var(--font-ui); font-size: var(--text-sm); font-weight: 500;
  letter-spacing: 0.04em; color: var(--color-text-muted);
}
.nav-links a:hover, .nav-links a[aria-current='page'] { color: var(--color-gold-soft); }
.theme-toggle {
  display: grid; place-items: center; width: 38px; height: 38px;
  border: 1px solid var(--color-border); border-radius: var(--radius-full); color: var(--color-text-muted);
}
.theme-toggle:hover { color: var(--color-gold); border-color: var(--color-gold-deep); }
.menu-btn { display: none; color: var(--color-text); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  font-family: var(--font-ui); font-size: var(--text-sm); font-weight: 600; letter-spacing: 0.04em;
  padding: var(--space-3) var(--space-6); border-radius: var(--radius-full);
  transition: all var(--transition); border: 1px solid transparent;
}
.btn-primary {
  background: linear-gradient(180deg, var(--color-gold-soft), var(--color-gold));
  color: var(--color-ink-deep); box-shadow: var(--shadow-gold);
}
.btn-primary:hover { color: var(--color-ink-deep); transform: translateY(-1px); box-shadow: 0 0 48px rgba(217,164,65,0.28); }
.btn-ghost { border-color: var(--color-border); color: var(--color-text); background: transparent; }
.btn-ghost:hover { border-color: var(--color-gold-deep); color: var(--color-gold-soft); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

/* ---------- Hero ---------- */
.hero { position: relative; overflow: hidden; }
.hero-media { position: absolute; inset: 0; z-index: -1; }
.hero-media img { width: 100%; height: 100%; object-fit: cover; opacity: 0.55; }
.hero-media::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, color-mix(in oklab, var(--color-bg) 55%, transparent) 0%, color-mix(in oklab, var(--color-bg) 82%, transparent) 55%, var(--color-bg) 100%);
}
.hero-inner { padding-block: clamp(var(--space-24), 16vw, 12rem) var(--space-24); text-align: center; }
.hero h1 {
  font-size: var(--text-3xl); font-weight: 600; margin-top: var(--space-5);
  max-width: 24ch; margin-inline: auto;
}
.hero .lede {
  font-size: var(--text-lg); color: var(--color-text-muted);
  max-width: 54ch; margin: var(--space-6) auto var(--space-8);
}
.hero-cta { display: flex; flex-wrap: wrap; gap: var(--space-4); justify-content: center; }

/* ---------- Sections ---------- */
.section { padding-block: clamp(var(--space-16), 9vw, var(--space-32)); }
.section-head { max-width: 60ch; margin-bottom: var(--space-12); }
.section-head.center { margin-inline: auto; }
.section-head h2 { font-size: var(--text-2xl); margin-top: var(--space-3); }
.section-head p { color: var(--color-text-muted); font-size: var(--text-lg); margin-top: var(--space-4); }
.divider-rule { border: 0; height: 1px; background: linear-gradient(90deg, transparent, var(--color-border), transparent); }

/* ---------- Promise / feature trio ---------- */
.trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-8); }
.feature { padding: var(--space-6); }
.feature .icon {
  width: 48px; height: 48px; display: grid; place-items: center;
  color: var(--color-gold); border: 1px solid var(--color-gold-deep); border-radius: var(--radius-full);
  margin-bottom: var(--space-5);
}
.feature h3 { font-size: var(--text-lg); }
.feature p { color: var(--color-text-muted); font-size: var(--text-base); margin-top: var(--space-2); }

/* ---------- Catalog grid ---------- */
.catalog-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-10); }
.book-card {
  display: grid; grid-template-columns: 160px 1fr; gap: var(--space-6);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: var(--space-6); transition: all var(--transition);
}
.book-card:hover { border-color: var(--color-gold-deep); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.book-cover { border-radius: var(--radius-md); overflow: hidden; box-shadow: var(--shadow-md); align-self: start; aspect-ratio: 2/3; }
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-body { display: flex; flex-direction: column; }
.book-badge {
  align-self: flex-start; font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 600;
  letter-spacing: 0.06em; color: var(--color-gold-soft); background: var(--color-gold-glow);
  border: 1px solid var(--color-gold-deep); border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-3); margin-bottom: var(--space-3);
}
.book-title { font-size: var(--text-xl); }
.book-subtitle { font-family: var(--font-display); font-style: italic; color: var(--color-text-muted); font-size: var(--text-lg); margin-top: var(--space-1); }
.book-descriptor { font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: 0.1em; text-transform: uppercase; color: var(--color-text-faint); margin-top: var(--space-3); }
.book-blurb { color: var(--color-text-muted); margin-top: var(--space-3); font-size: var(--text-base); }
.book-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: auto; padding-top: var(--space-5); }
.book-actions .btn { padding-block: var(--space-2); }

/* ---------- Cards / panels ---------- */
.panel {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: clamp(var(--space-6), 4vw, var(--space-10));
}

/* ---------- Forms ---------- */
.field { margin-bottom: var(--space-5); }
.field label { display: block; font-family: var(--font-ui); font-size: var(--text-sm); font-weight: 500; margin-bottom: var(--space-2); color: var(--color-text); }
.field .hint { font-family: var(--font-ui); font-size: var(--text-xs); color: var(--color-text-faint); margin-top: var(--space-2); }
.input {
  width: 100%; font-family: var(--font-ui); font-size: var(--text-base);
  padding: var(--space-3) var(--space-4); color: var(--color-text);
  background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-md);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input:focus { outline: none; border-color: var(--color-gold); box-shadow: 0 0 0 3px var(--color-gold-glow); }
.input::placeholder { color: var(--color-text-faint); }
.form-divider {
  display: flex; align-items: center; gap: var(--space-4); margin-block: var(--space-6);
  font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: 0.2em; text-transform: uppercase; color: var(--color-text-faint);
}
.form-divider::before, .form-divider::after { content: ''; flex: 1; height: 1px; background: var(--color-divider); }

.alert { border-radius: var(--radius-md); padding: var(--space-4); font-family: var(--font-ui); font-size: var(--text-sm); margin-bottom: var(--space-5); }
.alert-error { background: rgba(161,52,68,0.12); border: 1px solid rgba(161,52,68,0.4); color: #e59aa4; }
[data-theme='light'] .alert-error { color: #8a2331; background: rgba(161,52,68,0.08); }

/* ---------- Success / library state ---------- */
.success-mark {
  width: 64px; height: 64px; display: grid; place-items: center; margin: 0 auto var(--space-5);
  color: var(--color-gold); border: 1px solid var(--color-gold-deep); border-radius: var(--radius-full);
  box-shadow: var(--shadow-gold);
}
.entitlement-list { display: flex; flex-direction: column; gap: var(--space-4); margin-top: var(--space-6); }
.entitlement {
  display: grid; grid-template-columns: 64px 1fr auto; gap: var(--space-5); align-items: start;
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-4);
}
.entitlement .dl { align-self: center; }
.entitlement .mini-cover { border-radius: var(--radius-sm); overflow: hidden; aspect-ratio: 2/3; box-shadow: var(--shadow-sm); }
.entitlement .mini-cover img { width: 100%; height: 100%; object-fit: cover; }
.entitlement .meta h4 { font-size: var(--text-lg); font-weight: 600; }
.entitlement .meta .edn { font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: 0.06em; color: var(--color-gold-soft); margin-top: var(--space-1); }
.entitlement .dl { display: flex; flex-direction: column; gap: var(--space-2); justify-content: center; }
.entitlement .dl .btn { width: 100%; justify-content: center; }
.entitlement .dl .btn { padding: var(--space-2) var(--space-4); font-size: var(--text-xs); }
.changelog { margin-top: var(--space-3); }
.changelog summary { cursor: pointer; font-family: var(--font-ui); font-size: var(--text-xs); color: var(--color-text-muted); letter-spacing: 0.04em; }
.changelog summary:hover { color: var(--color-gold-soft); }
.changelog ul { list-style: none; margin-top: var(--space-3); border-left: 1px solid var(--color-gold-deep); padding-left: var(--space-4); }
.changelog li { font-size: var(--text-sm); color: var(--color-text-muted); margin-bottom: var(--space-3); }
.changelog li strong { color: var(--color-text); font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: 0.04em; }

/* ---------- Prose (terms / about) ---------- */
.prose { max-width: 68ch; }
.prose h2 { font-size: var(--text-xl); margin-top: var(--space-10); margin-bottom: var(--space-3); }
.prose h2:first-child { margin-top: 0; }
.prose p { margin-bottom: var(--space-4); color: var(--color-text); font-size: var(--text-lg); line-height: 1.7; }
.prose ul { margin: 0 0 var(--space-4) var(--space-6); }
.prose li { margin-bottom: var(--space-2); font-size: var(--text-lg); }
.prose .lead { font-family: var(--font-display); font-size: var(--text-xl); font-style: italic; color: var(--color-text-muted); line-height: 1.5; }

/* ---------- Footer ---------- */
.site-footer {
  margin-top: auto; border-top: 1px solid var(--color-divider);
  background: var(--color-surface-offset); padding-block: var(--space-10);
}
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: var(--space-6); justify-content: space-between; align-items: center; }
.footer-links { display: flex; flex-wrap: wrap; gap: var(--space-5); font-family: var(--font-ui); font-size: var(--text-sm); }
.footer-links a { color: var(--color-text-muted); }
.footer-links a:hover { color: var(--color-gold-soft); }
.footer-copy { font-family: var(--font-ui); font-size: var(--text-xs); color: var(--color-text-faint); letter-spacing: 0.03em; }

/* ---------- Loading ---------- */
.spinner {
  width: 18px; height: 18px; border: 2px solid var(--color-gold-glow); border-top-color: var(--color-gold);
  border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .trio { grid-template-columns: 1fr; gap: var(--space-4); }
  .catalog-grid { grid-template-columns: 1fr; }
  .nav-links { display: none; }
  .nav-links.open {
    display: flex; flex-direction: column; position: absolute; top: 100%; right: var(--space-6);
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md);
    padding: var(--space-4) var(--space-6); box-shadow: var(--shadow-lg); gap: var(--space-4);
  }
  .menu-btn { display: grid; place-items: center; width: 38px; height: 38px; }
}
@media (max-width: 560px) {
  .book-card { grid-template-columns: 1fr; }
  .book-cover { max-width: 180px; }
  .entitlement { grid-template-columns: 56px 1fr; }
  .entitlement .dl { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; justify-content: flex-start; }
  .entitlement .dl .btn { width: auto; }
}
