/* Live visualization (/live). Loaded after site.css. */

body.live {
  --bg: #07080a;
  --panel-line: rgba(228, 228, 226, .09);
  --label: #a9acb0;   /* 8.3:1 on --bg */
  --value: #ecebe7;   /* 16:1 */
  --halo: 0 0 3px #07080a, 0 0 8px #07080a, 0 0 14px rgba(7, 8, 10, .9);
  --warm: #f0b26e;
  --cool: #9cc8f2;
  background: var(--bg);
  font-size: 16px;
  line-height: 1.5;
}

.observatory {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- Stage: the p5 field with overlaid title and readout ---------------- */

.stage {
  position: relative;
  height: max(360px, 58vh);
  overflow: hidden;
}

.stage__canvas, .stage__canvas canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.stage__title, .stage__readout {
  position: absolute;
  top: clamp(1rem, 3vh, 2rem);
  z-index: 1;
  font-family: var(--mono);
  pointer-events: none;
  text-shadow: var(--halo);
}

.stage__title { left: clamp(1rem, 2vw, 2rem); }

.stage__title h1 {
  font-size: clamp(1.4rem, 2.6vw, 2.1rem);
  font-weight: 400;
  letter-spacing: .12em;
  text-transform: uppercase;
  line-height: 1.1;
}

.stage__sub {
  margin-top: .35rem;
  font-size: .85rem;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--label);
}

.stage__meta {
  margin-top: 1.1rem;
  font-size: .88rem;
  line-height: 1.6;
  color: var(--label);
}

.stage__readout {
  right: clamp(1rem, 2vw, 2rem);
  font-size: .9rem;
  line-height: 1.6;
  text-align: right;
  color: var(--label);
}

.stage__readout > div { display: flex; justify-content: flex-end; gap: .5ch; }
.stage__readout dt::after { content: ':'; }
.stage__readout > div > dd { color: var(--value); font-variant-numeric: tabular-nums; }
.readout__time dd { color: var(--label); }
.stage__readout > .readout__filters > dd { color: var(--label); }
.filters-link {
  font: inherit;
  color: var(--value);
  text-shadow: inherit;
  line-height: 1.25;
  background: none;
  border: 0;
  border-bottom: 1px solid rgba(240, 120, 84, .7);
  padding: 0;
  cursor: pointer;
  pointer-events: auto;
}
.filters-link:hover, .filters-link:focus-visible { border-bottom-color: #f07854; outline: none; }
.readout__conn { margin-top: .7rem; }

.conn {
  display: inline-flex;
  align-items: center;
  gap: .5ch;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-size: .78rem;
  color: var(--label);
}
.conn::before {
  content: '';
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  background: currentColor;
}
.conn[data-state="connected"] { color: #8fd3a8; }
.conn[data-state="connecting"],
.conn[data-state="reconnecting"],
.conn[data-state="buffering"] { color: var(--warm); }
.conn[data-state="offline"] { color: #e0786e; }

.readout__listen { margin-top: .7rem; }
.readout__listen dd { display: flex; flex-direction: column; align-items: flex-end; gap: .3rem; }

/* Sound switch and volume knob: a small channel strip. */
.strip {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: .9rem;
  padding: .45rem .7rem .4rem .6rem;
  background: linear-gradient(180deg, rgba(28, 29, 32, .82), rgba(12, 13, 15, .82));
  border: 1px solid rgba(228, 228, 226, .14);
  border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05), 0 6px 18px rgba(0, 0, 0, .45);
  text-shadow: none;
}
.strip[hidden] { display: none; }
.strip__status {
  align-self: center;  /* centred under the strip */
  font-size: .72rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--label);
  min-height: 1em;
}

.switch {
  display: grid;
  justify-items: center;
  gap: .3rem;
  font: inherit;
  background: none;
  border: 0;
  padding: 0;
  color: var(--label);
  cursor: pointer;
}
.switch:focus-visible { outline: 1px solid var(--warm); outline-offset: 4px; border-radius: 3px; }
.switch__led {
  width: 7px; height: 7px; border-radius: 50%;
  background: #2a2b2e;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, .6);
  transition: background .2s, box-shadow .2s;
}
.switch[data-state="buffering"] .switch__led { background: var(--warm); box-shadow: 0 0 6px var(--warm); animation: led-blink 1s steps(2) infinite; }
.switch[data-state="on"] .switch__led { background: #8fd3a8; box-shadow: 0 0 8px #8fd3a8; }
@keyframes led-blink { 50% { opacity: .35; } }
.switch__body {
  position: relative;
  width: 18px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(180deg, #0b0c0e, #1b1c1f);
  border: 1px solid rgba(228, 228, 226, .18);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .7);
}
.switch__lever {
  position: absolute; left: 2px; right: 2px; bottom: 2px;
  height: 13px;
  border-radius: 7px;
  background: linear-gradient(180deg, #d9d8d4, #8e8f93);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .6);
  transition: bottom .15s ease;
}
.switch[aria-checked="true"] .switch__lever { bottom: 13px; }
.switch__label, .knob__label {
  font-size: .62rem;
  letter-spacing: .18em;
  text-transform: uppercase;
}
.switch:hover .switch__label, .switch[aria-checked="true"] .switch__label { color: var(--value); }

.knob {
  position: relative;
  display: grid;
  justify-items: center;
  width: 64px;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
  color: var(--label);
}
.knob:focus-visible { outline: 1px solid var(--warm); outline-offset: 2px; border-radius: 6px; }
.knob svg { display: block; width: 58px; height: 58px; overflow: visible; }
.knob__tick { stroke: rgba(228, 228, 226, .28); stroke-width: .8; }
.knob__tick--major { stroke: rgba(228, 228, 226, .6); stroke-width: 1.1; }
.knob__unity { fill: var(--warm); }
.knob__arc { fill: none; stroke: var(--warm); stroke-width: 1.6; stroke-linecap: round; opacity: .75; }
.knob__skirt {
  fill: #141518;
  stroke: rgba(228, 228, 226, .22);
  stroke-width: 1;
  stroke-dasharray: 1.2 1.6;  /* the ridged rim */
}
.knob__cap { fill: #2a2c30; stroke: rgba(0, 0, 0, .6); stroke-width: 1; }
.knob__pointer { stroke: var(--value); stroke-width: 2.2; stroke-linecap: round; }
.knob:hover .knob__pointer, .knob:focus-visible .knob__pointer { stroke: var(--warm); }
.knob__label { margin-top: -.1rem; }
.knob__value {
  font-size: .68rem;
  color: var(--value);
  font-variant-numeric: tabular-nums;
}

/* ---- Memory dial: motifs as stations on a tuning scale ---------------- */

.dial {
  position: relative;
  padding: .4rem clamp(1rem, 2vw, 2rem) .7rem;
  border-top: 1px solid var(--panel-line);
  background: linear-gradient(180deg, rgba(240, 178, 110, .025), rgba(7, 8, 10, 0));
}
.dial > canvas { display: block; width: 100%; height: 88px; cursor: default; }
.dial__legend {
  margin-top: .2rem;
  font-family: var(--mono);
  font-size: .74rem;
  color: var(--label);
}
.dial__title {
  margin-right: 1ch;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--value);
}
.dial__needle { color: #f07854; }
.dial__foot { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.dial__export {
  flex: none;
  margin-top: .2rem;
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--label);
  background: rgba(7, 8, 10, .6);
  border: 1px solid rgba(240, 120, 84, .45);
  border-radius: 3px;
  padding: .2rem .55rem;
  cursor: pointer;
}
.dial__export:hover, .dial__export:focus-visible { color: var(--value); border-color: #f07854; outline: none; }
.dial__export:disabled { opacity: .45; cursor: default; }
.dial__foot .dial__legend { min-width: 0; }

.motif-tip {
  position: absolute;
  z-index: 2;
  padding: .35rem .6rem;
  font-family: var(--mono);
  font-size: .8rem;
  line-height: 1.5;
  color: var(--value);
  background: rgba(7, 8, 10, .92);
  border: 1px solid rgba(228, 228, 226, .2);
  white-space: nowrap;
  pointer-events: none;
}
.motif-tip b { font-weight: 400; }
.motif-tip span { color: var(--label); }

/* ---- Filters overlay ----------------------------------------------------- */

.filters {
  margin: auto;
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  padding: 1.3rem 1.5rem 1.2rem;
  font-family: var(--mono);
  font-size: .85rem;
  line-height: 1.6;
  color: var(--label);
  background: rgba(7, 8, 10, .96);
  border: 1px solid rgba(228, 228, 226, .2);
}
.filters::backdrop { background: rgba(7, 8, 10, .7); }
.filters h2 {
  font-size: .8rem;
  font-weight: 400;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--value);
  margin-bottom: .7rem;
}
.filters ul { list-style: none; margin: .9rem 0; padding: 0; }
.filters li { padding: .55rem 0; border-top: 1px solid var(--panel-line); color: var(--value); }
.filters li:last-child { border-bottom: 1px solid var(--panel-line); }
.filters li span { color: var(--label); }
.filters li span::before { content: '· '; }
.filters li code { display: block; font: inherit; font-size: .78rem; color: var(--label); overflow-wrap: anywhere; }
.filters form { margin-top: 1rem; text-align: right; }

/* ---- Panels ------------------------------------------------------------- */

/* Two independent column groups: the signal plots (with the harmonic map
   below them) and the observations (with the interpretation below them).
   Text that grows on one side never pushes the other side down. */
.panels {
  display: grid;
  grid-template-columns: 2.35fr 2.1fr;
  gap: 2rem;
  align-items: start;
  padding: 1.2rem clamp(1rem, 2vw, 2rem) 1.5rem;
  border-top: 1px solid var(--panel-line);
}

.panels__group {
  display: grid;
  gap: 1.4rem 2rem;
  align-items: start;
  min-width: 0;
}
.panels__group--signal { grid-template-columns: 1.35fr 1fr; }
.panels__group--observations { grid-template-columns: 1fr 1.1fr; }

.panel { min-width: 0; }
.panel--harmonic, .panel--interpretation { grid-column: 1 / -1; }
.panel--interpretation { border-left: 1px solid var(--panel-line); padding-left: 2rem; }
.panel--events { border-left: 1px solid var(--panel-line); padding-left: 2rem; }

.panel h2 {
  font-family: var(--mono);
  font-size: .82rem;
  font-weight: 400;
  letter-spacing: .22em;
  color: var(--value);
  margin-bottom: .7rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .3rem 1rem;
}

.phase {
  font-size: .72rem;
  letter-spacing: .1em;
  color: var(--label);
  border: 1px solid var(--panel-line);
  padding: 0 .45rem;
}

.plot {
  display: grid;
  grid-template-columns: 1fr;
  font-family: var(--mono);
  font-size: .74rem;
  color: var(--label);
}
.plot--yaxis { grid-template-columns: 4.4rem 1fr; }
.plot canvas {
  width: 100%;
  height: calc(140px * var(--plot-scale, 1));
  display: block;
  background: rgba(255, 255, 255, .015);
  border: 1px solid var(--panel-line);
}
.panel--harmonic canvas { height: 112px; }
.plot--yaxis .axis--x { grid-column: 2; }

.axis { list-style: none; }
.axis--x {
  display: flex;
  justify-content: space-between;
  margin-top: .3rem;
}
.axis--y {
  position: relative;
  margin-right: .5rem;
}
.axis--y li, .axis--log li {
  position: absolute;
  white-space: nowrap;
}
.axis--y li { right: 0; transform: translateY(-50%); }
.axis--log { position: relative; height: 1.2em; }
.axis--log li { transform: translateX(-50%); }

.features, .events { font-family: var(--mono); font-size: .88rem; }

.features div {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 1rem;
  padding: .2rem 0;
  border-bottom: 1px solid var(--panel-line);
}
.features dt { color: var(--label); }
.features dd { color: var(--value); font-variant-numeric: tabular-nums; }

.events { list-style: none; }
.events li {
  display: grid;
  grid-template-columns: 6.2rem 1fr;
  gap: .8rem;
  padding: .2rem 0;
  color: var(--value);
}
.events time { color: var(--label); font-variant-numeric: tabular-nums; }
.events .events__empty { display: block; color: var(--label); }
.events li[data-kind="transient"] span { color: var(--cool); }
.events li[data-kind="resonance"] span { color: var(--warm); }
.events li[data-kind="end"] span { color: var(--label); }
.events li[data-kind="motif"] span { color: #c9b8f0; }

.interpretation {
  list-style: none;
  font-family: var(--mono);
  font-size: .84rem;
  line-height: 1.6;
  color: var(--label);
}
.interpretation li {
  display: grid;
  grid-template-columns: 5.2rem 1fr;
  gap: .8rem;
  padding: .3rem 0;
  border-bottom: 1px solid var(--panel-line);
}
.interpretation time { font-variant-numeric: tabular-nums; }
.interpretation__now span { color: var(--value); }
.interpretation .interpretation__wait { display: block; border: 0; font-style: italic; }
.interpretation__meta {
  margin-top: .6rem;
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--label);
}

/* Teleprinter line above the dial. */
.teleprinter {
  display: flex;
  align-items: center;
  gap: .9rem;
  min-height: 2.2rem;
  padding: .35rem 0 .45rem;
  margin-bottom: .2rem;
  border-bottom: 1px solid var(--panel-line);
  font-family: var(--mono);
}
.teleprinter__label {
  flex: none;
  padding-right: .9rem;
  border-right: 2px solid #f07854;
  font-size: .72rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--value);
}
.teleprinter__scroll {
  flex: 1;
  min-width: 0;
  height: 3em;                 /* one text (up to two lines) at a time */
  overflow-y: auto;
  overscroll-behavior: contain; /* the page doesn't scroll at the ends */
  scroll-snap-type: y mandatory;
  scrollbar-width: none;        /* the jog wheel replaces the scrollbar */
  font-size: .95rem;
  line-height: 1.5;
}
.teleprinter__scroll:focus-visible { outline: 1px solid rgba(240, 120, 84, .6); outline-offset: 2px; }
.teleprinter__scroll::-webkit-scrollbar { display: none; }
.jog {
  flex: none;
  width: 18px;
  height: 2.9em;
  cursor: ns-resize;
  touch-action: none;
}
.jog[hidden] { display: none; }
.jog.is-idle { opacity: .35; cursor: default; }
.jog:focus-visible { outline: 1px solid rgba(240, 120, 84, .6); outline-offset: 2px; border-radius: 4px; }
.teleprinter__list { list-style: none; }
.teleprinter__list li {
  display: flex;
  align-items: center;
  gap: .9rem;
  min-height: 3em;
  scroll-snap-align: start;
}
.teleprinter__list time {
  flex: none;
  font-size: .78rem;
  color: var(--label);
  font-variant-numeric: tabular-nums;
}
.teleprinter__list span { color: var(--value); }
.teleprinter__list li + li span { color: var(--label); }
.teleprinter__wait span { color: var(--label); font-style: italic; }
.teleprinter__list span.is-typing::after {
  content: '▌';
  margin-left: .15ch;
  color: #f07854;
  animation: tp-blink 1s steps(1) infinite;
}
@keyframes tp-blink { 50% { opacity: 0; } }
.teleprinter__more {
  flex: none;
  align-self: center;
  font: inherit;
  font-size: .72rem;
  color: var(--label);
  background: none;
  border: 0;
  cursor: pointer;
  white-space: nowrap;
}
.teleprinter__more.is-new { color: #f07854; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 640px) {
  .teleprinter { flex-wrap: wrap; gap: .3rem .8rem; }
  .teleprinter__scroll { flex-basis: 100%; height: 4.5em; }
  .teleprinter__list li { min-height: 4.5em; }
}

.credit {
  margin-top: auto;
  padding: 1rem clamp(1rem, 2vw, 2rem) 1.4rem;
  border-top: 1px solid var(--panel-line);
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--label);
}

/* Wide screens: the page fits the window. The stage takes whatever height
   the dial, panels and credit leave; everything below it has a fixed height
   (single-line events and features), so the waves don't jump. */
@media (min-width: 1101px) {
  .observatory { height: 100vh; height: 100dvh; }
  .stage { flex: 1 1 auto; height: auto; min-height: 320px; }
  .dial, .panels, .credit { flex: none; }
  .credit { margin-top: 0; }
  .plot canvas { height: calc(100px * var(--plot-scale, 1)); }
  .panel--harmonic canvas { height: 76px; }
  .panels { padding-top: .9rem; padding-bottom: 1rem; gap: 1rem 2rem; }
  .panels__group { gap: 1rem 2rem; }
}
/* Short windows: tighter still, so the waves keep their room. */
@media (min-width: 1101px) and (max-height: 860px) {
  .stage { min-height: 270px; }
  .dial__legend { display: none; }
  .plot canvas { height: calc(76px * var(--plot-scale, 1)); }
  .panel--harmonic canvas { height: 56px; }
  .features div, .events li { padding: .1rem 0; }
  .credit { padding-top: .6rem; padding-bottom: .7rem; }
}

.features dt {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.events li span, .features dd {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 1100px) {
  .panels { grid-template-columns: 1fr; }
  .panel--events, .panel--interpretation { border-left: 0; padding-left: 0; }
}

@media (max-width: 640px) {
  .stage { height: 62vh; }
  .stage__meta { display: none; }
  .panels__group--signal, .panels__group--observations { grid-template-columns: 1fr; }
}
