/* Songsheets — application layout and controls. The song sheet itself is styled by sheet.css. */
*, *::before, *::after { box-sizing: border-box; }
:root {
  --radius: 10px;
  --radius-lg: 14px;
  --nav-h: 60px;                 /* height of the phone tab bar */
  --bottom-offset: 0px;          /* raised on routes that show the tab bar, so toasts clear it */
  --warn: #a35d00;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --warn: #f0b45a; } }
:root[data-theme="night"] { --warn: #f0b45a; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
@media (max-width: 499px) { html { font-size: 16px; } }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
  font-family: verdana, arial, helvetica, sans-serif;
  line-height: 1.4;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: -999px; top: 0; z-index: 100; background: var(--accent); color: var(--accent-contrast); padding: 8px 12px; }
.skip-link:focus { left: 8px; top: 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.86em; }
.spacer { flex: 1 1 auto; }
kbd {
  font-family: ui-monospace, Consolas, monospace; font-size: 0.85em;
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--surface);
}
code { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: 0.92em; background: var(--surface); border-radius: 4px; padding: 1px 4px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lead { font-size: 1.05em; color: var(--muted); }

/* ---- header and navigation ---------------------------------------------------------------------- */
.app-header {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--background);
}
.brand { text-decoration: none; font-weight: bold; font-size: 1.15em; color: var(--title); }
.app-nav { display: flex; gap: 2px; margin-left: auto; }
.nav-link {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 8px;
  text-decoration: none; color: var(--muted);
}
.nav-link:hover { background: var(--surface); color: var(--text); }
.nav-link.is-active { color: var(--accent); background: var(--surface); }

.app-main { max-width: 1100px; margin: 0 auto; padding: 12px 16px 64px; outline: none; }
body[data-route="edit"] .app-main, body[data-route="new"] .app-main { max-width: 1400px; }

/* Phones: the four main pages get a labelled tab bar at the bottom, within thumb reach. Pages you work
   inside (a song, the editor, a set, the converter) drop the header altogether: they have their own way back. */
@media (max-width: 640px) {
  .app-header { padding: 6px 14px; padding-top: max(6px, env(safe-area-inset-top)); }
  .brand { font-size: 1.05em; }
  .app-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; margin: 0; gap: 0;
    justify-content: space-around; background: var(--background); border-top: 1px solid var(--border);
    padding: 4px 6px max(4px, env(safe-area-inset-bottom));
  }
  .nav-link {
    flex: 1 1 0; flex-direction: column; justify-content: center; gap: 2px; min-height: 52px; padding: 6px 4px;
    font-size: 0.72rem; border-radius: 12px;
  }
  .nav-link.is-active { background: color-mix(in srgb, var(--accent) 16%, var(--background)); }
  .nav-text { display: block; }
  body[data-route="song"] .app-header, body[data-route="play"] .app-header, body[data-route="edit"] .app-header,
  body[data-route="new"] .app-header, body[data-route="set"] .app-header, body[data-route="convert"] .app-header { display: none; }
  body[data-route="library"], body[data-route="sets"], body[data-route="settings"], body[data-route="help"], body[data-route="notfound"] {
    --bottom-offset: calc(var(--nav-h) + env(safe-area-inset-bottom));
  }
  .view-sets.is-empty .fab { display: none; }
  body[data-route="library"] .app-main, body[data-route="sets"] .app-main, body[data-route="settings"] .app-main,
  body[data-route="help"] .app-main, body[data-route="notfound"] .app-main {
    padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 88px);
  }
  .app-main { padding-top: 8px; }
}

/* ---- buttons and inputs ------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--background); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap; line-height: 1.2;
}
.btn:hover:not([disabled]) { background: var(--surface); }
.btn[disabled] { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover:not([disabled]) { background: var(--accent); filter: brightness(1.1); }
.btn-soft {
  color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--background));
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}
.btn-soft:hover:not([disabled]) { background: color-mix(in srgb, var(--accent) 16%, var(--background)); }
.btn-lg { min-height: 48px; padding: 10px 20px; font-size: 1.05em; border-radius: 10px; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn-danger.btn-primary, .dialog .btn-primary.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--accent-contrast); }
.btn-danger-icon:hover:not([disabled]) { color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-link { border: 0; background: none; color: var(--accent); cursor: pointer; font-weight: bold; padding: 4px 6px; }
.btn-small { min-height: 30px; padding: 4px 9px; font-size: 0.92em; }
.btn-icon { width: 36px; min-width: 36px; padding: 0; }
.btn-toggle.is-on { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--background)); }
.btn .icon { flex: 0 0 auto; }
.btn.is-fav, .fav-btn.is-fav { color: #e0a800; }
.btn-icon-slot { display: inline-flex; }
.font-glyph { font-family: Georgia, serif; font-weight: bold; }
.font-glyph.small-a { font-size: 0.8em; }
.font-glyph.big-a { font-size: 1.25em; }
.font-glyph.display-glyph { font-size: 1.1em; letter-spacing: -0.03em; }

.input, .select {
  min-height: 36px; padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--background); color: var(--text);
  width: 100%;
}
.select { width: auto; max-width: 100%; padding-right: 26px; }
.input:focus, .select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.color-input { width: 48px; height: 32px; padding: 0 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--background); }
.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.check input { flex: 0 0 auto; margin: 0; }
.check > span { flex: 1 1 0; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 0.86em; color: var(--muted); }
.field-note { margin: 2px 0 0; font-size: 0.86em; }
.field-note.warn { color: var(--danger); }

/* ---- toolbars ----------------------------------------------------------------------------------- */
.toolbar { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 12px; }
.toolbar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.view-title { font-size: 1.4em; margin: 0; color: var(--text); text-wrap: balance; }
.view-nav { display: flex; align-items: center; gap: 6px; margin: 0 0 4px; }
.back-link { padding-left: 4px; color: var(--muted); }
.search-wrap { position: relative; flex: 1 1 260px; min-width: 0; display: flex; align-items: center; }
.search-wrap > .icon { position: absolute; left: 10px; color: var(--muted); pointer-events: none; }
.search-wrap .input { padding-left: 34px; padding-right: 34px; }
.search-clear {
  position: absolute; right: 3px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent;
  color: var(--muted); display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.search-clear:hover { background: var(--surface); color: var(--text); }

/* ---- library ------------------------------------------------------------------------------------ */
.view-library.is-empty .toolbar { display: none; }
.library-search { flex-wrap: nowrap; }
.sort-select, .library-more { flex: 0 0 auto; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; min-height: 28px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--background); cursor: pointer; font-size: 0.9em;
}
.chip:hover { border-color: var(--accent); }
.chip-on { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.chip-count { opacity: 0.7; font-size: 0.85em; }
.list-count { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 6px; min-height: 30px; }
.view-library.is-empty .list-count { display: none; }
.song-list, .set-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.song-row, .set-row {
  display: flex; align-items: center; gap: 8px; padding: 2px 4px 2px 0; border-bottom: 1px solid var(--border);
}
.song-row:hover, .set-row:hover { background: var(--surface); }
.song-link, .set-link { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 9px 8px; text-decoration: none; }
.song-title { font-size: 1.1em; color: var(--title); overflow-wrap: anywhere; }
.song-meta { color: var(--muted); font-size: 0.88em; overflow-wrap: anywhere; }
.song-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 0.78em; padding: 0 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.key-pill {
  flex: 0 0 auto; min-width: 2.4em; text-align: center; padding: 1px 8px; border-radius: 999px; font-size: 0.84em; font-weight: bold;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--background));
}
.song-date { flex: 0 0 auto; }
.fav-btn { color: var(--muted); }
.empty-state { text-align: center; max-width: 720px; margin: 28px auto; padding: 0 8px; }
.empty-state h2 { color: var(--text); font-size: 1.5em; margin: 0 0 6px; text-wrap: balance; }
.empty-state .lead, .convert-head .lead { text-wrap: pretty; }
.empty-state .lead { max-width: 34em; margin: 0 auto; }
.restore-line .btn-link { padding: 8px 2px; font-size: 1em; }
.empty-results { padding: 20px 4px; text-align: center; color: var(--muted); }
.empty-results p { margin: 0 0 10px; }
.start-cards { display: grid; gap: 10px; margin: 22px 0 18px; text-align: left; }
.start-card {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--surface); cursor: pointer; text-align: left; width: 100%;
}
.start-card:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.start-icon {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--background));
}
.start-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.start-title { font-weight: bold; color: var(--text); }
.start-desc { font-size: 0.9em; color: var(--muted); }
@media (min-width: 720px) {
  .start-cards { grid-template-columns: repeat(2, 1fr); }
  .start-card { flex-direction: column; align-items: flex-start; padding: 18px; }
}
body.drop-target::after {
  content: "Drop files to import them"; position: fixed; inset: 12px; z-index: 50;
  display: flex; align-items: center; justify-content: center; font-size: 1.4em;
  border: 3px dashed var(--accent); border-radius: 16px; color: var(--accent);
  background: color-mix(in srgb, var(--background) 88%, transparent); pointer-events: none;
}

.notice {
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border)); background: color-mix(in srgb, var(--accent) 7%, var(--background));
  border-radius: 12px; padding: 10px 14px; margin: 0 0 12px;
}
.notice p { margin: 0 0 8px; }
.notice-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* The round + button that opens "add a song" (phones only). */
.fab {
  display: none; position: fixed; right: 16px; z-index: 30;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  width: 56px; height: 56px; border: 0; border-radius: 50%; cursor: pointer;
  align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-contrast); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
}
.fab:active { transform: scale(0.96); }
@media (max-width: 640px) {
  .fab { display: inline-flex; }
  .view-library.is-empty .fab { display: none; }
  .view-library .toolbar-actions { display: none; }
  .chip-row { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px 6px; padding: 2px 16px 6px; scrollbar-width: none; }
  .chip-row::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; }
  .sort-select { max-width: 8.6em; }
}
@media (max-width: 499px) { .song-date { display: none; } }
@media (max-width: 640px) { .set-add-btn { display: none; } }
@media (pointer: coarse) { .drop-hint { display: none; } }

/* ---- song sheet view ---------------------------------------------------------------------------- */
.play-nav-controls { display: inline-flex; align-items: center; gap: 6px; }
.play-bar { display: none; }
.song-actions, .song-actions-phone { display: flex; align-items: center; gap: 6px; }
.song-actions { flex-wrap: wrap; justify-content: flex-end; }
.song-actions-phone { display: none; }
.sheet-toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  padding: 8px 0; margin-bottom: 8px;
  background: var(--background); border-bottom: 1px solid var(--border);
  transition: transform 0.2s ease;
}
.btn-more { display: none; }
.ctl-group { display: inline-flex; align-items: center; gap: 4px; }
.ctl-extra { margin-left: auto; flex-wrap: wrap; }
.ctl-caption { display: none; color: var(--muted); font-size: 0.92em; }
.ctl-pair { display: inline-flex; gap: 4px; }
.transpose-group .select { min-width: 7.5em; }
.sheet-page { text-align: center; padding: 8px 0 40px; }
.sheet-header { text-align: center; margin: 12px auto 18px; max-width: 40em; }
.sheet-title { font-size: 1.5em; margin: 0 0 4px; color: var(--title); font-weight: bold; }
.sheet-meta { margin: 0; color: var(--muted); }
.sheet-column { display: block; text-align: center; }
.sheet-column .lyrics { text-align: left; max-width: 100%; }
@media (max-width: 499px) {
  .btn-label { display: none; }
}
@media (max-width: 359px) { .chords-label { display: none; } }
@media (max-width: 640px) {
  .song-actions { display: none; }
  .song-actions-phone { display: flex; }
  /* play mode: previous and next live at the bottom, where a thumb rests */
  .play-nav-controls { display: none; }
  .view-play { padding-bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); }
  .play-footer { display: none; }
  .play-bar {
    display: flex; align-items: center; gap: 8px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 8px 12px max(8px, env(safe-area-inset-bottom)); background: var(--background); border-top: 1px solid var(--border);
  }
  .play-bar .btn { flex: 1 1 0; }
  body[data-route="play"] { --bottom-offset: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
}
/* Phones: one row of essentials (chords, key); the display options open with the ⋯ button, each with its
   name beside it. The row slides away while scrolling down a song and returns on scrolling up. */
@media (max-width: 640px) {
  .sheet-toolbar { gap: 6px; flex-wrap: nowrap; padding: 6px 0; }
  .sheet-toolbar.show-more { flex-wrap: wrap; }
  .sheet-toolbar.is-tucked { transform: translateY(calc(-100% - 2px)); }
  .sheet-toolbar:not(.show-more) .ctl-secondary { display: none; }
  .sheet-toolbar .btn-more { display: inline-flex; }
  .sheet-toolbar .ctl-more { margin-left: auto; order: 1; }
  .sheet-toolbar.show-more .ctl-secondary {
    order: 2; width: 100%; justify-content: space-between; padding: 6px 2px 0; border-top: 1px solid var(--border);
  }
  .sheet-toolbar.show-more .ctl-caption { display: inline; }
  .sheet-toolbar.show-more .ctl-extra { width: 100%; margin-left: 0; }
  .transpose-group { flex: 1 1 0; min-width: 0; }
  .transpose-group .select { min-width: 0; flex: 1 1 auto; width: 100%; }
  .transpose-group .btn-reset { display: none; }
  .ctl-extra { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { .sheet-toolbar { transition: none; } }

/* ---- editor ------------------------------------------------------------------------------------- */
.editor-toolbar .toolbar-row { flex-wrap: wrap; }
.save-status { font-size: 0.86em; color: var(--muted); white-space: nowrap; }
.save-status.ok { color: var(--ok); }
.save-status.error { color: var(--danger); white-space: normal; }
.editor-fields { display: grid; grid-template-columns: 2fr 1.2fr 1.2fr; gap: 8px 12px; margin-bottom: 10px; }
.editor-meta { display: contents; }
.meta-toggle { display: none; }
.title-input { font-size: 1.15em; font-weight: bold; }
.editor-hint { position: relative; margin: 0 0 12px; padding-right: 44px; }
.hint-close { position: absolute; top: 2px; right: 2px; color: var(--muted); }
.editor-hint p { line-height: 1.6; }
.editor-panes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; position: relative; }
.pane { min-width: 0; }
.pane-text { display: flex; flex-direction: column; gap: 6px; }
.snippet-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.snippet-bar .check { margin-left: auto; color: var(--muted); }
.lyrics-input {
  min-height: 60vh; resize: vertical; line-height: 1.5; tab-size: 2;
  font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: 0.95rem; white-space: pre-wrap; overflow-wrap: anywhere;
}
.pane-preview { border: 1px solid var(--border); border-radius: 10px; padding: 0 12px 16px; position: sticky; top: 8px; max-height: calc(100vh - 16px); overflow: auto; }
.preview-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--background); z-index: 2; }
.preview-label { font-weight: bold; color: var(--muted); margin-right: auto; }
.preview-key { min-width: 4.5em; text-align: center; }
.preview-sheet { text-align: center; }
.pane-toggle { display: none; gap: 0; }
.pane-toggle .btn { border-radius: 0; }
.pane-toggle .btn:first-child { border-radius: 8px 0 0 8px; }
.pane-toggle .btn:last-child { border-radius: 0 8px 8px 0; margin-left: -1px; }
.pane-toggle .btn.is-on { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
@media (max-width: 899px) {
  .pane-toggle { display: inline-flex; }
  .editor-panes { grid-template-columns: 1fr; }
  .view-edit .pane-preview { display: none; position: static; max-height: none; }
  .view-edit.show-preview .pane-preview { display: block; }
  .view-edit.show-preview .pane-text { display: none; }
  .lyrics-input { min-height: 50vh; }
  /* the bar with Done stays put while you write; the chord buttons ride just under it */
  .view-edit .editor-toolbar {
    position: sticky; top: 0; z-index: 8; margin: 0 0 8px; padding: 8px 0; min-height: 61px;
    background: var(--background); border-bottom: 1px solid var(--border);
  }
  .snippet-bar { position: sticky; top: 61px; z-index: 7; padding: 6px 0; background: var(--background); }
}
@media (max-width: 800px) {
  .editor-fields { grid-template-columns: 1fr; gap: 6px; }
  .field-title .field-label { display: none; }
  .meta-toggle {
    display: flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 0; border: 0; background: none;
    color: var(--muted); text-align: left; cursor: pointer; min-width: 0;
  }
  .meta-toggle > span:not(.meta-summary) { white-space: nowrap; flex: 0 0 auto; }
  .meta-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .editor-meta { display: none; grid-template-columns: 1fr 1fr; gap: 8px; }
  .editor-fields.show-meta .editor-meta { display: grid; }
  .editor-fields.show-meta .editor-meta { display: grid; }
  .editor-fields.show-meta .meta-toggle .icon { transform: rotate(180deg); }
}
@media (max-width: 640px) {
  .editor-meta { grid-template-columns: 1fr; }
  .save-time, .shortcut-toggle, .help-btn { display: none; }
  .editor-toolbar .toolbar-row { flex-wrap: nowrap; }
  .editor-toolbar .toolbar-row > .btn:first-child { flex: 0 0 auto; }
  /* the save state is a small coloured dot here (the words are still there for screen readers) */
  .save-status { display: inline-flex; align-items: center; flex: 0 0 auto; }
  .save-status::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
  .save-status.ok::before { content: "\2713"; width: auto; height: auto; background: none; color: var(--ok); font-weight: bold; margin-right: 4px; }
  .save-status.pending::before { background: var(--warn); }
  .save-status .save-text {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .save-status.error { flex: 1 1 auto; min-width: 0; white-space: normal; font-size: 0.8em; line-height: 1.25; }
  .save-status.error::before { background: var(--danger); flex: 0 0 auto; margin-right: 6px; }
  .save-status.error .save-text { position: static; width: auto; height: auto; clip: auto; white-space: normal; }
  .snippet-bar { gap: 5px; }
  .snippet-bar .btn-small { padding: 6px 8px; min-width: 40px; }
  .pane-toggle .btn { padding-left: 10px; padding-right: 10px; }
}
@media (max-width: 380px) {
  /* one row that scrolls sideways, rather than a second row pinned above the keyboard */
  .snippet-bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .snippet-bar::-webkit-scrollbar { display: none; }
  .snippet-bar .btn { flex: 0 0 auto; }
}
@media (min-width: 400px) and (max-width: 640px) {
  /* room for the word next to the tick; narrower phones show the tick alone */
  .save-status.ok .save-text { position: static; width: auto; height: auto; clip: auto; white-space: nowrap; }
}
/* the very smallest phones (320px): the save dot makes way, so Done, Text/Preview and the menu still fit */
@media (max-width: 340px) {
  .editor-toolbar .toolbar-row { flex-wrap: wrap; row-gap: 6px; }
  .save-status:not(.error) { display: none; }
  .save-status.error { flex: 1 1 100%; order: 9; }
  .view-edit .editor-toolbar .toolbar-row > .btn-primary { padding-left: 10px; padding-right: 10px; }
  .pane-toggle .btn { padding-left: 9px; padding-right: 9px; }
}
.help-panel {
  position: absolute; right: 0; top: 0; z-index: 9; width: min(460px, 100%); max-height: 80vh; overflow: auto;
  background: var(--background); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 4px 16px 16px;
}
.help-head { display: flex; align-items: center; justify-content: space-between; }
.help-head h2 { font-size: 1.1em; }
.help-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; margin: 0 0 12px; }
.help-list dt { white-space: nowrap; }
.help-list dd { margin: 0; }
.help-shortcuts { padding-left: 18px; }
.help-shortcuts li { margin: 4px 0; }
@media (max-width: 560px) { .help-list { grid-template-columns: 1fr; } .help-list dd { margin-bottom: 6px; } }

/* ---- sets --------------------------------------------------------------------------------------- */
.typeahead-wrap { position: relative; margin-bottom: 12px; max-width: 560px; }
.typeahead {
  list-style: none; margin: 4px 0 0; padding: 4px; position: absolute; left: 0; right: 0; z-index: 8;
  background: var(--background); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}
.typeahead-item { width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.typeahead-item:hover, .typeahead-item:focus { background: var(--surface); outline: none; }
.typeahead-empty { padding: 8px 10px; }
.set-items { list-style: none; margin: 0 0 12px; padding: 0; border-top: 1px solid var(--border); }
.set-item { display: flex; align-items: flex-start; gap: 8px; padding: 8px 4px; border-bottom: 1px solid var(--border); background: var(--background); }
.set-item.dragging { opacity: 0.5; }
.set-item.drag-over { box-shadow: inset 0 3px 0 var(--accent); }
.drag-handle { cursor: grab; color: var(--muted); display: inline-flex; padding-top: 8px; }
.set-num { flex: 0 0 1.8em; width: 1.8em; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 7px; }
.set-item-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.set-item-top { display: flex; align-items: center; gap: 4px; }
.set-item-title { flex: 1 1 auto; min-width: 0; font-size: 1.08em; color: var(--title); text-decoration: none; overflow-wrap: anywhere; }
.set-item-title:hover { text-decoration: underline; }
.set-item-controls { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.mini-field { display: inline-flex; align-items: center; gap: 6px; font-size: 0.9em; color: var(--muted); }
.mini-field .select { min-height: 30px; padding: 3px 24px 3px 8px; color: var(--text); }
.set-item-actions { flex: 0 0 auto; display: flex; gap: 0; }
@media (max-width: 560px) {
  .drag-handle { display: none; }
  .set-item-controls { gap: 6px; }
  /* label above the picker: Key and Capo share a row, and a Tune picker gets one of its own */
  .mini-field { flex: 2 1 0; min-width: 0; flex-direction: column; align-items: stretch; gap: 2px; font-size: 0.85em; }
  .mini-field-key { flex-grow: 3; }
  .mini-field-tune { flex: 1 1 100%; }
  .mini-field .select { width: 100%; min-width: 0; }
  .set-title-line { flex: 1 1 100%; }
  .view-set .toolbar-row .spacer { display: none; }
  .view-set .toolbar-row > .btn-primary { flex: 1 1 auto; }
}
.set-title-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.set-title-line .view-title { min-width: 0; overflow-wrap: anywhere; }
.play-nav { flex-wrap: wrap; }
.set-counter { font-variant-numeric: tabular-nums; min-width: 4em; text-align: center; color: var(--muted); }
.play-footer { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 12px; }
.play-footer .btn { max-width: 48%; overflow: hidden; text-overflow: ellipsis; }

/* ---- settings and help -------------------------------------------------------------------------- */
.settings-body, .help-body { max-width: 720px; }
.settings-section { border-top: 1px solid var(--border); padding: 8px 0 14px; }
.settings-section h2 { font-size: 1.1em; margin: 10px 0 6px; color: var(--text); }
.setting { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 10px 0; }
.check.setting { flex-wrap: nowrap; }
.setting-label { min-width: 9em; color: var(--muted); }
.setting-value { min-width: 3.5em; text-align: center; }
.radio-group { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.radio { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.help-body h2 { font-size: 1.15em; margin-top: 22px; color: var(--text); }
.help-body h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 1.02em; color: var(--text); }
.help-card {
  margin: 12px 0; padding: 14px 16px; border-radius: var(--radius-lg);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border)); background: color-mix(in srgb, var(--accent) 6%, var(--background));
}
.help-card p { margin: 0 0 12px; }
.help-card .button-row + p { margin: 10px 0 0; }
@media (max-width: 640px) {
  .setting-label { min-width: 0; flex: 1 1 100%; }
}

/* ---- convert with AI ---------------------------------------------------------------------------- */
.view-convert { max-width: 1000px; margin: 0 auto; }
.convert-head { margin: 4px 0 6px; }
.privacy { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0 0; }
.privacy .icon { flex: 0 0 auto; margin-top: 3px; color: var(--accent); }
.skip-note { margin: 10px 0 0; padding: 10px 12px; border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 7%, var(--background)); border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border)); }
.skip-note p { margin: 0; }
.skip-note .btn-link { display: block; padding: 8px 0 0; min-height: 40px; text-align: left; }
.convert-head .lead { max-width: 46em; margin: 6px 0 0; }
.convert-steps { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.convert-step { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px 16px; }
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.step-head h2 { margin: 0; font-size: 1.12em; color: var(--text); }
.step-num {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-contrast); font-weight: bold; font-size: 0.92em;
}
.step-body > p { margin: 0 0 8px; }
.step-actions { margin: 12px 0 6px; }
.mini-steps { margin: 4px 0 10px; padding-left: 1.3em; }
.mini-steps li { margin: 4px 0; }
.copy-prompt { min-width: 13em; }
.copy-prompt.is-done { background: var(--ok); border-color: var(--ok); color: var(--accent-contrast); }
.prompt-details summary { cursor: pointer; color: var(--accent); padding: 8px 0; font-weight: bold; }
.prompt-text, .reply-text { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: 0.86rem; line-height: 1.45; white-space: pre-wrap; resize: vertical; }
.callout {
  display: flex; gap: 10px; align-items: flex-start; margin: 12px 0 0; padding: 10px 12px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 7%, var(--background)); border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border));
}
.callout .icon { flex: 0 0 auto; margin-top: 2px; color: var(--accent); }
.convert-grid { display: grid; gap: 16px; }
@media (min-width: 900px) { .convert-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } }
.convert-col { min-width: 0; }
.reply-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; min-height: 30px; }
.reply-bar .field-label { white-space: nowrap; }
.convert-meta { display: grid; grid-template-columns: 1.6fr 1fr; gap: 8px; margin: 10px 0; }
.convert-status { margin: 6px 0 0; }
.convert-note { display: flex; gap: 8px; align-items: flex-start; margin: 5px 0; font-size: 0.92em; }
.convert-note .icon { flex: 0 0 auto; margin-top: 2px; }
.convert-note.ok { color: var(--ok); }
.convert-note.warn { color: var(--warn); }
.convert-note.info { color: var(--muted); }
.convert-preview { border: 1px solid var(--border); border-radius: var(--radius); padding: 0 12px 16px; max-height: 72vh; overflow: auto; text-align: center; min-height: 6em; }
.preview-empty { padding-top: 1.4em; }
.convert-actions {
  position: sticky; bottom: 0; z-index: 5; display: flex; justify-content: flex-end; margin-top: 12px;
  padding: 12px 0 max(12px, env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--background) 65%, transparent);
}
@media (max-width: 899px) { .convert-preview { max-height: none; overflow: visible; } }
@media (max-width: 640px) {
  .reply-bar { flex-direction: column; align-items: stretch; gap: 6px; }
  .reply-bar .btn { width: 100%; }
  .convert-actions .btn { flex: 1 1 auto; }
  .convert-meta { grid-template-columns: 1fr; }
  .copy-prompt { width: 100%; }
}

/* ---- menus, dialogs, toasts --------------------------------------------------------------------- */
.menu {
  position: absolute; z-index: 60; min-width: 220px; max-width: min(340px, calc(100vw - 16px)); max-height: 70vh; overflow: auto;
  padding: 6px; background: var(--background); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}
.menu-item {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; text-align: left;
  padding: 8px 10px; border: 0; border-radius: 6px; background: none; cursor: pointer;
}
.menu-item:hover:not([disabled]), .menu-item:focus { background: var(--surface); outline: none; }
.menu-item[disabled] { opacity: 0.5; cursor: default; }
.menu-item .icon { margin-top: 1px; color: var(--muted); }
.menu-item.is-danger, .menu-item.is-danger .icon { color: var(--danger); }
.menu-icon-space { width: 18px; flex: 0 0 18px; }
.menu-text { display: flex; flex-direction: column; min-width: 0; }
.menu-hint { font-size: 0.82em; color: var(--muted); }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--border); }
.menu-heading { font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 4px 10px 2px; }

.dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(460px, calc(100vw - 32px));
  background: var(--background); color: var(--text); box-shadow: var(--shadow);
}
.dialog[open]:not(:modal) { position: fixed; top: 20vh; left: 0; right: 0; margin: auto; z-index: 70; }
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog form { padding: 18px 20px 16px; }
.dialog-title { font-size: 1.15em; margin: 0 0 10px; }
.dialog-body p { margin: 0 0 8px; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.toast-region {
  position: fixed; left: 50%; bottom: calc(var(--bottom-offset) + max(16px, env(safe-area-inset-bottom))); transform: translateX(-50%);
  z-index: 80; display: flex; flex-direction: column; gap: 8px; width: min(560px, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 8px;
  padding: 10px 8px 10px 14px; border-radius: 10px; background: var(--text); color: var(--background); box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
}
.toast-text { flex: 1 1 auto; }
.toast .btn-link { color: inherit; text-decoration: underline; }
.toast-close { color: inherit; border: 0; background: transparent; width: 28px; min-width: 28px; min-height: 28px; }
.toast-error { background: var(--danger); color: var(--accent-contrast); }
.toast-ok { background: var(--text); }
.toast-warning { background: var(--warn); color: var(--accent-contrast); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---- touch screens ------------------------------------------------------------------------------
   Fields use 16px text so iPhone Safari does not zoom in when one is tapped, and controls get
   finger-sized hit areas (about 44px). */
@media (pointer: coarse), (max-width: 640px) {
  .input, .select, .lyrics-input, .mini-field .select, .typeahead-item { font-size: 16px; }
  .btn { min-height: 44px; }
  .btn-icon { width: 44px; min-width: 44px; }
  .btn-small { min-height: 40px; padding: 6px 12px; }
  .pane-toggle .btn { min-height: 44px; }
  .input:not(textarea), .select { min-height: 44px; }
  .mini-field .select { min-height: 40px; }
  .chip { min-height: 38px; padding: 6px 14px; }
  .nav-link { min-height: 44px; min-width: 44px; justify-content: center; }
  .menu-item { padding: 12px 12px; }
  .typeahead-item { padding: 12px 10px; }
  .toast-close { width: 40px; min-width: 40px; min-height: 40px; }
  input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; }
  .check, .radio { min-height: 44px; }
  .song-link, .set-link { padding-top: 12px; padding-bottom: 12px; }
  .set-item-title { padding: 6px 0; }
  .lyrics .transpose-preset { padding: 8px 0; }
  .search-clear { width: 40px; height: 40px; }
  .color-input { height: 44px; width: 56px; }
}
@media (max-width: 640px) { .nav-link { min-height: 52px; } }

/* ---- print ------------------------------------------------------------------------------------------
   Ctrl+P on a page prints the page, not the app around it. (Printing through Export > Print builds its own document.) */
@media print {
  .view-nav, .fab, .app-nav, .play-bar, .play-footer, .convert-actions, .editor-hint { display: none !important; }
}
