:root {
  --bg: #101218;
  --panel: #171b22;
  --line: #2a3140;
  --text: #e8eef6;
  --muted: #93a0b3;
  --accent: #3ea0ff;
  --warn: #f0c14b;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: default;
}

body:not(.is-stage) #stage {
  left: 380px;
  width: calc(100% - 380px);
}

#panel {
  position: fixed;
  inset: 0 auto 0 0;
  width: 380px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: auto;
  padding: 18px 18px 32px;
  z-index: 3;
}

body.is-stage #panel { display: none; }

h1 {
  font-size: 18px;
  margin: 0 0 6px;
  letter-spacing: 0.02em;
}

.lead, .hint, #midiStatus, #songMeta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.row {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}

button, select, input[type="text"] {
  background: #222834;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  font: inherit;
}

button {
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: #081018;
  border-color: transparent;
  font-weight: 700;
}

button:hover { filter: brightness(1.08); }

#drop {
  border: 1px dashed #3b465c;
  border-radius: 14px;
  padding: 18px;
  text-align: center;
  margin: 12px 0;
}

#drop.hot {
  border-color: var(--accent);
  background: rgba(62, 160, 255, 0.08);
}

label.field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
  margin: 8px 0;
  font-size: 13px;
  color: var(--muted);
}

label.field input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
}

label.check {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  margin: 8px 0;
}

section, details {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

section h2, details h2 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--warn);
}

#handles {
  pointer-events: none;
}

#handles.hidden { display: none; }

.handle {
  position: fixed;
  pointer-events: auto;
  z-index: 5;
  border-radius: 999px;
  user-select: none;
  touch-action: none;
}

#handle-left, #handle-right {
  background: rgba(62, 160, 255, 0.55);
  cursor: ew-resize;
  border: 1px solid #9fd0ff;
}

#handle-hit {
  background: rgba(240, 193, 75, 0.55);
  cursor: ns-resize;
}

#handle-bottom {
  background: rgba(255, 255, 255, 0.28);
  cursor: ns-resize;
}

input[type="file"] { display: none; }

.filebtn {
  display: inline-block;
  margin-top: 8px;
  background: var(--accent);
  color: #081018;
  border-radius: 10px;
  padding: 9px 12px;
  font-weight: 700;
  cursor: pointer;
}

.kills {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
}

.kills b { color: var(--text); font-weight: 650; }

details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: "▾"; color: var(--muted); }
details:not([open]) > summary::after { content: "▸"; }
details > summary h2 { margin: 0; }
details[open] > summary { margin-bottom: 8px; }

#topbar, .sheet-head, #backdrop, .mobile-only, #calibDone { display: none; }

#toast {
  position: fixed;
  left: 50%;
  top: 56px;
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(23, 27, 34, 0.94);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

#toast.show { opacity: 1; }

#stage, .handle, button, .filebtn, summary {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body.no-midi .midi-only { display: none; }

/* ---------- Phones and small tablets ---------- */
body.is-mobile {
  --topbar-h: 52px;
  height: 100dvh;
}

body.is-mobile .desk-only { display: none; }
body.is-mobile .mobile-only { display: block; }

body.is-mobile #topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 4;
}

#mTitle {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

button.icon {
  min-width: 44px;
  height: 44px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

body.is-mobile #stage {
  left: 0;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  width: 100%;
  height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top));
}

body.is-mobile #panel {
  inset: auto 0 0 0;
  width: 100%;
  max-height: 82dvh;
  border-right: 0;
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 0 max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  box-shadow: var(--shadow);
  transform: translateY(105%);
  overscroll-behavior: contain;
  z-index: 10;
}

body.is-mobile.sheet-open #panel { transform: none; }
body.is-mobile.ready #panel { transition: transform 0.25s ease; }

body.is-mobile .sheet-head {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 44px;
  margin: 0 -16px 4px;
  background: var(--panel);
  z-index: 1;
}

.grabber {
  width: 40px;
  height: 5px;
  border-radius: 99px;
  background: var(--line);
}

#mClose {
  position: absolute;
  right: 8px;
  top: 0;
  background: transparent;
  border: 0;
  font-size: 18px;
}

body.is-mobile.sheet-open #backdrop {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 9;
}

body.is-mobile button,
body.is-mobile select,
body.is-mobile input[type="text"],
body.is-mobile .filebtn {
  min-height: 44px;
  font-size: 16px; /* prevents iOS zoom on focus */
}

body.is-mobile .row > button,
body.is-mobile .row > label.field { flex: 1; }

body.is-mobile .row > label.field input { width: 100%; }

body.is-mobile button.wide { width: 100%; margin: 4px 0 10px; }

body.is-mobile label.field,
body.is-mobile label.check { font-size: 15px; }

body.is-mobile label.check { min-height: 40px; }

body.is-mobile input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

body.is-mobile input[type="range"] {
  height: 32px;
  accent-color: var(--accent);
}

body.is-mobile #drop { border: 0; padding: 0; margin: 8px 0; text-align: left; }
body.is-mobile .filebtn { display: flex; align-items: center; justify-content: center; margin: 0; }

body.is-mobile.calib #calibDone {
  display: block;
  position: fixed;
  left: 50%;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 12px);
  transform: translateX(-50%);
  z-index: 6;
  min-width: 140px;
  box-shadow: var(--shadow);
}

body.is-mobile #toast { top: calc(var(--topbar-h) + env(safe-area-inset-top) + 12px); }
