/* ── Reset & Variables ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f5f3ee;
  --surface:     #ffffff;
  --surface2:    #f0ede6;
  --border:      #d8d4cc;
  --border-light:#e8e4dc;
  --text:        #1a1814;
  --text-muted:  #6b6760;
  --text-faint:  #a09c96;
  --primary:     #2c5282;
  --primary-h:   #1a3a5c;
  --accent:      #c0392b;
  --accent-h:    #96281b;
  --chord-color: #c0392b;
--green:       #27ae60;
  --header-h:    56px;
  --sidebar-w:   260px;
  --sidebar-files-w:  200px;
  --sidebar-chords-w: 240px;
  --toolbar-h:   88px;
  --radius:      6px;
  --shadow:      0 1px 3px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.06);
  --shadow-lg:   0 4px 16px rgba(0,0,0,.16);
  --font-ui:     -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-lyrics: 'Georgia', 'Times New Roman', serif;
  --font-mono:   'Courier New', Courier, monospace;
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ─────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100%; }

/* ── Header ─────────────────────────────────────────────────── */
#header {
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  z-index: 100;
}
.header-left  { display: flex; align-items: center; gap: 8px; min-width: 0; }
.header-center { flex: 1; text-align: center; font-size: 15px; font-weight: 600; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: 6px; }

.sync-status {
  font-size: 11px;
  color: rgba(255,255,255,.6);
  white-space: nowrap;
  transition: color .15s;
}
.sync-status.sync-error { color: #ffb4a8; }

.app-logo { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.logo-icon { font-size: 20px; }
.logo-text { font-size: 17px; font-weight: 700; letter-spacing: -.3px; }

.btn-header {
  background: rgba(255,255,255,.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: var(--radius);
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-header:hover { background: rgba(255,255,255,.28); }
#btn-ready-toggle.ready { background: #bfe3ff; color: #0d3a5c; border-color: #8fcaf5; }
#btn-ready-toggle.ready:hover { background: #a9d7fc; }

/* ── Layout ─────────────────────────────────────────────────── */
#layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
/* Desktop: files menu on the left, chords menu on the right, main content between */
#sidebar-files, #sidebar-chords {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface2);
  overflow: hidden;
}

#sidebar-files {
  width: var(--sidebar-files-w);
  border-right: 1px solid var(--border);
}

#sidebar-chords {
  width: var(--sidebar-chords-w);
  border-left: 1px solid var(--border);
}

#panel-songs, #panel-chords {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* iPad: no side menus — full-width performance view */
body.is-ipad #sidebar-files, body.is-ipad #sidebar-chords { display: none; }

/* Landing page (song grid): no side menus in any mode */
body.view-landing #sidebar-files, body.view-landing #sidebar-chords { display: none; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-light);
  background: var(--surface2);
  flex-shrink: 0;
}

.panel-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}

.panel-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 8px;
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}

/* ── Song List ─────────────────────────────────────────────── */
#song-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
}

.song-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s;
  margin-bottom: 1px;
}
.song-list-item:hover { background: var(--border-light); }
.song-list-item.active { background: var(--primary); color: #fff; }
.song-list-item.active .song-list-title { color: #fff; }

.song-list-title {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-icon-xs {
  opacity: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  font-size: 12px;
  color: var(--text-muted);
  transition: opacity .12s, background .12s;
  flex-shrink: 0;
}
.song-list-item:hover .btn-icon-xs { opacity: 1; }
.song-list-item.active .btn-icon-xs { opacity: .6; color: #fff; }
.btn-icon-xs:hover { background: rgba(0,0,0,.12); opacity: 1 !important; }

/* ── Chord Palette ─────────────────────────────────────────── */
.chord-search-input {
  flex: 1;
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
  min-width: 0;
}
.chord-search-input:focus { outline: none; border-color: var(--primary); }

#chord-palette {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
}

.chord-group { margin-bottom: 10px; border-radius: var(--radius); transition: opacity .15s; }
.chord-group.dragging-group { opacity: .35; }
.chord-group-bookmarked {
  background: #fdf6e3;
  border: 1px solid #f0dfa8;
  padding: 6px 6px 8px;
  margin: -6px -6px 12px;
}
.chord-group-bookmarked .chord-group-label { color: #8a6d1f; }
.bookmark-placeholder {
  font-size: 11px;
  color: var(--text-faint);
  font-style: italic;
  padding: 2px 2px 4px;
}
.chord-group-label-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
  padding-left: 2px;
}
.chord-group-label-row:hover .group-rename-btn { opacity: 1; }
.chord-group-label-row:hover .group-drag-handle { opacity: .5; }

.group-drag-handle {
  width: 12px;
  font-size: 11px;
  padding: 0;
}
body.is-ipad .group-drag-handle { opacity: .5; }

.chord-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
  cursor: pointer;
}

.group-rename-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 2px;
  font-size: 9px;
  line-height: 1;
  color: var(--text-faint);
  opacity: 0;
  transition: opacity .12s, color .12s;
}
.group-rename-btn:hover { color: var(--primary); }
body.is-ipad .group-rename-btn { opacity: .6; }

.chord-group-rename-input {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  border: 1px solid var(--primary);
  border-radius: 3px;
  padding: 1px 4px;
  background: var(--surface);
  color: var(--text);
  flex: 1;
  min-width: 0;
  outline: none;
}

.chord-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chord-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--chord-color);
  cursor: grab;
  user-select: none;
  transition: background .1s, border-color .1s, transform .1s, box-shadow .1s;
  min-width: 40px;
  text-align: center;
}
.chord-chip:hover {
  background: #fff8f7;
  border-color: var(--chord-color);
  box-shadow: 0 1px 4px rgba(192,57,43,.15);
}
.chord-chip.dragging { opacity: .4; transform: scale(.96); }

.btn-chip-add {
  padding: 2px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background .1s, color .1s, border-color .1s;
}
.btn-chip-add:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

.chip-edit-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 15px;
  height: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 8px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, background .12s, color .12s;
}
.chord-chip:hover .chip-edit-btn { opacity: 1; }
.chip-edit-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
body.is-ipad .chip-edit-btn { opacity: .7; width: 18px; height: 18px; font-size: 10px; }

.chip-delete-btn {
  position: absolute;
  top: -6px;
  left: -6px;
  width: 15px;
  height: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 10px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, background .12s, color .12s;
}
.chord-chip:hover .chip-delete-btn { opacity: 1; }
.chip-delete-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
body.is-ipad .chip-delete-btn { opacity: .7; width: 18px; height: 18px; font-size: 12px; }

.chip-bookmark-btn {
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 15px;
  height: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 9px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, background .12s, color .12s;
}
.chord-chip:hover .chip-bookmark-btn { opacity: 1; }
.chip-bookmark-btn:hover { background: #f5c518; color: #5c4300; border-color: #f5c518; }
.chip-bookmark-btn.bookmarked { opacity: .9; background: #f5c518; color: #5c4300; border-color: #f5c518; }
body.is-ipad .chip-bookmark-btn { opacity: .7; width: 18px; height: 18px; font-size: 11px; }
body.is-ipad .chip-bookmark-btn.bookmarked { opacity: 1; }

/* ── Main Content ─────────────────────────────────────────── */
#main {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.view { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.view.active { display: flex; }

/* ── Song List View ─────────────────────────────────────────── */
#view-song-list {
  overflow-y: auto;
  padding: 0;
}

.view-hero {
  text-align: center;
  padding: 40px 20px 24px;
  background: linear-gradient(to bottom, var(--primary) 0%, #3a6dad 100%);
  color: #fff;
}
.view-hero h2 { font-size: 28px; font-weight: 800; margin-bottom: 6px; letter-spacing: -.5px; }
.view-hero p { font-size: 15px; opacity: .75; margin-bottom: 20px; }

.song-grid-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 0;
}
.song-count {
  font-size: 12px;
  color: var(--text-muted);
}

#song-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  padding: 20px;
}

.song-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  transition: box-shadow .15s, transform .15s, border-color .15s;
  box-shadow: var(--shadow);
}
.song-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  border-color: var(--primary);
}
.song-card.song-card-ready { background: #d6ecff; border-color: #a9d4f5; }
.song-card-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; color: var(--text); }
.song-card-artist { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.song-card-meta {
  font-size: 11px;
  color: var(--text-faint);
  display: flex;
  gap: 6px;
}
.song-card-meta span {
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 3px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  grid-column: 1 / -1;
}
.empty-state p { margin-bottom: 14px; font-size: 15px; }

/* ── Editor View ─────────────────────────────────────────────── */
#view-editor { background: var(--bg); }

#editor-toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px 8px;
  flex-shrink: 0;
}

.title-input {
  display: block;
  width: 100%;
  border: none;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  margin-bottom: 4px;
  padding: 0;
  outline: none;
  font-family: var(--font-ui);
}
.title-input::placeholder { color: var(--text-faint); font-weight: 400; }

.artist-input {
  display: block;
  width: 100%;
  border: none;
  font-size: 14px;
  color: var(--text-muted);
  background: transparent;
  margin-bottom: 8px;
  padding: 0;
  outline: none;
  font-family: var(--font-ui);
}
.artist-input::placeholder { color: var(--text-faint); }

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.select-sm {
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.select-sm:focus { outline: none; border-color: var(--primary); }

.input-sm {
  width: 52px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
  text-align: center;
}
.input-sm:focus { outline: none; border-color: var(--primary); }

.toolbar-divider { width: 1px; height: 20px; background: var(--border); margin: 0 2px; }

.btn-toolbar {
  padding: 4px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .1s, color .1s;
  white-space: nowrap;
}
.btn-toolbar:hover { background: var(--border-light); color: var(--text); }
.btn-toolbar:disabled { opacity: .5; cursor: default; }
.btn-toolbar:disabled:hover { background: var(--surface2); color: var(--text-muted); }
.btn-toolbar-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-toolbar-primary:hover { background: var(--primary-h); color: #fff; }

.editor-hint {
  font-size: 11px;
  color: var(--text-faint);
  padding: 5px 14px;
  background: #fffef8;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

#editor-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 60px;
}

/* ── Editor Lines ─────────────────────────────────────────── */
.editor-line {
  position: relative;
  margin-bottom: 4px;
  border-radius: var(--radius);
  transition: background .1s, opacity .15s;
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
}
.editor-line:hover { background: rgba(0,0,0,.02); }
.editor-line:hover .line-controls { opacity: 1; }
.editor-line:hover .drag-handle { opacity: .5; }
.editor-line.dragging-line { opacity: .35; }
.editor-line.editor-line-selected { background: rgba(44,82,130,.08); }
.editor-line.editor-line-selected:hover { background: rgba(44,82,130,.12); }

/* Line selection checkbox */
.line-select-checkbox {
  flex-shrink: 0;
  width: 13px;
  height: 13px;
  margin: 5px 2px 0 0;
  cursor: pointer;
  opacity: .35;
  transition: opacity .12s;
  align-self: center;
}
.editor-line:hover .line-select-checkbox,
.line-select-checkbox:checked {
  opacity: 1;
}

/* Sections (Chorus, Verse, etc.) — a run of lines with a shared label,
   shown as a bracket down the right edge with the name written vertically. */
.editor-section {
  display: flex;
  align-items: stretch;
  margin-bottom: 4px;
}
.editor-section-lines {
  flex: 1;
  min-width: 0;
}
.editor-section-lines .editor-line { margin-bottom: 0; }
.editor-section-lines .editor-line:not(:last-child) { margin-bottom: 2px; }
.editor-section-label {
  flex-shrink: 0;
  width: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-left: 4px;
  background: var(--surface2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 6px 0;
}
.editor-section-label-text {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--primary);
  white-space: nowrap;
  cursor: pointer;
}
.editor-section-remove {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  color: var(--text-faint);
  padding: 2px;
}
.editor-section-remove:hover { color: var(--accent); }

/* Drag handle */
.drag-handle {
  flex-shrink: 0;
  width: 16px;
  font-size: 14px;
  color: var(--text-faint);
  cursor: grab;
  opacity: 0;
  transition: opacity .12s;
  user-select: none;
  align-self: center;
  padding: 4px 2px;
  line-height: 1;
}
.drag-handle:active { cursor: grabbing; }

/* Line drop indicator */
.line-drop-indicator {
  height: 2px;
  background: var(--primary);
  border-radius: 1px;
  margin: 1px 0;
  pointer-events: none;
  animation: blink .5s ease-in-out infinite alternate;
  width: 100%;
}

/* Column wrapper: stacks chord-bar above lyric-row, fills remaining width */
.line-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.line-col-instrumental {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.line-controls {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .12s;
  z-index: 2;
}

.btn-line-ctrl {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background .1s, color .1s;
}
.btn-line-ctrl:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Chord bar above each lyric line */
.chord-bar {
  position: relative;
  height: 24px;
  margin-left: 0;
  pointer-events: auto;
  overflow: visible;
}

.editor-chord-chip {
  position: absolute;
  top: 2px;
  font-size: 12px;
  font-weight: 700;
  color: var(--chord-color);
  background: #fff5f4;
  border: 1.5px solid #f0b8b2;
  border-radius: 4px;
  padding: 0 4px;
  line-height: 18px;
  cursor: grab;
  pointer-events: all;
  transition: background .1s, border-color .1s, transform .1s, opacity .1s;
  white-space: nowrap;
  z-index: 1;
}
.editor-chord-chip:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: translateY(-1px);
}
.editor-chord-chip:active { cursor: grabbing; }
.editor-chord-chip.dragging { opacity: .35; }

.drop-indicator {
  position: absolute;
  top: 0;
  width: 2px;
  height: 22px;
  background: var(--chord-color);
  border-radius: 1px;
  pointer-events: none;
  animation: blink .6s ease-in-out infinite alternate;
}
@keyframes blink { from { opacity: 1; } to { opacity: .3; } }

.drop-ghost {
  position: absolute;
  top: 2px;
  font-size: 12px;
  font-weight: 700;
  color: var(--chord-color);
  background: #fff5f4;
  border: 1.5px dashed var(--chord-color);
  border-radius: 4px;
  padding: 0 4px;
  line-height: 18px;
  pointer-events: none;
  opacity: .7;
  white-space: nowrap;
}

/* Lyric input */
.lyric-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.lyric-input {
  flex: 1;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 16px;
  font-family: var(--font-lyrics);
  color: var(--text);
  background: transparent;
  outline: none;
  transition: border-color .15s, background .15s;
  min-width: 0;
}
.lyric-input:focus {
  border-color: var(--primary);
  background: var(--surface);
}
.lyric-input.drag-over {
  background: #f0f5ff;
  border-color: var(--primary);
}
.lyric-input::placeholder { color: var(--text-faint); font-style: italic; font-family: var(--font-ui); font-size: 13px; }


/* Blank line */
.editor-line-blank { height: 14px; min-height: 14px; }

/* Add line button */
.add-line-btn {
  display: block;
  width: 100%;
  padding: 8px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-faint);
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  transition: border-color .1s, color .1s;
  margin-top: 8px;
}
.add-line-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Viewer View ─────────────────────────────────────────────── */
#view-viewer { background: var(--bg); }

#viewer-toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.range-sm { width: 70px; accent-color: var(--primary); cursor: pointer; }

.toggle-label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
.toggle-label input[type=checkbox] { accent-color: var(--primary); width: 14px; height: 14px; cursor: pointer; }

#scroll-speed-label { opacity: .5; transition: opacity .2s; }
#scroll-speed-label.active { opacity: 1; }

#viewer-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px 80px;
  -webkit-overflow-scrolling: touch;
}

/* Columns mode (iPad): flow the song into fixed-height columns instead of a vertical scroll */
body.is-ipad #viewer-content.columns-mode {
  overflow-y: hidden;
  overflow-x: auto;
  height: 100%;
  column-width: 340px;
  column-gap: 40px;
  column-fill: auto;
  column-rule: 1px solid var(--border-light);
}
body.is-ipad #viewer-content.columns-mode .viewer-header,
body.is-ipad #viewer-content.columns-mode .viewer-line,
body.is-ipad #viewer-content.columns-mode .viewer-lyric-line,
body.is-ipad #viewer-content.columns-mode .viewer-instrumental-line {
  break-inside: avoid;
}

.viewer-header {
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--border);
}
.viewer-title { font-size: 26px; font-weight: 800; margin-bottom: 4px; color: var(--text); }
.viewer-artist { font-size: 16px; color: var(--text-muted); margin-bottom: 6px; }
.viewer-meta { font-size: 13px; color: var(--text-faint); display: flex; gap: 10px; }
.viewer-meta span { background: var(--surface2); padding: 2px 8px; border-radius: 4px; }

.viewer-line { margin-bottom: 0; }

.viewer-lyric-line {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  line-height: 1;
  margin-bottom: 2px;
}

.viewer-segment {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  vertical-align: bottom;
}

/* Groups the chord/lyric sub-segments of one word so the word wraps as a
   single unit and is never split mid-word — only whitespace wraps. */
.viewer-word {
  display: inline-flex;
  align-items: flex-end;
  flex-wrap: nowrap;
}

.viewer-chord {
  font-size: .7em;
  font-weight: 800;
  color: var(--chord-color);
  line-height: 1.6;
  min-height: 1.6em;
  font-family: var(--font-ui);
  letter-spacing: -.2px;
  white-space: nowrap;
  padding-right: 4px;
}
.viewer-chord:empty { visibility: hidden; }

.viewer-lyric {
  font-family: var(--font-lyrics);
  white-space: pre;
  color: var(--text);
  line-height: 1.4;
}


.viewer-line-blank { height: 1em; }

/* ── Chord Tooltip ──────────────────────────────────────────── */
#chord-tooltip {
  position: fixed;
  z-index: 2000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  text-align: center;
  min-width: 82px;
}
#chord-tooltip .tip-name {
  font-size: 13px;
  font-weight: 800;
  color: var(--chord-color);
  margin-bottom: 5px;
  font-family: var(--font-ui);
}
#chord-tooltip .tip-nodiagram {
  font-size: 11px;
  color: var(--text-faint);
  padding: 6px 0;
}
#chord-tooltip svg { display: block; margin: 0 auto; }

/* ── Line Context Menu (right-click copy/paste) ────────────── */
.context-menu {
  position: fixed;
  z-index: 2500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  min-width: 150px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.context-menu-item {
  background: none;
  border: none;
  text-align: left;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  border-radius: 5px;
  transition: background .1s;
}
.context-menu-item:hover:not(:disabled) { background: var(--surface2); }
.context-menu-item:disabled { color: var(--text-faint); cursor: default; }
.context-menu-divider { height: 1px; background: var(--border-light); margin: 4px 2px; }

/* ── Instrumental Lines ─────────────────────────────────────── */
.editor-line-instrumental {
  padding: 3px 4px;
  background: #f0f4fa;
  border: 1px dashed #b0bfd4;
  align-items: center;
}
.instrumental-label {
  font-size: 15px;
  color: var(--primary);
  opacity: .6;
  flex-shrink: 0;
  user-select: none;
}
.instrumental-zone {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  border-radius: 4px;
  transition: background .12s;
  padding: 2px 4px;
}
.instrumental-zone.drag-over { background: #dce8ff; }

.instrumental-chord-chip {
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius);
  padding: 2px 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  transition: background .1s, color .1s;
}
.instrumental-chord-chip:hover { background: var(--primary); color: #fff; }

.instrumental-placeholder {
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
}

/* Viewer instrumental */
.viewer-instrumental-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  flex-wrap: wrap;
}
.viewer-instrumental-label {
  font-size: .8em;
  color: var(--primary);
  opacity: .5;
  flex-shrink: 0;
}
/* ── Tab Lines ──────────────────────────────────────────────── */
.line-col-tab {
  flex-direction: row;
  align-items: flex-start;
  gap: 6px;
}
.editor-line-tab {
  padding: 3px 4px;
  background: #f7f5ef;
  border: 1px dashed #c9c2ac;
  align-items: flex-start;
}
.tab-label {
  font-size: 15px;
  color: var(--text-muted);
  opacity: .6;
  flex-shrink: 0;
  user-select: none;
  padding-top: 4px;
}
.tab-textarea {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.4;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  resize: vertical;
  white-space: pre;
  overflow-x: auto;
}
.tab-textarea:focus { border-color: var(--primary); outline: none; }
.tab-textarea::placeholder { color: var(--text-faint); }

.tab-template-btn {
  flex-shrink: 0;
  align-self: flex-start;
  padding: 4px 8px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background .1s, color .1s, border-color .1s;
}
.tab-template-btn:hover { background: var(--border-light); color: var(--text); border-color: var(--primary); }

/* Viewer tab */
.viewer-tab-line {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
}
.viewer-tab-label {
  font-size: .8em;
  color: var(--text-muted);
  opacity: .5;
  flex-shrink: 0;
  padding-top: 2px;
}
.viewer-tab {
  font-family: var(--font-mono);
  font-size: .85em;
  line-height: 1.3;
  color: var(--text);
  white-space: pre;
  overflow-x: auto;
  margin: 0;
}

.viewer-instrumental-chord {
  font-size: .85em;
  font-weight: 800;
  color: var(--primary);
  background: rgba(44,82,130,.08);
  border: 1px solid rgba(44,82,130,.2);
  border-radius: 4px;
  padding: 1px 8px;
  cursor: default;
  font-family: var(--font-ui);
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--primary-h); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--border-light); }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius);
  font-size: 18px;
  color: #fff;
  transition: background .1s;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: rgba(255,255,255,.15); }

.btn-text-sm {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-faint);
  padding: 3px 5px;
  border-radius: 3px;
  transition: color .1s, background .1s;
}
.btn-text-sm:hover { color: var(--primary); background: var(--border-light); }
.btn-text-danger:hover { color: var(--accent); background: #fdecea; }

.hidden { display: none !important; }

/* ── Dialog ─────────────────────────────────────────────────── */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.dialog {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  width: 90%;
  max-width: 540px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dialog-header h3 { font-size: 17px; font-weight: 700; }

.dialog-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  padding: 4px 6px;
  border-radius: 4px;
}
.dialog-close:hover { background: var(--surface2); }

.dialog-sub { font-size: 13px; color: var(--text-muted); }

.missing-chords-list {
  max-height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.missing-chord-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border-light);
}
.missing-chord-row:last-child { border-bottom: none; }
.missing-chord-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.missing-chord-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--chord-color);
}
.missing-chord-songs {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#paste-textarea {
  width: 100%;
  height: 240px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  font-size: 14px;
  font-family: var(--font-lyrics);
  resize: vertical;
  color: var(--text);
  background: var(--bg);
  outline: none;
}
#paste-textarea:focus { border-color: var(--primary); }

.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.dialog-footer-spacer { flex: 1; }

.btn-danger { color: #c0392b; border-color: #e6b0a8; }
.btn-danger:hover { background: #fdecea; border-color: #c0392b; }

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.form-label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  flex: 1;
  min-width: 140px;
}
.input-md {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.input-md:focus { border-color: var(--primary); }

.fret-inputs {
  display: flex;
  gap: 6px;
}
.fret-input-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
}
.fret-input { width: 100%; text-align: center; }

.dialog-error {
  font-size: 12px;
  color: #c0392b;
  min-height: 14px;
}

/* ── Read-only mode (not logged in) ────────────────────────────
   Reading/browsing stays fully usable; anything that mutates data is
   hidden or disabled. The server independently rejects writes from an
   unauthenticated session regardless of what the UI shows. */
body.read-only #btn-new-song,
body.read-only #btn-hero-new,
body.read-only #btn-sync-now,
body.read-only #btn-ready-toggle,
body.read-only #btn-edit-song,
body.read-only #btn-import,
body.read-only #file-import,
body.read-only #btn-export,
body.read-only #btn-import-chords,
body.read-only #file-import-chords,
body.read-only #btn-export-chords,
body.read-only #btn-clear-chords,
body.read-only #btn-add-chord,
body.read-only #btn-find-missing-chords,
body.read-only .song-list-item .btn-icon-xs,
body.read-only .chip-edit-btn,
body.read-only .chip-delete-btn,
body.read-only .group-rename-btn,
body.read-only .group-drag-handle {
  display: none !important;
}
body.read-only #editor-content,
body.read-only #editor-toolbar .toolbar-row,
body.read-only .title-input,
body.read-only .artist-input,
body.read-only #chord-palette {
  pointer-events: none;
  opacity: .7;
}

/* ── iPad / Touch Styles ─────────────────────────────────────── */
.btn-desktop-only { display: inline-flex; }
.viewer-ipad-only { display: none; }

body.is-ipad {
  --font-size-viewer: 20px;
}

body.is-ipad .btn-desktop-only { display: none !important; }
body.is-ipad .viewer-ipad-only { display: flex; }

body.is-ipad #main { width: 100%; }

/* iPad viewer optimizations */
body.is-ipad .viewer-title  { font-size: 30px; }
body.is-ipad .viewer-artist { font-size: 18px; }
body.is-ipad .viewer-lyric  { font-size: 22px; }
body.is-ipad .viewer-chord  { font-size: 16px; }

body.is-ipad #viewer-content { padding: 24px 24px 120px; }


/* iPad: editor is simplified / hidden on viewer */
body.is-ipad #view-editor .editor-hint { font-size: 12px; }
body.is-ipad .lyric-input { font-size: 18px; }

/* ── Scrollbar Styling ────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ── Responsive tweaks (narrow desktop) ─────────────────────── */
@media (max-width: 700px) {
  :root { --sidebar-w: 220px; --sidebar-files-w: 160px; --sidebar-chords-w: 190px; }
  .logo-text { display: none; }
  .editor-hint { display: none; }
}

/* ── Phone width (iPhone, or any narrow viewport) ─────────────
   Not gated on .is-ipad — the point is that nothing in the header or
   viewer ever overflows/clips, whatever put the viewport at this width. */
@media (max-width: 480px) {
  #header { padding: 0 6px; gap: 4px; }
  .header-center { display: none; } /* song title already shows at the top of the viewer content */
  .header-right { gap: 3px; overflow-x: auto; scrollbar-width: none; }
  .header-right::-webkit-scrollbar { display: none; }
  .btn-header { padding: 5px 8px; font-size: 11px; white-space: nowrap; }
  .sync-status { display: none; }

  /* Touch mode's tablet-sized viewer defaults are too large for a phone's
     width — same idea, scaled down so lines wrap less. */
  body.is-ipad .viewer-title  { font-size: 23px; }
  body.is-ipad .viewer-artist { font-size: 15px; }
  body.is-ipad .viewer-lyric  { font-size: 18px; }
  body.is-ipad .viewer-chord  { font-size: 14px; }
  body.is-ipad #viewer-content { padding: 16px 14px 100px; }
}


/* ── Print ─────────────────────────────────────────────────── */
@media print {
  #header, #sidebar-files, #sidebar-chords, #viewer-toolbar { display: none; }
  #main { overflow: visible; }
  #view-viewer { display: block; overflow: visible; }
  #viewer-content { padding: 0; overflow: visible; }
  .viewer-title { font-size: 20px; }
}

/* Buy Me a Coffee link under the hero button */
.support-link {
  display: block;
  width: fit-content;
  margin: 14px auto 0;
  font-size: 12px;
  color: #fff;
  opacity: .65;
  text-decoration: none;
}
.support-link:hover { opacity: 1; text-decoration: underline; }

.support-links { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; margin-top: 14px; }
.support-links .support-link { margin: 0; }
.yt-link { font-size: 12px; font-weight: 700; color: #fff; opacity: .9; text-decoration: none; }
.yt-link:hover { opacity: 1; text-decoration: underline; }

/* Back to the landing page + version label */
a.home-x { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.view-hero .ver { margin: 10px 0 0; font-size: 11px; opacity: .45; }
.view-hero .ver:empty { display: none; }
