:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #f0f2f4;
  --ink: #17201b;
  --muted: #637069;
  --line: #d9e0d9;
  --topbar-bg: rgba(246, 247, 244, 0.94);
  --input-bg: #ffffff;
  --hover-line: #a9b9ad;
  --line-hover: #f5f7f8;
  --focus-bg: #fff7df;
  --chip-bg: #e2f5f5;
  --chip-line: #7ecfd0;
  --chip-ink: #006b6c;
  --mod-bg: #eef2fa;
  --mod-line: #bfcae4;
  --mod-ink: #273f70;
  --custom-bg: #f5f1e8;
  --custom-line: #d8caa8;
  --custom-ink: #634b19;
  --recent-bg: #fff7df;
  --recent-line: #ddc476;
  --recent-ink: #5c4306;
  --chord-ink: #573f05;
  --chord-hover-bg: #fff9e9;
  --chord-hover-line: rgba(216, 191, 120, 0.65);
  --preview-bg: #101814;
  --preview-ink: #eef6f0;
  --accent: var(--brand-teal);
  --accent-2: #325d8f;
  --warn: #9a5425;
  --danger: #ad3333;
  --shadow: 0 12px 28px rgba(33, 44, 38, 0.09);
  --brand-teal: #009b9c;
  --brand-ink: #1b2a33;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #111513;
  --surface: #181f1c;
  --surface-2: #222c27;
  --ink: #eef5ef;
  --muted: #a7b4ad;
  --line: #344039;
  --topbar-bg: rgba(17, 21, 19, 0.94);
  --input-bg: #121815;
  --hover-line: #607168;
  --line-hover: #1d2622;
  --focus-bg: #283025;
  --chip-bg: #083c42;
  --chip-line: #158f92;
  --chip-ink: #9af1ef;
  --mod-bg: #1d2a42;
  --mod-line: #3d5480;
  --mod-ink: #c9d9ff;
  --custom-bg: #332c1b;
  --custom-line: #665833;
  --custom-ink: #f0dc9f;
  --recent-bg: #332b15;
  --recent-line: #786229;
  --recent-ink: #f4dc86;
  --chord-ink: #f3d77d;
  --chord-hover-bg: #332b15;
  --chord-hover-line: #80682b;
  --preview-bg: #090d0b;
  --preview-ink: #dbeee3;
  --accent: var(--brand-teal);
  --accent-2: #79a9e8;
  --warn: #e1a15f;
  --danger: #ff8e8e;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.32);
  --brand-teal: #1fc0bb;
  --brand-ink: #e8f1f2;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

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

button {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  gap: 7px;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
}

button:hover {
  border-color: var(--hover-line);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

button.secondary {
  background: var(--surface-2);
}

button.danger {
  border-color: color-mix(in srgb, var(--danger), var(--line) 55%);
  color: var(--danger);
}

.button-icon {
  align-items: center;
  border-radius: 5px;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 850;
  height: 18px;
  justify-content: center;
  line-height: 1;
  min-width: 18px;
}

button.primary .button-icon {
  background: rgba(255, 255, 255, 0.16);
}

button.secondary .button-icon,
button:not(.primary):not(.danger) .button-icon {
  background: var(--surface-2);
}

button.danger .button-icon {
  background: color-mix(in srgb, var(--danger), transparent 88%);
}

button.icon {
  align-items: center;
  display: inline-flex;
  font-size: 18px;
  justify-content: center;
  padding: 0;
  width: 36px;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  align-items: center;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 14px 18px;
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.brand-icon {
  border-radius: 10px;
  box-shadow: 0 7px 18px rgba(16, 28, 34, 0.16);
  display: block;
  flex: 0 0 auto;
  height: 44px;
  object-fit: cover;
  width: 44px;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.wordmark {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  font-size: clamp(20px, 2.3vw, 30px);
  font-weight: 850;
  line-height: 0.98;
  margin: 0;
  text-transform: none;
}

.wordmark span {
  display: inline-block;
  margin-right: 7px;
}

.wordmark-accent {
  color: var(--brand-teal);
}

.wordmark-main {
  color: var(--brand-ink);
}

.brand-context {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.screen {
  margin: 0 auto;
  max-width: 1480px;
  padding: 22px 18px 40px;
}

.library-tools,
.form-grid,
.editor-grid,
.export-layout {
  display: grid;
  gap: 16px;
}

.library-tools {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.search,
.library-sort {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--input-bg);
  color: var(--ink);
  min-height: 40px;
  padding: 0 12px;
  width: 100%;
}

.library-sort {
  min-width: 170px;
}

.song-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.song-card {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 14px;
}

.song-card h2 {
  font-size: 16px;
  margin: 0 0 4px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.empty {
  border: 1px dashed #b9c3bb;
  border-radius: 8px;
  color: var(--muted);
  margin-top: 18px;
  padding: 32px;
  text-align: center;
}

.pro-tip {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  padding: 9px 11px;
}

.pro-tip.compact {
  margin-bottom: 10px;
  padding: 7px 9px;
}

.form-grid {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.field-heading {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 0 4px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.field input,
.field textarea {
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--ink);
  border-radius: 7px;
  padding: 10px 12px;
  width: 100%;
}

.field textarea {
  font-family: var(--mono);
  line-height: 1.5;
  min-height: 330px;
  resize: vertical;
}

.three,
.metadata-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 2fr 1fr 120px;
}

.metadata-grid {
  grid-template-columns: 2fr 1.3fr 85px 80px 85px 95px 1fr 1fr;
}

.metadata-mini-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr 1fr 1fr;
}

.metadata-form {
  display: grid;
  gap: 12px;
}

.metadata-form h2 {
  margin-bottom: 0;
}

.field textarea.notes-input {
  font-family: var(--sans);
  line-height: 1.35;
  min-height: 46px;
  resize: vertical;
}

.editor-grid {
  align-items: start;
  grid-template-columns: 250px minmax(0, 1fr) 8px var(--preview-width, 340px);
}

.editor-grid.preview-collapsed {
  grid-template-columns: 250px minmax(0, 1fr) 50px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
  padding: 14px;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 150px);
  max-height: calc(100vh - 150px);
  overflow: hidden;
}

.preview-resizer {
  align-self: stretch;
  cursor: col-resize;
  min-height: calc(100vh - 150px);
  position: relative;
}

.preview-resizer::before {
  background: var(--line);
  border-radius: 999px;
  content: "";
  left: 3px;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
}

.preview-resizer:hover::before,
.resizing-preview .preview-resizer::before {
  background: var(--accent);
}

.resizing-preview {
  cursor: col-resize;
  user-select: none;
}

.editor-grid.preview-collapsed .preview-resizer {
  display: none;
}

.preview-panel.collapsed {
  height: auto;
  min-height: 0;
  padding: 10px 6px;
}

.preview-panel.collapsed h2,
.preview-panel.collapsed .preview,
.preview-panel.collapsed [data-action="copy"] {
  display: none;
}

.preview-panel.collapsed .lyrics-tools {
  justify-content: center;
  margin-bottom: 0;
}

.panel h2 {
  font-size: 14px;
  margin: 0 0 10px;
}

.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.palette.compact {
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  align-items: center;
  background: var(--chip-bg);
  border: 1px solid var(--chip-line);
  border-radius: 7px;
  color: var(--chip-ink);
  cursor: grab;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 30px;
  min-width: 34px;
  padding: 0 10px;
  user-select: none;
  width: auto;
}

.chip.mod {
  background: var(--mod-bg);
  border-color: var(--mod-line);
  color: var(--mod-ink);
  min-width: 32px;
  padding: 0 9px;
}

.chip.custom {
  background: var(--custom-bg);
  border-color: var(--custom-line);
  color: var(--custom-ink);
}

.chip.recent {
  background: var(--recent-bg);
  border-color: var(--recent-line);
  color: var(--recent-ink);
  font-family: var(--mono);
  min-width: 36px;
}

.recent-palette {
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
  padding-bottom: 12px;
}

.advanced-chords {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  margin-top: 4px;
  padding-top: 12px;
}

.advanced-toggle {
  background: var(--surface-2);
  justify-self: start;
}

.advanced-content {
  display: none;
}

.advanced-content.open {
  display: grid;
  gap: 8px;
}

.custom-modifier-form {
  display: grid;
  gap: 6px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.custom-modifier-form input {
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--ink);
  border-radius: 7px;
  min-height: 34px;
  min-width: 0;
  padding: 0 9px;
}

.custom-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.custom-modifier-item {
  align-items: center;
  display: inline-flex;
  gap: 2px;
}

.custom-remove {
  border-radius: 5px;
  color: var(--danger);
  font-size: 12px;
  min-height: 24px;
  padding: 0 7px;
}

.selected-box {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
}

.selected-chord {
  align-items: center;
  background: var(--surface-2);
  border-radius: 7px;
  display: flex;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 800;
  justify-content: space-between;
  min-height: 42px;
  padding: 0 10px;
}

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

.mini {
  font-size: 12px;
  min-height: 28px;
  padding: 0 8px;
}

.lyrics-tools {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.lyrics-tools h2 {
  margin-bottom: 0;
}

.tool-title {
  align-items: center;
  display: inline-flex;
  gap: 8px;
}

.help-dot {
  border-radius: 999px;
  font-weight: 850;
  min-height: 26px;
  min-width: 26px;
  padding: 0;
}

.audition-toggle {
  color: var(--muted);
}

.audition-toggle[aria-pressed="true"] {
  background: var(--chip-bg);
  border-color: var(--chip-line);
  color: var(--chip-ink);
}

.lyrics-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: calc(100vh - 180px);
  min-height: 520px;
  overflow: auto;
  padding: 14px 16px 20px;
  white-space: nowrap;
}

.lyric-line {
  border-radius: 7px;
  display: grid;
  grid-template-columns: max-content;
  font-family: var(--mono);
  grid-template-rows: 23px 26px;
  line-height: 26px;
  margin-bottom: 7px;
  min-width: 100%;
  padding: 3px 8px 4px;
  position: relative;
  width: max-content;
}

.lyric-line:hover {
  background: var(--line-hover);
}

.lyric-line.line-selected {
  background: var(--line-hover);
  box-shadow: inset 3px 0 0 var(--accent);
}

.line-chords,
.line-text {
  display: block;
  min-height: 23px;
  min-width: 80ch;
  position: relative;
  white-space: pre;
  width: max-content;
}

.line-chords {
  overflow: visible;
}

.line-text {
  font-size: 16px;
  line-height: 26px;
}

.line-text[contenteditable="true"] {
  outline: none;
}

.line-text:focus {
  background: var(--focus-bg);
}

.empty-line-hint {
  color: #a1aaa4;
}

.empty-line-hint:empty::before {
  color: var(--muted);
  content: attr(data-placeholder);
  pointer-events: none;
}

.empty-chord-line {
  background: color-mix(in srgb, var(--surface-2), transparent 45%);
  min-width: 82ch;
}

.empty-chord-line .line-chords::before {
  color: var(--muted);
  content: "Drop chords above";
  font-family: var(--sans);
  font-size: 12px;
  left: 0;
  opacity: 0.74;
  pointer-events: none;
  position: absolute;
  top: 1px;
}

.empty-chord-line:has(.chord-token) .line-chords::before {
  content: "";
}

.empty-chord-line .line-text {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
}

.empty-chord-line .line-text:focus {
  color: var(--ink);
}

.append-row-button {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  display: block;
  font: 700 13px/1 var(--sans);
  margin: 6px 0 2px 6px;
  opacity: 0.72;
  padding: 8px 10px;
  text-align: left;
  width: max-content;
}

.append-row-button:hover,
.append-row-button:focus-visible {
  color: var(--accent);
  opacity: 1;
  outline: none;
}

.drop-caret {
  background: var(--accent);
  bottom: 4px;
  display: none;
  position: absolute;
  top: 4px;
  width: 2px;
  z-index: 3;
}

.lyric-line.drag-over .drop-caret {
  display: block;
}

.chord-token {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  box-sizing: border-box;
  border-radius: 5px;
  color: var(--chord-ink);
  cursor: grab;
  display: inline-flex;
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 800;
  height: 22px;
  line-height: 20px;
  min-height: 22px;
  min-width: 0;
  padding: 0 3px;
  position: absolute;
  top: 0;
  transform: translateX(-3px);
  user-select: none;
  white-space: nowrap;
  z-index: 4;
}

.chord-token:hover {
  background: var(--chord-hover-bg);
  border-color: var(--chord-hover-line);
}

.chord-token.modifier-target {
  background: var(--chord-hover-bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent), transparent 62%);
  z-index: 8;
}

.chord-token.modifier-target::after {
  background: var(--accent);
  border-radius: 5px;
  color: white;
  content: "Modify " attr(data-value);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 800;
  left: 50%;
  line-height: 1;
  padding: 4px 6px;
  pointer-events: none;
  position: absolute;
  top: -24px;
  transform: translateX(-50%);
  white-space: nowrap;
}

.chord-token.selected {
  background: #1f7a5a;
  border-color: #1f7a5a;
  color: white;
}

.preview {
  background: var(--preview-bg);
  border-radius: 8px;
  color: var(--preview-ink);
  flex: 1;
  font-family: var(--mono);
  line-height: 1.55;
  margin: 0;
  min-height: 0;
  overflow: auto;
  padding: 14px;
  white-space: pre;
}

.export-layout {
  grid-template-columns: minmax(0, 1fr);
}

.export-text {
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--ink);
  border-radius: 8px;
  font-family: var(--mono);
  line-height: 1.45;
  min-height: 560px;
  padding: 14px;
  resize: vertical;
  width: 100%;
}

.toast {
  background: #17201b;
  border-radius: 7px;
  bottom: 18px;
  color: white;
  left: 50%;
  opacity: 0;
  padding: 10px 14px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 12px);
  transition: 160ms ease;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 980px) {
  .editor-grid {
    grid-template-columns: minmax(0, 1fr) 8px minmax(240px, var(--preview-width, 320px));
  }

  .editor-grid.preview-collapsed {
    grid-template-columns: minmax(0, 1fr) 50px;
  }

  .panel.side {
    grid-column: 1 / -1;
    order: -1;
  }

  .preview-panel.collapsed .lyrics-tools {
    justify-content: flex-start;
  }

  .preview-panel {
    height: min(420px, 70vh);
    max-height: min(420px, 70vh);
  }

  .lyrics-editor {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .editor-grid,
  .editor-grid.preview-collapsed {
    grid-template-columns: 1fr;
  }

  .preview-resizer {
    display: none;
  }

  .topbar,
  .song-card,
  .library-tools,
  .three,
  .metadata-grid,
  .metadata-mini-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    display: grid;
  }

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