:root {
  color-scheme: dark;
  --bg: #15131c;
  --surface: #1d1a26;
  --raised: #272333;
  --edge: #383244;
  --text: #f8f4fa;
  --muted: #c1b7cb;
  --accent: #e5fc82;
  --purple: #cbb4fa;
  --error: #ffb6b6;
  --focus: #e5fc82;
  --control-edge: #625374;
  --control-bg: #332943;
  --control-hover: #47355f;
  --track-active: #28243a;
  --missing: #dfbbaf;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f3fb;
  --surface: #fff;
  --raised: #eee7f7;
  --edge: #dcd2e8;
  --text: #241b34;
  --muted: #5f536d;
  --purple: #604086;
  --error: #9e2438;
  --focus: #684598;
  --control-edge: #bca9d4;
  --control-bg: #eee5fb;
  --control-hover: #e1d3f5;
  --track-active: #f6f0ff;
  --missing: #8b4b3b;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; }
button, input, textarea { font: inherit; }
button, summary { cursor: pointer; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p, dl, dd { margin: 0; }
button:focus-visible, summary:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.topbar { border-bottom: 1px solid var(--edge); }
.topbar-inner, .library { max-width: 73rem; margin: 0 auto; padding-inline: clamp(1rem, 4vw, 3rem); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: .6rem; min-height: 4.25rem; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.brand { display: inline-flex; align-items: center; gap: .7rem; font-weight: 850; letter-spacing: .12em; white-space: nowrap; }
.brand-mark {
  display: inline-flex; justify-content: center; align-items: center; gap: 3px;
  width: 2.35rem; height: 2.35rem; border-radius: .7rem; background: var(--accent); color: #201e25;
}
.brand-mark i { display: block; width: 2px; height: 8px; background: currentColor; border-radius: 1px; }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(4) { height: 13px; }
.brand-mark i:nth-child(3) { height: 20px; }
.quiet-button, .primary-button, .icon-button {
  border: 1px solid var(--edge); border-radius: .65rem; padding: .65rem .95rem; min-height: 2.75rem;
  background: transparent; color: var(--text); font-weight: 650; font-size: .91rem;
}
.quiet-button:hover, .icon-button:hover { border-color: var(--purple); background: var(--raised); }
.primary-button { background: var(--accent); color: #201e25; border-color: var(--accent); }
.primary-button:hover { background: #f1ffb9; }
.primary-button span { font-size: 1.2em; margin-right: .25rem; line-height: .8; }
button:disabled { opacity: .55; }

.library { padding-block: 2.15rem 5rem; }
.hero {
  position: relative; isolation: isolate; overflow: hidden; display: flex; align-items: center;
  min-height: 17rem; padding: clamp(1.6rem, 4vw, 3.2rem); border: 1px solid #4b3a62; border-radius: 1.3rem;
  background: radial-gradient(ellipse at 85% 88%, #493568 0%, transparent 65%), linear-gradient(120deg, #242033, #34264c);
}
:root[data-theme="light"] .hero {
  border-color: #d7c8ec;
  background: radial-gradient(ellipse at 85% 88%, #d9c6f1 0%, transparent 65%), linear-gradient(120deg, #f8f4ff, #eadff9);
}
:root[data-theme="light"] .hero h1 span { color: var(--purple); }
.hero-text { position: relative; z-index: 1; }
.eyebrow { color: var(--purple); font-size: .85rem; font-weight: 750; letter-spacing: .16em; text-transform: uppercase; }
.hero h1, .login-panel h1 {
  font-size: clamp(2.5rem, 6vw, 4.75rem); font-weight: 840; letter-spacing: -.065em; line-height: 1.02;
  margin-top: .35rem;
}
.hero h1 span { color: var(--accent); }
.hero p:not(.eyebrow), .login-content > p:not(.eyebrow) { color: var(--muted); font-size: 1.04rem; margin-top: .75rem; }
.hero .primary-button { margin-top: 1.4rem; }
.waveform {
  position: absolute; pointer-events: none; right: -2%; top: 0; bottom: 0; width: 55%;
  display: flex; align-items: center; gap: clamp(2px, .45vw, 6px); padding: 1.7rem 1.2rem;
  mask-image: linear-gradient(to right, transparent, #000 28%, #000 94%, transparent);
}
.waveform i { flex: 1; min-width: 1px; border-radius: 5px; background: #b490ee; opacity: .5; }
.waveform i:nth-child(3n) { background: #ded0ff; }
.waveform i:nth-child(9n + 3) { background: var(--accent); opacity: .65; }

.library-section { margin-top: clamp(2rem, 5vw, 3.1rem); }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: .45rem 1rem; margin-bottom: 1rem; }
.section-heading h2, .dialog-heading h2 { font-size: clamp(1.45rem, 3vw, 1.8rem); letter-spacing: -.035em; line-height: 1.2; }
.section-heading p, .section-count { color: var(--muted); font-size: .9rem; }
.section-count { white-space: nowrap; }
.section-heading-wrap { flex-wrap: wrap; }
.track-list { overflow: hidden; border: 1px solid var(--edge); border-radius: .95rem; background: var(--surface); }
.track {
  display: grid; grid-template-columns: auto minmax(0, 1.65fr) minmax(9rem, 1fr) auto;
  gap: .45rem 1rem; align-items: center; padding: .9rem 1rem;
}
.track + .track { border-top: 1px solid var(--edge); }
.track:has(.player:not([hidden])) { background: var(--track-active); }
.track-name { min-width: 0; overflow-wrap: anywhere; }
.track-name h3 { font-size: 1.03rem; line-height: 1.28; }
.track-name p { color: var(--muted); font-size: .89rem; margin-top: .18rem; }
.track-name .track-status { color: var(--missing); font-size: .83rem; }
.track-metadata { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; overflow-wrap: anywhere; }
.track-metadata dt { color: var(--muted); font-size: .83rem; }
.track-metadata dd { font-weight: 650; font-size: .94rem; }
.track-notes { grid-column: 2 / -1; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); font-size: .9rem; }
.track-notes:empty { display: none; }
.play-button {
  display: grid; place-items: center; width: 2.75rem; height: 2.75rem; padding: 0;
  border: 1px solid var(--control-edge); border-radius: 50%; color: var(--purple); background: var(--control-bg);
}
.play-button:hover:not(:disabled) { background: var(--control-hover); border-color: var(--purple); }
.play-button[aria-pressed="true"] { background: var(--accent); color: #201e25; border-color: var(--control-edge); }
.play-button span { margin-left: 2px; width: 0; height: 0; border: 6px solid transparent; border-left: 10px solid currentColor; border-right: 0; }
.play-button[aria-pressed="true"] span { margin-left: 0; width: 10px; height: 12px; border: 0; border-inline: 3px solid currentColor; }
.empty { padding: 1.15rem; border: 1px dashed var(--edge); border-radius: .85rem; color: var(--muted); }

.member-list { display: grid; gap: .65rem; }
.member { border: 1px solid var(--edge); border-radius: .85rem; background: var(--surface); overflow: clip; }
.member[open] { border-color: var(--control-edge); }
.member summary {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto 1rem; gap: .85rem; align-items: center;
  padding: .65rem 1rem; min-height: 3.85rem; list-style: none;
}
.member summary::-webkit-details-marker { display: none; }
.member summary:hover { background: var(--raised); }
.member summary:focus-visible { outline-offset: -3px; }
.member-icon {
  display: grid; place-items: center; width: 2.3rem; height: 2.3rem; border-radius: .58rem;
  font-size: .96rem; font-weight: 750; background: var(--control-bg); color: var(--purple);
}
.member-name { font-weight: 730; }
.member-count { color: var(--muted); font-size: .88rem; }
.chevron { width: .54rem; height: .54rem; border: solid var(--purple); border-width: 0 2px 2px 0; transform: translateY(-2px) rotate(45deg); justify-self: center; }
.member[open] .chevron { transform: translateY(2px) rotate(225deg); }
.member-content { border-top: 1px solid var(--edge); }
.member-content .empty { border: none; }

.login { padding: clamp(2rem, 9vw, 7rem) 1rem 3rem; }
.login-panel { max-width: 32rem; margin: auto; overflow: hidden; border: 1px solid var(--edge); border-radius: 1.2rem; background: var(--surface); }
.login-accent { height: .43rem; background: linear-gradient(90deg, var(--accent) 0 24%, var(--purple) 24% 100%); }
.login-content { padding: clamp(1.5rem, 6vw, 3rem); }
.login-panel h1 { font-size: clamp(2.5rem, 8vw, 3.75rem); }
.login form { margin-top: 1.65rem; }
.login form > .primary-button { margin-top: 1rem; width: 100%; }
label { display: block; font-weight: 650; font-size: .91rem; }
input, textarea {
  display: block; width: 100%; margin-top: .35rem; color: var(--text); background: var(--bg);
  border: 1px solid var(--control-edge); border-radius: .6rem; padding: .64rem .75rem; font-size: 1rem;
}
textarea { resize: vertical; }
.form-error { color: var(--error); margin-top: .65rem; font-size: .9rem; overflow-wrap: anywhere; }

dialog {
  width: min(43rem, calc(100% - 1.5rem)); max-height: min(90dvh, 55rem); padding: 0; color: var(--text);
  background: var(--surface); border: 1px solid var(--control-edge); border-radius: 1rem; box-shadow: 0 1.5rem 6rem #0006;
}
dialog::backdrop { background: #0b0911c9; }
#song-form { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; max-height: min(90dvh, 55rem); }
.dialog-heading, .dialog-actions { padding: .9rem clamp(.9rem, 4vw, 1.5rem); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--edge); }
.dialog-content { padding: 1.2rem clamp(.9rem, 4vw, 1.5rem); overflow-y: auto; }
.song-fields { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
.full-width { grid-column: 1 / -1; }
.dialog-content h3 { margin-top: 1.4rem; }
.file-help, .file-current, .upload-status { color: var(--muted); font-size: .9rem; }
.file-help { margin: .24rem 0 .65rem; }
.file-current { display: block; font-weight: 400; overflow-wrap: anywhere; }
.upload-field { display: flex; align-items: center; gap: .65rem; padding: .7rem 0; border-top: 1px solid var(--edge); }
.upload-field label { flex: 1; min-width: 0; }
.remove-button { flex: none; min-height: 2.25rem; padding: .4rem .7rem; font-size: .85rem; }
.danger-button { color: var(--error); margin-right: auto; }
.danger-button:hover { border-color: var(--error); }
.upload-field input { font-size: .9rem; }
input::file-selector-button {
  cursor: pointer; color: var(--text); background: var(--raised); border: 1px solid var(--control-edge);
  border-radius: .4rem; padding: .28rem .5rem; margin-right: .5rem;
}
.dialog-actions { border-top: 1px solid var(--edge); }
.dialog-actions > div { display: flex; justify-content: flex-end; gap: .65rem; }
.dialog-actions > p { margin: 0 0 .65rem; }
.icon-button { position: relative; flex: none; width: 2.75rem; padding: 0; }
.close-button::before, .close-button::after {
  content: ""; width: 1rem; height: 2px; position: absolute; inset: 0; margin: auto;
  background: currentColor; transform: rotate(45deg);
}
.close-button::after { transform: rotate(-45deg); }

.player {
  grid-column: 1 / -1; display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(8rem, 12rem) auto;
  align-items: center; gap: .25rem .85rem; min-width: 0; margin-top: .3rem; padding: .65rem;
  background: var(--surface); border: 1px solid var(--control-edge); border-radius: .75rem;
}
.player audio { display: none; }
.player-timeline, .player-volume { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.player-timeline { font-variant-numeric: tabular-nums; }
.player-timeline span, .player-volume { color: var(--muted); font-size: .85rem; }
.player input[type="range"] {
  width: 100%; min-width: 0; height: 2.75rem; margin: 0; padding: 0;
  accent-color: var(--focus); cursor: pointer; background: transparent; border: 0;
}
.player .form-error { grid-column: 1 / -1; margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 39rem) {
  .hero { min-height: 15rem; }
  .hero h1 { font-size: clamp(2rem, 8vw, 2.75rem); }
  .topbar-actions .quiet-button { padding-inline: .65rem; }
  .brand { gap: .45rem; font-size: .9rem; }
  .waveform { width: 64%; opacity: .45; right: -12%; }
  .track { grid-template-columns: auto minmax(0, 1fr) auto; gap: .55rem .7rem; padding: .75rem; }
  .track-metadata { grid-column: 2 / -1; grid-row: 2; grid-template-columns: minmax(4.5rem, auto) 1fr; }
  .track-notes { grid-row: 3; }
  .edit-button { padding-inline: .6rem; }
  .member summary { gap: .55rem; padding-inline: .75rem; }
  .member-count { text-align: right; }
  .player { grid-template-columns: auto minmax(0, 1fr) auto; gap: .15rem .5rem; }
  .player-volume { grid-column: 1 / -1; grid-row: 2; }
  .player .close-button { grid-column: 3; grid-row: 1; }
  .song-fields { gap: .65rem; }
}

@media (max-width: 23rem) {
  .topbar-inner { flex-wrap: wrap; padding: .45rem .75rem; gap: .35rem; }
  .topbar-actions { gap: .3rem; }
  .topbar-actions .quiet-button { padding-inline: .45rem; }
  .brand { font-size: .8rem; letter-spacing: .06em; }
  .brand-mark { width: 1.95rem; height: 1.95rem; }
}
