:root {
  /* Palette (binding — see features/_design.md) */
  --bg:         #FAF6F0;
  --text:       #3A3A3A;
  --muted:      #888481;
  --border:     rgba(0, 0, 0, 0.08);

  /* Pastel accents — tag chips, section pills, card backgrounds */
  --c-sage:     #D6EADF;
  --c-peach:    #F7D7C4;
  --c-lavender: #E0D7F0;
  --c-butter:   #F5E6B8;
  --c-sky:      #CFE2F0;

  --accent:     #6F8C84;            /* muted teal — links, focus, include */
  --star-on:    #f1c40f;
  --star-off:   rgba(0, 0, 0, 0.18);
  --exclude:    #C97B7B;            /* dusty rose — excluded chip, destructive */

  /* Fonts */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* ============================================================
   Reset + page baseline
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}
/* Reserve the vertical scrollbar gutter at all times so the page doesn't
   shift right when the list shortens and the scrollbar disappears. */
html { scrollbar-gutter: stable; }
/* Global `hidden` rule with `!important` so component classes that set
   `display: inline-flex` / `flex` / `grid` don't silently override the UA's
   `[hidden] { display: none }` (this used to bite `.capo-badge`). */
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }
a:hover { filter: brightness(0.9); }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ============================================================
   Header (global, both domains)
   ============================================================ */
.site-header {
  padding: 1.4rem 1rem 0.6rem;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-title {
  text-decoration: none;
  color: var(--text);
}
.site-title h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  text-decoration: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.55);
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-size: 0.9rem;
  transition: filter 0.12s ease;
}
.header-link:hover { filter: brightness(0.97); }

.header-pdf[data-status="running"] {
  color: var(--muted);
}
.header-pdf[data-status="failed"] {
  color: var(--exclude);
}
.header-pdf[data-status="done"] {
  color: var(--text);
}

.header-pdf-icon,
.header-pdf-text {
  display: inline-block;
}

.header-fav {
  color: var(--text);
}

/* Wake-lock toggle in header (visible only if the API is supported) */
.header-wake {
  border: none;
  cursor: pointer;
  appearance: none;
  font: inherit;
  color: var(--muted);
}
.header-wake.header-wake-on {
  color: var(--star-on);
  background: rgba(241, 196, 15, 0.18);
}
.header-wake-icon { font-size: 1rem; line-height: 1; }
.header-fav-icon {
  color: var(--star-on);
}
.header-fav-count {
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Main container
   ============================================================ */
main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}

h1 { font-size: 1.8rem; font-weight: 600; margin: 0.4rem 0 0.8rem; }
h2 { font-size: 1.2rem; font-weight: 600; margin: 1rem 0 0.4rem; }
p  { margin: 0.5rem 0; }

/* ============================================================
   Home: search + filter row
   ============================================================ */
.page-home .home-filters {
  display: block;
  max-width: 800px;        /* match .song-grid width */
  margin: 0 auto 1rem;
}

.home-search {
  display: block;
  width: 100%;
  padding: 0.7rem 1rem;
  margin: 0.25rem 0 0.9rem;
  font: inherit;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
}
.home-search:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}
.home-search::placeholder { color: var(--muted); }

.home-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 1rem;
}

/* ============================================================
   Tag chip — tri-state via class names (.chip-include / .chip-exclude)
   ------------------------------------------------------------
   Per-tag chip color: deterministic via hash → JS sets a
   `color-<name>` class. Cycling via :nth-child is the fallback.
   ============================================================ */
.chip {
  --chip-color: var(--c-sage);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--chip-color);
  border: 2px solid transparent;
  line-height: 1.2;
  cursor: pointer;
  transition: filter 0.12s ease, opacity 0.12s ease;
  user-select: none;
}
.chip:hover { filter: brightness(0.97); }

/* Per-name colors (set by JS as color-sage / color-peach / etc.) */
.color-sage     { --chip-color: var(--c-sage); }
.color-peach    { --chip-color: var(--c-peach); }
.color-lavender { --chip-color: var(--c-lavender); }
.color-butter   { --chip-color: var(--c-butter); }
.color-sky      { --chip-color: var(--c-sky); }

/* Fallback deterministic cycle when no color-* class is present */
.home-chips .chip-tag:nth-child(5n+1) { --chip-color: var(--c-sage); }
.home-chips .chip-tag:nth-child(5n+2) { --chip-color: var(--c-peach); }
.home-chips .chip-tag:nth-child(5n+3) { --chip-color: var(--c-lavender); }
.home-chips .chip-tag:nth-child(5n+4) { --chip-color: var(--c-butter); }
.home-chips .chip-tag:nth-child(5n+5) { --chip-color: var(--c-sky); }

/* Tri-state */
.chip-include {
  border-color: var(--accent);
  font-weight: 600;
}

.chip-exclude {
  background: #fff;
  border-color: var(--exclude);
  color: var(--exclude);
  text-decoration: line-through;
}

/* The JS bakes the ✓/✕ glyph into textContent — no ::before needed.
   But keep them defensively in case the glyph is stripped, so the
   visual marker is still apparent via the border/color shift above. */

.chip-dim { opacity: 0.55; }

/* Favorites tri-state chip — neutral / include / exclude */
.chip-fav {
  --chip-color: rgba(255, 255, 255, 0.55);
  border-color: var(--border);
}
.chip-fav.chip-include {
  --chip-color: var(--star-on);
  color: #4a3a00;
  border-color: var(--star-on);
  text-decoration: none;
}
.chip-fav.chip-exclude {
  background: #fff;
  --chip-color: transparent;
  border-color: var(--exclude);
  color: var(--exclude);
  text-decoration: line-through;
}

/* Clear-all-filters chip (only rendered when at least one tag is active) */
.chip-clear {
  --chip-color: transparent;
  border-color: var(--exclude);
  color: var(--exclude);
}

/* ============================================================
   Song grid (home)
   ============================================================ */
.song-grid {
  margin: 0 auto;
  padding: 0;
  max-width: 800px;
  list-style: none;
  display: flex;
  flex-direction: column;
}

.song-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.25rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: background 0.12s ease;
}
.song-row:first-child { border-top: 1px solid var(--border); }
.song-row:hover { background: rgba(0, 0, 0, 0.025); }

.song-row-main {
  min-width: 0;
  display: block;
}

.song-row-title {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.song-row-author {
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.song-row-meta {
  margin-top: 0.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  align-items: center;
}

/* Small tag pill used in song-row meta and song-meta */
.tag-pill {
  --chip-color: var(--c-sage);
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--text);
  background: var(--chip-color);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.capo-badge-sm {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--c-butter);
  color: var(--text);
  font-weight: 600;
  font-size: 0.75rem;
}

/* ============================================================
   Star button (off/on)
   ============================================================ */
.star-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  min-width: 44px;                        /* mobile hit area */
  min-height: 44px;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--star-off);
  background: none;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  transition: color 0.12s ease, background 0.12s ease, transform 0.12s ease;
}
.star-btn:hover { background: rgba(255, 255, 255, 0.4); }
.star-btn[aria-pressed="true"],
.star-btn.star-on { color: var(--star-on); }
.star-btn[aria-pressed="true"]:hover,
.star-btn.star-on:hover { color: #d4a800; }

/* Detail-page star is larger */
.star-btn.star-lg {
  font-size: 1.8rem;
  width: 2.8rem;
  height: 2.8rem;
}

/* ============================================================
   Empty / loading states
   ============================================================ */
.empty-state,
.loading-placeholder {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
  font-size: 1rem;
}

/* ============================================================
   Song detail
   ============================================================ */
.page-song {
  max-width: 800px;   /* default: matches the home list */
  margin: 0 auto;
}
/* Toggle: widen to header width (1100px) so the body can go two-column. */
.page-song-wider {
  max-width: 1100px;
}

/* The width toggle row sits below the body, after the column rule ends. */
.song-wider-row {
  display: flex;
  justify-content: center;
  margin: 0.4rem 0 1.2rem;
}
.song-wider-btn {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  padding: 0.2rem 0.9rem;
  border-radius: 999px;
  transition: background 0.12s ease, color 0.12s ease;
}
.song-wider-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text);
}
/* Active (wide mode is on): subtle persistent background to indicate state. */
.page-song-wider .song-wider-btn {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text);
}
.page-song-wider .song-wider-btn:hover {
  background: rgba(0, 0, 0, 0.09);
}
.song-wider-btn svg { display: block; }

/* Width toggle only makes sense when the body is actually two columns —
   hide the whole row below the 2-col viewport threshold. */
@media (max-width: 1099px) {
  .song-wider-row { display: none; }
}

/* Prev / next arrows flank the song header in a 3-column grid.
   Header fills the available middle column (matches page-song width).
   The bottom border lives on the row so it spans the arrows too. */
.song-nav-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.song-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  min-height: 3rem;
  align-self: stretch;        /* fill the full song-header height */
  border-radius: 14px;
  color: var(--muted);
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}
.song-nav-btn svg {
  display: block;     /* drops inline baseline, so flex centering is exact */
}
.song-nav-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text);
}
.song-nav-btn.song-nav-disabled {
  opacity: 0.25;
  pointer-events: none;
  cursor: default;
}

.song-header {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4rem 0.2rem 0.8rem;
}

.song-header-main {
  flex: 1;
  min-width: 0;
}

.song-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.song-title {
  display: inline;
  font-size: 1.6rem;
  font-weight: 600;
  margin: 0 0 0.15rem;
  line-height: 1.25;
}

.song-author {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.song-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.capo-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--c-butter);
  color: var(--text);
  font-weight: 600;
  font-size: 0.8rem;
}
/* Global `[hidden]` rule (top of stylesheet) now handles inline-flex etc. */

.time-sig,
.meta-label {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text);
}

/* ============================================================
   Controls (mode + transpose)
   ============================================================ */
.song-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin: 0.5rem 0 1.2rem;
}

/* Capo badge + transpose controls stay glued together (no gap) */
.capo-trans-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Mode segmented control — connected pills */
.mode-switch {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  gap: 0;
}
.mode-btn {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.mode-btn:hover { background: rgba(255, 255, 255, 0.6); }
.mode-btn-on {
  background: var(--accent);
  color: #fff;
}
.mode-btn-on:hover { background: var(--accent); color: #fff; }

/* Transpose */
.transpose-ctrl {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
}
.transpose-btn,
.transpose-offset {
  appearance: none;
  border: none;
  background: transparent;
  min-width: 2.2rem;
  height: 2.2rem;
  padding: 0 0.7rem;
  border-radius: 999px;
  font-size: 1rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.transpose-btn:hover,
.transpose-offset:hover { background: rgba(255, 255, 255, 0.6); }
.transpose-btn { font-weight: 600; font-size: 1.2rem; }
.transpose-offset {
  font-family: var(--font-mono);
  font-weight: 600;
  min-width: 2.6rem;
}
.transpose-offset[data-offset="0"] { color: var(--muted); font-weight: 400; }

/* ============================================================
   Song body — chord/lyric rendering
   ============================================================ */
.song-body {
  max-width: 800px;
  margin: 0 auto;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
}

/* When the user widens the page, body fills the wider canvas. */
.page-song-wider .song-body {
  max-width: none;
}

/* Two-column layout above the column threshold — applies whether narrow or
   wide. Column breaks only allowed at blank lines (.ln-empty); every non-empty
   line refuses a break before it, so contiguous sections stay together.
   A blank line landing at the top of column 2 is accepted as the price of
   never splitting a verse mid-section. */
@media (min-width: 1100px) {
  .song-body {
    column-count: 2;
    column-gap: 2.5rem;
    column-rule: 1px solid var(--border);
  }
  .song-body > :not(.ln-empty) {
    break-before: avoid;
    break-inside: avoid;
  }
}

.ln-empty {
  height: 1.2em;
  min-height: 1.2em;
  margin: 0;
}

/* Stanza (chord + lyric block row) — segments are self-contained chord+lyric
   inline-blocks, so they can wrap to the next line on narrow screens without
   breaking chord alignment. Each chord still sits over its own lyric chunk. */
.ln-stanza {
  margin: 0;
}

/* Each chord/lyric segment is an inline-block with chord stacked above lyric */
.seg {
  display: inline-block;
  vertical-align: top;
  font-family: var(--font-mono);
}

/* The seg right before a wrap is the positioning context for its marker */
.seg.precedes-wrap {
  position: relative;
}
/* Marker sits just past the right edge of the pre-wrap seg, aligned with
   the lyric row. Absolutely positioned → doesn't grow the seg or push later
   segs around, so the wrap detection itself stays stable. */
.wrap-mark {
  position: absolute;
  left: 100%;
  bottom: 0;
  color: var(--muted);
  opacity: 0.6;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding-left: 0.1em;
  user-select: none;
  pointer-events: none;
}

.chord {
  display: block;
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.2;
  min-height: 1.2em;
  white-space: pre;
}

.lyric {
  display: block;
  font-family: var(--font-sans);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;
  /* `pre` so trailing spaces survive — they're the boundary between segments */
  white-space: pre;
}

/* Bare chord row (no lyrics) */
.ln-chord-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0.2em 0;
}
.chord-row-inner {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.chord-pill {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--accent);
  font-weight: 600;
}

.repeat-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--c-butter);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
}

/* Plain text line */
.ln-text {
  color: var(--text);
  white-space: pre-wrap;
  margin: 0;
}

/* Section markers — plain bracketed text like the source ([chorus], [verse1]) */
.ln-section-ref,
.ln-tag {
  margin: 0.6em 0 0.2em;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Inline section marker inside a chord row (e.g. `[solo] G Em H C [2x]`) */
.inline-tag {
  color: var(--muted);
}

/* ============================================================
   404 page
   ============================================================ */
.page-404 {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

/* ============================================================
   PDFs page
   ============================================================ */
.page-pdfs .pdfs-heading {
  margin-top: 0.6rem;
  font-size: 1.3rem;
  color: var(--text);
}

.pdfs-banner {
  background: var(--c-peach);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
  color: var(--text);
  font-size: 0.9rem;
}
.pdfs-banner-error {
  background: #fff;
  border: 1px solid var(--exclude);
  color: var(--exclude);
}

.pdfs-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 640px) {
  .pdfs-grid {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  }
}

.pdf-layout {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem 1rem;
}

.pdf-layout-title {
  margin: 0 0 0.6rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.pdf-file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.pdf-file {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 10px;
  font-size: 0.92rem;
}

.pdf-file-label {
  font-weight: 500;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-file-action {
  flex-shrink: 0;
}

.pdf-download {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.pdf-download:hover { text-decoration: underline; }

.pdf-pending {
  color: var(--muted);
  font-style: italic;
}

/* ============================================================
   Mobile tweaks
   ============================================================ */
@media (max-width: 640px) {
  main { padding: 0.75rem; }
  .site-header { padding: 1rem 0.75rem 0.4rem; }
  .site-title h1 { font-size: 1.1rem; }
  .header-link { padding: 0.25rem 0.6rem; font-size: 0.85rem; }

  .song-row { padding: 0.7rem 0.15rem; }

  .song-title { font-size: 1.4rem; }

  .song-controls {
    flex-direction: column;
    align-items: flex-start;       /* no full-width stretch */
  }
  .mode-switch {
    align-self: flex-start;        /* match transposition's left alignment */
    width: auto;
  }
  .transpose-ctrl, .capo-trans-wrap { align-self: flex-start; }

  .song-nav-row { gap: 0.25rem; }
  .song-nav-btn { width: 2.4rem; height: 2.4rem; }
  .song-nav-btn svg { width: 18px; height: 18px; }
}

/* ============================================================
   Print — keep title, author, body; drop chrome
   ============================================================ */
@media print {
  :root {
    --bg: #fff;
    --text: #000;
    --muted: #444;
    --accent: #000;
  }

  body { background: #fff; color: #000; }

  .site-header,
  .song-controls,
  .song-nav-row,
  .song-wider-row,
  .home-filters,
  .home-chips,
  .home-search,
  .star-btn,
  .pdfs-banner,
  nav { display: none !important; }

  main { max-width: none; padding: 0; }

  .page-song { max-width: none; }

  .song-header {
    padding: 0;
    border-bottom: 1px solid #999;
    margin-bottom: 0.6rem;
  }
  .song-title { font-size: 1.3rem; }
  .song-author { font-size: 0.95rem; }

  .song-body {
    max-width: none;
    font-size: 0.9rem;
  }

  .chord { color: #000; }
  .chord-pill,
  .capo-badge,
  .capo-badge-sm,
  .tag-pill,
  .repeat-badge {
    background: transparent !important;
    border: 1px solid #000;
    color: #000 !important;
  }

  a { color: #000; text-decoration: none; }
}
