:root {
  --bg: #f6f5f2;
  --bg-elev: #ffffff;
  --bg-sunk: #ecebe6;
  --text: #17181c;
  --muted: #6b6d76;
  --line: #e2e0da;
  --accent: #e2552d;
  --accent-2: #f2a03d;
  --accent-ink: #ffffff;
  --chord: #d2461f;
  --ok: #1f8a5b;
  --warn: #b7791f;
  --danger: #c43d3d;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 8px 24px rgba(20, 20, 30, .06);
  --radius: 18px;
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --song-size: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --bg-elev: #181b22; --bg-sunk: #0b0c10; --text: #eef0f4; --muted: #9399a6;
    --line: #262a33; --accent: #ff7a50; --accent-2: #ffb25b; --accent-ink: #14161b; --chord: #ff9a6e;
    --ok: #3ecf8e; --warn: #f0b354; --danger: #ff6b6b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --bg-elev: #181b22; --bg-sunk: #0b0c10; --text: #eef0f4; --muted: #9399a6;
  --line: #262a33; --accent: #ff7a50; --accent-2: #ffb25b; --accent-ink: #14161b; --chord: #ff9a6e;
  --ok: #3ecf8e; --warn: #f0b354; --danger: #ff6b6b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 16px; line-height: 1.5; min-height: 100dvh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; text-decoration: none; font-size: 17px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: #121214; border: 1px solid rgba(255, 255, 255, .08);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
}
.brand-mark img { width: 70%; height: 70%; object-fit: contain; display: block; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-elev);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { border-color: var(--muted); }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: none; }
  :root:not([data-theme="light"]) .i-moon { display: block; }
}

/* ---------- layout ---------- */
.view { max-width: 860px; margin: 0 auto; padding: 20px 16px 32px; outline: none; }
.hero { margin: 8px 0 22px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
h1 { font-size: clamp(28px, 6vw, 40px); line-height: 1.08; letter-spacing: -.035em; margin: 6px 0 8px; font-weight: 800; }
h2 { font-size: 20px; letter-spacing: -.02em; margin: 26px 0 10px; }
h3 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

.card {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card-accent {
  border: 0; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 30px color-mix(in srgb, var(--accent) 30%, transparent);
}
.card-accent .muted { color: rgba(255, 255, 255, .85); }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px;
  padding: 0 18px; border-radius: 12px; border: 1px solid transparent; font-weight: 700; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: var(--bg-elev); color: var(--text); border-color: var(--line); }
.btn-white { background: #fff; color: #1b1b1f; }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn svg { width: 18px; height: 18px; }

.field { display: block; }
.field > span { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; color: var(--muted); }
.input, textarea.input, select.input {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-elev); outline: none;
}
textarea.input { min-height: 220px; resize: vertical; font-family: ui-monospace, 'Cascadia Mono', Menlo, monospace; font-size: 14px; line-height: 1.5; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
.search { position: relative; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 20px; height: 20px; }
.search .input { padding-left: 44px; min-height: 52px; font-size: 17px; border-radius: 16px; }

/* ---------- chips & lists ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; background: var(--bg-sunk); color: var(--muted); white-space: nowrap;
}
.chip-key { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.chip-warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.chip-ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.chip-danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

.list { list-style: none; margin: 0; padding: 0; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list a, .list .item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px;
  text-decoration: none; min-height: 56px;
}
.list a:hover { background: var(--bg-sunk); }
.list .title { font-weight: 600; }
.list .num { width: 26px; color: var(--muted); font-weight: 700; font-size: 14px; flex: none; }
/* letter headings scroll with the list - sticky ones covered songs */
.letter { padding: 6px 16px; font-weight: 800; font-size: 13px; color: var(--accent); background: var(--bg-sunk); }

.service { margin-top: 18px; }
.service-name { font-weight: 800; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px 4px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center; gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px;
  text-decoration: none; font-size: 11px; font-weight: 700; color: var(--muted); border-radius: 12px;
}
.tabbar a.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* ---------- song view ---------- */
.song-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.song-tools {
  position: sticky; top: calc(var(--topbar-h, 61px) + 6px); z-index: 10; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px; margin: 14px -4px 18px; border-radius: 16px; background: var(--bg-elev); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.seg-ctl { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg-ctl button { border: 0; background: transparent; min-width: 38px; height: 36px; cursor: pointer; font-weight: 800; }
.seg-ctl button:hover { background: var(--bg-sunk); }
.seg-ctl .val { padding: 0 10px; font-weight: 800; min-width: 52px; text-align: center; color: var(--accent); }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; cursor: pointer; padding: 0 6px; }
.toggle input { accent-color: var(--accent); width: 18px; height: 18px; }

.song { font-size: var(--song-size); line-height: 1.3; }
.cp-section { margin-bottom: 1.1em; break-inside: avoid; }
.cp-label { font-size: .7em; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: .3em; }
.cp-chorus { padding-left: .9em; border-left: 3px solid color-mix(in srgb, var(--accent) 50%, transparent); }
.cp-line { display: flex; flex-wrap: wrap; align-items: flex-end; margin: 0 0 .15em; }
.cp-seg { display: inline-flex; flex-direction: column; white-space: pre; }
.cp-ch { color: var(--chord); font-weight: 800; font-size: .82em; min-height: 1.25em; padding-right: .35em; }
.cp-solo .cp-ch { padding-right: .7em; }
.cp-ly { white-space: pre-wrap; }
.no-chords .cp-ch { display: none; }
.cp-gap { height: .7em; }
.cp-comment { font-size: .78em; font-style: italic; color: var(--muted); margin: .2em 0 .35em; }
.cp-grid { font-family: ui-monospace, Menlo, monospace; font-weight: 700; color: var(--chord); font-size: .85em; margin: .2em 0; white-space: pre-wrap; }

/* ---------- misc ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.qr { background: #fff; padding: 14px; border-radius: 16px; width: min(260px, 100%); margin: 6px auto; display: block; }
.qr svg, .qr img { width: 100%; height: auto; display: block; stroke: none; }
.linkbox { font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; padding: 10px 12px; background: var(--bg-sunk); border-radius: 10px; }
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal { width: min(440px, 100%); max-height: 90dvh; overflow: auto; }
.login { max-width: 460px; margin: 6vh auto 0; text-align: center; }
.login .brand-mark { width: 104px; height: 104px; border-radius: 28px; margin: 0 auto 18px; }
.print-logo { display: none; }
.match-row { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 12px 16px; }
.match-row + .match-row { border-top: 1px solid var(--line); }
.editor { display: grid; gap: 16px; }
@media (min-width: 900px) { .editor { grid-template-columns: 1fr 1fr; } .view.wide { max-width: 1200px; } }

/* ---------- songbook / print ---------- */
.songbook-song { margin-top: 34px; padding-top: 24px; border-top: 1px dashed var(--line); }
.songbook-song h2 { margin: 0 0 4px; font-size: 24px; }
.missing { border: 1px dashed var(--warn); border-radius: 14px; padding: 14px; color: var(--warn); }
@media print {
  @page { size: A4; margin: 16mm 14mm; }
  :root, :root[data-theme="dark"] { --bg: #fff; --text: #000; --muted: #444; --chord: #000; --line: #ccc; color-scheme: light; }
  body { padding: 0; background: #fff; }
  .topbar, .tabbar, .no-print, .song-tools, .toast { display: none !important; }
  .view { max-width: none; padding: 0; }
  .card { box-shadow: none; }
  .song { font-size: 12pt; }
  .cp-ch { font-weight: 800; }
  .songbook-song { border-top: 0; margin-top: 0; padding-top: 0; break-before: page; }
  .print-cover h1 { font-size: 30pt; }
  .print-logo { display: block; width: 34mm; height: auto; margin: 0 0 8mm; }
  a { text-decoration: none; }
}
