/* ═══════════════════════════════════════════════════════════
   CRT OSCILLOSCOPE — scope.css
   Black & white UI. The scope area, overlays and fullscreen
   rules are the original ones; only the menu is TUI-styled.
   ═══════════════════════════════════════════════════════════ */

/* ── RESET ── */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: #0a0a0a;
  color: #ccc;
  font-family: Monaco, Menlo, Consolas, "DejaVu Sans Mono", monospace;
  font-size: 12px;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── TOP BAR: just the two buttons, floating over the panel column ── */
.top-bar {
  position: absolute;
  top: 0;
  right: 0;
  width: 250px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0 0;
  z-index: 10;
  pointer-events: none;
}
.top-bar .status {
  font-size: 11px;
  color: #666;
  padding: 2px 8px 0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.top-bar .status:empty { display: none; }
.top-bar .status.active { color: #ccc; }
.top-bar .status.error { color: #ff4444; }

.bar-btns { display: flex; gap: 8px; pointer-events: auto; }
.bar-btn {
  height: 20px;
  padding: 0 10px;
  background: #0d0d0d;
  border: 1px solid #555;
  color: #ccc;
  font: inherit;
  font-size: 12px;
  line-height: 18px;
  letter-spacing: 1px;
  cursor: pointer;
}
.bar-btn kbd {
  font: inherit;
  color: #666;
  margin-left: 8px;
}
.bar-btn:hover { background: #d4d4d4; color: #000; border-color: #d4d4d4; }
.bar-btn:hover kbd { color: #444; }

/* ── MAIN LAYOUT ── */
.main {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ── SCOPE AREA ── */
.scope-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  position: relative;
  min-width: 0;
}
.scope-container {
  position: relative;
  width: 100%;
  max-width: 1000px;
  aspect-ratio: 4 / 3;
  border-radius: 18px;
  overflow: hidden;
  box-shadow:
    0 0 2px rgba(255,255,255,0.05),
    0 0 30px rgba(0,0,0,0.3),
    inset 0 0 60px #00000088;
}

canvas#scope {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 18px;
}
canvas#signalCanvas {
  display: none;
}

/* CRT curvature vignette */
.crt-overlay {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(ellipse at center, transparent 58%, rgba(0,0,0,0.5) 100%);
}
.crt-overlay.off { display: none; }

/* Scanlines */
.scanlines {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  pointer-events: none;
  z-index: 3;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.1) 2px,
    rgba(0, 0, 0, 0.1) 4px
  );
  mix-blend-mode: multiply;
}
.scanlines.off { display: none; }

/* Flicker animation */
@keyframes flicker {
  0%   { opacity: 0.97; }
  5%   { opacity: 0.955; }
  10%  { opacity: 0.98; }
  50%  { opacity: 0.965; }
  100% { opacity: 0.97; }
}
.scope-container.crt-on {
  animation: flicker 0.15s infinite alternate;
}

/* Cursor readout overlay */
.cursor-readout {
  position: absolute;
  top: 8px;
  left: 12px;
  font-family: Monaco, Menlo, Consolas, "DejaVu Sans Mono", monospace;
  font-size: 11px;
  color: #ccc;
  z-index: 6;
  pointer-events: none;
  text-shadow: 0 0 4px rgba(255,255,255,0.15);
  line-height: 1.5;
}
.cursor-readout.off { display: none; }

/* Freeze indicator */
.freeze-badge {
  position: absolute;
  top: 8px;
  right: 12px;
  font-family: Monaco, Menlo, Consolas, "DejaVu Sans Mono", monospace;
  font-size: 13px;
  color: #999;
  z-index: 6;
  pointer-events: none;
  text-shadow: 0 0 8px rgba(255,255,255,0.2);
  display: none;
}
.freeze-badge.on { display: block; }

/* Hint shown until audio is running */
.start-hint {
  position: absolute;
  left: 0;
  right: 0;
  top: 38%;
  text-align: center;
  font-family: Monaco, Menlo, Consolas, "DejaVu Sans Mono", monospace;
  font-size: 12px;
  color: #fff;
  letter-spacing: 2px;
  line-height: 2;
  z-index: 6;
  pointer-events: none;
  text-shadow: 0 0 6px rgba(255,255,255,0.25);
}
.start-hint.off { display: none; }

/* ── SIDE PANEL (TUI) ── */
.panel {
  width: 250px;
  background: #0d0d0d;
  border-left: 1px solid #1a1a1a;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  padding-top: 34px;   /* room for the floating MENU / FULLSCREEN buttons */
  font-size: 12px;
  line-height: 1.5;
}
.panel::-webkit-scrollbar { width: 4px; }
.panel::-webkit-scrollbar-track { background: #0a0a0a; }
.panel::-webkit-scrollbar-thumb { background: #222; border-radius: 2px; }

.panel button, .panel select, .panel input { font: inherit; color: inherit; }
.panel button { background: none; border: none; cursor: pointer; }

.panel section { padding: 4px 0 8px; }

.panel h3 {
  padding: 0 8px 0 16px;
  font-size: 12px;
  font-weight: normal;
  color: #fff;
  text-transform: uppercase;
  margin-bottom: 2px;
}

/* Rows: one line of the TUI. The cursor row is drawn inverse. */
.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  padding: 0 8px 0 16px;
  color: #ccc;
  cursor: default;
  white-space: nowrap;
}
.row.cur { background: #d4d4d4; color: #000; }
.row.hidden { display: none; }

.row .k {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row.stack {
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding-bottom: 4px;
}
.row.stack .k { flex: none; }

/* Choice buttons: plain text, the active one inverse */
.choices { display: flex; gap: 1px; }
.btn {
  padding: 0 4px;
  color: #666;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.btn:hover { color: #ccc; }
.btn.active { background: #ccc; color: #000; }
.btn:disabled { opacity: 0.35; cursor: default; }
.row.cur .btn { color: #555; }
.row.cur .btn:hover { color: #000; }
.row.cur .btn.active { background: #000; color: #fff; }

/* Action buttons: [ LIKE THIS ], whole row is clickable */
.row[data-item="action"] { cursor: pointer; }
.btn.act { padding: 0; color: #ccc; letter-spacing: 1px; }
.btn.act::before { content: '[ '; color: #666; }
.btn.act::after  { content: ' ]'; color: #666; }
.row.cur .btn.act { color: #000; }
.row.cur .btn.act::before, .row.cur .btn.act::after { color: #555; }

/* Collapsible section */
.row[data-item="fold"] { cursor: pointer; }
.row[data-item="fold"] .k {
  color: #fff;
  text-transform: uppercase;
}
.row[data-item="fold"] .mark::before { content: '[-]'; color: #666; }
.fold.collapsed .row[data-item="fold"] .mark::before { content: '[+]'; }
.fold.collapsed .fold-body { display: none; }
.row.cur[data-item="fold"] .k,
.row.cur[data-item="fold"] .mark::before { color: #000; }

/* Sliders: a bar filled to --pct with a block cursor */
.row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 84px;
  height: 10px;
  margin: 0;
  border: none;
  outline: none;
  cursor: ew-resize;
  background: linear-gradient(to right, #ccc var(--pct, 0%), #262626 var(--pct, 0%));
}
.row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 3px;
  height: 10px;
  background: #fff;
}
.row.cur input[type="range"] {
  background: linear-gradient(to right, #000 var(--pct, 0%), #9a9a9a var(--pct, 0%));
}
.row.cur input[type="range"]::-webkit-slider-thumb { background: #000; }
.row input[type="range"]:disabled { opacity: 0.3; cursor: default; }
.row .val {
  width: 5ch;
  text-align: right;
}
.row:has(input:disabled) { color: #666; }

/* Selects: text with a small marker, left/right cycles them */
.sel {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 100%;
}
.sel select {
  -webkit-appearance: none;
  appearance: none;
  background: none;
  border: none;
  outline: none;
  cursor: pointer;
  width: 100%;
  padding: 0 16px 0 4px;
  text-overflow: ellipsis;
  color: inherit;
}
.sel::after {
  content: 'v';
  position: absolute;
  right: 4px;
  color: #666;
  pointer-events: none;
  font-size: 10px;
}
.row.cur .sel::after { color: #555; }
select option { background: #111; color: #ccc; }

/* Presets */
.preset-list { display: flex; flex-direction: column; }
.preset-row .preset-name {
  flex: 1;
  text-align: left;
  padding: 0;
  color: #ccc;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preset-row .preset-name::before { content: '* '; color: #666; }
.preset-row .preset-del { padding: 0; color: #666; }
.preset-row .preset-del::before { content: '[ '; }
.preset-row .preset-del::after  { content: ' ]'; }
.preset-row .preset-del:hover { color: #ff5555; }
.row.cur .preset-name { color: #000; }
.row.cur .preset-del { color: #555; }
.row.cur .preset-del:hover { color: #a00; }
.preset-msg {
  padding: 2px 8px 0 16px;
  font-size: 11px;
  color: #666;
  line-height: 1.4;
  white-space: normal;
}
.preset-msg:empty { display: none; }

/* ── DIALOGS ── */
.dlg {
  margin: auto;
  width: 320px;
  padding: 12px 14px;
  background: #0d0d0d;
  color: #ccc;
  border: 1px solid #666;
  font-family: Monaco, Menlo, Consolas, "DejaVu Sans Mono", monospace;
  font-size: 12px;
}
.dlg::backdrop { background: rgba(0, 0, 0, 0.7); }
.dlg form { display: flex; flex-direction: column; gap: 10px; }
.dlg h3 {
  font-size: 11px;
  font-weight: normal;
  color: #666;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.dlg p { line-height: 1.5; overflow-wrap: anywhere; }
.dlg input[type="text"] {
  width: 100%;
  background: #0a0a0a;
  color: #ccc;
  border: 1px solid #444;
  font: inherit;
  padding: 3px 6px;
  outline: none;
}
.dlg input[type="text"]:focus { border-color: #aaa; }
.dlg .btn-row { display: flex; justify-content: flex-end; gap: 12px; }
.dlg .btn {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  padding: 0;
  color: #ccc;
  letter-spacing: 1px;
}
.dlg .btn::before { content: '[ '; color: #666; }
.dlg .btn::after  { content: ' ]'; color: #666; }
.dlg .btn:hover, .dlg .btn:focus-visible {
  background: #d4d4d4;
  color: #000;
  outline: none;
}

/* ── COLLAPSIBLE PANEL ── */
.panel {
  transition: margin-right 0.25s ease, opacity 0.2s ease;
}
.panel.collapsed {
  margin-right: -250px;
  opacity: 0;
  pointer-events: none;
}

/* ── FULLSCREEN ── */
body.fullscreen .top-bar {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s ease;
}
body.fullscreen .top-bar:hover,
body.fullscreen .top-bar.visible {
  opacity: 1;
}
body.fullscreen .panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 99;
}
body.fullscreen .panel.collapsed {
  margin-right: -250px;
}
body.fullscreen .scope-wrap {
  padding: 0;
}
body.fullscreen .scope-container {
  max-width: none;
  aspect-ratio: auto;
  border-radius: 0;
  width: 100%;
  height: 100%;
}
body.fullscreen canvas#scope {
  border-radius: 0;
}
body.fullscreen .crt-overlay {
  border-radius: 0;
}
body.fullscreen .scanlines {
  border-radius: 0;
}
