:root {
  --bg: #f7f7f5;
  --fg: #1a1d1f;
  --muted: #707782;
  --accent: #cf6b83;
  --separator: #e6e8eb;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  --lyrics: 'Roboto Slab', 'Georgia', serif;
  --ui: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, Noto Sans, 'Apple Color Emoji', 'Segoe UI Emoji';
  --measure: 820px;
  --topbar-h: 56px;
  --topbar-gap: 56px;
  --icon-filter: none;
  --sticky-key-gap: 64px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.dark {
  --bg: #0e1013;
  --fg: #e7e7e7;
  --muted: #9fa6b0;
  --accent: #e89a3c;
  --separator: #1f2329;
  --icon-filter: brightness(0) invert(1);
}

main.container { max-width: var(--measure); margin: 0 auto; padding: calc(var(--topbar-h) + var(--space-4)) var(--space-5) var(--space-8); }
.is-song main.container { padding-top: var(--topbar-h); }
.topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 100; background: var(--bg); }
.topbar-row { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: var(--space-3); max-width: var(--measure); margin: 0 auto; padding: calc(8px + env(safe-area-inset-top)) var(--space-5) 8px; box-sizing: border-box; height: var(--topbar-h); }
.bar-spacer { height: 42px; }
.brand { display: inline-flex; align-items: center; text-decoration: none; color: var(--fg); font-family: var(--ui); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: 13px; }
.search { min-width: 0; position: relative; }
.search input { width: 100%; max-width: none; padding: 12px 44px 12px 14px; border-radius: 12px; border: 1px solid var(--separator); background: transparent; color: var(--fg); font-size: 16px; line-height: 1.2; }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.search .search-btn { position: absolute; top: 50%; right: 8px; transform: translateY(-50%); width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); display: inline-grid; place-items: center; padding: 0; }
.search .search-btn img { display: block; width: 20px; height: 20px; filter: var(--icon-filter); }
.search .search-btn:focus { outline: none; }
.search .search-btn:focus-visible { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.actions { display: flex; gap: var(--space-3); justify-self: end; }
.icon-btn { appearance: none; border: 0; background: transparent; color: var(--muted); padding: 10px; border-radius: 0; touch-action: manipulation; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:active { transform: translateY(1px); }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 12px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; z-index: 200; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-2px); }


.song-container { display: grid; gap: var(--space-6); }

.song { display: grid; gap: var(--space-3); }

.song-header { position: sticky; top: var(--topbar-h); padding: var(--space-2) 0 var(--space-1); background: var(--bg); z-index: 20; border-bottom: 1px solid var(--separator); }

.song-body { position: relative; }

.song-header { display: flex; align-items: center; gap: var(--space-3); }
.song-stack { width: 65%; display: grid; gap: 2px; align-content: center; }
.song-sub { color: var(--muted); font-size: 12px; }
.song-key { flex: 1; text-align: center; font-weight: 400; font-size: 12px; color: var(--muted); min-width: 96px; display: grid; grid-template-rows: auto auto auto; align-items: center; justify-items: center; gap: 2px; padding-top: 4px; padding-bottom: 2px; }
.song-links { width: 48px; flex-shrink: 0; display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.song-key .key-label { line-height: 1; padding: 0; }
.song-key .key-btn { padding: 4px; }
.song-key .icon { width: 16px; height: 16px; display: inline-block; background: currentColor; }
.song-key .icon-chev-up { -webkit-mask: url('https://cdn.jsdelivr.net/npm/@tabler/icons@3.11.0/icons/outline/chevron-up.svg') no-repeat center / contain; mask: url('https://cdn.jsdelivr.net/npm/@tabler/icons@3.11.0/icons/outline/chevron-up.svg') no-repeat center / contain; }
.song-key .icon-chev-down { -webkit-mask: url('https://cdn.jsdelivr.net/npm/@tabler/icons@3.11.0/icons/outline/chevron-down.svg') no-repeat center / contain; mask: url('https://cdn.jsdelivr.net/npm/@tabler/icons@3.11.0/icons/outline/chevron-down.svg') no-repeat center / contain; }
.song-key { position: relative; }
.song-key .key-label { cursor: pointer; user-select: none; }
/* hide transpose chevrons; picker-only selection */
.song-key .transpose-btn { display: none !important; }
.key-popover {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translate(-50%, 8px);
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--separator);
  box-shadow: none;
  border-radius: 8px;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(4, 32px);
  grid-auto-rows: 32px;
  gap: 6px;
  justify-content: center;
  z-index: 40;
}
.key-option {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  text-align: center;
}
.key-option.active {
  background: var(--accent);
  color: var(--bg);
}

.song-title {
  font-family: var(--lyrics);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 0.2px;
}

.song-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.song-meta .dot::before {
  content: '·';
  margin: 0 8px;
}


.icon-link { color: var(--muted); text-decoration: none; }
.icon-link:active { transform: translateY(1px); }

/* external icons */
.icon-btn img { display: block; width: 26px; height: 26px; filter: var(--icon-filter); }
.song-links img { width: 20px; height: 20px; display: block; filter: none; }

/* streaming icons via CSS masks (CDN sources) */
.icon-link.youtube, .icon-link.spotify { width: 20px; height: 20px; display: inline-block; background: currentColor; }
.icon-link.youtube { -webkit-mask: url('https://cdn.jsdelivr.net/npm/@tabler/icons@3.11.0/icons/outline/brand-youtube.svg') no-repeat center / contain; mask: url('https://cdn.jsdelivr.net/npm/@tabler/icons@3.11.0/icons/outline/brand-youtube.svg') no-repeat center / contain; }
.icon-link.spotify { -webkit-mask: url('https://cdn.jsdelivr.net/npm/@tabler/icons@3.11.0/icons/outline/brand-spotify.svg') no-repeat center / contain; mask: url('https://cdn.jsdelivr.net/npm/@tabler/icons@3.11.0/icons/outline/brand-spotify.svg') no-repeat center / contain; }

.song-section { scroll-margin-top: calc(var(--topbar-h) + var(--sticky-key-gap)); }

.section-header { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); position: static; top: auto; z-index: auto; background: transparent; margin: var(--space-7) 0 var(--space-3); padding: 0; }

/* remove blur under sticky headers */
.song-header::after, .section-header::after { content: none; }

pre.chords, pre.lyrics { white-space: pre; }

pre.chords {
  margin: 0;
  font-family: var(--mono);
  color: var(--accent);
  font-size: 14px;
  line-height: 1.3;
}

pre.lyrics {
  margin: 0 0 var(--space-4) 0;
  font-family: var(--lyrics);
  font-weight: 600;
  font-size: 17px;
  line-height: 1.4;
}

pre.chords + pre.lyrics { margin-top: var(--space-1); }

.song-section + .song-section { margin-top: var(--space-8); }

.song-separator { border: 0; height: 1px; margin: var(--space-7) auto; width: clamp(160px, 40%, 220px); background: color-mix(in srgb, var(--fg) 16%, transparent); }

.font-large { font-size: 1.1rem; }
.font-normal { font-size: 1rem; }

/* search results */
.results { display: grid; gap: var(--space-2); }
.result-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: var(--space-2); padding: var(--space-2) 0; border-radius: 0; }
.result-main { display: grid; gap: var(--space-1); text-decoration: none; color: inherit; }
.result-main .result-link,
.result-main .result-link:visited,
.result-main .result-link:hover,
.result-main .result-link:active {
  text-decoration: none;
  color: inherit;
  display: grid;
  gap: 4px;
}
.result-main .result-link[aria-disabled="true"] { pointer-events: none; }
.result-main .list-title { font-family: var(--lyrics); font-weight: 600; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-main .list-meta { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: var(--space-2); }
.result-main .result-links { display: flex; gap: var(--space-2); margin-top: 2px; }
.selected-list .list-title { font-family: var(--lyrics); font-weight: 600; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.selected-list .list-artist { color: var(--muted); font-size: 12px; }
.result-main .song-meta .dot::before { content: '·'; margin: 0 var(--space-2); }
.result-actions { display: flex; gap: var(--space-3); }

/* plus button */
.plus-btn { border: 0; border-radius: 8px; width: 32px; height: 32px; font-weight: 700; color: var(--muted); background: transparent; padding: 0; line-height: 32px; font-size: 20px; }
.plus-btn.is-active { background: var(--accent); color: var(--bg); }

/* selected panel visibility */
.is-hidden { display: none !important; }

/* setlist selection UI */
.selected-panel { display: grid; gap: var(--space-1); margin-bottom: var(--space-2); padding-bottom: var(--space-2); }
.selected-header { display: grid; grid-template-columns: 1fr auto; align-items: baseline; }
.selected-title { font-weight: 600; font-size: 13px; color: var(--muted); }
.selected-actions { display: flex; gap: var(--space-4); }
.selected-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.selected-item { display: grid; grid-template-columns: 1fr 96px auto; align-items: center; gap: var(--space-3); padding: 0; border-radius: 0; min-height: 44px; }
.selected-controls { display: inline-flex; gap: var(--space-2); }
.drag-handle { width: 32px; height: 32px; cursor: grab; color: var(--muted); font-size: 18px; display: inline-grid; place-items: center; }
.drag-handle:active { cursor: grabbing; }
.selected-item.drag-hide { display: none; }
.drop-placeholder { height: 44px; border-radius: 8px; background: color-mix(in srgb, var(--fg) 8%, transparent); transition: transform 80ms ease, background-color 120ms ease; }
.selected-item.drag-hide ~ .drop-placeholder { transform: scaleY(1.02); }
.selected-item .sel-stack { min-width: 0; display: grid; gap: var(--space-1); }
.selected-item .sel-key { position: relative; width: 96px; display: inline-flex; align-items: center; justify-content: center; padding: 0; text-align: center; grid-column: auto; grid-row: auto; }
.selected-item .sel-key .key-label { margin: 0; line-height: 1; white-space: nowrap; color: var(--muted); font-size: 12px; font-weight: 400; cursor: pointer; user-select: none; }
.selected-item .song-stack { min-width: 0; display: inline-flex; align-items: center; gap: var(--space-2); }
.selected-item .song-title, .selected-item .song-meta { white-space: nowrap; }

.remove-btn { width: 32px; height: 32px; line-height: 32px; font-size: 20px; border-radius: 8px; }
.result-actions .plus-btn, .remove-btn { display: inline-grid; place-items: center; }

/* do not recolor the entire row on selection; only the plus button changes */
.result-row.selected { outline: none; }

/* centered hero */
.search-hero { display: none; place-items: center; min-height: calc(100dvh - var(--topbar-h)); }
.search-large input { padding: var(--space-4) 56px var(--space-4) var(--space-4); font-size: 18px; border-radius: 12px; }
.hero-center { display: grid; gap: 12px; justify-items: center; }
.hero-hint { color: var(--muted); font-size: 13px; }

.search-header { position: sticky; top: var(--topbar-h); background: var(--bg); z-index: 15; padding: var(--space-3) 0 var(--space-2); }
.results { margin-top: var(--space-3); }
.selected-list .song-title { font-size: 16px; }
.selected-item .song-meta { font-size: 12px; }

@media (min-width: 720px) {
  .song-title { font-size: 20px; }
  pre.chords { font-size: 15px; }
  pre.lyrics { font-size: 18px; }
}

@media print {
  form, nav, header, footer { display: none !important; }
}
