@font-face {
  font-family: "Oswald";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/oswald-500.woff2") format("woff2");
}

@font-face {
  font-family: "Oswald";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/oswald-700.woff2") format("woff2");
}

:root {
  /* Panel: brushed-black enclosure. Ink: silkscreen lettering.
     Amber is the "live" accent (chords, active controls); green is the
     pilot-light accent (status: downloaded, song structure markers). */
  --bg: #121214;
  --bg-2: #1b1b1e;
  --fg: #ececea;
  --fg-dim: #8f8f8a;
  --accent: #ffb020;
  --accent-ink: #1a1300;
  --led-green: #5fd97a;
  --led-red: #e0685f;
  --border: #313134;
  --chord: var(--accent);
  --section: var(--led-green);
  --font-display: "Oswald", "Arial Narrow", sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, "Cascadia Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  /* Faint brushed-panel texture — subtle enough to stay out of the way of
     reading chords, distinct enough to not read as flat dashboard-dark. */
  background-image:
    radial-gradient(ellipse 120% 60% at 50% 0%, rgba(255, 255, 255, 0.04), transparent 60%),
    repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.012) 0px, rgba(255, 255, 255, 0.012) 1px, transparent 1px, transparent 3px);
  background-color: var(--bg);
}

button, input {
  font-family: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.loading { padding: 2rem; color: var(--fg-dim); text-align: center; }

.app-header {
  position: sticky;
  top: 0;
  height: 52px;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  align-items: center;
  z-index: 10;
  backdrop-filter: saturate(140%) blur(8px);
  background: color-mix(in oklab, var(--bg) 85%, transparent);
}

.app-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.2rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
}

.app-header .count {
  margin-left: auto;
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
}

.app-header .back {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  line-height: 1;
}

.search {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  background: #0c0c0d;
  color: var(--fg);
  border-radius: 8px;
  font-size: 1rem;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

.search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5), 0 0 0 3px color-mix(in oklab, var(--accent) 25%, transparent);
}

.search-wrap { padding: 0.75rem 1rem 0.5rem; }

.sort-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.tc-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-dim);
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list li {
  border-bottom: 1px solid var(--border);
}

.list a {
  display: flex;
  flex-direction: column;
  padding: 0.9rem 1rem;
  color: var(--fg);
  text-decoration: none;
  min-height: 44px;
}

.list a:active { background: var(--bg-2); }

.list .title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.08rem;
  letter-spacing: 0.01em;
  line-height: 1.3;
}

.list .meta {
  font-size: 0.85rem;
  color: var(--fg-dim);
  margin-top: 0.25rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.list .badge {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  padding: 0.12rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg-dim);
}

/* Pilot light: always present, so offline-availability is a glance, not a
   click. Lit + glowing green when downloaded; a dim hollow ring otherwise. */
.dl-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--fg-dim);
  opacity: 0.55;
  /* Without this it's the first flex item to collapse on a narrow phone with
     a long unbreakable title — shrinking to a ~3px sliver. */
  flex: none;
}

.dl-error {
  margin: 0 1rem 0.75rem;
  font-size: 0.85rem;
  color: var(--led-red);
}

.dl-dot.lit {
  background: var(--led-green);
  border-color: var(--led-green);
  opacity: 1;
  box-shadow: 0 0 5px 1px color-mix(in oklab, var(--led-green) 65%, transparent);
}

.header-btn {
  appearance: none;
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: linear-gradient(180deg, #232326, #1a1a1c);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.65rem;
  font-size: 0.78rem;
  cursor: pointer;
  min-height: 36px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}

.header-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.header-btn.busy {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--accent) 25%, transparent);
}

.tab-view {
  padding: 0 1rem 4rem;
}

.tab-view header.song {
  padding: 1rem 0;
}

.tab-view header.song h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.6rem;
  line-height: 1.15;
}

.tab-view header.song .artist {
  color: var(--fg-dim);
  font-size: 1rem;
  margin-top: 0.3rem;
}

.tab-controls {
  position: sticky;
  top: 52px; /* matches .app-header's fixed height */
  z-index: 9;
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 1rem 0.75rem;
  margin: 0 -1rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  align-items: center;
  backdrop-filter: saturate(140%) blur(8px);
  background: color-mix(in oklab, var(--bg) 88%, transparent);
}

/* Re-blurring the sticky header/controls every frame while fast-scrolling
   fresh content underneath is expensive enough to stutter — drop it for the
   duration of auto-scroll (see startScroll/stopScroll in app.js). A slightly
   more opaque flat background keeps the bars readable without the blur. */
body.auto-scrolling .app-header,
body.auto-scrolling .tab-controls {
  backdrop-filter: none;
  background: color-mix(in oklab, var(--bg) 96%, transparent);
}

.tc-btn {
  appearance: none;
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: linear-gradient(180deg, #232326, #1a1a1c);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.tc-btn.tc-narrow {
  padding: 0.5rem 0.6rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.tc-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.tc-btn:active { transform: translateY(1px); }

.tc-group {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.15rem;
  background: var(--bg-2);
  touch-action: manipulation;
}

.tc-group .tc-btn {
  border: none;
  background: transparent;
  padding: 0.4rem 0.65rem;
  min-height: 40px;
}

.tc-group .tc-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 4px;
}

/* Signature: the auto-scroll control is a footswitch. It exists so hands
   stay on the guitar — engaging it should read like stomping a pedal on. */
#toggle-scroll[aria-pressed="true"] {
  box-shadow:
    0 0 0 3px color-mix(in oklab, var(--accent) 35%, transparent),
    0 0 14px 2px color-mix(in oklab, var(--accent) 55%, transparent);
  animation: led-pulse 1.8s ease-in-out infinite;
}

@keyframes led-pulse {
  0%, 100% {
    box-shadow:
      0 0 0 3px color-mix(in oklab, var(--accent) 30%, transparent),
      0 0 10px 1px color-mix(in oklab, var(--accent) 40%, transparent);
  }
  50% {
    box-shadow:
      0 0 0 3px color-mix(in oklab, var(--accent) 45%, transparent),
      0 0 18px 4px color-mix(in oklab, var(--accent) 65%, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  #toggle-scroll[aria-pressed="true"] { animation: none; }
}

.tc-val {
  display: inline-block;
  min-width: 2.5ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--led-green);
  font-size: 0.85rem;
  padding: 0.1rem 0.3rem;
  font-family: var(--font-mono);
  background: #0a0a0a;
  border-radius: 3px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6);
}

pre.tab-content,
.tab-content.wrapped {
  font-family: var(--font-mono);
  font-size: var(--tab-font-size, 0.9rem);
  line-height: 1.45;
  margin: 0;
  color: var(--fg);
  background: transparent;
}

pre.tab-content {
  /* Preserve exact whitespace + do not wrap: chord labels sit above lyric
     characters via column position, which only holds at a fixed width.
     Wrap in a scroll container so long lines scroll horizontally instead. */
  white-space: pre;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

pre.tab-content .section {
  color: var(--section);
  font-weight: 700;
}

pre.tab-content .chord {
  color: var(--chord);
  font-weight: 600;
}

/* Wrapped mode: alignment is structural (chord + word share one DOM node)
   instead of column-based, so it survives reflow at any width. */
.tab-content.wrapped .section {
  color: var(--section);
  font-weight: 700;
  margin: 0.5rem 0 0.15rem;
}

.tab-content.wrapped .plain-line {
  /* Credits/URL lines have no chord-anchored break points of their own — an
     unbroken long token (e.g. a source URL) would otherwise overflow the
     line's box without wrapping, and since nothing here clips horizontally
     the way .tab-block does, that spill escapes to the whole page and makes
     it pannable sideways, defeating the point of Wrap. */
  overflow-wrap: anywhere;
}

.tab-content.wrapped .plain-line .chord {
  color: var(--chord);
  font-weight: 600;
}

.tab-content.wrapped .blank-line {
  height: 0.9em;
}

.tab-content.wrapped .tab-block {
  font-family: var(--font-mono);
  font-size: inherit;
  white-space: pre;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.15rem 0;
}

.tab-content.wrapped .tab-block .chord {
  color: var(--chord);
  font-weight: 600;
}

.chord-line {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  margin: 0.1rem 0;
}

.chord-word {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  margin: 0 0.15em 0.3em 0;
}

.chord-word .chord {
  color: var(--chord);
  font-weight: 600;
  line-height: 1.3;
  min-height: 1.3em;
}

.chord-word .word {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.tab-meta {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  color: var(--fg-dim);
  font-size: 0.85rem;
  padding: 0.25rem 0 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.diagrams {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  padding: 0.5rem 0 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  color: var(--fg);
}

.chord-diagram {
  width: 64px;
  height: auto;
  color: var(--fg);
}

.official-fallback {
  padding: 1rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0.5rem 0;
}

.official-fallback p {
  color: var(--fg);
  margin: 0.5rem 0;
  font-size: 0.95rem;
}

.official-fallback .dim {
  color: var(--fg-dim);
  font-size: 0.85rem;
}

.official-preview {
  display: block;
  max-width: 100%;
  height: auto;
  background: #fff;
  border-radius: 6px;
  margin-top: 0.75rem;
}

.btn-link {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: var(--accent-ink) !important;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  min-height: 44px;
  line-height: 1.8;
}

.external {
  color: var(--accent);
  text-decoration: none;
}

.external:active { opacity: 0.7; }

.empty {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--fg-dim);
}

.empty h2 {
  margin-top: 0;
  font-family: var(--font-display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg);
}

.empty code {
  display: inline-block;
  background: var(--bg-2);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-family: var(--font-mono);
}

@media (min-width: 700px) {
  #app { max-width: 760px; margin: 0 auto; }
}
