/* ─── Cadence · laboratory-radio aesthetic ─────────────────────────────── */

:root {
  --bg: #08090b;
  --bg-elev: #0f1114;
  --panel: #14171c;
  --panel-hi: #1b1f26;
  --ink: #ece9df;
  --ink-dim: #878a93;
  --ink-faint: #4a4d55;
  --line: #272931;
  --line-hi: #3a3d47;

  --phosphor: #b8ff5a;
  --phosphor-deep: #72a030;
  --phosphor-glow: rgba(184, 255, 90, 0.4);

  --amber: #ffb547;
  --amber-deep: #8a5e1e;
  --rust: #ff6d52;
  --rust-deep: #8a2c1a;

  --radius: 4px;
  --radius-lg: 10px;
  --ease-snap: cubic-bezier(.2, .8, .2, 1);

  --font-display: "Fraunces", "Times New Roman", serif;
  --font-sans: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  min-height: 100vh;
  font-feature-settings: "ss01", "cv11";
  overflow-x: hidden;
  position: relative;
}

/* ─── Atmosphere ─────────────────────────────────────────────────────── */

.grain {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1000;
  opacity: .035;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  mix-blend-mode: overlay;
}

.scanlines {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 999;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(255, 255, 255, 0.015) 3px,
    transparent 4px
  );
}

body::before {
  content: "";
  position: fixed;
  inset: -10%;
  background:
    radial-gradient(circle at 15% 10%, rgba(184, 255, 90, 0.06), transparent 45%),
    radial-gradient(circle at 85% 90%, rgba(255, 181, 71, 0.04), transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ─── Typography helpers ─────────────────────────────────────────────── */

.mono { font-family: var(--font-mono); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.mono.dim { color: var(--ink-dim); }

/* ─── Masthead ──────────────────────────────────────────────────────── */

.masthead {
  max-width: 920px;
  margin: 0 auto;
  padding: 3rem 1.5rem 2rem;
  position: relative;
  z-index: 1;
  border-bottom: 1px solid var(--line);
}

.mast-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.75rem;
  color: var(--ink-dim);
}
.mast-meta .mono:last-child {
  color: var(--phosphor);
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}
.mast-meta .mono:last-child::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--phosphor);
  box-shadow: 0 0 10px var(--phosphor-glow);
  animation: blink 1.6s steps(1) infinite;
}
@keyframes blink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: .25; } }

.wordmark {
  font-family: var(--font-display);
  font-weight: 400;
  font-style: italic;
  font-size: clamp(4rem, 13vw, 8.5rem);
  line-height: .88;
  margin: 0;
  letter-spacing: -0.04em;
  font-variation-settings: "opsz" 144;
  color: var(--ink);
}
.wordmark .period { color: var(--phosphor); font-style: normal; }

.tagline {
  margin: 1.2rem 0 1.75rem;
  font-size: 1.05rem;
  max-width: 42ch;
  color: var(--ink);
}
.tagline em {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 1.15em;
}
.tagline .mono { color: var(--ink-dim); font-size: .78rem; }

.legend {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding-top: 1.25rem;
  border-top: 1px dashed var(--line);
}
.legend-item { display: inline-flex; align-items: center; gap: .5rem; color: var(--ink-dim); }
.legend .dot { width: 8px; height: 8px; border-radius: 1px; }
.legend .dot.tierA { background: var(--phosphor); box-shadow: 0 0 8px var(--phosphor-glow); }
.legend .dot.tierB { background: transparent; border: 1px solid var(--phosphor); }
.legend .dot.tierC { background: transparent; border: 1px solid var(--amber); }

/* ─── Grid ──────────────────────────────────────────────────────────── */

main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  position: relative;
  z-index: 1;
}

#audio-banner {
  grid-column: 1 / -1;
  padding: .75rem 1rem;
  border: 1px solid var(--phosphor);
  border-radius: var(--radius);
  background: rgba(184, 255, 90, 0.05);
  color: var(--phosphor);
  text-align: center;
  animation: pulse-border 2s ease-in-out infinite;
}
@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 var(--phosphor-glow); }
  50% { box-shadow: 0 0 0 4px rgba(184, 255, 90, 0.08); }
}

/* ─── Card (module) ─────────────────────────────────────────────────── */

.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-elev) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.25rem 1.1rem;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  transition: border-color .25s var(--ease-snap), transform .25s var(--ease-snap);
  overflow: hidden;
  isolation: isolate;
}

/* corner tick marks — like a lab panel */
.card::before,
.card::after {
  content: "";
  position: absolute;
  width: 12px; height: 12px;
  pointer-events: none;
  opacity: .5;
}
.card::before {
  top: 8px; left: 8px;
  border-top: 1px solid var(--line-hi);
  border-left: 1px solid var(--line-hi);
}
.card::after {
  bottom: 8px; right: 8px;
  border-bottom: 1px solid var(--line-hi);
  border-right: 1px solid var(--line-hi);
}

.card:hover {
  border-color: var(--line-hi);
  transform: translateY(-1px);
}

.card.playing {
  border-color: var(--phosphor);
  box-shadow:
    0 0 0 1px var(--phosphor) inset,
    0 0 24px -6px var(--phosphor-glow),
    0 0 80px -20px var(--phosphor-glow);
  animation: breathe 4s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 1px var(--phosphor) inset, 0 0 24px -6px var(--phosphor-glow); }
  50% { box-shadow: 0 0 0 1px var(--phosphor) inset, 0 0 40px -4px var(--phosphor-glow); }
}

/* card header — two-column layout */
.card-head {
  display: flex;
  flex-direction: row;
  gap: 0.75rem;
  padding-bottom: .75rem;
  border-bottom: 1px dashed var(--line);
}

.card-head-left {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.card-head-right {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.25rem;
}

.slot {
  font-family: var(--font-mono);
  font-size: .7rem;
  color: var(--ink-dim);
  letter-spacing: .12em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.slot .glyph {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--phosphor);
}
.slot .icon {
  font-size: .9rem;
  filter: saturate(.7);
}

.tier {
  font-family: var(--font-mono);
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .12em;
  padding: 3px 8px;
  vertical-align: middle;
  border-radius: 2px;
  white-space: nowrap;
  text-transform: uppercase;
  flex-shrink: 0;
}
.tier.A { background: var(--phosphor); color: #0a1400; }
.tier.B { background: transparent; color: var(--phosphor); border: 1px solid var(--phosphor-deep); }
.tier.C { background: transparent; color: var(--amber); border: 1px solid var(--amber-deep); }

/* info button */
.card button.info {
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid var(--line-hi);
  height: 22px;
  padding: 0 .5rem;
  border-radius: 2px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: .62rem;
  font-weight: 500;
  letter-spacing: .1em;
  transition: all .15s ease;
  white-space: nowrap;
}
.card button.info::before { content: "+ INFO"; }
.card button.info:hover { color: var(--ink); border-color: var(--ink-dim); }
.card button.info.open { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.card button.info.open::before { content: "− CLOSE"; }

/* frequency readout — the hero of each module */
.freq-readout {
  font-family: var(--font-mono);
  display: flex;
  align-items: baseline;
  gap: .3rem;
  color: var(--ink);
  padding-top: 0;
  margin-bottom: -0.25rem;
}
.freq-readout .value {
  font-size: 1.6rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--phosphor);
  text-shadow: 0 0 12px rgba(184, 255, 90, 0.25);
}
.card.info-only .freq-readout .value { color: var(--amber); text-shadow: 0 0 12px rgba(255, 181, 71, 0.2); }
.freq-readout .unit {
  font-size: .85rem;
  color: var(--ink-dim);
  letter-spacing: .05em;
}
/* modality label */
.card-head-right > .mode {
  font-family: var(--font-mono);
  font-size: .6rem;
  font-weight: 500;
  letter-spacing: .12em;
  color: var(--ink-faint);
  text-transform: uppercase;
  white-space: nowrap;
}

/* Special frequency readouts (Non-numeric) */
.freq-readout.special {
  align-items: flex-end;
  height: 3.6rem;
}

.special-graphic {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  max-width: 140px;
}

/* Tinnitus Notch SVG */
.notch-svg {
  width: 100%;
  height: 40px;
  color: var(--phosphor-dim);
  overflow: visible;
}
.notch-svg path {
  stroke: var(--phosphor);
  opacity: 0.7;
}
.notch-svg circle {
  animation: pulse-notch 2s infinite alternate;
}
@keyframes pulse-notch {
  0% { opacity: 0.4; transform: scale(0.8); }
  100% { opacity: 1; transform: scale(1.3); }
}

/* White Noise Spectrogram */
.spectrogram {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 30px;
  width: 100%;
}
.spectrogram span {
  flex: 1;
  background: var(--phosphor);
  opacity: 0.6;
  animation: noise-bar 0.5s infinite alternate;
  transform-origin: bottom;
}
.spectrogram span:nth-child(1) { animation-duration: 0.4s; height: 60%; }
.spectrogram span:nth-child(2) { animation-duration: 0.6s; height: 100%; }
.spectrogram span:nth-child(3) { animation-duration: 0.3s; height: 40%; }
.spectrogram span:nth-child(4) { animation-duration: 0.7s; height: 80%; }
.spectrogram span:nth-child(5) { animation-duration: 0.5s; height: 30%; }
.spectrogram span:nth-child(6) { animation-duration: 0.45s; height: 90%; }
.spectrogram span:nth-child(7) { animation-duration: 0.35s; height: 50%; }
.spectrogram span:nth-child(8) { animation-duration: 0.65s; height: 70%; }
.spectrogram span:nth-child(9) { animation-duration: 0.55s; height: 45%; }
.spectrogram span:nth-child(10) { animation-duration: 0.4s; height: 85%; }
.spectrogram span:nth-child(11) { animation-duration: 0.6s; height: 35%; }
.spectrogram span:nth-child(12) { animation-duration: 0.5s; height: 65%; }
.spectrogram span:nth-child(13) { animation-duration: 0.3s; height: 50%; }
.spectrogram span:nth-child(14) { animation-duration: 0.7s; height: 80%; }
.spectrogram span:nth-child(15) { animation-duration: 0.45s; height: 40%; }
.spectrogram span:nth-child(16) { animation-duration: 0.55s; height: 90%; }

@keyframes noise-bar {
  0% { transform: scaleY(0.5); opacity: 0.4; }
  100% { transform: scaleY(1); opacity: 0.8; }
}

/* headline */
.card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-style: italic;
  font-variation-settings: "opsz" 60;
  font-size: 1.5rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.blurb {
  margin: 0;
  color: var(--ink-dim);
  font-size: .92rem;
  line-height: 1.55;
}

.disclosure {
  background: rgba(255, 109, 82, 0.08);
  border-left: 2px solid var(--rust);
  padding: .6rem .8rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: .82rem;
  color: var(--ink);
}

/* details panel */
.details {
  margin-top: .5rem;
  padding-top: .9rem;
  border-top: 1px dashed var(--line);
  animation: slide-in .3s var(--ease-snap);
}
@keyframes slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.details .tech-label {
  font-family: var(--font-mono);
  font-size: .65rem;
  color: var(--phosphor-deep);
  letter-spacing: .15em;
  text-transform: uppercase;
  margin-bottom: .4rem;
}
.details .tech-note { font-size: .88rem; color: var(--ink); margin-bottom: .65rem; }
.details .dose {
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--ink-dim);
  letter-spacing: .06em;
  margin-bottom: .75rem;
  padding: .4rem .6rem;
  border: 1px dashed var(--line-hi);
  border-radius: 2px;
  display: inline-block;
}
.cite {
  display: block;
  font-size: .82rem;
  color: var(--ink);
  text-decoration: none;
  padding: .55rem .7rem;
  margin-top: .35rem;
  background: rgba(184, 255, 90, 0.03);
  border-left: 1px solid var(--phosphor-deep);
  border-radius: 0 2px 2px 0;
  transition: all .15s ease;
  position: relative;
  line-height: 1.4;
}
.cite::before {
  content: "↗";
  position: absolute;
  top: .55rem; right: .6rem;
  color: var(--phosphor);
  font-size: .75rem;
  opacity: 0;
  transition: opacity .15s;
}
.cite:hover {
  background: rgba(184, 255, 90, 0.08);
  border-left-color: var(--phosphor);
  padding-right: 1.8rem;
}
.cite:hover::before { opacity: 1; }

/* ─── Play control — hardware toggle ─────────────────────────────── */

.controls {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  padding-top: .5rem;
}

.card button.play {
  background: var(--panel-hi);
  color: var(--ink);
  border: 1px solid var(--line-hi);
  border-radius: var(--radius);
  padding: .9rem 1.1rem;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  position: relative;
  transition: transform .08s var(--ease-snap), background .15s;
  box-shadow: 0 3px 0 #000, inset 0 1px 0 rgba(255, 255, 255, 0.03);
  font-family: var(--font-mono);
}
.card button.play:hover { background: #22262e; }
.card button.play:active { transform: translateY(3px); box-shadow: 0 0 0 #000, inset 0 1px 0 rgba(255, 255, 255, 0.03); }

.card button.play .led {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex-shrink: 0;
  transition: all .2s;
}
.card button.play .label { flex: 1; text-align: left; }
.card button.play .dose-txt { color: var(--ink-dim); font-weight: 400; }

.card.playing button.play {
  background: #1a1f13;
  color: var(--phosphor);
  border-color: var(--phosphor);
  box-shadow: 0 3px 0 var(--phosphor-deep), inset 0 0 20px rgba(184, 255, 90, 0.08);
}
.card.playing button.play .led {
  background: var(--phosphor);
  box-shadow: 0 0 10px var(--phosphor-glow), 0 0 20px var(--phosphor-glow);
  animation: led-pulse 1.2s ease-in-out infinite;
}
@keyframes led-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
.card.playing button.play .dose-txt { color: var(--phosphor-deep); }

.card button[disabled] { opacity: .4; cursor: not-allowed; }

/* progress strip — oscilloscope fill */
.progress {
  height: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 1px;
  overflow: hidden;
  display: none;
  position: relative;
}
.card.playing .progress { display: block; }
.progress::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(to right, var(--line-hi) 0 1px, transparent 1px 10%);
  pointer-events: none;
  z-index: 2;
  opacity: .6;
}
.progress .fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--phosphor-deep), var(--phosphor));
  box-shadow: 0 0 8px var(--phosphor-glow);
  transition: width .4s linear;
}

.remaining {
  font-family: var(--font-mono);
  font-size: .7rem;
  letter-spacing: .1em;
  color: var(--ink-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-transform: uppercase;
}
.card:not(.playing) .remaining { display: none; }
.remaining::before {
  content: "⟶ elapsed";
  color: var(--ink-faint);
}

/* info-only cards */
.card.info-only { opacity: .92; }
.card.info-only .slot .glyph { color: var(--amber); }
.card.info-only::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(45deg, transparent 0 8px, rgba(255, 181, 71, 0.03) 8px 9px);
  border-bottom-right-radius: var(--radius-lg);
  width: auto; height: auto;
  border: 0;
  opacity: .5;
}

/* ─── Modal ─────────────────────────────────────────────────────────── */

dialog {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--phosphor);
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 440px;
  width: 90vw;
  box-shadow: 0 0 0 1px var(--bg), 0 20px 60px -10px rgba(0, 0, 0, 0.8), 0 0 80px -20px var(--phosphor-glow);
  font-family: var(--font-sans);
}
dialog::backdrop { background: rgba(8, 9, 11, 0.85); backdrop-filter: blur(8px); }

dialog .modal-head {
  padding: .8rem 1.25rem;
  border-bottom: 1px dashed var(--line);
  color: var(--phosphor);
}
dialog h2 {
  margin: 1rem 1.25rem .4rem;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 1.6rem;
  line-height: 1.15;
}
dialog p { margin: 0 1.25rem 1.25rem; color: var(--ink-dim); font-size: .9rem; }

.probe { padding: 0 1.25rem 1rem; }
.freq-big {
  display: block;
  font-family: var(--font-mono);
  font-size: 3rem;
  font-weight: 500;
  color: var(--phosphor);
  text-align: center;
  letter-spacing: -0.02em;
  text-shadow: 0 0 20px var(--phosphor-glow);
  margin-bottom: .75rem;
  font-variant-numeric: tabular-nums;
}
.freq-big span { font-size: 1rem; color: var(--ink-dim); margin-left: .3rem; }

dialog input[type="range"] {
  width: 100%;
  accent-color: var(--phosphor);
  margin: .5rem 0 .25rem;
}
.scale { display: flex; justify-content: space-between; color: var(--ink-faint); }

.modal-actions {
  display: flex;
  gap: .5rem;
  padding: 1rem 1.25rem;
  border-top: 1px dashed var(--line);
  justify-content: flex-end;
}
dialog button {
  background: var(--phosphor);
  color: #0a1400;
  border: 0;
  padding: .6rem 1.1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  transition: transform .08s var(--ease-snap);
  box-shadow: 0 3px 0 var(--phosphor-deep);
}
dialog button:active { transform: translateY(3px); box-shadow: 0 0 0 var(--phosphor-deep); }
dialog #tinnitus-cancel {
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid var(--line-hi);
  box-shadow: 0 3px 0 #000;
}

/* ─── Footer ────────────────────────────────────────────────────────── */

footer {
  max-width: 920px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
  position: relative;
  z-index: 1;
}
.foot-rule {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line-hi), transparent);
  margin-bottom: 1.5rem;
}
footer p { color: var(--ink-dim); text-align: center; margin: 0; }
footer a { color: var(--phosphor); text-decoration: none; border-bottom: 1px dashed var(--phosphor-deep); }
footer a:hover { color: var(--ink); }

/* ─── Responsive ────────────────────────────────────────────────────── */

@media (max-width: 680px) {
  .masthead { padding: 2rem 1.25rem 1.5rem; }
  main { padding: 1.5rem 1rem 3rem; grid-template-columns: 1fr; }
  .legend { gap: 1rem; font-size: .7rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .05ms !important; }
}
