/* Stems tool chrome — shared parchment tokens from ../../css/sangeet-theme.css.
   Pitch-feedback greens/magentas stay intentional (colorblind-safe). */
.wrap > main.stems-app-page {
  max-width: min(940px, 100%);
  margin: 0 auto;
  padding: 12px 16px 80px;
}

:root {
  --panel2: #f3e6cf;
  --good: #22d17c;
  --good2: #0ea862;
  --bad: #ff2d9b;
  --warn: #b5451d;
  --accent: var(--terra);
  --accent2: var(--terra-soft);
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pt-topnav {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.pt-topnav a { color: var(--terra); text-decoration: none; font-weight: 600; }
.pt-topnav a:hover { color: var(--terra-soft); }
header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.title h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
}
.title .sub { color: var(--muted); font-size: 13px; }
#scoreboard { display: flex; gap: 8px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 12px;
  min-width: 80px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat .num { display: block; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
#onPitch { color: var(--good2); }

#library { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
#library .grow { min-width: 220px; }
#library .grow2 { flex: 1; min-width: 260px; }
#library input[type=text],
#libraryAdd input[type=text] {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 14px;
  width: 100%;
}
#library select { width: 100%; }
#libraryAdd {
  display: block;
}
#libraryAdd .library-add-body {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}
#libraryAdd .sep-explain { flex: 1 1 100%; align-self: stretch; }
#libraryAdd summary,
.save-note summary {
  cursor: pointer;
  font-weight: 650;
  color: var(--ink);
}
#libraryAdd summary:hover,
.save-note summary:hover { color: var(--terra); }
#libraryAdd.hidden,
#delBtn.hidden,
#cleanup.hidden,
#liveLibraryNote.hidden,
#song-save-disclaimer.hidden { display: none; }
#libraryAdd .grow { min-width: 220px; }
#libraryAdd .grow2 { flex: 1; min-width: 260px; }
#addBtn {
  background: var(--terra);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  height: 38px;
  padding: 0 16px;
  cursor: pointer;
}
#addBtn:hover { background: var(--terra-soft); }
.opt { color: var(--muted); font-weight: 400; font-size: 10px; }
.jobstatus { color: var(--warn); font-size: 13px; min-height: 18px; align-self: center; }
.jobstatus.ok { color: var(--good2); }
.jobstatus.err { color: var(--bad); }
.job-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 2px 0 6px;
}
.job-progress.hidden { display: none; }
.job-progress-track {
  flex: 1;
  height: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.job-progress-fill {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--terra), var(--terra-soft));
  border-radius: inherit;
  transition: width 0.55s ease;
}
.job-progress.run .job-progress-fill {
  background-size: 140% 100%;
  animation: job-progress-sheen 1.6s linear infinite;
}
.job-progress.ok .job-progress-fill { background: var(--good2); animation: none; }
.job-progress.err .job-progress-fill { background: var(--bad); animation: none; }
.job-progress-pct {
  min-width: 3.2em;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
@keyframes job-progress-sheen {
  0% { filter: brightness(1); }
  50% { filter: brightness(1.18); }
  100% { filter: brightness(1); }
}

/* Pitch stage stays dark for contrast against the highway */
#stage {
  position: relative;
  background: linear-gradient(180deg, #1e463b, #122820);
  border: 1px solid var(--leaf-deep);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
#hud { display: block; width: 100%; height: 420px; }
#overlay { position: absolute; top: 12px; right: 16px; display: flex; gap: 10px; pointer-events: none; }
#bignote, #yournote {
  background: rgba(30, 70, 59, 0.82);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(240, 217, 168, 0.25);
  border-radius: 14px;
  padding: 8px 14px;
  text-align: center;
  min-width: 78px;
  color: var(--mist);
}
#bignote span, #yournote span { display: block; font-size: 24px; font-weight: 800; line-height: 1.1; }
#bignote em, #yournote em { display: block; font-style: normal; font-size: 14px; font-weight: 700; line-height: 1.2; }
#bignote small, #yournote small { color: var(--sand); font-size: 10px; text-transform: uppercase; letter-spacing: .6px; }
#targetNote { color: var(--glow); }
#targetSa { color: #9fc0ff; }
#userNote { color: var(--good); }
#userSa { color: #7fe6b4; }

#countdown {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 120px; font-weight: 800; color: #fff;
  text-shadow: 0 8px 40px rgba(47, 107, 90, 0.6);
  background: rgba(18, 40, 32, 0.35);
}
#micWarn {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(181, 69, 29, 0.14);
  border: 1px solid var(--terra);
  color: var(--terra);
  padding: 6px 12px; border-radius: 10px; font-size: 13px;
}
.hidden { display: none !important; }

#seekrow { display: flex; align-items: center; gap: 12px; }
#seekrow span { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; min-width: 38px; text-align: center; }
#seek { flex: 1; accent-color: var(--terra); height: 6px; cursor: pointer; }

#lyrics,
#stemLyrics {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 14px;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  text-align: center;
}
.lyr { transition: .2s; }
.lyr.prev { color: var(--muted); font-size: 14px; opacity: .6; }
.lyr.cur { color: var(--ink); font-size: 24px; font-weight: 700; line-height: 1.25; }
.lyr.cur .w { opacity: .45; transition: .12s; }
.lyr.cur .w.on { opacity: 1; color: var(--terra); }
.lyr.next { color: var(--muted); font-size: 15px; opacity: .8; }
#lyrics.empty,
#stemLyrics.empty { display: none; }

#results {
  position: fixed; inset: 0;
  background: rgba(61, 43, 31, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 24px;
}
.results-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px 26px;
  width: min(760px, 96%);
  max-height: 96%;
  overflow: auto;
  box-shadow: var(--shadow);
}
.res-close { position: absolute; top: 12px; right: 12px; background: transparent; border: none; color: var(--muted); font-size: 18px; padding: 4px 8px; cursor: pointer; }
.grade {
  font-size: 64px; font-weight: 900; text-align: center; line-height: 1;
  background: linear-gradient(90deg, var(--good2), var(--terra));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.results-card h2 { text-align: center; margin: 6px 0 14px; font-weight: 700; font-family: var(--font-display); }
.res-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.rs { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.rs span { display: block; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rs small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
#resCanvas {
  display: block; width: 100%; height: 160px;
  background: #122820;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 14px;
}
.res-phrases h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.res-phrases ul { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.res-phrases li {
  display: flex; justify-content: space-between; gap: 12px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font-size: 14px;
}
.res-phrases li .pct { font-weight: 800; font-variant-numeric: tabular-nums; }
.res-phrases li .lo { color: var(--bad); }
.res-phrases li .mid { color: var(--warn); }
.res-actions { display: flex; gap: 10px; justify-content: center; }

#pt-transport { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.speed-ctl { min-width: 140px; padding: 4px 10px; }
.speed-ctl input[type=range] { width: 110px; }
#settings { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
button {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: .15s;
  font-family: var(--font-sans);
}
button:hover { border-color: var(--terra); transform: translateY(-1px); }
button.primary { background: var(--terra); color: #fff; border-color: var(--terra); font-weight: 700; }
button.primary:hover { background: var(--terra-soft); }
button.live { background: var(--green); color: #fff; border-color: var(--green); }
.ctl {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px 12px;
}
.ctl select, .ctl input[type=range] { accent-color: var(--terra); }
.ctl select {
  background: var(--panel2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 4px;
}
.ctl span { color: var(--ink); font-weight: 700; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.rec-toggle {
  display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 12px; cursor: pointer;
}
.rec-toggle input { accent-color: var(--terra); width: 16px; height: 16px; cursor: pointer; }
.rec-toggle .opt { color: var(--muted); font-size: 11px; }
#recbar {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 14px;
}
#recbar .rec-label { color: var(--ink); font-weight: 700; font-size: 13px; white-space: nowrap; }
#recbar audio { flex: 1; height: 34px; }
#recbar a { color: var(--terra); text-decoration: none; font-size: 13px; white-space: nowrap; }
#recbar a:hover { text-decoration: underline; }
.cleanup-body { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-top: 12px; }
.cleanup-body .ctl { min-width: 170px; }
.cleanup-body .ctl small { color: var(--muted); font-size: 10px; font-weight: 400; }
.cleanup-actions { display: flex; align-items: center; gap: 10px; }
#delBtn:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); }
#delBtn:disabled { opacity: .4; cursor: not-allowed; }

#tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--line); padding-bottom: 2px; }
#tabs button {
  background: transparent; border: 1px solid transparent; border-bottom: none;
  border-radius: 12px 12px 0 0; padding: 10px 18px; font-size: 15px; font-weight: 600;
  color: var(--muted); cursor: pointer;
}
#tabs button:hover { color: var(--ink); transform: none; }
#tabs button.active { background: var(--panel); border-color: var(--line); color: var(--ink); }
.view { display: flex; flex-direction: column; gap: 10px; }
#settingsWrap,
#cleanup,
#sargamWrap,
#stemSargamWrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 14px;
}
#settingsWrap summary,
#cleanup summary,
#sargamWrap summary,
#stemSargamWrap summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  list-style: none;
}
#settingsWrap summary::-webkit-details-marker,
#cleanup summary::-webkit-details-marker,
#sargamWrap summary::-webkit-details-marker,
#stemSargamWrap summary::-webkit-details-marker { display: none; }
.sargam-sheet { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; max-height: 240px; overflow: auto; }
.sargam-row {
  display: block; width: 100%; text-align: left;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; cursor: pointer;
}
.sargam-row:hover { border-color: var(--terra); }
.sargam-row.on { border-color: var(--terra); background: var(--panel); }
.sargam-lyric { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.sargam-notes { display: block; font-size: 18px; font-weight: 700; letter-spacing: 0.06em; color: var(--ink); line-height: 1.35; }
#settingsWrap[open] #settings { margin-top: 10px; }
#settingsWrap #rangeHint { margin: 8px 0 0; }
.view.hidden { display: none; }

#stemActions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.sep-explain {
  flex: 1 1 100%;
  max-width: 72ch;
  margin: 0;
  padding: 4px 0 0;
}
.sep-explain summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}
.sep-explain .hint { margin: 6px 0 0; }
.stem-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.stem-tag {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; color: var(--ink);
}
#stemTransport {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
#stemSeek { flex: 1; min-width: 140px; accent-color: var(--terra); height: 6px; cursor: pointer; }
#stemMixer {
  display: grid;
  grid-template-columns: minmax(148px, 188px) 1fr;
  grid-template-rows: 1fr;
  height: min(56vh, 560px);
  min-height: 320px;
  background: linear-gradient(180deg, #1e463b, #122820);
  border: 1px solid var(--leaf-deep);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
#stemLaneChrome {
  display: grid;
  grid-template-rows: repeat(var(--stem-lanes, 4), 1fr);
  height: 100%;
  min-height: 0;
}
.stem-lane-side {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-content: center;
  column-gap: 6px;
  row-gap: 1px;
  padding: 2px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  color: #f3efe4;
}
.stem-lane-side:last-child { border-bottom: none; }
.stem-lane-side.muted { opacity: 0.55; }
.stem-lane-side.missing { opacity: 0.4; }
.stem-lane-side strong {
  font-size: 13px; letter-spacing: 0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stem-lane-guess {
  grid-column: 1;
  font-size: 10px; color: rgba(243,239,228,0.7);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stem-mute {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 8px;
  height: 26px;
  padding: 0 8px;
  font-weight: 700;
}
.stem-mute.off { background: transparent; color: rgba(243,239,228,0.8); }
.stem-mute:disabled { opacity: 0.45; cursor: default; }
#stemHwy { width: 100%; height: 100%; min-height: 0; display: block; }

html:has(#app.stems-mode),
body:has(#app.stems-mode) {
  height: 100%;
  overflow: hidden;
}
#app.stems-mode #scoreboard,
#app.stems-mode #songHelp,
#app.stems-mode header .sub { display: none; }
#app.stems-mode {
  height: 100dvh;
  max-height: 100dvh;
  padding-top: 8px;
  padding-bottom: 8px;
  box-sizing: border-box;
  overflow: hidden;
  gap: 8px;
}
#app.stems-mode #viewStems {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  gap: 8px;
}
#app.stems-mode #viewStems > *:not(#stemMixer) { flex-shrink: 0; }
#app.stems-mode #stemMixer {
  flex: 1 1 0;
  height: 0;
  min-height: 0;
}
#app.stems-mode #stemDisclaimer {
  margin: 0;
  font-size: 11px;
  line-height: 1.3;
}
#app.stems-mode #stemLyrics {
  min-height: 0;
  padding: 4px 12px;
}
#app.stems-mode #stemLyrics .lyr.prev,
#app.stems-mode #stemLyrics .lyr.next { display: none; }
#app.stems-mode #stemLyrics .lyr.cur { font-size: 18px; }
#app.stems-mode #stemTransport { gap: 8px; }
#app.stems-mode .stem-tag { padding: 4px 10px; font-size: 12px; }

.save-note {
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--ochre);
  background: var(--panel);
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.4;
  color: #5a4a34;
}
.save-note[open] { background: #fbf1da; }
.save-note code {
  font-size: 0.9em;
  color: var(--ink);
}

@media (max-width: 720px) {
  header { flex-direction: column; align-items: flex-start; }
  #hud { height: 360px; }
  .res-stats { grid-template-columns: repeat(2, 1fr); }
}
