:root {
  --bg: #070a11;
  --bg-soft: #0d1220;
  --panel: rgba(16, 22, 36, 0.82);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #e8eefb;
  --muted: #8fa0bd;
  --accent: #6fe3ff;
  --accent-2: #b98cff;
  --danger: #ff7a7a;
  --radius: 12px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(111, 227, 255, 0.12), transparent 60%),
    radial-gradient(900px 600px at 95% 10%, rgba(185, 140, 255, 0.12), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---------------- top bar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 11, 19, 0.7);
  backdrop-filter: blur(10px);
  flex: 0 0 auto;
}

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

.logo {
  font-size: 24px;
  color: var(--accent);
  text-shadow: 0 0 18px rgba(111, 227, 255, 0.6);
}

.brand h1 {
  font-size: 15px;
  margin: 0;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.tagline {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.meters {
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.meter b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ---------------- buttons & fields ---------------- */

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(135deg, rgba(111, 227, 255, 0.9), rgba(185, 140, 255, 0.9));
  border-color: transparent;
  color: #06121b;
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn.big {
  padding: 12px 22px;
  font-size: 15px;
}

.btn.small {
  padding: 6px 11px;
  font-size: 12px;
}

.btn.ghost {
  width: 34px;
  padding: 8px 0;
  text-align: center;
}

.btn.danger {
  border-color: rgba(255, 122, 122, 0.4);
  color: var(--danger);
}

.btn.active {
  background: rgba(111, 227, 255, 0.18);
  border-color: rgba(111, 227, 255, 0.6);
  color: var(--accent);
}

.btn.recording {
  background: rgba(255, 92, 92, 0.2);
  border-color: rgba(255, 92, 92, 0.7);
  color: #ff9c9c;
  animation: pulse 1.4s infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.6;
  }
}

/* ---------------- layout ---------------- */

main {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

.stage-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

.stage {
  position: relative;
  margin: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #04060b;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  touch-action: none;
}

.stage video,
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* `fill` on purpose: JS sizes the stage to the exact camera aspect ratio, so the
   image is never distorted, and normalised landmark coordinates always map
   linearly onto the box. `cover` would crop and break that mapping. */
.stage video {
  object-fit: fill;
  filter: saturate(0.85) contrast(1.03);
}

.stage video.mirrored {
  transform: scaleX(-1);
}

.stage canvas {
  pointer-events: none;
}

.stage.editing {
  cursor: crosshair;
}

.stage-foot {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  min-height: 18px;
}

/* ---------------- player HUD ---------------- */

.hud {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 7px;
  border-radius: 999px;
  background: rgba(6, 10, 18, 0.66);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  font-size: 11px;
  white-space: nowrap;
}

.chip .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 10px currentColor;
}

.chip .who {
  font-weight: 600;
  letter-spacing: 0.2px;
}

.chip .side {
  color: var(--muted);
}

.chip .speed {
  width: 54px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}

.chip .speed i {
  display: block;
  height: 100%;
  border-radius: 2px;
  transition: width 0.06s linear;
}

.chip .note {
  font-family: ui-monospace, monospace;
  min-width: 30px;
  text-align: right;
}

.chip .inst {
  color: var(--muted);
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------- gate & banner ---------------- */

/* Flex + auto margins rather than grid centring: when the card is taller than
   the stage (an error is showing) it must scroll instead of being clipped. */
.gate {
  position: absolute;
  inset: 0;
  display: flex;
  overflow-y: auto;
  padding: 20px;
  background: rgba(4, 6, 12, 0.9);
  backdrop-filter: blur(4px);
  z-index: 5;
}

.gate[hidden] {
  display: none;
}

.gate-card {
  max-width: 520px;
  margin: auto;
  text-align: center;
  flex: 0 0 auto;
}

.gate-card h2 {
  margin: 0 0 10px;
  font-size: 26px;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.gate-card p {
  color: #c3d0e6;
  margin: 0 0 14px;
}

.steps {
  text-align: left;
  display: inline-block;
  color: var(--muted);
  margin: 0 0 18px;
  padding-left: 20px;
}

.fineprint {
  margin-top: 14px !important;
  font-size: 11px;
  color: var(--muted);
}

/* With an error on screen the pitch is no longer the point: hide the intro so the
   explanation and its buttons fit without scrolling. */
.gate-card.has-error .intro,
.gate-card.has-error .steps,
.gate-card.has-error .fineprint {
  display: none;
}

.gate-error {
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 122, 122, 0.45);
  background: rgba(255, 122, 122, 0.07);
  border-radius: 12px;
  text-align: left;
}

.gate-error[hidden] {
  display: none;
}

.gate-error h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: #ffbdbd;
}

.gate-error p {
  margin: 0 0 10px !important;
  font-size: 12.5px;
  color: #d8e2f2;
}

.gate-error pre {
  margin: 0 0 12px;
  font-size: 11px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, monospace;
}

.row.center {
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Anchors styled as buttons need the text decoration and line box normalised. */
a.btn {
  text-decoration: none;
  display: inline-block;
}

.banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(6, 10, 18, 0.85);
  border: 1px solid var(--line-strong);
  font-size: 12px;
  z-index: 4;
  max-width: 88%;
  text-align: center;
  pointer-events: none; /* a floating message must never intercept a touch */
}

.banner.error {
  border-color: rgba(255, 122, 122, 0.6);
  color: #ffbdbd;
}

/* ---------------- side panel ---------------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  backdrop-filter: blur(10px);
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.tab {
  flex: 1;
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 11px 6px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-page {
  display: none;
  padding: 12px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.tab-page.active {
  display: block;
}

.row {
  display: flex;
  gap: 6px;
}

.row.wrap {
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.field {
  display: block;
  margin-bottom: 12px;
}

.field > span {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
}

.field small {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

select,
input[type='range'] {
  width: 100%;
}

select {
  appearance: none;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
}

input[type='range'] {
  accent-color: var(--accent);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 12.5px;
  color: #cbd6ea;
}

.check input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
}

.help,
.empty {
  font-size: 11.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border-left: 2px solid var(--accent);
  padding: 8px 10px;
  border-radius: 0 8px 8px 0;
  margin: 0 0 10px;
}

.empty {
  border-left-color: var(--line-strong);
}

/* ---------------- instrument rows ---------------- */

.inst-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.inst {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 0.15s, background 0.15s;
}

.inst.selected {
  border-color: var(--accent);
}

.inst.hit {
  background: rgba(111, 227, 255, 0.1);
}

.inst.muted {
  opacity: 0.55;
}

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

.inst .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 8px currentColor;
}

.inst-name {
  font-size: 13px;
  font-weight: 600;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  padding: 2px 0;
  min-width: 0;
}

.inst-name:focus {
  outline: 1px solid var(--line-strong);
  border-radius: 4px;
}

.icon-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 5px;
  line-height: 1;
}

.icon-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

/* Word labels instead of emoji: they render identically everywhere. */
.text-btn {
  font-size: 10.5px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  border: 1px solid var(--line);
  padding: 3px 6px;
}

.text-btn.on {
  color: var(--danger);
  border-color: rgba(255, 122, 122, 0.45);
}

.inst-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
}

.inst-meta select {
  font-size: 11.5px;
  padding: 4px 6px;
  flex: 1 1 auto;
}

.inst-tag {
  font-size: 10.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  padding: 3px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------------- modal ---------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(3, 5, 10, 0.78);
  backdrop-filter: blur(6px);
  padding: 20px;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  max-width: 620px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 22px 24px;
}

.modal-card h2 {
  margin: 0 0 14px;
  font-size: 20px;
}

.modal-card ul {
  padding-left: 18px;
  margin: 0 0 18px;
  color: #c6d2e8;
}

.modal-card li {
  margin-bottom: 10px;
}

.modal-card b {
  color: var(--text);
}

/* ---------------- responsive ---------------- */

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  main {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel {
    max-height: 46vh;
  }

  .meters {
    display: none;
  }
}
