:root {
  --bg: #faf7f0;
  --panel: #ffffff;
  --ink: #2c2620;
  --muted: #8a7f70;
  --line: #e5ddd0;
  --accent: #b3502a;
  --accent-soft: #f4e2d8;
  --green: #4a7c4e;
  --green-soft: #e4efe0;
  --gold: #b98a1e;
  --shadow: 0 2px 14px rgba(60, 45, 30, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", -apple-system, Roboto, "Helvetica Neue", sans-serif;
  background:
    radial-gradient(1200px 500px at 80% -10%, #f6ead9 0%, transparent 60%),
    radial-gradient(900px 400px at -10% 110%, #eef0e4 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px clamp(14px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 249, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}
#brand {
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
  color: var(--ink);
}
#brand span { color: var(--muted); font-weight: 400; font-size: 14px; }
#topbar nav a {
  margin-left: 18px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 15px;
  padding-bottom: 3px;
  border-bottom: 2px solid transparent;
}
#topbar nav a.active { color: var(--accent); border-bottom-color: var(--accent); }

main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 24px clamp(14px, 3vw, 32px) 60px; }
#footer { padding: 18px clamp(14px, 4vw, 40px); color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--line); }

a { color: var(--accent); }
h1 { font-size: 26px; margin: 8px 0 4px; }
h2 { font-size: 19px; margin: 26px 0 10px; }
.sub { color: var(--muted); margin: 0 0 18px; font-size: 14.5px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }

/* ---------- library ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 18px; }
.chip {
  border: 1.5px solid var(--line); border-radius: 999px; background: #fff;
  padding: 6px 14px; font-size: 13.5px; font-weight: 600; color: var(--muted);
  cursor: pointer; transition: all .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.card {
  display: block; text-decoration: none; color: inherit;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 16px 14px; box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s;
  position: relative;
}
.card:hover { transform: translateY(-2px); border-color: #d8c9b8; }
.card .flag { font-size: 22px; float: right; margin: -4px -4px 0 8px; }
.card .origin { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.card h3 { margin: 4px 0 2px; font-size: 16.5px; }
.card .native { color: var(--muted); font-size: 14px; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.badge {
  font-size: 11.5px; font-weight: 700; border-radius: 6px; padding: 2.5px 8px;
  background: var(--accent-soft); color: var(--accent);
}
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.gold { background: #f6ecd4; color: var(--gold); }
.card .note { font-size: 12px; color: var(--muted); margin-top: 8px; }
.card .practiced { position: absolute; top: 12px; left: 16px; font-size: 11px; color: var(--green); font-weight: 700; }

/* ---------- song page ---------- */
.songhead { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px 18px; }
.songhead .native-title { font-size: 20px; color: var(--muted); }
.origin-flag { font-size: 13px; font-weight: 700; color: var(--muted); }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 14px; }
.btn {
  border: 1.5px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 9px 16px; font-size: 14px; font-weight: 700; cursor: pointer;
  transition: all .15s; font-family: inherit;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #9c431f; color: #fff; }
.btn.small { padding: 5px 11px; font-size: 12.5px; border-radius: 8px; }
.btn.on { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.btn:disabled { opacity: .45; cursor: default; }
.viewtoggle { display: inline flex; gap: 0; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; }
.viewtoggle button {
  border: none; background: #fff; padding: 9px 14px; font-size: 13.5px; font-weight: 700;
  cursor: pointer; color: var(--muted); font-family: inherit;
}
.viewtoggle button.on { background: var(--accent); color: #fff; }

.field { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input[type=range] { accent-color: var(--accent); width: 120px; }
.field select {
  font-family: inherit; font-size: 13px; border: 1.5px solid var(--line); border-radius: 8px;
  padding: 6px 8px; background: #fff; color: var(--ink); font-weight: 600;
}
.val { min-width: 44px; display: inline-block; text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }

/* score */
#score-wrap { overflow-x: auto; margin-top: 16px; }
svg.score { display: block; margin: 0 auto; }
svg.score text { font-family: inherit; }
.sysrow { margin-bottom: 26px; }
.barbox { cursor: pointer; }
.barbox.loop-in { fill: rgba(179, 80, 42, 0.07); }
.barbox.loop-out { fill: rgba(179, 80, 42, 0.07); }
.barbox.selected { fill: rgba(74, 124, 78, 0.10); }
.barbox.loop-only { fill: rgba(74, 124, 78, 0.14); }
.barnum { font-size: 10px; fill: #b3a894; font-weight: 700; }
.chordname { font-size: 13px; font-weight: 800; fill: #7a5a2e; }
.chordname.sub { fill: #b3a894; }
.lyrictext { font-size: 12.5px; fill: #6d6357; }
.lyrictext.now { fill: var(--accent); font-weight: 700; }
.playline { stroke: var(--accent); stroke-width: 2.5; opacity: .85; }
.notehead { fill: var(--ink); }
.fret { font-size: 12.5px; font-weight: 800; fill: var(--ink); }
.stem { stroke: var(--ink); stroke-width: 1.6; }
.flagcurve { stroke: var(--ink); }
.notegrp.on .notehead { fill: var(--accent); stroke: var(--accent); }
.notegrp.on .fret { fill: var(--accent); }
.notegrp.on .stem { stroke: var(--accent); }
.notegrp.on .flagcurve { stroke: var(--accent); }
.strumtok.on { fill: var(--accent); }
.chordname.on { fill: var(--accent); }
.stringlabel { font-size: 10px; fill: #b3a894; font-weight: 700; }
.sectionlabel { font-size: 12px; font-weight: 800; fill: var(--muted); letter-spacing: .06em; text-transform: uppercase; }

/* practice panel */
.practice .row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-top: 10px; }
.loopinfo { font-size: 14px; font-weight: 700; color: var(--green); }
.stat { font-variant-numeric: tabular-nums; }
.help { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }

/* chord chart */
.chartbar { display: flex; align-items: flex-start; gap: 4px; }
.chartbar .chartchord { text-align: center; }

/* tuner */
.tunerbox { text-align: center; padding: 10px 0 4px; }
.gauge-wrap { max-width: 520px; margin: 0 auto; }
.readout { font-size: 42px; font-weight: 800; margin: 6px 0 0; }
.readout small { font-size: 18px; color: var(--muted); font-weight: 600; }
.cents { color: var(--muted); font-weight: 700; margin-bottom: 12px; }
.strings { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.strbtn {
  border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 14px;
  font-size: 14px; font-weight: 800; cursor: pointer; font-family: inherit;
}
.strbtn.detected { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.strbtn.playing { background: var(--accent-soft); border-color: var(--accent); }
.tuner-note { font-size: 13px; color: var(--muted); max-width: 560px; margin: 14px auto 0; }

/* performance mode */
body.perf { background: #14100c; color: #eee; }
body.perf #topbar, body.perf #footer { display: none; }
body.perf main { max-width: 1400px; padding-top: 30px; }
body.perf .panel { background: #1d1813; border-color: #3a3129; box-shadow: none; }
body.perf .btn { background: #1d1813; border-color: #3a3129; color: #ddd; }
body.perf .btn.primary { background: var(--accent); color: #fff; }
body.perf .field { color: #aaa; }
body.perf .field .val, body.perf .speedval, body.perf .loopinfo.stat { color: #ddd; }
body.perf .field select, body.perf .viewtoggle button { background: #1d1813; color: #ddd; border-color: #3a3129; }
body.perf .viewtoggle { border-color: #3a3129; }
body.perf .viewtoggle button.on { background: var(--accent); }
body.perf h1, body.perf .sub, body.perf .help { color: #cbbfae; }
body.perf .chordname { fill: #d9b36a; }
body.perf .lyrictext { fill: #a89a86; }
body.perf .lyrictext.now { fill: #f0a35e; }
body.perf .notehead { fill: #eee; }
body.perf .fret { fill: #eee; }
body.perf .stem { stroke: #eee; }
body.perf .flagcurve { stroke: #eee; }
body.perf .notegrp.on .notehead { fill: #f0a35e; stroke: #f0a35e; }
body.perf .notegrp.on .fret, body.perf .notegrp.on .stem, body.perf .notegrp.on .flagcurve { fill: #f0a35e; stroke: #f0a35e; }
body.perf .notegrp.on .fret { stroke: none; }
body.perf .strumtok.on { fill: #f0a35e; }
body.perf .chordname.on { fill: #f0a35e; }
body.perf .barnum, body.perf .stringlabel { fill: #7d7160; }
body.perf .playline { stroke: #f0a35e; }
body.perf .barbox.selected { fill: rgba(240, 163, 94, 0.10); }
body.perf .loopinfo { color: #8fbf92; }

/* toast */
#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: #2c2620; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; font-weight: 600; z-index: 100; box-shadow: var(--shadow);
}

@media (max-width: 640px) {
  .readout { font-size: 32px; }
  main { padding-bottom: 40px; }
}
