:root{padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}body{margin:0}img{max-width:100%}
/* Compact photo import and resilient narrow-screen song cards. */
#importBox { gap:14px; }
#importBox p { margin:0; }
#importBox .import-actions { display:flex; flex-wrap:wrap; gap:10px; min-width:0; }
.import-actions .btn { display:inline-flex; align-items:center; justify-content:center; text-align:center; text-decoration:none; line-height:1.3; max-width:100%; cursor:pointer; white-space:normal; }
#importMsg:empty { display:none; }
.songlist button > * { min-width:0; }
.songlist .t, .songlist .sub { overflow-wrap:anywhere; white-space:normal; }
.songlist .sub { display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
@media(max-width:600px){
  header.top { position:relative; top:auto; }
  .import-actions .btn { flex:1 1 140px; }
  #libView > .row { align-items:flex-start; }
}



/* Layout: one column of tabs (Sing / Lead / Songs); the editor goes wide on iPad with score above, keys below. */
:root {
  --bg: #eef0f2;
  --panel: #ffffff;
  --paper: #fbf9f4;
  --ink: #1d232b;
  --ink-soft: #55606d;
  --line: #d5dae0;
  --accent: #b3261e;          /* the hymnal's red page tab */
  --accent-ink: #ffffff;
  --accent-soft: rgba(179, 38, 30, 0.09);
  --ok: #1f7a4a;
  --warn: #a35a00;
  --S: #b3261e; --A: #a0631a; --T: #2f6b8f; --B: #4b4f9c;
  --display: "Alegreya", Georgia, "Times New Roman", serif;
  --body: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;
  --caps: "Alegreya Sans SC", "Alegreya Sans", system-ui, sans-serif;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181d; --panel: #1d232b; --paper: #f4f1ea; --ink: #e8ebee; --ink-soft: #a3adb8; --line: #323b46;
    --accent: #e0584d; --accent-ink: #1a0b0a; --accent-soft: rgba(224, 88, 77, 0.14); --ok: #58c08a; --warn: #e3a447;
    --S: #e0584d; --A: #d99a52; --T: #6aa9d0; --B: #8f93e0; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14181d; --panel: #1d232b; --paper: #f4f1ea; --ink: #e8ebee; --ink-soft: #a3adb8; --line: #323b46;
  --accent: #e0584d; --accent-ink: #1a0b0a; --accent-soft: rgba(224, 88, 77, 0.14); --ok: #58c08a; --warn: #e3a447;
  --S: #e0584d; --A: #d99a52; --T: #6aa9d0; --B: #8f93e0; color-scheme: dark;
}
html, body { background: var(--bg); color: var(--ink); }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { font: 17px/1.45 var(--body); padding-inline: 16px; padding-block: 0 40px; -webkit-tap-highlight-color: transparent; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.wrap { max-width: 1180px; margin: 0 auto; }

header.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--bg); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding-block: 12px 10px; border-bottom: 1px solid var(--line); }
.brand { font: 700 1.35rem/1 var(--display); letter-spacing: .01em; display: flex; align-items: center; gap: 8px; margin-right: auto; }
.brand-name { display: grid; gap: 4px; }
.brand-name small { font: 500 .75rem/1 var(--caps); letter-spacing: .04em; color: var(--ink-soft); }
.brand .tab { display: inline-block; background: var(--accent); color: var(--accent-ink); font: 700 .8rem/1 var(--caps); padding: 5px 7px 6px; border-radius: 3px; letter-spacing: .06em; }
nav.tabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
nav.tabs button { border: 0; background: transparent; padding: 7px 16px; border-radius: 999px; font: 700 .95rem var(--caps); letter-spacing: .05em; color: var(--ink-soft); }
nav.tabs button[aria-selected="true"] { background: var(--ink); color: var(--bg); }
.status { display: flex; gap: 6px; align-items: center; font: 500 .85rem var(--caps); letter-spacing: .04em; color: var(--ink-soft); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--ok); } .dot.warn { background: var(--warn); }

main section { padding-block: 18px; }
.sing-layout { display: grid; gap: 16px; grid-template-areas: "now" "music" "part"; align-items: start; }
.area-part { grid-area: part; } .area-now { grid-area: now; } .area-music { grid-area: music; }
.sing-paper { max-height: 64vh; overflow: auto; overscroll-behavior: contain; scroll-behavior: smooth; }
.sing-paper.off { display: none; }
@media (min-width: 900px) {
  .sing-layout { grid-template-columns: minmax(300px, 360px) minmax(0, 1fr); grid-template-areas: "now music" "part music"; }
  .area-music { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 72px); }
  .sing-paper { max-height: calc(100vh - 170px); }
}
.midi-ok { color: var(--ok); font-weight: 700; }
.mxl-row { display: grid; grid-template-columns: 2.4rem minmax(0, 1fr); gap: 10px; align-items: center; }
.pubrow { display: flex; gap: 10px; align-items: center; font-weight: 500; }
.pubrow input { width: 22px; height: 22px; flex: none; }
.chip.pub { background: color-mix(in srgb, var(--ok) 18%, transparent); }
.keys-help { display: none; font-size: .82rem; color: var(--ink-soft); line-height: 1.6; }
.keys-help kbd { font: 600 .78rem var(--body); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--panel); }
@media (hover: hover) and (pointer: fine) { .keys-help { display: block; } }
.family-join { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:18px; }
.family-join h3 { margin:0 0 8px; font-size:1rem; }
.family-advanced { grid-column:1 / -1; }
@media(max-width:600px) { .family-join { grid-template-columns:minmax(0,1fr); } }
.invite-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.invite-options { min-width: 0; border-top: 1px solid var(--line); padding-top: 12px; }
.invite-options summary { cursor: pointer; padding: 8px 0; color: var(--ink-soft); }
.invite-details { display: grid; gap: 12px; min-width: 0; padding-top: 10px; }
.qr { background: #fff; border-radius: 10px; padding: 6px; width: 180px; max-width: 100%; }
.qr svg { width: 100%; height: auto; display: block; }
.code { font: 600 1rem/1.6 var(--body); letter-spacing: .04em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; white-space: normal; min-width: 0; max-width: 100%; }
.url { word-break: break-all; font-size: .82rem; }
@media (max-width: 520px) { .invite-row { grid-template-columns: 1fr; } .qr { width: 200px; } }
.lead-fold { margin-block:12px; }
.lead-fold > summary { cursor:pointer; font-weight:600; padding:12px 0; min-height:44px; }
#leadBody { align-items:start; }
#familyControls { margin-bottom:16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 14px; min-width: 0; }
.card.lead-fold { display:block; }
.card.lead-fold > summary { margin:0; }
.card.lead-fold[open] > summary { margin-bottom:14px; }
.card h2 { font: 700 1.05rem/1.2 var(--caps); letter-spacing: .06em; margin: 0; color: var(--ink-soft); }
.label { font: 500 .8rem var(--caps); letter-spacing: .06em; color: var(--ink-soft); }
.muted { color: var(--ink-soft); font-size: .92rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 14px; font-weight: 700; min-height: 44px; }
.btn:hover { border-color: var(--ink-soft); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.big { font: 700 1.2rem var(--caps); letter-spacing: .05em; padding: 14px 26px; min-height: 58px; border-radius: 14px; }
.btn[disabled] { opacity: .45; cursor: default; }
.btn.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
input[type=text], input[type=number], select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; min-height: 44px; width: 100%; }
textarea { min-height: 70px; resize: vertical; line-height: 1.4; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 34px; }
.slider { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; }
.slider .val { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3.5ch; text-align: right; }
.slider input { grid-column: 1 / -1; }

/* part buttons */
.parts { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.part { border: 2px solid var(--line); background: var(--panel); border-radius: 12px; padding: 10px 4px 8px; display: grid; justify-items: center; gap: 2px; min-height: 72px; }
.part b { font: 700 1.7rem/1 var(--display); color: var(--pc, var(--ink)); }
.part span { font: 500 .72rem var(--caps); letter-spacing: .06em; color: var(--ink-soft); }
.part[aria-pressed="true"] { border-color: var(--pc, var(--ink)); background: color-mix(in srgb, var(--pc, var(--ink)) 10%, var(--panel)); }
.part[data-p=S] { --pc: var(--S); } .part[data-p=A] { --pc: var(--A); } .part[data-p=T] { --pc: var(--T); } .part[data-p=B] { --pc: var(--B); }

/* now playing */
.now { display: grid; gap: 10px; }
.now .title { font: 700 1.5rem/1.15 var(--display); text-wrap: balance; }
.meta { display: flex; gap: 14px; flex-wrap: wrap; font: 500 .85rem var(--caps); letter-spacing: .05em; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }
.lyric { font: 500 1.55rem/1.35 var(--display); min-height: 2.8em; text-wrap: pretty; }
.lyric .past { color: var(--ink-soft); }
.lyric .cur { color: var(--accent); text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 5px; }
.count { font: 700 3.2rem/1 var(--display); color: var(--accent); min-height: 1em; font-variant-numeric: tabular-nums; }
.join { display: grid; gap: 10px; justify-items: start; }

/* lead */
.big-tempo { font: 700 2.6rem/1 var(--display); font-variant-numeric: tabular-nums; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper .btn { min-width: 48px; font-size: 1.3rem; padding: 4px 10px; }
.stepper output { min-width: 5ch; text-align: center; font: 700 1.2rem var(--body); font-variant-numeric: tabular-nums; }
.singers { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.singers li { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.chip { font: 700 .8rem var(--caps); letter-spacing: .05em; border-radius: 6px; padding: 3px 7px; background: var(--accent-soft); color: var(--ink); }
.chip.S { background: color-mix(in srgb, var(--S) 18%, transparent); } .chip.A { background: color-mix(in srgb, var(--A) 18%, transparent); }
.chip.T { background: color-mix(in srgb, var(--T) 18%, transparent); } .chip.B { background: color-mix(in srgb, var(--B) 18%, transparent); }

/* songs */
.songlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.songlist button { width: 100%; text-align: left; display: grid; grid-template-columns: 2.4rem minmax(0, 1fr) auto; gap: 12px; align-items: baseline; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.songlist .num { font: 700 1.3rem var(--display); color: var(--accent); font-variant-numeric: tabular-nums; }
.songlist .t { font: 700 1.1rem var(--display); }
.songlist .sub { font: 500 .78rem var(--caps); letter-spacing: .05em; color: var(--ink-soft); }
.empty { border: 1px dashed var(--line); border-radius: var(--radius); padding: 22px; color: var(--ink-soft); }

/* editor */
.ed-head { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.ed-head .wide { grid-column: span 2; }
.paper { background: var(--paper); border-radius: 10px; border: 1px solid var(--line); overflow-x: auto; color: #1d232b; }
.paper svg { display: block; }

/* chord editor */
.ce { display: grid; gap: 14px; }
.ce-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; flex-wrap: wrap; }
.ce-where { font: 700 1.5rem var(--display); }
.ce-sub { color: var(--ink-soft); font-size: 1rem; min-height: 1.4em; }
.ce-sub b { color: var(--ink); font: 700 1.25rem var(--display); }
.ce-meter { display: flex; gap: 4px; }
.ce-meter span { width: 26px; height: 14px; border-radius: 4px; background: var(--line); }
.ce-meter span.done { background: var(--ink-soft); }
.ce-meter span.here { background: var(--accent); }
.ce-strip { position: relative; max-height: min(270px, 26vh); overflow: auto; cursor: pointer; }
.ce-cursor { position: absolute; pointer-events: none; border-radius: 6px; background: rgba(179, 38, 30, 0.13); outline: 2px solid rgba(179, 38, 30, 0.55); }
.ce-card { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 640px) { .ce-card { grid-template-columns: 1fr; } }
.ce-staff { align-items: start; align-content: start; background: var(--paper); color: #1d232b; border: 1px solid var(--line); border-radius: 12px; padding: 8px 8px 10px; display: grid; grid-template-columns: 2.4em 1fr 1fr; column-gap: 4px; }
.ce-staff .clef { grid-column: 1 / -1; font: 600 .8rem var(--caps); letter-spacing: .06em; color: #55606d; margin: 0 0 4px 2px; }
.ce-labels, .ce-voice { display: grid; grid-auto-rows: var(--rh, 25px); }
.ce-labels span { font: 500 .78rem var(--body); color: #7a8591; display: flex; align-items: center; justify-content: flex-end; padding-right: 4px; }
.ce-voice { border-radius: 8px; }
.ce-voice.sel { background: rgba(29, 35, 43, 0.05); box-shadow: inset 0 0 0 2px var(--vc); }
.ce-vh { display: flex; align-items: center; justify-content: center; gap: 6px; font: 700 .95rem var(--body); color: var(--vc); height: 30px; border: 0; background: none; cursor: pointer; }
.ce-pos { position: relative; border: 0; padding: 0; margin: 0; background: none; cursor: pointer; touch-action: manipulation; }
.ce-pos.line::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1.6px; margin-top: -.8px; background: #2b333d; }
.ce-pos.ledger::before { content: ""; position: absolute; left: 22%; right: 22%; top: 50%; border-top: 1.5px dotted #9aa3ad; }
.ce-pos:hover { background: rgba(29, 35, 43, 0.06); }
.ce-head-note { position: absolute; left: 50%; top: 50%; width: 26px; height: 19px; margin: -9.5px 0 0 -13px; border-radius: 50%; background: var(--vc); transform: rotate(-20deg); z-index: 2; }
.ce-pos.ledger-on::before { content: ""; position: absolute; left: calc(50% - 22px); width: 44px; top: 50%; height: 1.6px; margin-top: -.8px; background: #2b333d; border: 0; }
.ce-nm { position: absolute; left: calc(50% + 20px); top: 50%; transform: translateY(-50%); font: 700 1.05rem var(--body); color: var(--vc); white-space: nowrap; z-index: 3; background: rgba(251, 249, 244, 0.9); border-radius: 4px; padding: 0 3px; }
.ce-acc { position: absolute; right: calc(50% + 15px); top: 50%; transform: translateY(-50%); font: 700 1.25rem var(--body); color: var(--vc); z-index: 3; }
.ce-pos.held .ce-head-note { background: transparent; box-shadow: inset 0 0 0 3px var(--vc); opacity: .75; }
.ce-restmark { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font: 700 .9rem var(--body); color: var(--vc); z-index: 3; pointer-events: none; }
.ce-vtools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 8px; }
.ce-vtools button { min-height: 40px; border: 1px solid #d5dae0; border-radius: 8px; background: #fff; color: #1d232b; font: 700 1rem var(--body); padding: 2px 4px; cursor: pointer; }
.ce-vtools button.wide { grid-column: span 3; font-size: .85rem; }
.ce-vtools .pair { grid-column: span 3; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.ce-vtools button.on { background: #1d232b; color: #fff; border-color: #1d232b; }
.ce-block { display: grid; gap: 6px; }
.ce-lens { display: flex; flex-wrap: wrap; gap: 8px; }
.ce-lens button { min-width: 78px; min-height: 58px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); display: grid; place-items: center; padding: 4px 10px; cursor: pointer; }
.ce-lens button b { font: 700 1.3rem var(--body); line-height: 1; }
.ce-lens button small { font: 500 .72rem var(--caps); letter-spacing: .04em; color: var(--ink-soft); }
.ce-lens button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.ce-lens button.on small { color: inherit; }
.ce-nav { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 10px; position: sticky; bottom: 0; background: var(--bg); padding-block: 8px calc(8px + env(safe-area-inset-bottom, 0px)); z-index: 10; }
.ce-nav .btn.big { min-height: 60px; font-size: 1.1rem; }
.ce-more { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ce-more .sep { width: 1px; align-self: stretch; background: var(--line); margin-inline: 2px; }
.ce-help summary { cursor: pointer; color: var(--ink-soft); }
.ce-help ul { margin: 6px 0 0; padding-left: 1.2em; color: var(--ink-soft); }
.ce-help kbd { font: 600 .78rem var(--body); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--panel); }
@media (hover: none) { .ce-keys { display: none; } }

.ocr-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.ocr-bar label.btn { display: inline-flex; align-items: center; }
.ocr-panel { display: grid; gap: 12px; }
.ocr-panel h2 { margin: 0; }
.ocr-view { position: relative; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; overflow: auto; max-height: min(70vh, 720px); }
.ocr-view canvas { display: block; width: 100%; height: auto; }
.ocr-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.ocr-tools label { display: grid; gap: 4px; }
.ocr-legend { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ocr-busy { display: flex; gap: 10px; align-items: center; font-size: 1.05rem; }
.ocr-busy::before { content: ""; width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: ocrspin 0.9s linear infinite; }
@keyframes ocrspin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ocr-busy::before { animation: none; } }
.ocr-sum { font-size: 1.05rem; }
.ocr-sum b { font-variant-numeric: tabular-nums; }
.ocr-note { border-left: 4px solid #d97a00; padding: 6px 10px; background: color-mix(in srgb, #d97a00 10%, transparent); border-radius: 0 8px 8px 0; }
.ocr-strip { display: grid; gap: 8px; border: 2px solid #d97a00; border-radius: 12px; padding: 10px; background: var(--panel); }
.ocr-strip.ok { border-color: var(--line); }
.ocr-strip-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; }
.ocr-why { color: #9a5600; font-weight: 600; }
.ocr-strip.ok .ocr-why { color: var(--ink-soft); font-weight: 400; }
.ocr-crop { background: #fff; border-radius: 8px; overflow: hidden; display: flex; justify-content: center; }
.ocr-crop canvas { display: block; max-width: 100%; height: auto; }
.ocr-strip-nav { flex-wrap: wrap; gap: 8px; }
.words-list { display: grid; gap: 12px; }
.ocr-crop canvas { cursor: crosshair; touch-action: manipulation; }
.ocr-tap { display: grid; gap: 8px; padding: 10px; border-radius: 10px; background: color-mix(in srgb, var(--accent) 8%, var(--panel)); border: 1px solid var(--line); }
.ocr-how summary { cursor: pointer; color: var(--ink-soft); }
.ocr-how ul { margin: 6px 0 0; padding-left: 1.2em; }
.ocr-how .vS { color: var(--S); } .ocr-how .vA { color: var(--A); } .ocr-how .vT { color: var(--T); } .ocr-how .vB { color: var(--B); }
.acct-form { flex-wrap: nowrap; } .acct-form input { flex: 1 1 14ch; min-width: 0; }
.acct-note { padding: 6px 10px; border-left: 4px solid var(--T); background: color-mix(in srgb, var(--T) 10%, transparent); border-radius: 0 8px 8px 0; }
.acct-note.bad { border-left-color: #d97a00; background: color-mix(in srgb, #d97a00 10%, transparent); }
.rights-note { font-size: .9rem; color: var(--ink-soft); border-left: 3px solid var(--line); padding-left: 8px; }
.words-item { display: grid; gap: 6px; }
.words-item textarea { min-height: 5.5em; }
.words-item .head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.joincode { margin-bottom: 16px; }
.joincode .jc-in { font: 600 1.5rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; text-transform: uppercase; width: 11ch; min-width: 0; flex: 1 1 11ch; padding: 10px 12px; }
.joincode .jc-form { flex-wrap: nowrap; }
.score { min-height: 200px; touch-action: manipulation; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--line); margin-inline: 4px; }
.tb { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; min-width: 44px; min-height: 44px; padding: 3px 8px; font: 700 1rem var(--body); display: inline-grid; place-items: center; }
.tb.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tb small { display: block; font: 500 .62rem var(--caps); letter-spacing: .05em; }
.pt-S.on { background: var(--S); border-color: var(--S); color: #fff; } .pt-A.on { background: var(--A); border-color: var(--A); color: #fff; }
.pt-T.on { background: var(--T); border-color: var(--T); color: #fff; } .pt-B.on { background: var(--B); border-color: var(--B); color: #fff; }
.piano-wrap { overflow-x: auto; }
.piano { position: relative; height: 118px; display: flex; user-select: none; -webkit-user-select: none; touch-action: manipulation; min-width: 560px; }
.wk { flex: 1; border: 1px solid #9aa3ad; border-radius: 0 0 7px 7px; background: #fdfdfb; margin-right: -1px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 8px; font: 500 .72rem var(--caps); color: #6b7480; }
.wk:active, .wk.hit { background: #f3d9d6; }
.bk { position: absolute; top: 0; height: 72px; background: #1f252c; border-radius: 0 0 6px 6px; z-index: 2; }
.bk:active, .bk.hit { background: #b3261e; }
.problems { margin: 0; padding-left: 1.1em; color: var(--warn); font-size: .92rem; }
.lyr-row { display: grid; grid-template-columns: 2.4rem 1fr; gap: 8px; align-items: start; }
.lyr-row .n { font: 700 1.2rem var(--display); color: var(--accent); padding-top: 8px; }
.okline { font: 500 .85rem var(--caps); letter-spacing: .04em; }
.okline.good { color: var(--ok); } .okline.bad { color: var(--warn); }
.ed-bottom { position: sticky; bottom: 0; background: var(--bg); padding-block: 8px calc(8px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); display: grid; gap: 8px; z-index: 10; }
@media (max-height: 700px) { .piano { height: 96px; } .bk { height: 58px; } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 700; z-index: 50; max-width: calc(100% - 32px); }
.confirm { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; }
details summary { cursor: pointer; font: 500 .85rem var(--caps); letter-spacing: .05em; color: var(--ink-soft); }
@media (max-width: 520px) { .parts { grid-template-columns: repeat(5, 1fr); gap: 5px; } .part b { font-size: 1.35rem; } .lyric { font-size: 1.3rem; } .ed-head .wide { grid-column: auto; } }
@media (prefers-reduced-motion: reduce) { .bar i { transition: none; } }

/* Practice: shared transport, compact notation and a stable singing view. */
body { padding-bottom:calc(155px + env(safe-area-inset-bottom,0px)); }
.practice-controls { position:fixed; z-index:25; bottom:0; left:0; right:0; background:var(--panel); border-top:1px solid var(--line); padding:10px max(16px,calc((100vw - 1148px)/2)) calc(10px + env(safe-area-inset-bottom,0px)); display:grid; gap:8px; }
.practice-controls select { width:100%; min-width:0; }
.practice-controls .row { flex-wrap:nowrap; }
.practice-controls .btn { flex:1; min-width:0; padding:9px 8px; }
.sing-paper { max-height:70vh; scroll-behavior:auto; }
.area-music { padding:12px; min-width:0; }
.area-music h2 { font-size:1.1rem; margin:0; }
.sounding-note, .sounding-note * { fill:#b3261e !important; stroke:#b3261e !important; }
@media(min-width:700px){.practice-controls{grid-template-columns:minmax(180px,1fr) auto;align-items:center}.practice-controls .btn{min-width:80px}}
@media(max-width:600px){header.top{position:relative;top:auto}.sing-layout{gap:10px}.area-now{padding:12px}.now .title{font-size:1.35rem}}

/* Tighter spacing: cards already space children with `gap`, so drop stacked margins and empty placeholders. */
.card > p, .card > .lead-fold { margin-block:0; }
.card > div:empty, .card > p:empty { display:none; }
.card.lead-fold { margin-block:16px 0; }
/* Count-in floats over the now-playing card instead of reserving a blank band. */
.area-now { position:relative; }
.area-now > .count { position:absolute; top:8px; right:10px; min-height:0; pointer-events:none; background:var(--panel); padding:2px 10px; border-radius:10px; box-shadow:0 2px 10px rgb(0 0 0 / .12); }
.area-now > .count:empty { display:none; }
.lyric:empty { min-height:0; }
/* One-row transport so the fixed bar (and the space kept for it) stays short. */
.practice-controls .btn { white-space:nowrap; padding:9px 10px; flex:1 1 auto; }
body { padding-bottom:calc(122px + env(safe-area-inset-bottom,0px)); }
body:has(#listenHost[hidden]) { padding-bottom:calc(24px + env(safe-area-inset-bottom,0px)); }

/* Chord editor bar: one compact row that reads as a toolbar, edge to edge, above Safari's bottom bar. */
.ce-nav { grid-template-columns: auto 1fr 1.25fr; gap: 8px; padding-block: 8px calc(8px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line); box-shadow: 0 0 0 100vmax var(--bg); clip-path: inset(0 -100vmax); }
.ce-nav .btn.big { min-height: 46px; padding: 8px 12px; font: 700 1rem/1.1 var(--body, system-ui, sans-serif); letter-spacing: 0; white-space: nowrap; border-radius: 12px; }

/* A closed fold-out card is just its title. */
details.card:not([open]) { gap: 0; }

.no-ai { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.no-ai .muted { flex: 1 1 220px; }

/* Song editor header: which song this is, and a direct way to practise it. */
.ed-title-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin: 4px 0 14px; }
.ed-title { font: 700 1.5rem/1.2 var(--display); margin: 0; flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }

#importBox > summary { font-weight: 600; min-height: 32px; display: flex; align-items: center; gap: 8px; }
#importBox > summary::before { content: "\25B8"; } #importBox[open] > summary::before { content: "\25BE"; }
#importBox > summary::-webkit-details-marker { display: none; } #importBox > summary { list-style: none; }
#importBox h2 { margin-top: 4px; }
#importBox:not([open]) { display: block; padding-block: 10px; }
/* live tempo on the play bar: a small − 96 + beside the hymn picker */
.practice-controls .pc-top { flex-wrap:nowrap; gap:8px; align-items:center; }
.practice-controls .pc-top select { flex:1 1 auto; }
.practice-controls .live-tempo { display:flex; flex:0 0 auto; align-items:center; gap:2px; }
.practice-controls .live-tempo .btn { flex:0 0 auto; min-width:40px; width:40px; padding:8px 0; font-weight:700; }
.practice-controls .live-tempo-v { min-width:3ch; text-align:center; font-weight:700; font-variant-numeric:tabular-nums; }
.invite-code-big { font:700 1.35rem/1.4 ui-monospace, Menlo, Consolas, monospace; letter-spacing:.06em; word-spacing:.3em; margin:6px 0 10px; user-select:all; }
.join-mini > summary { cursor:pointer; font-weight:600; min-height:44px; display:flex; align-items:center; }
#leadBody { margin-bottom:16px; }
#joinMini { margin-top:16px; }
/* who's singing: one tap loads a person's part and volumes */
.who { margin-bottom:10px; }
.who-names { flex-wrap:wrap; gap:6px; }
.who-name { display:inline-flex; gap:6px; align-items:baseline; }
.who-name span { font-size:.8em; opacity:.7; }
.who-name.on { outline:2px solid var(--accent, #b3261e); }
.family-members { display:grid; gap:6px; margin:8px 0; }
.family-members .member { justify-content:space-between; flex-wrap:wrap; }
/* tidy-up */
.device-help { margin-top:10px; }
.device-help > summary { cursor:pointer; font-weight:600; min-height:40px; display:flex; align-items:center; gap:6px; color:var(--muted, #5b6470); list-style:none; }
.device-help > summary::-webkit-details-marker { display:none; }
.device-help > summary::before { content:'▸'; } .device-help[open] > summary::before { content:'▾'; }
.join-mini > summary { list-style:none; gap:6px; } .join-mini > summary::-webkit-details-marker { display:none; }
.join-mini > summary::before { content:'▸'; } .join-mini[open] > summary::before { content:'▾'; }
.device-help[open] > * + * { margin-top:8px; }
#addDevice > summary { cursor:pointer; list-style:none; display:flex; align-items:center; gap:8px; }
#addDevice > summary::-webkit-details-marker { display:none; }
#addDevice > summary::before { content:'▸'; } #addDevice[open] > summary::before { content:'▾'; }
#addDevice > summary h3 { margin:0; }
.area-now .who { margin:6px 0 10px; }
/* iPad portrait and other mid widths: your part sits beside the status card, music full width below */
@media (min-width: 600px) and (max-width: 899px) {
  .sing-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "now part" "music music"; }
}
/* the ⋯ menu on the play bar */
.practice-controls .pc-more { position:relative; flex:0 0 auto; }
.practice-controls .pc-more > summary { list-style:none; min-width:48px; text-align:center; font-weight:700; cursor:pointer; }
.practice-controls .pc-more > summary::-webkit-details-marker { display:none; }
.practice-controls .pc-menu { position:absolute; right:0; bottom:calc(100% + 8px); display:grid; gap:6px; min-width:180px; padding:8px; background:var(--panel); border:1px solid var(--line); border-radius:12px; box-shadow:0 8px 24px rgb(0 0 0 / .15); z-index:30; }
.practice-controls .pc-menu .btn { width:100%; }
/* nothing playing: just the title line */
.area-now.idle .meta, .area-now.idle .bar { display:none; }
/* join from any device */
.join-mini.join-top { margin:0 0 16px; }
.joincode .jc-form { flex-wrap:wrap; }
.joincode .jc-form .scan-btn { flex:1 1 100%; font-weight:700; }
.joincode .jc-form .jc-in { flex:1 1 8ch; width:auto; min-width:0; }
.scan-box { position:fixed; inset:0; z-index:60; background:rgb(0 0 0 / .88); display:grid; place-items:center; align-content:center; gap:14px; padding:20px; color:#fff; text-align:center; }
.scan-box video { width:min(92vw, 520px); aspect-ratio:1; object-fit:cover; border-radius:16px; background:#111; }
.guest-invite { margin-top:10px; }
.guest-invite > summary { cursor:pointer; font-weight:600; min-height:40px; display:flex; align-items:center; gap:6px; list-style:none; }
.guest-invite > summary::-webkit-details-marker { display:none; }
.guest-invite > summary::before { content:'▸'; } .guest-invite[open] > summary::before { content:'▾'; }
.guest-invite .qr { max-width:220px; }

/* Group bar: which group this device is in, one tap to switch, start or join another. */
.group-bar { margin: 10px 0 12px; }
.group-btn { width: 100%; display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; text-align: left; padding: 8px 14px; min-height: 48px; }
.group-btn .g-label { font: 500 .75rem var(--caps); letter-spacing: .06em; color: var(--ink-soft); }
.group-btn .g-name { font: 700 1.05rem/1.2 var(--display); min-width: 0; overflow-wrap: anywhere; }
.group-btn .g-sub { color: var(--ink-soft); font-weight: 500; font-size: .9rem; flex: 1 1 auto; }
.group-btn .g-switch { margin-left: auto; font: 700 .85rem var(--caps); letter-spacing: .05em; color: var(--accent); white-space: nowrap; }
.group-panel { margin-bottom: 16px; }
.group-panel .gp-head { justify-content: space-between; }
.group-panel h3 { margin: 0; font: 700 .95rem var(--caps); letter-spacing: .05em; color: var(--ink-soft); }
.group-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.group-list .g-item { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.group-list .g-item.here { border-color: var(--accent); background: var(--accent-soft); }
.group-list .g-info { display: grid; gap: 2px; flex: 1 1 180px; min-width: 0; }
.group-list .g-info b { overflow-wrap: anywhere; }
.group-list .g-item .btn { flex: 0 0 auto; }
.gp-this { display: grid; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; }
.gp-rename { flex-wrap: nowrap; } .gp-rename input { flex: 1 1 auto; min-width: 0; } .gp-rename .btn { flex: 0 0 auto; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg .btn { display: grid; gap: 2px; justify-items: center; }
.seg .btn small { font-weight: 500; font-size: .8rem; opacity: .8; }
.gp-fold { border-top: 1px solid var(--line); padding-top: 10px; }
.gp-fold > summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; }
.gp-fold[open] > * + * { margin-top: 10px; }
.gp-new { display: grid; gap: 8px; }
#psalmCard { margin-bottom: 16px; }
#handoffRow { flex-wrap: wrap; } #handoffRow select { flex: 1 1 160px; width: auto; } #handoffRow .btn { flex: 0 0 auto; }
.family-members .member .btn { flex: 0 0 auto; }
.group-list .g-actions { display: flex; gap: 8px; margin-left: auto; }
/* keep notices clear of the play bar */
body:not(:has(#listenHost[hidden])) .toast { bottom: calc(130px + env(safe-area-inset-bottom, 0px)); }
@media (max-width: 520px) { .group-btn .g-label { display: none; } .group-btn { padding: 8px 12px; } }
.gp-fold > summary { list-style: none; gap: 6px; } .gp-fold > summary::-webkit-details-marker { display: none; }
.gp-fold > summary::before { content: '▸'; } .gp-fold[open] > summary::before { content: '▾'; }
/* Sing and Lead are told apart at a glance: each has its own heading and colour, matched by its tab. */
.view-head { display: grid; gap: 2px; margin: 4px 0 14px; padding: 10px 14px; border-left: 5px solid var(--vh); border-radius: 0 10px 10px 0; background: color-mix(in srgb, var(--vh) 8%, transparent); }
.view-head h1 { margin: 0; font: 700 1.6rem/1.1 var(--display); color: var(--vh); }
.view-head p { margin: 0; color: var(--ink-soft); font-size: .95rem; }
.sing-head { --vh: var(--accent); }
.lead-head { --vh: var(--T); }
nav.tabs #tab-sing[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
nav.tabs #tab-lead[aria-selected="true"] { background: var(--T); color: #fff; }
/* Group panel: nothing inside may widen the card past the screen (Safari sizes the grid track from its widest child). */
.group-panel { grid-template-columns: minmax(0, 1fr); }
.group-panel > *, .group-panel form, .group-panel details, .group-panel .row { min-width: 0; max-width: 100%; }
.group-panel .jc-form, .gp-rename { width: 100%; }
.group-panel .jc-form .btn[type=submit], .gp-rename .btn { flex: 0 0 auto; }
.group-panel input, .group-panel select { min-width: 0; max-width: 100%; }
.seg { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.seg .btn { min-width: 0; white-space: normal; }
.seg .btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
/* Every card: one column that can shrink to the screen, so a wide word, input or font never pushes it off the edge. */
.card:not(.ce-card) { grid-template-columns: minmax(0, 1fr); }
.card > * { min-width: 0; }
.joincode .jc-form { min-width: 0; max-width: 100%; }
.joincode .jc-form .btn[type=submit] { flex: 0 0 auto; }
/* Who's singing: name chips with the part in its colour; the chosen person is clearly marked, like the part buttons. */
.area-now .who { margin: 2px 0 8px; display: grid; gap: 8px; }
.who-names { display: flex; flex-wrap: wrap; gap: 8px; }
.who-name { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 10px 6px 14px; border-width: 2px; outline: none; }
.who-name .who-name-t { font-weight: 700; }
.who-name .chip { font-size: .75rem; padding: 2px 7px; }
.who-name.on { outline: none; border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.who-name.on::before { content: '✓'; color: var(--accent); font-weight: 800; margin-right: -2px; }
.who-new { min-height: 44px; border-style: dashed; color: var(--ink-soft); font-weight: 600; }
.who-name, .who-new { font-size: 1rem; }
.who-name .who-name-t { font-size: 1rem; opacity: 1; } .who-name .chip { opacity: 1; }

/* Start screen and join setup: one clear screen each, nothing else showing. */
html.at-home main, html.at-home #groupBar, html.at-home #groupPanel, html.at-home #listenHost, html.at-home nav.tabs, html.at-home .status,
html.in-setup main, html.in-setup #groupBar, html.in-setup #groupPanel, html.in-setup #listenHost, html.in-setup nav.tabs { display: none !important; }
html.at-home body, html.in-setup body { padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
.home, .setup { display: grid; gap: 14px; max-width: 560px; margin: 8px auto 0; }
.home[hidden], .setup[hidden] { display: none; }
.home-intro h1 { margin: 6px 0 4px; font: 700 1.9rem/1.1 var(--display); }
.home-intro p { margin: 0; color: var(--ink-soft); }
.home .card h2, .setup .card h2 { font-size: 1rem; }
.home-start > summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; list-style: none; gap: 6px; }
.home-start > summary::-webkit-details-marker { display: none; }
.home-start > summary::before { content: '▸'; } .home-start[open] > summary::before { content: '▾'; }
.home-alone, .setup-leave { justify-self: center; background: transparent; border-color: transparent; color: var(--ink-soft); font-weight: 600; text-decoration: underline; }
.setup-go { width: 100%; }
.setup-go:disabled { opacity: .45; }
.setup-msg:empty { display: none; }
.setup .who-names:empty { display: none; }

/* A joined device: sing only. No tabs, no Sing heading, no name box (the setup screen and the name chips cover it). */
html.guest nav.tabs, html.guest .sing-head, html.guest #familyResume { display: none !important; }
html.guest .area-part .row:has(#nick) { display: none; }
.group-bar { display: flex; gap: 8px; align-items: stretch; }
.group-bar .group-btn { flex: 1 1 auto; min-width: 0; }
.group-btn.static { cursor: default; opacity: 1; }
.group-btn.static .g-switch { display: none; }
.group-btn:disabled { color: inherit; }
.group-leave { flex: 0 0 auto; font-weight: 700; color: var(--accent); }
.group-leave.armed { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
html.guest #psalmCard { margin-top: 14px; }
/* Playlist card on Lead */
.playlist { display: grid; gap: 10px; }
.pl-add { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; } .pl-add select { width: 100%; min-width: 0; }
.pl-list { margin: 0; padding-left: 1.4em; display: grid; gap: 6px; }
.pl-list:empty { display: none; }
.pl-list li { margin: 0 !important; }
.pl-go { flex-wrap: wrap; gap: 10px 14px; }
.pl-list .pl-item { display: grid; grid-template-columns: minmax(0, 1fr) 44px 44px 44px; gap: 6px; align-items: center; }
.pl-list .pl-item .btn { padding: 8px 0; }
.pl-list .pl-name { text-align: left; padding: 8px 12px !important; white-space: normal; overflow-wrap: anywhere; }
.pl-list .pl-x { color: var(--ink-soft); }
.lead-switch { font-weight: 700; gap: 10px; }

/* Secondary measure controls stay quiet, with comfortable touch targets. */
.practice-controls .pc-measure-nav { display:flex;gap:2px;align-items:center;justify-content:flex-end; }
.practice-controls .pc-measure-nav .btn { flex:0 0 44px;min-width:44px;min-height:44px;padding:4px;background:transparent;border-color:transparent;box-shadow:none;color:var(--ink-soft);font-size:1.25rem; }
.practice-controls .pc-measure-caption { flex:0 0 auto;font-size:.85rem; }



/* A single playback row; secondary settings open above it without resizing the dock. */
.practice-controls { display:flex; align-items:center; gap:6px; padding:8px max(12px,calc((100vw - 1148px)/2)) calc(8px + env(safe-area-inset-bottom,0px)); }
.practice-controls > .btn { flex:0 0 auto; min-width:56px; min-height:44px; padding:8px 12px; }
.practice-controls > .primary { flex:1 1 auto; min-width:80px; }
.practice-controls > .pc-stop { background:transparent; border-color:transparent; color:var(--ink-soft); }
.practice-controls .pc-measure-nav { flex:0 0 auto; }
.practice-controls .pc-more > summary { display:flex; align-items:center; justify-content:center; width:44px; min-width:44px; min-height:44px; padding:4px; }
.practice-controls .pc-menu { width:min(320px,calc(100vw - 24px)); min-width:0; max-height:calc(100dvh - 110px - env(safe-area-inset-bottom,0px)); overflow:auto; padding:14px; gap:10px; }
.practice-controls .pc-menu .pc-tempo { justify-content:space-between; }
.practice-controls .pc-menu .live-tempo .btn { width:44px; min-width:44px; min-height:44px; }
body { padding-bottom:calc(var(--playbar-height,60px) + 16px); }
body:not(:has(#listenHost[hidden])) .toast { bottom:calc(var(--playbar-height,60px) + 12px); }
.sing-paper { max-height:70dvh; }

/* The host prepares, invites and plays from one rehearsal dashboard. */
.host-dashboard { display:grid; grid-template-columns:minmax(0,1.25fr) minmax(0,1fr); grid-template-areas:"current invite" "playlist invite" "playlist mix"; gap:16px; align-items:start; }
.host-dashboard #leadBody { display:contents; }
.host-dashboard .host-current { grid-area:current; }
.host-dashboard .lead-song { grid-area:playlist; }
.host-dashboard #familyControls { grid-area:invite; }
.host-dashboard .host-mix-wrap { grid-area:mix; display:grid; gap:10px; }
.host-dashboard .card { margin:0; }
.host-current h2 { font:700 1.6rem/1.2 var(--display); margin:0; }
.host-current select { width:100%; }
.host-actions { flex-wrap:wrap; }
.host-actions .primary { flex:1 1 120px; }
.host-actions .btn { min-height:48px; }
.host-card-head { justify-content:space-between; }
.host-card-head h2 { margin:0; }
.host-dashboard .family-join { margin:0; grid-template-columns:minmax(0,1fr); }
.host-dashboard #inviteQr { width:min(100%,240px); margin:12px auto; background:#fff; padding:8px; border-radius:10px; }
.host-dashboard #inviteQr svg { display:block; width:100%; height:auto; }
.host-dashboard .invite-code-big { font-size:1.8rem; }
.host-dashboard #addDevice > summary { min-height:44px; }
.host-dashboard #addDevice > summary h3 { font-size:1rem; }
.host-dashboard .singers { padding:0; }
.host-dashboard .singers li { flex-wrap:wrap; }
.host-tempo { justify-content:space-between; margin-top:12px; }
.host-audio { padding:0 4px; }
.host-mix-wrap .area-part { grid-area:auto; }
@media(max-width:760px) {
  .host-dashboard { grid-template-columns:minmax(0,1fr); grid-template-areas:"current" "invite" "mix" "playlist"; }
  .host-dashboard #inviteQr { width:180px; }
  .host-dashboard .host-current h2 { font-size:1.4rem; }
}


/* Keep the playlist clear of the sticky header after dock navigation. */
#rehearsalPlaylist { scroll-margin-top:calc(88px + env(safe-area-inset-top,0px)); }
