:root {
  --bg: #0e1116;
  --panel: #171b22;
  --panel-2: #1f242d;
  --line: #2a3038;
  --text: #eef2f7;
  --muted: #8a93a2;
  --accent: #4cc2ff;
  --accent-dim: #2b6f92;
  --good: #37d67a;
  --warn: #f2c14e;
  --nut: #e7ecf2;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
}

.brand {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.pill {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  transition: color .2s, border-color .2s, background .2s;
}
.pill--idle    { color: var(--muted); }
.pill--listen  { color: var(--warn);  border-color: var(--warn);  background: rgba(242,193,78,.08); }
.pill--active  { color: var(--good);  border-color: var(--good);  background: rgba(55,214,122,.10); }

.confidence__bar--level {
  background: var(--good);
  transition: width .06s linear;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 6px 18px 18px;
}

.chord-name {
  font-size: clamp(84px, 32vw, 168px);
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-top: 4px;
  min-height: 0.9em;
  transition: opacity .12s;
}
.chord-name .accidental { font-size: 0.5em; vertical-align: 0.42em; color: var(--muted); }
.chord-name .quality    { color: var(--accent); }

.chord-numeral {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  margin-top: 4px;
}

.chord-sub {
  font-size: 14px;
  color: var(--muted);
  min-height: 18px;
  margin-top: 6px;
}

.diagram {
  width: min(58vw, 200px);
  height: auto;
  margin: 4px 0;
}

.confidence {
  width: min(100%, 340px);
  margin-top: 2px;
}
.confidence__label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.confidence__track {
  height: 8px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
}
.confidence__bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 999px;
  transition: width .12s linear;
}

.progression {
  width: min(100%, 340px);
  margin-top: 10px;
}
.progression__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.progression__label {
  font-size: 12px;
  color: var(--muted);
}
.progression__count { color: var(--text); font-weight: 700; }
.progression__actions { display: flex; gap: 12px; }

.linkbtn {
  appearance: none;
  border: none;
  background: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.linkbtn:active { opacity: .6; }
.linkbtn.is-active { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }

.key-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.key-row__label { font-size: 12px; color: var(--muted); }
.key-select {
  appearance: none;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 600;
}
.key-row__detected { font-size: 12px; color: var(--muted); }

.progression__list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 40px;
  align-content: flex-start;
  max-height: 132px;
  overflow-y: auto;
  scrollbar-width: none;
}
.progression__list::-webkit-scrollbar { display: none; }
.progression__empty { font-size: 13px; color: var(--muted); }
.progression__chip {
  flex: 0 0 auto;
  padding: 7px 11px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 15px;
  animation: pop .18s ease-out;
}
.progression__chip.is-current {
  border-color: var(--accent);
  color: var(--accent);
}
@keyframes pop {
  from { transform: scale(.8); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}

.song-input {
  width: min(100%, 340px);
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.song-input input {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 11px 12px;
  font-size: 14px;
}
.actionbtn--sm { flex: 0 0 auto; padding: 11px 16px; }

.lookup {
  width: min(100%, 340px);
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.actionbtn {
  flex: 1;
  text-align: center;
  text-decoration: none;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  padding: 11px 8px;
  border-radius: 12px;
  cursor: pointer;
}
.actionbtn:active { background: var(--panel-2); }
.actionbtn[hidden] { display: none; }

.song-result {
  width: min(100%, 360px);
  margin: 4px 0 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--accent-dim);
  font-size: 14px;
}
.song-result__title { font-weight: 700; font-size: 16px; }
.song-result__artist { color: var(--muted); }
.song-result__cta {
  display: block;
  margin-top: 10px;
  text-align: center;
  text-decoration: none;
  background: var(--accent);
  color: #06222f;
  font-weight: 700;
  font-size: 15px;
  padding: 12px;
  border-radius: 12px;
}
.song-result__cta:active { opacity: .9; }
.song-result__links { margin-top: 8px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; }
.song-result__links a { color: var(--accent); font-weight: 600; text-decoration: none; }
.song-result__lk { font-size: 12px; color: var(--muted); margin-right: 2px; }
.song-result__msg { color: var(--muted); }

.audd-setup {
  width: min(100%, 340px);
  margin-top: 10px;
}
.audd-setup__label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.audd-setup__row { display: flex; gap: 8px; }
.audd-setup__row input {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
}
.audd-setup__hint { font-size: 11px; color: var(--muted); margin: 6px 0 0; }
.audd-setup__hint a { color: var(--accent); }

.controls {
  position: sticky;
  bottom: 0;
  padding: 12px 18px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.source-hint {
  width: min(100%, 340px);
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
  text-align: center;
}

.mode-switch {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}
.mode-switch button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.mode-switch button.is-active {
  background: var(--panel-2);
  color: var(--text);
}

.btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 16px 0;
  width: min(100%, 340px);
  font-size: 18px;
  font-weight: 700;
  color: #06222f;
  background: var(--accent);
  cursor: pointer;
  transition: transform .08s, background .2s, color .2s;
}
.btn:active { transform: scale(.98); }
.btn--stop { background: #ff5d6c; color: #2a0308; }

.error {
  margin: 0;
  color: #ff8a94;
  font-size: 13px;
  text-align: center;
  max-width: 340px;
}

/* Diagram primitives (set as classes so JS just adds elements) */
.diagram .fret   { stroke: var(--line); stroke-width: 2; }
.diagram .string { stroke: var(--line); stroke-width: 2; }
.diagram .nut    { stroke: var(--nut);  stroke-width: 6; stroke-linecap: round; }
.diagram .dot    { fill: var(--accent); }
.diagram .open   { fill: none; stroke: var(--muted); stroke-width: 2.5; }
.diagram .mute   { stroke: var(--muted); stroke-width: 2.5; stroke-linecap: round; }
.diagram .label  { fill: var(--muted); font-size: 13px; font-weight: 600; text-anchor: middle; }
.diagram .diagram-name { fill: var(--text); font-size: 22px; font-weight: 800; text-anchor: middle; }
