:root {
  --bg: #12141a;
  --panel: #1b1f29;
  --panel-2: #232836;
  --line: #2f3547;
  --text: #e8eaf0;
  --muted: #98a0b5;
  --accent: #ffb84d;
  --accent-soft: rgba(255, 184, 77, 0.28);
  --done: #7f89a3;
  --good: #5bd48b;
  --bad: #ff6b6b;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 0.6rem; font-weight: 600; }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 0.5rem 0 0; }
.spacer { flex: 1; }

input, select, button { font: inherit; color: inherit; }
input[type="text"], input[type="password"], input:not([type]), input[type="number"], select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 0.55rem 0.7rem;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { display: block; font-size: 0.85rem; color: var(--muted); }
label > input, label > select { margin-top: 0.25rem; color: var(--text); font-size: 1rem; }
label.check { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.6rem; color: var(--text); font-size: 0.9rem; }
label.check input { width: auto; margin: 0; }

button { cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); padding: 0.55rem 0.9rem; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); color: #1a1405; border-color: var(--accent); font-weight: 700; }
button.ghost { background: transparent; }
button.wide { width: 100%; margin-top: 0.8rem; }
button.sq { width: 2.4rem; padding: 0.4rem 0; font-size: 1.1rem; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.pill { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 0.15rem 0.7rem; font-size: 0.8rem; color: var(--accent); }

/* ---- login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(380px, 100%); display: grid; gap: 0.9rem; padding: 1.6rem; }
.login-card h1 { font-size: 1.7rem; }
.login-card p { margin: 0; }

/* ---- lobby layout ---- */
.topbar { display: flex; gap: 0.8rem; align-items: center; padding: 0.7rem 1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 5; }
.topbar h1 { font-size: 1.15rem; }
.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr) 280px; gap: 1rem; padding: 1rem; max-width: 1400px; margin: 0 auto; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.side section + section { margin-top: 1.4rem; }
.chordpanel { position: sticky; top: 4.2rem; }

details > summary { list-style: none; cursor: pointer; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; margin-bottom: 0.6rem; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: " ▾"; }
details:not([open]) > summary::after { content: " ▸"; }
.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.people li { display: flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0.5rem; border-radius: 8px; background: var(--panel-2); font-size: 0.92rem; }
.people .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 0.7rem; padding: 0.05rem 0.45rem; border-radius: 999px; background: var(--accent); color: #1a1405; font-weight: 700; }
.badge.you { background: var(--panel); color: var(--muted); border: 1px solid var(--line); }

/* ---- controls ---- */
.controls { display: grid; gap: 0.8rem; margin-bottom: 1rem; }
.row { display: flex; gap: 0.8rem; align-items: end; flex-wrap: wrap; }
.grow { flex: 1; min-width: 200px; }
.tempo-row { display: flex; gap: 0.4rem; align-items: center; margin-top: 0.25rem; }
.tempo-row input { width: 5rem; text-align: center; margin: 0; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.status { margin: 0; min-height: 1.5em; color: var(--muted); font-size: 0.92rem; }
.status.live { color: var(--good); }
.transport { align-items: center; }
body:not(.is-host) .host-only { display: none; }
body:not(.is-host) #song-select, body:not(.is-host) #bpm-num, body:not(.is-host) #bpm-range,
body:not(.is-host) #bpm-up, body:not(.is-host) #bpm-down { pointer-events: none; opacity: 0.7; }

/* ---- song ---- */
.song { padding: 0.5rem 0 40vh; }
.sec-label { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin: 1.6rem 0 0.5rem; }
.line { display: flex; flex-wrap: wrap; align-items: flex-end; padding: 0.15rem 0.4rem; border-radius: 10px; margin-bottom: 0.35rem; border: 1px solid transparent; transition: background 0.2s; }
.line.plain { padding-top: 0.6rem; }
.line.active { background: var(--panel); border-color: var(--line); }
.seg { position: relative; display: inline-flex; flex-direction: column; justify-content: flex-end; padding-right: 0.15rem; border-radius: 6px; }
.seg .lyr { white-space: pre-wrap; font-size: 1.15rem; padding: 0.1rem 0.15rem; }
.line.plain .lyr { font-size: 1.15rem; }
.chord { display: flex; flex-direction: column; align-items: flex-start; background: none; border: none; padding: 0 0.15rem; color: var(--accent); text-align: left; min-width: 2ch; line-height: 1.15; }
.chord.empty { cursor: default; }
.chord .cname { font-weight: 800; font-size: 1.1rem; }
.chord .cnotes { font-size: 0.68rem; color: var(--muted); font-weight: 500; letter-spacing: 0.02em; white-space: nowrap; }
body.hide-notes .chord .cnotes { display: none; }
.instrumental .seg { margin-right: 0.9rem; }
.repeat { align-self: center; color: var(--muted); font-size: 0.85rem; margin-left: 0.3rem; }
.note { margin: 0.8rem 0; padding: 0.5rem 0.8rem; border-left: 3px solid var(--accent); background: var(--panel); border-radius: 0 8px 8px 0; color: var(--muted); font-style: italic; font-size: 0.92rem; }

/* playhead: the active chord's span fills left to right, with a vertical line riding its leading edge */
.seg.done .lyr, .seg.done .cname { color: var(--done); }
.seg.active { --p: 0%; background: linear-gradient(90deg, var(--accent-soft) var(--p), transparent var(--p)); }
.seg.active::after { content: ""; position: absolute; top: -2px; bottom: -2px; left: var(--p); width: 3px; margin-left: -1.5px; background: var(--accent); border-radius: 2px; box-shadow: 0 0 10px var(--accent); }
.seg.active .cname { color: #fff; }

/* ---- chord panel ---- */
.chord-card { display: grid; justify-items: center; gap: 0.2rem; }
.chord-big { font-size: 2.6rem; font-weight: 800; color: var(--accent); line-height: 1.1; }
.chord-notes { font-size: 1.05rem; letter-spacing: 0.08em; margin-bottom: 0.3rem; }
.chord-empty { color: var(--muted); padding: 1rem 0; text-align: center; }
.diagram { width: 100%; max-width: 230px; height: auto; }
.diagram .fret { stroke: var(--line); stroke-width: 1.5; }
.diagram .string { stroke: var(--muted); stroke-width: 1.5; }
.diagram .nut { fill: var(--text); }
.diagram .dot { fill: var(--accent); }
.diagram .dot-label { fill: #1a1405; font-size: 11px; font-weight: 700; }
.diagram .open { fill: none; stroke: var(--text); stroke-width: 1.5; }
.diagram .mark { fill: var(--muted); font-size: 16px; }
.diagram .basefret { fill: var(--muted); font-size: 12px; }
.diagram .string-note { fill: var(--text); font-size: 12px; font-weight: 600; }
.diagram .string-name { fill: var(--muted); font-size: 10px; }
.next-card { margin-top: 1rem; padding-top: 0.8rem; border-top: 1px solid var(--line); font-size: 0.9rem; color: var(--muted); display: flex; gap: 0.5rem; align-items: baseline; }
.next-card strong { color: var(--text); font-size: 1.2rem; }

/* ---- responsive ---- */
@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr) 260px; }
  .side { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
  .side section + section { margin-top: 0; }
}
@media (max-width: 680px) {
  .layout { grid-template-columns: 1fr; padding: 0.6rem; }
  .side { grid-template-columns: 1fr; }
  .chordpanel { position: sticky; top: 3.4rem; order: -1; z-index: 4; padding: 0.4rem 0.8rem; box-shadow: 0 6px 14px rgba(0, 0, 0, 0.45); }
  .chordpanel h2 { display: none; }
  /* name + notes on the left, diagram on the right, "Next" under the name */
  .chord-card { grid-template-columns: 1fr auto; justify-items: start; align-items: center; column-gap: 0.8rem; }
  .chord-big { grid-column: 1; font-size: 2rem; }
  .chord-notes { grid-column: 1; margin: 0; }
  .chord-card .diagram { grid-column: 2; grid-row: 1 / span 3; max-width: 105px; }
  .chord-card .chord-empty { grid-column: 1 / -1; padding: 0.3rem 0; }
  .next-card { margin-top: 0; padding-top: 0; border-top: none; }
  .seg .lyr { font-size: 1.02rem; }
}
