:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #657080;
  --line: #d9dee6;
  --soft: #eef2f6;
  --accent: #176f7b;
  --accent-ink: #ffffff;
  --warn: #8a5515;
  --danger: #9f2d3b;
  --shadow: 0 12px 30px rgba(24, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}

button:active {
  transform: translateY(1px);
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-end;
  padding: 24px clamp(16px, 3vw, 36px) 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.app-header h1,
.app-header p,
h2,
h3 {
  margin: 0;
}

.app-header h1 {
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  line-height: 1.05;
}

.app-header p {
  margin-top: 8px;
  color: var(--muted);
}

.summary {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.summary span {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  white-space: nowrap;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.85fr);
  gap: 18px;
  padding: 18px clamp(12px, 3vw, 36px) 32px;
}

.library-panel,
.playlist-panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.library-panel,
.playlist-panel {
  padding: 16px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-header h2 {
  font-size: 1.1rem;
}

.panel-header button,
.playlist-actions button {
  padding: 0 14px;
}

.panel-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panel-note {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.filter-stack {
  display: grid;
  gap: 10px;
  justify-items: end;
}

.search-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
}

.search-field input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--panel);
}

.mode-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.mode-control button {
  min-width: 104px;
  border: 0;
  border-radius: 0;
  background: var(--panel);
  color: var(--muted);
}

.mode-control button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  user-select: none;
}

.filter-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.chord-filter {
  margin-top: 16px;
}

.chord-filter h3,
.inspector h3 {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.86rem;
  text-transform: uppercase;
}

.inspector-context {
  margin-left: 6px;
  color: var(--accent);
  font-size: 0.95em;
  font-weight: 700;
  text-transform: none;
}

.chord-buttons,
.shared-chords {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chord-map {
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  overflow: hidden;
}

.chord-map.empty {
  display: grid;
  place-items: center;
  padding: 18px;
}

.chord-map svg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 260px;
}

.map-links line {
  stroke: #b8c2cc;
  stroke-width: 1.2;
  opacity: 0.42;
}

.map-links line.strong {
  stroke: var(--accent);
  stroke-width: 2.4;
  opacity: 0.72;
}

.map-chords circle {
  fill: #edf2f6;
  stroke: #9aa8b6;
  stroke-width: 1;
}

.map-chords circle.shared {
  fill: var(--accent);
  stroke: var(--accent);
}

.map-chords text {
  fill: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
  text-anchor: middle;
  pointer-events: none;
}

.map-chords circle.shared + text {
  fill: var(--accent-ink);
}

.map-songs circle {
  fill: var(--warn);
}

.map-songs text {
  fill: var(--ink);
  font-size: 0.78rem;
  font-weight: 650;
  paint-order: stroke;
  stroke: #fbfcfd;
  stroke-width: 4px;
  stroke-linejoin: round;
}

.chord-buttons button,
.chord-pill {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--ink);
}

.chord-buttons button.active,
.chord-pill.strong {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.song-list,
.suggestions {
  display: grid;
  gap: 10px;
}

.playlist-list {
  display: grid;
  gap: 14px;
}

.song-list {
  margin-top: 16px;
}

.song-card,
.playlist-card,
.suggestion-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.song-card.selected {
  border-color: var(--accent);
  background: #f0f8f9;
}

.song-main,
.playlist-main,
.suggestion-main {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.song-title,
.playlist-title,
.suggestion-title {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.song-link {
  color: inherit;
  text-decoration: none;
}

.song-link:hover {
  text-decoration: underline;
}

.song-actions,
.playlist-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.song-main > div:first-child,
.playlist-main > div:first-child,
.suggestion-main > div:first-child {
  min-width: 0;
  flex: 1 1 0;
}

.song-actions button,
.playlist-controls button {
  width: 42px;
  min-height: 38px;
  padding: 0;
  font-weight: 700;
}

.capo-field,
.move-track-field {
  display: inline-flex;
  min-width: 0;
  flex: 0 1 auto;
}

.capo-field select,
.move-track-field select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.capo-field select {
  width: 92px;
  padding: 0 10px;
}

.move-track-field select {
  width: 100%;
  min-width: 0;
  max-width: 140px;
  padding: 0 34px 0 10px;
}

.song-actions button.remove,
.playlist-controls button.remove {
  color: var(--danger);
}

.chord-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-chord {
  padding: 4px 7px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 0.84rem;
}

.playlist-list {
  min-height: 76px;
}

.playlist-set {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.playlist-set.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 20%, transparent);
}

.set-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  flex-wrap: wrap;
  cursor: pointer;
}

.set-header button,
.set-header input,
.set-header select,
.set-header label {
  cursor: auto;
}

.set-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 0;
}

.set-drag-handle {
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: grab;
}

.set-drag-handle:active {
  cursor: grabbing;
}

.set-badge {
  min-width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.set-name-input {
  min-height: 40px;
  width: min(260px, 100%);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

.set-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  width: 100%;
}

.set-controls button.active,
.set-controls button[data-action="activate"]:disabled {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.set-meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.playlist-set.active .set-meta {
  color: var(--accent);
  font-weight: 700;
}

.set-song-list {
  display: grid;
  gap: 10px;
  min-height: 24px;
}

.set-song-list-collapsed {
  min-height: 0;
}

.collapsed-track-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.collapsed-track-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
}

.collapsed-track-index {
  color: var(--muted);
  font-size: 0.8rem;
}

.collapsed-track-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.collapsed-track-remove {
  width: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 999px;
  font-weight: 700;
  line-height: 1;
  color: var(--danger);
}

.playlist-card {
  background: #fbfcfd;
  cursor: grab;
}

.playlist-card:active {
  cursor: grabbing;
}

.drag-chosen {
  border-color: var(--accent);
}

.drag-ghost {
  opacity: 0.45;
}

.playlist-index {
  min-width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 0.86rem;
}

.inspector {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.empty {
  color: var(--muted);
}

.suggestion-card {
  background: #fffaf1;
}

.suggestion-score {
  color: var(--warn);
  font-weight: 700;
  white-space: nowrap;
}

.playlist-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.playlist-actions.top-actions {
  grid-template-columns: repeat(5, minmax(42px, 52px));
  justify-content: end;
  margin-top: 0;
  margin-bottom: 14px;
}

.icon-button {
  min-height: 42px;
  width: 100%;
  padding: 0;
  font-size: 1.05rem;
  line-height: 1;
}

@media (max-width: 860px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary {
    justify-content: flex-start;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-header {
    padding-top: 18px;
  }

  .library-panel,
  .playlist-panel {
    padding: 12px;
  }

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

  .filter-stack {
    justify-items: start;
  }

  .mode-control button {
    min-width: 0;
  }

  .song-main,
  .set-header,
  .playlist-main,
  .suggestion-main {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-actions,
  .set-controls {
    justify-content: stretch;
  }

  .set-name-input {
    width: 100%;
  }

  .song-actions,
  .playlist-controls {
    justify-content: flex-end;
  }

  .capo-field,
  .capo-field select,
  .move-track-field,
  .move-track-field select {
    width: 100%;
    max-width: none;
  }

  .set-controls {
    width: 100%;
  }
}
