:root {
    color-scheme: dark;
    --bg: #11151a;
    --surface: #1a2027;
    --surface-2: #212a33;
    --border: #28313b;
    --text: #e8edf2;
    --muted: #8da0b3;
    --dim: #5d6b7a;
    --accent: #ffd27a;
    --good: #8ee6a8;
    --bad: #ff8a8a;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    overscroll-behavior: none;
}

.wrap {
    max-width: 560px;
    margin: 0 auto;
    padding: 20px 16px 32px;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

h2 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 10px;
}

.tagline {
    color: var(--muted);
    font-size: 0.9rem;
    margin-top: 6px;
    line-height: 1.5;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    margin-top: 16px;
}

.hidden { display: none !important; }

/* ── buttons and inputs ─────────────────────────────────────────────────── */

button {
    font: inherit;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 12px;
    padding: 13px 18px;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
}

button:disabled { opacity: 0.45; cursor: default; }

button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #11151a;
    font-weight: 700;
}

button.danger {
    background: transparent;
    border-color: #7a2f33;
    color: var(--bad);
}

button.wide { width: 100%; }

input[type="text"], select {
    font: inherit;
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 13px 14px;
}

select { appearance: none; }

input::placeholder { color: var(--dim); }

.row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.row > input, .row > button { flex: 1; min-width: 0; }

label.field {
    display: block;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 6px;
}

.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--dim);
    font-size: 0.78rem;
    margin: 18px 0 2px;
}

.divider::before, .divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.note {
    font-size: 0.8rem;
    color: var(--dim);
    line-height: 1.5;
    margin-top: 10px;
}

.error {
    color: var(--bad);
    font-size: 0.85rem;
    margin-top: 10px;
}

/* ── room header ────────────────────────────────────────────────────────── */

.roomhead {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    color: var(--accent);
}

/* ── connection / sync pill ─────────────────────────────────────────────── */

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 10px;
    white-space: nowrap;
}

.pill .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--dim);
}

.pill.open .dot { background: var(--good); }
.pill.connecting .dot { background: var(--accent); animation: blink 1s ease-in-out infinite; }
.pill.closed .dot { background: var(--bad); }

@keyframes blink { 50% { opacity: 0.25; } }

/* ── share link ─────────────────────────────────────────────────────────── */

/* A real anchor, so a long-press always offers the browser's own "Copy link"
   however badly the clipboard APIs are behaving. */
.share {
    display: block;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.8rem;
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 12px;
    overflow-wrap: anywhere;
    user-select: all;
    text-decoration: none;
}

/* ── parts ──────────────────────────────────────────────────────────────── */

.parts {
    display: grid;
    gap: 10px;
}

.part {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    width: 100%;
    padding: 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
}

/* The claimed tint is painted as a layer rather than mixed into the background:
   colour-mix is not everywhere yet, and where it is missing the whole
   declaration is dropped, which left "mine" and "not mine" nearly identical. */
.part[data-status="mine"]::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--part-color);
    opacity: 0.22;
    pointer-events: none;
}

.part > * { position: relative; }

.part .swatch {
    width: 14px;
    height: 34px;
    border-radius: 4px;
    flex: none;
    background: var(--part-color, var(--dim));
}

.part .meta { flex: 1; min-width: 0; }
.part .name { font-weight: 600; }

.part .who {
    font-size: 0.82rem;
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Empty ring when it's going spare, filled badge when it's yours. */
.part .tick {
    flex: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border);
    color: var(--dim);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1;
}

/* ── the three part states ──────────────────────────────────────────────── */
/* Distinguished by outline style as well as colour — dashed / solid / ringed
   survives a glance across a dark room far better than a shade of grey does. */

/* Nobody has it: obviously an empty slot, obviously tappable. */
.part[data-status="free"] {
    border-style: dashed;
    border-color: #3d4a59;
    background: transparent;
}

.part[data-status="free"] .swatch { opacity: 0.3; }
.part[data-status="free"] .name { color: var(--muted); }
.part[data-status="free"] .who { color: var(--dim); }
.part[data-status="free"] .tick { border-style: dashed; }

/* Someone else has it: solid and settled, with their name in the part's colour
   so the person and the part are tied together. */
.part[data-status="taken"] .name { color: var(--text); }
.part[data-status="taken"] .who { color: var(--part-color); font-weight: 600; }

.part[data-status="taken"] .tick {
    border-color: transparent;
    background: #3d4a59;
    color: var(--text);
    font-size: 0.85rem;
}

/* Yours: the loudest thing on the screen. */
.part[data-status="mine"] {
    /* Inset so claiming does not nudge the row's height by a pixel. */
    box-shadow: inset 0 0 0 2px var(--part-color);
    border-color: transparent;
}

.part[data-status="mine"] .name { color: #fff; font-weight: 700; }
.part[data-status="mine"] .who { color: #fff; font-weight: 600; }

.part[data-status="mine"] .tick {
    border-color: var(--part-color);
    background: var(--part-color);
    color: #11151a;
}

/* ── roster ─────────────────────────────────────────────────────────────── */

.roster {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.member {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 12px;
}

.member.offline { opacity: 0.4; }
.member .crown { font-size: 0.75rem; }

.member .chips {
    display: inline-flex;
    gap: 3px;
}

.member .chip {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* ── the stage ──────────────────────────────────────────────────────────── */

#stage {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
    gap: 12px;
}

.stage-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.75rem;
    color: var(--muted);
}

.beats {
    display: flex;
    justify-content: center;
    gap: 14px;
    padding: 6px 0 2px;
}

.beat {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    transition: transform 90ms ease-out, background-color 90ms ease-out;
}

.beat.lit {
    background: var(--muted);
    border-color: var(--muted);
}

.beat.lit.downbeat {
    background: var(--accent);
    border-color: var(--accent);
}

.beat.hit { transform: scale(1.55); }

.lyrics {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    text-align: center;
    min-height: 0;
}

/* Several parts can land on the same beat, so a "line" is really a stack of
   them — one row per part, each in its own colour. With a single part claimed
   this collapses to exactly one row and the label is suppressed. */

#cue-block, #next-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.cue-part {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--part-color, var(--muted));
    margin-bottom: 2px;
}

.cue-part::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}

.cue-text {
    font-size: clamp(1.5rem, 7.5vw, 2.5rem);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

/* Sung already. The fade is the only thing distinguishing "you are singing this"
   from "you just sang this" when the words repeat. */
.cue-line { transition: opacity 220ms ease-out; }
.cue-line.done { opacity: 0.3; }

/* Your turn is over and something else is coming: pull the eye downward. */
#cue-block.spent { transform: scale(0.96); transition: transform 220ms ease-out; }
#cue-block { transition: transform 220ms ease-out; }

.next.up-next { border-top-color: var(--muted); }
.next.up-next .label { color: var(--accent); }
.next.up-next #next-block .cue-text { color: var(--text); }

#cue-block.enter { animation: cue-in 220ms ease-out; }

@keyframes cue-in {
    from { opacity: 0.25; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

.next {
    border-top: 1px solid var(--border);
    padding-top: 16px;
    width: 100%;
    color: var(--dim);
}

.next .label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--dim);
    margin-bottom: 6px;
}

#next-block { gap: 4px; }

#next-block .cue-text {
    font-size: clamp(1rem, 4.5vw, 1.3rem);
    font-weight: 500;
    color: var(--muted);
    line-height: 1.35;
}

#next-block .cue-part { font-size: 0.66rem; opacity: 0.8; }
#next-block .cue-part::before { width: 7px; height: 7px; }

.resting { color: var(--dim); font-style: italic; font-weight: 500; }

/* Stacked parts get a colour rule so the eye can tell them apart at a glance. */
#cue-block .cue-line + .cue-line,
#next-block .cue-line + .cue-line {
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

.progress {
    height: 3px;
    border-radius: 2px;
    background: var(--surface-2);
    overflow: hidden;
}

.progress > span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--muted);
}

.stage-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.nudge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
}

.nudge button {
    padding: 9px 14px;
    border-radius: 9px;
    font-variant-numeric: tabular-nums;
}

.nudge .value {
    min-width: 82px;
    text-align: center;
    font-size: 0.8rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.toggle-btn {
    padding: 10px 14px;
    font-size: 0.82rem;
    font-weight: 600;
}

.toggle-btn.on {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── count-in and flash overlays ────────────────────────────────────────── */

#countin {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--bg);
    z-index: 20;
}

#countin .num {
    font-size: clamp(6rem, 40vw, 14rem);
    font-weight: 800;
    line-height: 1;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

#countin .num.hit { animation: countin-pop 200ms ease-out; }

@keyframes countin-pop {
    from { transform: scale(1.35); opacity: 0.5; }
    to { transform: none; opacity: 1; }
}

#countin .hint {
    color: var(--muted);
    font-size: 0.95rem;
    text-align: center;
    padding: 0 24px;
    line-height: 1.5;
}

#flash {
    position: fixed;
    inset: 0;
    background: #fff;
    opacity: 0;
    pointer-events: none;
    z-index: 30;
}

/* ── small screens ──────────────────────────────────────────────────────── */

@media (max-height: 620px) {
    .lyrics { gap: 12px; }
    .next { padding-top: 10px; }
    .beats { padding: 2px 0; }
}
