:root {
  --bg: #0e1216;
  --panel: #161d24;
  --line: #232c36;
  --text: #cfe0ea;
  --dim: #7d919e;
  --accent: #4fd1a5;
  --warn: #f2a65a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

header h1 { font-size: 18px; margin: 0; font-weight: 600; }

#status { font-size: 13px; color: var(--dim); }

main {
  display: grid;
  grid-template-columns: 250px minmax(380px, 1fr) 330px;
  gap: 16px;
  padding: 16px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--dim);
  margin: 2px 0 12px;
}

.ctl { margin-bottom: 12px; }

.ctl label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 3px;
}

.ctl label output { color: var(--text); }

.shdr {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent);
  margin: 7px 0 5px;
  margin-bottom: 4px;
  padding-top: 5px;
  border-top: 1px solid #2a3540;
}

#sliders .shdr:first-child { border-top: none; margin-top: 0; padding-top: 0; }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

#shareBtn {
  grid-column: 1 / -1;
  width: 100%;
  margin-top: 2px;
  padding: 9px 12px;
  border: 1px solid var(--accent);
  border-radius: 9px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#shareBtn:hover { background: rgba(79, 209, 165, 0.12); }
#shareBtn:active { transform: translateY(1px); }

#randBtn {
  grid-column: 1 / -1;
  width: 100%;
  margin-top: 2px;
  padding: 9px 12px;
  border: 1px solid #e8b04b;
  border-radius: 9px;
  background: transparent;
  color: #e8b04b;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#randBtn:hover { background: rgba(232, 176, 75, 0.12); }
#randBtn:active { transform: translateY(1px); }

#shareMsg {
  grid-column: 1 / -1;
  min-height: 15px;
  font-size: 11px;
  color: var(--dim);
  text-align: center;
}

/* Advanced constants dialog: one side-by-side column per section. Modal, so
   the rest of the page is inert while it is open; the space key still drives
   the push button through the window-level key handlers. */
#advanced {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  padding: 12px 14px 14px;
  width: min(96vw, 1500px);
  max-height: 88vh;
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.45);
}

#advanced::backdrop { background: rgba(6, 10, 14, 0.55); }

.advhead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--dim);
}

#advClose, #advReset, #advRand {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

#advClose:hover { border-color: var(--accent); color: var(--accent); }
#advClose:active { transform: translateY(1px); }
#advReset:hover { border-color: #e8b04b; color: #e8b04b; }
#advReset:active { transform: translateY(1px); }
#advRand:hover { border-color: #e8b04b; color: #e8b04b; }
#advRand:active { transform: translateY(1px); }

/* The scroll area holds the section columns; 9 columns overflow sideways on
   narrow screens, each column scrolls on its own when it grows tall. */
#advSliders {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(172px, 1fr);
  gap: 0 16px;
  overflow: auto;
  max-height: calc(88vh - 84px);
  padding-right: 2px;
}

.scol { min-width: 0; }

.scol .shdr { border-top: none; margin-top: 0; padding-top: 0; }

#advBtn {
  grid-column: 1 / -1;
  width: 100%;
  margin-top: 2px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--dim);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#advBtn:hover { border-color: var(--accent); color: var(--accent); }
#advBtn:active { transform: translateY(1px); }

#stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

#diagram { width: 100%; height: 320px; display: block; }

#push {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: none;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #062018;
  background: radial-gradient(circle at 35% 30%, #77e6bd, #2fae85);
  box-shadow: 0 6px 22px rgba(79, 209, 165, 0.35), inset 0 -6px 12px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  transition: transform 0.05s ease;
}

#push.pressed {
  transform: scale(0.93);
  background: radial-gradient(circle at 35% 30%, #ffd28a, #e08b3c);
  box-shadow: 0 2px 10px rgba(242, 166, 90, 0.4), inset 0 -4px 10px rgba(0, 0, 0, 0.3);
}

#gaugeGrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

#gaugeGrid canvas {
  width: 100%;
  aspect-ratio: 1;
  display: block;
}

#spectrumPanel { grid-column: 1 / -1; }

#spectrum { width: 100%; height: 170px; display: block; }

@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; }
}

/* Compact vertical portrait layout: the whole visual interface stacks on one
   phone screen. The viz leads, then the gauges, then the spectrum, with the
   tuning controls below. */
@media (max-width: 700px) {
  header { padding: 8px 12px; flex-wrap: wrap; gap: 8px; }
  header h1 { font-size: 15px; }
  #status { font-size: 11px; }

  main { grid-template-columns: 1fr; gap: 10px; padding: 10px; }
  #stage { gap: 8px; }

  #diagram { height: clamp(170px, 23vh, 240px); }

  #push { width: 96px; height: 96px; font-size: 14px; }

  #gaugeGrid { grid-template-columns: repeat(4, 1fr); gap: 8px 6px; }

  #spectrum { height: 116px; }

  #sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
  #advSliders { grid-auto-flow: row; grid-template-columns: 1fr 1fr; max-height: 66vh; }
  .ctl { margin-bottom: 3px; }
  .ctl label { font-size: 10px; margin-bottom: 1px; }
  input[type="range"] { height: 22px; }
  .panel { padding: 10px; }
  h2 { margin: 0 0 8px; }
}

@media (max-width: 340px) {
  #gaugeGrid { grid-template-columns: repeat(2, 1fr); }
  #sliders { grid-template-columns: 1fr; }
  #advSliders { grid-template-columns: 1fr; }
}
