/* Оформление снято с mediapipe.aa.arthew0.online: тёплый монохром,
   Martian Mono для всего, Instrument Serif курсивом для заголовков,
   границы в полпикселя, мелкие капсовые подписи. Цветных акцентов нет —
   активное состояние = более светлый текст + подсветка #ffffff14. */

@import url("https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Martian+Mono:wght@300;400;500&display=swap");

:root {
  --bg: #0b0b0d;
  --bg2: #131316;
  --bg3: #1a1a1f;
  --border: #ffffff0e;
  --border2: #ffffff1a;
  --text: #ddd8cc;
  --muted: #ddd8cc52;
  --accent: #ffffff8c;
  --on: #ffffff14;
  --warn: #e84a4a73;
  --mono: "Martian Mono", ui-monospace, monospace;
  --serif: "Instrument Serif", serif;
  font-family: var(--mono);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 400;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button, select, input {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  background: none;
  border: .5px solid var(--border2);
  border-radius: 5px;
  padding: 6px 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  transition: all .13s;
}
button { cursor: pointer; user-select: none; }
button:hover:not(:disabled), select:hover { color: var(--text); border-color: var(--accent); }
button.on { color: var(--text); border-color: var(--accent); background: var(--on); }
button:disabled { opacity: .35; cursor: not-allowed; }
button.wide { width: 100%; text-align: center; }
select { appearance: none; background: var(--bg2); padding-right: 20px; text-transform: none; letter-spacing: .03em; }
input[type=number], input[type=search], input[type=text] {
  background: var(--bg2);
  color: var(--text);
  text-transform: none;
  letter-spacing: .03em;
  border-radius: 5px;
  padding: 6px 8px;
}
input:focus { border-color: var(--accent); outline: none; }
input[type=range] {
  appearance: none;
  padding: 0;
  border: none;
  background: none;
  height: 12px;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 1px;
  background: var(--border2);
}
input[type=range]::-webkit-slider-thumb {
  appearance: none;
  width: 9px;
  height: 9px;
  margin-top: -3.5px;
  border-radius: 50%;
  background: var(--text);
  opacity: .8;
}
input[type=checkbox] { appearance: none; width: 12px; height: 12px; padding: 0; border-radius: 3px; }
input[type=checkbox]:checked { background: var(--text); border-color: var(--accent); }

.spacer { flex: 1; }

/* ---------- шапка ---------- */

.top {
  display: flex;
  flex: none;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  border-bottom: .5px solid var(--border);
}
/* Бутерброды в шапке: первый сворачивает левую панель, второй — весь хром
   (шапка, тюнер, спектр), остаётся водопад с линией настройки. */
.burger {
  flex: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  width: 26px;
  height: 24px;
  padding: 0;
  align-items: center;
  border-radius: 4px;
}
.burger i { display: block; width: 13px; height: 1px; background: var(--muted); transition: all .16s; }
.burger:hover i { background: var(--text); }
.burger.on i { background: var(--text); }
/* Свёрнутая панель — полоски сходятся в крест. */
.burger.off i:nth-child(1) { transform: translateY(4px) rotate(45deg); }
.burger.off i:nth-child(2) { opacity: 0; }
.burger.off i:nth-child(3) { transform: translateY(-4px) rotate(-45deg); }

.fld { display: flex; align-items: center; gap: 8px; }
.fld > span {
  font-size: 8px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.fld select { max-width: 300px; }

.conn { display: flex; align-items: center; gap: 5px; }
.conn .lbl {
  font-size: 8px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 10px;
}
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border2); display: inline-block; }
.dot.on { background: var(--text); opacity: .85; }
.dot.err { background: #e84a4a; opacity: .7; }
.smeter {
  font-size: 9px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  min-width: 54px;
}

/* ---------- каркас ---------- */

main { display: flex; flex: 1; min-height: 0; }

/* Кинорежим: шапка снимается, бутерброд висит поверх водопада. */
body.chromeOff header.top {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 30;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  pointer-events: none;
}
body.chromeOff header.top > :not(#btnChrome):not(#btnShuffle):not(#btnAudio):not(.spacer) { display: none; }
body.chromeOff #btnChrome,
body.chromeOff #btnShuffle,
body.chromeOff #btnAudio {
  pointer-events: auto;
  background: #0b0b0dd9;
  border-color: var(--border);
}
#btnShuffle { display: none; }
body.chromeOff #btnShuffle {
  display: flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  font-size: 8px;
  letter-spacing: .12em;
}
body.chromeOff main { flex: 1; height: auto; }
body.chromeOff #rail,
body.chromeOff #panel {
  width: 0;
  overflow: hidden;
  border: none;
}
body.chromeOff .tuner,
body.chromeOff #spectrum,
body.chromeOff #ruler,
body.chromeOff .zoomBox,
body.chromeOff .statusbar { display: none; }
body.chromeOff #stage { padding: 0; gap: 0; }
body.chromeOff #scopeWrap { border: none; border-radius: 0; }

#chromeDice { display: none; }
body.chromeOff #chromeDice {
  display: flex;
  position: fixed;
  bottom: calc(12px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  gap: 6px;
}
body.chromeOff #chromeDice button {
  background: #0b0b0dd9;
  border-color: var(--border);
  height: 24px;
  padding: 0 10px;
  font-size: 8px;
  letter-spacing: .12em;
}

#rail {
  width: 244px;
  flex: none;
  border-right: .5px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: width .16s;
}
#rail.hidden { width: 0; overflow: hidden; border: none; }
.tabs { display: flex; gap: 3px; padding: 12px 12px 10px; flex-wrap: wrap; }
.tab {
  border-radius: 3px;
  padding: 4px 9px;
  font-size: 9px;
}
.pane { display: none; padding: 0 12px 14px; overflow: auto; min-height: 0; }
.pane.on { display: block; }
.pane input[type=search] { width: 100%; margin-bottom: 8px; }

.list { display: flex; flex-direction: column; gap: 1px; }
.item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 7px;
  border-radius: 5px;
  border: .5px solid transparent;
  cursor: pointer;
  color: var(--muted);
  transition: all .12s;
}
.item:hover { color: var(--text); background: #ffffff0a; }
.item.cur { color: var(--text); background: var(--on); border-color: var(--accent); }
.item b {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  min-width: 68px;
  text-align: right;
  font-size: 9px;
}
.item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; }
.item .tag {
  font-size: 8px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-left: auto;
  font-style: normal;
}
.item .x { margin-left: auto; color: var(--muted); font-style: normal; padding-left: 6px; }
.item .x:hover { color: #f0a0a0; }

.row { margin: 8px 0; }
.knob { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 9px 0; }
.knob > span {
  font-size: 8px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.knob input[type=range] { width: 118px; }
.knob input[type=number] { width: 74px; }
.knob.inline { margin: 0; }
.hint {
  color: var(--muted);
  font-size: 8px;
  letter-spacing: .05em;
  line-height: 1.7;
  margin-top: 12px;
}
.hint b { color: var(--text); font-weight: 500; }

/* ---------- центр ---------- */

#stage { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 12px 16px; gap: 10px; }

.tuner {
  display: flex;
  align-items: center;
  gap: 20px;
  padding-bottom: 10px;
  border-bottom: .5px solid var(--border);
}
.digits { display: flex; align-items: baseline; gap: 0; user-select: none; }
.digits .d {
  font-size: 34px;
  font-weight: 300;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-style: normal;
  padding: 2px 0;
  cursor: ns-resize;
  color: var(--text);
  border-bottom: 1px solid transparent;
  transition: color .12s, border-color .12s;
}
.digits .d:hover { color: #fff; border-bottom-color: var(--accent); }
.digits .d.lead { color: var(--muted); }
.digits .sep { font-size: 34px; font-weight: 300; font-style: normal; color: var(--muted); padding: 0 3px; }
.digits .unit {
  font-size: 8px;
  font-style: normal;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-left: 12px;
  align-self: flex-end;
  padding-bottom: 4px;
}

.tunerRight { display: flex; align-items: center; gap: 16px; margin-left: auto; }
.modes { display: flex; gap: 3px; }
.modes button { min-width: 40px; border-radius: 3px; padding: 4px 9px; font-size: 9px; text-align: center; }

#scopeWrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #000;
  border: .5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#spectrum { width: 100%; height: 108px; flex: none; display: block; touch-action: none; }
/* Спектр сворачивается — водопад забирает его высоту. */
#scopeWrap.noSpec #spectrum { display: none; }
#ruler { width: 100%; height: 24px; flex: none; display: block; touch-action: none; }
#waterfall { width: 100%; flex: 1; min-height: 0; display: block; cursor: crosshair; touch-action: none; }

.cursorInfo {
  position: absolute;
  pointer-events: none;
  padding: 3px 7px;
  background: #0b0b0dd9;
  border: .5px solid var(--border2);
  border-radius: 5px;
  color: var(--text);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
  transform: translate(10px, 10px);
  display: none;
}
.zoomBox {
  position: absolute;
  right: 12px;
  top: 120px;
  display: flex;
  gap: 3px;
  align-items: center;
  background: #0b0b0dd9;
  border: .5px solid var(--border);
  border-radius: 5px;
  padding: 3px;
}
#scopeWrap.noSpec .zoomBox { top: 12px; }
.zoomBox button { padding: 3px 7px; border-radius: 3px; font-size: 9px; }
.zoomBox .sep { width: .5px; height: 12px; background: var(--border2); margin: 0 2px; }
#specToggle { text-transform: none; letter-spacing: .04em; }
.zoomBox span {
  color: var(--muted);
  min-width: 22px;
  text-align: center;
  font-size: 8px;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.statusbar {
  display: flex;
  gap: 14px;
  align-items: center;
  color: var(--muted);
  font-size: 8px;
  letter-spacing: .05em;
  padding-top: 2px;
}
#log { font-variant-numeric: tabular-nums; color: var(--text); }
.keys { color: var(--muted); opacity: .7; }

/* ---------- панель оригинального клиента ---------- */

#panel {
  width: 420px;
  flex: none;
  border-left: .5px solid var(--border);
  display: flex;
  flex-direction: column;
}
#panel.hidden { width: 0; overflow: hidden; border: none; }
.panelHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: .5px solid var(--border);
  color: var(--muted);
  font-size: 8px;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.panelHead button { padding: 2px 8px; border-radius: 3px; }
#frames { flex: 1; position: relative; min-height: 0; }
/* iframe всегда в DOM. Не прячем его opacity:0 / z-index:-1 за непрозрачный
   body: Chrome тогда считает кадр невидимым и глушит AudioContext. */
#frames iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #0b0b0d; }
#panel.hidden #frames,
body.chromeOff #panel #frames {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 8px;
  height: 8px;
  overflow: hidden;
  pointer-events: none;
  opacity: 1;
  z-index: 40;
}
#panel.hidden #frames iframe,
body.chromeOff #panel #frames iframe {
  position: static;
  inset: auto;
  width: 400px;
  height: 300px;
}

/* iPhone / узкий экран: шапка переносится, «звук» остаётся в первом ряду.
   Левая панель и клиент приёмника — оверлеи, чтобы не сжимать водопад. */
@media (max-width: 980px) {
  body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  .top {
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
  }
  .top .spacer { display: none; }

  #btnRail { order: 1; }
  #btnChrome { order: 2; }
  #btnAudio {
    order: 3;
    min-height: 44px;
    min-width: 72px;
    padding: 0 14px;
    color: var(--text);
    border-color: var(--accent);
  }
  #btnPanel {
    order: 4;
    min-height: 44px;
    min-width: 48px;
  }
  #btnShuffle { order: 5; min-height: 44px; }
  .conn {
    order: 6;
    margin-left: auto;
  }
  .conn .lbl { display: none; }
  .fld {
    order: 10;
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
  }
  .fld > span { display: none; }
  .fld select {
    width: 100%;
    max-width: none;
    min-height: 44px;
    font-size: 16px;
  }

  .burger {
    width: 44px;
    height: 44px;
  }

  main { position: relative; }

  #rail:not(.hidden) {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 20;
    width: min(280px, 86vw);
    background: var(--bg);
    box-shadow: 8px 0 28px #000a;
  }
  #panel:not(.hidden) {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 20;
    width: min(100%, 420px);
    background: var(--bg);
    box-shadow: -8px 0 28px #000a;
  }

  #stage { padding: 8px 10px; gap: 8px; }

  .tuner {
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-start;
  }
  .digits .d, .digits .sep { font-size: 26px; }
  .tunerRight {
    margin-left: 0;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }
  .modes button { min-height: 40px; min-width: 48px; }
  .knob.inline { width: 100%; }
  .knob.inline input[type=range] { flex: 1; min-width: 0; }
  #muteBtn { min-height: 40px; }

  .keys { display: none; }
  .zoomBox {
    right: 8px;
    top: auto;
    bottom: 8px;
  }
  #scopeWrap.noSpec .zoomBox { top: auto; bottom: 8px; }
  .zoomBox button { min-height: 36px; min-width: 36px; }

  body.chromeOff header.top {
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  }
  body.chromeOff #btnAudio {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
