*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #252547;
  --border: #2a2a4a;
  --text: #e8e8f0;
  --text-dim: #7777a0;
  --accent: #ff4d6a;
  --accent-glow: #ff4d6a44;
  --green: #2ecc71;
  --yellow: #f1c40f;
  --red: #e74c3c;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

chord-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ── */
.app-header {
  background: var(--surface);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header h1 { font-size: 1.1rem; font-weight: 600; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.header-btn {
  padding: 6px 14px; border: 1px solid var(--border); background: transparent;
  color: var(--text-dim); border-radius: 6px; cursor: pointer; font-size: 0.8rem;
}
.header-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Tabs ── */
.tabs { display: flex; gap: 2px; background: var(--bg); padding: 3px; border-radius: var(--radius); }
.tab-btn {
  padding: 8px 22px; border: none; background: transparent; color: var(--text-dim);
  cursor: pointer; border-radius: 7px; font-size: 0.85rem; font-weight: 500; transition: all 0.15s;
}
.tab-btn.active { background: var(--accent); color: #fff; }
.tab-btn:hover:not(.active) { color: var(--text); }

/* ── Main content ── */
.main-content {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 32px 24px; gap: 20px; max-width: 800px; margin: 0 auto; width: 100%;
}
.mode-panel { display: none; flex-direction: column; align-items: center; gap: 18px; width: 100%; }
.mode-panel.active { display: flex; }

/* ── Hero chord card ── */
.hero-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 24px 32px 16px;
  text-align: center;
  min-width: 240px;
  max-width: 340px;
  transition: border-color 0.3s;
  overflow: hidden;
}
.hero-card.detected { border-color: var(--accent); box-shadow: 0 0 32px var(--accent-glow); }
.hero-chord-name {
  font-size: 3.5rem; font-weight: 800; color: var(--accent);
  line-height: 1.1; letter-spacing: -1px;
}
.hero-diagram-wrap {
  width: 170px; height: 200px; margin: 4px auto; overflow: hidden;
}
.hero-chord-diagram {
  display: block;
  transform: scale(1.55); transform-origin: top center;
  pointer-events: none; margin: 0 auto;
}
.hero-confidence-text { font-size: 0.8rem; color: var(--text-dim); margin-top: 4px; }
.hero-confidence-bar {
  width: 140px; height: 4px; background: var(--bg); border-radius: 2px;
  margin: 4px auto 0; overflow: hidden;
}
.hero-confidence-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.3s; }

/* Chord shift selector in hero card */
.chord-shift-row {
  margin-top: 10px; display: flex; gap: 6px; justify-content: center;
}
.chord-shift-btn {
  padding: 3px 10px; border: 1px solid var(--border); background: transparent;
  color: var(--text-dim); border-radius: 4px; cursor: pointer; font-size: 0.7rem;
}
.chord-shift-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chord-shift-btn:hover:not(.active) { border-color: var(--accent); color: var(--text); }

/* ── Prediction bar ── */
.prediction-bar {
  display: none; align-items: center; gap: 6px; font-size: 0.9rem;
  color: var(--text-dim); background: var(--surface); padding: 6px 14px;
  border-radius: var(--radius); border: 1px solid var(--border);
}
.prediction-bar.visible { display: flex; }
.prediction-bar .pred-label { color: var(--text-dim); }
.prediction-bar strong { color: var(--accent); font-size: 1.1rem; }
.prediction-bar chord-diagram { display: inline-block; width: 60px; height: 90px; overflow: hidden; }
.prediction-bar chord-diagram::part(svg) { transform: scale(0.6); transform-origin: top left; }

/* ── Signal meter (global) ── */
.signal-meter-wrap {
  width: 100%; max-width: 400px;
}
.signal-meter {
  width: 100%; height: 6px; background: var(--surface);
  border-radius: 3px; overflow: hidden;
}
.signal-meter-fill { height: 100%; background: var(--green); transition: width 0.08s; border-radius: 3px; min-width: 0%; }

/* ── Source buttons ── */
.source-row {
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; align-items: center;
}
.source-btn {
  padding: 10px 20px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: var(--radius); cursor: pointer; font-size: 0.9rem;
  transition: all 0.15s; white-space: nowrap;
}
.source-btn:hover { border-color: var(--accent); }
.source-btn.active-btn { background: var(--accent); border-color: var(--accent); color: #fff; }
.source-btn.stop-btn { background: var(--red); border-color: var(--red); color: #fff; }
.url-input {
  padding: 10px 14px; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); border-radius: var(--radius); width: 240px; font-size: 0.85rem;
}
.url-input:focus { outline: none; border-color: var(--accent); }
.url-input::placeholder { color: var(--text-dim); }

/* ── Drop zone ── */
.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px;
  text-align: center; color: var(--text-dim); cursor: pointer; transition: all 0.2s;
  width: 100%; max-width: 400px;
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--accent); color: var(--accent); }
.drop-zone input[type="file"] { display: none; }

/* ── Chord history strip ── */
.history-strip {
  width: 100%; overflow-x: auto; display: flex; gap: 6px; padding: 8px 0;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.history-item {
  flex-shrink: 0; text-align: center; padding: 4px 8px; background: var(--surface);
  border-radius: 6px; border: 1px solid var(--border); cursor: default;
  font-size: 0.75rem; color: var(--text-dim);
}
.history-item chord-diagram { transform: scale(0.55); transform-origin: top center; margin-top: 2px; }

/* ── Bar status ── */
.bar-status {
  text-align: center; padding: 20px; color: var(--text-dim);
}
.bar-status-text { font-size: 1rem; margin-bottom: 4px; }

/* ── Bar timeline ── */
.bar-timeline {
  display: flex; gap: 10px; overflow-x: auto; padding: 12px 0; width: 100%;
  scrollbar-width: thin;
}
.bar-block {
  flex-shrink: 0; text-align: center; padding: 10px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); cursor: pointer; transition: all 0.15s;
}
.bar-block:hover { border-color: var(--accent); }
.bar-block.current { border-color: var(--accent); background: var(--surface2); box-shadow: 0 0 12px var(--accent-glow); }
.bar-number { font-size: 0.7rem; color: var(--text-dim); margin-bottom: 4px; }
.bar-time { font-size: 0.65rem; color: var(--text-dim); margin-top: 4px; }

/* ── Playback bar ── */
.playback-bar {
  display: flex; align-items: center; gap: 12px; width: 100%; max-width: 600px;
  padding: 8px 0;
}
.playback-bar .source-btn { padding: 6px 16px; font-size: 0.85rem; }
.playback-progress-wrap {
  flex: 1; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; cursor: pointer;
}
.playback-progress {
  height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.1s linear;
}
.playback-time { font-size: 0.75rem; color: var(--text-dim); white-space: nowrap; min-width: 90px; text-align: right; }

/* ── Sheet view ── */
.sheet-view { width: 100%; max-width: 700px; }
.sheet-bar {
  display: flex; align-items: stretch; margin-bottom: 2px;
  border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
  background: var(--surface);
}
.sheet-bar-label {
  width: 32px; display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; color: var(--text-dim); background: var(--surface2);
  flex-shrink: 0;
}
.sheet-beats { display: flex; flex: 1; }
.sheet-beat {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 6px 2px; border-right: 1px solid var(--border);
  min-height: 44px; position: relative;
}
.sheet-beat:last-child { border-right: none; }
.sheet-beat-num { font-size: 0.55rem; color: var(--text-dim); position: absolute; top: 2px; right: 4px; }
.sheet-chord {
  font-size: 1rem; font-weight: 700; color: var(--accent);
}
.sheet-beat.playing {
  background: var(--accent); color: #fff;
  animation: beat-pulse 0.3s ease;
  box-shadow: 0 0 16px var(--accent-glow);
}
.sheet-beat.playing .sheet-beat-num { color: rgba(255,255,255,0.7); }
.sheet-beat.playing .sheet-chord { color: #fff; }
@keyframes beat-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* ── Tuner ── */
.tuner-display { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.tuner-note { font-size: 5rem; font-weight: 800; color: var(--accent); line-height: 1; }
.tuner-frequency { font-size: 1.3rem; color: var(--text-dim); }
.tuner-gauge {
  position: relative; width: 320px; height: 10px;
  background: linear-gradient(to right, var(--red) 0%, var(--yellow) 35%, var(--green) 50%, var(--yellow) 65%, var(--red) 100%);
  border-radius: 5px; margin: 20px 0;
}
.tuner-needle {
  position: absolute; top: -8px; width: 3px; height: 26px; background: #fff;
  border-radius: 2px; transform: translateX(-50%); transition: left 0.1s; box-shadow: 0 0 6px #fff8;
}
.tuner-cents { font-size: 1.1rem; }
.tuner-cents.in-tune { color: var(--green); }
.tuner-cents.sharp { color: var(--yellow); }
.tuner-cents.flat { color: var(--red); }
.tuner-string-select { display: flex; gap: 8px; }
.tuner-string-btn {
  padding: 8px 16px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: var(--radius); cursor: pointer; font-size: 0.85rem;
}
.tuner-string-btn.active { background: var(--accent); border-color: var(--accent); }

/* ── Tuning bar ── */
.tuning-bar {
  display: flex; gap: 24px; flex-wrap: wrap; align-items: center; justify-content: center;
  padding: 14px 20px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); width: 100%; max-width: 700px;
}
.setting-group { display: flex; align-items: center; gap: 6px; }
.setting-group label { font-size: 0.8rem; color: var(--text-dim); }
.setting-group select {
  padding: 6px 10px; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); border-radius: 5px; font-size: 0.8rem;
}

/* ── Status bar ── */
.status-bar {
  padding: 8px 24px; background: var(--surface); border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; font-size: 0.75rem;
  color: var(--text-dim);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.status-dot.connected { background: var(--green); }
.status-dot.disconnected { background: var(--red); }
.status-dot.busy { background: var(--yellow); }

/* ── Progress ── */
.progress-wrap { width: 160px; height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); transition: width 0.3s; }

/* ── Chord library modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: #000000aa; z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.modal-content {
  background: var(--surface); border-radius: 16px; padding: 24px; max-width: 750px;
  width: 95%; max-height: 85vh; overflow-y: auto; border: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.modal-content .chord-library {
  overflow-y: auto; flex: 1; min-height: 0;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 4px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; }
.modal-header h2 { font-size: 1.2rem; white-space: nowrap; }
.modal-tabs { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 6px; }
.modal-tab { padding: 5px 14px; border: none; background: transparent; color: var(--text-dim); cursor: pointer; border-radius: 4px; font-size: 0.8rem; }
.modal-tab.active { background: var(--accent); color: #fff; }
.modal-tab:hover:not(.active) { color: var(--text); }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 1.5rem; cursor: pointer; }
.modal-close:hover { color: var(--accent); }

.chord-library {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 6px; padding: 8px 0;
}

/* ── Toast notifications ── */
#toast-container {
  position: fixed; top: 16px; right: 16px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: var(--radius); font-size: 0.85rem;
  animation: toast-in 0.3s ease; max-width: 360px;
  box-shadow: 0 4px 16px #00000044;
}
.toast.error { border-color: var(--red); }
.toast.success { border-color: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }

/* ── Chroma bars ── */
.chroma-heatmap { display: flex; gap: 2px; width: 100%; max-width: 400px; height: 50px; align-items: flex-end; }
.chroma-bar { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; transition: height 0.2s; min-height: 2px; }
.chroma-label-row { display: flex; gap: 2px; width: 100%; max-width: 400px; }
.chroma-label { flex: 1; text-align: center; font-size: 0.55rem; color: var(--text-dim); }
.chroma-toggle { font-size: 0.7rem; color: var(--text-dim); cursor: pointer; background: none; border: none; }
.chroma-toggle:hover { color: var(--accent); }
