:root {
  color-scheme: dark;

  --background: #0a0c10;
  --surface: #101319;
  --surface-raised: #171b22;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f4f5f7;
  --muted: #8e96a3;
  --accent: #f5b971;
  --accent-soft: rgba(245, 185, 113, 0.1);
  --violet: #b6a3ff;
  --danger: #fb7185;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;

  overflow: hidden;

  background: var(--background);
  color: var(--text);

  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

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

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app {
  height: 100vh;

  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.toolbar {
  display: grid;
  grid-template-columns: auto minmax(190px, 1fr) auto auto;
  align-items: end;

  gap: clamp(18px, 2.5vw, 38px);

  padding: 14px 20px;

  background: rgba(10, 12, 16, 0.95);

  border-bottom: 1px solid var(--line);
}

.brand {
  align-self: center;

  display: inline-flex;
  align-items: center;

  gap: 9px;

  color: var(--text);

  font-size: 13px;
  font-weight: 700;

  text-decoration: none;
}

.brand-mark {
  width: 10px;
  height: 10px;

  background: linear-gradient(135deg, var(--accent), var(--violet));

  border-radius: 50%;
}

.song-title,
.section-title {
  width: 100%;

  padding: 0;

  background: transparent;
  color: var(--text);

  border: 0;

  font-weight: 620;
  letter-spacing: -0.03em;
}

.song-title {
  height: 38px;

  font-size: 20px;
}

.song-settings {
  display: flex;
  align-items: end;

  gap: 8px;
}

.song-settings label {
  min-width: 105px;
}

.song-settings .compact-setting {
  min-width: 70px;
}

.song-settings label > span,
.editor-label {
  display: block;

  margin-bottom: 5px;

  color: var(--muted);

  font-size: 9px;
  font-weight: 750;

  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.song-settings select,
.song-settings input,
.add-section select {
  width: 100%;
  height: 34px;

  padding: 0 9px;

  background: var(--surface-raised);
  color: var(--text);

  border: 1px solid var(--line);
  border-radius: 6px;
}

.toolbar-actions {
  align-self: center;

  display: flex;
  align-items: center;

  gap: 10px;
}

.save-status {
  color: var(--muted);

  font-size: 10px;

  white-space: nowrap;
}

.save-status.saving {
  color: var(--accent);
}

.text-button,
.section-actions button,
.transpose-actions button {
  min-height: 32px;

  padding: 0 10px;

  background: transparent;
  color: var(--muted);

  border: 1px solid var(--line);
  border-radius: 6px;
}

.text-button:hover,
.section-actions button:hover,
.transpose-actions button:hover {
  color: var(--text);

  border-color: var(--line-strong);
}

.workspace {
  min-height: 0;

  display: grid;
  grid-template-columns: 220px minmax(460px, 1fr) 260px;
}

.structure-panel,
.palette-panel,
.editor-panel {
  min-height: 0;
}

.structure-panel,
.palette-panel {
  display: flex;
  flex-direction: column;

  padding: 22px 16px;

  background: var(--surface);
}

.structure-panel {
  border-right: 1px solid var(--line);
}

.palette-panel {
  border-left: 1px solid var(--line);
}

.panel-heading,
.editor-heading,
.sheet-heading,
.transpose-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;

  gap: 16px;
}

.eyebrow {
  margin: 0 0 5px;

  color: var(--muted);

  font-size: 9px;
  font-weight: 750;

  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h2,
h3,
p {
  margin-top: 0;
}

.panel-heading h2,
.transpose-panel h3 {
  margin-bottom: 0;

  font-size: 18px;
  font-weight: 620;

  letter-spacing: -0.035em;
}

.count {
  min-width: 25px;
  height: 25px;

  display: grid;
  place-items: center;

  color: var(--muted);

  border: 1px solid var(--line);
  border-radius: 50%;

  font-size: 10px;
}

.section-list {
  min-height: 0;

  display: flex;
  flex: 1;
  flex-direction: column;

  gap: 5px;

  margin: 20px 0;

  overflow-y: auto;
}

.section-item {
  width: 100%;

  display: grid;
  grid-template-columns: 25px minmax(0, 1fr) auto;
  align-items: center;

  gap: 9px;

  padding: 10px 9px;

  background: transparent;
  color: var(--muted);

  border: 1px solid transparent;
  border-radius: 7px;

  text-align: left;
}

.section-item:hover {
  background: rgba(255, 255, 255, 0.025);
  color: var(--text);
}

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

  border-color: rgba(245, 185, 113, 0.28);
}

.section-index,
.section-lines {
  color: var(--muted);

  font-size: 9px;
}

.section-item strong {
  overflow: hidden;

  font-size: 12px;
  font-weight: 600;

  text-overflow: ellipsis;
  white-space: nowrap;
}

.add-section {
  display: grid;
  grid-template-columns: 1fr;

  gap: 7px;
}

.add-section button {
  height: 36px;

  background: var(--accent-soft);
  color: var(--accent);

  border: 1px solid rgba(245, 185, 113, 0.28);
  border-radius: 6px;
}

.editor-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);

  background:
    radial-gradient(
      circle at 50% 20%,
      rgba(182, 163, 255, 0.04),
      transparent 45%
    );
}

.editor-heading {
  padding: 16px 22px;

  border-bottom: 1px solid var(--line);
}

.section-title {
  font-size: 22px;
}

.section-actions {
  display: flex;

  gap: 5px;
}

.section-actions .danger:hover {
  color: var(--danger);

  border-color: rgba(251, 113, 133, 0.4);
}

.editor-body {
  min-height: 0;

  display: grid;
  grid-template-columns:
    minmax(0, 1.08fr)
    minmax(0, 0.92fr);
}

.writing-area {
  min-height: 0;

  display: grid;
  grid-template-rows: auto minmax(0, 1fr);

  padding: 20px 0 22px 22px;
}

.writing-area[hidden] {
  display: none;
}

#lyricsEditor {
  width: 100%;
  height: 100%;

  padding: 18px;

  resize: none;

  background: rgba(0, 0, 0, 0.16);
  color: var(--text);

  border: 1px solid var(--line);
  border-radius: 8px;

  font-family:
    "SFMono-Regular",
    Consolas,
    "Liberation Mono",
    monospace;
  font-size: 14px;

  line-height: 1.8;
}

#lyricsEditor::placeholder {
  color: #555d69;
}

.tab-editor {
  min-height: 0;

  padding: 20px 0 22px 22px;
}

.tab-editor[hidden] {
  display: none;
}

.tab-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;

  gap: 14px;

  margin-bottom: 9px;
}

.tab-toolbar .editor-label {
  margin-bottom: 0;
}

.tab-actions {
  display: flex;

  gap: 6px;
}

.tab-actions button {
  min-height: 29px;

  padding: 0 9px;

  background: transparent;
  color: var(--muted);

  border: 1px solid var(--line);
  border-radius: 5px;

  font-size: 10px;
}

.tab-actions button:hover {
  color: var(--accent);

  border-color: rgba(245, 185, 113, 0.32);
}

.tab-rows {
  overflow-x: auto;

  background: rgba(0, 0, 0, 0.2);

  border: 1px solid var(--line);
  border-radius: 8px;
}

.tab-row {
  min-width: 680px;

  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;

  border-bottom: 1px solid rgba(255, 255, 255, 0.045);
}

.tab-row:last-child {
  border-bottom: 0;
}

.string-label {
  color: var(--accent);

  font-family:
    "SFMono-Regular",
    Consolas,
    "Liberation Mono",
    monospace;
  font-size: 12px;
  font-weight: 700;

  text-align: center;
}

.tab-input {
  width: 100%;
  height: 39px;

  padding: 0 10px;

  background: transparent;
  color: var(--text);

  border: 0;

  font-family:
    "SFMono-Regular",
    Consolas,
    "Liberation Mono",
    monospace;
  font-size: 13px;

  letter-spacing: 0.03em;
  white-space: pre;
}

.tab-input:focus-visible {
  position: relative;

  outline-offset: -2px;
}

.tab-legend {
  display: flex;
  flex-wrap: wrap;

  gap: 8px 14px;

  padding: 11px 2px 0;

  color: var(--muted);

  font-size: 9px;
}

.tab-legend b {
  color: var(--violet);

  font-family: monospace;
}

.tab-preview {
  min-width: max-content;

  margin: 0;

  color: var(--text);

  font-family:
    "SFMono-Regular",
    Consolas,
    "Liberation Mono",
    monospace;
  font-size: 13px;

  line-height: 1.75;
  white-space: pre;
}

.sheet {
  min-height: 0;

  display: grid;
  grid-template-rows: auto minmax(0, 1fr);

  padding: 20px 22px;

  border-left: 1px solid var(--line);
}

.sheet-heading {
  padding-bottom: 8px;
}

.sheet-heading .editor-label {
  margin-bottom: 0;
}

.sheet-heading > span:last-child {
  color: var(--muted);

  font-size: 9px;
}

.sheet-preview {
  min-height: 0;

  padding: 18px;

  overflow: auto;

  background: rgba(255, 255, 255, 0.018);

  border: 1px solid var(--line);
  border-radius: 8px;
}

.sheet-line {
  min-height: 34px;

  width: max-content;
  min-width: 100%;

  white-space: pre;
}

.lyric-segment {
  display: inline-flex;
  flex-direction: column;

  min-width: 1.4em;

  vertical-align: bottom;
}

.inline-chord {
  min-height: 15px;

  color: var(--accent);

  font-size: 10px;
  font-weight: 700;
}

.inline-lyric {
  font-size: 13px;

  line-height: 1.45;
}

.empty-preview {
  color: #555d69;

  font-size: 12px;
}

.palette-help {
  margin: 16px 0;

  color: var(--muted);

  font-size: 10px;

  line-height: 1.5;
}

.chord-palette {
  display: grid;
  grid-template-columns: 1fr 1fr;

  gap: 7px;
}

.chord-option {
  min-width: 0;

  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
}

.insert-chord,
.hear-chord {
  height: 39px;

  background: var(--surface-raised);
  color: var(--text);

  border: 1px solid var(--line);
}

.insert-chord {
  overflow: hidden;

  padding: 0 8px;

  border-radius: 6px 0 0 6px;

  font-size: 12px;
  font-weight: 650;

  text-align: left;
  text-overflow: ellipsis;
}

.hear-chord {
  margin-left: -1px;
  padding: 0;

  color: var(--muted);

  border-radius: 0 6px 6px 0;
}

.insert-chord:hover,
.hear-chord:hover,
.hear-chord.sounding {
  background: var(--accent-soft);
  color: var(--accent);

  border-color: rgba(245, 185, 113, 0.32);
}

.insert-chord:disabled {
  color: #555d69;

  cursor: not-allowed;
  opacity: 0.55;
}

.transpose-panel,
.notation-help {
  margin-top: 20px;
  padding-top: 18px;

  border-top: 1px solid var(--line);
}

.transpose-actions {
  display: grid;
  grid-template-columns: 32px auto 32px;
  align-items: center;

  gap: 7px;
}

.transpose-actions button {
  padding: 0;

  color: var(--text);

  font-size: 18px;
}

.transpose-actions span {
  color: var(--muted);

  font-size: 9px;
}

.notation-help {
  margin-top: auto;
}

.notation-help code {
  display: block;

  padding: 9px;

  background: rgba(0, 0, 0, 0.2);
  color: var(--violet);

  border-radius: 5px;

  font-size: 10px;
}

.notation-help > p:last-child {
  margin: 9px 0 0;

  color: var(--muted);

  font-size: 9px;

  line-height: 1.5;
}

.print-document {
  display: none;
}

@media (max-width: 1050px) {
  body {
    overflow: auto;
  }

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

  .toolbar {
    grid-template-columns: auto 1fr auto;
  }

  .song-settings {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .workspace {
    grid-template-columns: 190px minmax(420px, 1fr);
  }

  .palette-panel {
    grid-column: 1 / -1;

    min-height: 300px;

    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .chord-palette {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .notation-help {
    margin-top: 20px;
  }
}

@media (max-width: 850px) {
  .editor-body {
    grid-template-columns: 1fr;
    grid-template-rows:
      minmax(330px, 1fr)
      minmax(250px, 0.8fr);
  }

  .writing-area,
  .tab-editor {
    padding: 18px 18px 0;
  }

  .sheet {
    padding: 18px;

    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (max-width: 700px) {
  .toolbar {
    grid-template-columns: 1fr auto;

    padding: 14px;
  }

  .song-title {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .song-settings {
    grid-row: 3;

    flex-wrap: wrap;
  }

  .toolbar-actions {
    grid-column: 2;
    grid-row: 1;
  }

  .save-status {
    display: none;
  }

  .workspace {
    display: block;
  }

  .structure-panel,
  .palette-panel {
    min-height: 0;
  }

  .structure-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .section-list {
    max-height: 210px;
  }

  .editor-panel {
    min-height: 760px;
  }

  .editor-heading {
    align-items: end;

    padding: 14px;
  }

  .section-actions button {
    padding: 0 7px;

    font-size: 10px;
  }

  .writing-area,
  .sheet {
    padding-right: 14px;
    padding-left: 14px;
  }

  .chord-palette {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media print {
  @page {
    margin: 0.65in;
  }

  :root {
    color-scheme: light;
  }

  body {
    overflow: visible;

    background: white;
    color: #111;

    font-family:
      Arial,
      Helvetica,
      sans-serif;
  }

  .app {
    display: none;
  }

  .print-document {
    display: block;
  }

  .print-header {
    display: flex;
    align-items: end;
    justify-content: space-between;

    gap: 24px;

    padding-bottom: 14px;

    border-bottom: 2px solid #111;
  }

  .print-header h1 {
    margin: 0;

    font-size: 24pt;

    letter-spacing: -0.035em;
  }

  .print-header p {
    margin: 0 0 3px;

    color: #555;

    font-size: 9pt;

    white-space: nowrap;
  }

  .print-header p span {
    padding: 0 4px;
  }

  .print-sections {
    padding-top: 7px;
  }

  .print-section {
    padding: 15px 0 9px;

    break-inside: avoid;
  }

  .print-section h2 {
    margin: 0 0 12px;

    color: #555;

    font-size: 9pt;
    font-weight: 700;

    letter-spacing: 0.13em;
    text-transform: uppercase;
  }

  .print-chord-sheet {
    overflow: visible;
  }

  .print-chord-sheet .sheet-line {
    min-height: 30px;

    font-size: 0;

    white-space: pre;
  }

  .print-chord-sheet .lyric-segment {
    display: inline-flex;
    flex-direction: column;

    min-width: 1.3em;

    vertical-align: bottom;
  }

  .print-chord-sheet .inline-chord {
    min-height: 13px;

    color: #111;

    font-size: 8.5pt;
    font-weight: 700;
  }

  .print-chord-sheet .inline-lyric {
    color: #111;

    font-size: 10.5pt;

    line-height: 1.35;
  }

  .print-tab {
    margin: 0;

    overflow: visible;

    color: #111;

    font-family:
      "Courier New",
      Courier,
      monospace;
    font-size: 9pt;

    line-height: 1.65;
    white-space: pre;
  }

  .print-empty {
    margin: 0;

    color: #888;

    font-size: 9pt;
    font-style: italic;
  }
}
