/* Moonstone: midnight blue, lavender and peach; Outfit for display, DM Sans
   for text. Both fonts are self-hosted so the app works offline. */
@font-face {
  font-family: "Outfit";
  src: url("/fonts/outfit.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "DM Sans";
  src: url("/fonts/dm-sans.woff2") format("woff2");
  font-weight: 100 1000;
  font-display: swap;
}

:root {
  --bg: #0e1628;
  --surface: #172340;
  --surface-2: #1f2d50;
  --line: #2a3a63;
  --text: #eef0f8;
  --soft: #c3cae0;
  --muted: #9aa6c4;
  --faint: #6f7b99;
  --accent: #b7a4f5;
  --accent-ink: #17112e;
  --accent-deep: #2a2457;
  --accent-glow: rgba(183, 164, 245, 0.14);
  --warm: #f2b89b;
  --warm-ink: #2b1408;
  --moon: #f4ead0;
  --danger: #f29b9b;
  --display: "Outfit", system-ui, sans-serif;
  --body: "DM Sans", system-ui, sans-serif;
  --gutter: 20px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--body);
  min-height: 100vh;
}
main {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 22px var(--gutter) 40px;
}
body.has-mini main { padding-bottom: 110px; }
h1, h2, h3 { font-family: var(--display); font-weight: 300; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 34px; line-height: 1.1; }
h2 { font-size: 20px; font-weight: 400; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.soft { color: var(--soft); }
.small { font-size: 14px; }
.wide { width: 100%; }
.page-title { margin-bottom: 20px; }
.card.flush { margin: 0; }
.card.yt { margin-top: 30px; }
.result-row { display: flex; align-items: baseline; gap: 8px; margin: 6px 0 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.page-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 20px; }
.clock { font-family: var(--display); color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin: 26px 0 14px; }
.section-head span { font-size: 13px; color: var(--muted); }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); }

/* ---------- buttons & fields ---------- */
.btn {
  appearance: none; cursor: pointer; border: 0;
  background: var(--accent); color: var(--accent-ink);
  font: 600 15px/1 var(--body); padding: 0 20px; height: 48px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: 0.4; cursor: default; filter: none; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 500; }
.btn.ghost:hover { border-color: var(--accent); }
.btn.big { height: 64px; font: 500 22px/1 var(--display); width: 100%; }
.btn.round { width: 48px; padding: 0; }
.btn small { font-weight: 400; color: inherit; opacity: 0.7; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
.btn-row > .btn.ghost { flex: 1 1 120px; }

input[type="range"] { accent-color: var(--accent); width: 100%; min-width: 80px; height: 28px; }
select, input[type="text"], input[type="url"] {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; min-height: 48px;
}
.field-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; margin-bottom: 16px; }
.slider-field, .select-field { display: flex; flex-direction: column; gap: 6px; color: var(--soft); font-size: 14px; min-width: 150px; flex: 1; }
.seg { border: 0; padding: 0; margin: 0 0 16px; display: flex; gap: 6px; width: 100%; }
.seg legend { color: var(--soft); font-size: 14px; margin-bottom: 6px; padding: 0; }
.seg label {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; text-align: center; cursor: pointer;
  background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; min-height: 48px; font-size: 14px;
}
.seg label:has(input:checked) { border-color: var(--accent); background: var(--accent-deep); color: var(--text); font-weight: 600; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 28px; padding: 20px; margin: 14px 0; }
.card h2 { margin-bottom: 12px; }
.note { display: flex; gap: 12px; align-items: flex-start; font-size: 14px; color: var(--soft); background: var(--surface); border-radius: 20px; padding: 14px 16px; margin: 14px 0; }
.note svg { flex: none; margin-top: 2px; }
.note b { color: var(--text); }

/* ---------- Tonight card ---------- */
.tonight {
  display: flex; align-items: center; gap: 16px; padding: 18px 18px 18px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 28px;
}
.tonight-open {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px;
  background: none; border: 0; padding: 0; color: inherit; text-align: left; font: inherit; cursor: pointer;
}
.tonight-open svg { flex: none; }
.tonight-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tonight-title { font: 400 22px/1.2 var(--display); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tonight-desc { font-size: 13px; color: var(--muted); }
.play-circle {
  flex: none; width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); display: grid; place-items: center;
}
.play-circle svg { width: 18px; height: 18px; fill: var(--accent-ink); }

.presets { display: flex; gap: 8px; overflow-x: auto; margin: 14px calc(-1 * var(--gutter)) 0; padding: 0 var(--gutter) 4px; scrollbar-width: none; }
.presets::-webkit-scrollbar { display: none; }
.preset {
  flex: none; height: 40px; padding: 0 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: transparent; color: var(--soft); font: 500 14px var(--body);
}
.preset:hover { border-color: var(--accent); color: var(--text); }

/* ---------- sound orbs ---------- */
.orb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 18px 8px; }
.orb {
  background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; font: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
}
.orb-ring {
  width: 76px; height: 76px; border-radius: 50%; background: var(--surface); border: 1.5px solid var(--line);
  display: grid; place-items: center; transition: background 0.25s, border-color 0.25s, box-shadow 0.25s;
}
.orb-ring svg { width: 28px; height: 28px; stroke: var(--soft); transition: stroke 0.25s; }
.orb-label { font-size: 13px; font-weight: 500; line-height: 1.25; }
.orb-label small { display: block; font-size: 11px; color: var(--faint); font-weight: 400; }
.orb:hover .orb-ring { border-color: var(--accent); }
.orb[aria-pressed="true"] { color: var(--text); }
.orb[aria-pressed="true"] .orb-ring { background: var(--accent-deep); border-color: var(--accent); box-shadow: 0 0 0 6px var(--accent-glow); }
.orb[aria-pressed="true"] .orb-ring svg { stroke: var(--accent); }

/* ---------- YouTube ---------- */
.yt-add { display: flex; gap: 8px; flex-wrap: wrap; }
.yt-add input[type="url"] { flex: 2 1 220px; min-width: 0; }
.yt-add input[type="text"] { flex: 1 1 140px; min-width: 0; }
.form-error { color: var(--danger); margin-top: 8px; }
.yt-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.yt-list li { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 18px; padding: 6px 6px 6px 16px; }
.yt-list li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.yt-list .btn { height: 38px; padding: 0 14px; font-size: 14px; }
.yt-sub { margin: 16px 0 0; color: var(--muted); font: 600 12px var(--body); text-transform: uppercase; letter-spacing: 0.12em; }
.yt-player { margin-top: 12px; position: relative; aspect-ratio: 16 / 9; border-radius: 18px; overflow: hidden; background: #000; }
.yt-player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---------- tab bar (pinned at the top) + mini player ---------- */
.dock {
  position: sticky; top: max(10px, env(safe-area-inset-top)); z-index: 30;
  width: min(calc(100% - 32px), 460px); margin: max(10px, env(safe-area-inset-top)) auto 0;
  display: flex; gap: 4px; padding: 6px; border-radius: 999px;
  background: rgba(23, 35, 64, 0.94); border: 1px solid var(--line); backdrop-filter: blur(10px);
}
.dock a {
  flex: 1; height: 48px; border-radius: 999px; color: var(--muted); text-decoration: none;
  display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; font-weight: 500;
}
.dock a svg { width: 20px; height: 20px; display: none; }
.dock a.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.dock a.active svg { display: block; }

.mini {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 29;
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(calc(100% - 32px), 460px);
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 18px; border-radius: 22px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.mini-open { flex: 1; min-width: 0; background: none; border: 0; color: var(--text); text-align: left; font: inherit; cursor: pointer; padding: 6px 0; }
.mini-open b { display: block; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-open span { font-size: 12px; color: var(--muted); }
.mini .play-circle { width: 44px; height: 44px; }
.mini .play-circle svg { width: 14px; height: 14px; }

/* ---------- Now playing sheet ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto;
  animation: rise 0.28s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet-inner {
  max-width: 560px; margin: 0 auto; min-height: 100%;
  padding: max(20px, env(safe-area-inset-top)) var(--gutter) max(26px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 22px;
}
.sheet-top { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--surface); color: var(--text);
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }
.sheet h1 { font-size: 44px; line-height: 1.05; letter-spacing: -0.015em; }
.timer-card { display: flex; flex-direction: column; gap: 12px; }
.timer-head { display: flex; justify-content: space-between; align-items: baseline; }
.timer-head b { font-size: 15px; }
.timer-left { font: 300 30px/1 var(--display); color: var(--warm); font-variant-numeric: tabular-nums; }
.timer-bar { height: 8px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.timer-bar div { height: 100%; width: 0; border-radius: 4px; background: var(--warm); transition: width 1s linear; }
.chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.chip {
  height: 40px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--soft);
  font: 500 14px var(--body); cursor: pointer;
}
.chip[aria-pressed="true"] { border-color: var(--warm); background: var(--warm); color: var(--warm-ink); font-weight: 600; }
.layers { display: flex; flex-direction: column; gap: 14px; }
.layer { display: flex; align-items: center; gap: 14px; font-size: 15px; }
.layer span { width: 118px; flex: none; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer.all { color: var(--muted); }
.toggle-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer;
  padding: 14px 18px; border-radius: 22px; background: var(--surface); border: 1px solid var(--line);
}
.toggle-card span { display: flex; flex-direction: column; gap: 2px; }
.toggle-card b { font-size: 15px; }
.toggle-card small { font-size: 13px; color: var(--muted); }
.toggle-card input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.lock-card .seg { margin-bottom: 10px; }
.lock-card p { margin: 0 0 8px; }
.live-log { list-style: none; padding: 0; margin: 0 0 10px; font-size: 13px; color: var(--soft); max-height: 180px; overflow-y: auto; }
.live-log li { padding: 4px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.live-log li:first-child { border-top: 0; }
.live-log .bad { color: var(--warm); }
.sheet-actions { margin-top: auto; display: flex; gap: 10px; }
.sheet-actions .btn { height: 56px; font-size: 16px; }
.sheet-actions .btn.ghost { flex: 1; }
.sheet-actions .btn:not(.ghost) { flex: 2; }

/* ---------- tinnitus ---------- */
.step-bars { display: flex; gap: 6px; margin: 12px 0 10px; }
.step-bars span { flex: 1; height: 4px; border-radius: 2px; background: var(--line); transition: background 0.3s; }
.step-bars span.on { background: var(--accent); }
.tin-hint { font-size: 14px; color: var(--muted); }
.dial { position: relative; width: 100%; max-width: 350px; margin: 8px auto 0; aspect-ratio: 350 / 230; }
.dial svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.dial-readout { position: absolute; left: 0; right: 0; top: 47%; display: flex; flex-direction: column; align-items: center; }
.freq { font: 200 72px/1 var(--display); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.freq-sub { font-size: 14px; color: var(--muted); }
.tune-freq { display: flex; flex-direction: column; align-items: center; padding: 10px 0 4px; }
.tune-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.tune-row .btn { padding: 0 6px; font-size: 14px; }
.octave-check { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.octave-check p { font-size: 14px; color: var(--soft); }
.oct-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.oct-row .btn { flex-direction: column; gap: 3px; height: 60px; padding: 0 6px; font-size: 14px; }
.tin-note { font-size: 14px; color: var(--warm); margin-top: 12px; text-align: center; }
.vol-note { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-radius: 20px; background: var(--surface); margin: 16px 0; }
.vol-note label { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--soft); }
.result-freq { font: 200 56px/1 var(--display); color: var(--accent); letter-spacing: -0.02em; }
.history { list-style: none; padding: 0; margin: 0; }
.history li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.history li:first-child { border-top: 0; }
.history .h-freq { font: 400 18px var(--display); min-width: 5.5em; font-variant-numeric: tabular-nums; }
.history .h-meta { color: var(--muted); flex: 1; font-size: 13px; min-width: 140px; }
.history .btn { height: 36px; padding: 0 14px; font-size: 13px; }

/* ---------- scenes ---------- */
.feature {
  display: block; width: 100%; padding: 0; text-align: left; cursor: pointer; font: inherit; color: var(--text);
  border-radius: 28px; overflow: hidden; background: #1b1f45; border: 1px solid #343a78;
}
.feature canvas { display: block; width: 100%; aspect-ratio: 350 / 190; }
.feature-text { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px 16px; }
.feature-text b { display: block; font: 400 21px var(--display); }
.feature-text small { font-size: 13px; color: #a9b2d6; }
.feature .play-circle { width: 48px; height: 48px; }
.feature .play-circle svg { width: 16px; height: 16px; }
.scene-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.scene-row {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px 10px 10px; cursor: pointer;
  border-radius: 22px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; text-align: left;
}
.scene-row:hover { border-color: var(--accent); }
.scene-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.scene-icon svg { width: 26px; height: 26px; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.scene-row .scene-text { flex: 1; display: flex; flex-direction: column; }
.scene-row b { font-size: 15px; font-weight: 600; }
.scene-row small { font-size: 13px; color: var(--muted); }
.scene-row > svg { width: 18px; height: 18px; stroke: var(--faint); fill: none; stroke-width: 1.8; }

/* ---------- scene player ---------- */
.player { position: fixed; inset: 0; z-index: 50; background: #000; }
.player canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.player-dim { position: absolute; inset: 0; background: #000; opacity: 0.2; pointer-events: none; }
.player-ui {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between;
  padding: max(20px, env(safe-area-inset-top)) var(--gutter) max(30px, env(safe-area-inset-bottom));
  transition: opacity 0.6s; pointer-events: none;
}
.player-ui > * { pointer-events: auto; }
.player-ui.hide { opacity: 0; }
.player-ui.hide > * { pointer-events: none; }
.player.idle { cursor: none; }
.player-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.player-title { font-weight: 600; font-size: 14px; color: rgba(238, 240, 248, 0.75); }
.player-top .icon-btn { background: rgba(23, 35, 64, 0.8); }
.player-bottom {
  align-self: center; width: min(100%, 520px);
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: center;
  padding: 8px 10px; border-radius: 28px; background: rgba(23, 35, 64, 0.88); border: 1px solid var(--line); backdrop-filter: blur(8px);
}
.player-bottom .bright { display: flex; align-items: center; gap: 8px; flex: 1 1 160px; padding-left: 8px; }
.player-bottom .bright svg { width: 20px; height: 20px; stroke: var(--text); fill: none; stroke-width: 1.7; flex: none; }
.player-bottom select { min-height: 44px; border-radius: 999px; padding: 6px 14px; background: var(--surface-2); }
#player-options { display: inline-flex; gap: 8px; flex-wrap: wrap; }
#player-options label { display: inline-flex; }
.sound-toggle { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--surface-2); display: grid; place-items: center; cursor: pointer; }
.sound-toggle svg { width: 20px; height: 20px; stroke: var(--text); fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sound-toggle[aria-pressed="true"] { background: var(--accent); }
.sound-toggle[aria-pressed="true"] svg { stroke: var(--accent-ink); }

.foot { margin-top: 36px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--faint); font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  *, .sheet { transition: none !important; animation: none !important; }
}
