:root {
  --paper: #F3F1F8;
  --paper-2: #E9E5F2;
  --ink: #1E1935;
  --ink-2: #3E3858;
  --muted: #5B5575;
  --rule: #D9D4E7;
  --accent: #6A3FD6;
  --accent-soft: #E3DAFA;
  --r1: #00889E;
  --r2: #6A3FD6;
  --r3: #B8620A;
  --strip-bg: #000004;
  --playhead: #FFFFFF;
  --playhead-shadow: rgba(0, 0, 4, 0.55);
  --strip-wash: rgba(255, 255, 255, 0.08);
  --strip-marker: rgba(255, 255, 255, 0.55);
  --sheet-bg: #FFFFFF;
  --focus: #6A3FD6;
  --shadow: rgba(30, 25, 53, 0.18);
  --shadow-strong: rgba(30, 25, 53, 0.28);
  --serif: "Newsreader", Georgia, serif;
  --sans: "Familjen Grotesk", "Helvetica Neue", Arial, sans-serif;
  --measure: 40rem;
  --wide: 72rem;
  --duration: 200ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #17132A;
    --paper-2: #211C38;
    --ink: #ECE8F7;
    --ink-2: #CFC9E3;
    --muted: #A9A2C4;
    --rule: #2F2848;
    --accent: #9A76F5;
    --accent-soft: #2E2550;
    --r1: #1B9AAB;
    --r2: #9A76F5;
    --r3: #CF7A2A;
    --focus: #B89CFF;
    --shadow: rgba(0, 0, 0, 0.45);
    --shadow-strong: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #17132A;
  --paper-2: #211C38;
  --ink: #ECE8F7;
  --ink-2: #CFC9E3;
  --muted: #A9A2C4;
  --rule: #2F2848;
  --accent: #9A76F5;
  --accent-soft: #2E2550;
  --r1: #1B9AAB;
  --r2: #9A76F5;
  --r3: #CF7A2A;
  --focus: #B89CFF;
  --shadow: rgba(0, 0, 0, 0.45);
  --shadow-strong: rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.1875rem;
  line-height: 1.6;
  font-optical-sizing: auto;
}
a { color: var(--accent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 2px; }

.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: var(--paper); padding: 0.5rem 1rem; font-family: var(--sans); }
.skip:focus { left: 1rem; top: 1rem; z-index: 10; }

h1, h2, h3, h4 { font-family: var(--sans); color: var(--ink); font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 0.75rem; }
h3 { font-size: 1.3rem; line-height: 1.25; margin: 0; }
h4 { font-size: 0.95rem; margin: 1.25rem 0 0.25rem; color: var(--muted); font-weight: 500; }
p { margin: 0 0 1rem; }

.prose { max-width: var(--wide); margin-left: auto; margin-right: auto; padding: 0 16px; }
.prose > * { max-width: var(--measure); }
main > section { margin-top: 5.5rem; }

/* hero */
.hero { max-width: var(--wide); margin: 0 auto; padding: 4.5rem 16px 1rem; }
.byline { font-family: var(--sans); color: var(--muted); font-size: 1rem; margin: 0 0 1.25rem; }
.hero-title {
  font-size: clamp(2.6rem, 7.4vw, 6rem);
  line-height: 0.98;
  letter-spacing: -0.035em;
  font-weight: 700;
  margin: 0 0 1.75rem;
  max-width: 13ch;
}
.hero-copy { max-width: var(--measure); color: var(--ink-2); }
.hero-player { margin-top: 2rem; }

/* spectrogram player: the one bold element */
.player { max-width: var(--wide); margin: 0 auto; }
.strip {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 2.4;
  min-height: 84px;
  background: var(--strip-bg) center / 100% 100% no-repeat;
  border: 0;
  padding: 0;
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
}
.hero-player .strip { aspect-ratio: 16 / 3.6; border-radius: 8px; }
.strip .played {
  position: absolute; inset: 0 auto 0 0; width: 0;
  background: var(--strip-wash);
  pointer-events: none;
}
.strip .head {
  position: absolute; top: 0; bottom: 0; left: 0; width: 2px;
  background: var(--playhead);
  box-shadow: 0 0 0 1px var(--playhead-shadow);
  transform: translateX(-2px);
  pointer-events: none;
}
.strip .marker {
  position: absolute; top: 6px; width: 1px; bottom: 6px;
  background: var(--strip-marker);
  pointer-events: none;
}
.transport {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  font-family: var(--sans); font-size: 0.95rem; color: var(--muted);
  margin-top: 0.6rem;
}
.button, .play {
  font-family: var(--sans); font-size: 0.95rem; font-weight: 600;
  color: var(--paper); background: var(--ink);
  border: 0; border-radius: 999px; padding: 0.45rem 1rem 0.45rem 0.8rem;
  cursor: pointer; display: inline-flex; align-items: center; gap: 0.5rem;
  transition: background-color var(--duration) var(--ease);
}
.button { padding: 0.55rem 1.1rem; }
.play:hover, .button:hover { background: var(--accent); }
.play svg { width: 0.9rem; height: 0.9rem; fill: currentColor; }
.time { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hero-player .caption { color: var(--muted); font-family: var(--sans); font-size: 0.95rem; }

/* hashlinks */
.hashlink {
  margin-left: 0.4em;
  font-family: var(--sans);
  font-weight: 500;
  font-size: 0.8em;
  color: var(--muted);
  text-decoration: none;
  opacity: 0;
  transition: opacity var(--duration) var(--ease), color var(--duration) var(--ease);
}
h2:hover .hashlink, h3:hover .hashlink, .hashlink:focus-visible, .hashlink.copied { opacity: 1; }
.hashlink:hover { color: var(--accent); }
.hashlink.copied { color: var(--accent); font-size: 0.6em; }
@media (hover: none) { .hashlink { opacity: 0.55; } }
section[id], article[id], aside[id], footer[id] { scroll-margin-top: 1.5rem; }

/* method */
.steps { padding-left: 1.4rem; margin: 0 0 1.5rem; }
.steps li { margin-bottom: 0.75rem; padding-left: 0.25rem; }
.note { border-left: 3px solid var(--accent); padding: 0.25rem 0 0.25rem 1.1rem; margin: 2rem 0 0; }
.note h3 { font-size: 1.05rem; margin-bottom: 0.4rem; }
.note p { color: var(--ink-2); margin: 0; }

/* download */
.download { margin-top: 1rem; }
.helper { font-family: var(--sans); font-size: 0.95rem; color: var(--muted); margin-top: 0.5rem; }

/* entries */
.entries { margin-top: 2.5rem; }
.entry { max-width: var(--wide); margin: 0 auto 4.5rem; padding: 0 16px; }
.entry-grid {
  display: grid;
  grid-template-columns: minmax(0, var(--measure)) minmax(0, 17rem);
  justify-content: space-between;
  gap: 2rem 3rem;
  margin-top: 1.5rem;
}
.entry-title { font-size: 1.45rem; }
.entry-credit { font-family: var(--sans); color: var(--muted); font-size: 0.95rem; margin: 0.3rem 0 1rem; }
.entry-headline { font-size: 1.45rem; line-height: 1.3; font-style: italic; color: var(--ink); margin-bottom: 0.25rem; }
.entry-noticed, .entry-felt { color: var(--ink-2); }
.entry-why { font-family: var(--sans); font-size: 0.95rem; color: var(--muted); border-top: 1px solid var(--rule); padding-top: 0.75rem; }
.entry-why:empty { display: none; }
.entry-beat { font-family: var(--sans); font-weight: 600; color: var(--accent); margin: -0.5rem 0 1rem; }
.entry-surprise { border-left: 3px solid var(--accent); padding: 0.1rem 0 0.1rem 1rem; margin: 1rem 0 0.5rem; }
.entry-surprise h4 { margin-top: 0; }
.entry-surprise p { margin: 0; color: var(--ink-2); }
.fugue-sheet { margin-top: 0.5rem; }
.entry-side { font-family: var(--sans); }
.glyph svg { display: block; width: 100%; max-width: 17rem; height: auto; overflow: visible; }
.glyph .petal { fill: var(--accent); fill-opacity: 0.82; stroke: var(--paper); stroke-width: 2; }
.glyph .petal:hover, .glyph .petal:focus { fill-opacity: 1; outline: none; }
.glyph .ring { fill: none; stroke: var(--rule); stroke-width: 1; }
.glyph .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--sans); }
.glyph .axis-val { fill: var(--ink); font-size: 11px; font-weight: 600; font-family: var(--sans); }
.pull { display: flex; align-items: baseline; gap: 0.5rem; margin: 0.5rem 0 1rem; }
.pull-num { font-size: 2.6rem; font-weight: 700; letter-spacing: -0.03em; color: var(--ink); line-height: 1; font-variant-numeric: tabular-nums; }
.pull-label { color: var(--muted); font-size: 0.95rem; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 1rem; margin: 0; font-size: 0.9rem; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; }
.sheet { margin-top: 1.25rem; font-family: var(--sans); font-size: 0.95rem; }
.sheet summary { cursor: pointer; color: var(--accent); }
.sheet img { display: block; width: 100%; max-width: 1100px; height: auto; margin-top: 1rem; border-radius: 6px; background: var(--sheet-bg); }

/* charts */
.chart-fig { max-width: var(--wide); margin: 2rem auto 0; padding: 0 16px; font-family: var(--sans); }
.chart-fig > div[id$="-chart"] { max-width: 56rem; }
.chart-fig figcaption { color: var(--muted); font-size: 0.95rem; margin-top: 0.75rem; max-width: var(--measure); }
.legend { display: flex; gap: 1.25rem; flex-wrap: wrap; font-size: 0.95rem; color: var(--ink-2); margin-bottom: 0.5rem; }
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend i.r1 { background: var(--r1); }
.legend i.r2 { background: var(--r2); }
.legend i.r3 { background: var(--r3); }
.legend i.felt { background: var(--accent); }
.legend i.ring { background: transparent; border: 2px solid var(--accent); }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-svg .grid line { stroke: var(--rule); }
.chart-svg .grid .domain { display: none; }
.chart-svg text { fill: var(--muted); font-family: var(--sans); font-size: 12px; }
.chart-svg .label { fill: var(--ink-2); font-size: 13px; }
.chart-svg .dot { stroke: var(--paper); stroke-width: 2; }
.chart-svg .hit { fill: transparent; cursor: pointer; }
.chart-svg .hit:focus { outline: none; }
.chart-svg .hit:focus + .dot, .chart-svg .row:hover .dot { stroke: var(--ink); }
.chart-svg .stem { stroke: var(--rule); stroke-width: 2; }
.chart-svg .pred { fill: var(--paper); stroke: var(--accent); stroke-width: 2; }
.chart-svg .felt { fill: var(--accent); stroke: var(--paper); stroke-width: 2; }
.tooltip {
  position: fixed; pointer-events: none; z-index: 20;
  background: var(--ink); color: var(--paper);
  font-family: var(--sans); font-size: 0.9rem; line-height: 1.35;
  padding: 0.5rem 0.7rem; border-radius: 6px; max-width: 18rem;
  opacity: 0; transition: opacity var(--duration) var(--ease);
}
.tooltip.show { opacity: 1; }
.table-view { margin-top: 1rem; font-size: 0.95rem; }
.table-view summary { cursor: pointer; color: var(--accent); }
.table-view table { border-collapse: collapse; width: 100%; margin-top: 0.75rem; }
.table-view th, .table-view td { text-align: left; padding: 0.3rem 0.6rem 0.3rem 0; border-bottom: 1px solid var(--rule); }
.table-view td.num { font-variant-numeric: tabular-nums; }

footer { margin: 6rem auto 4rem; font-size: 1rem; color: var(--ink-2); }
footer h2 { font-size: 1.2rem; }
.fine { font-family: var(--sans); font-size: 0.9rem; color: var(--muted); }

@media (max-width: 820px) {
  body { font-size: 1.0625rem; }
  .entry-grid { grid-template-columns: minmax(0, 1fr); }
  .entry-side { display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); gap: 0 1.25rem; align-items: start; }
  .entry-side .glyph { grid-row: span 2; }
  .hero { padding-top: 2.5rem; }
  .hero-player .strip { aspect-ratio: 16 / 5; }
}
@media (max-width: 420px) {
  .entry-side { grid-template-columns: minmax(0, 1fr); }
  .glyph svg { max-width: 14rem; }
}
/* floating playlist */
body.has-fab { padding-bottom: 5.5rem; }
.fab {
  position: fixed; z-index: 15;
  right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 0.55rem;
  height: 3.5rem; padding: 0 1.3rem 0 1.1rem;
  font-family: var(--sans); font-size: 1rem; font-weight: 600;
  color: var(--paper); background: var(--ink);
  border: 0; border-radius: 999px; cursor: pointer;
  box-shadow: 0 6px 20px var(--shadow-strong), 0 1px 3px var(--shadow);
  transition: background-color var(--duration) var(--ease), transform var(--duration) var(--ease);
}
.fab:hover, .fab[aria-expanded="true"] { background: var(--accent); }
.fab:active { transform: scale(0.96); }
.fab-icon svg { width: 1.4rem; height: 1.4rem; fill: currentColor; display: block; }
.fab-bars { display: none; align-items: flex-end; gap: 2px; width: 1.4rem; height: 1.1rem; justify-content: center; }
.fab-bars i { width: 3px; height: 100%; background: currentColor; border-radius: 1px; transform-origin: bottom; animation: pl-bar 900ms var(--ease) infinite alternate; }
.fab-bars i:nth-child(2) { animation-delay: -300ms; }
.fab-bars i:nth-child(3) { animation-delay: -600ms; }
.fab.is-playing .fab-icon { display: none; }
.fab.is-playing .fab-bars { display: inline-flex; }
@keyframes pl-bar { from { transform: scaleY(0.25); } to { transform: scaleY(1); } }

.pl-panel {
  position: fixed; z-index: 14;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 4.25rem);
  width: min(26rem, calc(100vw - 32px));
  max-height: calc(100dvh - 7rem);
  display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 14px;
  box-shadow: 0 18px 48px var(--shadow-strong), 0 2px 6px var(--shadow);
  font-family: var(--sans); font-size: 0.95rem;
  opacity: 0; visibility: hidden; transform: translateY(12px) scale(0.98); transform-origin: bottom right;
  transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease), visibility 0s linear var(--duration);
}
.pl-panel.open { opacity: 1; visibility: visible; transform: none; transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease), visibility 0s; }
.pl-head { display: flex; align-items: center; justify-content: space-between; padding: 0.8rem 0.75rem 0.4rem 1.1rem; }
.pl-head h2 { font-size: 1.15rem; margin: 0; }
.pl-icon {
  flex: none; width: 2.5rem; height: 2.5rem; display: inline-grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink); cursor: pointer;
  transition: background-color var(--duration) var(--ease), color var(--duration) var(--ease);
}
.pl-icon svg { width: 1rem; height: 1rem; fill: currentColor; }
.pl-icon:hover { background: var(--accent-soft); color: var(--accent); }
.pl-icon:disabled { color: var(--rule); background: transparent; cursor: default; }
.pl-toggle { background: var(--ink); color: var(--paper); }
.pl-toggle:hover { background: var(--accent); color: var(--paper); }
.pl-sets { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0.25rem 1.1rem 0.5rem; }
.pl-chip {
  font-family: var(--sans); font-size: 0.875rem; font-weight: 500; white-space: nowrap;
  color: var(--ink-2); background: var(--paper-2);
  border: 1px solid var(--rule); border-radius: 999px; padding: 0.3rem 0.7rem; cursor: pointer;
  transition: background-color var(--duration) var(--ease), color var(--duration) var(--ease), border-color var(--duration) var(--ease);
}
.pl-chip:hover { border-color: var(--accent); color: var(--accent); }
.pl-chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.pl-count { font-variant-numeric: tabular-nums; opacity: 0.75; margin-left: 0.15rem; }
.pl-summary { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.35rem 1.1rem 0.6rem; border-bottom: 1px solid var(--rule); }
.pl-note { margin: 0; color: var(--muted); font-size: 0.875rem; line-height: 1.35; }
.pl-summary .button { flex: none; white-space: nowrap; }
.pl-summary .button svg { width: 0.9rem; height: 0.9rem; fill: currentColor; }
.pl-tracks { list-style: none; margin: 0; padding: 0.35rem 0.5rem; overflow-y: auto; min-height: 6rem; flex: 1 1 auto; overscroll-behavior: contain; }
.pl-track {
  width: 100%; display: grid; grid-template-columns: 1.6rem minmax(0, 1fr) auto; gap: 0.6rem; align-items: center;
  text-align: left; font-family: var(--sans); color: var(--ink);
  background: transparent; border: 0; border-radius: 8px; padding: 0.45rem 0.6rem; cursor: pointer;
  transition: background-color var(--duration) var(--ease);
}
.pl-track:hover { background: var(--paper-2); }
.pl-track.is-current { background: var(--accent-soft); }
.pl-n { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; font-size: 0.85rem; }
.pl-track.is-current .pl-n { color: var(--accent); font-weight: 700; }
.pl-t { display: flex; flex-direction: column; min-width: 0; }
.pl-title { font-size: 0.925rem; font-weight: 500; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-sub { color: var(--muted); font-size: 0.8rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-d { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.pl-now { display: flex; align-items: center; gap: 0.35rem; padding: 0.6rem 0.75rem; border-top: 1px solid var(--rule); background: var(--paper-2); border-radius: 0 0 14px 14px; }
.pl-now-text { display: flex; flex-direction: column; min-width: 0; margin-left: 0.4rem; }
.pl-now-title { font-weight: 600; color: var(--ink); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-now-title:hover { color: var(--accent); text-decoration: underline; }
.pl-now-time { color: var(--muted); font-size: 0.825rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 600px) {
  .fab { height: 3.25rem; padding: 0 1.1rem 0 0.95rem; }
  .pl-panel { left: 16px; right: 16px; width: auto; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 4rem); max-height: calc(100dvh - 6rem); }
  .pl-summary { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  .button, .play, .tooltip, .hashlink, .fab, .pl-panel, .pl-panel.open, .pl-icon, .pl-chip, .pl-track { transition: none; }
  .fab-bars i { animation: none; transform: scaleY(0.7); }
}
