/* ═══════════════════════════════════════════════════════════
   DESIGN TOKENS
   ═══════════════════════════════════════════════════════════ */
:root {
  --bg:          #0f0f0f;
  --surface:     #1a1a1a;
  --surface-2:   #242424;
  --border:      #3a3a3a;
  --text:        #e8e8e8;
  --text-muted:  #a0a0a0;
  --accent:      #2196F3;
  --accent-dim:  #1565C0;
  --danger:      #e53935;
  --font:        ui-monospace, 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
  --radius:      5px;
  --navbar-h:    62px;
  --fs-base:     15px;
  --fs-small:    14px;
  --fs-xs:       13px;
  --btn-pad:     8px 16px;
  --input-pad:   6px 10px;
  --touch-min:   40px;   /* minimum tap target height */
}

/* ═══════════════════════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
}

/* ═══════════════════════════════════════════════════════════
   NAVBAR
   ═══════════════════════════════════════════════════════════ */
#navbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  height: var(--navbar-h);
  min-height: var(--navbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.navbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.navbar-center {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

/* ─── file input ─── */
.file-label {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  white-space: nowrap;
}

#file {
  font-family: var(--font);
  font-size: var(--fs-xs);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--input-pad);
  cursor: pointer;
  max-width: 240px;
  min-height: var(--touch-min);
}
#file::-webkit-file-upload-button {
  font-family: var(--font);
  font-size: var(--fs-xs);
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 4px 10px;
  margin-right: 8px;
  cursor: pointer;
}
#file::-webkit-file-upload-button:hover { background: var(--accent); color: #fff; }

#current-file {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

/* ─── buttons ─── */
.btn {
  font-family: var(--font);
  font-size: var(--fs-small);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--btn-pad);
  min-height: var(--touch-min);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  line-height: 1;
}
.btn:hover { border-color: var(--text-muted); color: var(--text); }

#play-button { border-color: var(--accent); color: var(--accent); }
#play-button:hover,
#play-button.playing { background: var(--accent); color: #fff; border-color: var(--accent); }

#stop-button:hover { border-color: var(--danger); color: var(--danger); }

#reset-button { color: var(--text-muted); font-size: var(--fs-xs); }
#reset-button:hover { color: var(--text); }

/* ─── download link ─── */
#xml_file_out {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font);
  font-size: var(--fs-xs);
  text-decoration: none;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--btn-pad);
  min-height: var(--touch-min);
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
  line-height: 1;
}
#xml_file_out:hover { border-color: var(--accent); color: var(--accent); }

/* ─── quant form ─── */
#quant_form {
  display: flex;
  align-items: center;
  gap: 5px;
}
#quant_form label { color: var(--text-muted); font-size: var(--fs-xs); white-space: nowrap; }
#quant {
  font-family: var(--font);
  font-size: var(--fs-xs);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--input-pad);
  min-height: var(--touch-min);
  cursor: pointer;
}
#quant:focus { outline: none; border-color: var(--accent); }

/* ─── about button ─── */
#about_button { text-decoration: none; }
#about_button button {
  font-family: var(--font);
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--btn-pad);
  min-height: var(--touch-min);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  line-height: 1;
}
#about_button button:hover { color: var(--text); border-color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════
   CONTROLS BAR  (toggle + page-help)
   ═══════════════════════════════════════════════════════════ */
#controls-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 14px;
  min-height: 44px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#settings {
  display: flex;
  align-items: center;
  gap: 8px;
}
#settings > label[for="x_enved"] {
  color: var(--text-muted);
  font-size: var(--fs-small);
}

/* toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 22px;
  transition: 0.25s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  bottom: 3px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: 0.25s;
}
input:checked + .slider { background: var(--accent); border-color: var(--accent); }
input:checked + .slider::before { background: #fff; transform: translateX(18px); }
input:focus + .slider { box-shadow: 0 0 0 2px rgba(33,150,243,0.25); }

/* page help */
#page-help {
  display: flex;
  gap: 14px;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  margin-left: auto;
}
#page-help span { white-space: nowrap; }

/* ═══════════════════════════════════════════════════════════
   SCORE AREA  (flex row: score-column | y-slider)
   ═══════════════════════════════════════════════════════════ */
#score-area {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
  overflow: hidden;
}

/* left column: x-slider on top, score below */
#score-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* ── horizontal time slider (top of score column) ── */
#dynamic_gui_x {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  min-height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#dynamic_gui_x > label {
  color: var(--text-muted);
  font-size: var(--fs-small);
  white-space: nowrap;
}

#X_slider {
  height: 12px;
  flex: 1;
  min-width: 120px;
  position: static;
  left: auto;
}

/* thicker horizontal track to match */
.noUi-horizontal { height: 12px; }

.noUi-horizontal .noUi-handle {
  width:  24px !important;
  height: 24px !important;
  right:  -12px !important;
  top:    -7px  !important;
}

/* vertical envelope sliders (gradual mode) */
#X0_slider,
#X1_slider {
  height: 200px;
  position: static;
  overflow: visible;
}

/* envelope canvas */
#x_y_control {
  cursor: crosshair;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: block;
}

/* ── score panel ── */
#svg_panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg);
  padding: 8px;
}

/* ── vertical pitch slider (right sidebar) ── */
#dynamic_gui_y {
  width: 160px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow: visible;
  padding: 28px 0;   /* top/bottom room so handles aren't clipped */
}

#Y_slider {
  height: 280px;
  position: static;
  overflow: visible;
}

/* Invert Verovio SVG for dark background */
#svg_output { filter: invert(1); }

/* ═══════════════════════════════════════════════════════════
   LOADING OVERLAY
   ═══════════════════════════════════════════════════════════ */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 1000;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
}
#loading-overlay.hidden { display: none; }

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════════════
   noUiSlider THEME
   ═══════════════════════════════════════════════════════════ */
.noUi-target {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: none;
}
.noUi-connects { border-radius: var(--radius); }
.noUi-connect  { background: var(--accent); }

/* ── horizontal slider (size defined near #X_slider above) ── */
.noUi-horizontal .noUi-handle::before,
.noUi-horizontal .noUi-handle::after { display: none; }
.noUi-horizontal .noUi-handle:hover  { border-color: #fff; }
.noUi-horizontal .noUi-active        { border-color: #fff; background: var(--accent); }

/* ── vertical slider ── */
.noUi-vertical { width: 28px; }

.noUi-vertical .noUi-handle {
  background: var(--surface);
  border: 3px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(33,150,243,0.35);
  cursor: ns-resize;
  width:   32px !important;
  height:  32px !important;
  right:   -2px !important;    /* centre on 28px track: (32-28)/2 = 2 */
  bottom: -16px !important;    /* noUiSlider vertical uses bottom, not top */
  top:    auto !important;     /* unset any inherited top so bottom takes effect */
}
.noUi-vertical .noUi-handle::before,
.noUi-vertical .noUi-handle::after { display: none; }
.noUi-vertical .noUi-handle:hover  { border-color: #fff; box-shadow: 0 0 8px rgba(255,255,255,0.25); }
.noUi-vertical .noUi-active        { background: var(--accent); border-color: #fff; }

/* ═══════════════════════════════════════════════════════════
   Y SLIDER PANEL  (pitch range)
   ═══════════════════════════════════════════════════════════ */
.y-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 18px;   /* side room so handles aren't clipped */
}

.y-panel-title {
  font-family: var(--font);
  font-size: var(--fs-base);
  color: var(--text);
  letter-spacing: 0.04em;
  text-align: center;
}

.y-limit {
  font-family: var(--font);
  font-size: var(--fs-base);
  color: var(--accent);
  white-space: nowrap;
  min-width: 70px;
  text-align: center;
}

.y-hint {
  font-family: var(--font);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-align: center;
  letter-spacing: 0.06em;
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE  — small / touch screens  (≤ 768 px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root {
    --fs-base:    17px;
    --fs-small:   16px;
    --fs-xs:      15px;
    --btn-pad:    10px 18px;
    --input-pad:  8px 12px;
    --touch-min:  48px;
    --navbar-h:   72px;
  }

  /* navbar wraps to two rows on narrow screens */
  #navbar {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--navbar-h);
    padding: 8px 12px;
    gap: 8px;
  }
  .navbar-left  { flex: 1 1 100%; }   /* file input takes full first row */
  .navbar-center,
  .navbar-right { flex: 1 1 auto; }

  /* hide verbose labels that waste space */
  .file-label { display: none; }
  #quant_form label { display: none; }

  /* thicker X slider track on touch */
  #X_slider { height: 18px; }
  .noUi-horizontal { height: 18px; }
  .noUi-horizontal .noUi-handle {
    width:  32px !important;
    height: 32px !important;
    right: -16px !important;
    top:   -8px  !important;
  }

  /* wider Y slider sidebar */
  #dynamic_gui_y { width: 180px; }
  #Y_slider       { height: 320px; }
  .noUi-vertical  { width: 36px; }
  .noUi-vertical .noUi-handle {
    width:  40px !important;
    height: 40px !important;
    right:  -2px !important;
    bottom:-20px !important;
  }

  /* controls bar wraps */
  #controls-bar { flex-wrap: wrap; gap: 12px; }
  #page-help { margin-left: 0; }
}
