/* Tokens. Dark by default; light under prefers-color-scheme. All colours OKLCH. */
:root {
  color-scheme: dark light;
  --hue: 60;
  --bg: #17140f;
  --bg: oklch(0.18 0.012 var(--hue));
  --surface: oklch(0.22 0.014 var(--hue));
  --surface-2: oklch(0.26 0.016 var(--hue));
  --edge: oklch(from var(--surface) calc(l + 0.08) calc(c * 0.8) h);
  --text: oklch(0.93 0.012 var(--hue));
  --muted: oklch(0.70 0.018 var(--hue));
  --accent: oklch(0.80 0.14 70);
  --accent-ink: oklch(0.22 0.04 70);
  --chord: oklch(0.82 0.13 70);
  --chip: oklch(from var(--surface) calc(l + 0.05) calc(c + 0.01) h);
  --shadow-tint: oklch(0.08 0.02 var(--hue));
  --shadow:
    0 1px 1px color-mix(in oklch, var(--shadow-tint) 40%, transparent),
    0 2px 4px color-mix(in oklch, var(--shadow-tint) 30%, transparent),
    0 8px 20px color-mix(in oklch, var(--shadow-tint) 25%, transparent);
  --radius: 12px;
  --gutter: 16px;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: oklch(0.97 0.008 var(--hue));
    --surface: oklch(0.995 0.004 var(--hue));
    --surface-2: oklch(0.95 0.01 var(--hue));
    --edge: oklch(from var(--surface) calc(l - 0.09) calc(c + 0.01) h);
    --text: oklch(0.24 0.02 var(--hue));
    --muted: oklch(0.50 0.02 var(--hue));
    --accent: oklch(0.62 0.15 55);
    --accent-ink: oklch(0.99 0.01 55);
    --chord: oklch(0.52 0.15 45);
    --chip: oklch(0.94 0.02 var(--hue));
    --shadow-tint: oklch(0.45 0.04 var(--hue));
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  min-height: 100dvh;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }

/* Top bar */
.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px max(var(--gutter), env(safe-area-inset-left));
  border-bottom: 1px solid var(--edge);
}
.brand { font-weight: 650; text-decoration: none; letter-spacing: -0.01em; }
.bar-link { margin-left: auto; color: var(--muted); text-decoration: none; }
.bar-link:hover { color: var(--text); }

.page { max-width: 760px; margin: 0 auto; padding: 24px var(--gutter) 64px; }

/* Search */
.search input {
  width: 100%;
  padding: 14px 18px;
  font-size: 1.15rem;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  outline: none;
}
.search input:focus { border-color: var(--accent); }
.search input::-webkit-search-cancel-button { filter: grayscale(1); opacity: 0.6; }
.search.htmx-request input { border-color: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { border-color: var(--edge); } }

.notice { color: var(--muted); margin: 24px 4px; }

.results, .history, .favourites { list-style: none; margin: 16px 0 0; padding: 0; }
.result {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "title chips" "artist chips";
  column-gap: 16px;
  padding: 12px 14px;
  border-radius: var(--radius);
  text-decoration: none;
}
.result:hover, .result:focus-visible { background: var(--surface); outline: none; }
.result-title { grid-area: title; font-weight: 600; }
.result-artist { grid-area: artist; color: var(--muted); font-size: 0.92rem; }
.chips { grid-area: chips; display: flex; flex-wrap: wrap; justify-content: flex-end; align-content: center; gap: 6px; }
.chip {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}
.chip b { color: var(--text); font-weight: 600; }

@media (max-width: 560px) {
  .result { grid-template-columns: 1fr; grid-template-areas: "title" "artist" "chips"; }
  .chips { justify-content: flex-start; margin-top: 6px; }
}

.history li a {
  display: block;
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
}
.history li a:hover { background: var(--surface); color: var(--text); }

/* Song page */
.song-page { max-width: 1400px; margin: 0 auto; padding: 20px var(--gutter) 64px; }
.song-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.song-head h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.02em; line-height: 1.2; }
.song-head .artist { color: var(--muted); font-size: 1.1rem; }
.fav {
  margin-left: auto;
  background: none;
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  color: var(--muted);
}
.fav[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

.song-grid { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1024px) {
  .song-grid { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; }
  .media { position: sticky; top: 16px; }
}

.video {
  aspect-ratio: 16 / 9;
  width: 100%;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  display: block;
}
.video-form { display: flex; gap: 8px; margin-top: 12px; }
.video-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 8px;
}
.btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: var(--surface-2);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.links { margin-top: 12px; color: var(--muted); font-size: 0.92rem; }
.links a { color: var(--muted); }

.tab-panel {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}
.tab-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--edge);
}
.tab-tools select {
  max-width: 100%;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--edge);
  border-radius: 8px;
}
.meta { color: var(--muted); font-size: 0.9rem; display: flex; gap: 12px; flex-wrap: wrap; }
.meta b { color: var(--text); font-weight: 600; }
.transpose { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.transpose button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: var(--surface-2);
  cursor: pointer;
  font-weight: 600;
}
.transpose button:hover { border-color: var(--accent); }
.transpose output { min-width: 3ch; text-align: center; font-variant-numeric: tabular-nums; }
.capo-hint { color: var(--accent); font-size: 0.9rem; }

.tab-body {
  margin: 0;
  padding: 16px;
  font: 14px/1.55 var(--mono);
  white-space: pre;
  overflow-x: auto;
  tab-size: 4;
}
@media (max-width: 560px) { .tab-body { font-size: 12.5px; padding: 12px; } }
.chord { color: var(--chord); font-weight: 700; }
.stale { padding: 8px 14px; color: var(--muted); font-size: 0.85rem; border-bottom: 1px solid var(--edge); }

/* Login */
.login {
  max-width: 320px;
  margin: 18vh auto 0;
  display: grid;
  gap: 10px;
}
.login input {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 10px;
}
.login button {
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  cursor: pointer;
}
.errors { color: var(--chord); margin: 0; }
