:root {
  --bg: #f6f3ee; --card: #fff; --ink: #231f2e; --muted: #6d6879; --line: #e4dfd6;
  --brand: #2b2540; --accent: #d98a1f; --accent-ink: #fff; --chord: #b4570a; --ok: #2f7d4f; --bad: #b3261e;
  --soft: #efe9de; --bar: #2b2fa8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17141f; --card: #221e2e; --ink: #eeeaf5; --muted: #a39db3; --line: #383349;
    --brand: #0f0d16; --accent: #f2b45a; --accent-ink: #1b1424; --chord: #f2b45a; --ok: #6fd09a; --bad: #ff8a80; --soft: #2d283c;
  }
}
:root[data-theme="dark"] {
  --bg: #17141f; --card: #221e2e; --ink: #eeeaf5; --muted: #a39db3; --line: #383349;
  --brand: #0f0d16; --accent: #f2b45a; --accent-ink: #1b1424; --chord: #f2b45a; --ok: #6fd09a; --bad: #ff8a80; --soft: #2d283c;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.7rem; }
[hidden] { display: none !important; }

.top { background: var(--bar); color: #fff; display: flex; align-items: center; gap: 18px; padding: 10px 16px; flex-wrap: wrap; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; text-decoration: none; font-size: 1.1rem; margin-right: auto; }
.logo { color: #f2b45a; margin-right: 4px; }
.top nav { display: flex; gap: 6px; }
.top nav a { text-decoration: none; padding: 6px 12px; border-radius: 999px; opacity: .85; }
.top nav a.on, .top nav a:hover { background: rgba(255,255,255,.14); opacity: 1; }
.who { font-size: .9rem; opacity: .9; }
.who .link { color: #f2b45a; }

main { max-width: 980px; margin: 0 auto; padding: 20px 16px 80px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 8px 14px; border-radius: 10px; text-decoration: none; display: inline-block; min-height: 40px; }
button:hover, .btn:hover { border-color: var(--accent); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button.link { background: none; border: 0; padding: 0; min-height: 0; text-decoration: underline; }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; min-height: 42px; }
textarea { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92rem; line-height: 1.5; min-height: 320px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid4 { display: grid; grid-template-columns: 2fr 2fr 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .grid2, .grid4 { grid-template-columns: 1fr 1fr; } .who { width: 100%; } }

.error { color: var(--bad); font-weight: 600; }
.notice { background: var(--soft); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 8px; }

/* auth */
.auth { max-width: 420px; margin: 6vh auto 0; }
.auth h1 { text-align: center; }
.auth .tabs { margin-bottom: 14px; }

.tabs { display: flex; gap: 4px; background: var(--soft); padding: 4px; border-radius: 12px; }
.tabs button { flex: 1; border: 0; background: transparent; min-height: 36px; }
.tabs button.on { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* song list */
.search { margin: 12px 0 14px; }
.songs { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.songs a { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; }
.songs a:hover { border-color: var(--accent); }
.songs .t { font-weight: 600; }
.pill { background: var(--soft); color: var(--chord); font-weight: 700; padding: 2px 10px; border-radius: 999px; font-size: .85rem; white-space: nowrap; }
.empty { text-align: center; padding: 40px 16px; }

/* add hub */
.hub { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-top: 14px; }
.hub .card { display: flex; flex-direction: column; gap: 10px; }
.hub .big { font-size: 1.8rem; }

/* song view */
.toolbar { position: sticky; top: 56px; z-index: 5; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin: 14px 0; display: flex; gap: 10px 18px; flex-wrap: wrap; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.keybox { display: flex; align-items: center; gap: 6px; }
.keybox .cur { min-width: 58px; text-align: center; font-weight: 800; font-size: 1.25rem; color: var(--chord); }
.keybox button { width: 40px; padding: 0; font-weight: 700; font-size: 1.1rem; }
.keybox select { width: auto; min-width: 74px; }
.sheet { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; overflow-x: auto; }
.song { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: var(--fs, 17px); line-height: 1.25; }
.song .ln { margin: 0; min-height: 1.25em; display: flex; flex-wrap: wrap; align-items: flex-end; }
.song .seg { display: inline-flex; flex-direction: column; }
.song .ch { color: var(--chord); font-weight: 800; min-height: 1.3em; padding-right: .6em; white-space: pre; }
.song .tx { white-space: pre; min-height: 1.25em; }
.song.nochords .ch { display: none; }
.song .sec { margin: 1.1em 0 .3em; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; font-size: .8em; color: var(--muted); font-family: system-ui, sans-serif; }
.song .sec:first-child { margin-top: 0; }
.song .blank { height: .7em; }
.meta { display: flex; gap: 14px; flex-wrap: wrap; }

/* editor */
.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .editor { grid-template-columns: 1fr; } }
.insertbar { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.insertbar button { min-height: 32px; padding: 3px 10px; font-size: .85rem; }
.history { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.history div { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.history div:last-child { border-bottom: 0; }

/* progress */
.bar { height: 8px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 40%; background: var(--accent); border-radius: 99px; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
@media (prefers-reduced-motion: reduce) { .bar i { animation: none; width: 100%; } }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--brand); color: #fff; padding: 10px 18px; border-radius: 99px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media print {
  .top, .toolbar, #toast, .noprint { display: none !important; }
  body { background: #fff; color: #000; }
  .sheet, .card { border: 0; padding: 0; }
  .song .ch { color: #000; }
}

/* ===== app shell: sidebar + song area (iPad-style) ===== */
.iconbtn { background: transparent; border: 0; color: #fff; font-size: 1.4rem; width: 44px; padding: 0; min-height: 44px; }
.top .iconbtn { display: none; }
.shell { display: block; }
.side { position: fixed; top: 0; bottom: 0; left: 0; width: min(340px, 88vw); z-index: 40; background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; transform: translateX(-102%); transition: transform .25s; }
.side[hidden] { display: none !important; }
.side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 35; }
.panel { flex: 1; overflow: auto; padding: 14px 12px; }
.sidetabs { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); background: var(--card); }
.sidetabs button { border: 0; border-radius: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 0; font-size: .78rem; padding: 8px 4px 10px; color: var(--muted); }
.sidetabs button span { font-size: 1.15rem; }
.sidetabs button.on { color: var(--bar); font-weight: 700; box-shadow: inset 0 3px 0 var(--bar); }
:root[data-theme="dark"] .sidetabs button.on, :root:not([data-theme="light"]) .sidetabs button.on { color: var(--accent); }
@media (min-width: 900px) {
  .top .iconbtn { display: none !important; }
  .shell.has-side { display: grid; grid-template-columns: 330px 1fr; }
  .shell.has-side .side { position: sticky; top: 56px; height: calc(100vh - 56px); transform: none; width: auto; z-index: 1; box-shadow: none; }
  .scrim { display: none !important; }
  .shell.has-side main { max-width: none; width: 100%; }
}
@media (max-width: 899px) { .top .iconbtn { display: block; } .top.nomenu .iconbtn { display: none; } }
.panel h2 { font-size: 1.1rem; margin: 0 0 8px; }
.panel .search { margin: 8px 0 10px; }
.letter { position: sticky; top: -14px; background: var(--card); padding: 6px 4px 2px; font-weight: 800; color: var(--bar); font-size: .9rem; border-bottom: 1px solid var(--line); z-index: 1; }
:root[data-theme="dark"] .letter, :root:not([data-theme="light"]) .letter { color: var(--accent); }
.slist a, .slist .row { display: block; padding: 9px 6px; text-decoration: none; border-radius: 8px; border-bottom: 1px solid var(--line); }
.slist a:hover { background: var(--soft); }
.slist a.cur { background: var(--soft); box-shadow: inset 3px 0 0 var(--bar); }
.slist .t { display: block; font-weight: 600; line-height: 1.25; }
.slist .s { display: block; color: var(--muted); font-size: .8rem; }
.azrail { position: absolute; right: 2px; top: 110px; display: flex; flex-direction: column; font-size: .62rem; color: var(--muted); }
.azrail a { padding: 0 3px; text-decoration: none; }
.setcard { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.setcard > .hd { display: flex; align-items: center; gap: 8px; padding: 10px 12px; cursor: pointer; background: var(--soft); font-weight: 700; }
.setcard .hd small { color: var(--muted); font-weight: 400; margin-left: auto; }
.setcard .bd { padding: 6px 8px 10px; }
.setrow { display: flex; align-items: center; gap: 4px; }
.setrow a { flex: 1; padding: 7px 4px; text-decoration: none; }
.setrow button, .tiny { min-height: 28px; padding: 0 8px; font-size: .8rem; }
.field { margin-bottom: 14px; }
.field > label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.seg3 { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg3 button { flex: 1; border: 0; border-radius: 0; min-height: 36px; padding: 4px; }
.seg3 button.on { background: var(--bar); color: #fff; font-weight: 700; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 32px; height: 32px; min-height: 0; padding: 0; border-radius: 50%; border: 3px solid transparent; }
.swatches button.on { border-color: var(--ink); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; }
.switch input { width: 22px; height: 22px; min-height: 0; }

/* song screen */
main#app { min-width: 0; }
.songbar { background: var(--bar); color: #fff; border-radius: 12px 12px 0 0; display: flex; align-items: center; gap: 6px; padding: 8px 10px; flex-wrap: wrap; position: sticky; top: 56px; z-index: 6; }
.songbar .ttl { flex: 1; min-width: 150px; text-align: center; line-height: 1.15; }
.songbar .ttl b { display: block; font-size: 1rem; }
.songbar .ttl small { opacity: .85; font-size: .78rem; }
.songbar button, .songbar .btn { background: rgba(255,255,255,.14); color: #fff; border: 0; min-height: 36px; padding: 4px 11px; font-size: .88rem; }
.songbar button:hover, .songbar .btn:hover { background: rgba(255,255,255,.28); }
.songbar button.on { background: #fff; color: var(--bar); font-weight: 700; }
.songbar .nav2 { display: flex; gap: 4px; align-items: center; font-size: .82rem; }
.songbar .nav2 button { min-width: 36px; padding: 0 6px; }
.pop { background: var(--card); border: 1px solid var(--line); border-top: 0; padding: 14px; display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: center; }
.pop .big { font-size: 2rem; font-weight: 800; color: var(--chord); min-width: 70px; text-align: center; }
.pop .keys { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.pop .keys button { min-width: 48px; padding: 4px; min-height: 36px; }
.pop .keys button.on { background: var(--bar); color: #fff; border-color: var(--bar); font-weight: 700; }
.diagrams { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.diagrams svg { color: var(--ink); }
.songhead { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 0 0 14px; }
.songhead h1 { margin: 0; font-size: 1.5rem; }
.songhead .k { font-weight: 800; color: var(--chord); white-space: nowrap; }
.sheet.flat { border-radius: 0 0 14px 14px; border-top: 0; }
.song.cols { column-width: 22em; column-gap: 34px; }
.song .blk { break-inside: avoid; margin-bottom: 1.1em; }
.song.single .blk { break-inside: auto; }
.song.nohead .sec { display: none; }
.song .ch.bold { font-weight: 800; }
.song .ch { font-weight: 600; }
.song.boldch .ch { font-weight: 800; }
.song .blk .sec { margin-top: 0; }
@media (max-width: 600px) { .songbar .ttl { order: -1; width: 100%; flex-basis: 100%; } }
@media print { .side, .scrim, .songbar, .pop { display: none !important; } .shell.has-side { display: block; } }
@media (max-width: 600px) { .song { font-size: min(var(--fs, 17px), 14px); } .sheet { padding: 14px; } }

/* listen panel (video + pitch-shifting audio) */
.listen { background: var(--card); border: 1px solid var(--line); border-top: 0; padding: 14px; display: grid; gap: 12px; }
.vwrap { position: relative; width: 100%; max-width: 560px; aspect-ratio: 16 / 9; background: #000; border-radius: 12px; overflow: hidden; }
.vwrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.listen .ctl { display: grid; gap: 10px; }
.listen .ctl input[type=range] { flex: 1; min-width: 120px; padding: 0; min-height: 32px; }
.listen .keybox button { width: 40px; padding: 0; font-weight: 700; }
.pitchlbl { min-width: 42px; text-align: center; font-weight: 800; font-size: 1.15rem; color: var(--chord); }
@media print { .listen { display: none !important; } }
.listen input[type=checkbox] { width: 20px; min-height: 0; height: 20px; flex: none; }
.listen label { white-space: nowrap; }
.editor > div { min-width: 0; }
.editor textarea { max-width: 100%; }

.editor { grid-template-columns: 1fr; }
.editor textarea { min-height: 460px; }
