:root {
  color-scheme: light dark;
  --bg: #fafaf7;
  --fg: #1d1d1f;
  --muted: #6b6b70;
  --card: #ffffff;
  --line: #d9d9de;
  --accent: #e8833a;
  --accent-fg: #1d1d1f;
  --link: #3b6fd8;
  --error: #c0392b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --fg: #ececf0;
    --muted: #9a9aa3;
    --card: #1e1e22;
    --line: #34343b;
    --link: #7fa2f0;
    --error: #ff7b6b;
  }
}

* { box-sizing: border-box; }

/* iPhone: quick repeated taps (▶ ▶ ▶) must not zoom the page. */
button, a, select, input, summary { touch-action: manipulation; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
}

/* Room for the notch at the top, and for the tab bar (plus the home bar) at the bottom. */
main {
  max-width: 1120px; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(84px + env(safe-area-inset-bottom));
}
.page-title, .config-page h1 { margin: 0 0 8px; font-size: 22px; }

.picker-label {
  margin: 12px 0 6px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-width: 44px;
  min-height: 40px;
  padding: 6px 12px;
  font-size: 15px;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

details.more { margin-top: 10px; }
details.more summary { padding: 10px 0; color: var(--link); cursor: pointer; }
.family h3 { margin: 10px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }

.chord-info {
  margin-top: 20px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.chord-name { margin: 0; font-size: 40px; }
.chord-fullname { margin: 2px 0 14px; color: var(--muted); }
.tones {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: auto auto;
  grid-auto-columns: minmax(44px, max-content);
  gap: 4px 10px;
  max-width: 100%;
  overflow-x: auto;
}
.tones .degree { font-size: 14px; text-align: center; color: var(--muted); }
.tones .tone { font-size: 22px; font-weight: 600; text-align: center; }
.tones .tone.root { color: var(--accent); }
.tones.with-bass { grid-template-rows: auto auto auto; }
.tones .bass-tag {
  min-height: 1em;
  font-size: 11px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.error { color: var(--error); }

/* ---- Phase 2: chips as links, chord layout, diagram, fretboard ---- */
a.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.error a { color: var(--link); }

/* `minmax(0, 1fr)` and `min-width: 0` let these columns be narrower than their widest
   content (the 480-wide fretboard), so on a phone only the fretboard scrolls sideways
   instead of the whole page growing wider than the screen. */
.chord-layout { margin-top: 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.chord-main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.chord-layout > *, .chord-main > * { min-width: 0; }
.diagram-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.diagram-row .chord-info { margin-top: 0; flex: 1 1 200px; }

.form-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.form-label { font-weight: 600; font-size: 15px; }
.form-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 40px;
  border-radius: 999px;
  color: var(--fg);
  text-decoration: none;
}
@media (hover: hover) { .form-arrow:not(.disabled):hover { background: var(--line); } }
.form-arrow.disabled { opacity: 0.3; }

.chord-diagram { width: 150px; height: auto; flex: 0 0 auto; }
.chord-diagram .string, .chord-diagram .fret { stroke: var(--muted); stroke-width: 1; }
.chord-diagram .nut { fill: var(--fg); }
.chord-diagram .fret-label { fill: var(--muted); font-size: 11px; }
.chord-diagram .marker { fill: var(--muted); font-size: 14px; }
.chord-diagram .open-marker { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.chord-diagram .barre { fill: var(--fg); }
.chord-diagram .dot { fill: var(--fg); }
.chord-diagram .dot.root { fill: var(--accent); }
.chord-diagram .dot-label { fill: var(--bg); font-size: 11px; font-weight: 700; }
.chord-diagram .dot-label.root { fill: var(--accent-fg); }
.chord-diagram .dot-label.long { font-size: 9px; }
.chord-diagram .open-label { fill: var(--fg); font-size: 10px; font-weight: 700; }

.fretboard-wrap { overflow-x: auto; }
.fretboard { display: block; width: 100%; min-width: 480px; height: auto; }
.fretboard .string { stroke: var(--muted); stroke-width: 1; }
.fretboard .fret { stroke: var(--line); stroke-width: 2; }
.fretboard .nut { fill: var(--fg); }
.fretboard .inlay { fill: var(--line); }
.fretboard .fret-number { fill: var(--muted); font-size: 9px; }
.fretboard .marker { fill: var(--muted); font-size: 12px; }
.fretboard .mark { fill: var(--fg); }
.fretboard .mark.open { fill: var(--card); stroke: var(--fg); stroke-width: 1.5; }
.fretboard .mark.root { fill: var(--accent); stroke: var(--accent); }
.fretboard .mark-label { fill: var(--bg); font-size: 8px; font-weight: 700; }
.fretboard .mark.open + .mark-label { fill: var(--fg); }
.fretboard .mark-label.root { fill: var(--accent-fg); }

@media (min-width: 800px) {
  .chord-layout { grid-template-columns: minmax(400px, 1fr) 1.3fr; align-items: start; }
}

/* Visually hidden but read by screen readers. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- Phase 3: play buttons ---- */
.play-buttons { display: flex; gap: 10px; }
.play {
  flex: 1;
  min-height: 48px;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-fg);
  background: var(--accent);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}
.play:disabled { opacity: 0.5; cursor: default; }
/* Strum (↓ ↑) takes two thirds of the row, Arpeggio (▶) one third. */
.play-groups { display: flex; gap: 16px; }
.play-group { display: flex; flex-direction: column; gap: 4px; }
.play-group.strum { flex: 2; }
.play-group.arpeggio { flex: 1; }
.play-group .play { font-size: 22px; }
.sound-status { min-height: 1.4em; margin: 0; font-size: 14px; color: var(--muted); }
.retry {
  margin-left: 6px;
  padding: 6px 12px;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.instrument-picker .chip { min-width: 72px; }
.dot-label-picker { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.picker-caption { color: var(--muted); font-size: 0.9rem; }
.dot-label-picker .chip { min-width: 64px; }

/* ---- Phase 4 ---- */
/* The browser keeps vertical scrolling and pinch-zoom; horizontal swipes change the form. */
.diagram-row { touch-action: pan-y pinch-zoom; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.hint.debug { font-family: ui-monospace, monospace; }

/* ---- Phase 5 ---- */
/* The US chord name shown next to the Brazilian one: "C7M  Cmaj7". */
.chip .hint { margin-left: 0.3em; font-size: 0.8em; color: var(--muted); }
.chip.on .hint { color: inherit; opacity: 0.8; }

/* Arpeggio: a ring around the note sounding now, with a short pop as it appears. */
.sounding {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
  animation: sounding-pop 0.2s ease-out;
}
@keyframes sounding-pop { from { transform: scale(1.6); opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .sounding { animation: none; } }

/* Language toggle: pushed to the right end of the top bar, a little smaller than chips. */
.lang-toggle { margin-left: auto; gap: 4px; }
.lang-toggle .chip { min-width: 40px; min-height: 36px; padding: 4px 10px; font-size: 13px; }

/* ---------- Songs ---------- */
.muted { color: var(--muted); font-size: 13px; }
.song-list { display: flex; flex-direction: column; gap: 12px; max-width: 640px; }
.song-list h1 { margin: 0; font-size: 22px; }
.songs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.song-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.song-link { flex: 1; display: flex; flex-direction: column; gap: 2px; color: var(--fg); text-decoration: none; min-width: 0; }
.song-link b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.confirm { display: flex; align-items: center; gap: 6px; }

.song-editor { display: flex; flex-direction: column; gap: 12px; max-width: 760px; padding-bottom: 40px; }
.song-editor .back { color: var(--link); text-decoration: none; }
.field { display: flex; flex-direction: column; gap: 4px; }
.input {
  font: inherit; color: var(--fg); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
select.input { align-self: flex-start; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper b { min-width: 72px; text-align: center; }
.chip:disabled { opacity: 0.4; cursor: default; }
.warning { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0 0; color: var(--error); }
.pattern { display: grid; gap: 3px; max-width: 420px; }
.slot {
  display: flex; flex-direction: column; align-items: center; padding: 4px 0;
  font-size: 18px; background: var(--card); border: 1px solid var(--line); border-radius: 8px;
}
.slot small { font-size: 10px; color: var(--muted); }
.slot.now { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.slot.now small { color: var(--accent-fg); }
.bars { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
@media (min-width: 700px) { .bars { grid-template-columns: repeat(4, 1fr); } }
.bar {
  position: relative; display: grid; padding: 26px 4px 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}
.bar.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.bar.add { display: flex; align-items: center; justify-content: center; padding: 12px; font: inherit; color: var(--link); cursor: pointer; }
/* The bar number: small to look at, but a thumb-sized strip (44×26) to tap. */
.bar-no {
  position: absolute; top: 0; left: 0; min-width: 44px; height: 26px; padding: 0 10px;
  display: flex; align-items: center;
  font: inherit; font-size: 12px; color: var(--muted); background: none; border: 0; cursor: pointer;
}
.beat {
  min-width: 0; padding: 8px 0; overflow: hidden; text-overflow: ellipsis;
  font: inherit; font-size: 15px; color: var(--muted); background: none; border: 0; border-radius: 6px; cursor: pointer;
}
.beat.has { color: var(--fg); font-weight: 700; }
/* Only with a mouse: on a phone a tapped cell would keep the hover look. */
@media (hover: hover) { .beat:hover { background: var(--bg); } }
.bar-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.bar-tools-head, .bar-tools-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; width: 100%; }
.bar-tools-head b { flex: 1; }
.chip.move { min-width: 44px; justify-content: center; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, 0.35); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-width: 760px; max-height: 80vh; margin: 0 auto; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 3px solid var(--accent); border-radius: 14px 14px 0 0;
  box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.25);
}
.sheet-title { font-weight: 700; }
.sheet-form { display: flex; align-items: center; gap: 12px; }
.sheet .chord-diagram { width: 96px; }
.sheet-chord { display: flex; flex-direction: column; gap: 2px; }
.sheet-symbol { font-size: 28px; }
.sheet .form-nav { display: flex; align-items: center; gap: 6px; }
button.form-arrow { font: inherit; font-size: 18px; color: var(--link); background: none; border: 0; padding: 4px 8px; cursor: pointer; }
button.form-arrow:disabled { color: var(--muted); opacity: 0.4; cursor: default; }
.sheet-actions { position: sticky; bottom: 0; display: flex; gap: 8px; padding-top: 6px; background: var(--card); }
.sheet-actions .play { flex: 1; }

/* Player page */
.play-along { display: flex; flex-direction: column; gap: 14px; max-width: 520px; }
.play-along .back { color: var(--link); text-decoration: none; }
.play-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.beats { display: grid; gap: 6px; }
.beats span {
  text-align: center; padding: 10px 0; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line);
  font-size: 22px; font-weight: 700; color: var(--muted);
}
.beats span.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.song-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
/* A link styled as a play button: centre its text like a real button. */
a.play { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
/* The editor's ▶ Tocar: a compact pill at the top right, not a full-width bar. */
.song-play { flex: 0 0 auto; min-height: 40px; padding: 0 18px; border-radius: 999px; font-size: 15px; }
.play-along .now-row { display: flex; align-items: center; justify-content: space-around; gap: 12px; min-height: 160px; }
.play-along .now { display: flex; flex-direction: column; gap: 4px; }
.play-along .big { font-size: 64px; font-weight: 800; line-height: 1; }
.play-along .now-row .chord-diagram { width: 140px; }
.play-along .next {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px dashed var(--line); border-radius: 12px; padding: 6px 12px;
}
.play-along .next-symbol { font-size: 28px; }
.play-along .next .chord-diagram { width: 70px; }
.play-row { display: flex; align-items: center; gap: 10px; }
.play-row .play { flex: 1; }
.play-row .instrument-picker { flex-wrap: nowrap; }

.sound-switches { display: flex; gap: 8px; }
.sound-switches .chip { flex: 1; min-height: 44px; font-size: 16px; }

/* Rhythm sheet: the slots are buttons here */
.rhythm-grid { max-width: none; }
button.slot { font: inherit; font-size: 22px; color: var(--fg); cursor: pointer; min-height: 52px; }
.edit-rhythm { align-self: flex-start; }

/* A bar with its own rhythm: a small tag at its top right */
.bar-tag {
  position: absolute; top: 6px; right: 6px; max-width: 60%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 0 5px; border-radius: 6px; font-size: 10px;
  background: #e0b04a; color: #1d1f24;
}
.bar-rhythm { display: flex; align-items: center; gap: 6px; }
.bar-rhythm .input { width: auto; }
.tempo-row { display: flex; align-items: center; gap: 10px; }
.tempo-row input[type="range"] { flex: 1; accent-color: var(--accent); min-height: 32px; }
.tempo-row .muted { min-width: 7.5em; text-align: right; font-variant-numeric: tabular-nums; }

/* Loop: the chip row and a one-row strip of bars that scrolls sideways */
.loop-row { display: flex; align-items: center; gap: 10px; }
.loop-strip { display: flex; gap: 4px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: thin; }
.loop-strip button {
  flex: 0 0 auto; min-width: 40px; min-height: 40px; font: inherit; font-size: 14px;
  color: var(--muted); background: var(--card); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.loop-strip button.in { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.loop-strip button.pending { border: 2px dashed var(--accent); color: var(--fg); }
.loop-strip button.now { outline: 2px solid var(--fg); outline-offset: 1px; }
.song-list-actions { display: flex; gap: 8px; align-items: center; }
.song-list-actions .play { flex: 1; }
.hidden-picker { display: none; }

/* Bottom tab bar */
/* Saving failed: a red bar just above the tab bar, on every page. */
.save-warning {
  position: fixed; left: 8px; right: 8px; z-index: 9; margin: 0;
  bottom: calc(68px + env(safe-area-inset-bottom));
  padding: 8px 12px; border-radius: 10px; font-size: 14px;
  background: var(--error); color: #fff;
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  display: flex; justify-content: space-around;
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.tab {
  flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--muted); text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tab-icon { display: flex; padding: 3px 18px; border-radius: 999px; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.on { color: var(--accent); font-weight: 600; }
.tab.on .tab-icon { background: color-mix(in srgb, var(--accent) 18%, transparent); }

/* Config screen */
.config-page { display: flex; flex-direction: column; gap: 12px; max-width: 640px; }
.config-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.app-version { margin-top: 24px; }
.offline-state { color: var(--muted); font-size: 14px; text-align: right; }
.offline-state.ok { color: var(--fg); font-weight: 600; }
