/* ----------------------------------------------------------------
   Dune Timeline — minimalist theme
   Palette: warm near-black ground, sand text, spice + Eyes-of-Ibad accents
   Type: monospace labels (technology) + serif titles (epic)
------------------------------------------------------------------- */

:root {
  --bg:         #0e0c09;
  --sand:       #e9dcc3;
  --sand-dim:   #a2957b;
  --sand-faint: #6b6250;
  --line:       #2a2417;

  --spice:      #d98a3d;   /* amber spice */
  --ibad:       #5aa9c4;   /* Eyes of Ibad blue */
  --accent:     var(--spice);

  --maxw: 760px;
  --spine: 132px; /* x-position of the timeline spine; date sits in the gutter to its left */

  --gap: clamp(3rem, 7vw, 5rem); /* space between timeline elements */
  --gap-tight: 1.6rem;           /* opening divider → its first element */
  --barh: 54px;                  /* sticky toolbar-bar height (desktop + mobile) */

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Menlo", monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

html {
  font-size: 112.5%; /* ~18px base — scales the whole rem-based layout up a notch */
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, #1c160c 0%, rgba(28,22,12,0) 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--sand);
  font-family: var(--sans);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container {
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: 24px;
}

/* faint desert grain overlay --------------------------------------- */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* header ----------------------------------------------------------- */
.site-header {
  text-align: center;
  padding-top: 20vh;
  padding-bottom: 14vh;
}

.kicker {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--sand-dim);
  margin-bottom: 1.6rem;
  padding-left: 0.42em; /* optical balance for tracking */
}

.site-header h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.4rem, 7vw, 4.1rem);
  line-height: 1.04;
  letter-spacing: 0.01em;
}

.subtitle {
  margin: 1.6rem auto 0;
  max-width: 48ch;
  color: var(--sand-dim);
  font-size: 1.02rem;
}

/* timeline --------------------------------------------------------- */
.events {
  position: relative;
}

/* the vertical spine */
.events::before {
  content: "";
  position: absolute;
  left: var(--spine);
  top: 0.6rem;
  bottom: 0;
  width: 1px;
  background: linear-gradient(180deg, transparent 0, var(--line) 3rem, var(--line) calc(100% - 6rem), transparent 100%);
}

/* Unified vertical rhythm. Every timeline element — events and book markers
   alike — is separated from the previous one by --gap. The only exception is
   the era header, which hugs its first following element with --gap-tight. */
.events > * { margin-top: var(--gap); }
.events > :first-child { margin-top: 0; }
.era-header + * { margin-top: var(--gap-tight); }

.event {
  position: relative;
  padding-left: calc(var(--spine) + 24px);

  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.event.visible {
  opacity: 1;
  transform: none;
}

/* era section header on the timeline — sticks to the top while its era scrolls */
.era-header {
  position: sticky;
  top: var(--barh); /* pin just below the toolbar bar, merging with it */
  z-index: 5;
  /* nudge the box (and its bottom border) 16px wider on each side so the line
     reads as a touch longer than the content without shifting off-centre; the
     extra left padding keeps the header text in place */
  margin-left: -16px;
  margin-right: -32px;
  padding: 0.85rem 0 0.85rem calc(var(--spine) + 40px);

  /* match the page background exactly (same fixed gradient) so the sticky
     header reads as the same colour, not a tinted band */
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, #1c160c 0%, rgba(28, 22, 12, 0) 60%),
    var(--bg);
  background-attachment: fixed;
  border-bottom: 1px solid var(--line);

  opacity: 0;
  transition: opacity 0.7s ease;
}
.era-header.visible { opacity: 1; }

.era-name {
  position: relative;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.35rem, 3.4vw, 1.75rem);
  color: var(--era);
  letter-spacing: 0.02em;
}

/* era marker dot — seated on the spine/node column and vertically centred on
   the title (top:50% tracks the responsive font size, unlike a fixed offset) */
.era-name::before {
  content: "";
  position: absolute;
  left: -31.5px; /* from the indented title back onto the node column */
  top: 50%;
  transform: translateY(-50%);
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--era);
  box-shadow: 0 0 0 4px var(--bg), 0 0 18px -2px var(--era);
}

.era-tagline {
  margin-top: 0.35rem;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--sand-faint);
}

/* book boundary markers — where each of the six novels begins / ends ------
   A book is a "reading layer" over the in-world eras. Start and end share one
   quiet style; the whole marker is a single centred row so the AG span (gutter),
   the open-book glyph (on the spine) and the label all line up. */
.book-mark {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 1.5rem;
  padding-left: calc(var(--spine) + 24px);
  opacity: 0;
  transition: opacity 0.7s ease;
}
.book-mark.visible { opacity: 1; }


/* the open-book glyph, seated on the spine and centred on the row
   (the bg halo masks the spine line running behind it) */
.book-mark__glyph {
  position: absolute;
  /* centre on the 1px spine (its centre is at spine + 0.5px), matching the
     event nodes — a 16px glyph therefore offsets by 8 − 0.5 = 7.5px */
  left: calc(var(--spine) - 7.5px);
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent); /* match the year, like the event nodes do */
  background: var(--bg);
  box-shadow: 0 0 0 5px var(--bg);
}

/* the AG year, styled exactly like an event date in the gutter */
.book-mark__span {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: calc(var(--spine) - 20px);
  text-align: right;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  color: var(--accent);
}

.book-mark__label {
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--sand-faint);
}

/* node on the spine — seated on the node column and vertically centred on the
   title (top:50% tracks the responsive title size, like the era dot) */
.event__title::before {
  content: "";
  position: absolute;
  left: -30.5px; /* from the indented title back onto the node column */
  top: 50%;
  transform: translateY(-50%);
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--bg);
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 0 4px var(--bg), 0 0 14px -2px var(--accent);
}

/* the year/date, in the gutter left of the node, centred on the title too.
   Its right edge is pinned 20px left of the spine (44px = 24px title indent +
   20px gap), so a long date grows leftward into the gutter — never into the
   node — instead of relying on a fixed-width box. */
.event__date {
  position: absolute;
  right: calc(100% + 44px);
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap; /* keep the "AG"/"BG" suffix on the year's line */
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  color: var(--accent);
}

.category {
  display: block;
  margin-bottom: 0.55rem; /* sits under the title, above the description */
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--sand-faint);
}

.event__title {
  position: relative; /* anchors the gutter date + spine node to the title */
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.15rem, 2.8vw, 1.5rem);
  line-height: 1.2;
  margin-bottom: 0.4rem;
}

.event__desc {
  color: var(--sand-dim);
  max-width: 58ch;
}

.error {
  color: #c96a5a;
  font-family: var(--mono);
  font-size: 0.85rem;
}

/* footer ----------------------------------------------------------- */
.site-footer {
  padding-top: 6vh;
  padding-bottom: 12vh;
  text-align: center;
}
.site-footer p {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  color: var(--sand-faint);
}

/* toolbar — full-width sticky top bar holding filter + navigate + legend.
   Same treatment as the mobile bar: a translucent blurred background with a
   bottom border, sitting above the page content that scrolls beneath it. */
.toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  height: var(--barh);
  padding: 0 24px;
  background: rgba(14, 12, 9, 0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

/* hidden events / eras / book marks (filtered out) + empty state */
.event.is-hidden,
.era-header.is-hidden,
.book-mark.is-hidden {
  display: none;
}
.timeline-empty {
  padding-left: calc(var(--spine) + 24px);
  padding-top: 1rem;
  color: var(--sand-dim);
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
}

/* search --------------------------------------------------------- */
.search {
  position: relative;
  display: flex;
  align-items: center;
  background: #1b1610;
  border: 1px solid #322a1c;
  border-radius: 999px;
  transition: width 0.32s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.2s ease;
}
.search:focus-within { border-color: var(--sand-faint); }

.search__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  color: var(--sand-dim);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.2s ease;
}
.search__toggle:hover { color: var(--sand); }

/* the filter reads as a "Filter" pill identical to Navigate / Legend (label +
   chevron, no icon) — the magnifier is dropped entirely */
.search__toggle svg { display: none; }
.search__toggle {
  width: auto;
  padding: 0 0.85rem;
  gap: 0.5rem;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.search__chevron { font-size: 0.9rem; line-height: 1; }

.search__input {
  width: 0;
  padding: 0;
  opacity: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--sand);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  transition: width 0.28s ease, opacity 0.2s ease, padding 0.28s ease;
}
.search__input::placeholder { color: var(--sand-faint); }
/* open pill is a fixed length; the input flexes to fill whatever the count +
   clear button don't use, so the box never changes size */
.search[data-open="true"] { width: 18rem; }
.search[data-open="true"] .search__input {
  flex: 1;
  min-width: 0;
  width: auto;
  padding-right: 0.3rem;
  opacity: 1;
}

.search__clear {
  display: none;
  width: 30px;
  height: 34px;
  flex: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--sand-faint);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s ease;
}
.search__clear:hover { color: var(--sand); }
.search[data-open="true"][data-has-query="true"] .search__clear { display: inline-flex; }

/* result count sits inside the pill, right-aligned between the input and ✕ */
.search__count {
  flex: none;
  padding: 0 0.15rem 0 0.45rem;
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  color: var(--sand-faint);
  white-space: nowrap;
  pointer-events: none;
}
.search__count:empty { display: none; }

/* legend --------------------------------------------------------- */
.legend {
  position: relative;
}

.legend__toggle {
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--sand-dim);
  background: #1b1610;
  border: 1px solid #322a1c;
  border-radius: 999px;
  height: 34px;
  padding: 0 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.legend__toggle:hover {
  color: var(--sand);
  border-color: var(--sand-faint);
}
.legend__chevron {
  font-size: 0.9rem;
  line-height: 1;
}

.legend__body {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 250px;
  max-width: calc(100vw - 40px);
  background: #14100a;
  border: 1px solid #322a1c;
  border-radius: 12px;
  padding: 0.95rem 1.05rem;
  box-shadow: 0 12px 34px -14px rgba(0, 0, 0, 0.75);
}
.legend[data-collapsed="true"] .legend__body {
  display: none;
}

.legend__title {
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--sand-faint);
  margin-bottom: 0.8rem;
}
.legend__list {
  display: grid;
  gap: 0.65rem;
}
.legend__row {
  display: grid;
  grid-template-columns: 2.4rem 1fr;
  gap: 0.6rem;
  align-items: baseline;
}
.legend__row dt {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--spice);
}
.legend__row dd {
  font-size: 0.76rem;
  line-height: 1.45;
  color: var(--sand-dim);
}

/* navigate — jump-nav popover, styled like the legend --------------- */
.nav { position: relative; }

.nav__toggle {
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--sand-dim);
  background: #1b1610;
  border: 1px solid #322a1c;
  border-radius: 999px;
  height: 34px;
  padding: 0 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.nav__toggle:hover { color: var(--sand); border-color: var(--sand-faint); }
.nav__chevron { font-size: 0.9rem; line-height: 1; }

.nav__body {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 250px;
  max-width: calc(100vw - 40px);
  max-height: 70vh;
  overflow-y: auto;
  background: #14100a;
  border: 1px solid #322a1c;
  border-radius: 12px;
  padding: 0.95rem 1.05rem;
  box-shadow: 0 12px 34px -14px rgba(0, 0, 0, 0.75);
}
.nav[data-collapsed="true"] .nav__body { display: none; }

.nav__section + .nav__section { margin-top: 1rem; }
.nav__title {
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--sand-faint);
  margin-bottom: 0.55rem;
}
.nav__list { display: grid; gap: 0.1rem; }
.nav__link {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.32rem 0.4rem;
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 0.82rem;
  line-height: 1.25;
  color: var(--sand-dim);
  transition: color 0.15s ease, background 0.15s ease;
}
.nav__link:hover { color: var(--sand); background: #1f1810; }
.nav__num {
  display: inline-block;
  width: 1.6rem;
  text-align: right;
  margin-right: 0.6rem;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  color: var(--sand-faint);
}

/* jump-nav scroll targets clear the toolbar bar + sticky era header */
.era-header { scroll-margin-top: calc(var(--barh) + 0.5rem); }
.book-mark { scroll-margin-top: calc(var(--barh) + 5rem); }

/* on wide screens, nudge the timeline left by half the date-rail width so the
   reading content (right of the rail) sits centred in the viewport */
@media (min-width: 1000px) {
  .timeline {
    position: relative;
    left: calc((var(--spine) + 24px) / -2);
  }
}

/* narrow / mobile — same top bar, but controls (no icons) are evenly spaced
   across the viewport rather than aligned to the right */
@media (max-width: 1080px) {
  .toolbar {
    padding: 0 12px;
    gap: 4px;
    justify-content: space-evenly;
  }

  /* nav + legend panels drop as near-full-width sheets below the bar */
  .nav__body,
  .legend__body {
    position: fixed;
    top: calc(var(--barh) + 4px);
    left: 12px;
    right: 12px;
    width: auto;
    max-width: none;
  }

  /* when the filter opens, drop Navigate + Legend so it gets the whole bar
     and can align/expand cleanly */
  .search[data-open="true"] ~ .nav,
  .search[data-open="true"] ~ .legend { display: none; }
  .search[data-open="true"] { flex: 1; }
  .search[data-open="true"] .search__input {
    flex: 1;
    width: auto;
    max-width: none;
  }
}

/* narrow screens — tighten the date gutter -------------------------- */
@media (max-width: 560px) {
  :root { --spine: 96px; }
  .event__date { font-size: 0.58rem; }
  .book-mark__span { font-size: 0.6rem; }
}

/* accessibility ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .event, .era-header { opacity: 1; transform: none; transition: none; }
}
