:root {
  color-scheme: light;
  --bg: #f5f6f1;
  --panel: #ffffff;
  --panel-muted: #eef2ec;
  --ink: #171c18;
  --muted: #667066;
  --line: #d9ded5;
  --accent: #1f7a62;
  --accent-strong: #115c49;
  --accent-soft: #d9eee5;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(37, 43, 35, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  min-height: 100vh;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.sidebar-collapsed .library-panel {
  display: none;
}

.sidebar-toggle {
  flex-shrink: 0;
}

.song-title-group {
  flex: 1;
  min-width: 0;
}

.library-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.brand-row,
.song-header,
.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
}

h2 {
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.03;
}

.brand-row p,
.eyebrow,
.song-meta,
label span,
.song-row span,
.list-empty {
  color: var(--muted);
}

.icon-button {
  width: 40px;
  min-width: 40px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.search-box,
.import-form label,
.form-grid label,
.content-label,
.toolbar label {
  display: grid;
  gap: 7px;
}

label span {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.import-form {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-muted);
}

.import-form button,
.dialog-actions button[type="submit"] {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.import-form button:hover:not(:disabled),
.dialog-actions button[type="submit"]:hover:not(:disabled) {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.sync-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbf8;
}

.sync-panel > div:first-child {
  display: grid;
  gap: 4px;
}

.sync-panel span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.sync-panel strong {
  overflow-wrap: anywhere;
}

.sync-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.song-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding-right: 4px;
}

.song-row {
  display: grid;
  gap: 4px;
  width: 100%;
  height: auto;
  min-height: 68px;
  padding: 12px;
  text-align: left;
  border-color: transparent;
  background: transparent;
}

.song-row strong {
  overflow-wrap: anywhere;
}

.song-row.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.list-empty {
  padding: 16px 4px;
}

.song-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  min-height: 100vh;
}

.song-header {
  align-items: flex-start;
  padding: 32px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.eyebrow {
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 700;
}

.song-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.song-meta span {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 8px;
  padding: 0 10px;
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.danger-button {
  color: var(--danger);
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 14px;
  padding: 14px 32px;
  border-bottom: 1px solid var(--line);
  background: #fafbf8;
}

.toolbar label {
  width: min(180px, 30vw);
}

.viewer {
  overflow: auto;
  min-width: 0;
  padding: 32px 32px 104px;
}

.empty-state {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.sheet {
  --sheet-font-size: 16px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: var(--sheet-font-size);
  line-height: 1.45;
  white-space: pre;
}

.sheet-line {
  min-height: calc(var(--sheet-font-size) * 1.45);
}

.sheet-line.has-chords {
  margin: 7px 0;
}

.chord-line {
  min-height: calc(var(--sheet-font-size) * 1.25);
  color: var(--accent-strong);
  font-weight: 800;
}

.lyric-line {
  min-height: calc(var(--sheet-font-size) * 1.25);
  color: var(--ink);
}

.plain-chord-line,
.pair-desktop-chords {
  color: var(--accent-strong);
  font-weight: 800;
}

.mobile-flow-line {
  display: none;
}

.section-label {
  display: block;
  width: fit-content;
  margin: 22px 0 8px;
  border-radius: 8px;
  padding: 3px 9px;
  color: #fff;
  background: #313a33;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
  font-weight: 800;
}

dialog {
  width: min(880px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(12, 18, 14, 0.45);
}

#songForm {
  display: grid;
  gap: 20px;
  padding: 22px;
}

.dialog-header {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  font-size: 24px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

textarea {
  min-height: 360px;
  resize: vertical;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  line-height: 1.4;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(380px, calc(100vw - 40px));
  transform: translateY(12px);
  border-radius: 8px;
  padding: 12px 14px;
  color: #fff;
  background: #222a24;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

.toast.error {
  background: var(--danger);
}

.autoscroll-controls {
  position: fixed;
  right: 24px;
  bottom: 20px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(430px, calc(100vw - 48px));
  border: 1px solid rgba(217, 222, 213, 0.92);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 14px 32px rgba(37, 43, 35, 0.16);
  backdrop-filter: blur(10px);
}

.autoscroll-controls.hidden {
  display: none;
}

.autoscroll-controls button {
  min-width: 78px;
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.autoscroll-controls.is-active button {
  border-color: #313a33;
  background: #313a33;
}

.autoscroll-controls label {
  display: grid;
  flex: 1;
  gap: 4px;
  min-width: 0;
}

.autoscroll-controls input {
  padding: 0;
}

.autoscroll-controls output {
  min-width: 58px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

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

  .library-panel {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .song-panel {
    min-height: 70vh;
  }

  .song-header,
  .toolbar,
  .viewer {
    padding-left: 20px;
    padding-right: 20px;
  }

  .viewer {
    padding-bottom: 112px;
  }

  .sheet {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .sheet-line {
    min-height: 0;
    white-space: normal;
  }

  .chord-lyric-pair {
    margin: 12px 0;
  }

  .pair-desktop-chords,
  .pair-desktop-lyrics {
    display: none;
  }

  .mobile-flow-line {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 10px;
    align-items: flex-end;
  }

  .mobile-flow-segment {
    display: inline-grid;
    grid-template-rows: auto auto;
    min-width: 0;
    max-width: 100%;
    break-inside: avoid;
  }

  .mobile-flow-chord {
    color: var(--accent-strong);
    font-size: 0.82em;
    font-weight: 800;
    line-height: 1.1;
  }

  .mobile-flow-lyric {
    color: var(--ink);
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .plain-chord-line {
    white-space: pre-wrap;
  }

  .song-header,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .sidebar-toggle {
    align-self: flex-start;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions button {
    flex: 1;
  }

  .toolbar label {
    width: 100%;
  }

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

  .autoscroll-controls {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
  }
}
