/* Stillwater — a calm room, after dark */

:root {
  --bg: #12101a;
  --bg-soft: #1a1726;
  --panel: rgba(30 26 44 / 0.72);
  --panel-edge: rgba(255 235 200 / 0.08);
  --ink: #ece5d8;
  --ink-dim: #9c94a8;
  --ink-faint: #6b6478;
  --amber: #e8b46a;
  --c-brown: hsl(22 70% 62%);
  --c-pink: hsl(340 55% 68%);
  --c-rain: hsl(205 60% 64%);
  --c-binaural: hsl(266 55% 70%);
  --radius: 18px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0 clamp(14px, 4vw, 48px) calc(40px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

/* slow aurora behind everything */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60% 45% at 18% 8%, rgba(84 64 120 / 0.28), transparent 70%),
    radial-gradient(55% 40% at 85% 18%, rgba(120 78 60 / 0.20), transparent 70%),
    radial-gradient(70% 60% at 55% 100%, rgba(40 60 90 / 0.22), transparent 75%),
    var(--bg);
  animation: backdropDrift 90s ease-in-out infinite alternate;
}
@keyframes backdropDrift {
  from { transform: translate3d(-1.5%, -1%, 0) scale(1.02); }
  to   { transform: translate3d(1.5%, 1%, 0) scale(1.06); }
}
@media (prefers-reduced-motion: reduce) {
  .backdrop { animation: none; }
}

/* ---------- masthead ---------- */

.masthead {
  width: 100%;
  max-width: 1180px;
  padding-top: clamp(22px, 5vh, 54px);
}
.masthead-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 44px; height: 44px; color: var(--amber); opacity: 0.9; }
.brand h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.7rem, 3.4vw, 2.3rem);
  letter-spacing: 0.02em;
  margin: 0;
  line-height: 1.05;
}
.tagline {
  margin: 2px 0 0;
  color: var(--ink-dim);
  font-size: 0.82rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.transport {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 999px;
  padding: 10px 22px 10px 12px;
  backdrop-filter: blur(8px);
}

.play-btn {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid rgba(255 235 200 / 0.22);
  background: radial-gradient(circle at 35% 30%, #3a3350, #221d33 70%);
  color: var(--amber);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  flex: none;
}
.play-btn:hover { transform: scale(1.05); box-shadow: 0 0 26px rgba(232 180 106 / 0.22); }
.play-btn svg { width: 24px; height: 24px; fill: currentColor; grid-area: 1 / 1; }
.play-btn .icon-pause { display: none; }
.play-btn[aria-pressed="true"] .icon-pause { display: block; }
.play-btn[aria-pressed="true"] .icon-play { display: none; }
.play-ring {
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 1px solid rgba(232 180 106 / 0.55);
  opacity: 0;
  pointer-events: none;
}
.play-btn:not([aria-pressed="true"]) .play-ring { animation: invite 3.2s ease-out infinite; }
@keyframes invite {
  0% { transform: scale(1); opacity: 0.5; }
  70%, 100% { transform: scale(1.45); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .play-btn:not([aria-pressed="true"]) .play-ring { animation: none; opacity: 0.25; }
}

.transport-fields { display: flex; align-items: center; gap: 20px; }
.master-vol label, .sleep label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 4px;
}
.master-vol output { color: var(--amber); }
.master-vol input { width: 130px; }
.sleep-row { display: flex; align-items: center; gap: 8px; }
.sleep select {
  background: var(--bg-soft);
  color: var(--ink);
  border: 1px solid var(--panel-edge);
  border-radius: 9px;
  padding: 6px 8px;
  font-size: 0.85rem;
  min-height: 34px;
}
.sleep-count {
  font-variant-numeric: tabular-nums;
  color: var(--amber);
  font-size: 0.85rem;
  min-width: 3.2em;
}

.status-line {
  margin: 14px 4px 0;
  color: var(--ink-dim);
  font-size: 0.86rem;
  letter-spacing: 0.02em;
  transition: opacity 0.6s ease;
}

/* ---------- visualization ---------- */

.viz-wrap {
  width: 100%;
  max-width: 1180px;
  margin-top: 18px;
  position: relative;
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(24 21 38 / 0.55), rgba(16 14 26 / 0.75));
  overflow: hidden;
}
#viz { display: block; width: 100%; height: clamp(150px, 24vh, 230px); }
.viz-caption {
  position: absolute;
  right: 16px;
  bottom: 8px;
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  pointer-events: none;
}

/* ---------- presets ---------- */

.presets {
  width: 100%;
  max-width: 1180px;
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.presets-label {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-right: 4px;
}
.preset-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.84rem;
  cursor: pointer;
  transition: border-color 0.25s ease, background 0.25s ease, transform 0.2s ease;
  min-height: 38px;
}
.chip:hover { border-color: rgba(232 180 106 / 0.5); transform: translateY(-1px); }
.chip.active { border-color: var(--amber); color: var(--amber); }
.chip-save { border-style: dashed; color: var(--ink-dim); }
.save-form { display: flex; gap: 8px; align-items: center; }
.save-form[hidden] { display: none; }
.preset-item { display: inline-flex; align-items: center; gap: 3px; }
.chip-del {
  border: 1px solid transparent;
  background: none;
  color: var(--ink-faint);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.chip-del:hover { color: #e89a9a; border-color: rgba(220 90 90 / 0.4); }
.save-form input {
  background: var(--bg-soft);
  border: 1px solid var(--panel-edge);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.84rem;
  min-height: 38px;
  width: 170px;
}

/* ---------- board of channels ---------- */

.board {
  width: 100%;
  max-width: 1180px;
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(266px, 1fr));
  gap: 16px;
}

.channel {
  --accent: var(--ink);
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  backdrop-filter: blur(8px);
  transition: border-color 0.4s ease, box-shadow 0.4s ease, opacity 0.4s ease;
  position: relative;
}
.channel.ch-brown { --accent: var(--c-brown); }
.channel.ch-pink { --accent: var(--c-pink); }
.channel.ch-rain { --accent: var(--c-rain); }
.channel.ch-binaural { --accent: var(--c-binaural); }

.channel.is-active { border-color: color-mix(in srgb, var(--accent) 38%, transparent); }
.channel.is-muted { opacity: 0.55; }
.channel.is-solo {
  border-color: var(--accent);
  box-shadow: 0 0 34px color-mix(in srgb, var(--accent) 16%, transparent);
}
.channel.is-dimmed-by-solo { opacity: 0.4; }

.ch-head { display: flex; align-items: flex-start; gap: 12px; }
.ch-glyph { width: 34px; height: 34px; color: var(--accent); flex: none; margin-top: 3px; }
.ch-title { flex: 1; min-width: 0; }
.ch-title h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.18rem;
  margin: 0;
  letter-spacing: 0.01em;
}
.ch-desc { margin: 3px 0 0; font-size: 0.8rem; color: var(--ink-dim); }
.hp-note { color: var(--c-binaural); }

.ch-flags { display: flex; gap: 6px; flex: none; }
.flag {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: transparent;
  color: var(--ink-faint);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.25s ease;
}
.flag:hover { color: var(--ink); border-color: rgba(255 235 200 / 0.3); }
.flag-mute[aria-pressed="true"] {
  background: rgba(220 90 90 / 0.16);
  border-color: rgba(220 90 90 / 0.55);
  color: #e89a9a;
}
.flag-solo[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-color: var(--accent);
  color: var(--accent);
}

/* level meter */
.meter {
  height: 3px;
  border-radius: 2px;
  background: rgba(255 255 255 / 0.06);
  margin: 14px 0 16px;
  overflow: hidden;
}
.meter i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  transition: width 90ms linear;
}

/* ---------- sliders ---------- */

.slider-row { margin-top: 13px; }
.slider-row label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 7px;
}
.slider-row output {
  color: var(--accent);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  text-transform: none;
  font-variant-numeric: tabular-nums;
  transition: opacity 0.3s ease;
}
.slider-hint { margin: 5px 0 0; font-size: 0.72rem; color: var(--ink-faint); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 34px; /* generous touch target */
  background: transparent;
  cursor: pointer;
  --fill: 50%;
  touch-action: pan-x;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background:
    linear-gradient(var(--accent, var(--amber)), var(--accent, var(--amber)))
    0 0 / var(--fill) 100% no-repeat,
    rgba(255 255 255 / 0.09);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6e6, var(--accent, var(--amber)) 75%);
  border: 1px solid rgba(0 0 0 / 0.35);
  box-shadow: 0 1px 7px rgba(0 0 0 / 0.5), 0 0 10px color-mix(in srgb, var(--accent, var(--amber)) 45%, transparent);
  transition: transform 0.18s ease;
}
input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: rgba(255 255 255 / 0.09);
}
input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: 3px;
  background: var(--accent, var(--amber));
}
input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6e6, var(--accent, var(--amber)) 75%);
  border: 1px solid rgba(0 0 0 / 0.35);
  box-shadow: 0 1px 7px rgba(0 0 0 / 0.5);
  transition: transform 0.18s ease;
}
input[type="range"]:hover::-webkit-slider-thumb,
input[type="range"]:focus-visible::-webkit-slider-thumb { transform: scale(1.18); }
input[type="range"]:hover::-moz-range-thumb,
input[type="range"]:focus-visible::-moz-range-thumb { transform: scale(1.18); }

/* focus visibility everywhere */
:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ---------- toggle (thunder) ---------- */

.toggle-row { margin-top: 14px; }
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: var(--ink-dim);
  font-size: 0.84rem;
  cursor: pointer;
  padding: 6px 2px;
  min-height: 38px;
}
.toggle-track {
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: rgba(255 255 255 / 0.1);
  border: 1px solid var(--panel-edge);
  position: relative;
  transition: background 0.3s ease, border-color 0.3s ease;
  flex: none;
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ink-dim);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s ease;
}
.toggle[aria-pressed="true"] { color: var(--c-rain); }
.toggle[aria-pressed="true"] .toggle-track {
  background: color-mix(in srgb, var(--c-rain) 26%, transparent);
  border-color: var(--c-rain);
}
.toggle[aria-pressed="true"] .toggle-thumb {
  transform: translateX(18px);
  background: var(--c-rain);
}

/* ---------- binaural readout ---------- */

.band-readout {
  margin: 2px 0 4px;
  font-size: 0.94rem;
  color: var(--ink);
}
.band-readout strong { color: var(--c-binaural); font-weight: 600; }
.band-hint { color: var(--ink-dim); font-size: 0.82rem; }
#beatHz { font-variant-numeric: tabular-nums; }

/* ---------- footer ---------- */

.colophon {
  width: 100%;
  max-width: 1180px;
  margin-top: 34px;
  color: var(--ink-faint);
  font-size: 0.78rem;
  line-height: 1.6;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- responsive ---------- */

@media (max-width: 720px) {
  .masthead-inner { flex-direction: column; align-items: stretch; }
  .transport { border-radius: 22px; padding: 14px 16px; }
  .transport-fields { flex: 1; flex-wrap: wrap; gap: 12px 18px; }
  .master-vol { flex: 1; min-width: 130px; }
  .master-vol input { width: 100%; }
  .board { grid-template-columns: 1fr; }
  .play-btn { width: 64px; height: 64px; }
  input[type="range"] { height: 44px; }
  input[type="range"]::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: -10px; }
  input[type="range"]::-moz-range-thumb { width: 26px; height: 26px; }
  #viz { height: 150px; }
  .status-line { font-size: 0.8rem; }
}

@media (max-width: 400px) {
  body { padding-left: 12px; padding-right: 12px; }
  .channel { padding: 15px 16px 17px; }
}
