/* ============================================================
   Marina Cienfuegos — prototype
   Tokens, modular scale, light/dark theme, layout
   ------------------------------------------------------------
   Philosophy: a single modular scale drives both typographic
   sizes and spacing. Change --ratio and the whole site
   recomposes its rhythm at once.
   Inspired by: https://every-layout.dev/rudiments/modular-scale/
   ============================================================ */

/* ---------- Self-hosted fonts (latin subset) ---------- */
@font-face {
  font-family: "Cabin Sketch";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/cabin-sketch-400.woff2") format("woff2");
}
@font-face {
  font-family: "Cabin Sketch";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/cabin-sketch-700.woff2") format("woff2");
}
@font-face {
  font-family: "Special Elite";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/special-elite-400.woff2") format("woff2");
}

:root {
  /* ─── Color ─── */
  --accent: #1f6f7a;
  --accent-soft: rgba(31, 111, 122, 0.12);
  --paper: #f5f1ea;
  --paper-raised: #fbf8f2;
  --ink: #1a1815;
  --ink-soft: #5a5651;
  --rule: #d9d2c6;

  /* ─── Typography: families ─── */
  /* Chalk-style alternatives: "Eraser", "Rubik Scribble", "Caveat Brush" */
  --font-display: "Cabin Sketch", "Comic Sans MS", cursive;
  --font-prose: "Special Elite", "Courier New", monospace;
  --font-ui: "Special Elite", "Courier New", monospace;

  /* ─── Modular scale (Every Layout) ─────────────────────
     A single ratio = visual rhyme between type and space.
     Tweak --ratio (1.125 / 1.2 / 1.333 / 1.5 / 1.618 …) and
     the whole page breathes differently. */
  --ratio: 1.5;
  --s0: 1rem;                                  /* seed */
  --s-2: calc(var(--s-1) / var(--ratio));      /* ≈ 0.444rem */
  --s-1: calc(var(--s0)  / var(--ratio));      /* ≈ 0.667rem */
  --s1:  calc(var(--s0)  * var(--ratio));      /* = 1.5rem */
  --s2:  calc(var(--s1)  * var(--ratio));      /* = 2.25rem */
  --s3:  calc(var(--s2)  * var(--ratio));      /* ≈ 3.375rem */
  --s4:  calc(var(--s3)  * var(--ratio));      /* ≈ 5.0625rem */

  /* ─── Fluid base size ─────────────────────────────────
     vi (viewport-inline) instead of vw → respects writing-mode.
     In rem → respects the user's font-size preference. */
  --fs-base: clamp(0.95rem, 0.88rem + 0.4vi, 1.1875rem);

  /* ─── Line-heights ─── */
  --line-tight: 1.1;
  --line-snug: 1.3;
  --line-normal: 1.65;

  /* ─── Content widths (in ch — they scale with the font) ─── */
  --measure-min: 30ch;
  --measure: 64ch;
  --measure-wide: 78ch;
  --page-max: 90ch;
  --gutter: var(--s1);

  /* ─── Other ─── */
  --radius: 2px;
  --border-width: 1px;
  --border: var(--border-width) solid var(--rule);
  --transition: 0.2s ease;
  --transition-fast: 0.15s ease;
  --tilt: -0.4deg;        /* slight H1 tilt, notebook feel */
  --drop-cap: 3.25em;     /* drop-cap size for the first paragraph */

  /* ─── Responsive breakpoints (constants — media queries cannot
     read custom properties, but they are documented here for reference) ─── */
  /* --bp-hamburger:    540px   (header collapses into a hamburger) */
  /* --bp-two-columns:  70ch    (author-hero, works, book-hero shift to 2 columns) */

  color-scheme: light dark;
}

:root[data-theme="dark"],
:root.theme-dark {
  --accent: #5fb8c4;
  --accent-soft: rgba(95, 184, 196, 0.15);
  --paper: #14171a;
  --paper-raised: #1b1f23;
  --ink: #e8e4dc;
  --ink-soft: #9a948a;
  --rule: #2a2d31;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #5fb8c4;
    --accent-soft: rgba(95, 184, 196, 0.15);
    --paper: #14171a;
    --paper-raised: #1b1f23;
    --ink: #e8e4dc;
    --ink-soft: #9a948a;
    --rule: #2a2d31;
  }
}

/* ---------- Soft reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-prose);
  font-size: var(--fs-base);
  line-height: var(--line-normal);
  transition: background-color var(--transition), color var(--transition);
}
img, svg { max-width: 100%; height: auto; display: block; }
a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}
a:hover { background: var(--accent-soft); }
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  background: var(--accent-soft);
}

/* ---------- Skip link ---------- */
.skip-link {
  position: absolute;
  left: var(--s-1);
  top: calc(-1 * var(--s2));
  background: var(--paper);
  padding: var(--s-1) var(--s0);
  border: var(--border-width) solid var(--ink);
  z-index: 100;
}
.skip-link:focus { top: var(--s-1); }

/* ---------- Header / Nav ---------- */
.site-header {
  border-bottom: var(--border);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(6px);
}
.site-header__inner {
  width: min(var(--page-max), 100% - var(--gutter) * 2);
  margin: 0 auto;
  padding-block: var(--s0);
  display: flex;
  align-items: center;
  gap: var(--s0);
  flex-wrap: wrap;
  /* Minimal "Holy Albatross": brand at one end, tools at the other. */
  justify-content: space-between;
}
.site-brand {
  font-family: var(--font-display);
  font-size: var(--s1);
  text-decoration: none;
  white-space: nowrap;
}
.site-brand:hover { background: transparent; }
.site-brand em { font-style: normal; color: var(--accent); }

/* ---------- Subnav (below the header) ---------- */
.subnav {
  border-bottom: var(--border);
  background: var(--paper);
}
.subnav__inner {
  width: min(var(--page-max), 100% - var(--gutter) * 2);
  margin: 0 auto;
  padding-block: var(--s-1);
}
.site-nav {
  display: flex;
  gap: var(--s1);
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - var(--s1)), transparent 100%);
          mask-image: linear-gradient(to right, #000 0, #000 calc(100% - var(--s1)), transparent 100%);
  padding-right: var(--s1);
}
.site-nav::-webkit-scrollbar { display: none; }
.site-nav a {
  text-decoration: none;
  font-size: var(--s0);
  color: var(--ink-soft);
  white-space: nowrap;
}
.site-nav a:hover { color: var(--accent); background: transparent; }
.site-nav a[aria-current="page"] {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

/* ---------- Hamburger button ---------- */
.nav-toggle {
  display: none;
  background: transparent;
  border: var(--border-width) solid var(--rule);
  color: var(--ink);
  padding: var(--s-2) var(--s-1);
  border-radius: var(--radius);
  cursor: pointer;
  align-items: center;
  gap: var(--s-2);
  font: inherit;
  font-family: var(--font-ui);
  font-size: var(--s-1);
}
.nav-toggle:hover { background: var(--accent-soft); }
.nav-toggle__icon { width: 1.1em; height: 1.1em; }
.nav-toggle__icon line { stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* Narrow screens: nav → hamburger.
   Px on purpose (physical, not font-relative). See the note in :root above. */
@media (max-width: 540px) {
  .nav-toggle { display: inline-flex; }
  .subnav { display: none; }
  html[data-nav-open="true"] .subnav { display: block; }
  html[data-nav-open="true"] .site-nav {
    flex-direction: column;
    gap: var(--s-1);
    overflow: visible;
    mask-image: none;
    -webkit-mask-image: none;
    padding-right: 0;
  }
}

.site-tools {
  display: flex;
  gap: var(--s-1);
  align-items: center;
}
.lang-switch {
  display: inline-flex;
  border: var(--border-width) solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: var(--s-1);
  font-family: var(--font-ui);
}
.lang-switch a {
  padding: var(--s-2) var(--s-1);
  text-decoration: none;
  color: var(--ink-soft);
  background: transparent;
}
.lang-switch a[aria-current="true"] {
  background: var(--accent);
  color: var(--paper);
}
.lang-switch a:hover:not([aria-current="true"]) {
  background: var(--accent-soft);
  color: var(--ink);
}
.theme-toggle {
  background: transparent;
  border: var(--border-width) solid var(--rule);
  color: var(--ink);
  font: inherit;
  font-size: var(--s-1);
  padding: var(--s-2) var(--s-1);
  cursor: pointer;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-family: var(--font-ui);
}
.theme-toggle:hover { background: var(--accent-soft); }
.theme-toggle__icon { width: 1em; height: 1em; }

/* ---------- Main / containers ---------- */
.wrap {
  width: min(var(--page-max), 100% - var(--gutter) * 2);
  margin-inline: auto;
  padding-block: var(--s2) var(--s3);
}
.prose-wrap {
  /* Prose: never narrower than --measure-min ch, never wider than --measure ch. */
  width: clamp(var(--measure-min), 100% - var(--gutter) * 2, var(--measure));
  margin-inline: auto;
  padding-block: var(--s2) var(--s4);
}

/* ---------- Typography ---------- */
h1, h2, h3 {
  font-family: var(--font-display);
  color: var(--ink);
  line-height: var(--line-tight);
  margin: 0 0 0.5em;
  font-weight: 400;
}
h1 {
  /* Fluid but tied to the scale: between --s2 and --s3 */
  font-size: clamp(var(--s2), 4vi + 0.75rem, var(--s3));
  letter-spacing: 0.01em;
  line-height: var(--line-tight);
  transform: rotate(var(--tilt));
  transform-origin: left center;
}
h1 em { color: var(--accent); font-style: normal; }
h2 {
  font-size: clamp(var(--s1), 2vi + 0.5rem, var(--s2));
  line-height: var(--line-tight);
  margin-top: var(--s2);
}
h2 em { color: var(--accent); font-style: normal; }
h3 {
  font-size: var(--s1);
  line-height: var(--line-snug);
}
.eyebrow {
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: var(--s-1);
  color: var(--ink-soft);
  margin: 0 0 var(--s-1);
}
.lede {
  font-size: var(--s1);
  color: var(--ink-soft);
  font-style: italic;
  max-width: var(--measure);
}
hr.rule {
  border: 0;
  border-top: var(--border);
  margin: var(--s2) 0;
}
hr.rule--ornament {
  position: relative;
  text-align: center;
  margin: var(--s2) 0;
}
hr.rule--ornament::before {
  content: "❦";
  display: block;
  color: var(--accent);
  font-size: var(--s1);
}

/* ---------- Author page ---------- */
.author-hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s2);
  align-items: center;
  margin-bottom: var(--s3);
}
@media (min-width: 70ch) {
  .author-hero { grid-template-columns: 1.3fr 1fr; }
}
.author-hero__art {
  border: var(--border);
  background: var(--paper-raised);
  padding: var(--s1);
}
.author-hero__art svg { width: 100%; height: auto; }

/* Works list */
.works {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s2);
  margin-top: var(--s0);
}
@media (min-width: 70ch) {
  .works { grid-template-columns: 1fr 1fr; }
}
.work-card {
  border: var(--border);
  background: var(--paper-raised);
  padding: var(--s1);
  display: flex;
  flex-direction: column;
  gap: var(--s0);
  transition: transform var(--transition), border-color var(--transition);
}
.work-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.work-card__cover {
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  border: var(--border);
}
.work-card__cover svg { max-height: 100%; }
.work-card h3 {
  font-family: var(--font-display);
  font-size: var(--s1);
  margin: 0;
}
.work-card p { margin: 0; color: var(--ink-soft); }
.work-card a.work-card__link {
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: var(--s0);
  color: var(--accent);
  margin-top: auto;
}
.work-card a.work-card__link::after { content: " →"; }

/* ---------- Book page ---------- */
.book-hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s2);
  align-items: start;
  margin-bottom: var(--s2);
}
@media (min-width: 70ch) {
  .book-hero { grid-template-columns: 1fr 1.5fr; }
}
.book-hero__cover {
  border: var(--border);
  background: var(--paper-raised);
  padding: var(--s1);
}
.book-meta {
  list-style: none;
  padding: 0;
  margin: var(--s1) 0 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--s-2) var(--s0);
  font-family: var(--font-ui);
  font-size: var(--s0);
}
.book-meta dt { color: var(--ink-soft); }
.book-meta dd { margin: 0; }

/* Chapter index */
.toc {
  border-top: var(--border);
  margin-top: var(--s1);
}
.toc__item {
  border-bottom: var(--border);
  display: grid;
  grid-template-columns: 3ch 1fr auto;
  gap: var(--s0);
  align-items: baseline;
  padding: var(--s0) 0;
}
.toc__num {
  font-family: var(--font-display);
  font-size: var(--s1);
  color: var(--accent);
  font-style: italic;
}
.toc__title {
  font-family: var(--font-display);
  font-size: var(--s1);
  text-decoration: none;
}
.toc__title:hover { color: var(--accent); background: transparent; }
.toc__meta {
  font-family: var(--font-ui);
  font-size: var(--s-1);
  color: var(--ink-soft);
}

/* ---------- Breadcrumbs ---------- */
/* Always one line. Horizontal scroll with a fade if it overflows. */
.breadcrumbs {
  font-family: var(--font-ui);
  font-size: var(--s-1);
  color: var(--ink-soft);
  margin-bottom: var(--s1);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - var(--s1)), transparent 100%);
          mask-image: linear-gradient(to right, #000 0, #000 calc(100% - var(--s1)), transparent 100%);
}
.breadcrumbs::-webkit-scrollbar { display: none; }
.breadcrumbs ol {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: nowrap;
  gap: var(--s-1);
  width: max-content;
  padding-right: var(--s1);
}
.breadcrumbs li { white-space: nowrap; }
.breadcrumbs li + li::before {
  content: "/";
  margin-right: var(--s-1);
  color: var(--rule);
}
.breadcrumbs a { text-decoration: none; color: var(--ink-soft); }
.breadcrumbs a:hover { color: var(--accent); background: transparent; }
.breadcrumbs [aria-current="page"] { color: var(--ink); }

/* ---------- Chapter ---------- */
.chapter-header {
  text-align: center;
  margin-bottom: var(--s2);
}
.chapter-header .eyebrow { justify-content: center; }
.chapter-prose p {
  margin: 0 0 1.25em;
  text-align: left;
}
.chapter-prose p:first-of-type::first-letter {
  font-family: var(--font-display);
  font-size: var(--drop-cap);
  float: left;
  line-height: 0.9;
  padding: 0.15em 0.2em 0 0;
  color: var(--accent);
}
.chapter-prose blockquote {
  border-left: 2px solid var(--accent);
  margin: var(--s1) 0;
  padding: var(--s-1) 0 var(--s-1) var(--s1);
  color: var(--ink-soft);
  font-style: italic;
}

/* Inline illustration */
.illustration {
  margin: var(--s2) auto;
  text-align: center;
}
.illustration svg {
  max-width: 360px;
  margin: 0 auto;
}
.illustration figcaption {
  font-family: var(--font-ui);
  font-size: var(--s-1);
  color: var(--ink-soft);
  margin-top: var(--s-1);
  font-style: italic;
}

/* Prev/next navigation */
.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s0);
  margin-top: var(--s3);
  border-top: var(--border);
  padding-top: var(--s1);
}
.chapter-nav a {
  text-decoration: none;
  display: block;
  padding: var(--s0);
  border: var(--border);
  font-family: var(--font-ui);
  font-size: var(--s0);
}
.chapter-nav a:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.chapter-nav .label {
  display: block;
  font-size: var(--s-1);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--ink-soft);
  margin-bottom: var(--s-2);
}
.chapter-nav .title {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--ink);
}
.chapter-nav .next { text-align: right; }
.chapter-nav .empty {
  border: var(--border-width) dashed var(--rule);
  opacity: 0.5;
}

/* ---------- «Last updated» line (book and chapter pages) ---------- */
.last-updated {
  font-family: var(--font-ui);
  font-size: var(--s-1);
  color: var(--ink-soft);
  font-style: italic;
  margin: 0;
}
.last-updated--top    { margin-bottom: var(--s1); }
.last-updated--bottom { margin-top: var(--s2); text-align: right; }

/* ---------- Footer ---------- */
.site-footer {
  border-top: var(--border);
  padding: var(--s1) var(--gutter);
  text-align: center;
  font-family: var(--font-ui);
  font-size: var(--s-1);
  color: var(--ink-soft);
}
.site-footer a { color: var(--ink-soft); }

/* ---------- SVG sketch helpers ---------- */
.sketch {
  stroke: var(--ink);
  stroke-width: 1.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sketch--accent { stroke: var(--accent); }
.sketch--fill-accent { fill: var(--accent); stroke: none; }
.sketch--soft { stroke: var(--ink-soft); }

/* Honour prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
