/* ── Hz · a frequency instrument ─────────────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: #05040f;
  color: #cfc7e8;
  font-family: "Palatino Linotype", Palatino, "Iowan Old Style", Georgia, serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -2;
  background:
    radial-gradient(ellipse 80% 55% at 50% -10%, rgba(96, 60, 160, .22), transparent 60%),
    radial-gradient(ellipse 60% 45% at 85% 100%, rgba(40, 110, 140, .14), transparent 60%),
    radial-gradient(ellipse 50% 40% at 10% 80%, rgba(140, 80, 60, .08), transparent 60%),
    #05040f;
}
#stars { position: fixed; inset: 0; z-index: -1; width: 100%; height: 100%; pointer-events: none; }

/* ── top bar ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 9px;
  color: #e6c87e; font-size: 21px; letter-spacing: .14em;
}
.brand svg { width: 21px; height: 21px; opacity: .85; }
.iconbtn {
  background: none; border: none; cursor: pointer;
  color: rgba(230, 200, 126, .75);
  padding: 8px; border-radius: 50%;
  transition: color .3s, transform .5s ease;
  line-height: 0; font-size: 15px; font-family: inherit;
}
.iconbtn:hover { color: #f0dfa8; transform: rotate(45deg); }
.topright { display: flex; align-items: center; gap: 4px; }
.langpick {
  display: flex; align-items: center; gap: 2px;
  border: 1px solid rgba(230, 200, 126, .2); border-radius: 999px;
  padding: 3px 10px; background: rgba(22, 17, 44, .45);
}
.langpick button {
  background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 12.5px; letter-spacing: .12em; text-transform: uppercase;
  color: rgba(143, 135, 173, .8); padding: 3px 4px; transition: color .3s;
}
.langpick button.active { color: #e6c87e; text-shadow: 0 0 12px rgba(230, 200, 126, .5); }
.langpick .sep { color: rgba(230, 200, 126, .3); font-size: 11px; }
.iconbtn.small:hover { transform: none; }
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn.small svg { width: 20px; height: 20px; }
#muteBtn.muted { color: rgba(160, 150, 190, .45); }
#muteBtn.muted .wv { opacity: 0; }

/* ── layout ── */
main {
  height: 100dvh; overflow-y: auto; overflow-x: hidden;
  padding: calc(58px + env(safe-area-inset-top)) 20px calc(112px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}
.panel {
  display: none;
  max-width: 540px; margin: 0 auto;
  flex-direction: column; align-items: center; gap: 15px;
}
.panel.active { display: flex; }
.caption {
  margin: 0 0 2px; font-style: italic; font-size: 14px;
  color: rgba(180, 168, 214, .62); letter-spacing: .06em; text-align: center;
}

/* ── listen ── */
.mandala-wrap {
  position: relative;
  width: min(84vw, 46dvh, 420px); aspect-ratio: 1;
}
#meterCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.readout {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  pointer-events: none; transition: opacity .6s;
}
.readout.dim { opacity: .35; }
.hz-line { display: flex; align-items: baseline; gap: 8px; }
#hzValue {
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  font-weight: 200; font-size: clamp(40px, 11vw, 64px);
  font-variant-numeric: tabular-nums;
  color: #f2e8cb; text-shadow: 0 0 28px rgba(230, 200, 126, .35);
  letter-spacing: .01em; line-height: 1;
}
.hz-unit { font-size: 17px; color: rgba(230, 200, 126, .7); letter-spacing: .1em; }
.note { margin-top: 8px; font-size: 17px; color: #a89ecf; letter-spacing: .08em; font-style: italic; }
.substats { display: flex; gap: 10px; font-size: 13px; color: rgba(168, 158, 207, .8); font-variant-numeric: tabular-nums; }
.substats .dot { opacity: .4; }
.fineinfo { font-size: 11.5px; color: rgba(143, 135, 173, .55); letter-spacing: .05em; }

/* ── buttons ── */
.mainbtn {
  margin-top: 4px;
  font-family: inherit; font-size: 15px; letter-spacing: .18em; text-transform: lowercase;
  color: #e6c87e; background: rgba(230, 200, 126, .06);
  border: 1px solid rgba(230, 200, 126, .4); border-radius: 999px;
  padding: 13px 34px; cursor: pointer;
  transition: all .35s;
  box-shadow: 0 0 0 rgba(230, 200, 126, 0);
}
.mainbtn:hover { background: rgba(230, 200, 126, .13); }
.mainbtn.on {
  color: #14102a; background: linear-gradient(160deg, #ecd490, #c9a95e);
  border-color: transparent;
  box-shadow: 0 0 34px rgba(230, 200, 126, .35);
}
.ghostbtn {
  font-family: inherit; font-size: 13px; letter-spacing: .08em;
  color: rgba(180, 168, 214, .8); background: none;
  border: 1px solid rgba(180, 168, 214, .3); border-radius: 999px;
  padding: 8px 18px; cursor: pointer;
}
.ghostbtn:hover { color: #cfc7e8; border-color: rgba(180, 168, 214, .55); }
.hint { font-size: 12.5px; font-style: italic; color: rgba(143, 135, 173, .75); text-align: center; max-width: 40ch; }

/* ── emit ── */
.scope-wrap {
  width: 100%; height: clamp(120px, 22dvh, 180px);
  border: 1px solid rgba(230, 200, 126, .16); border-radius: 16px;
  background: rgba(10, 8, 26, .55); overflow: hidden;
  box-shadow: inset 0 0 40px rgba(5, 4, 15, .8);
}
#scopeCanvas { width: 100%; height: 100%; display: block; }
.wavepick { display: flex; gap: 8px; }
.wavepick button {
  width: 62px; height: 40px; border-radius: 12px; cursor: pointer;
  background: rgba(22, 17, 44, .5); border: 1px solid rgba(180, 168, 214, .18);
  color: rgba(168, 158, 207, .75); transition: all .3s; line-height: 0;
  display: flex; align-items: center; justify-content: center;
}
.wavepick svg { width: 34px; height: 17px; }
.wavepick button.active {
  color: #e6c87e; border-color: rgba(230, 200, 126, .5);
  background: rgba(230, 200, 126, .08);
  box-shadow: 0 0 16px rgba(230, 200, 126, .15);
}
.freqrow { display: flex; align-items: center; gap: 8px; }
.step {
  font-family: inherit; font-size: 13px; color: rgba(207, 199, 232, .85);
  background: rgba(22, 17, 44, .5); border: 1px solid rgba(180, 168, 214, .18);
  border-radius: 10px; width: 44px; height: 38px; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.step:hover { border-color: rgba(230, 200, 126, .45); color: #e6c87e; }
.freqbox { text-align: center; min-width: 128px; }
.freqline { display: flex; align-items: baseline; justify-content: center; gap: 6px; }
#freqInput {
  width: 118px; background: none; border: none; outline: none;
  border-bottom: 1px solid rgba(230, 200, 126, .3);
  color: #f2e8cb; text-align: center;
  font-family: ui-sans-serif, system-ui, sans-serif; font-weight: 200; font-size: 30px;
  font-variant-numeric: tabular-nums; padding: 0 0 2px;
  -moz-appearance: textfield; appearance: textfield;
}
#freqInput::-webkit-outer-spin-button, #freqInput::-webkit-inner-spin-button { -webkit-appearance: none; }
#freqInput:focus { border-bottom-color: rgba(230, 200, 126, .7); }
.freqline .unit { color: rgba(230, 200, 126, .7); font-size: 14px; letter-spacing: .08em; }
.mini { font-size: 12.5px; color: rgba(168, 158, 207, .8); font-variant-numeric: tabular-nums; }
#emitNote { margin-top: 4px; font-style: italic; }

/* ── sliders ── */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  height: 26px; background: none; cursor: pointer; width: 190px;
}
input[type="range"].wide, #volSlider, #entrainVolSlider { width: min(100%, 400px); }
input[type="range"]::-webkit-slider-runnable-track {
  height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, rgba(230, 200, 126, .45), rgba(160, 143, 255, .45));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%; margin-top: -7px;
  background: radial-gradient(circle at 35% 35%, #f6ecc8, #cfab5e);
  box-shadow: 0 0 12px rgba(230, 200, 126, .55);
  border: none;
}
input[type="range"]::-moz-range-track {
  height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, rgba(230, 200, 126, .45), rgba(160, 143, 255, .45));
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; border: none;
  background: radial-gradient(circle at 35% 35%, #f6ecc8, #cfab5e);
  box-shadow: 0 0 12px rgba(230, 200, 126, .55);
}

/* ── chips ── */
.chips {
  display: flex; gap: 7px; max-width: 100%; overflow-x: auto; padding: 2px 2px 6px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; font-family: inherit; font-size: 12.5px;
  color: rgba(168, 158, 207, .85); background: rgba(22, 17, 44, .5);
  border: 1px solid rgba(180, 168, 214, .18); border-radius: 999px;
  padding: 6px 13px; cursor: pointer; font-variant-numeric: tabular-nums;
  transition: all .25s; letter-spacing: .04em;
}
.chip:hover { border-color: rgba(230, 200, 126, .4); }
.chip.active {
  color: #e6c87e; border-color: rgba(230, 200, 126, .55);
  background: rgba(230, 200, 126, .09);
}
.volrow { display: flex; align-items: center; gap: 12px; width: min(100%, 430px); justify-content: center; }

/* ── entrain ── */
.pulse-wrap { position: relative; width: min(64vw, 30dvh, 280px); aspect-ratio: 1; }
#pulseCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.bandlabel {
  font-size: 15px; color: #e6c87e; letter-spacing: .12em; font-style: italic;
  text-shadow: 0 0 18px rgba(230, 200, 126, .3);
}
.paramrow {
  display: flex; align-items: center; gap: 12px; width: min(100%, 430px);
}
.paramrow label {
  min-width: 52px; text-align: right; font-size: 13px;
  color: rgba(168, 158, 207, .85); letter-spacing: .08em;
}
.paramrow input[type="range"] { flex: 1; }
.paramrow .mini { width: 74px; }
.modetoggle {
  display: flex; border: 1px solid rgba(180, 168, 214, .22); border-radius: 999px; padding: 3px;
  background: rgba(22, 17, 44, .5);
}
.modetoggle button {
  font-family: inherit; font-size: 13px; letter-spacing: .08em;
  color: rgba(168, 158, 207, .8); background: none; border: none;
  border-radius: 999px; padding: 7px 18px; cursor: pointer; transition: all .3s;
}
.modetoggle button.active {
  color: #14102a; background: linear-gradient(160deg, #ecd490, #c9a95e);
}

/* ── floating oval tabs ── */
#tabs {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; gap: 4px; padding: 6px; border-radius: 999px;
  background: rgba(22, 17, 44, .58);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border: 1px solid rgba(230, 200, 126, .22);
  box-shadow: 0 10px 36px rgba(0, 0, 0, .55), inset 0 0 26px rgba(230, 200, 126, .045);
  z-index: 30;
}
.tab {
  display: flex; align-items: center; gap: 7px;
  font-family: inherit; font-size: 13.5px; letter-spacing: .1em;
  color: rgba(143, 135, 173, .9); background: none; border: none;
  border-radius: 999px; padding: 9px 16px; cursor: pointer; transition: all .35s;
}
.tab svg { width: 17px; height: 17px; }
.tab.active {
  color: #e9d8a6;
  background: linear-gradient(180deg, rgba(230, 200, 126, .16), rgba(230, 200, 126, .05));
  box-shadow: inset 0 0 0 1px rgba(230, 200, 126, .28), 0 0 20px rgba(230, 200, 126, .12);
}

/* ── settings ── */
#settingsOverlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(5, 4, 15, .62);
  -webkit-backdrop-filter: blur(9px); backdrop-filter: blur(9px);
  display: flex; justify-content: center; align-items: flex-end;
}
#settingsOverlay[hidden] { display: none; }
.sheet {
  width: min(560px, 100%); max-height: 88dvh; overflow-y: auto;
  background: linear-gradient(180deg, #16112e, #0a081e);
  border: 1px solid rgba(230, 200, 126, .24);
  border-radius: 22px 22px 0 0;
  padding: 4px 22px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 60px rgba(0, 0, 0, .6);
}
.sheet > header {
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; background: linear-gradient(180deg, #16112e 75%, transparent);
  padding: 14px 0 8px; z-index: 2;
}
.sheet h2 { margin: 0; font-size: 18px; font-weight: 400; letter-spacing: .16em; color: #e6c87e; }
.sheet h3 {
  margin: 22px 0 4px; font-size: 13.5px; font-weight: 400;
  letter-spacing: .18em; color: rgba(230, 200, 126, .85);
  border-bottom: 1px solid rgba(230, 200, 126, .16); padding-bottom: 7px;
}
.sheet footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-top: 20px; }
.setrow {
  display: grid; grid-template-columns: 1fr auto; gap: 1px 14px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid rgba(255, 255, 255, .045);
}
.setrow .lab { font-size: 14px; color: #cfc7e8; }
.setrow .hint2 { grid-column: 1 / -1; font-size: 11.5px; color: rgba(143, 135, 173, .65); font-style: italic; margin-top: 3px; }
.setrow .ctl { display: flex; align-items: center; gap: 9px; justify-content: flex-end; }
.setrow .val { font-size: 12.5px; color: rgba(230, 200, 126, .85); min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; }
.setrow input[type="range"] { width: 130px; }
.setrow select, .setrow input[type="number"] {
  font-family: inherit; font-size: 13.5px; color: #e8e2f5;
  background: rgba(22, 17, 44, .8); border: 1px solid rgba(180, 168, 214, .25);
  border-radius: 9px; padding: 7px 10px; outline: none; max-width: 210px;
}
.setrow input[type="number"] { width: 86px; text-align: right; font-variant-numeric: tabular-nums; }
.setrow select:focus, .setrow input[type="number"]:focus { border-color: rgba(230, 200, 126, .5); }
/* toggle */
.tgl { position: relative; width: 42px; height: 23px; flex: 0 0 auto; }
.tgl input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; position: absolute; z-index: 1; }
.tgl .knob {
  position: absolute; inset: 0; border-radius: 999px;
  background: rgba(180, 168, 214, .18); border: 1px solid rgba(180, 168, 214, .3);
  transition: all .3s;
}
.tgl .knob::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px;
  border-radius: 50%; background: #8f87ad; transition: all .3s;
}
.tgl input:checked + .knob { background: rgba(230, 200, 126, .28); border-color: rgba(230, 200, 126, .55); }
.tgl input:checked + .knob::after { left: 21px; background: #ecd490; box-shadow: 0 0 10px rgba(230, 200, 126, .6); }

@media (min-width: 700px) {
  #settingsOverlay { align-items: center; }
  .sheet { border-radius: 22px; max-height: 82dvh; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01s !important; }
}
