:root, :root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f4ed;
  --surface: #fffdf8;
  --text: #25241f;
  --muted: #6b685f;
  --line: #d9d3c7;
  --accent: #315f4c;
  --accent-text: #fff;
  --danger: #a62d2d;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151513;
  --surface: #201f1b;
  --text: #f4f0e7;
  --muted: #b6b0a5;
  --line: #454239;
  --accent: #82b89e;
  --accent-text: #10251c;
  --danger: #ff8b87;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #151513;
    --surface: #201f1b;
    --text: #f4f0e7;
    --muted: #b6b0a5;
    --line: #454239;
    --accent: #82b89e;
    --accent-text: #10251c;
    --danger: #ff8b87;
  }
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; color: var(--text); background: var(--bg); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { min-height: 44px; border: 1px solid var(--accent); border-radius: .65rem; padding: .6rem .9rem; color: var(--accent-text); background: var(--accent); cursor: pointer; }
button:hover { filter: brightness(1.06); }
button:disabled { cursor: not-allowed; opacity: .45; }
button.secondary, .tab, .icon-button { color: var(--text); border-color: var(--line); background: var(--surface); }
a { color: var(--accent); }
input { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: .65rem; padding: .7rem .8rem; color: var(--text); background: var(--surface); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 65%, transparent); outline-offset: 3px; }
[hidden] { display: none !important; }

.skip-link { position: fixed; z-index: 20; left: 1rem; top: -5rem; padding: .75rem; color: var(--accent-text); background: var(--accent); }
.skip-link:focus { top: 1rem; }
.site-header { display: flex; align-items: end; justify-content: space-between; gap: 1rem; max-width: 70rem; margin: auto; padding: 1.5rem clamp(1rem, 4vw, 2rem) 1rem; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.55rem, 4vw, 2.25rem); }
h2 { margin-bottom: 0; }
nav { display: flex; align-items: center; gap: .4rem; }
.tab[aria-current="page"] { color: var(--accent-text); border-color: var(--accent); background: var(--accent); }
.theme-switcher { display: flex; padding: 2px; border: 1px solid var(--line); border-radius: .8rem; background: var(--surface); }
.theme-switcher button { display: grid; place-items: center; width: 44px; min-height: 44px; padding: 0; color: var(--muted); border: 0; border-radius: .6rem; background: transparent; }
.theme-switcher button[aria-pressed="true"] { color: var(--accent-text); background: var(--accent); box-shadow: 0 1px 3px rgb(0 0 0 / .18); }
.theme-switcher svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
main { max-width: 70rem; margin: auto; padding: 1rem clamp(1rem, 4vw, 2rem) 4rem; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1rem 0; }
.retry { margin-bottom: 1rem; }
.search-label, .playlist-form label { display: block; margin-bottom: .4rem; font-weight: 650; }
.status { min-height: 1.5rem; margin: .75rem 0; color: var(--muted); }
.status.error { color: var(--danger); }

.song-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr)); gap: .7rem; margin: 0; padding: 0; list-style: none; }
.song-row { display: flex; align-items: stretch; gap: .4rem; }
.song-open { display: grid; grid-template-columns: auto minmax(0, 1fr); flex: 1; align-items: baseline; gap: .6rem; min-width: 0; padding: .75rem; color: var(--text); border-color: var(--line); text-align: left; background: var(--surface); transition: border-color .15s, box-shadow .15s, transform .15s; }
.song-open:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); box-shadow: 0 3px 10px rgb(0 0 0 / .07); transform: translateY(-1px); filter: none; }
.song-number { color: var(--accent); font-weight: 800; font-variant-numeric: tabular-nums; }
.song-name { overflow: hidden; font-weight: 550; text-overflow: ellipsis; white-space: nowrap; }
.app-links { display: none; align-items: center; gap: .8rem; width: min(calc(100% - 2rem), 66rem); margin: 0 auto; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: .75rem; background: var(--surface); }
.playlist-form { max-width: 38rem; margin: 1.25rem 0; }
.playlist-form > div { display: flex; gap: .5rem; }
.playlist-list { display: grid; gap: .75rem; }
.playlist-card { padding: .8rem; border: 1px solid var(--line); border-radius: .8rem; background: var(--surface); }
.playlist-summary { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.playlist-open { flex: 1; min-width: 12rem; text-align: left; }
.playlist-edit { color: var(--text); border-color: var(--line); background: transparent; }
.danger { color: var(--danger); border-color: currentColor; background: transparent; }
.occurrence-list { margin: .8rem 0 0; padding: 0; list-style: none; }
.occurrence { display: grid; grid-template-columns: minmax(0, 1fr) repeat(3, 44px); align-items: center; gap: .3rem; padding: .35rem 0; border-top: 1px solid var(--line); }
.occurrence span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.occurrence button { padding: 0; color: var(--text); border-color: var(--line); background: transparent; }

.picker { width: min(32rem, calc(100% - 2rem)); max-height: min(80dvh, 42rem); padding: 1rem; border: 1px solid var(--line); border-radius: 1rem; color: var(--text); background: var(--surface); }
dialog::backdrop { background: rgb(0 0 0 / .6); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.dialog-heading h2 { margin: 0; }
.icon-button { flex: 0 0 44px; width: 44px; padding: 0; font-size: 1.5rem; }
.picker-list { display: grid; gap: .5rem; margin-top: 1rem; }
.picker-list button { text-align: left; }

.presentation { width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); border: 0; color: #fff; background: #050505; overflow: hidden; }
.presentation[open] { display: grid; grid-template: auto minmax(0, 1fr) / auto minmax(0, 1fr) auto; gap: .6rem; }
.presentation-bar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: .6rem; transition: opacity .2s; }
.presentation-bar button { color: #fff; border-color: #777; background: #222; }
.presentation:fullscreen.controls-hidden { cursor: none; }
.presentation:fullscreen.controls-hidden .presentation-bar,
.presentation:fullscreen.controls-hidden .slide-arrow { opacity: 0; pointer-events: none; }
#slideCounter { color: #ddd; font-variant-numeric: tabular-nums; }
#fullscreenButton { flex: 0 0 44px; padding-inline: 0; }
.slide-viewport { grid-column: 2; display: grid; place-items: center; min-width: 0; min-height: 0; overflow: auto; cursor: pointer; }
.slide-text { max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; font-weight: 650; line-height: 1.15; text-align: center; }
.slide-text.title { font-weight: 800; }
.slide-arrow { align-self: stretch; width: clamp(44px, 6vw, 72px); padding: 0; color: #ddd; border: 0; background: transparent; font-size: 3rem; transition: opacity .2s; }
.previous { grid-column: 1; }
.next { grid-column: 3; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

@media (max-width: 42rem), (pointer: coarse) {
  .app-links { display: flex; }
  .site-header { align-items: start; flex-direction: column; }
  nav { width: 100%; flex-wrap: wrap; }
  .tab { flex: 1; }
  .theme-switcher { flex: 0 0 auto; margin-left: auto; }
  .playlist-form > div { align-items: stretch; flex-direction: column; }
  .presentation { padding-inline: max(.5rem, env(safe-area-inset-left)); }
  .presentation[open] { grid-template: auto minmax(0, 1fr) auto / 1fr 1fr; }
  .slide-viewport { grid-row: 2; grid-column: 1 / -1; }
  .slide-arrow { grid-row: 3; align-self: auto; width: 100%; height: 44px; border: 1px solid #333; background: #111; font-size: 2rem; }
  .previous { grid-column: 1; }
  .next { grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
