:root {
  --bg: #101114;
  --fg: #ececec;
  --muted: #8a8f98;
  --chord: #ffb703;
  --section: #8ecae6;
  --active: #1d2a3b;
  --bar: #000000d9;
  --line: #2c2f36;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.warn { color: #ffb4a2; }

/* ---------- top bar */
#topbar {
  position: fixed; inset: 0 0 auto 0; height: 50px; z-index: 10;
  display: flex; align-items: center; gap: 8px; padding: 0 8px;
  background: var(--bar); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line);
}
#title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#prog { position: absolute; left: 0; bottom: -1px; height: 2px; width: 0; background: var(--chord); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #555; flex: none; }
.dot.ok { background: #4caf50; }
.dot.bad { background: #e53935; }
#beat { width: 20px; height: 20px; border-radius: 50%; background: #2a2d33; flex: none; }
#beat.on { background: #4caf50; }
#beat.accent { background: #ff5252; }
#status { width: 1em; text-align: center; }

.btn {
  background: #24272e; color: var(--fg); border: 1px solid #3a3e47; border-radius: 10px;
  padding: 7px 11px; font-size: 16px; min-width: 40px; cursor: pointer; touch-action: manipulation;
}
.btn:active { background: #343844; }
.btn.primary { background: #2e7d32; border-color: #3f9b44; }
.btn.big { font-size: 22px; padding: 14px 28px; }
.btn.pending { outline: 2px solid var(--chord); }

/* ---------- popover settings */
.pop {
  position: fixed; top: 56px; right: 8px; z-index: 12; display: none;
  background: #1b1d22; border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-width: 240px;
}
.pop.open { display: block; }
.row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.row label { flex: 1; }

/* ---------- sheet */
#sheet {
  --fs: 20px;
  padding: 64px 14px 75vh;
  font-size: var(--fs);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
  line-height: 1.3;
}
.waiting { font-family: system-ui, sans-serif; color: var(--muted); text-align: center; margin-top: 30vh; padding: 0 20px; }
.songhead { font-family: system-ui, sans-serif; margin-bottom: 0.8em; }
.songhead h1 { margin: 0; font-size: 1.3em; }
.songhead .artist { color: var(--muted); }
.songhead .meta { color: var(--chord); font-size: 0.75em; margin-top: 4px; }
.section {
  font-family: system-ui, sans-serif; color: var(--section); font-weight: 700;
  font-size: 0.72em; text-transform: uppercase; letter-spacing: 0.06em; margin: 1.1em 0 0.3em;
}
.line { margin: 1px -8px; padding: 2px 8px; border-radius: 8px; border-left: 3px solid transparent; transition: background 0.2s; }
.line.active { background: var(--active); border-left-color: var(--chord); }
.chunk { display: inline-flex; flex-direction: column; vertical-align: bottom; }
.ch { color: var(--chord); font-weight: 700; white-space: pre; }
.chunk .ch { padding-right: 0.45em; }
.ly { white-space: pre; }
.pair { white-space: pre-wrap; }
.chords { white-space: pre-wrap; }
.text { white-space: pre-wrap; color: #d6d6d6; }
.tab { font-size: 0.6em; color: #b9bec7; overflow-x: auto; margin-top: 4px; margin-bottom: 4px; }
.blank { height: 0.6em; }
body[data-role="admin"] .line { cursor: pointer; }
body[data-role="admin"] #sheet { padding-bottom: 80vh; }

#focus { position: fixed; left: 0; right: 0; top: 33vh; border-top: 1px dashed #ffffff1f; pointer-events: none; z-index: 1; }
#countin {
  position: fixed; inset: 0; z-index: 20; display: none; align-items: center; justify-content: center;
  font-size: 40vmin; font-weight: 800; background: #0009; pointer-events: none;
}

/* ---------- overlays */
.overlay {
  position: fixed; inset: 0; z-index: 30; background: #000000ee;
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px;
}
.overlay p { color: var(--muted); max-width: 340px; margin: 12px auto; }
#toast {
  position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #c62828; color: #fff; padding: 10px 14px; border-radius: 10px; z-index: 40;
  transition: all 0.25s; pointer-events: none; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- admin */
#drawer {
  position: fixed; top: 50px; right: 0; bottom: 60px; width: min(440px, 100%); z-index: 15;
  background: #17191e; border-left: 1px solid var(--line); overflow: auto; padding: 4px 16px 24px; display: none;
}
#drawer.open { display: block; }
#drawer h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.field {
  width: 100%; background: #0f1013; color: var(--fg); border: 1px solid #3a3e47; border-radius: 8px;
  padding: 9px; font-size: 16px; margin: 4px 0;
}
#drawer textarea { min-height: 180px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
#drawer .row input { width: 90px; }
#drawer .hint { color: var(--muted); font-size: 13px; }
#drawer details { margin-top: 10px; }
#busy { display: none; color: var(--chord); margin: 8px 0; }
#qr { width: 200px; height: 200px; background: #fff; display: block; margin: 8px 0; border-radius: 8px; }
#musicianLink { color: var(--section); word-break: break-all; }
#transport {
  position: fixed; inset: auto 0 0 0; height: 60px; z-index: 10;
  display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 6px;
  background: var(--bar); border-top: 1px solid var(--line);
}
#transport .sep { width: 8px; }
/* small handle to hide/show the playback bar */
#transportToggle {
  position: fixed; right: 6px; bottom: 64px; z-index: 11; font-size: 12px; line-height: 1;
  padding: 4px 9px; min-width: 0; border-radius: 999px; opacity: .8;
}
body.transport-hidden #transport { display: none; }
body.transport-hidden #transportToggle { bottom: 6px; }
body.transport-hidden #followBtn { bottom: 6px; }
#bpmVal { min-width: 2.2em; text-align: center; font-weight: 700; }
#pos { min-width: 3.5em; text-align: right; font-size: 13px; }
@media (max-width: 420px) {
  #transport { gap: 3px; }
  #transport .btn { padding: 7px 8px; min-width: 34px; }
  #pos, #sync { display: none; }
}

/* ---------- connection, preview, library, setup */
.dot.slow { background: #f9a825; }
#connNote {
  display: none; position: fixed; top: 50px; left: 0; right: 0; z-index: 9; text-align: center;
  background: #3e2c00; color: #ffe08a; font-size: 13px; padding: 6px 10px;
}
body[data-role="musician"] #drawer { bottom: 0; }
#previewBar {
  display: none; position: fixed; top: 50px; left: 0; right: 0; z-index: 9; padding: 6px 10px;
  background: #0d3b66; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px;
}
body.previewing #previewBar { display: flex; }
body.previewing #focus { display: none; }
.library { list-style: none; padding: 0; margin: 0; }
.library li { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); }
.library li.live { background: #1d2a3b; }
.library .songname {
  flex: 1; text-align: left; background: none; border: 0; color: var(--fg); font-size: 15px;
  padding: 10px 6px; cursor: pointer;
}
.library a { color: var(--section); display: block; padding: 10px 6px; }
.tag { background: #c62828; color: #fff; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 6px; margin-left: 6px; }
.btn.mini { min-width: 32px; padding: 4px 8px; font-size: 14px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); margin: 6px 0; }
#setup { max-width: 480px; margin: 0 auto; padding: 24px 16px; }
#setup h3 { color: var(--muted); font-size: 14px; text-transform: uppercase; margin-top: 24px; }
#setup .btn.big { width: 100%; margin-top: 10px; }
.hint { color: var(--muted); font-size: 13px; }
.overlay .field { max-width: 260px; text-align: center; font-size: 22px; margin: 8px auto 14px; display: block; }
.overlay a { color: var(--section); }
/* song editor */
#editor { padding: 10px; }
.editbox {
  width: 100%; max-width: 900px; height: 100%; display: flex; flex-direction: column; gap: 6px;
  text-align: left; background: var(--bar); border: 1px solid var(--line); border-radius: 12px; padding: 12px;
}
.editbox h3 { margin: 0; }
.editbox .row { display: flex; gap: 8px; justify-content: flex-end; }
#editor .field { max-width: none; text-align: left; font-size: 16px; margin: 0; }
#edText {
  flex: 1; min-height: 0; resize: none; white-space: pre; overflow: auto;
  font-family: ui-monospace, Menlo, monospace; font-size: 16px; line-height: 1.35; /* 16px: no iOS zoom */
}
.editbox .hint { margin: 0; max-width: none; }
#toast.info { background: #2e7d32; }
.btn.danger { background: #7f1d1d; border-color: #b91c1c; }
a.btn { text-decoration: none; display: inline-block; }
#myBands li { padding-right: 4px; }
.btn.blocked { border-color: #f9a825; animation: pulse 1s infinite; }
@keyframes pulse { 50% { background: #5a4300; } }
.btn.trval { min-width: 84px; font-weight: 700; }
#followBtn {
  /* slim, flat pill so it hides as little of the sheet as possible */
  display: none; position: fixed; left: 50%; bottom: 6px; transform: translateX(-50%); z-index: 12;
  font-size: 12px; line-height: 1; padding: 5px 12px; min-height: 0; border-radius: 999px;
  box-shadow: none; opacity: .75; font-weight: 600;
}
body.previewing #followBtn { display: none !important; }
body[data-role="admin"] #followBtn { bottom: 72px; }
