:root {
  --bg: #faf7f2;
  --bg-alt: #ffffff;
  --text: #2a2118;
  --text-muted: #6b5d4f;
  --accent: #c9722a;
  --accent-dark: #a35a1e;
  --border: #e6ddd0;
  --fret-nut: #3a2f24;
  --string-line: #9c8c76;
  --fret-line: #cbbfab;
  --good: #3a8a4a;
  --bad: #c0392b;
  --info: #3a6fc4;
  --shadow: 0 2px 10px rgba(42, 33, 24, 0.08);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1512;
    --bg-alt: #241d18;
    --text: #f3ece1;
    --text-muted: #b8a98f;
    --accent: #e08a3e;
    --accent-dark: #f0a35c;
    --border: #3a2f24;
    --fret-nut: #f3ece1;
    --string-line: #8a7a63;
    --fret-line: #4a3f30;
    --good: #6fcf7f;
    --bad: #e77468;
    --info: #7aa2f0;
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  padding: 0 16px;
  padding-block: 0;
}

h1, h2, .brand-name, .tuner-note, .metro-bpm-display, .lib-label {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
}

/* ---------- Header ---------- */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 4px 12px;
  max-width: 720px;
  margin: 0 auto;
  flex-wrap: wrap;
  gap: 10px;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { font-size: 1.4rem; color: var(--accent); }
.brand-name { font-weight: 700; font-size: 1.25rem; }
.brand-tld { color: var(--text-muted); font-weight: 500; }

.support-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  border: 1.5px solid var(--accent);
  padding: 6px 14px;
  border-radius: 999px;
  transition: background 0.15s, color 0.15s;
}
.support-link:hover { background: var(--accent); color: var(--bg-alt); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  max-width: 720px;
  margin: 0 auto;
  padding: 6px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tab-btn:hover { background: var(--border); }
.tab-btn.active { background: var(--accent); color: #fff; }

/* ---------- Main / panels ---------- */
main {
  max-width: 720px;
  margin: 0 auto;
  padding-block: 24px 40px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.section-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 8px;
  text-align: center;
}

.hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 40ch;
  margin: 0;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  font-family: inherit;
  font-weight: 700;
  font-size: 1rem;
  padding: 14px 32px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary.active { background: var(--bad); }

.btn-secondary {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 24px;
  border-radius: 999px;
  cursor: pointer;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-round {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
}
.btn-round:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Tuner ---------- */
.tuner-status { color: var(--text-muted); font-size: 0.9rem; min-height: 1.2em; }

.tuner-display { display: flex; flex-direction: column; align-items: center; gap: 4px; }

.tuner-needle-wrap {
  position: relative;
  width: 220px;
  height: 100px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.tuner-scale {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0 6px;
}
.tuner-needle {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 3px;
  height: 88px;
  background: var(--accent);
  transform-origin: bottom center;
  border-radius: 3px;
  transition: transform 0.1s ease-out, background 0.15s;
}
.tuner-needle.in-tune { background: var(--good); }
.tuner-center-line {
  position: absolute;
  bottom: 0; left: 50%;
  width: 1px; height: 90px;
  background: var(--border);
  transform: translateX(-50%);
  z-index: -1;
}

.tuner-note { font-size: 3.2rem; font-weight: 700; line-height: 1; }
.tuner-sub { display: flex; gap: 14px; color: var(--text-muted); font-size: 0.95rem; min-height: 1.3em; }

.string-refs { width: 100%; }
.string-buttons { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.string-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}
.string-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Metronome ---------- */
.metro-beats { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; max-width: 420px; }
.beat-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.08s, transform 0.08s;
}
.beat-dot.active { background: var(--accent); transform: scale(1.3); }

.metro-bpm-row { display: flex; align-items: center; gap: 20px; }
.metro-bpm-display { display: flex; flex-direction: column; align-items: center; min-width: 90px; }
#metro-bpm { font-size: 2.6rem; font-weight: 700; line-height: 1; }
.bpm-label { font-size: 0.75rem; color: var(--text-muted); letter-spacing: 0.08em; }

.metro-slider { width: 100%; max-width: 320px; accent-color: var(--accent); }
.metro-controls { display: flex; gap: 12px; }
.metro-timesig-row { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--text-muted); }
.metro-timesig-row select,
.metro-timesig-row input {
  font-family: inherit;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
}
.metro-timesig-row input.ts-beats-input { width: 56px; text-align: center; }
.metro-timesig-slash { font-weight: 700; color: var(--text-muted); }

.metro-timesig-presets { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.metro-preset-btn {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--bg-alt);
  color: var(--text-muted);
  cursor: pointer;
}
.metro-preset-btn:hover { border-color: var(--accent); color: var(--accent); }
.metro-preset-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Chord/Scale Library ---------- */
.lib-mode-toggle { display: flex; gap: 6px; background: var(--bg); border-radius: 999px; padding: 4px; flex-wrap: wrap; justify-content: center; }
.toggle-btn {
  background: transparent;
  border: none;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 8px 20px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-muted);
}
.toggle-btn.active { background: var(--accent); color: #fff; }

.lib-selectors { display: flex; gap: 10px; }
.lib-selectors select {
  font-family: inherit;
  font-size: 1rem;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
}

.lib-label { font-size: 1.4rem; font-weight: 700; }
.lib-diagram { width: 100%; overflow-x: auto; display: flex; justify-content: center; }

.fretboard-svg { width: 100%; max-width: 420px; height: auto; }
.scale-svg { max-width: 100%; }

.string-line { stroke: var(--string-line); stroke-width: 1.5; }
.fret-line { stroke: var(--fret-line); stroke-width: 1.5; }
.finger-dot { fill: var(--accent); }
.open-marker { fill: none; stroke: var(--text); stroke-width: 2; }
.mute-marker { fill: var(--text-muted); font-size: 16px; font-weight: 700; }
.barre-line { stroke: var(--accent); stroke-width: 14; stroke-linecap: round; opacity: 0.35; }
.fret-label { fill: var(--text-muted); font-size: 13px; }
.fret-dot-marker { fill: var(--fret-line); }
.scale-dot { fill: var(--bg-alt); stroke: var(--accent); stroke-width: 2; }
.scale-dot.root-dot { fill: var(--accent); }
.scale-note-text { font-size: 9px; fill: var(--text); font-weight: 600; pointer-events: none; }
.root-dot + .scale-note-text, .scale-dot.root-dot ~ text { fill: #fff; }

/* Chord Finder: multiple positions across the neck */
.chord-positions { display: flex; gap: 20px; flex-wrap: wrap; justify-content: center; width: 100%; }
.chord-position { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.chord-position-label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); margin: 0; }
.chord-position .fretboard-svg { width: 160px; }

/* Chord Builder */
.lib-builder-controls { align-items: center; justify-content: space-between; gap: 12px; width: 100%; flex-wrap: wrap; }
.builder-svg { cursor: pointer; }
.builder-hit { fill: transparent; stroke: var(--fret-line); stroke-width: 1.5; transition: fill 0.1s; }
.builder-hit:hover { fill: color-mix(in srgb, var(--accent) 25%, transparent); }
.builder-selected { fill: var(--accent) !important; stroke: var(--accent); }
.lib-builder-result { min-height: 2.4em; text-align: center; }
.chord-result-name { font-size: 1.6rem; font-weight: 700; margin: 4px 0; }
.chord-result-slash { color: var(--text-muted); font-weight: 500; }
.chord-result-alt { font-size: 0.8rem; color: var(--text-muted); margin: 0; }

/* ---------- Trainer ---------- */
.trainer-score { font-weight: 600; color: var(--text-muted); }
.trainer-question { text-align: center; font-size: 1.15rem; min-height: 2.4em; }
.trainer-pos { color: var(--accent); font-weight: 700; }

.trainer-choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 8px;
  width: 100%;
}
.choice-btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 12px 8px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  cursor: pointer;
}
.choice-btn:hover:not(:disabled) { border-color: var(--accent); }
.choice-btn:disabled { cursor: default; }
.choice-btn.correct { background: var(--good); border-color: var(--good); color: #fff; }
.choice-btn.wrong { background: var(--bad); border-color: var(--bad); color: #fff; }

.trainer-feedback { font-weight: 600; min-height: 1.4em; }
.trainer-feedback.good { color: var(--good); }
.trainer-feedback.bad { color: var(--bad); }

/* ---------- Tab Sync ---------- */
.tabsync-card { align-items: stretch; transition: max-width 0.2s ease; }

/* Once a file is loaded, break out of the site's 720px column so tab/sheet music is
   actually legible — centered independently of <main>'s max-width. */
.tabsync-card.has-file {
  width: min(92vw, 1200px);
  position: relative;
  left: 50%;
  transform: translateX(-50%);
}

.tabsync-layout { display: flex; flex-direction: column; gap: 20px; width: 100%; }
.tabsync-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.tabsync-sidebar { display: flex; flex-direction: column; gap: 18px; }

/* Once a file is loaded, give the canvas the majority of the width on screens wide
   enough for a side-by-side layout — the controls move into a sidebar instead of
   stacking above the canvas and eating vertical (and, on mobile, width) space. */
@media (min-width: 860px) {
  .has-file .tabsync-layout { flex-direction: row; align-items: flex-start; }
  .has-file .tabsync-main { flex: 1; }
  .has-file .tabsync-sidebar { width: 260px; flex-shrink: 0; }
}

.tabsync-toolbar { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
.file-label { cursor: pointer; }

.tabsync-page-nav { display: none; align-items: center; justify-content: center; gap: 14px; font-size: 0.9rem; color: var(--text-muted); }
.tabsync-page-nav button:disabled { opacity: 0.4; cursor: default; }

.tabsync-status { text-align: center; color: var(--text-muted); font-size: 0.9rem; min-height: 1.3em; margin: 0; }

.tabsync-canvas-wrap {
  width: 100%;
  max-height: 60vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.has-file .tabsync-canvas-wrap { max-height: 75vh; }
.tabsync-canvas-inner { position: relative; display: inline-block; }
#tabsync-canvas { display: block; }

.tabsync-overlay {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
}
.tabsync-overlay.ts-clickable { pointer-events: auto; cursor: crosshair; }

.ts-bar {
  position: absolute;
  border: 2px dashed var(--accent);
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  opacity: 0.85;
}
.ts-bar-current { border-color: var(--good); border-style: solid; opacity: 1; background: color-mix(in srgb, var(--good) 14%, transparent); }
.ts-bar-template { border-color: var(--info); border-style: solid; background: color-mix(in srgb, var(--info) 16%, transparent); }
.ts-bar-template .ts-bar-label { background: var(--info); }
.ts-bar-label {
  position: absolute;
  left: -2px; top: -20px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  padding: 1px 6px;
  border-radius: 4px;
  line-height: 1.4;
}
.ts-bar-current .ts-bar-label { background: var(--good); }

.ts-pending-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  pointer-events: none;
  animation: ts-pending-pulse 1s ease-in-out infinite;
}
.ts-pending-marker.ts-pending-fill { background: var(--good); box-shadow: 0 0 8px var(--good); }
@keyframes ts-pending-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.ts-playhead {
  position: absolute;
  width: 3px;
  background: var(--bad);
  box-shadow: 0 0 10px var(--bad);
  border-radius: 2px;
}

.tabsync-bpm-row { display: flex; align-items: center; gap: 14px; justify-content: center; flex-wrap: wrap; }
.tabsync-slider { max-width: 200px; }

.tabsync-controls { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }
.tabsync-mute-label { text-align: center; font-size: 0.85rem; color: var(--text-muted); display: flex; align-items: center; justify-content: center; gap: 6px; }

.tabsync-markers-panel { border-top: 1px solid var(--border); padding-top: 14px; }
.tabsync-markers-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.small-btn { padding: 6px 14px; font-size: 0.8rem; }

.tabsync-markers-list { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.ts-empty { color: var(--text-muted); font-size: 0.9rem; text-align: center; margin: 0; }
.ts-marker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.ts-marker-row > span:first-child { flex: 1; }
.ts-marker-row-template {
  border-color: var(--info);
  background: color-mix(in srgb, var(--info) 10%, transparent);
  color: var(--info);
  font-size: 0.82rem;
}
.ts-beats-input {
  width: 56px;
  font-family: inherit;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
}
.ts-beats-label { color: var(--text-muted); font-size: 0.8rem; }
.ts-del-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 6px;
}
.ts-del-btn:hover { color: var(--bad); }

/* ---------- Support ---------- */
.support-section {
  max-width: 560px;
  margin: 0 auto 40px;
  text-align: center;
  padding: 32px 20px;
  border-top: 1px solid var(--border);
}
.support-section h2 { margin-bottom: 8px; }
.support-section p { color: var(--text-muted); margin-bottom: 20px; }
.support-btn { display: inline-block; text-decoration: none; }

.site-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 20px 0 32px;
}

/* ---------- Circle of Fifths ---------- */
.cof-card { gap: 20px; }

.cof-explainer {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  background: var(--bg);
}
.cof-explainer summary { font-weight: 700; cursor: pointer; }
.cof-explainer ul { margin: 10px 0 2px; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; color: var(--text-muted); }
.cof-explainer li strong { color: var(--text); }

.cof-svg-wrap { width: 100%; max-width: 420px; margin: 0 auto; }
.cof-svg { width: 100%; height: auto; }
.cof-ring { fill: none; stroke: var(--border); stroke-width: 1; }
.cof-spoke { stroke: var(--border); stroke-width: 1; }

.cof-key { cursor: pointer; }
.cof-major-dot { fill: var(--bg-alt); stroke: var(--string-line); stroke-width: 1.5; transition: fill 0.15s, stroke 0.15s; }
.cof-minor-dot { fill: var(--bg); stroke: var(--string-line); stroke-width: 1.5; transition: fill 0.15s, stroke 0.15s; }
.cof-key:hover .cof-major-dot, .cof-key:hover .cof-minor-dot { stroke: var(--accent); }
.cof-key.cof-selected .cof-major-dot, .cof-key.cof-selected .cof-minor-dot { fill: var(--accent); stroke: var(--accent); }
.cof-major-text { font-size: 14px; font-weight: 700; fill: var(--text); pointer-events: none; }
.cof-minor-text { font-size: 10px; font-weight: 600; fill: var(--text-muted); pointer-events: none; }
.cof-key.cof-selected .cof-major-text, .cof-key.cof-selected .cof-minor-text { fill: #fff; }

.cof-info { width: 100%; text-align: center; }
.cof-title { margin: 0 0 4px; }
.cof-sig, .cof-relative { color: var(--text-muted); margin: 2px 0; font-size: 0.92rem; }

.cof-chords { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 8px 0 18px; }
.cof-chord-chip {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  min-width: 52px;
}
.cof-chord-roman { font-size: 0.7rem; color: var(--text-muted); }
.cof-chord-name { font-weight: 700; }

.cof-neighbors { display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; color: var(--text-muted); text-align: left; max-width: 480px; margin: 0 auto; }
.cof-neighbors strong { color: var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .tuner-note { font-size: 2.4rem; }
  #metro-bpm { font-size: 2.1rem; }
  .card { padding: 22px 16px; }
}
