:root {
  --bg: #0e1118;
  --bg-2: #121621;
  --surface: #151924;
  --raised: #1c2230;
  --line: rgba(232, 237, 245, 0.08);
  --line-strong: rgba(232, 237, 245, 0.16);
  --text: #e8edf5;
  --muted: #9aa3b5;
  --faint: #848ea3;
  --gold: #ffb800;
  --gold-dim: rgba(255, 184, 0, 0.16);
  --gold-line: rgba(255, 184, 0, 0.45);
  --danger: #f0a0a8;
  --ok: #8fd0a8;
  --font: "Segoe UI", "Helvetica Neue", system-ui, -apple-system, sans-serif;
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", Georgia, serif;
  --mono: "IBM Plex Mono", "ui-monospace", "SFMono-Regular", Menlo, Consolas, monospace;
  --r: 10px;
  --inspector: 28rem;
  --touch: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
html { scrollbar-color: #3a4254 transparent; }
body {
  font: 16px/1.5 var(--font);
  letter-spacing: -0.011em;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--gold); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: #ffd45c; }
img { max-width: 100%; height: auto; display: block; }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

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

.skip {
  position: absolute; left: 0.75rem; top: -3rem;
  background: var(--gold); color: #111; padding: 0.4rem 0.7rem; border-radius: 6px; z-index: 30;
}
.skip:focus { top: 0.75rem; }

.shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(900px 420px at 8% -10%, rgba(255, 184, 0, 0.05), transparent 55%),
    var(--bg);
}

.mast {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.25rem 2rem 0.9rem;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 8;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
}
.wordmark { text-decoration: none; color: inherit; display: grid; gap: 0.15rem; }
.wordmark:hover { color: inherit; }
.wm-kicker {
  font-size: 0.7rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--gold); font-weight: 650;
}
.wm-title {
  font-family: var(--display); font-weight: 500; font-size: 1.55rem;
  line-height: 1.1; letter-spacing: -0.02em;
}

.tabs { display: flex; gap: 0.25rem; }
.tabs a {
  color: var(--muted); text-decoration: none;
  min-height: var(--touch); padding: 0 0.9rem;
  border-radius: 999px; font-size: 0.92rem;
  display: inline-flex; align-items: center;
}
.tabs a:hover { color: var(--text); background: var(--raised); }
.tabs a[aria-current="page"] {
  color: #111; background: var(--gold); font-weight: 650;
}

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.view { flex: 1; min-width: 0; }
#view-timeline[hidden], #view-overview[hidden], #view-decisions[hidden] { display: none !important; }
#view-timeline { display: flex; flex-direction: column; min-height: 0; }

/* Standalone (not an iframe / ?embed=1): desktop timeline uses an internal scroller. */
html:not(.embed) #view-timeline {
  height: calc(100dvh - 5.5rem);
  max-height: calc(100dvh - 5.5rem);
}
html:not(.embed) #tl-lane { overflow: auto; min-height: 0; flex: 1; }

/* Overview */
.overview { padding: 1.5rem 2rem 2rem; max-width: 68rem; }
.overview h1 {
  font-family: var(--display); font-size: clamp(1.55rem, 2.8vw, 2.05rem);
  line-height: 1.28; font-weight: 400; max-width: 42rem; margin: 0 0 0.85rem;
  letter-spacing: -0.02em;
}
.overview .intro { color: var(--muted); max-width: 42rem; margin: 0 0 0.35rem; }
.overview .log-span { color: var(--faint); margin: 0 0 1.25rem; font-size: 0.95rem; }
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem; margin: 0 0 1.25rem;
}
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 0.9rem 1rem 0.85rem;
}
.stat b {
  display: block; font-family: var(--display); font-size: 1.65rem; font-weight: 500;
  letter-spacing: -0.03em; color: var(--text);
}
.stat span { color: var(--muted); font-size: 0.82rem; }

.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  margin: 0 0 0.65rem;
}
.section-head h2 {
  font-family: var(--display); font-weight: 500; font-size: 1.35rem;
  margin: 0; letter-spacing: -0.02em;
}
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.9rem; }
.card {
  display: flex; flex-direction: column; gap: 0; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  overflow: hidden; min-height: 100%;
}
.card:hover { border-color: var(--gold-line); color: inherit; }
.card img { aspect-ratio: 16 / 9; object-fit: contain; object-position: center; background: #0a0c12; width: 100%; }
.card .card-body { padding: 0.7rem 1rem 0.85rem; display: grid; gap: 0.25rem; }
.card .card-body h3 { margin: 0; font-size: 1rem; letter-spacing: -0.015em; line-height: 1.3; }
.card time { color: var(--faint); font-size: 0.82rem; }
.jump {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--touch);
  background: var(--gold); color: #111; font-weight: 650;
  padding: 0 0.95rem; border-radius: 999px; text-decoration: none;
}
.jump:hover { color: #111; filter: brightness(1.08); }

/* Timeline chrome */
.tl-heading {
  font-family: var(--display); font-weight: 500; font-size: 1.15rem;
  margin: 0; padding: 0.65rem 1.25rem 0; letter-spacing: -0.02em;
}
.tl-bar {
  display: flex; flex-direction: column; gap: 0.45rem;
  padding: 0.65rem 1.25rem 0.75rem; border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.tl-bar-row {
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
}
.tl-filters { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.tl-count { color: var(--faint); font-size: 0.88rem; white-space: nowrap; }
#tl-search {
  flex: 1 1 14rem; min-width: 10rem; min-height: var(--touch);
  background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 0 0.7rem;
}
.chip-btn, .kind-label select, .reset-btn {
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 0 0.8rem; cursor: pointer;
  min-height: var(--touch);
  display: inline-flex; align-items: center; justify-content: center;
}
.kind-label select { padding-right: 1.6rem; }
.chip-btn[aria-pressed="true"] {
  background: var(--gold-dim); border-color: var(--gold-line); color: var(--gold);
}
button.chip-btn.filters-toggle { display: none; }
.kind-label { color: var(--muted); font-size: 0.8rem; display: flex; align-items: center; gap: 0.35rem; }

.scrub { padding: 0 1.25rem 0.15rem; border-bottom: 1px solid var(--line); }
.scrub-hit {
  display: flex; align-items: center; height: var(--touch); margin: 0;
}
#tl-scrub-range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: var(--touch); margin: 0; padding: 0;
  background: transparent; cursor: pointer;
}
#tl-scrub-range::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px;
  background: linear-gradient(to right, var(--gold) var(--pct, 0%), var(--raised) var(--pct, 0%));
}
#tl-scrub-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--gold); border: 0; margin-top: -5px;
}
#tl-scrub-range::-moz-range-track {
  height: 6px; border-radius: 999px; background: var(--raised);
}
#tl-scrub-range::-moz-range-progress {
  height: 6px; border-radius: 999px; background: var(--gold);
}
#tl-scrub-range::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--gold); border: 0;
}
.scrub-labels {
  display: flex; justify-content: space-between; color: var(--faint);
  font-size: 0.72rem; margin: -0.15rem 0 0.35rem;
}

.tl-body { flex: 1; display: flex; min-height: 0; min-width: 0; }
.lane {
  flex: 1; padding: 1rem 1.5rem 2rem;
  outline: none; min-width: 0;
}
.gap {
  display: flex; align-items: center; gap: 0.75rem;
  color: var(--faint); font-size: 0.75rem; margin: 0.35rem 0 0.35rem 7.6rem;
}
.gap::before, .gap::after {
  content: ""; height: 0; flex: 1;
  border-top: 1px dotted var(--line-strong);
}

.group-label {
  margin: 1.1rem 0 0.45rem; color: var(--gold);
  font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 650;
  font-family: var(--font);
}

.chip {
  display: grid; grid-template-columns: 6.8rem 12px 1fr; gap: 0.7rem;
  width: 100%; text-align: left; background: none; border: 0;
  padding: 0.35rem 0; cursor: pointer; color: inherit; align-items: start;
}
.chip .when { color: var(--faint); font-size: 0.75rem; padding-top: 0.55rem; line-height: 1.25; }
.chip .rail { position: relative; height: 100%; min-height: 2.6rem; }
.chip .rail::before {
  content: ""; position: absolute; left: 5px; top: -0.35rem; bottom: -0.35rem;
  width: 1px; background: var(--line-strong);
}
.chip .dot {
  position: absolute; left: 0; top: 0.7rem; width: 11px; height: 11px;
  border-radius: 50%; background: var(--raised); border: 2px solid var(--muted);
  z-index: 1;
}
.chip.key .dot { background: var(--gold); border-color: var(--gold); }
.chip .body {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 0.7rem 0.85rem 0.75rem; display: grid; gap: 0.25rem; min-width: 0;
}
.chip:hover .body, .chip[aria-current="true"] .body { border-color: var(--gold-line); }
.chip[aria-current="true"] .body { background: color-mix(in srgb, var(--gold) 8%, var(--surface)); }
.chip h3 { margin: 0; font-size: 1rem; font-weight: 650; letter-spacing: -0.015em; line-height: 1.3; }
.chip .blurb { color: var(--muted); font-size: 0.86rem; margin: 0; }
.badges { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.badge {
  font-size: 0.68rem; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 0.12rem 0.4rem; border-radius: 999px; border: 1px solid var(--line-strong);
  color: var(--muted);
}
.badge.key { color: #111; background: var(--gold); border-color: var(--gold); font-weight: 700; }

/* Compact zoom: true single-line rows, denser than Standard. */
.lane[data-zoom="compact"] .chip {
  padding: 0.08rem 0; align-items: center;
  grid-template-columns: 6.8rem 12px 1fr;
}
.lane[data-zoom="compact"] .chip .when { padding-top: 0; }
.lane[data-zoom="compact"] .chip .rail { min-height: 0; }
.lane[data-zoom="compact"] .chip .dot { top: 50%; transform: translateY(-50%); }
.lane[data-zoom="compact"] .chip .body {
  padding: 0.25rem 0.7rem; display: flex; flex-direction: row;
  align-items: center; gap: 0.55rem; min-height: var(--touch);
}
.lane[data-zoom="compact"] .chip h3 {
  font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-weight: 600;
}
.lane[data-zoom="compact"] .chip .blurb { display: none; }
.lane[data-zoom="compact"] .chip .badges { flex-shrink: 0; }

.empty { color: var(--muted); padding: 2rem 1rem; display: grid; gap: 0.8rem; justify-items: start; }

/* Inspector */
.inspector {
  flex: 0 0 var(--inspector); width: var(--inspector);
  min-width: 16rem; min-height: 0; align-self: stretch;
  border-left: 1px solid var(--line); background: var(--bg-2);
  overflow: auto; padding: 1rem 1.1rem 2rem;
}
.inspector.wide { flex-basis: min(38rem, 55vw); width: min(38rem, 55vw); }
.in-tools { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; margin-bottom: 0.8rem; }
.in-tools .grow { flex: 1; }
.in-tools button {
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 0 0.7rem; cursor: pointer;
  min-height: var(--touch); display: inline-flex; align-items: center;
}
.in-tools button:disabled { opacity: 0.4; cursor: default; }
.inspector h2 {
  font-family: var(--display); font-weight: 500; font-size: 1.45rem;
  line-height: 1.25; margin: 0 0 0.4rem; letter-spacing: -0.02em;
}
.inspector .when { color: var(--muted); margin: 0 0 1rem; }
.inspector .summary { margin: 0 0 1rem; }
.twists { display: grid; gap: 0.7rem; margin: 0 0 1rem; }
.twist { background: var(--surface); border-radius: var(--r); padding: 0.75rem 0.85rem; border: 1px solid var(--line); }
.twist.broke { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.twist.fix { border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); }
.twist b { display: block; font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.25rem; }
.gallery { display: grid; gap: 0.6rem; margin: 0 0 1rem; }
.gallery button {
  padding: 0; border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; background: #0a0c12; cursor: zoom-in;
}
.refs { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0 0 0.8rem; }
.refs a, .refs span {
  font-size: 0.8rem; border: 1px solid var(--line-strong); border-radius: 999px;
  padding: 0.15rem 0.5rem; color: var(--muted); text-decoration: none;
}
.refs a { color: var(--gold); }
.refs code { font-family: var(--mono); font-size: 0.76rem; }
.note-private { color: var(--faint); font-size: 0.8rem; margin-top: 0.8rem; }

/* Decisions */
.decisions { padding: 2rem; max-width: 48rem; }
.decisions h1 {
  font-family: var(--display); font-weight: 500; font-size: 2rem;
  margin: 0 0 0.4rem; letter-spacing: -0.02em;
}
.decisions .lede { color: var(--muted); margin: 0 0 1.5rem; }
.decision {
  border-top: 1px solid var(--line); padding: 1rem 0 1.15rem;
}
.decision time { color: var(--gold); font-size: 0.8rem; letter-spacing: 0.04em; }
.decision h2 { font-size: 1.08rem; margin: 0.2rem 0 0.35rem; letter-spacing: -0.015em; }
.decision p { margin: 0; color: var(--muted); }
.decision .src { margin-top: 0.35rem; color: var(--faint); font-size: 0.8rem; }

.colophon {
  padding: 0.8rem 0 0.4rem; margin-top: 1.5rem;
  border-top: 1px solid var(--line);
  color: var(--faint); font-size: 0.78rem;
}
.lane > .colophon { margin: 1.5rem 0 0 7.6rem; }

.lightbox {
  inset: 0; width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; padding: 1.25rem; border: 0; background: transparent;
  color: var(--text);
}
.lightbox::backdrop { background: rgba(5, 7, 12, 0.82); }
.lb-frame {
  background: #0a0c12; max-width: min(96vw, 1200px); width: min(96vw, 1200px);
  margin: 0 auto; border-radius: 10px; overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.lb-head {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.35rem 0.5rem 0.35rem 1rem;
  border-bottom: 1px solid var(--line); background: var(--bg-2);
  min-height: var(--touch);
}
.lb-title {
  flex: 1; margin: 0; font-weight: 650; letter-spacing: -0.015em;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lb-close {
  background: var(--gold); color: #111; border: 0; border-radius: 8px;
  min-height: var(--touch); min-width: var(--touch);
  padding: 0 0.9rem; cursor: pointer; font-weight: 650;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.lightbox img { width: 100%; max-height: calc(88vh - 4rem); object-fit: contain; background: #0a0c12; }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .cards { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .mast { flex-direction: column; align-items: flex-start; padding: 0.85rem 1rem 0.65rem; gap: 0.5rem; }
  .overview, .decisions { padding-left: 1rem; padding-right: 1rem; }
  .tl-heading, .tl-bar, .scrub { padding-left: 1rem; padding-right: 1rem; }
  html:not(.embed) #view-timeline { height: auto; max-height: none; }
  html:not(.embed) #tl-lane { overflow: visible; flex: none; }
  button.chip-btn.filters-toggle { display: inline-flex; }
  .tl-filters { display: none; }
  .tl-bar.filters-open .tl-filters { display: flex; }
  .tl-body { flex-direction: column; }
  .chip { grid-template-columns: 4.8rem 10px 1fr; gap: 0.45rem; }
  .lane[data-zoom="compact"] .chip { grid-template-columns: 4.8rem 10px 1fr; }
  .gap { margin-left: 5.3rem; }
  .lane > .colophon { margin-left: 0; }
  .inspector, .inspector.wide {
    position: fixed; inset: 0; z-index: 20;
    width: 100%; min-width: 0; max-height: none; height: 100%;
    flex-basis: auto;
    border-left: 0; border-top: 0;
    background: var(--bg-2);
    padding: 0.85rem 1rem 1.5rem;
    display: flex; flex-direction: column;
  }
  .inspector[hidden] { display: none !important; }
  .wider-btn { display: none !important; }
  .inspector .in-tools {
    position: sticky; top: 0; z-index: 1;
    background: var(--bg-2); padding: 0 0 0.65rem;
  }
  .inspector h2, .inspector .summary, .inspector .when, .twists, .gallery, .refs, .note-private {
    flex-shrink: 0;
  }
  html.sheet-open, html.sheet-open body { overflow: hidden; }
}

@media (max-width: 480px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .wm-title { font-size: 1.3rem; }
}
