*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #3B82F6;
  --green:   #22C55E;
  --red:     #EF4444;
  --amber:   #F59E0B;
  --bg:      #F1F5F9;
  --surface: #FFFFFF;
  --border:  #E2E8F0;
  --text:    #1E293B;
  --muted:   #64748B;
  --chord:   #1D4ED8;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

/* ── Header ─────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  display: flex; align-items: center; gap: 8px;
  z-index: 50; min-height: 54px;
}
.app-header h1 {
  font-size: 1.05rem; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-icon {
  background: none; border: none; color: var(--text);
  font-size: 1.15rem; cursor: pointer;
  padding: 7px; border-radius: 8px; line-height: 1;
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg); }

/* ── Main ────────────────────────────────────────────────── */
.main { padding: 16px; max-width: 680px; margin: 0 auto; }

/* ── Views ───────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border: 1px solid transparent; border-radius: 8px;
  font-size: 1rem; font-weight: 500; cursor: pointer;
  transition: background .15s, opacity .15s; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: #2563EB; }
.btn-danger  { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover:not(:disabled) { background: #DC2626; }
.btn-ghost   { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }
.btn-sm { padding: 6px 12px; font-size: .875rem; }
.btn-xs { padding: 3px 9px; font-size: .78rem; border-radius: 6px; }

/* ── Inputs ───────────────────────────────────────────────── */
.input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 1rem; background: var(--surface); color: var(--text);
  transition: border-color .15s;
}
.input:focus { outline: none; border-color: var(--primary); }
.input.error  { border-color: var(--red); }
textarea.input {
  resize: vertical; min-height: 220px;
  font-family: "Courier New", Courier, monospace; font-size: .88rem; line-height: 1.6;
}

.field-group  { margin-bottom: 14px; }
.field-label  { display: block; font-size: .875rem; font-weight: 500; margin-bottom: 5px; }
.field-error  { color: var(--red); font-size: .8rem; margin-top: 4px; min-height: 1em; }
.field-hint   { color: var(--muted); font-size: .8rem; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; margin-bottom: 10px;
  cursor: pointer; transition: box-shadow .15s, border-color .15s;
}
.card:hover { box-shadow: 0 2px 10px rgba(0,0,0,.08); border-color: #CBD5E1; }
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 3px; }
.card-sub   { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }

/* ── Tags ─────────────────────────────────────────────────── */
.tag {
  display: inline-block; background: #EFF6FF; color: #1D4ED8;
  border-radius: 20px; padding: 2px 10px; font-size: .72rem;
  font-weight: 600; margin: 2px 2px 0 0;
}

/* ── Toast ────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1E293B; color: #fff;
  padding: 10px 20px; border-radius: 8px;
  font-size: .9rem; opacity: 0;
  transition: opacity .25s, transform .25s;
  z-index: 999; pointer-events: none; white-space: nowrap;
}
#toast.show    { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error   { background: var(--red); }
#toast.success { background: var(--green); }

/* ── Search ───────────────────────────────────────────────── */
.search-wrap { position: relative; margin-bottom: 12px; }
.search-wrap .input { padding-left: 38px; }
.search-icon {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%); pointer-events: none;
  color: var(--muted); font-size: .9rem;
}

/* ── FAB ──────────────────────────────────────────────────── */
.fab {
  position: fixed; bottom: 24px; right: 20px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 1.7rem; border: none; cursor: pointer;
  box-shadow: 0 4px 16px rgba(59,130,246,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; transition: transform .1s;
}
.fab:active { transform: scale(.93); }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 200;
  align-items: flex-end; justify-content: center;
}
.modal-overlay.open { display: flex; }
@media (min-width: 500px) { .modal-overlay { align-items: center; } }
.modal {
  background: var(--surface); border-radius: 16px 16px 0 0;
  padding: 24px 20px; width: 100%;
  max-height: 88dvh; overflow-y: auto;
}
@media (min-width: 500px) { .modal { border-radius: 16px; max-width: 440px; } }
.modal h3 { font-size: 1.1rem; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

/* ── Song meta ────────────────────────────────────────────── */
.song-meta { margin-bottom: 18px; }
.s-title  { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.s-artist { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.s-capo   {
  display: inline-block; background: #FEF3C7; color: #92400E;
  border-radius: 6px; padding: 2px 9px; font-size: .78rem;
  font-weight: 600; margin-top: 6px;
}

/* ── Transpose bar ────────────────────────────────────────── */
.transpose-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 14px; margin-bottom: 20px;
}
.t-label { font-size: .8rem; color: var(--muted); }
.t-key   { font-weight: 700; font-size: 1.05rem; min-width: 36px; text-align: center; color: var(--chord); }
.btn-t {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 11px; font-size: .85rem;
  font-weight: 600; cursor: pointer; color: var(--text);
  transition: background .1s;
}
.btn-t:hover { background: #E2E8F0; }
.t-sep { color: var(--border); user-select: none; }

/* ── Song content ─────────────────────────────────────────── */
.song-content { font-size: 1rem; line-height: 1.5; padding-bottom: 80px; }

.chord-line { display: flex; flex-wrap: wrap; margin-bottom: 1px; }

.cp { display: inline-flex; flex-direction: column; }
.cp .ach  {
  color: var(--chord); font-weight: 700; font-size: .8rem;
  line-height: 1.55; min-height: 1.35em; white-space: pre; font-style: normal;
}
.cp .alyr { white-space: pre; line-height: 1.5; }

.song-sect {
  color: var(--muted); font-size: .76rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  margin: 18px 0 5px;
}
.song-spacer { height: 8px; }
.song-txt    { white-space: pre-wrap; line-height: 1.5; }

/* ── Version history ──────────────────────────────────────── */
.version-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 10px;
}
.version-card.current { border-color: var(--primary); border-width: 2px; }
.v-head   { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.v-num    { font-weight: 700; font-size: .9rem; }
.v-badge  {
  background: #EFF6FF; color: var(--primary);
  border-radius: 20px; padding: 1px 9px; font-size: .72rem; font-weight: 700;
}
.v-meta   { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.v-note   { font-size: .85rem; font-style: italic; margin-top: 6px; }
.v-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ── Admin ────────────────────────────────────────────────── */
.user-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px;
}
.u-info  { flex: 1; }
.u-name  { font-size: .9rem; font-weight: 500; }
.u-email { font-size: .78rem; color: var(--muted); }
.u-badge {
  background: #FEF3C7; color: #92400E;
  border-radius: 20px; padding: 2px 9px; font-size: .72rem; font-weight: 700;
}

/* ── Misc ─────────────────────────────────────────────────── */
.empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty .e-icon  { font-size: 3rem; margin-bottom: 10px; }
.empty .e-title { font-size: 1.05rem; font-weight: 600; color: var(--text); margin-bottom: 4px; }

.spinner {
  display: inline-block; width: 22px; height: 22px;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

code {
  background: #F1F5F9; border-radius: 4px;
  padding: 1px 5px; font-size: .85em; color: var(--chord);
}

hr.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── Wake lock active indicator ───────────────────────────── */
.wakelock-on { color: var(--amber) !important; }

/* ── Print ────────────────────────────────────────────────── */
@media print {
  #loading-overlay, .app-header, .fab, #btn-fab-import,
  .transpose-bar, #toast, .modal-overlay,
  #d-tags, .s-capo { display: none !important; }

  body   { background: #fff; font-size: 11pt; }
  .main  { padding: 6mm; max-width: 100%; }

  /* Hide all views except active detail */
  .view             { display: none !important; }
  #view-detail.active { display: block !important; }

  .song-meta   { margin-bottom: 8mm; border-bottom: 0.5pt solid #ccc; padding-bottom: 5mm; }
  .s-title     { font-size: 18pt; font-weight: 900; }
  .s-artist    { font-size: 12pt; color: #555; margin-top: 2mm; }

  .song-content { font-size: 11pt; line-height: 1.6; padding-bottom: 0; }

  .chord-line { margin-bottom: 0; }
  .cp .ach    { color: #000; font-weight: 900; font-size: 9pt; }
  .cp .alyr   { font-size: 11pt; }
  .song-sect  { color: #777; font-size: 8pt; margin: 6mm 0 2mm; }
  .song-spacer { height: 4mm; }
}
