@font-face {
  font-family: "Atkinson Hyperlegible";
  font-weight: 400;
  font-display: swap;
  src: url("fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-weight: 700;
  font-display: swap;
  src: url("fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-weight: 400;
  font-display: swap;
  src: url("fonts/atkinson-hyperlegible-latin-ext-400-normal.woff2") format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-weight: 700;
  font-display: swap;
  src: url("fonts/atkinson-hyperlegible-latin-ext-700-normal.woff2") format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* Bar: a deep mulberry, like a choir folder. Paper stays pure white. */
  --bar: #3f1d2b;
  --bar-ink: #fbf4f6;
  --bar-muted: #d9c3cc;
  --bar-hover: rgba(255, 255, 255, 0.12);

  /* Mode colours: the one bold thing, readable across a room. */
  --solo: #bfaeb6;
  --leader: #e8b440;
  --follower: #6fd0bf;

  --surface: #ffffff;
  --ink: #26151d;
  --muted: #6f5b64;
  --rule: #eadfe3;
  --raised: #f7f1f3;
  --primary: #3f1d2b;
  --primary-ink: #ffffff;
  --danger: #a3243b;
  --focus: #2f6fdb;

  --font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface: #23161c;
    --ink: #f6eef1;
    --muted: #bba7b0;
    --rule: #3d2b33;
    --raised: #2e1f26;
    --primary: #e8b440;
    --primary-ink: #26151d;
    --danger: #ff7a8c;
    --focus: #8ab4ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #ffffff;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------------------------------------------------------------- viewer */

#viewer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #ffffff;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#viewer canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
}

#songsView {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  background: var(--surface);
  color: var(--ink);
}
#songsView[hidden] { display: none; }
#songsView .songs .item { min-height: 56px; }
#songsView .songs .title { font-size: 1.25rem; }
#songsView .songs li.current { background: var(--raised); }

#emptyHint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 6rem 1.5rem 2rem;
  text-align: center;
  color: #6f5b64;
  max-width: 34rem;
  margin: 0 auto;
}
#emptyHint p { margin: 0 0 0.75rem; }
#emptyHint p:first-child { font-size: 1.375rem; font-weight: 700; color: #26151d; }
#emptyHint[hidden] { display: none; }
@media (hover: none) { .desktop-only { display: none; } }

/* ---------------------------------------------------------------- bar */

#bar {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 2;
  background: var(--bar);
  background: color-mix(in srgb, var(--bar) 94%, transparent);
  color: var(--bar-ink);
  padding: calc(env(safe-area-inset-top, 0px) + 0.375rem) calc(env(safe-area-inset-right, 0px) + 0.5rem) 0.375rem calc(env(safe-area-inset-left, 0px) + 0.5rem);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}
#bar[hidden] { display: none; }

.bar-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}

#bar button {
  min-height: 44px;
  padding: 0 0.875rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--bar-ink);
  font-weight: 700;
  cursor: pointer;
}
#bar button:hover { background: var(--bar-hover); }
#bar button:disabled { opacity: 0.45; cursor: default; }

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: inset 0 0 0 2px var(--mode-colour, var(--solo));
}
.mode-pill[data-mode="solo"] { --mode-colour: var(--solo); }
.mode-pill[data-mode="leader"] { --mode-colour: var(--leader); }
.mode-pill[data-mode="follower"] { --mode-colour: var(--follower); }
.mode-pill .dot {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--mode-colour);
}
.mode-pill[data-live="true"] .dot { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .mode-pill .dot { animation: none !important; } }

#bar .icon-btn { width: 44px; padding: 0; display: inline-grid; place-items: center; }
#bar .icon-btn[hidden] { display: none; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn .fs-exit, .icon-btn[data-on="true"] .fs-enter { display: none; }
.icon-btn[data-on="true"] .fs-exit { display: block; }

#pageLabel {
  margin-left: auto;
  padding: 0 0.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#status .doc { color: var(--bar-ink); font-weight: 700; margin-right: 0.75rem; }
h2:focus { outline: none; }

#status {
  margin: 0.125rem 0.875rem 0.25rem;
  font-size: 0.875rem;
  color: var(--bar-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.options { gap: 1rem; padding: 0 0.875rem 0.125rem; font-size: 0.875rem; color: var(--bar-muted); }
.options label { display: inline-flex; align-items: center; gap: 0.4rem; min-height: 36px; cursor: pointer; }
.options input { width: 1.1rem; height: 1.1rem; accent-color: var(--leader); }

/* ---------------------------------------------------------------- dialogs */

dialog {
  width: min(32rem, calc(100vw - 1.5rem));
  max-height: min(42rem, calc(100dvh - 2rem));
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 64px rgba(30, 10, 20, 0.35);
  display: none;
  flex-direction: column;
}
dialog[open] { display: flex; }
dialog::backdrop { background: rgba(38, 21, 29, 0.55); }

.dialog-head { padding: 1.25rem 1.25rem 0.75rem; border-bottom: 1px solid var(--rule); }
.dialog-head h2 { margin: 0; font-size: 1.375rem; line-height: 1.2; }
.dialog-head input[type="search"] {
  width: 100%;
  margin-top: 0.75rem;
  min-height: 44px;
  padding: 0 0.875rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--raised);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--rule);
}
dialog button {
  min-height: 44px;
  padding: 0 1.1rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
}
dialog button:hover { background: var(--raised); }
button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
button.primary:hover { background: var(--primary); filter: brightness(1.12); }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
#emptyHint button.primary {
  min-height: 48px; padding: 0 1.5rem; border: 0; border-radius: 8px;
  background: #3f1d2b; color: #fff; font-weight: 700; cursor: pointer; margin-top: 0.5rem;
}

.list { list-style: none; margin: 0; padding: 0.25rem 0; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.list li { display: flex; align-items: center; border-bottom: 1px solid var(--rule); }
.list li:last-child { border-bottom: 0; }
.list .item {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 0.875rem;
  min-height: 56px;
  padding: 0.625rem 1.25rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: left;
  font-weight: 400;
}
.list .item:hover { background: var(--raised); }
.list .name { display: block; font-size: 1.0625rem; font-weight: 700; overflow-wrap: anywhere; }
.list .detail { display: block; font-size: 0.875rem; color: var(--muted); }
.list .remove {
  flex: none;
  width: 48px;
  min-height: 48px;
  margin-right: 0.5rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
}
.list .remove:hover { color: var(--danger); background: var(--raised); }
.list .remove svg { width: 22px; height: 22px; }

.songs .item { min-height: 48px; }
.songs .num { flex: none; min-width: 2.5rem; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.songs .title { font-size: 1.0625rem; }
.songs li.current .title { font-weight: 700; }
.songs li.current .num { color: var(--ink); font-weight: 700; }

.empty { margin: 0; padding: 1.5rem 1.25rem; color: var(--muted); text-align: center; }
.empty[hidden] { display: none; }

.dialog-form { display: flex; flex-direction: column; min-height: 0; }
.note { margin: 0; padding: 0.75rem 1.25rem; background: var(--raised); color: var(--muted); font-size: 0.9375rem; }
.note[hidden] { display: none; }

.confirm-text { margin: 0; padding: 1rem 1.25rem 1.25rem; }

.form { padding: 1rem 1.25rem; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem; }
.modes { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.375rem; }
.modes legend { font-weight: 700; margin-bottom: 0.375rem; padding: 0; }
.modes label {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  cursor: pointer;
}
.modes label:has(input:checked) { border-color: var(--ink); background: var(--raised); }
.modes input { margin-top: 0.2rem; width: 1.1rem; height: 1.1rem; accent-color: var(--primary); }
.modes strong { display: block; }
.modes span { color: var(--muted); }
.modes strong { color: var(--ink); }

.field { display: flex; flex-direction: column; gap: 0.375rem; font-weight: 700; }
.field input {
  min-height: 44px;
  padding: 0 0.875rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--raised);
  font-weight: 400;
}
.field small { font-weight: 400; color: var(--muted); }
.conn { margin: 0; color: var(--muted); font-size: 0.9375rem; }
#inviteBtn { align-self: flex-start; }

/* ---------------------------------------------------------------- toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1.5rem);
  z-index: 10;
  max-width: calc(100vw - 2rem);
  padding: 0.75rem 1.125rem;
  border-radius: 10px;
  background: #26151d;
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, 1rem);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
