:root {
  --bg: #0b0c0e;
  --surface: #15171b;
  --surface-2: #1e2127;
  --line: #2b2f37;
  --text: #f6f3ec;
  --muted: #a3a3ab;
  --accent: #ffc53d;
  --on-accent: #141007;
  --next: #5eb4ff;
  --danger: #ff8a7a;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

h1, h2, p { margin: 0; }
h2 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.primary {
  width: 100%;
  padding: 14px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 800;
  font-size: 17px;
}
.primary.on { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 2px var(--accent); }
.primary.big { padding: 18px 22px; font-size: 19px; }

.ghost {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  font-weight: 600;
}
.ghost:hover { background: var(--surface-2); }
.small-btn { padding: 8px 12px; font-size: 14px; width: auto; }
.danger { color: var(--danger); }
.muted { color: var(--muted); font-size: 14px; line-height: 1.4; }
.error { color: var(--danger); font-size: 14px; line-height: 1.4; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }

/* Home */
.home { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.home-inner { width: min(460px, 100%); display: grid; gap: 22px; }
.home h1 { font-size: clamp(44px, 12vw, 64px); line-height: 1; letter-spacing: -.02em; font-weight: 900; }
.lede { font-size: 20px; line-height: 1.4; color: var(--muted); }
.resume { color: var(--accent); font-weight: 700; text-align: center; }
.join { display: grid; gap: 8px; color: var(--muted); }
.join-row { display: flex; gap: 8px; }
.join-row input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  text-transform: uppercase;
  letter-spacing: .1em;
}

/* Room */
.room { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
}
.song-title { flex: 1; min-width: 0; font-size: 20px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { flex: none; padding: 6px 12px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 15px; white-space: nowrap; }
.pill b { color: var(--text); font-weight: 800; }
.status { flex: none; color: var(--muted); font-size: 14px; white-space: nowrap; }
.status.bad { color: var(--danger); }
.status.good::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 50%;
  background: #4ade80;
}

.body { flex: 1; min-height: 0; display: flex; }
.stage { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }

.now {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  border-right: 1px solid var(--line);
}
.chord {
  max-width: 100%;
  color: var(--accent);
  font-size: clamp(96px, min(19vw, 42vh), 340px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -.03em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chord[data-size="m"] { font-size: clamp(76px, min(14vw, 32vh), 240px); }
.chord[data-size="s"] { font-size: clamp(58px, min(10vw, 24vh), 170px); }
.chord.off { color: var(--text); }
.chord.idle { color: var(--line); }

.next-row { display: flex; align-items: baseline; gap: 12px; color: var(--muted); font-size: clamp(20px, 3vw, 32px); }
.next-row b { color: var(--next); font-size: clamp(34px, 5vw, 60px); font-weight: 800; }

.sheet { min-width: 0; overflow-y: auto; padding: 20px 20px 40vh; scroll-behavior: smooth; overscroll-behavior: contain; }
.chart { display: grid; gap: 22px; }
.section { display: grid; gap: 10px; }
.line { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.cell {
  min-width: 2.6em;
  padding: .3em .55em;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: clamp(26px, 3.4vw, 46px);
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  transition: background .08s linear, color .08s linear;
}
button.cell:hover { background: var(--surface-2); }
.cell.next { border-color: var(--next); }
.cell.on { background: var(--accent); color: var(--on-accent); }
.repeat { color: var(--muted); font-size: 22px; font-weight: 700; }

.live-panel { display: grid; gap: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; min-height: 44px; }
.chips .cell { min-width: 2.2em; }
.chips.small .cell { font-size: clamp(20px, 2.4vw, 28px); background: transparent; border-color: var(--line); }
.chips.small .cell:last-child { border-color: var(--accent); }
.empty-note { color: var(--muted); font-size: 16px; line-height: 1.4; }

/* Leader panel */
.panel {
  flex: none;
  width: 340px;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--surface);
  overscroll-behavior: contain;
}
.group { display: grid; gap: 12px; padding: 16px; border-bottom: 1px solid var(--line); }
.field { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
.field select, .field input, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 16px;
  color: var(--text);
}
.field textarea { font-family: ui-monospace, Menlo, Consolas, monospace; line-height: 1.5; resize: vertical; }
.check { display: flex; gap: 10px; align-items: center; font-size: 15px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.tip { font-size: 13px; }

.meter { height: 8px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); }

.share { grid-template-columns: 1fr; }
.qr { width: 160px; padding: 8px; border-radius: 10px; background: #fff; line-height: 0; }
.qr svg { width: 100%; height: auto; display: block; }
.share-text { display: grid; gap: 8px; font-size: 14px; line-height: 1.4; color: var(--muted); justify-items: start; }
.band-link { color: var(--accent); font-weight: 700; word-break: break-all; }

.songs { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.songs li { display: flex; gap: 6px; }
.song-pick {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.song-pick.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.stepper { display: inline-flex; align-items: center; gap: 10px; }
.stepper b { min-width: 2ch; text-align: center; }

.editor {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}
.editor::backdrop { background: rgba(0, 0, 0, .7); }
.editor form { display: grid; gap: 14px; }

/* Phones and narrow screens: chord on top, chart scrolls underneath */
@media (max-width: 860px), (max-aspect-ratio: 1/1) {
  .stage { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .now {
    flex-direction: row;
    gap: 22px;
    padding: 14px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .chord { font-size: clamp(76px, 26vw, 150px); }
  .chord[data-size="m"] { font-size: clamp(58px, 19vw, 110px); }
  .chord[data-size="s"] { font-size: clamp(42px, 14vw, 84px); }
  .next-row { flex-direction: column; align-items: center; gap: 0; font-size: 15px; }
  .next-row b { font-size: clamp(30px, 9vw, 48px); }
  .sheet { padding: 16px 16px 40vh; }
  .cell { font-size: clamp(22px, 7vw, 34px); }
  .bar { gap: 8px; padding-left: 16px; padding-right: 16px; }
  .song-title { font-size: 17px; }
  .pill { font-size: 13px; padding: 5px 10px; }
  .status { font-size: 12px; }
}

/* Leader panel slides over the stage when there is no room beside it */
@media (max-width: 1100px) {
  .panel {
    position: fixed;
    z-index: 5;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(360px, 100vw);
    box-shadow: -12px 0 40px rgba(0, 0, 0, .5);
  }
}
