/* ==========================================================================
   SonicForge - Design tokens, reset, and application shell
   Deep onyx substrate · neon cyan actives
   · violet script accents · glassmorphism
   ========================================================================= */

:root {
  /* --- Substrate ------------------------------------------------------- */
  --onyx-900: #05070d;
  --onyx-850: #080b13;
  --onyx-800: #0b0f19;
  --onyx-700: #111726;
  --onyx-600: #18203285;
  --onyx-500: #1d2740;

  /* --- Accents --------------------------------------------------------- */
  --cyan: #00f2fe;
  --cyan-dim: #00b8c4;
  --cyan-glow: rgba(0, 242, 254, 0.45);
  --cyan-wash: rgba(0, 242, 254, 0.08);
  --violet: #7f00ff;
  --violet-lite: #a855f7;
  --violet-glow: rgba(127, 0, 255, 0.45);
  --violet-wash: rgba(127, 0, 255, 0.1);
  --amber: #ffb020;
  --rose: #ff3d71;
  --lime: #29ff9a;

  /* --- Text ------------------------------------------------------------ */
  --ink-hi: #eef3ff;
  --ink: #b9c4dc;
  --ink-mid: #7d89a6;
  --ink-low: #4d5872;

  /* --- Glass ----------------------------------------------------------- */
  --glass-bg: rgba(17, 23, 38, 0.55);
  --glass-bg-solid: rgba(11, 15, 25, 0.92);
  --glass-brd: rgba(255, 255, 255, 0.07);
  --glass-brd-hi: rgba(0, 242, 254, 0.28);
  --glass-blur: 18px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  --shadow-lift: 0 18px 44px rgba(0, 0, 0, 0.62);

  /* --- Geometry -------------------------------------------------------- */
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 16px;
  --rail-l: 248px;
  --rail-r: 384px;
  --header-h: 58px;
  --status-h: 26px;
  --gap: 12px;

  /* --- Type ------------------------------------------------------------ */
  --ff-ui:
    "Inter",
    "Segoe UI Variable",
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
  --ff-mono:
    "JetBrains Mono",
    "SF Mono",
    "Cascadia Code",
    ui-monospace,
    Menlo,
    Consolas,
    monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: dark;
}

/* ==========================================================================
   Reset
   ========================================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--ff-ui);
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--onyx-800);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Ambient field: two slow radial auroras over the onyx substrate. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(
      1100px 620px at 12% -12%,
      rgba(0, 242, 254, 0.1),
      transparent 62%
    ),
    radial-gradient(
      940px 560px at 104% 8%,
      rgba(127, 0, 255, 0.12),
      transparent 60%
    ),
    radial-gradient(
      760px 700px at 48% 116%,
      rgba(0, 120, 255, 0.07),
      transparent 66%
    );
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

h1,
h2,
h3,
h4,
p,
figure {
  margin: 0;
}

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

canvas {
  display: block;
}

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection {
  background: var(--cyan-glow);
  color: var(--onyx-900);
}

/* --- Scrollbars ------------------------------------------------------- */

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 242, 254, 0.22) transparent;
}

::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 242, 254, 0.18);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 242, 254, 0.4);
  background-clip: padding-box;
}

/* ==========================================================================
   Application shell
   ========================================================================= */

/*
 * One column that may never grow past the viewport. Without the explicit
 * minmax(0, 1fr), the grid sizes its implicit column to the widest child's
 * min-content, so a header that could not shrink widened the whole page.
 * The header row is auto so the top bar can wrap onto a second line.
 */
#app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr var(--status-h);
  height: 100vh;
  height: 100dvh;
}

.shell {
  display: grid;
  grid-template-columns: var(--rail-l) minmax(0, 1fr) var(--rail-r);
  gap: var(--gap);
  padding: 0 var(--gap) var(--gap);
  min-height: 0;
}

.rail,
.stage {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 2px;
}

/* ==========================================================================
   Header
   ========================================================================= */

/*
 * A single row where it fits, wrapping onto more rows where it does not.
 * The block padding keeps the one-row bar at exactly --header-h: 34 px of
 * controls, 11.5 px above and below, and the 1 px border.
 */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  min-height: var(--header-h);
  padding: 11.5px 16px;
  border-bottom: 1px solid var(--glass-brd);
  background: linear-gradient(
    180deg,
    rgba(11, 15, 25, 0.9),
    rgba(11, 15, 25, 0.62)
  );
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand__mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 7px var(--cyan-glow));
}

.brand__name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-hi);
}

.brand__name em {
  font-style: normal;
  color: var(--cyan);
}

.brand__tag {
  font-size: 9.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-low);
  margin-top: -3px;
}

.topbar__spacer {
  flex: 1;
}

.topbar__group {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-left: 1px solid var(--glass-brd);
  height: 34px;
}

.topbar__group:first-of-type {
  border-left: none;
}

/* ==========================================================================
   Glass panels
   ========================================================================= */

.panel {
  position: relative;
  border: 1px solid var(--glass-brd);
  border-radius: var(--r-lg);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Specular top edge - the tell that sells frosted glass. */
.panel::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.045),
    transparent 38%
  );
}

/*
 * Panels inside a scrolling rail must keep their natural height. Without this
 * they inherit flex-shrink:1, compress to fit the rail, and silently clip
 * their own copy - the calibration note loses its last line and nothing
 * indicates it is missing.
 */
.rail > .panel,
.stage > .panel {
  flex-shrink: 0;
}

/* The one panel that is *meant* to absorb the leftover space and scroll. */
.panel--flush {
  flex: 1 1 0;
  min-height: 200px;
}

.panel--accent {
  border-color: rgba(127, 0, 255, 0.22);
}

.panel__head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--glass-brd);
  flex-shrink: 0;
}

.panel__title {
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-mid);
  white-space: nowrap;
}

.panel__icon {
  width: 14px;
  height: 14px;
  color: var(--cyan);
  flex-shrink: 0;
}

.panel--accent .panel__icon {
  color: var(--violet-lite);
}

.panel__spacer {
  flex: 1;
}

.panel__body {
  padding: 13px 14px;
  min-height: 0;
  overflow: auto;
}

.panel__body--tight {
  padding: 8px;
}

.panel__body--flush {
  padding: 0;
  overflow: hidden;
  flex: 1;
}

/* ==========================================================================
   Status bar
   ========================================================================= */

.statusbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  font-family: var(--ff-mono);
  font-size: 10px;
  letter-spacing: 0.05em;
  color: var(--ink-low);
  border-top: 1px solid var(--glass-brd);
  background: rgba(5, 7, 13, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  overflow: hidden;
  white-space: nowrap;
}

.statusbar b {
  color: var(--ink-mid);
  font-weight: 500;
}

.statusbar__spacer {
  flex: 1;
}

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-low);
  margin-right: 5px;
  vertical-align: middle;
  transition: background 0.2s, box-shadow 0.2s;
}

.status-dot--live {
  background: var(--lime);
  box-shadow: 0 0 8px var(--lime);
  animation: pulse-dot 2s var(--ease) infinite;
}

.status-dot--warn {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}

.status-dot--err {
  background: var(--rose);
  box-shadow: 0 0 8px var(--rose);
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.42;
  }
}

/* ==========================================================================
   Utilities
   ========================================================================= */

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row--wrap {
  flex-wrap: wrap;
}

.row--between {
  justify-content: space-between;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.grow {
  flex: 1;
  min-width: 0;
}

.mono {
  font-family: var(--ff-mono);
  font-variant-numeric: tabular-nums;
}

.label {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-low);
  white-space: nowrap;
}

.hint {
  font-size: 11px;
  color: var(--ink-low);
  line-height: 1.5;
}

.divider {
  height: 1px;
  background: var(--glass-brd);
  margin: 10px 0;
  flex-shrink: 0;
}

.text-cyan {
  color: var(--cyan);
}
.text-violet {
  color: var(--violet-lite);
}
.text-amber {
  color: var(--amber);
}
.text-rose {
  color: var(--rose);
}
.text-lime {
  color: var(--lime);
}
.text-hi {
  color: var(--ink-hi);
}

.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;
}

[hidden] {
  display: none !important;
}

/* ==========================================================================
   Responsive
   ========================================================================= */

/*
 * Laptops, 1241-1599 px: keep the top bar on one row by tightening it and
 * dropping two readouts that repeat what is shown elsewhere. The Nyquist
 * limit follows from the rate selector beside it, and the A4 deviation from
 * the pitch standard chosen next to it. Both return once the bar wraps.
 */
@media (max-width: 1599px) {
  .brand__tag,
  #a4-cents,
  #nyquist-badge {
    display: none;
  }
  .topbar {
    column-gap: 10px;
  }
  .topbar__group {
    padding: 0 8px;
  }
}

@media (max-width: 1400px) {
  .topbar {
    column-gap: 6px;
  }
  .topbar__group {
    gap: 8px;
    padding: 0 6px;
  }
}

@media (max-width: 1500px) {
  :root {
    --rail-r: 340px;
    --rail-l: 216px;
  }
}

@media (max-width: 1240px) {
  .shell {
    grid-template-columns: minmax(0, 1fr) var(--rail-r);
  }
  .rail--left {
    display: none;
  }
  .rail--left.is-open {
    display: flex;
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: var(--status-h);
    width: 280px;
    z-index: 60;
    padding: var(--gap);
    background: var(--glass-bg-solid);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-right: 1px solid var(--glass-brd-hi);
    box-shadow: var(--shadow-lift);
  }
  .rail-toggle {
    display: inline-flex !important;
  }

  /* From here down the bar wraps, so separators would start new rows. */
  #a4-cents,
  #nyquist-badge {
    display: inline-flex;
  }
  .topbar {
    padding: 8px 12px;
  }
  .topbar__group {
    border-left: none;
    padding: 0;
  }
  .topbar__spacer {
    display: none;
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }
  #app {
    height: auto;
    min-height: 100dvh;
    grid-template-rows: auto 1fr var(--status-h);
  }
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .rail--right {
    overflow: visible;
  }
  .rail,
  .stage {
    overflow: visible;
  }
  .topbar {
    gap: 8px 12px;
  }
}

/*
 * Small phones. The master group alone - label, slider, readout and meter -
 * is wider than a 360 px screen, so a group may wrap onto a second line of
 * its own instead of pushing the page wider.
 */
@media (max-width: 600px) {
  .topbar__group {
    flex-wrap: wrap;
    height: auto;
    row-gap: 6px;
  }
  /* A panel's title, badge and buttons may take two lines, likewise. */
  .panel__head {
    flex-wrap: wrap;
    row-gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
