:root {
  --bg: #fff;
  --fg: #111;
  --muted: #777;
  --faint: #d4d4d4;
  --tick: #b5b5b5;
  --accent: #0a66ff;
  --red: #e5484d;
  --label-bg: rgba(255, 255, 255, 0.92);
  --rail-w: 64px;
  --rail-pad: 40px;
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e0e;
    --fg: #ececec;
    --muted: #8a8a8a;
    --faint: #2c2c2c;
    --tick: #4a4a4a;
    --accent: #5b9cff;
    --red: #ff6369;
    --label-bg: rgba(14, 14, 14, 0.92);
  }
}

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Top bar ---------------------------------------------------------------- */

.topbar {
  position: fixed;
  top: 0;
  right: 0;
  display: flex;
  gap: 4px;
  padding: 16px 24px;
  z-index: 20;
}

.about-link {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.15s ease, background 0.15s ease;
}
.about-link:hover {
  color: var(--fg);
  background: color-mix(in srgb, var(--fg) 6%, transparent);
}

/* Posts ------------------------------------------------------------------ */

.posts {
  max-width: 640px;
  margin: 0 auto;
  padding: 64px 24px 50vh;
}

.post {
  margin-bottom: 3rem;
  scroll-margin-top: 64px;
}

.date, h2 {
  margin-bottom: 0;
}

.date {
  margin-top: 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

h2 a {
    color: var(--fg);
    text-decoration: none;
}
h2 {
  margin-top: 0;
  font-size: 20px;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.body {
  margin-top: 0.5rem;
  margin-bottom: 0;
}
.body p {
  margin: 0 0 0.5rem;
}
.body p:last-of-type {
  display: inline;   /* so the permalink sits on the last line */
}

/* Inline links in NRK's text */
.body a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--faint);
  text-underline-offset: 3px;
}
.body a:hover { text-decoration-color: var(--fg); }

.body a.permalink {
  color: var(--muted);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 12px;
}
.body a.permalink:hover { color: var(--accent); }

/* Rail ------------------------------------------------------------------- */

.rail {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--rail-w);
  padding: var(--rail-pad) 0 var(--rail-pad) 20px;
  box-sizing: border-box;
  user-select: none;
  cursor: pointer;
  z-index: 10;
}

.rail-ticks {
  position: relative;
  height: 100%;
  width: 12px;
}

/* Viewport window: which slice of the story is on screen right now. */
.rail-viewport {
  position: absolute;
  top: 0;
  left: -4px;
  right: -4px;
  background: var(--fg);
  opacity: 0.08;
  border-radius: 3px;
  pointer-events: none;
  will-change: transform, height;
}

@media (prefers-color-scheme: dark) {
  .rail-viewport { opacity: 0.14; }
}

.tick {
  position: absolute;
  left: 0;
  display: block;
  width: 12px;
  height: 1px;
  margin-top: -0.5px;
  background: var(--tick);
  transform-origin: left center;
  opacity: 0.35;
  will-change: transform, opacity;
}
/* A larger invisible hit area so the whole rail width is hoverable. */
.tick::after {
  content: "";
  position: absolute;
  inset: -2px -40px -2px -20px;
}

.tick.is-active {
  background: var(--accent);
  opacity: 1 !important;
}

.tick.is-near {
  background: var(--fg);
}

/* Key events: red tick, plus a dot hanging off its left end. The dot is a
   sibling rather than a pseudo-element so the lens doesn't stretch it. */
.tick.is-event,
.tick.is-event.is-near,
.tick.is-event.is-active {
  background: var(--red);
  opacity: 1 !important;
}
.rail-dot {
  position: absolute;
  left: -8px;
  width: 4px;
  height: 4px;
  margin-top: -2px;
  border-radius: 50%;
  background: var(--red);
  pointer-events: none;
}

.rail-year {
  position: absolute;
  left: 20px;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.04em;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.rail.is-hover .rail-year { opacity: 0; }

.rail-event {
  color: var(--red);
  font-weight: 500;
  white-space: nowrap;
}

.rail-label {
  position: absolute;
  top: 0;
  left: calc(20px + 48px);
  width: 240px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 10px;
  background: var(--label-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--faint);
  border-radius: 8px;
  pointer-events: none;
  opacity: 0;
  translate: -4px 0;
  transition: opacity 0.15s ease, translate 0.15s cubic-bezier(0.2, 0, 0, 1);
}
.rail.is-hover .rail-label {
  opacity: 1;
  translate: 0 0;
  pointer-events: auto;
}
/* Invisible bridge over the gap between the tick column and the label, so
   the pointer never leaves the rail on its way across. */
.rail-label::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: 100%;
  width: 40px;
}

.rail-label-date {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}
/* Event tag after the date, e.g. "26. sep. 2022 · Eksplosjonene". */
.rail-label-date[data-event]:not([data-event=""]) {
  color: var(--red);
}
.rail-label-date[data-event]:not([data-event=""])::after {
  content: " · " attr(data-event);
}

.rail-label-title {
  font-size: 13px;
  line-height: 1.3;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (max-width: 860px), (hover: none) {
  .rail { display: none; }
}

/* About page ------------------------------------------------------------- */

.about-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 96px 24px 96px;
}

.about-main h1 {
  font-size: 32px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 24px;
}

.about-main h2 {
  font-size: 16px;
  margin: 0 0 4px;
}

.about-main section {
  margin-top: 56px;
}

.about-main p {
  margin: 0 0 16px;
}

.lede {
  font-size: 18px;
  line-height: 1.5;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.about-main a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--faint);
  text-underline-offset: 3px;
}
.about-main a:hover { text-decoration-color: var(--fg); }

.stats {
  display: flex;
  gap: 32px;
  margin-top: 40px !important;
  padding-top: 24px;
  border-top: 1px solid var(--faint);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.about-footer {
  margin-top: 64px;
  padding-top: 16px;
  border-top: 1px solid var(--faint);
  font-size: 12px;
  color: var(--muted);
}

/* Horizontal timeline ---------------------------------------------------- */

.hline {
  margin-top: 24px;
  user-select: none;
}

.hline-axis {
  position: relative;
  height: 32px;
  border-bottom: 1px solid var(--faint);
}

.hline-rug {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 12px;
}
.hline-rug i {
  position: absolute;
  bottom: 0;
  width: 1px;
  height: 100%;
  background: var(--tick);
  opacity: 0.5;
}

.hline-years {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 14px;
}
.hline-years span {
  position: absolute;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
/* Year labels sit at Jan 1; nudge the first one so it isn't clipped. */
.hline-years span:first-child { transform: none; }

.hline-dot {
  position: absolute;
  bottom: -4px;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 2px var(--bg);
  z-index: 1;
  transition: box-shadow 0.15s ease;
}
.hline-dot.is-hover {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--red);
}
.hline-label.is-hover { border-color: var(--red); }

/* Connector space (36px) plus one or two 40px label rows; the SVG overlays
   both so connectors can reach the second row. Heights are set from JS. */
.hline-body {
  position: relative;
  padding-top: 36px;
}
.hline-links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.hline-links polyline {
  fill: none;
  stroke: var(--faint);
  stroke-width: 1;
  transition: stroke 0.15s ease;
}
.hline-links polyline.is-hover {
  stroke: var(--red);
}
/* Stacking: base connectors (0) < labels (1) < hovered connector (2).
   The top layer is see-through to the pointer so labels stay hoverable. */
.hline-links { z-index: 0; }
.hline-links-top { z-index: 2; pointer-events: none; }

.hline-labels {
  position: relative;
  height: 40px;
  z-index: 1;
}

.hline-label {
  position: absolute;
  top: 0;
  display: flex;
  flex-direction: column;
  padding: 0 6px 4px;
  border-left: 1px solid var(--faint);
  background: var(--bg);   /* occludes connectors passing behind */
  text-decoration: none !important;
  white-space: nowrap;
  transition: border-color 0.15s ease;
}
.hline-label:hover { border-color: var(--red); }
.hline-label-date {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
}
.hline-label-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--red);
}

/* Bar chart -------------------------------------------------------------- */

.chart {
  position: relative;
  margin-top: 16px;
}
.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.chart .grid {
  stroke: var(--faint);
  stroke-width: 1;
}
.chart .baseline {
  stroke: var(--muted);
  stroke-width: 1;
}
.chart .axis {
  font-family: var(--mono);
  font-size: 10px;
  fill: var(--muted);
}
.chart .value {
  font-family: var(--mono);
  font-size: 11px;
  fill: var(--fg);
}
.chart .mark {
  fill: var(--accent);
  transition: opacity 0.15s ease;
}
.chart .hit { fill: transparent; }
.chart .bar { outline: none; cursor: default; }
.chart.has-tip .bar:not(.is-hover) .mark { opacity: 0.4; }

.chart-tip {
  position: absolute;
  transform: translate(-50%, calc(-100% - 8px));
  padding: 4px 8px;
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
  background: var(--label-bg);
  border: 1px solid var(--faint);
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.chart.has-tip .chart-tip { opacity: 1; }

.table-view {
  margin-top: 12px;
  font-size: 13px;
}
.table-view summary {
  cursor: pointer;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}
.table-view table {
  margin-top: 8px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.table-view th, .table-view td {
  text-align: left;
  padding: 3px 24px 3px 0;
  border-bottom: 1px solid var(--faint);
}
.table-view th { font-weight: 500; color: var(--muted); }

@media (max-width: 560px) {
  .stats { gap: 20px; flex-wrap: wrap; }
  .hline-label-text { font-size: 11px; }
}
