:root {
  --green-950: #0d2419;
  --green-900: #133324;
  --green-800: #1a4430;
  --green-700: #22563d;
  --green-600: #2e6d4e;
  --cream: #f5ecd7;
  --cream-2: #ece0c3;
  --cream-dim: #c9bd9f;
  --ink: #1d1a14;
  --gold: #d9a93b;
  --gold-soft: #f0cf7a;
  --gold-glow: rgba(217, 169, 59, 0.16);
  --red: #a8322d;
  --muted: #9fb3a6;
  --serif: 'EB Garamond', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius: 14px;
  --header-h: 56px;
  --footer-h: 132px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--green-900);
  background-image: radial-gradient(ellipse at top, var(--green-800), var(--green-950) 70%);
  background-attachment: fixed;
  color: var(--cream);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- App header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  height: var(--header-h); padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  height: calc(var(--header-h) + env(safe-area-inset-top));
  background: rgba(13, 36, 25, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(217, 169, 59, 0.25);
}
.brand { font-family: var(--serif); font-size: 26px; font-weight: 600; letter-spacing: 0.3px; margin: 0; flex: 1; }
.brand span { color: var(--gold); }
.tabs { display: flex; gap: 4px; background: var(--green-950); border-radius: 999px; padding: 3px; }
.tabs a {
  text-decoration: none; padding: 6px 12px; border-radius: 999px; font-size: 14px; color: var(--muted);
}
.tabs a.active { background: var(--green-700); color: var(--cream); }

/* ---------- Library ---------- */
.library { max-width: 720px; margin: 0 auto; padding: 14px 16px 40px; }
.search {
  width: 100%; padding: 12px 14px 12px 40px; border-radius: var(--radius);
  border: 1px solid var(--green-600); background: var(--green-950) no-repeat 13px 50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%239fb3a6' stroke-width='2'%3E%3Ccircle cx='8' cy='8' r='6'/%3E%3Cpath d='M13 13l4 4'/%3E%3C/svg%3E");
  font-size: 16px; outline: none;
}
.search:focus { border-color: var(--gold); }
.filters { display: flex; gap: 6px; margin: 12px -16px 4px; padding: 0 16px; overflow-x: auto; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip { flex: none; }
.chip {
  border: 1px solid var(--green-600); background: transparent; border-radius: 999px;
  padding: 6px 12px; font-size: 13px; color: var(--cream-dim);
}
.chip[aria-pressed='true'] { background: var(--gold); border-color: var(--gold); color: var(--green-950); font-weight: 600; }
.count { color: var(--muted); font-size: 13px; margin: 10px 2px; }
.song-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.song-item {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px;
  background: var(--cream); color: var(--ink); border-radius: var(--radius); padding: 10px 8px 10px 12px;
  box-shadow: 0 1px 0 rgba(0,0,0,.25);
}
.song-item a { text-decoration: none; display: contents; }
.rank { font-family: var(--serif); font-size: 18px; color: #8a7a55; text-align: center; }
.song-title { font-family: var(--serif); font-size: 19px; font-weight: 600; line-height: 1.15; }
.song-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; font-size: 12px; color: #5f5440; align-items: center; }
.pill { border-radius: 999px; padding: 1px 8px; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.pill.easy { background: #d5e8d6; color: #1f5a33; }
.pill.medium { background: #f3e3b5; color: #7a5a0c; }
.pill.hard { background: #f1cfc9; color: #8a2a22; }
.pill.pending { background: #e3ddd0; color: #6d6350; }
.star {
  border: 0; background: none; font-size: 22px; width: 40px; height: 40px; border-radius: 50%;
  color: #b9ab89; line-height: 1;
}
.star[aria-pressed='true'] { color: var(--gold); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; font-family: var(--serif); font-size: 18px; }

/* ---------- Setlists ---------- */
.set-new { display: flex; gap: 8px; margin-bottom: 14px; }
.set-new input { flex: 1; padding: 11px 14px; border-radius: var(--radius); border: 1px solid var(--green-600); background: var(--green-950); outline: none; }
.btn {
  border: 0; border-radius: var(--radius); padding: 11px 16px; font-weight: 600;
  background: var(--gold); color: var(--green-950);
}
.btn.ghost { background: transparent; color: var(--cream); border: 1px solid var(--green-600); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.set-card { background: var(--cream); color: var(--ink); border-radius: var(--radius); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.set-card a { flex: 1; text-decoration: none; }
.set-card h3 { margin: 0; font-family: var(--serif); font-size: 20px; }
.set-card p { margin: 2px 0 0; font-size: 13px; color: #5f5440; }
.set-row { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; background: var(--cream); color: var(--ink); border-radius: 12px; padding: 8px 8px 8px 12px; }
.set-row .song-title { font-size: 17px; }
.set-row .ctrls { display: flex; gap: 2px; }
.icon-btn { border: 0; background: none; width: 36px; height: 36px; border-radius: 50%; font-size: 17px; color: inherit; }
.icon-btn:active { background: rgba(0,0,0,.08); }
.set-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.set-head h2 { flex: 1; margin: 0; font-family: var(--serif); font-size: 26px; }

/* ---------- Player ---------- */
.player { position: fixed; inset: 0; display: flex; flex-direction: column; }
.p-head {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  background: rgba(13, 36, 25, 0.96); border-bottom: 1px solid rgba(217, 169, 59, 0.25);
}
.p-title { flex: 1; min-width: 0; }
.p-title h1 { margin: 0; font-family: var(--serif); font-size: 21px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-title p { margin: 1px 0 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.colheads {
  flex: none; display: grid; grid-template-columns: var(--cols); gap: 8px; padding: 4px 12px;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted);
  background: var(--green-950);
}
.colheads span:nth-child(2) { text-align: center; }
.colheads span:nth-child(3) { text-align: center; }
.player { --cols: minmax(0, 1.12fr) minmax(0, 0.6fr) minmax(0, 1.08fr); }

.scroller {
  flex: 1; overflow-y: auto; position: relative; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.scroller::-webkit-scrollbar { display: none; }
.now-band {
  position: absolute; left: 0; right: 0; pointer-events: none; z-index: 2;
  border-top: 2px solid var(--gold); border-bottom: 2px solid var(--gold);
  background: var(--gold-glow); box-shadow: 0 0 24px rgba(217,169,59,.18);
  transition: top .25s ease, height .25s ease;
}
.now-marker {
  position: absolute; left: 0; width: 5px; background: var(--gold); border-radius: 0 3px 3px 0; z-index: 3; pointer-events: none;
}
.rows { padding: 0 12px; position: relative; }
.spacer-top, .spacer-bottom { pointer-events: none; }
.section-head {
  display: flex; align-items: center; gap: 8px; padding: 14px 0 6px;
  font-family: var(--serif); font-style: italic; font-size: 16px; color: var(--gold-soft);
}
.section-head::after { content: ''; flex: 1; height: 1px; background: linear-gradient(to right, rgba(217,169,59,.4), transparent); }
.loop-btn {
  order: 2; font-family: var(--sans); font-style: normal; font-size: 11.5px; font-weight: 600;
  border: 1px solid var(--green-600); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 3px 10px;
}
.loop-btn[aria-pressed='true'] { background: var(--gold); color: var(--green-950); border-color: var(--gold); }
.section-head.looping { color: var(--gold); }

.row {
  display: grid; grid-template-columns: var(--cols); gap: 8px; align-items: center;
  min-height: 62px; padding: 5px 0; transition: opacity .3s;
}
.row.past { opacity: 0.42; }
.lyric { font-family: var(--serif); font-size: 19.5px; line-height: 1.22; overflow-wrap: anywhere; }
.lyric.placeholder { font-family: var(--sans); font-size: 12.5px; color: var(--muted); border: 1px dashed rgba(159,179,166,.45); border-radius: 8px; padding: 6px 8px; }
.lyric.instrumental { color: var(--muted); font-size: 16px; }
.chord { text-align: center; font-weight: 700; font-size: 21px; letter-spacing: -.3px; line-height: 1.1; overflow-wrap: anywhere; }
.chord .beats { display: block; font-size: 10px; font-weight: 500; color: var(--muted); letter-spacing: 2px; margin-top: 3px; white-space: nowrap; }
.chord.same { color: var(--cream-dim); font-weight: 500; }
.row.now .chord { color: var(--gold-soft); }
.row.now .lyric { color: #fff; }
.kbd { display: flex; flex-direction: column; align-items: center; justify-content: center; border: 0; background: none; padding: 0; width: 100%; }
.kbd svg { width: 100%; max-width: 168px; height: auto; display: block; filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); border-radius: 4px; }
.kbd:active svg { transform: scale(.97); }
.kbd .lh { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.kbd.nc { color: var(--muted); font-size: 12px; min-height: 40px; }
.kbd.playing svg { filter: drop-shadow(0 0 6px rgba(240,207,122,.8)); }
.endcard { text-align: center; padding: 30px 10px; font-family: var(--serif); font-size: 22px; color: var(--gold-soft); }
.endcard .btn { font-family: var(--sans); margin-top: 12px; }

.p-foot {
  flex: none; background: rgba(13, 36, 25, 0.97); border-top: 1px solid rgba(217,169,59,.25);
  padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
  display: grid; gap: 8px;
}
.tempo-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.tempo-row input[type=range] { flex: 1; accent-color: var(--gold); height: 28px; }
.tempo-row output { min-width: 82px; text-align: right; color: var(--cream); font-variant-numeric: tabular-nums; }
.transport { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.key-ctl { display: flex; align-items: center; gap: 2px; background: var(--green-950); border-radius: 999px; padding: 2px; }
.key-ctl button { border: 0; background: none; width: 34px; height: 34px; border-radius: 50%; font-size: 18px; color: var(--cream); }
.key-ctl button:active { background: var(--green-700); }
.key-ctl .key { min-width: 54px; text-align: center; font-weight: 700; font-size: 15px; }
.key-ctl .key small { display: block; font-size: 9.5px; color: var(--muted); font-weight: 500; letter-spacing: .6px; text-transform: uppercase; }
.play {
  width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--gold); color: var(--green-950);
  display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
.play svg { width: 26px; height: 26px; }
.round { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--green-600); background: transparent; display: grid; place-items: center; color: var(--cream); }
.round svg { width: 20px; height: 20px; }
.round[aria-pressed='true'] { background: var(--green-700); border-color: var(--gold); color: var(--gold-soft); }
.hbtn { border: 0; background: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--cream); flex: none; }
.hbtn svg { width: 22px; height: 22px; }
.hbtn[aria-pressed='true'] { color: var(--gold); }
.hbtn:active { background: var(--green-800); }

.countin {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; pointer-events: none;
  font-family: var(--serif); font-size: 150px; color: var(--gold); text-shadow: 0 0 40px rgba(217,169,59,.5);
}
.countin span { animation: pop .45s ease-out; }
@keyframes pop { from { transform: scale(1.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Sheets & toasts ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 520px; background: var(--cream); color: var(--ink); border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 80dvh; overflow-y: auto;
}
.sheet h2 { margin: 0 0 12px; font-family: var(--serif); font-size: 24px; }
.sheet .opt { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 4px; border: 0; border-bottom: 1px solid var(--cream-2); background: none; color: var(--ink); text-align: left; font-size: 16px; }
.sheet .opt:last-child { border-bottom: 0; }
.sheet .opt small { color: #6d6350; }
.switch { appearance: none; width: 46px; height: 28px; border-radius: 999px; background: #cfc4a8; position: relative; flex: none; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch:checked { background: var(--green-600); }
.switch:checked::after { left: 21px; }
.sheet .set-new input { background: #fff; color: var(--ink); border-color: var(--cream-2); }
.sheet-note { font-size: 13px; color: #6d6350; line-height: 1.45; }
.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  background: var(--cream); color: var(--ink); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.4); animation: pop .25s ease-out;
}

@media (min-width: 700px) {
  .player { --cols: minmax(0, 1.4fr) minmax(0, 0.5fr) minmax(0, 0.9fr); }
  .rows, .colheads { max-width: 760px; margin: 0 auto; width: 100%; }
  .lyric { font-size: 23px; }
  .chord { font-size: 25px; }
}
@media (max-width: 360px) {
  .lyric { font-size: 17px; }
  .chord { font-size: 18px; }
  .player { --cols: minmax(0, 1.1fr) minmax(0, 0.55fr) minmax(0, 1.05fr); }
}
@media (prefers-reduced-motion: reduce) {
  .now-band { transition: none; }
  .countin span, .toast { animation: none; }
}

.stage { flex: 1; position: relative; min-height: 0; }
.stage .scroller { position: absolute; inset: 0; }

/* ---------- Arrangement (style + hands) ---------- */
.colheads button {
  border: 0; background: none; padding: 0; font: inherit; letter-spacing: inherit; text-transform: inherit;
  color: var(--gold-soft); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kbd.two { gap: 3px; }
.kbd .hand { display: flex; align-items: center; gap: 3px; width: 100%; justify-content: center; }
.kbd .hand b { font-size: 9px; font-weight: 700; color: var(--muted); width: 8px; flex: none; }
.kbd .hand svg { max-width: 156px; }
.kbd .hand:last-child b { color: #9fd0b2; }
.lyric.cont { min-height: 1px; }
.chord.cont { font-size: 18px; }
.lh-hint { display: block; font-family: var(--sans); font-style: normal; font-size: 11px; color: var(--muted); margin-top: 2px; }
.section-head span { min-width: 0; }
.sheet-label { margin: 14px 0 6px; font-size: 12px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: #6d6350; }
.level-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.level-opt {
  border: 1px solid var(--cream-2); background: #fff; border-radius: 12px; padding: 8px 4px; color: var(--ink);
  display: grid; gap: 2px; justify-items: center; font-size: 11.5px; line-height: 1.2;
}
.level-opt strong { font-size: 18px; font-family: var(--serif); }
.level-opt[aria-pressed='true'], .style-opt[aria-pressed='true'] { background: var(--green-800); border-color: var(--green-800); color: var(--cream); }
.style-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.style-opt {
  border: 1px solid var(--cream-2); background: #fff; border-radius: 12px; padding: 9px 10px; color: var(--ink);
  text-align: left; display: grid; gap: 2px;
}
.style-opt strong { font-family: var(--serif); font-size: 17px; }
.style-opt small { font-size: 11.5px; color: #6d6350; line-height: 1.25; }
.style-opt[aria-pressed='true'] small { color: var(--cream-dim); }


/* ---------- UX pass: structure lines, toolbar, sound, tour ---------- */
:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 2px; border-radius: 6px; }
button:disabled { cursor: default; }

/* Clear lines between chunks: every chord row, and a strong band between sections. */
.row { border-top: 1px solid rgba(245, 236, 215, 0.1); }
.row.cont-row { border-top: 1px dashed rgba(245, 236, 215, 0.14); }
.section-head + .row { border-top-color: transparent; }
.section-head {
  margin: 14px -12px 0; padding: 9px 12px 8px;
  background: linear-gradient(to right, rgba(217,169,59,.16), rgba(13,36,25,.4) 60%);
  border-top: 2px solid rgba(217, 169, 59, 0.65);
  border-bottom: 1px solid rgba(217, 169, 59, 0.22);
  font-size: 17px;
}
.section-head::after { display: none; }
.spacer-top + .section-head { margin-top: 0; }
.section-head span { flex: 1; }
.loop-btn { min-height: 32px; padding: 4px 12px; }

.toolbar {
  flex: none; display: flex; gap: 8px; padding: 8px 12px; overflow-x: auto; scrollbar-width: none;
  background: var(--green-950); border-bottom: 1px solid rgba(217, 169, 59, 0.18);
}
.toolbar::-webkit-scrollbar { display: none; }
.tchip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; max-width: 72vw;
  border: 1px solid rgba(217,169,59,.5); background: rgba(217,169,59,.08); color: var(--gold-soft);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600;
}
.tchip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tchip svg { width: 16px; height: 16px; flex: none; }
.colheads { padding-top: 5px; padding-bottom: 5px; border-bottom: 1px solid rgba(245,236,215,.08); }
.loading {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 5;
  background: var(--cream); color: var(--ink); font-size: 13px; font-weight: 600;
  padding: 6px 14px; border-radius: 999px; box-shadow: 0 4px 14px rgba(0,0,0,.35); white-space: nowrap;
}

.field { display: grid; gap: 4px; padding: 10px 4px; border-bottom: 1px solid var(--cream-2); }
.field label { font-size: 13px; font-weight: 600; color: #5f5440; }
.field select {
  appearance: none; width: 100%; padding: 11px 36px 11px 12px; border-radius: 12px; border: 1px solid #d9cdb0;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%235f5440' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 14px center;
  color: var(--ink); font-size: 16px;
}
.field-note { color: #6d6350; font-size: 12.5px; }
.mix-row { display: grid; grid-template-columns: 40px 64px 1fr; align-items: center; gap: 6px; padding: 4px 0; }
.mix-row label { font-size: 14px; font-weight: 600; }
.mix-row input { accent-color: var(--green-700); width: 100%; height: 32px; }
.mute { border: 0; background: #fff; border-radius: 10px; width: 40px; height: 36px; font-size: 17px; }
.mute[aria-pressed='true'] { background: #f1cfc9; }
.btn.ghost-dark { width: 100%; margin-top: 10px; background: var(--green-800); color: var(--cream); }

.tour { position: fixed; inset: 0; z-index: 80; }
.tour-spot {
  position: fixed; border-radius: 12px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(5, 15, 10, 0.74), 0 0 0 2px var(--gold-soft), 0 0 24px rgba(240,207,122,.5);
  transition: all .3s ease;
}
.tour-card {
  position: fixed; left: 16px; right: 16px; max-width: 420px; margin: 0 auto;
  background: var(--cream); color: var(--ink); border-radius: 18px; padding: 16px 16px 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5); transition: top .3s ease;
}
.tour-step { font-size: 11px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: #8a7a55; }
.tour-card h3 { margin: 4px 0 6px; font-family: var(--serif); font-size: 23px; }
.tour-card p { margin: 0 0 12px; font-size: 15px; line-height: 1.45; color: #3b352a; }
.tour-actions { display: flex; align-items: center; gap: 8px; }
.tour-actions span { flex: 1; }
.tour-skip, .tour-back { border: 0; background: none; color: #6d6350; font-weight: 600; min-height: 44px; padding: 0 8px; }
.tour-next { min-height: 44px; }
@media (prefers-reduced-motion: reduce) { .tour-spot, .tour-card { transition: none; } }
.tchip { flex: 1 1 0; min-width: 0; max-width: none; justify-content: center; }

/* Per-row play button under each chord */
.row-play {
  display: inline-grid; place-items: center; margin-top: 6px; width: 34px; height: 34px; border-radius: 50%;
  border: 1.5px solid rgba(217, 169, 59, 0.6); background: rgba(13, 36, 25, 0.6); color: var(--gold-soft); padding: 0;
}
.row-play svg { width: 15px; height: 15px; margin-left: 2px; }
.row-play:active, .row-play.on { background: var(--gold); color: var(--green-950); border-color: var(--gold); }
.row.now .row-play { background: var(--gold); color: var(--green-950); border-color: var(--gold); }
.row.past .row-play { opacity: .7; }
