/* hartBeat — Piano Chord Trainer */

:root {
  /* Core palette */
  --bg: #0f1117;
  --bg-raised: #1a1d27;
  --bg-hover: #242836;
  --surface: #2a2e3b;
  --border: #3a3f50;

  --text: #e8eaf0;
  --text-muted: #8b90a0;
  --text-dim: #5a5f70;

  --accent: #6c8cff;
  --accent-hover: #8ba3ff;
  --accent-glow: rgba(108, 140, 255, 0.15);

  --success: #4ecb71;
  --success-glow: rgba(78, 203, 113, 0.15);
  --error: #ff5c5c;
  --error-glow: rgba(255, 92, 92, 0.15);
  --warning: #ffb84d;

  /* Piano key colors */
  --key-white: #f0f0f0;
  --key-white-hover: #e0e0e0;
  --key-black: #2a2a2a;
  --key-black-hover: #3a3a3a;
  --key-highlight: var(--accent);
  --key-active: var(--success);
  --key-wrong: var(--error);
  --key-partial: var(--warning);

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Spacing */
  --gap: 1rem;
  --gap-sm: 0.5rem;
  --gap-lg: 1.5rem;
  --radius: 8px;
  --radius-sm: 4px;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────── */

header {
  display: flex;
  align-items: center;
  gap: var(--gap-lg);
  /* Tight vertical padding — header stays compact so the practice surface
   * gets the bulk of viewport height. The horizontal padding stays full
   * width so logo + tabs + status pills don't crowd together. */
  padding: 0.4rem var(--gap-lg);
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}

.logo {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  white-space: nowrap;
}

.logo .logo-hart {
  color: #ff6600;
}

.logo .accent {
  color: var(--accent);
}

/* Version pill in the header — small but visible. Sits at the right end
 * of the header (after the Settings tab) so it doesn't compete with the
 * branding or nav for attention. `margin-left: auto` claims all the
 * remaining flex space, pushing the pill plus the elements after it
 * (Mic + MIDI status) to the right. Hover reveals release notes. */
.app-version {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  letter-spacing: 0;
  align-self: center;
  margin-left: auto;
  /* Override the generic [data-tooltip] dotted underline — the pill shape
   * is already a clear hover affordance. */
  text-decoration: none;
}

.app-version[data-tooltip]:hover {
  background: rgba(108, 140, 255, 0.25);
}

#main-nav {
  display: flex;
  gap: var(--gap-sm);
}

.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.tab.active {
  color: var(--accent);
  background: var(--accent-glow);
}

.btn-mic {
  /* Right-cluster grouping is now anchored by .app-version which holds
   * the margin-left: auto. Mic + MIDI status follow it naturally on the
   * right of the header. */
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-mic:hover {
  border-color: var(--accent);
  color: var(--text);
}

.btn-mic.listening {
  background: var(--success-glow);
  border-color: var(--success);
  color: var(--success);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.midi-status {
  margin-left: 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.midi-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.3s ease;
}

.midi-status.connected .midi-dot {
  background: var(--success);
  box-shadow: 0 0 6px var(--success-glow);
}

.midi-status.connected .midi-label {
  color: var(--success);
}

/* ── Main Content ────────────────────────── */

main {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--gap-lg);
}

.tab-content {
  display: none;
}

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

/* ── Practice Mode Toggle ───────────────── */

.mode-toggle {
  display: flex;
  justify-content: center;
  gap: 0;
  margin-bottom: var(--gap);
}

.mode-btn {
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 1.5rem;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-btn:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}

.mode-btn:not(:first-child) {
  border-left: none;
}

.mode-btn:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.mode-btn.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Chord Card ──────────────────────────── */

.chord-card {
  text-align: center;
  padding: var(--gap-lg) var(--gap);
  margin-bottom: var(--gap);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chord-name {
  font-size: 1.1rem;
  color: var(--text-muted);
  margin-bottom: var(--gap-sm);
}

.chord-symbol {
  font-size: 3.5rem;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--text);
  line-height: 1.1;
}

.chord-category {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: var(--gap-sm);
}

/* ── Song Progress Bar ───────────────────── */

.song-progress {
  height: 6px;
  background: var(--surface);
  border-radius: 3px;
  margin-bottom: var(--gap);
  overflow: hidden;
}

.song-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}

/* ── Feedback Banner ─────────────────────── */

.feedback-banner {
  text-align: center;
  padding: 0.6rem var(--gap);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: var(--gap);
  transition: all 0.2s ease;
}

.feedback-banner.correct {
  background: var(--success-glow);
  color: var(--success);
  border: 1px solid var(--success);
}

.feedback-banner.wrong {
  background: var(--error-glow);
  color: var(--error);
  border: 1px solid var(--error);
}

.feedback-banner.partial {
  background: rgba(255, 184, 77, 0.1);
  color: var(--warning);
  border: 1px solid var(--warning);
}

.hidden {
  display: none !important;
}

/* ── Tooltip System ──────────────────────────
 *
 * Hover-popover help for metric labels. The dotted underline is the
 * affordance — readers understand it as "hover for help" without needing
 * a question-mark icon. Pointer-events:none on the popover keeps the
 * underlying click target hot and prevents the popover from holding
 * itself open. Width/wrap chosen so a 2-3-sentence tooltip stays
 * readable without spanning the whole viewport.
 */
[data-tooltip] {
  position: relative;
  cursor: help;
  text-decoration: underline dotted;
  text-decoration-color: var(--text-dim);
  text-underline-offset: 3px;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus::after {
  content: attr(data-tooltip);
  position: absolute;
  /* Default: render above the element. Elements near the top of the
   * viewport (e.g., the header version pill) carry .tooltip-below so the
   * popover flips downward and doesn't clip off-screen. */
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.5rem 0.75rem;
  background: var(--bg-raised);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: normal;
  font-style: normal;
  font-family: var(--font);
  line-height: 1.45;
  text-align: left;
  letter-spacing: normal;
  text-transform: none;
  /* pre-wrap honors \n in data-tooltip so multi-line content (release
   * notes, multi-paragraph explanations) renders without manual <br>. */
  white-space: pre-wrap;
  width: max-content;
  max-width: 320px;
  z-index: 100;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  text-decoration: none;
}

/* Render the tooltip below the element instead of above. Use on any
 * tooltip that sits near the top of the viewport. */
.tooltip-below[data-tooltip]:hover::after,
.tooltip-below[data-tooltip]:focus::after {
  bottom: auto;
  top: calc(100% + 6px);
}

/* ── Mic Monitor ────────────────────────── */

.mic-monitor {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem var(--gap);
  margin-bottom: var(--gap);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.mic-monitor-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap);
  /* tabular-nums forces every digit glyph to the same advance width, so
   * "0.0123" and "0.0987" occupy the same horizontal space — no shimmer
   * as values update at 60 Hz. */
  font-variant-numeric: tabular-nums;
}

.mic-monitor strong {
  color: var(--accent);
  /* Each value cell takes its worst-case width so the surrounding labels
   * (RMS / Freq / Note / Stable) stay locked in place when digit count
   * changes. Right-align so the units stick to a fixed column instead of
   * sliding. min-width chosen by the longest possible content per stat:
   *   RMS    "0.0000"           = 6 chars
   *   Freq   "4186.0 Hz"        = 9 chars
   *   Note   "F#5"              = 3 chars
   *   Stable "9999 frames"      = 11 chars
   */
  display: inline-block;
  text-align: right;
}

#mon-rms    { min-width: 6ch; }
#mon-freq   { min-width: 9ch; }
#mon-note   { min-width: 3ch; }
#mon-stable { min-width: 11ch; }

.mic-level-bar {
  flex: 1;
  min-width: 100px;
  height: 6px;
  background: var(--surface);
  border-radius: 3px;
  overflow: hidden;
}

.mic-level-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--success), var(--warning), var(--error));
  border-radius: 3px;
  transition: width 0.05s linear;
}

.mic-graph {
  width: 100%;
  /* Aspect ratio chosen via the golden ratio — width:height ≈ φ:1 makes
   * the graph proportional to the eye while giving each octave enough
   * vertical room to read individual note transitions. The container
   * scales fluidly; aspect-ratio keeps the shape consistent across
   * widths instead of locking pixels. */
  aspect-ratio: 1.618 / 1;
  height: auto;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.mic-transcript {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.75rem;
}

.mic-transcript-label {
  color: var(--text-muted);
  white-space: nowrap;
}

.mic-transcript-notes {
  color: var(--accent);
  word-break: break-all;
  font-weight: 600;
}

/* ── Piano Keyboard ──────────────────────── */

.keyboard-container {
  margin-bottom: var(--gap);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
  overflow: hidden;
}

#piano-keyboard,
#detail-piano-keyboard {
  width: 100%;
  height: auto;
  display: block;
}

/* SVG key styles */
.piano-key-white {
  fill: var(--key-white);
  stroke: #ccc;
  stroke-width: 0.5;
  cursor: pointer;
  transition: fill 0.1s ease;
}

.piano-key-white:hover {
  fill: var(--key-white-hover);
}

.piano-key-black {
  fill: var(--key-black);
  stroke: #111;
  stroke-width: 0.5;
  cursor: pointer;
  transition: fill 0.1s ease;
}

.piano-key-black:hover {
  fill: var(--key-black-hover);
}

.piano-key-white.highlighted,
.piano-key-black.highlighted {
  fill: var(--key-highlight);
}

.piano-key-white.active,
.piano-key-black.active {
  fill: var(--key-active);
}

.piano-key-white.wrong,
.piano-key-black.wrong {
  fill: var(--key-wrong);
}

.piano-key-white.partial,
.piano-key-black.partial {
  fill: var(--key-partial);
}

.key-label {
  font-family: var(--font);
  font-size: 7px;
  fill: var(--text-dim);
  pointer-events: none;
  text-anchor: middle;
}

.key-label-black {
  fill: #999;
}

.finger-number {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  fill: white;
  pointer-events: none;
  text-anchor: middle;
}

/* ── Practice Controls ───────────────────── */

.practice-controls {
  display: flex;
  justify-content: center;
  gap: var(--gap);
  margin-bottom: var(--gap);
}

.btn {
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.6rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-small {
  font-size: 0.8rem;
  padding: 0.3rem 0.8rem;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-danger {
  background: var(--error-glow);
  color: var(--error);
  border: 1px solid var(--error);
}

.btn-danger:hover {
  background: var(--error);
  color: white;
}

/* ── Session Stats ───────────────────────── */

.session-stats {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.session-stats span {
  font-weight: 700;
  font-family: var(--font-mono);
}

#stat-correct {
  color: var(--success);
}

#stat-wrong {
  color: var(--error);
}

#stat-streak {
  color: var(--accent);
}

/* ── Reference Tab ───────────────────────── */

.reference-filters {
  margin-bottom: var(--gap-lg);
}

.filter-group {
  margin-bottom: var(--gap);
}

.filter-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: var(--gap-sm);
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.pill {
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill:hover {
  border-color: var(--accent);
  color: var(--text);
}

.pill.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--gap-sm);
  margin-bottom: var(--gap-lg);
}

.ref-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ref-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.ref-card .ref-symbol {
  font-size: 1.2rem;
  font-weight: 700;
}

.ref-card .ref-name {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.reference-detail {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(700px, 95vw);
  background: var(--bg-raised);
  border: 1px solid var(--accent);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: var(--gap);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
  z-index: 100;
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateX(-50%) translateY(100%); }
  to { transform: translateX(-50%) translateY(0); }
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--gap);
}

.detail-header h2 {
  font-size: 1.3rem;
}

.detail-fingering {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: var(--gap-sm);
}

/* ── Settings Tab ────────────────────────── */

.settings-group {
  margin-bottom: var(--gap-lg);
  padding: var(--gap);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.settings-group h2 {
  font-size: 1rem;
  margin-bottom: var(--gap);
  color: var(--text);
}

.select {
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 0.5rem 0.8rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 100%;
  margin-bottom: var(--gap-sm);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: 0.4rem 0;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.chord-type-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-sm);
}

/* ── Custom Chord Set Picker (Practice tab) ── */

.custom-set-panel {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap-sm) var(--gap);
  margin-bottom: var(--gap);
}

.custom-set-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-sm);
  flex-wrap: wrap;
}

.custom-set-actions {
  display: flex;
  gap: var(--gap-sm);
}

.custom-set-summary {
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: var(--text);
}

.custom-set-summary.empty {
  color: var(--text-muted);
  font-style: italic;
}

.custom-set-picker {
  margin-top: var(--gap-sm);
  padding-top: var(--gap-sm);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.chip-row {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  align-items: center;
  gap: var(--gap-sm);
}

.chip-row-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chip-row-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.chord-chip {
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.1s ease;
  min-width: 2.6rem;
}

.chord-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.chord-chip.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Trend Delta (in-the-moment feedback) ─── */

.trend-delta {
  text-align: center;
  margin-top: -0.5rem;
  margin-bottom: var(--gap);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.trend-line {
  color: var(--text-muted);
}

.trend-line.trend-better {
  color: var(--success);
}

.trend-line.trend-worse {
  color: var(--text-muted);
}

.trend-line.trend-neutral {
  color: var(--text-muted);
}

/* ── Practice History (Reference detail) ──── */

.detail-history {
  margin-top: var(--gap);
  padding-top: var(--gap);
  border-top: 1px solid var(--border);
}

.detail-history-heading {
  font-size: 0.95rem;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.detail-history-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

.detail-history-stats {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.detail-history-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin: 0.4rem 0 0.2rem;
}

.sparkline {
  width: 100%;
  height: 60px;
  display: block;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.sparkline .spark-line {
  stroke: var(--accent);
}

.sparkline .spark-dot {
  fill: var(--success);
}

.cleanliness-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.clean-seg {
  width: 10px;
  height: 14px;
  border-radius: 2px;
}

.clean-seg.clean {
  background: var(--success);
}

.clean-seg.dirty {
  background: var(--text-dim);
}

/* ── Responsive ──────────────────────────── */

@media (max-width: 600px) {
  header {
    flex-wrap: wrap;
    gap: var(--gap-sm);
  }

  .logo {
    font-size: 1.2rem;
  }

  .midi-status {
    order: -1;
    margin-left: 0;
  }

  #main-nav {
    width: 100%;
    justify-content: center;
  }

  .chord-symbol {
    font-size: 2.5rem;
  }

  .reference-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  }
}
