:root {
  --bg: #fbf3ec;
  --bg-2: #f3e7db;
  --card: #ffffff;
  --text: #2c2521;
  --muted: #8c7d72;
  --accent: #ef6b4a;
  --accent-press: #d8553a;
  --teal: #1f9e90;
  --line: #d8c9bd;
  --string: #c9b8aa;
  --nut: #6b5a4e;
  --beginner: #2f9e63;
  --beginner-bg: #e3f5ea;
  --intermediate: #c2762a;
  --intermediate-bg: #fbeed8;
  --advanced: #8b5cf6;
  --advanced-bg: #ede9fe;
  --shadow: 0 2px 12px rgba(90, 55, 30, .09);
  --shadow-lg: 0 8px 28px rgba(90, 55, 30, .14);
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181311;
    --bg-2: #211a16;
    --card: #251d19;
    --text: #f2e9e2;
    --muted: #a99a8e;
    --accent: #ff7a5c;
    --accent-press: #ff9077;
    --teal: #4fc4b6;
    --line: #4a3c33;
    --string: #5a4a3f;
    --nut: #cdb8a8;
    --beginner: #5fd396;
    --beginner-bg: #1c3327;
    --intermediate: #f0b461;
    --intermediate-bg: #352815;
    --advanced: #b794f6;
    --advanced-bg: #2a2140;
    --shadow: 0 2px 12px rgba(0, 0, 0, .35);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- App bar ---------- */
.app-bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 18px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.brand { font-weight: 800; font-size: 1.15rem; letter-spacing: .2px; display: flex; align-items: center; gap: 7px; }
.brand-mark { font-size: 1.3rem; }
.tuning {
  font-weight: 700; font-size: .72rem; letter-spacing: 2px; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  padding: 5px 10px; border-radius: 999px;
}

/* ---------- Layout ---------- */
#app { max-width: 560px; margin: 0 auto; padding: 18px 16px 110px; }
.view-title { font-size: 1.5rem; font-weight: 800; margin: 6px 0 4px; }
.view-sub { color: var(--muted); margin: 0 0 18px; line-height: 1.45; font-size: .95rem; }
.section-h { font-size: 1.05rem; font-weight: 800; margin: 26px 0 12px; }
.disclaimer { color: var(--muted); font-size: .8rem; line-height: 1.5; margin-top: 22px; text-align: center; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid color-mix(in srgb, var(--line) 45%, transparent);
}

/* ---------- Song list ---------- */
.song-list { display: flex; flex-direction: column; gap: 12px; }
.song-card {
  display: flex; align-items: center; gap: 12px; padding: 15px 16px;
  transition: transform .12s ease, box-shadow .12s ease;
}
.song-card:active { transform: scale(.985); box-shadow: var(--shadow-lg); }
.song-card-main { flex: 1; min-width: 0; }
.song-title { font-weight: 800; font-size: 1.06rem; line-height: 1.2; }
.song-artist { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-weight: 700; font-size: .72rem; letter-spacing: .3px;
  background: var(--bg-2); color: var(--text);
  padding: 4px 9px; border-radius: 8px;
}
.song-card-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.go { color: var(--muted); font-size: 1.6rem; line-height: 1; font-weight: 700; }

.badge {
  font-weight: 800; font-size: .68rem; letter-spacing: .4px; text-transform: uppercase;
  padding: 4px 9px; border-radius: 999px; white-space: nowrap;
}
.badge.beginner { color: var(--beginner); background: var(--beginner-bg); }
.badge.intermediate { color: var(--intermediate); background: var(--intermediate-bg); }
.badge.advanced { color: var(--advanced); background: var(--advanced-bg); }

/* ---------- Search & filter ---------- */
.search {
  width: 100%; padding: 13px 15px; font-size: 1rem; font-family: inherit;
  color: var(--text); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 13px; margin-bottom: 12px;
}
.search::placeholder { color: var(--muted); }
.filter-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip {
  flex: 0 0 auto; padding: 8px 15px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--card); color: var(--muted);
  font-weight: 700; font-size: .82rem; transition: all .12s ease;
}
.filter-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.result-count { color: var(--muted); font-size: .78rem; font-weight: 700; letter-spacing: .3px; margin-bottom: 12px; text-transform: uppercase; }
.empty { color: var(--muted); text-align: center; padding: 36px 12px; line-height: 1.5; }

/* ---------- Chord diagrams (SVG) ---------- */
.chord-diagram { width: 100%; height: auto; display: block; }
.chord-diagram text { font-family: inherit; }
.cd-name { fill: var(--text); font-weight: 800; font-size: 19px; }
.cd-fret { stroke: var(--line); stroke-width: 1.4; }
.cd-nut { stroke: var(--nut); stroke-width: 4.5; stroke-linecap: round; }
.cd-string { stroke: var(--string); stroke-width: 1.5; }
.cd-open { fill: none; stroke: var(--muted); stroke-width: 1.8; }
.cd-dot, .cd-barre { fill: var(--accent); }
.cd-finger { fill: #fff; font-size: 12px; font-weight: 800; }
.cd-label { fill: var(--muted); font-size: 11px; font-weight: 700; }

/* ---------- Chord library grid ---------- */
.chord-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.chord-card {
  padding: 12px 10px 8px; border: 1px solid color-mix(in srgb, var(--line) 45%, transparent);
  transition: transform .1s ease, box-shadow .1s ease;
}
.chord-card:active, .chord-card.tap { transform: scale(.95); box-shadow: var(--shadow-lg); }
.chord-card.tap { animation: tap .35s ease; }
@keyframes tap { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); } 100% { box-shadow: 0 0 0 14px transparent; } }
@media (min-width: 440px) { .chord-grid { grid-template-columns: repeat(4, 1fr); } }

/* ---------- Song detail ---------- */
.back { display: inline-block; color: var(--accent); font-weight: 700; margin-bottom: 10px; font-size: .95rem; }
.song-title-lg { font-size: 1.7rem; font-weight: 800; line-height: 1.1; margin: 2px 0 6px; }
.detail-meta { color: var(--muted); font-size: .9rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.song-note {
  background: var(--bg-2); border-radius: 14px; padding: 12px 14px; margin: 14px 0 0;
  font-size: .9rem; line-height: 1.5; border-left: 4px solid var(--accent);
}

/* ---------- Player ---------- */
.player { margin-top: 18px; }
.stage {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid color-mix(in srgb, var(--line) 45%, transparent);
  padding: 18px 16px 14px;
}
.stage-top { display: flex; gap: 16px; align-items: stretch; }
.cur { width: 46%; max-width: 220px; flex-shrink: 0; }
.cur-diagram { transition: transform .15s ease; }
.cur-diagram:active { transform: scale(.97); }
.cur-diagram.playing { animation: glow 1s ease-in-out infinite alternate; border-radius: 14px; }
@keyframes glow {
  from { filter: drop-shadow(0 0 0 transparent); }
  to { filter: drop-shadow(0 3px 10px color-mix(in srgb, var(--accent) 45%, transparent)); }
}
.cur-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.next { display: flex; flex-direction: column; gap: 1px; margin-bottom: 12px; }
.next-label { font-size: .7rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700; }
.next-name { font-size: 1.9rem; font-weight: 800; color: var(--teal); line-height: 1; }
.guide { display: flex; flex-direction: column; gap: 5px; }
.g-line { font-size: .82rem; line-height: 1.3; font-weight: 600; }
.g-open { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.hint { font-size: .72rem; color: var(--muted); margin-top: auto; padding-top: 10px; font-style: italic; }

.beat-dots { display: flex; gap: 9px; justify-content: center; margin: 16px 0 12px; }
.beat-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: color-mix(in srgb, var(--muted) 35%, transparent);
  transition: transform .08s ease, background .08s ease;
}
.beat-dot.accent { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent); }
.beat-dot.lit { background: var(--accent); transform: scale(1.45); }

.prog-strip {
  display: flex; gap: 8px; overflow-x: auto; padding: 6px 2px 4px;
  scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.prog-strip::-webkit-scrollbar { display: none; }
.prog-item {
  flex: 0 0 auto; scroll-snap-align: center;
  min-width: 46px; padding: 9px 12px; border-radius: 11px;
  border: 1.5px solid var(--line); background: transparent; color: var(--muted);
  font-weight: 800; font-size: .95rem; transition: all .12s ease;
}
.prog-item.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
  transform: scale(1.06); box-shadow: var(--shadow);
}

/* ---------- Controls ---------- */
.controls { margin-top: 16px; display: flex; flex-direction: column; gap: 14px; }
.transport { display: flex; align-items: center; justify-content: center; gap: 14px; }
.ctrl {
  width: 52px; height: 52px; border-radius: 50%; border: 1.5px solid var(--line);
  background: var(--card); color: var(--text); font-size: 1.25rem; line-height: 1;
  display: grid; place-items: center; transition: transform .1s ease, background .1s ease;
}
.ctrl:active { transform: scale(.92); }
.ctrl.play {
  width: 66px; height: 66px; font-size: 1.7rem; border: none;
  background: var(--accent); color: #fff; box-shadow: var(--shadow-lg);
}
.ctrl.play.is-playing { background: var(--accent-press); }

.slider-row { font-size: .85rem; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.slider-row strong { color: var(--text); }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px;
  border-radius: 999px; background: var(--bg-2); outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--card); box-shadow: var(--shadow); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent);
  border: 3px solid var(--card); box-shadow: var(--shadow); cursor: pointer;
}
.select-row { font-size: .85rem; font-weight: 600; color: var(--muted); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.select-row select {
  font-family: inherit; font-weight: 700; font-size: .9rem; color: var(--text);
  background: var(--bg-2); border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 12px;
}

.toggle-row { display: flex; gap: 8px; flex-wrap: wrap; }
.toggle {
  flex: 1; min-width: 96px; padding: 11px 8px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--card); color: var(--muted);
  font-weight: 700; font-size: .8rem; transition: all .12s ease;
}
.toggle.on { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }

.mini-chords { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (min-width: 440px) { .mini-chords { grid-template-columns: repeat(4, 1fr); } }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; max-width: 560px; margin: 0 auto;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0 9px; color: var(--muted); font-size: .72rem; font-weight: 700;
}
.nav-ico { font-size: 1.35rem; filter: grayscale(.4) opacity(.7); transition: filter .15s ease; }
.nav-item.active { color: var(--accent); }
.nav-item.active .nav-ico { filter: none; }

/* ---------- Tuner ---------- */
.tuner-view { text-align: center; }
.tuner-view .view-sub { text-align: center; }

.tuner-readout { margin: 16px 0 12px; }
.tuner-note {
  font-size: 4.6rem; font-weight: 800; line-height: 1; color: var(--muted);
  transition: color .15s ease; font-variant-numeric: tabular-nums;
}
.tuner-note sub { font-size: 1.4rem; font-weight: 700; vertical-align: baseline; opacity: .75; }
.tuner-note.in { color: var(--beginner); }
.tuner-note.near { color: var(--intermediate); }
.tuner-note.off { color: var(--accent); }
.tuner-meta { display: flex; justify-content: center; gap: 14px; align-items: baseline; margin-top: 6px; }
#tFreq { color: var(--muted); font-weight: 600; font-size: .95rem; font-variant-numeric: tabular-nums; }
.tuner-cents { font-weight: 800; font-size: .95rem; color: var(--muted); }
.tuner-cents.in { color: var(--beginner); }
.tuner-cents.near { color: var(--intermediate); }
.tuner-cents.off { color: var(--accent); }

.meter { margin: 10px 0 16px; }
.meter-track {
  position: relative; height: 28px; border-radius: 999px;
  background: var(--bg-2); border: 1.5px solid var(--line); overflow: hidden;
}
.meter-band {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 10%; transform: translateX(-50%);
  background: color-mix(in srgb, var(--beginner) 26%, transparent);
}
.meter-tick { position: absolute; top: 5px; bottom: 5px; width: 1.5px; background: var(--line); transform: translateX(-50%); }
.meter-tick.center { width: 2px; background: var(--muted); top: 3px; bottom: 3px; }
.meter-needle {
  position: absolute; top: -2px; bottom: -2px; left: 50%; width: 4px; transform: translateX(-50%);
  background: var(--muted); border-radius: 999px; transition: left .08s linear, background .12s ease, box-shadow .12s ease;
}
.meter-needle.in { background: var(--beginner); box-shadow: 0 0 10px color-mix(in srgb, var(--beginner) 65%, transparent); }
.meter-needle.near { background: var(--intermediate); }
.meter-needle.off { background: var(--accent); }
.meter-labels { display: flex; justify-content: space-between; margin-top: 6px; font-size: .68rem; color: var(--muted); font-weight: 600; }

.tuner-graph {
  display: block; width: 100%; height: 150px; border-radius: 14px;
  background: var(--card); border: 1px solid color-mix(in srgb, var(--line) 50%, transparent);
}

.string-targets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 16px 0; }
.string-target {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 13px 4px;
  border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); color: var(--text);
  transition: transform .1s ease, border-color .12s ease, background .12s ease;
}
.string-target:active, .string-target.tap { transform: scale(.95); }
.string-target .st-name { font-size: 1.35rem; font-weight: 800; line-height: 1; }
.string-target .st-freq { font-size: .66rem; color: var(--muted); font-weight: 600; }
.string-target.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.string-target.tuned { border-color: var(--beginner); background: color-mix(in srgb, var(--beginner) 18%, transparent); }
.string-target.tuned .st-name { color: var(--beginner); }

.tuner-btn {
  width: 100%; padding: 16px; border-radius: 14px; border: none; margin-top: 4px;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 1.05rem;
  box-shadow: var(--shadow-lg); transition: transform .1s ease, background .12s ease;
}
.tuner-btn:active { transform: scale(.98); }
.tuner-btn.active { background: var(--accent-press); animation: listenPulse 1.6s ease-in-out infinite; }
@keyframes listenPulse {
  0%, 100% { box-shadow: var(--shadow-lg); }
  50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--accent) 22%, transparent); }
}
.tuner-error { color: var(--accent); font-weight: 600; font-size: .85rem; line-height: 1.45; margin: 12px 0 0; }
.tuner-privacy { color: var(--muted); font-size: .76rem; line-height: 1.5; margin: 14px 0 0; }
