/* kardashev.uk — a public instrument for a logarithmic civilisation scale.
   Stations are data-driven. When a station gains `href`, the renderer
   emits an essay link; until then plates are complete on this page. */

:root {
  --void: #05070d;
  --void-2: #0a101c;
  --ink: #e8eefc;
  --muted: #8b97b3;
  --gold: #f0c14a;
  --gold-hot: #ffd56a;
  --ember: #ff8a14;
  --teal: #3ee0c2;
  --blue: #7aa2ff;
  --line: rgba(232, 238, 252, 0.12);
  --plate: rgba(8, 12, 22, 0.72);
  --font-display: "Fraunces", "Times New Roman", serif;
  --font-body: "Outfit", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --gutter: max(clamp(1.1rem, 3.5vw, 2.8rem), env(safe-area-inset-left));
  --mast: 3.6rem;
  --k-min: 0;
  --k-max: 3.08;
  --nebula: 12, 18, 32;
  color-scheme: dark;
}

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

html {
  scroll-behavior: smooth;
  background: var(--void);
}

html:focus-within { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 50% -10%, rgba(var(--nebula), 0.55), transparent 60%),
    radial-gradient(900px 500px at 80% 20%, rgba(58, 90, 208, 0.08), transparent 50%),
    var(--void);
  background-attachment: fixed;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

img, svg { display: block; max-width: 100%; }
a { color: inherit; }
:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
}

.stars {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.55;
}
main, .mast { position: relative; z-index: 1; }
.colophon { position: relative; z-index: 0; }

.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: 1rem;
  top: -4rem;
  z-index: 20;
  padding: 0.6rem 0.9rem;
  background: var(--gold);
  color: #1a1000;
  font-weight: 600;
}
.skip:focus { top: 0.6rem; }

.mono { font-family: var(--font-mono); font-size: 0.92em; }

.eyebrow {
  margin: 0 0 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--teal);
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -0.02em;
}

h1 { font-size: clamp(2.4rem, 6vw, 5.4rem); margin: 0 0 1rem; }
h2 { font-size: clamp(1.8rem, 3.6vw, 3rem); margin: 0 0 1rem; }
h3 { font-size: 1.05rem; margin: 0 0 0.5rem; }

.lede {
  font-size: clamp(1.05rem, 2vw, 1.28rem);
  color: var(--muted);
  max-width: 38rem;
}

/* Masthead */

.mast {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.8rem;
  height: var(--mast);
  padding: 0 var(--gutter);
  background: rgba(5, 7, 13, 0.72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.mast-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 0.04em;
}
.mast-brand img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(240, 193, 74, 0.25);
}

.mast-readout {
  margin: 0;
  display: flex;
  gap: 1rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--gold-hot);
}
.mast-p { color: var(--muted); white-space: nowrap; }
.mast-p sup, .tick-label sup, .power-label sup, .factors sup, .hero-power sup, .formula sup {
  font-size: 0.65em;
  line-height: 0;
}

.mast-domain {
  justify-self: end;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Hero */

.hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(1.5rem, 4vw, 4rem);
  align-items: center;
  padding: clamp(1.5rem, 5vh, 4rem) var(--gutter) 4rem;
  min-height: calc(100svh - var(--mast));
}

.hero-copy { max-width: 38rem; }

.hero-figure {
  display: grid;
  margin: 2.2rem 0 0.6rem;
  gap: 0.15rem;
}
.hero-kicker {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.hero-num {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(5.4rem, 16vw, 9.5rem);
  line-height: 0.85;
  letter-spacing: -0.06em;
  background: linear-gradient(180deg, #fff8e8 10%, #ffd56a 45%, #ff8a14 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 24px rgba(255, 138, 20, 0.18));
}
.hero-unit {
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 3vw, 1.8rem);
  color: var(--gold);
}
.hero-power {
  color: var(--muted);
  margin: 0 0 1.8rem;
}
.hero-power .mono { white-space: nowrap; }
.hero-power strong { color: var(--ink); font-weight: 500; }

.descend {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--teal);
  text-decoration: none;
  font-weight: 500;
  letter-spacing: 0.04em;
}
.descend::after {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  translate: 0 -0.1rem;
}
.descend:hover { color: var(--gold-hot); }

.instrument {
  margin: 0;
  width: min(100%, 34rem);
  justify-self: center;
}
@media (max-width: 720px) {
  .instrument { width: min(100%, 22.5rem); }
}
.instrument svg {
  width: 100%;
  height: auto;
  border-radius: 50%;
  box-shadow:
    0 0 0 1px rgba(232, 238, 252, 0.08),
    0 30px 80px rgba(0, 0, 0, 0.45),
    0 0 80px rgba(62, 224, 194, 0.08);
}
.instrument-key {
  margin: 0.9rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
}

@media (min-width: 960px) {
  .hero {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
    padding-top: 2rem;
  }
  .instrument { justify-self: end; }
}

/* Keep copy and instrument as a pair. Do not let 1fr columns
   fling them to the far edges on ultrawide screens. */
@media (min-width: 1500px) {
  .hero {
    grid-template-columns: minmax(0, 38rem) minmax(22rem, 48rem);
    justify-content: center;
    column-gap: clamp(4rem, 4vw, 6.5rem);
    width: min(100%, 130rem);
    margin-inline: auto;
  }
  .hero-copy {
    justify-self: stretch;
    width: min(100%, 38rem);
    max-width: none;
  }
  .instrument {
    justify-self: stretch;
    width: min(100%, 48rem, calc(100svh - var(--mast) - 7.5rem));
  }
}

@media (min-width: 2200px) {
  .hero {
    grid-template-columns: minmax(0, 42rem) minmax(26rem, 56rem);
    column-gap: clamp(4.5rem, 3vw, 6rem);
  }
  .hero-copy { width: min(100%, 42rem); }
  .instrument {
    width: min(100%, 56rem, calc(100svh - var(--mast) - 5.5rem));
  }
}

@media (min-width: 3000px) {
  .hero {
    grid-template-columns: minmax(0, 44rem) minmax(30rem, 64rem);
    column-gap: clamp(5rem, 2.4vw, 7rem);
  }
  .hero-copy { width: min(100%, 44rem); }
  .instrument {
    width: min(100%, 64rem, calc(100svh - var(--mast) - 5rem));
  }
}

@media (min-width: 1800px) {
  :root {
    --gutter: max(3.5rem, env(safe-area-inset-left), env(safe-area-inset-right));
  }
}
@media (min-width: 2400px) {
  :root {
    --gutter: max(4.75rem, env(safe-area-inset-left), env(safe-area-inset-right));
  }
}

/* Primer + magnitudes */

.primer,
.magnitudes,
.ladder-head,
.coda,
.colophon {
  padding: 4.5rem var(--gutter);
}

.primer {
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(21, 32, 56, 0.35), transparent);
}

.primer-grid {
  display: grid;
  gap: 2rem;
  max-width: 72rem;
  margin: 0 auto;
}
.primer p { color: #c5cde0; max-width: 42rem; }
.formula {
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  background: rgba(5, 7, 13, 0.5);
  font-size: 1.05rem;
}
.primer-note {
  padding: 1.3rem 1.4rem;
  border: 1px solid var(--line);
  background: var(--plate);
  backdrop-filter: blur(10px);
  align-self: start;
}
.primer-note p { margin: 0; color: var(--muted); }

@media (min-width: 860px) {
  .primer-grid { grid-template-columns: 1.4fr 0.8fr; align-items: start; }
}

.magnitudes { max-width: 52rem; margin: 0 auto; }
.lede-s { color: var(--muted); max-width: 36rem; }

.bars { display: grid; gap: 1.6rem; margin: 2.2rem 0 1.6rem; }
.bar { margin: 0; }
.bar figcaption {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.45rem;
  font-size: 0.92rem;
  color: var(--muted);
}
.bar-track {
  position: relative;
  height: 1.15rem;
  border-radius: 999px;
  background: rgba(232, 238, 252, 0.06);
  border: 1px solid var(--line);
  overflow: visible;
}
.bar-fill {
  height: 100%;
  width: var(--p);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  box-shadow: 0 0 18px rgba(62, 224, 194, 0.25);
}
.bar-fill.lin {
  min-width: 3px;
  background: var(--ember);
  box-shadow: 0 0 12px rgba(255, 138, 20, 0.5);
}
.bar-pip {
  position: absolute;
  left: var(--p);
  top: calc(100% + 0.35rem);
  translate: -50% 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-hot);
}
.bar-pip.hair { translate: 0 0; left: 0.2rem; }

.factors {
  display: grid;
  gap: 0.55rem;
  padding: 0;
  margin: 2.2rem 0 0;
  list-style: none;
}
.factors li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
}
.factors .mono { color: var(--ink); }

/* Ladder */

.ladder-section {
  padding-bottom: 2rem;
  --unit: 220vh;
}
.ladder-head { max-width: 40rem; padding-bottom: 1rem; }
.ladder-head p { color: var(--muted); }

.ladder {
  max-width: 76rem;
  margin: 0 auto;
  padding: 28vh 0 36vh;
  --span: 3.55;
}
.ladder-track {
  position: relative;
  height: calc(var(--span) * 100vh);
  min-height: 280vh;
}

.filament {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 1.35rem;
  width: 2px;
  background: linear-gradient(
    180deg,
    rgba(139, 151, 179, 0.2),
    var(--teal) 32%,
    var(--gold) 64%,
    var(--blue) 92%,
    transparent
  );
  border-radius: 2px;
  opacity: 0.85;
}
.filament-fill {
  position: absolute;
  top: 0;
  left: -1px;
  width: 4px;
  height: 0%;
  border-radius: 4px;
  background: #fff8e8;
  box-shadow: 0 0 16px rgba(255, 213, 106, 0.7);
}

.ticks, .stations {
  position: absolute;
  inset: 0;
}

.tick {
  position: absolute;
  left: 1.35rem;
  width: 12px;
  height: 1px;
  background: rgba(232, 238, 252, 0.22);
  translate: 0 -50%;
}
.tick[data-major="true"] {
  width: 22px;
  background: rgba(232, 238, 252, 0.5);
}
.tick-label {
  position: absolute;
  left: 2.9rem;
  top: 50%;
  translate: 0 -50%;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  color: rgba(139, 151, 179, 0.85);
  white-space: nowrap;
}

.station {
  position: absolute;
  left: 0;
  right: 0;
  translate: 0 -50%;
}

.node {
  position: absolute;
  left: 1.35rem;
  top: 50%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  translate: -50% -50%;
  background: var(--void);
  border: 2px solid var(--muted);
  box-shadow: 0 0 0 6px rgba(5, 7, 13, 0.7);
  z-index: 2;
}
.station[data-accent="teal"] .node { border-color: var(--teal); box-shadow: 0 0 0 6px rgba(5, 7, 13, 0.7), 0 0 18px rgba(62, 224, 194, 0.45); }
.station[data-accent="gold"] .node { border-color: var(--gold); box-shadow: 0 0 0 6px rgba(5, 7, 13, 0.7), 0 0 22px rgba(240, 193, 74, 0.5); }
.station[data-accent="blue"] .node { border-color: var(--blue); box-shadow: 0 0 0 6px rgba(5, 7, 13, 0.7), 0 0 18px rgba(122, 162, 255, 0.5); }
.station[data-kind="here"] .node {
  width: 22px;
  height: 22px;
  background: radial-gradient(circle at 35% 35%, #fff8e8, #ff8a14);
  border-color: #fff8e8;
  animation: pulse 3.2s ease-in-out infinite;
}
.station[data-kind="horizon"] .node { border-style: dotted; opacity: 0.7; }
.station[data-kind="milestone"] .node,
.station[data-kind="programme"] .node {
  width: 9px;
  height: 9px;
  border-width: 1.5px;
}

.station[data-kind="programme"],
.station[data-kind="milestone"] {
  left: 1.35rem;
  right: auto;
  width: min(22.5rem, calc(100vw - 3rem));
  z-index: 5;
  scroll-margin-top: 5.5rem;
}
.station.is-open { z-index: 12; }

.pip {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  padding: 0.15rem 0.2rem 0.15rem 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.pip .node {
  position: relative;
  left: 0;
  top: 0;
  translate: 0 0;
  flex: 0 0 auto;
  box-shadow: 0 0 0 4px rgba(5, 7, 13, 0.85);
}
.pip-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  background: rgba(5, 7, 13, 0.88);
  padding: 0.12rem 0.4rem;
  border-radius: 2px;
}
.station[data-kind="programme"].is-open .pip-label,
.pip:hover .pip-label,
.pip:focus-visible .pip-label {
  color: var(--ink);
}
.station[data-accent="teal"] .pip-label { color: rgba(62, 224, 194, 0.8); }
.station[data-accent="gold"] .pip-label { color: rgba(240, 193, 74, 0.85); }

.dialog {
  position: absolute;
  left: 1.15rem;
  top: calc(100% + 0.45rem);
  z-index: 9;
  width: min(22.5rem, calc(100vw - 3.4rem));
  padding: 0.95rem 1.05rem 1.1rem;
  background: rgba(8, 12, 22, 0.94);
  border: 1px solid var(--line);
  border-top: 2px solid rgba(232, 238, 252, 0.28);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  text-align: left;
  max-height: min(70vh, 32rem);
  overflow: auto;
}
.station[data-accent="teal"] .dialog { border-top-color: var(--teal); }
.station[data-accent="gold"] .dialog { border-top-color: var(--gold); }
.station[data-accent="blue"] .dialog { border-top-color: var(--blue); }
.dialog h3 {
  font-size: 1.25rem;
  margin: 0 0 0.15rem;
}
.dialog .power-label { margin-bottom: 0.45rem; }
.dialog-place {
  margin: 0 0 0.65rem !important;
  color: var(--gold-hot) !important;
  font-size: 0.92rem;
}
.dialog[hidden] { display: none; }

.station[data-kind="programme"] .plate,
.station[data-kind="milestone"] .plate { display: none; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 6px rgba(5, 7, 13, 0.7), 0 0 0 0 rgba(255, 213, 106, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(5, 7, 13, 0.7), 0 0 0 12px rgba(255, 213, 106, 0); }
}

.plate {
  position: relative;
  z-index: 3;
  margin-left: 3.2rem;
  max-width: 36rem;
  padding: 1.15rem 1.2rem 1.25rem;
  background: var(--plate);
  border: 1px solid var(--line);
  border-top: 2px solid rgba(232, 238, 252, 0.2);
  backdrop-filter: blur(16px);
}
.station[data-accent="teal"] .plate { border-top-color: var(--teal); }
.station[data-accent="gold"] .plate { border-top-color: var(--gold); }
.station[data-accent="blue"] .plate { border-top-color: var(--blue); }
.station[data-kind="here"] .plate {
  background: rgba(28, 20, 8, 0.72);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
}

.plate-kicker {
  margin: 0 0 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.station[data-accent="teal"] .plate-kicker { color: var(--teal); }
.station[data-accent="gold"] .plate-kicker { color: var(--gold); }
.station[data-accent="blue"] .plate-kicker { color: var(--blue); }

.plate h3 {
  font-size: clamp(1.4rem, 2.5vw, 2rem);
  margin: 0 0 0.2rem;
}
.roman {
  font-family: var(--font-display);
  font-weight: 500;
  opacity: 0.45;
  margin-right: 0.35rem;
}
.power-label {
  margin: 0 0 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
}
.plate p { margin: 0; color: #d5dcee; }

.essay {
  display: none;
  margin-top: 0.9rem;
  color: var(--teal);
  font-weight: 500;
  text-decoration: none;
  letter-spacing: 0.03em;
}
.plate:has(.essay[href]) .essay { display: inline-flex; }
.essay:hover { color: var(--gold-hot); }

.station.is-in-view .plate { border-color: rgba(232, 238, 252, 0.28); }

@media (min-width: 900px) {
  .ladder-section { --unit: 130vh; }
  .filament { left: 50%; }
  .tick { left: 50%; }
  .tick-label { left: calc(50% + 1.6rem); }
  .node { left: 50%; }
  .station[data-kind="programme"],
  .station[data-kind="milestone"] {
    left: 50%;
    width: min(24rem, 42vw);
  }
  .pip { translate: -4.5px 0; }
  .dialog { left: 1.35rem; }
  .station[data-kind="programme"][data-side="left"],
  .station[data-kind="milestone"][data-side="left"] {
    left: auto;
    right: 50%;
  }
  .station[data-kind="programme"][data-side="left"] .pip,
  .station[data-kind="milestone"][data-side="left"] .pip {
    flex-direction: row-reverse;
    width: 100%;
    justify-content: flex-start;
    translate: 5px 0;
  }
  .station[data-kind="programme"][data-side="left"] .dialog,
  .station[data-kind="milestone"][data-side="left"] .dialog {
    left: auto;
    right: 1.35rem;
  }
  .station[data-side="left"] .plate {
    margin-left: 0;
    margin-right: calc(50% + 2.4rem);
    margin-left: auto;
    text-align: right;
  }
  .station[data-side="right"] .plate {
    margin-left: calc(50% + 2.4rem);
  }
}

@media (min-width: 1200px) {
  .plate { padding: 1.4rem 1.5rem 1.55rem; }
}

/* Coda */

.coda {
  text-align: center;
  padding-top: 6rem;
  padding-bottom: 5rem;
}
.coda-kicker {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  color: var(--gold-hot);
  margin: 0 0 1rem;
}
.coda-lines {
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 2.4vw, 1.7rem);
  line-height: 1.45;
  color: var(--ink);
  margin: 0 0 1.4rem;
}
.coda-end { color: var(--muted); margin: 0; }

.colophon {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
  max-width: 46rem;
  margin: 0 auto;
}
.colophon p { margin: 0 0 0.7rem; }
.colophon strong { color: var(--ink); font-weight: 500; }
.colophon-small { font-size: 0.82rem; opacity: 0.85; }
.colophon-credit {
  margin: 1.15rem 0 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(139, 151, 179, 0.72);
}
.colophon-credit a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.colophon-credit a:hover,
.colophon-credit a:focus-visible {
  color: var(--muted);
  border-bottom-color: rgba(139, 151, 179, 0.45);
}
.colophon-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.15rem;
  font-size: 0.82rem;
}
.colophon-links a {
  color: rgba(139, 151, 179, 0.8);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  white-space: nowrap;
}
.colophon-links a:hover,
.colophon-links a:focus-visible {
  color: var(--muted);
  border-bottom-color: rgba(139, 151, 179, 0.45);
}

.noscript-stations {
  max-width: 40rem;
  margin: 0 var(--gutter) 3rem;
  color: var(--muted);
}

/* Motion */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .station[data-kind="here"] .node { animation: none; }
}

@media (max-width: 720px) {
  .mast {
    grid-template-columns: 1fr auto;
    height: auto;
    padding: 0.65rem var(--gutter);
  }
  .mast-domain { display: none; }
  .mast-readout { justify-self: end; }
  .mast-p { display: none; }
  .hero { min-height: auto; padding-top: 1.2rem; }
}

/* Print */

@media print {
  .mast, .skip, .descend { display: none; }
  body { background: #fff; color: #111; }
  .plate { break-inside: avoid; background: #fff; color: #111; }
}
