/* Songbook — gaya. Semua ukuran di area lagu memakai em dari --song-font-size. */

:root {
  --bg: #fdfbf7;
  --bg-elev: #ffffff;
  --bg-sunken: #f4f0e8;
  --fg: #1c1917;
  --fg-dim: #6b6259;
  --fg-faint: #9a9088;
  --line: #e6e0d6;
  --accent: #b45309;
  --accent-soft: #fef3e2;
  --danger: #b91c1c;
  --radius: 14px;
  --tap: 46px;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.06), 0 8px 24px rgba(28, 25, 23, 0.06);
  --song-font-size: 20px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12100e;
    --bg-elev: #1c1917;
    --bg-sunken: #0c0a09;
    --fg: #f5f1e8;
    --fg-dim: #a8a095;
    --fg-faint: #7c7368;
    --line: #2e2a26;
    --accent: #fbbf24;
    --accent-soft: #2a2118;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #12100e;
  --bg-elev: #1c1917;
  --bg-sunken: #0c0a09;
  --fg: #f5f1e8;
  --fg-dim: #a8a095;
  --fg-faint: #7c7368;
  --line: #2e2a26;
  --accent: #fbbf24;
  --accent-soft: #2a2118;
  --danger: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Atribut [hidden] harus selalu menang: beberapa elemen di bawah memakai display:flex,
   yang tanpa aturan ini mengalahkan display:none bawaan browser. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 16px;
  overscroll-behavior-y: none;
}

body { padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }

#app { min-height: 100%; display: flex; flex-direction: column; }

button { font-family: inherit; color: inherit; }

/* ---------- bar ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  padding: 10px 14px 12px;
}
.bar-row { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.brand { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.02em; margin: 0; flex: 1; }
.bar-actions { display: flex; gap: 4px; margin-left: auto; }

.icon-btn {
  min-width: var(--tap); min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  font-size: 1.2rem; line-height: 1; cursor: pointer;
}
.icon-btn:active { background: var(--bg-sunken); }
.icon-btn:disabled { opacity: 0.35; }

.search-wrap { margin-top: 10px; }
#search {
  width: 100%; height: 42px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-sunken); color: var(--fg); font-size: 1rem;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- banner ---------- */
.banner, .install-hint {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 10px 14px 0; padding: 10px 12px;
  border-radius: 12px; background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  font-size: 0.86rem; color: var(--fg);
}
.banner-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.install-hint { flex-direction: column; align-items: flex-start; gap: 4px; }
.install-hint .icon-btn { position: absolute; right: 18px; margin-top: -4px; }
.install-hint span { color: var(--fg-dim); line-height: 1.4; }

/* ---------- library ---------- */
main { flex: 1; padding: 12px 14px 40px; }
.list-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 2px 2px 10px; color: var(--fg-dim); font-size: 0.84rem;
}

.btn {
  min-height: var(--tap); padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--fg);
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
}
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 0.82rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
/* Teks gelap hanya untuk aksen terang di tema gelap; tanpa pembatasan ini,
   tema terang ikut kena dan kontrasnya jatuh ke 3.48:1 (gagal WCAG AA). */
:root[data-theme="dark"] .btn-primary,
:root[data-theme="dark"] .ctl.is-active { color: #1c1917; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-primary,
  :root:not([data-theme="light"]) .ctl.is-active { color: #1c1917; }
}
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-wide { width: 100%; }

.song-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.song-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 14px; border-radius: var(--radius);
  background: var(--bg-elev); border: 1px solid var(--line);
  box-shadow: var(--shadow); cursor: pointer;
}
.song-item:active { transform: scale(0.995); }
.song-main { flex: 1; min-width: 0; }
.song-title {
  font-weight: 650; font-size: 1rem; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.song-sub { color: var(--fg-dim); font-size: 0.82rem; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-key {
  flex: 0 0 auto; min-width: 34px; height: 34px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px; background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 0.85rem;
}
.song-play {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); border: none; font-size: 0.9rem;
}
.empty { color: var(--fg-dim); text-align: center; margin-top: 40px; line-height: 1.6; font-size: 0.92rem; }

/* ---------- editor ---------- */
#editorView, #mainView { display: flex; flex-direction: column; min-height: 100vh; }
#editorView[hidden], #mainView[hidden] { display: none; }

.mode-switch {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--bg-sunken); border-radius: 10px; margin: 0 auto;
}
.mode-tab {
  min-height: 34px; padding: 0 14px; border-radius: 8px; border: none;
  background: transparent; color: var(--fg-dim); font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.mode-tab.is-active { background: var(--bg-elev); color: var(--fg); box-shadow: var(--shadow); }

.meta-row { display: flex; gap: 8px; margin-top: 10px; }
.meta-input {
  flex: 1; min-width: 0; height: 40px; padding: 0 12px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-sunken); color: var(--fg); font-size: 0.95rem;
}
.meta-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.meta-title { font-weight: 650; flex: 2; }
.meta-key { flex: 0 0 62px; text-align: center; text-transform: none; }

.editor-body { padding: 12px 14px 0; }
.mode-panel { display: flex; flex-direction: column; }
#bodyInput {
  width: 100%; min-height: 320px; padding: 14px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--fg);
  font-family: var(--font-mono); font-size: 0.92rem; line-height: 1.7;
  resize: vertical; spellcheck: false;
}
#bodyInput:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint { color: var(--fg-faint); font-size: 0.78rem; line-height: 1.5; margin: 8px 2px 0; }
.hint code { font-family: var(--font-mono); background: var(--bg-sunken); padding: 1px 5px; border-radius: 4px; }

.preview-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 6px; color: var(--fg-dim);
  font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.08em;
}
.save-state { text-transform: none; letter-spacing: 0; color: var(--fg-faint); }
.save-state.is-saving { color: var(--accent); }

/* ---------- song area: inti render ---------- */
.song-area {
  padding: 8px 16px 24px;
  font-size: var(--song-font-size);
  line-height: 1.45;
}
.song-area.preview { font-size: 17px; }

.sb-line {
  display: block;
  margin: 0 0 0.55em;
  /* pre-wrap: spasi dalam lirik terjaga; segmen membungkus sebagai unit */
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: normal;
}

.sb-seg {
  display: inline-block;
  /* Segmen yang chordnya lebih lebar dari teksnya melebar mengikuti chord,
     sehingga chord tidak pernah bertumpuk dengan segmen berikutnya. */
  min-width: min-content;
  vertical-align: bottom;
  white-space: pre-wrap;
}

.sb-chord {
  display: block;
  font-weight: 700;
  font-size: 0.92em;
  line-height: 1.15;
  color: var(--accent);
  letter-spacing: 0.01em;
  /* ruang napas di kanan chord supaya tidak menempel ke segmen berikutnya */
  padding-right: 0.14em;
}

.sb-text {
  display: block;
  white-space: pre-wrap;
  line-height: 1.35;
}

.sb-gap { height: 0.9em; }

.sb-tab {
  font-family: var(--font-mono);
  font-size: 0.78em;
  line-height: 1.25;
  white-space: pre;
  overflow-x: auto;
  color: var(--fg-dim);
  background: var(--bg-sunken);
  padding: 0.5em 0.7em;
  border-radius: 8px;
  margin: 0.3em 0 0.7em;
}

.sb-comment {
  color: var(--fg-faint);
  font-style: italic;
  font-size: 0.85em;
  margin: 0.2em 0 0.5em;
}

/* ---------- main mode ---------- */
#mainView { background: var(--bg); }
.main-bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.main-bar.is-hidden { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.main-title { font-weight: 650; font-size: 0.95rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main-area {
  flex: 1;
  padding: 18px 20px 40vh;
  --song-font-size: 28px;
  font-size: var(--song-font-size);
}

.main-controls {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg-elev) 94%, transparent);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 6px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.main-controls.is-hidden { transform: translateY(100%); opacity: 0; pointer-events: none; }
.ctl-row { display: flex; align-items: center; gap: 6px; }
.ctl {
  min-width: var(--tap); min-height: var(--tap);
  padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-sunken); color: var(--fg);
  font-size: 0.92rem; font-weight: 650; cursor: pointer;
}
.ctl:active { background: var(--line); }
.ctl-wide { flex: 1; }
.ctl-ghost { background: transparent; color: var(--fg-dim); font-weight: 500; font-size: 0.82rem; padding: 0 8px; min-width: 0; }
.ctl.is-active { background: var(--accent); color: #1c1917; border-color: var(--accent); }
.ctl-label, .ctl-key {
  min-width: 42px; text-align: center; font-variant-numeric: tabular-nums;
  font-size: 0.86rem; color: var(--fg-dim);
}
.ctl-key { font-weight: 700; color: var(--accent); font-size: 1rem; }
.ctl-sep { flex: 1; }
.ctl-range { flex: 1; accent-color: var(--accent); height: var(--tap); }
.show-controls {
  position: fixed; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 30;
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--fg-dim);
  box-shadow: var(--shadow); font-size: 1rem;
}

/* ---------- dialogs ---------- */
dialog {
  border: none; border-radius: 18px; padding: 0;
  background: var(--bg-elev); color: var(--fg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  width: min(560px, calc(100vw - 28px));
  max-height: 86vh;
}
dialog::backdrop { background: rgba(12, 10, 9, 0.5); backdrop-filter: blur(3px); }
.dialog-body { padding: 18px; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.dialog-body h2 { font-size: 1.05rem; margin: 0; letter-spacing: -0.01em; }
.dialog-body p { margin: 0; color: var(--fg-dim); line-height: 1.5; font-size: 0.9rem; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.dialog-tabs { display: flex; gap: 6px; }
.dialog-tabs .mode-tab { background: var(--bg-sunken); }

#importFiles { font-size: 0.9rem; }
#importPaste, #visualStage { font-family: var(--font-mono); font-size: 0.9rem; }
#importPaste {
  width: 100%; min-height: 180px; padding: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-sunken); color: var(--fg);
  font-family: var(--font-mono); resize: vertical;
}
.import-preview { border-top: 1px solid var(--line); padding-top: 10px; max-height: 40vh; overflow-y: auto; }
.import-item { padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 0.86rem; }
.import-item:last-child { border-bottom: none; }
.import-item b { font-weight: 650; }
.import-warn { color: var(--danger); font-size: 0.8rem; margin-top: 3px; line-height: 1.4; }
.import-ok { color: var(--fg-dim); font-size: 0.8rem; margin-top: 2px; }
.import-conflict { background: var(--accent-soft); border-radius: 8px; padding: 8px; margin-top: 6px; }
.import-conflict label { display: block; font-size: 0.84rem; padding: 3px 0; }

.menu-body { padding: 8px; gap: 2px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 46px; padding: 0 12px; border-radius: 10px;
  border: none; background: transparent; color: var(--fg);
  font-size: 0.94rem; text-align: left; cursor: pointer;
}
.menu-item:active { background: var(--bg-sunken); }
.menu-item.is-danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--line); margin: 6px 8px; }

.status-body { display: flex; flex-direction: column; gap: 8px; font-size: 0.88rem; }
.status-row { display: flex; justify-content: space-between; gap: 12px; }
.status-row span:first-child { color: var(--fg-dim); }
.status-row span:last-child { text-align: right; font-weight: 600; }
.status-warn { color: var(--danger); font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--fg); color: var(--bg);
  padding: 10px 16px; border-radius: 999px;
  font-size: 0.85rem; font-weight: 600;
  z-index: 100; box-shadow: var(--shadow);
  max-width: calc(100vw - 40px); text-align: center;
}
.toast[hidden] { display: none; }

/* ---------- visual chord editor ---------- */
#visualStage { white-space: pre-wrap; }
.vline { position: relative; display: block; margin-bottom: 0.6em; }
.vseg-hit { cursor: pointer; }
.vseg-hit:active { background: var(--accent-soft); border-radius: 4px; }
.vchord-chip {
  display: inline-block; cursor: pointer;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 5px; padding: 0 4px; font-weight: 700;
}

/* ---------- print / PDF ---------- */
@media print {
  :root { --bg: #fff; --fg: #000; --accent: #000; }
  body { padding: 0; }
  .bar, .main-controls, .main-bar, .banner, .install-hint, .list-head,
  .preview-head, .toast, .show-controls, #btnTheme, .bar-actions { display: none !important; }
  .song-area { font-size: 11pt; padding: 0; }
  .sb-chord { color: #000; }
  .print-song { break-after: page; }
  .print-song:last-child { break-after: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
