/* ------------------------------------------------------------------
   Songbook – site chrome.
   Minimal: one ink colour, one accent, hairlines instead of boxes.
   System UI font, light and dark via prefers-color-scheme.
   The rendered documents keep their own fonts (see the @font-face block).
   ------------------------------------------------------------------ */

:root {
  color-scheme: light dark;
  --bg: #fafaf8;
  --fg: #1c1c1a;
  --muted: #6a6a64;
  --card: #ffffff;
  --border: #e4e3de;
  --accent: #1d4fa6;
  --accent-fg: #ffffff;
  --hover: #f0efeb;
  --danger: #b3261e;
  --ok: #1b7a3d;
  --tap: 48px;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --fg: #ebebe8;
    --muted: #a0a09a;
    --card: #1b1b1a;
    --border: #2f2f2d;
    --accent: #8db6ff;
    --accent-fg: #0b1a33;
    --hover: #222221;
    --danger: #ff8a80;
    --ok: #7fd49a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--fg);
  overflow-x: hidden;
}

a { color: var(--accent); }

.wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 8px 20px 48px;
}

/* Header / toolbar ------------------------------------------------ */
header.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 6px 16px;
  min-height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 2;
}
/* Pages that scroll the bar away (the song list keeps only its search). */
header.bar.static { position: static; border-bottom: 0; }
header.bar.static .inner,
header.bar.page .inner { width: 100%; max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 8px; }
header.bar.static { padding: 6px 20px; }
header.bar .inner { max-width: 640px !important; }

header.bar h1 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

a.brand {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--fg);
  text-decoration: none;
  margin-right: auto;
}

nav.nav { display: flex; gap: 4px; }
nav.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: .95rem;
}
nav.nav a:hover { color: var(--fg); background: var(--hover); }
nav.nav a[aria-current="page"] { color: var(--fg); font-weight: 600; }

header.bar .tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
/* Narrow screens: tools get their own row under the title. */
@media (max-width: 720px) {
  header.bar { padding-bottom: 10px; }
  header.bar .tools { flex: 1 0 100%; }
  header.bar .tools .btn.small { padding: 0 10px; }
}

.btn, .back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  text-decoration: none;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover, .back:hover { background: var(--hover); border-color: var(--muted); }
.btn:active { background: var(--border); }
.btn.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 600;
}
.btn.primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { min-height: 44px; padding: 0 12px; font-size: .95rem; }
.back { padding: 0 10px; border-color: transparent; color: var(--muted); }
.back:hover { border-color: transparent; color: var(--fg); }

/* Key (transpose) control */
.key { display: inline-flex; }
.key .key-name { position: relative; gap: 6px; margin: 0; font-size: .95rem; font-weight: 600; }
.key .key-name:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
/* The native menu covers the label: tapping anywhere on it opens the list. */
.key .key-name select {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 16px; /* below 16px iOS zooms in on focus */
}
.key .caret {
  width: 0;
  height: 0;
  border: 4px solid transparent;
  border-top: 5px solid currentColor;
  border-bottom: 0;
  opacity: .6;
}
.key .from { font-weight: 400; color: var(--muted); white-space: pre; }
@media (max-width: 400px) {
  header.bar .tools { gap: 4px; }
  header.bar .tools .btn.small { padding: 0 7px; }
  .key .from { display: none; }
}
sb-chord-new { display: inline-block; width: 0; white-space: pre; text-indent: 0; text-align: left; transform-origin: left; pointer-events: none; user-select: none; }

/* Forms ----------------------------------------------------------- */
input[type="search"], input[type="text"], input[type="password"], input[type="file"] {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  font: inherit;
}
input:focus-visible, .btn:focus-visible, .back:focus-visible, .song:focus-visible,
nav.nav a:focus-visible, a.brand:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
label { display: block; font-weight: 600; font-size: .95rem; margin: 20px 0 6px; }
.help { color: var(--muted); font-size: .9rem; margin: 6px 0 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1 1 200px; }

/* Song list ------------------------------------------------------- */
/* The search stays in reach while scrolling a long list. */
.search {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0 -20px;
  padding: 8px 20px 12px;
  background: var(--bg);
}
.search input { background: var(--hover); border-color: transparent; }
.search input:focus-visible { background: var(--card); border-color: var(--border); }
ul.songs {
  list-style: none;
  margin: 0;
  padding: 0;
}
ul.songs:empty { display: none; }
ul.songs li.letter {
  padding: 24px 0 6px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: .85rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
}
ul.songs li.letter:first-child { padding-top: 8px; }
a.song {
  display: flex;
  align-items: center;
  padding: 12px 0;
  min-height: 52px;
  color: var(--fg);
  text-decoration: none;
  font-size: 1.05rem;
  border-radius: var(--radius);
}
a.song:hover { color: var(--accent); }
a.song:focus-visible { outline-offset: 0; }
.count { color: var(--muted); font-size: .9rem; margin: 4px 0 8px; }

.state { padding: 32px 8px; color: var(--muted); text-align: center; }
.state.error { color: var(--danger); }

/* Status messages ------------------------------------------------- */
.msg { padding: 10px 12px; border-radius: var(--radius); margin: 12px 0; border: 1px solid var(--border); }
.msg.error { border-color: var(--danger); color: var(--danger); }
.msg.ok { border-color: var(--ok); color: var(--ok); }

/* Upload ----------------------------------------------------------- */
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 40px 0 16px; }
ul.files { list-style: none; margin: 12px 0; padding: 0; }
ul.files li { border-top: 1px solid var(--border); padding: 12px 0; }
ul.files .name { font-weight: 600; word-break: break-word; }
ul.files .status { margin-top: 6px; font-size: .95rem; color: var(--muted); }
ul.files .status.error { color: var(--danger); }
ul.files .status.ok { color: var(--ok); }
ul.files input[type="text"] { margin-top: 6px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Services page --------------------------------------------------- */
h2 { font-size: 1.2rem; letter-spacing: -.01em; margin: 40px 0 4px; }
#main-section > h2:first-child { margin-top: 20px; }
h3 { font-size: 1rem; margin: 0; }
ul.picker { max-height: 320px; overflow-y: auto; margin-top: 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
ul.picker:empty { display: block; }
ul.picker li + li { border-top: 1px solid var(--border); }
label.pick {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 10px 14px;
  min-height: 48px;
  font-size: 1rem;
  font-weight: 400;
  cursor: pointer;
}
label.pick:hover { background: var(--hover); }
label.pick input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.chosen-head { margin-top: 28px; }
.chosen-head .count { font-weight: 400; }
ol.chosen { margin: 8px 0 0; padding-left: 28px; }
ol.chosen:empty { display: none; }
ol.chosen li { display: flex; gap: 6px; align-items: center; padding: 4px 0; }
ol.chosen li::marker { color: var(--muted); }
ol.chosen .grow { flex: 1 1 0; min-width: 0; overflow-wrap: anywhere; }
ol.chosen .btn.small { padding: 0; min-width: 44px; border-color: transparent; color: var(--muted); }
ol.chosen .btn.small:hover { color: var(--fg); }
#service-save, #password-save { margin-top: 20px; }
article.service { border-top: 1px solid var(--border); padding: 16px 0 4px; margin: 0; }
#saved article.service:first-child { margin-top: 8px; }
article.service .when { color: var(--muted); font-size: .9rem; }
article.service ol { margin: 10px 0 12px; padding-left: 28px; }
article.service li.missing { color: var(--muted); }
details.upload { margin-top: 40px; border-top: 1px solid var(--border); padding-top: 8px; }
details.upload summary { cursor: pointer; font-size: 1.2rem; font-weight: 700; letter-spacing: -.01em; min-height: var(--tap); display: flex; align-items: center; }

/* Document viewer ------------------------------------------------- */
.wrap.viewer {
  max-width: 900px;
  padding: 16px 0;
}
/* Wrapper is scaled with a transform; height is corrected in JS. */
#doc-scale {
  transform-origin: top left;
  width: max-content;
}
#doc {
  width: 100%;
  overflow: hidden;         /* fit mode: nothing leaks sideways */
  position: relative;
}
#doc.actual { overflow-x: auto; }  /* actual size: scroll inside the box, not the body */
/* Edit mode: the page is editable text */
#doc.editing { outline: 2px solid var(--accent); outline-offset: 2px; }
#doc.editing article { outline: none; cursor: text; }
#doc.editing [contenteditable="false"] { cursor: default; opacity: .6; }
.wrap.viewer .msg { margin-left: 16px; margin-right: 16px; }

/* docx-preview output: the page is a white sheet in any theme */
.docx-wrapper {
  background: transparent !important;
  padding: 0 !important;
  display: block !important;
}
.docx-wrapper > section.docx {
  background: #ffffff !important;
  color: #000000;
  box-shadow: 0 0 0 1px rgba(0,0,0,.08);
  margin: 0 0 16px 0 !important;
}

/* An empty paragraph takes a full line in Word; in HTML an empty <p> or an
   empty <span> makes no line box. A zero-size inline-block creates one
   without adding glyphs. */
.docx p:empty::after, .docx p > span:empty::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
}

.loading { color: var(--muted); padding: 40px 16px; text-align: center; }
.loading::before {
  content: "";
  display: block;
  width: 24px; height: 24px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading::before { animation-duration: 3s; } }

/* ------------------------------------------------------------------
   Metric-compatible web fonts, declared under the ORIGINAL family names
   so a document asking for "Times New Roman" renders with Tinos on a
   phone that has no Times New Roman. Same letter widths, so the chords
   stay above their syllables.
     Tinos   -> Times New Roman
     Arimo   -> Arial
     Carlito -> Calibri
     Cousine -> Courier New
   Files: Fontsource on jsDelivr, pinned. Only loaded when a document
   actually uses the family.
   ------------------------------------------------------------------ */
@font-face { font-family: "Times New Roman"; font-style: normal; font-weight: 400; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/tinos@5.3.0/files/tinos-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Times New Roman"; font-style: normal; font-weight: 700; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/tinos@5.3.0/files/tinos-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Times New Roman"; font-style: italic; font-weight: 400; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/tinos@5.3.0/files/tinos-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Times New Roman"; font-style: italic; font-weight: 700; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/tinos@5.3.0/files/tinos-latin-700-italic.woff2") format("woff2"); }

@font-face { font-family: "Arial"; font-style: normal; font-weight: 400; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/arimo@5.3.0/files/arimo-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Arial"; font-style: normal; font-weight: 700; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/arimo@5.3.0/files/arimo-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Arial"; font-style: italic; font-weight: 400; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/arimo@5.3.0/files/arimo-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Arial"; font-style: italic; font-weight: 700; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/arimo@5.3.0/files/arimo-latin-700-italic.woff2") format("woff2"); }

@font-face { font-family: "Calibri"; font-style: normal; font-weight: 400; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/carlito@5.3.0/files/carlito-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Calibri"; font-style: normal; font-weight: 700; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/carlito@5.3.0/files/carlito-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Calibri"; font-style: italic; font-weight: 400; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/carlito@5.3.0/files/carlito-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Calibri"; font-style: italic; font-weight: 700; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/carlito@5.3.0/files/carlito-latin-700-italic.woff2") format("woff2"); }

@font-face { font-family: "Courier New"; font-style: normal; font-weight: 400; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/cousine@5.3.0/files/cousine-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Courier New"; font-style: normal; font-weight: 700; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/cousine@5.3.0/files/cousine-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Courier New"; font-style: italic; font-weight: 400; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/cousine@5.3.0/files/cousine-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Courier New"; font-style: italic; font-weight: 700; font-display: block;
  src: url("https://cdn.jsdelivr.net/npm/@fontsource/cousine@5.3.0/files/cousine-latin-700-italic.woff2") format("woff2"); }

/* Print: only the document, at actual size --------------------------- */
@media print {
  body { background: #fff; color: #000; overflow: visible; }
  header.bar, .no-print { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .viewer { padding: 0; }
  #doc { overflow: visible !important; height: auto !important; }
  #doc-scale { transform: none !important; width: auto; }
  .docx-wrapper > section.docx { box-shadow: none; margin: 0 !important; page-break-after: always; }
}
