/* Colour has meaning here, so keep it scarce:
   amber = the handler, teal = you and the loop you're practising, green/red = how
   you did. Everything else is neutral charcoal (UI chrome, toggles, labels). */
:root {
  --bg: #0f1113;
  --panel: #16191d;
  --panel-2: #1e2227;
  --line: #2b3037;
  --line-2: #3a4049;
  --text: #e8eaed;
  --muted: #9aa1aa;
  --handler: #f5b942;
  --you: #4fd1c5;
  --good: #6fd08c;
  --bad: #ff7a6b;
  --on-bg: rgba(255, 255, 255, 0.09);
  --on-line: rgba(255, 255, 255, 0.55);
  --radius: 10px;
  --ov-h: 44px; /* timeline scrubber at the bottom of the lane */
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; min-height: 100vh; }
button, select, input { font: inherit; color: inherit; }
button, .btn, select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
button:hover, .btn:hover, select:hover { border-color: var(--line-2); }
button.primary { background: var(--text); color: #111317; border-color: transparent; font-weight: 600; }
/* toggles: a little on/off switch inside the button says the state (the knob
   slides right and the track fills when it's on), not colour alone */
button.toggle.on { background: var(--on-bg); border-color: var(--on-line); }
button.switch::after {
  content: ""; flex: none; width: 26px; height: 15px; border-radius: 8px; margin-left: 2px;
  background: radial-gradient(circle at 7.5px 50%, #c9ced4 4.6px, transparent 5.2px), rgba(255,255,255,.12);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
  transition: background .15s;
}
button.switch.on::after {
  background: radial-gradient(circle at 18.5px 50%, #111317 4.6px, transparent 5.2px), var(--text);
  box-shadow: none;
}
/* the mic is "you": its switch fills teal */
#micBtn.on::after { background: radial-gradient(circle at 18.5px 50%, #06201d 4.6px, transparent 5.2px), var(--you); }
button.sm { padding: 3px 9px; }
button.ghost { background: transparent; }
button:disabled { opacity: .45; cursor: default; }
button { display: inline-flex; align-items: center; gap: 6px; }
button svg, label svg {
  width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
svg .f { fill: currentColor; }
button.icon { padding: 6px 9px; justify-content: center; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: 11px; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- header */
header.top {
  display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .2px; white-space: nowrap; }
.now { display: flex; align-items: baseline; gap: 12px; min-width: 0; flex: 1; }
.now h2 { margin: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.status { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.status.err { color: var(--bad); }
.source { display: flex; gap: 8px; align-items: center; flex: 1; flex-wrap: wrap; }
.source input[type=url] {
  flex: 1; min-width: 220px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px;
}
.source .or { color: var(--muted); }
#library { max-width: 220px; }
#streamOpt { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
/* while practising, the loading controls fold away behind "Change video" */
body.working:not(.choosing) .source { display: none; }
body.working.choosing .source { flex-basis: 100%; }
body.working.choosing #changeBtn { background: var(--on-bg); border-color: var(--on-line); }

/* ---------------------------------------------------------------- start page */
main { padding: 10px 16px 16px; }
.empty .drop {
  max-width: 720px; margin: 6vh auto; padding: 32px; border: 2px dashed var(--line);
  border-radius: 16px; background: var(--panel);
}
.empty h1 { margin: 0 0 8px; font-size: 24px; }
.empty ul { padding-left: 18px; color: var(--muted); }
.empty li b { color: var(--text); }
.tip { background: var(--panel-2); padding: 8px 12px; border-radius: 8px; }
.seeds { margin: 20px 0 16px; }
.seeds h3 { margin: 0 0 2px; font-size: 16px; }
.seeds > p { margin: 0 0 10px; }
.seed-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.seed {
  display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 0 0 10px; overflow: hidden;
  text-align: left; white-space: normal; background: var(--panel-2);
}
.seed:hover { border-color: var(--on-line); }
.seed img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; background: var(--bg); }
.seed-t { padding: 0 10px; font-weight: 600; line-height: 1.3; }
.seed-m { padding: 0 10px; color: var(--muted); font-size: 12px; }
@media (max-width: 520px) { .empty .drop { padding: 20px 16px; margin: 3vh auto; } }

/* ---------------------------------------------------------------- practice screen
   full height: header, the lane (fills), settings (when open), the control bar */
body.working { height: 100vh; height: 100dvh; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
body.working main { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 10px 12px 0; }
#workspace { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }

/* the lane, plus the video either floating over it (pip) or in its own column (side) */
.stage { position: relative; flex: 1; min-height: 0; display: flex; gap: 10px; }
.lane-pane {
  position: relative; flex: 1; min-width: 0; min-height: 240px;
  border-radius: var(--radius); overflow: hidden; background: var(--panel); border: 1px solid var(--line);
}
#lane {
  position: absolute; left: 0; top: 0; width: 100%; height: calc(100% - var(--ov-h));
  display: block; cursor: grab; touch-action: none; user-select: none;
}
#overview {
  position: absolute; left: 0; bottom: 0; width: 100%; height: var(--ov-h); display: block;
  border-top: 1px solid var(--line); background: var(--bg); cursor: crosshair; touch-action: none;
}

/* lane toolbar, top-left (right of the note names) */
.lane-tools {
  position: absolute; left: 48px; top: 6px; z-index: 2; display: flex; gap: 6px; align-items: center;
}
.lane-mode, .zoom {
  display: flex; align-items: center; background: rgba(15,17,19,.85); border: 1px solid var(--line); border-radius: 8px; padding: 2px;
}
.lane-mode button { border: 0; background: transparent; padding: 3px 9px; font-size: 12px; border-radius: 6px; color: var(--muted); gap: 5px; }
.lane-mode button svg { width: 14px; height: 14px; }
.lane-mode button.on { background: rgba(255,255,255,.12); color: var(--text); }
.zoom { gap: 6px; padding: 2px 8px; color: var(--muted); }
.zoom svg { width: 14px; height: 14px; }
#zoom { width: 80px; }
@media (max-width: 700px) { .lane-mode button span { display: none; } #zoom { width: 56px; } }

.video-pane {
  aspect-ratio: 16 / 9; background: #000; border-radius: 8px; overflow: hidden; border: 1px solid var(--line-2);
  display: flex; align-items: center; justify-content: center;
}
/* picture-in-picture: over the past (left) side of the lane, above the time labels */
.stage.pip .video-pane {
  position: absolute; z-index: 6; /* above every lane overlay: nothing may sit in front of a YouTube player */ left: 51px; bottom: calc(var(--ov-h) + 31px);
  width: min(24%, 280px); min-width: 150px; box-shadow: 0 8px 28px rgba(0,0,0,.5);
}
/* side by side: its own column, top-left; the lane takes the rest */
.stage.side .video-pane { position: relative; flex: 0 0 min(34%, 560px); align-self: flex-start; }
/* the resize grip is for the PiP; side by side is sized by the layout */
.stage:not(.pip) .video-grip { display: none; }
/* YouTube embed: at least 200px tall (356px wide at 16:9) in every view */
.stage.yt.side .video-pane { flex-basis: max(356px, min(34%, 560px)); }
@media (max-width: 760px) {
  .stage.side { flex-direction: column; }
  .stage.side .video-pane { flex: none; width: 100%; max-height: 32vh; }
  .stage.yt.side .video-pane { flex: none; max-height: none; min-height: 200px; }
}
/* video view switch in the control bar */
.seg { display: flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 8px; border-radius: 6px; color: var(--muted); }
.seg button.on { background: rgba(255,255,255,.12); color: var(--text); }
.seg button:disabled { opacity: .35; }
.video-pane video { width: 100%; height: 100%; object-fit: cover; display: block; cursor: pointer; }
.yt-host { width: 100%; height: 100%; }
.yt-host iframe { width: 100%; height: 100%; border: 0; display: block; }
.video-msg { position: absolute; color: var(--muted); font-size: 12px; text-align: center; padding: 8px; pointer-events: none; }
.video-msg:empty { display: none; }
/* resize grip, top-right (the pane is anchored bottom-left, so it grows up and right) */
.video-grip {
  position: absolute; z-index: 3; right: 0; top: 0; width: 22px; height: 22px; cursor: nesw-resize; touch-action: none;
  background: linear-gradient(225deg, rgba(0,0,0,.55) 50%, transparent 50%); opacity: 0; transition: opacity .15s;
}
.video-grip::after {
  content: ""; position: absolute; right: 4px; top: 4px; width: 8px; height: 8px;
  border-top: 2px solid rgba(255,255,255,.85); border-right: 2px solid rgba(255,255,255,.85);
}
.video-pane:hover .video-grip, .video-pane.sizing .video-grip { opacity: 1; }
@media (hover: none) { .video-grip { opacity: .8; } }
.video-pane.sizing iframe, .video-pane.sizing video { pointer-events: none; }

.lane-name {
  position: absolute; z-index: 3; height: 24px; padding: 2px 8px; font-size: 12px; font-weight: 600;
  background: var(--bg); color: var(--handler); border: 1px solid var(--handler); border-radius: 6px; outline: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}

/* the loop's own controls, beside its LOOP ✕ label: ⟲ Loop | 🗣 Call & response.
   One segmented control: the selected half is filled; a new loop shows neither
   (pending) with a soft pulse until you pick. */
.loop-ask {
  position: absolute; z-index: 4; display: flex; padding: 2px; border-radius: 8px;
  background: rgba(15,17,19,.94); border: 1px solid var(--line-2);
}
.loop-ask button {
  padding: 2px 9px; font-size: 12px; gap: 5px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted);
}
.loop-ask button svg { width: 13px; height: 13px; }
.loop-ask button:hover { color: var(--text); background: rgba(255,255,255,.08); }
.loop-ask button.sel { background: var(--text); color: #111317; font-weight: 600; }
.loop-ask.pending { border-color: var(--on-line); animation: ask-pulse 1.2s ease-in-out infinite alternate; }
.loop-ask.pending button { color: var(--text); }
/* picked Call & response with the mic off: the same box asks to turn the mic on */
.loop-mic { display: none; align-items: center; gap: 6px; padding-left: 8px; font-size: 12px; color: var(--text); }
.loop-ask.asking-mic > button { display: none; }
.loop-ask.asking-mic .loop-mic { display: flex; }
.loop-ask.asking-mic .loop-mic button { color: var(--text); }
.loop-ask.asking-mic .loop-mic button.sel { color: #111317; }
.loop-ask.asking-mic { border-color: var(--on-line); animation: ask-pulse 1.2s ease-in-out infinite alternate; }
@keyframes ask-pulse { from { box-shadow: 0 0 0 0 rgba(255,255,255,0); } to { box-shadow: 0 0 0 4px rgba(255,255,255,.18); } }

/* ---------------------------------------------------------------- settings (⚙) */
.settings-panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; max-height: 40vh; overflow: auto;
}
.set-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 10px; }
.set-grid label { display: flex; flex-direction: column; gap: 4px; }
.keys { line-height: 2; }

/* ---------------------------------------------------------------- control bar */
.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px;
  padding: 2px 4px 12px;
}
.bar .group { display: flex; align-items: center; gap: 6px; }
.play { min-width: 46px; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 88px; margin-left: 4px; }
.loop-info { font-variant-numeric: tabular-nums; white-space: nowrap; }
.loop-info:empty { display: none; }
#echoMode { padding: 5px 8px; font-size: 13px; }
/* mic level lives inside the Mic button */
.level { width: 28px; height: 6px; background: rgba(255,255,255,.1); border-radius: 3px; overflow: hidden; display: inline-block; }
.level span { display: block; height: 100%; width: 0; background: var(--you); transition: width .05s; }
#listenBtn.nudge { animation: nudge 1s ease-in-out infinite alternate; border-color: var(--on-line); }
@keyframes nudge { from { box-shadow: 0 0 0 0 rgba(255,255,255,0); } to { box-shadow: 0 0 0 4px rgba(255,255,255,.3); } }

/* your status: whose turn, mic prompt, handler/you pitch */
.status-zone {
  flex: 1; min-width: 330px; display: flex; align-items: center; gap: 16px; justify-content: flex-end;
  font-size: 13px; white-space: nowrap; overflow: hidden; min-height: 32px;
}
.turn-msg { flex: none; display: flex; align-items: center; font-weight: 700; }
/* "Your turn": a teal pill (you = teal), quieter once you've started whistling */
.turn-msg .pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px 4px 10px; border-radius: 999px;
  background: var(--you); color: #06201d; font-size: 14px;
}
.turn-msg .pill svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.turn-msg.started .pill { background: rgba(79,209,197,.16); color: var(--you); }

.turn-msg:empty { display: none; }
.turn-msg.started { font-weight: 600; }
.turn-msg small { margin-left: 10px; color: var(--text); font-weight: 400; font-size: 12px; opacity: .8; }
.mic-ask { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mic-ask span { overflow: hidden; text-overflow: ellipsis; }
.mic-ask button { padding: 2px 10px; font-size: 12px; }
.pitch-ro { display: flex; gap: 16px; min-width: 0; overflow: hidden; font-variant-numeric: tabular-nums; }
.pitch-ro:empty { display: none; }
.pitch-ro > span {
  /* fixed widths so nothing shifts as the numbers change */
  display: inline-grid; grid-template-columns: auto 48px auto; gap: 6px; align-items: baseline;
}
.pitch-ro .y { grid-template-columns: auto 120px; }
.pitch-ro .k { color: var(--muted); font-size: 11px; }
.pitch-ro .h b { color: var(--handler); }
.pitch-ro .y b { color: var(--you); }
.pitch-ro .idle b { color: var(--muted); }
.pitch-ro small { color: var(--muted); font-size: 11px; }
.pitch-ro .y b.good { color: var(--good); } .pitch-ro .y b.mid { color: var(--text); } .pitch-ro .y b.bad { color: var(--bad); }

@media (max-width: 760px) {
  body.working main { padding: 8px 8px 0; }
  .bar .group { flex-wrap: wrap; }
  body.working .brand span { display: none; }
  .bar { gap: 8px 10px; }
  .status-zone { order: -1; flex-basis: 100%; justify-content: space-between; }
  .clock { min-width: 0; }
  .bar .toggle:not(.icon) { padding: 6px 9px; }
  .stage.pip .video-pane { min-width: 120px; width: 40%; }
}

/* ---------------------------------------------------------------- overlays */
.drop-overlay {
  position: fixed; inset: 0; background: rgba(15,17,19,.85); z-index: 20; display: flex;
  align-items: center; justify-content: center; font-size: 22px; border: 3px dashed var(--on-line);
}
.toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%); z-index: 30;
  background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 18px; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: calc(100vw - 32px);
}

/* practice-screen tools in the header (only while practising) */
.top-tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }
body:not(.working) .top-tools { display: none; }
.turn-msg small { margin-left: 0; }
