/* ==========================================================================
   Songbook — application styles
   ========================================================================== */

/* --------------------------------------------------------------- reset */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

body.no-scroll,
body.dialog-open {
  overflow: hidden;
}

h1, h2, h3, h4, p, ul, ol, figure {
  margin: 0;
  padding: 0;
}

ul, ol {
  list-style: none;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

/* Layout rules below set display on overlays, so [hidden] needs to win. */
[hidden] {
  display: none !important;
}

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--r-xs);
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

.skip-link {
  position: fixed;
  top: -100px;
  left: var(--s-4);
  z-index: 200;
  padding: var(--s-2) var(--s-4);
  background: var(--accent);
  color: var(--text-on-accent);
  border-radius: var(--r-sm);
  font-weight: 600;
  text-decoration: none;
  transition: top var(--dur) var(--ease);
}

.skip-link:focus {
  top: calc(var(--s-3) + var(--safe-t));
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Filled glyphs read better than outlines at small sizes. */
.icon-fill .icon,
.is-favorite .icon-star .icon,
[data-icon-fill] .icon {
  fill: currentColor;
  stroke: none;
}

/* ------------------------------------------------------------ primitives */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 38px;
  padding: 0 var(--s-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 550;
  letter-spacing: 0.005em;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.btn:hover {
  background: var(--surface-3);
  border-color: var(--border-accent);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--text-on-accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: transparent;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-2);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  border-color: transparent;
  color: #fff;
}

.btn-danger-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--danger);
}

.btn-danger-ghost:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.btn-sm {
  min-height: 30px;
  padding: 0 var(--s-3);
  font-size: var(--fs-sm);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease);
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.icon-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}

.icon-btn.tiny {
  width: 26px;
  height: 26px;
}

.icon-btn.tiny .icon {
  width: 15px;
  height: 15px;
}

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 6px;
  border: 0;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: 550;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.text-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.text-btn .icon {
  width: 14px;
  height: 14px;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xs);
  background: var(--surface-2);
  color: var(--text-3);
  font-family: var(--font-ui);
  font-size: var(--fs-2xs);
  font-weight: 600;
  line-height: 1;
}

.field {
  width: 100%;
  min-height: 38px;
  padding: 8px var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-0);
  color: var(--text);
  font-size: var(--fs-base);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.field:hover {
  border-color: var(--border-strong);
}

.field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field::placeholder {
  color: var(--text-4);
}

.field-lg {
  min-height: 44px;
  font-size: var(--fs-lg);
  font-weight: 550;
}

.field-textarea {
  min-height: 120px;
  padding: var(--s-3);
  font-family: var(--font-mono);
  font-size: var(--fs-md);
  line-height: 1.6;
  resize: vertical;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-group.grow {
  flex: 1 1 200px;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
}

.field-row > .field-group {
  flex: 1 1 110px;
}

.field-label {
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  flex-wrap: wrap;
}

.field-optional {
  color: var(--text-4);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.field-hint {
  color: var(--text-3);
  font-size: var(--fs-xs);
}

.select-shell {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.select-shell .icon {
  position: absolute;
  right: 9px;
  width: 15px;
  height: 15px;
  color: var(--text-3);
  pointer-events: none;
}

.select {
  appearance: none;
  min-height: 34px;
  padding: 0 30px 0 var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  color: var(--text-2);
  font-size: var(--fs-sm);
  cursor: pointer;
}

.select:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.switch-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 7px 0;
  color: var(--text-2);
  font-size: var(--fs-md);
  cursor: pointer;
}

.switch-row input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 38px;
  height: 22px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-full);
  background: var(--surface-2);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-3);
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}

.switch-row input:checked + .switch {
  background: var(--accent);
  border-color: transparent;
}

.switch-row input:checked + .switch::after {
  background: var(--text-on-accent);
  transform: translateX(16px);
}

.switch-row input:focus-visible + .switch {
  box-shadow: var(--ring);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-1);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 550;
  white-space: nowrap;
}

.chip-accent {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}

.fuzzy-hit {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 3px;
  padding: 0 1px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-9) var(--s-5);
  text-align: center;
  color: var(--text-3);
}

.empty-state h3 {
  color: var(--text);
  font-size: var(--fs-lg);
  font-weight: 600;
}

.empty-state p {
  max-width: 34ch;
  font-size: var(--fs-md);
}

.empty-state .btn {
  margin-top: var(--s-1);
}

/* ------------------------------------------------------------------ app */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) calc(var(--s-4) + var(--safe-r)) 0 calc(var(--s-4) + var(--safe-l));
  border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--surface-0) 84%, transparent);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  flex: 0 0 auto;
  z-index: 30;
}

.nav-toggle {
  display: none;
}

/* Shown only on desktop — see the collapse block in the responsive section. */
.panel-toggle {
  display: none;
}

/* A folded panel reads as the quieter state. */
.panel-toggle[aria-expanded="false"] {
  color: var(--text-4);
}

.panel-toggle[aria-expanded="false"]:hover {
  color: var(--text-2);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: 0 0 auto;
  min-width: 0;
}

.brand-mark {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--accent);
}

.brand-name {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 650;
  letter-spacing: -0.015em;
}

.search-shell {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  max-width: 560px;
  margin: 0 auto;
}

.search-shell .search-icon {
  position: absolute;
  left: 11px;
  width: 16px;
  height: 16px;
  color: var(--text-3);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 76px 0 34px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  color: var(--text);
  font-size: var(--fs-md);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.search-input::-webkit-search-cancel-button {
  display: none;
}

.search-input::placeholder {
  color: var(--text-4);
}

.search-input:hover {
  border-color: var(--border-strong);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-0);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-clear {
  position: absolute;
  right: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-2);
  cursor: pointer;
}

.search-clear .icon {
  width: 13px;
  height: 13px;
}

.search-kbd {
  position: absolute;
  right: 9px;
  pointer-events: none;
}

.search-shell:focus-within .search-kbd {
  opacity: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: 0 0 auto;
}

/* ------------------------------------------------------------- workspace */

.workspace {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(320px, 1fr) var(--detail-w);
  flex: 1 1 auto;
  min-height: 0;
}

.scrim {
  display: none;
}

/* --------------------------------------------------------------- sidebar */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  min-height: 0;
  padding: var(--s-5) var(--s-4) var(--s-4) calc(var(--s-4) + var(--safe-l));
  border-right: 1px solid var(--border-soft);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.scope-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.scope-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: 34px;
  padding: 0 var(--s-3);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-md);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.scope-item .icon {
  width: 16px;
  height: 16px;
  color: var(--text-3);
}

.scope-item:hover {
  background: var(--surface-1);
  color: var(--text);
}

.scope-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.scope-item.active .icon {
  color: var(--accent);
}

.scope-count {
  margin-left: auto;
  color: var(--text-4);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.scope-item.active .scope-count {
  color: var(--accent);
}

.side-block {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  min-height: 0;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  padding: 0 var(--s-3);
}

.side-head h2 {
  color: var(--text-3);
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

.setlist-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setlist-item {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  border-radius: var(--r-sm);
  transition: background var(--dur-fast) var(--ease);
}

.setlist-item:hover {
  background: var(--surface-1);
}

.setlist-item.active {
  background: var(--accent-soft);
}

.setlist-open {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: 1 1 auto;
  min-width: 0;
  min-height: 32px;
  padding: 0 0 0 var(--s-3);
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-md);
  text-align: left;
  cursor: pointer;
}

.setlist-item.active .setlist-open {
  color: var(--accent);
  font-weight: 600;
}

.setlist-open-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.setlist-open-count {
  margin-left: auto;
  color: var(--text-4);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.setlist-item .icon-btn {
  opacity: 0;
  margin-right: 4px;
}

.setlist-item:hover .icon-btn,
.setlist-item:focus-within .icon-btn {
  opacity: 1;
}

.side-empty {
  padding: var(--s-2) var(--s-3);
  color: var(--text-4);
  font-size: var(--fs-sm);
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 var(--s-3);
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 25px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 550;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease);
}

.tag-chip:hover {
  border-color: var(--border-accent);
  color: var(--text);
}

.tag-chip.active {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}

.tag-chip-count {
  color: var(--text-4);
  font-variant-numeric: tabular-nums;
}

.tag-chip.active .tag-chip-count {
  color: inherit;
  opacity: 0.75;
}

.sidebar-foot {
  margin-top: auto;
  padding: var(--s-3) var(--s-3) 0;
  border-top: 1px solid var(--border-soft);
  color: var(--text-4);
  font-size: var(--fs-xs);
  line-height: 1.6;
}

.backup-note.warn {
  color: var(--warning);
}

.backup-note a {
  color: inherit;
}

/* --------------------------------------------------------------- library */

.library {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border-soft);
}

.library-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-5) var(--s-5) var(--s-3);
  flex: 0 0 auto;
}

.library-title {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.library-sub {
  margin-top: 2px;
  color: var(--text-3);
  font-size: var(--fs-sm);
}

.library-head-tools {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: 0 0 auto;
}

.setlist-toolbar,
.filter-summary {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
  margin: 0 var(--s-5) var(--s-3);
  padding: var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-1);
  font-size: var(--fs-sm);
  color: var(--text-2);
}

.setlist-toolbar-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-right: auto;
  min-width: 0;
}

.setlist-toolbar-name {
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 600;
}

.setlist-toolbar-stats {
  color: var(--text-3);
  font-size: var(--fs-xs);
}

.filter-summary-text {
  margin-right: auto;
}

/* Song list ------------------------------------------------------------ */

.song-list {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0 var(--s-5) var(--s-8);
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 60px;
}

.song-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  padding: var(--s-3) var(--s-3);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.song-row + .song-row {
  margin-top: 1px;
}

.song-row::after {
  content: "";
  position: absolute;
  left: var(--s-3);
  right: var(--s-3);
  bottom: -1px;
  height: 1px;
  background: var(--border-soft);
}

.song-row:last-child::after,
.song-row:hover::after,
.song-row.selected::after {
  opacity: 0;
}

.song-row:hover {
  background: var(--surface-1);
}

.song-row.selected {
  background: var(--surface-2);
  border-color: var(--border);
}

.song-row.selected::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12%;
  bottom: 12%;
  width: 3px;
  border-radius: var(--r-full);
  background: var(--accent);
}

.song-row-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.song-row-title {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
  color: var(--song-title-color, var(--text));
  font-size: var(--fs-lg);
  font-weight: 550;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.song-row-title .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.song-row-fav {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  fill: var(--warning);
  stroke: none;
}

.song-row-meta {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
  color: var(--text-3);
  font-size: var(--fs-xs);
}

.song-row-meta .dot {
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: var(--text-4);
  flex: 0 0 auto;
}

.song-row-artist {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.song-row-tags {
  display: flex;
  gap: 4px;
  overflow: hidden;
}

.song-row-tag {
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  color: var(--text-3);
  font-size: var(--fs-2xs);
  white-space: nowrap;
}

.song-row-side {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: 0 0 auto;
}

.song-row-key {
  min-width: 34px;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-align: center;
}

.song-row-preview {
  max-width: 190px;
  overflow: hidden;
  color: var(--text-4);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.song-list.compact .song-row {
  padding: 7px var(--s-3);
}

.song-list.compact .song-row-title {
  font-size: var(--fs-md);
}

.song-list.compact .song-row-meta {
  display: none;
}

.list-section-label {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: var(--s-4) var(--s-3) 5px;
  background: linear-gradient(180deg, var(--bg) 62%, transparent);
  color: var(--text-4);
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

/* Setlist rows get a drag handle and an index. */
.song-row.orderable {
  grid-template-columns: 26px minmax(0, 1fr) auto;
}

.song-row-index {
  color: var(--text-4);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.song-row-drag {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 30px;
  margin-left: -4px;
  border: 0;
  background: transparent;
  color: var(--text-4);
  cursor: grab;
  touch-action: none;
}

.song-row-drag:hover {
  color: var(--text-2);
}

.song-row.dragging {
  opacity: 0.35;
}

.song-row.drop-before {
  box-shadow: inset 0 2px 0 var(--accent);
}

.song-row.drop-after {
  box-shadow: inset 0 -2px 0 var(--accent);
}

/* Alphabet rail -------------------------------------------------------- */

.alpha-rail {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 2px;
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--surface-1) 70%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
  z-index: 4;
}

.library:hover .alpha-rail,
.alpha-rail:focus-within,
.alpha-rail.scrubbing {
  opacity: 1;
}

.alpha-btn {
  width: 18px;
  height: 15px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--text-4);
  font-size: 9.5px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.alpha-btn:hover:not(:disabled),
.alpha-btn.scrub {
  background: var(--accent-soft);
  color: var(--accent);
}

.alpha-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.alpha-btn.active {
  color: var(--text);
}

.alpha-bubble {
  position: fixed;
  z-index: 60;
  display: none;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-3);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-size: var(--fs-2xl);
  font-weight: 650;
  transform: translateY(-50%);
  pointer-events: none;
}

.alpha-bubble.visible {
  display: grid;
}

/* ---------------------------------------------------------------- detail */

.detail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 calc(var(--s-5) + var(--safe-r)) var(--s-8) var(--s-5);
}

.detail-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-3);
  height: 100%;
  padding: var(--s-6);
  text-align: center;
  color: var(--text-4);
}

.detail-empty .icon {
  width: 30px;
  height: 30px;
  opacity: 0.5;
}

.detail-head {
  position: sticky;
  top: 0;
  z-index: 3;
  padding: var(--s-5) 0 var(--s-3);
  background: linear-gradient(180deg, var(--bg) 78%, transparent);
}

.detail-back {
  display: none;
}

.detail-title {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  color: var(--song-title-color, var(--text));
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.detail-artist {
  margin-top: 2px;
  color: var(--text-3);
  font-size: var(--fs-md);
}

.detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--s-3);
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-top: var(--s-4);
}

.detail-tabs {
  display: flex;
  gap: 2px;
  margin: var(--s-4) 0 var(--s-3);
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  width: fit-content;
}

.detail-tab {
  min-height: 28px;
  padding: 0 var(--s-3);
  border: 0;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--text-3);
  font-size: var(--fs-sm);
  font-weight: 550;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.detail-tab:hover {
  color: var(--text);
}

.detail-tab.active {
  background: var(--surface-3);
  color: var(--text);
}

.detail-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-1);
  margin-bottom: var(--s-4);
}

.control-group {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.control-label {
  color: var(--text-3);
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

.stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-0);
  overflow: hidden;
}

.stepper-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.stepper-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.stepper-btn .icon {
  width: 15px;
  height: 15px;
}

.stepper-value {
  min-width: 44px;
  padding: 0 4px;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.capo-field {
  width: 66px;
  min-height: 30px;
  padding: 0 var(--s-2);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.detail-panel {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-0);
  overflow: hidden;
}

.chord-display,
.lyrics-display {
  margin: 0;
  padding: var(--s-5);
  overflow-x: auto;
  color: var(--chord-text);
  font-family: var(--font-mono);
  font-size: var(--detail-chart-size, 16px);
  font-weight: 500;
  line-height: 1.65;
  white-space: pre-wrap;
  /* Wrap between chords, never inside one — a split "Cmaj7" is unreadable. */
  overflow-wrap: normal;
  word-break: normal;
  tab-size: 4;
}

.chord-display.compact,
.lyrics-display.compact {
  line-height: 1.28;
}

/* Applied only while the fitter measures: unwrapped text reveals true width. */
.chord-display.measuring,
.stage-chart.measuring {
  white-space: pre;
}

.lyrics-display {
  color: var(--lyrics-text);
  font-size: var(--fs-md);
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.chord-token {
  color: var(--chord-token);
  font-weight: 700;
}

.section-label,
.chord-rich-note {
  color: var(--section-accent);
  font-weight: 700;
}

.lyrics-chord-line .chord-token {
  color: var(--chord-accent);
}

.chord-empty {
  color: var(--text-4);
  font-style: italic;
}

.detail-notes {
  margin-top: var(--s-4);
  padding: var(--s-4);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  border-radius: var(--r-md);
  background: var(--surface-1);
}

.detail-notes h4 {
  color: var(--text-3);
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  margin-bottom: 5px;
}

.detail-notes p {
  color: var(--text-2);
  font-size: var(--fs-md);
  white-space: pre-wrap;
}

.detail-footnote {
  margin-top: var(--s-4);
  color: var(--text-4);
  font-size: var(--fs-xs);
}

/* --------------------------------------------------------------- drawers */

.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  justify-content: flex-end;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}

.drawer-overlay.visible {
  opacity: 1;
}

.drawer {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  height: 100%;
  border-left: 1px solid var(--border);
  background: var(--surface-0);
  box-shadow: var(--shadow-lg);
  transform: translateX(24px);
  transition: transform var(--dur-slow) var(--ease-out);
}

.drawer-overlay.visible .drawer {
  transform: none;
}

.editor-drawer {
  width: min(760px, 100%);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  flex: 0 0 auto;
  padding: calc(var(--s-4) + var(--safe-t)) var(--s-5) var(--s-4);
  border-bottom: 1px solid var(--border-soft);
}

.drawer-head h2 {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.drawer-head-actions {
  display: flex;
  gap: var(--s-2);
}

.drawer-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--s-5) var(--s-5) calc(var(--s-8) + var(--safe-b));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.drawer-group {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.drawer-group h3 {
  color: var(--text-3);
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

.drawer-note {
  color: var(--text-3);
  font-size: var(--fs-sm);
}

.btn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--s-2);
}

.btn-grid .btn {
  justify-content: flex-start;
}

.import-row {
  display: flex;
  gap: var(--s-2);
}

.import-row .field {
  flex: 1 1 auto;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--s-2);
}

.theme-option {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  color: var(--text-2);
  cursor: pointer;
  text-align: left;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.theme-option:hover {
  border-color: var(--border-accent);
}

.theme-option.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.theme-swatch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 34px;
  height: 22px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xs);
  overflow: hidden;
  flex: 0 0 auto;
}

.theme-option-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.theme-option-name {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text);
}

.theme-option-hint {
  color: var(--text-3);
  font-size: var(--fs-xs);
}

/* Editor --------------------------------------------------------------- */

.editor-body {
  gap: var(--s-4);
}

.chord-tools {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.detected-key {
  color: var(--text-4);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.chord-editor {
  min-height: 190px;
  padding: var(--s-3);
  font-family: var(--font-mono);
  font-size: var(--fs-md);
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow-y: auto;
  tab-size: 4;
}

.chord-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-4);
}

.chord-editor .chord-rich-note {
  color: var(--chord-accent);
  font-size: 0.82em;
  font-weight: 700;
}

.lyrics-editor {
  min-height: 170px;
}

.field-details {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-1);
}

.field-details > summary {
  padding: var(--s-3) var(--s-4);
  color: var(--text-2);
  font-size: var(--fs-md);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.field-details > summary::-webkit-details-marker {
  display: none;
}

.field-details > summary::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: var(--s-3);
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(-45deg);
  transition: transform var(--dur) var(--ease);
}

.field-details[open] > summary::before {
  transform: translateY(-1px) rotate(45deg);
}

.field-details-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: 0 var(--s-4) var(--s-4);
}

.editor-footer {
  display: flex;
  justify-content: flex-start;
  padding-top: var(--s-2);
  border-top: 1px solid var(--border-soft);
  margin-top: var(--s-2);
}

/* --------------------------------------------------------------- dialogs */

.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: var(--s-5);
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}

.dialog-overlay.visible {
  opacity: 1;
}

.dialog-panel {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  width: min(440px, 100%);
  max-height: min(80dvh, 720px);
  padding: var(--s-5);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  transform: scale(0.97) translateY(6px);
  transition: transform var(--dur) var(--ease-out);
}

.dialog-overlay.visible .dialog-panel {
  transform: none;
}

.dialog-md {
  width: min(560px, 100%);
}

.dialog-title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 650;
  letter-spacing: -0.015em;
}

.dialog-message {
  color: var(--text-2);
  font-size: var(--fs-md);
  line-height: 1.6;
}

.dialog-detail {
  max-height: 210px;
  margin: 0;
  padding: var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-0);
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.6;
  overflow: auto;
  white-space: pre-wrap;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
  margin-top: auto;
}

.dialog-form {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.dialog-choice-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 380px;
  overflow-y: auto;
}

.dialog-choice {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-0);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.dialog-choice:hover {
  border-color: var(--accent-line);
  background: var(--surface-2);
}

.dialog-choice-index {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: var(--r-xs);
  background: var(--surface-3);
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: 700;
  flex: 0 0 auto;
}

.dialog-choice-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.dialog-choice-label {
  font-size: var(--fs-md);
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-choice-meta {
  color: var(--text-3);
  font-size: var(--fs-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shortcut-table {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px var(--s-4);
  align-items: center;
  font-size: var(--fs-md);
}

.shortcut-table dt {
  display: flex;
  gap: 3px;
  justify-content: flex-end;
}

.shortcut-sep {
  color: var(--text-4);
  font-size: var(--fs-xs);
  padding: 0 1px;
}

.shortcut-table dd {
  margin: 0;
  color: var(--text-2);
}

.shortcut-group-title {
  grid-column: 1 / -1;
  margin-top: var(--s-2);
  color: var(--text-3);
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

/* ---------------------------------------------------------------- toasts */

.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(var(--s-5) + var(--safe-b));
  z-index: 160;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  width: min(430px, calc(100vw - var(--s-8)));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease-out);
}

.toast.visible {
  opacity: 1;
  transform: none;
}

.toast.leaving {
  opacity: 0;
  transform: translateY(6px) scale(0.98);
}

.toast-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1 1 auto;
  min-width: 0;
}

.toast-message {
  font-size: var(--fs-md);
  font-weight: 550;
}

.toast-detail {
  color: var(--text-3);
  font-size: var(--fs-xs);
}

.toast-success {
  border-left: 3px solid var(--success);
}

.toast-danger {
  border-left: 3px solid var(--danger);
}

.toast-action {
  padding: 5px var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xs);
  background: var(--surface-0);
  color: var(--accent);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  flex: 0 0 auto;
}

.toast-action:hover {
  border-color: var(--accent-line);
}

.toast-close {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--text-4);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}

.toast-close:hover {
  color: var(--text);
}

/* -------------------------------------------------------- command palette */

.palette-overlay {
  position: fixed;
  inset: 0;
  z-index: 140;
  display: flex;
  justify-content: center;
  padding: max(9vh, var(--s-6)) var(--s-4) var(--s-4);
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}

.palette-overlay.visible {
  opacity: 1;
}

.palette {
  display: flex;
  flex-direction: column;
  width: min(620px, 100%);
  max-height: min(62dvh, 560px);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: scale(0.98) translateY(-8px);
  transition: transform var(--dur) var(--ease-out);
}

.palette-overlay.visible .palette {
  transform: none;
}

.palette-input-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4);
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-3);
}

.palette-input {
  flex: 1 1 auto;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: var(--fs-lg);
  outline: none;
}

.palette-input:focus-visible {
  box-shadow: none;
}

.palette-input::placeholder {
  color: var(--text-4);
}

.palette-results {
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--s-2);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.palette-group {
  padding: var(--s-3) var(--s-3) 4px;
  color: var(--text-4);
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  padding: var(--s-2) var(--s-3);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  text-align: left;
  cursor: pointer;
}

.palette-item .icon {
  width: 16px;
  height: 16px;
  color: var(--text-4);
  flex: 0 0 auto;
}

.palette-item.active {
  background: var(--accent-soft);
  color: var(--text);
}

.palette-item.active .icon {
  color: var(--accent);
}

.palette-item-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 auto;
}

.palette-item-label {
  font-size: var(--fs-md);
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette-item-meta {
  color: var(--text-4);
  font-size: var(--fs-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette-item-hint {
  color: var(--text-4);
  font-size: var(--fs-xs);
  flex: 0 0 auto;
}

.palette-empty {
  padding: var(--s-6) var(--s-4);
  color: var(--text-4);
  font-size: var(--fs-md);
  text-align: center;
}

.palette-foot {
  display: flex;
  gap: var(--s-4);
  padding: var(--s-2) var(--s-4);
  border-top: 1px solid var(--border-soft);
  color: var(--text-4);
  font-size: var(--fs-xs);
}

.palette-foot span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* -------------------------------------------------------- progress overlay */

.progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: var(--s-5);
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.progress-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  width: min(380px, 100%);
  padding: var(--s-7) var(--s-5);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.progress-card h2 {
  font-size: var(--fs-lg);
  font-weight: 650;
}

.progress-card p {
  color: var(--text-2);
  font-size: var(--fs-md);
}

.progress-detail {
  color: var(--text-4) !important;
  font-size: var(--fs-xs) !important;
}

#progress-cancel-btn {
  margin-top: var(--s-3);
}

.progress-spinner {
  width: 30px;
  height: 30px;
  margin-bottom: var(--s-2);
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 720ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ----------------------------------------------------------------- stage */

.stage {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: var(--stage-bg);
  color: var(--stage-text);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}

.stage.visible {
  opacity: 1;
}

.stage-head,
.stage-foot {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex: 0 0 auto;
  background: var(--stage-chrome);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.stage-head {
  justify-content: space-between;
  padding: calc(var(--s-3) + var(--safe-t)) calc(var(--s-4) + var(--safe-r)) var(--s-3) calc(var(--s-4) + var(--safe-l));
  border-bottom: 1px solid var(--stage-chrome-border);
}

.stage-foot {
  flex-direction: column;
  align-items: stretch;
  gap: var(--s-2);
  padding: var(--s-3) calc(var(--s-4) + var(--safe-r)) calc(var(--s-3) + var(--safe-b)) calc(var(--s-4) + var(--safe-l));
  border-top: 1px solid var(--stage-chrome-border);
}

/* Chrome fades away while playing, and comes back on any interaction. */
.stage.chrome-hidden .stage-head {
  opacity: 0;
  transform: translateY(-100%);
  pointer-events: none;
}

.stage.chrome-hidden .stage-foot {
  opacity: 0;
  transform: translateY(100%);
  pointer-events: none;
}

.stage.chrome-hidden .stage-edge {
  opacity: 0;
}

.stage-head-left {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 0;
}

.stage-head-right {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: 0 0 auto;
}

.stage-titles {
  min-width: 0;
}

.stage-title {
  color: var(--song-title-color, var(--stage-text));
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 650;
  letter-spacing: -0.015em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-title.hidden {
  visibility: hidden;
}

.stage-subtitle {
  color: color-mix(in srgb, var(--stage-text) 55%, transparent);
  font-size: var(--fs-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--stage-chrome-border);
  border-radius: var(--r-sm);
  background: transparent;
  color: color-mix(in srgb, var(--stage-text) 78%, transparent);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.stage-btn:hover {
  background: color-mix(in srgb, var(--stage-text) 10%, transparent);
  color: var(--stage-text);
}

.stage-btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.seg {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--stage-chrome-border);
  border-radius: var(--r-sm);
}

.seg-btn {
  min-height: 30px;
  padding: 0 var(--s-3);
  border: 0;
  border-radius: var(--r-xs);
  background: transparent;
  color: color-mix(in srgb, var(--stage-text) 60%, transparent);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: color-mix(in srgb, var(--stage-text) 14%, transparent);
  color: var(--stage-text);
}

.seg-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.stage-body {
  position: relative;
  display: flex;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
}

.stage-chart {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: var(--s-5) calc(var(--s-6) + var(--safe-r)) var(--s-6) calc(var(--s-6) + var(--safe-l));
  overflow: auto;
  overscroll-behavior: contain;
  color: var(--stage-text);
  font-family: var(--font-mono);
  font-size: var(--stage-font-size, 72px);
  font-weight: 600;
  line-height: 1.32;
  letter-spacing: -0.01em;
  white-space: pre-wrap;
  overflow-wrap: normal;
  word-break: normal;
  tab-size: 4;
  scroll-behavior: auto;
}

.stage-chart.compact {
  line-height: 1.1;
}

.stage-chart.lyrics-mode {
  font-size: var(--stage-font-size, 40px);
  font-weight: 500;
  line-height: 1.5;
}

.stage-chart .chord-token {
  color: var(--stage-text);
}

.stage-chart .section-label,
.stage-chart .chord-rich-note {
  color: var(--chord-accent);
}

.stage-edge {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  border: 0;
  background: transparent;
  color: color-mix(in srgb, var(--stage-text) 30%, transparent);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur) var(--ease), color var(--dur) var(--ease);
}

.stage-body:hover .stage-edge {
  opacity: 1;
}

.stage-edge:hover {
  color: var(--stage-text);
  background: linear-gradient(90deg, color-mix(in srgb, var(--stage-text) 8%, transparent), transparent);
}

.stage-edge .icon {
  width: 30px;
  height: 30px;
  stroke-width: 1.4;
}

.stage-edge-prev {
  left: 0;
}

.stage-edge-next {
  right: 0;
}

.stage-edge:disabled {
  opacity: 0 !important;
  pointer-events: none;
}

.stage-controls {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  flex-wrap: wrap;
}

.stage-control {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.stage-control-scroll {
  flex: 1 1 180px;
  max-width: 320px;
}

.stage-control-label {
  color: color-mix(in srgb, var(--stage-text) 48%, transparent);
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
}

.stage-foot .stepper {
  border-color: var(--stage-chrome-border);
  background: transparent;
}

.stage-foot .stepper-btn {
  color: color-mix(in srgb, var(--stage-text) 70%, transparent);
}

.stage-foot .stepper-btn:hover {
  background: color-mix(in srgb, var(--stage-text) 10%, transparent);
  color: var(--stage-text);
}

.stage-foot .stepper-value {
  color: var(--stage-text);
}

.stage-tempo-value {
  color: var(--stage-text);
  font-size: var(--fs-md);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.stage-tempo-value.beat {
  color: var(--accent);
}

.range {
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--stage-text) 20%, transparent);
  cursor: pointer;
}

.range::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 0;
}

.range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
}

.stage-progress {
  display: flex;
  gap: 3px;
  height: 3px;
}

.stage-progress-seg {
  flex: 1 1 0;
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--stage-text) 16%, transparent);
  padding: 0;
  border: 0;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}

.stage-progress-seg.done {
  background: color-mix(in srgb, var(--stage-text) 34%, transparent);
}

.stage-progress-seg.current {
  background: var(--accent);
}

/* ------------------------------------------------------------ responsive */

/* Desktop only: the sidebar and the detail pane fold away independently.
   Narrower layouts already hide them behind the drawer and the sheet, and
   print flattens the workspace, so both are left alone. */
@media screen and (min-width: 1041px) {
  .panel-toggle {
    display: inline-flex;
  }

  .app.sidebar-collapsed .sidebar,
  .app.detail-collapsed .detail {
    display: none;
  }

  .app.sidebar-collapsed .workspace {
    grid-template-columns: minmax(320px, 1fr) var(--detail-w);
  }

  .app.detail-collapsed .workspace {
    grid-template-columns: var(--sidebar-w) minmax(320px, 1fr);
  }

  .app.sidebar-collapsed.detail-collapsed .workspace {
    grid-template-columns: minmax(320px, 1fr);
  }

  /* Nothing sits to the right of the list any more, so drop the seam. */
  .app.detail-collapsed .library {
    border-right: 0;
  }
}

@media (max-width: 1240px) {
  :root {
    --sidebar-w: 240px;
    --detail-w: minmax(340px, 0.85fr);
  }

  .song-row-preview {
    display: none;
  }
}

@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: minmax(300px, 1fr) minmax(340px, 1fr);
  }

  .nav-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: calc(var(--topbar-h) + var(--safe-t));
    bottom: 0;
    left: 0;
    z-index: 50;
    width: min(300px, 84vw);
    background: var(--surface-0);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transform: translateX(-102%);
    transition: transform var(--dur-slow) var(--ease-out);
  }

  .app.nav-open .sidebar {
    transform: none;
  }

  .app.nav-open .scrim {
    display: block;
    position: fixed;
    inset: calc(var(--topbar-h) + var(--safe-t)) 0 0 0;
    z-index: 40;
    background: var(--overlay);
  }
}

@media (max-width: 820px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .library {
    border-right: 0;
  }

  /* The detail pane becomes a full-screen sheet on phones. */
  .detail {
    position: fixed;
    inset: calc(var(--topbar-h) + var(--safe-t)) 0 0 0;
    z-index: 45;
    background: var(--bg);
    background-image: var(--bg-gradient);
    padding: 0 var(--s-4) calc(var(--s-8) + var(--safe-b));
    transform: translateX(100%);
    transition: transform var(--dur-slow) var(--ease-out);
    visibility: hidden;
  }

  .app.detail-open .detail {
    transform: none;
    visibility: visible;
  }

  .detail-empty {
    display: none;
  }

  .detail-head {
    padding-top: var(--s-3);
  }

  .detail-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-bottom: var(--s-2);
    padding: 5px 9px 5px 5px;
    border: 1px solid var(--border);
    border-radius: var(--r-full);
    background: var(--surface-1);
    color: var(--text-2);
    font-size: var(--fs-sm);
    font-weight: 550;
    cursor: pointer;
  }

  .alpha-rail {
    right: 0;
  }

  .brand-name {
    display: none;
  }

  .topbar {
    gap: var(--s-2);
  }

  .topbar-actions .btn span {
    display: none;
  }

  .topbar-actions .btn {
    width: 38px;
    padding: 0;
  }

  .library-head {
    padding: var(--s-4) var(--s-4) var(--s-2);
  }

  .song-list {
    padding: 0 var(--s-4) var(--s-8);
  }

  .setlist-toolbar,
  .filter-summary {
    margin: 0 var(--s-4) var(--s-3);
  }

  .stage-chart {
    padding-left: var(--s-4);
    padding-right: var(--s-4);
  }

  .stage-edge {
    width: 46px;
  }

  .toast-region {
    bottom: calc(var(--s-4) + var(--safe-b));
  }
}

@media (max-width: 620px) {
  /* Below this the mark costs more than it earns; the search field needs the room. */
  .brand {
    display: none;
  }

  .search-input {
    padding-right: var(--s-3);
  }

  .search-kbd {
    display: none;
  }

  .search-clear {
    right: 6px;
  }

  .icon-btn,
  .topbar-actions .btn {
    width: 36px;
    height: 36px;
  }
}

@media (max-width: 560px) {
  .search-shell {
    max-width: none;
  }

  .stage-head-right .seg {
    display: none;
  }

  .stage-controls {
    gap: var(--s-3);
    justify-content: space-between;
  }

  .stage-control-scroll {
    flex-basis: 100%;
    max-width: none;
    order: 3;
  }

  .drawer {
    width: 100%;
    border-left: 0;
  }

  .btn-grid {
    grid-template-columns: 1fr;
  }
}

@media (hover: none) {
  .alpha-rail {
    opacity: 1;
  }

  .stage-edge {
    opacity: 1;
    color: color-mix(in srgb, var(--stage-text) 22%, transparent);
  }

  .setlist-item .icon-btn {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ----------------------------------------------------------------- print */

@media print {
  .topbar,
  .sidebar,
  .alpha-rail,
  .alpha-bubble,
  .toast-region,
  .library-head-tools,
  .detail-actions,
  .detail-tabs,
  .detail-controls,
  .stage,
  .drawer-overlay,
  .palette-overlay,
  .progress-overlay {
    display: none !important;
  }

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

  .app,
  .workspace {
    display: block;
    height: auto;
  }

  .detail {
    overflow: visible;
    padding: 0;
  }
}
