:root {
  --bg: #0f0d12; --panel: #1a1620; --panel2: #231d2b; --line: #332a3d;
  --text: #ece6f2; --muted: #9a8fa8; --accent: #d9577a; --accent2: #f08aa6;
  --warn: #f2b34a; --danger: #e0475b; --ok: #5cc28a;
  --r: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #2a1630 0%, transparent 60%), var(--bg);
  color: var(--text); min-height: 100vh;
  font: 15px/1.55 system-ui, -apple-system, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  padding: 0 16px 40px;
}
a { color: var(--accent2); }
[hidden] { display: none !important; }

.top { display: flex; justify-content: space-between; align-items: center; max-width: 1100px; margin: 0 auto; padding: 16px 0; }
.brand { font-weight: 700; font-size: 20px; letter-spacing: .5px; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.online { color: var(--muted); font-size: 13px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; }
.narrow { max-width: 520px; margin: 24px auto; }
.center { text-align: center; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 19px; margin: 0 0 16px; }
h3 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 16px 0 0; }
.rules { padding-left: 20px; color: #d4cadf; }
.rules li { margin: 6px 0; }

button, .btn {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-block;
  transition: background .15s, border-color .15s, transform .05s;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent2); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.warn { border-color: var(--warn); color: var(--warn); }
button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
button.big { width: 100%; padding: 14px; font-size: 17px; }
.ghost { background: transparent; }
.small-btn { padding: 4px 10px; font-size: 12px; }

input[type=text], input:not([type]), input[maxlength] {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; min-width: 0;
}
input:focus { outline: none; border-color: var(--accent); }
label { display: block; margin: 0 0 14px; }
label > input:not([type=checkbox]):not([type=radio]):not([type=range]) { display: block; width: 100%; margin-top: 6px; }
.check, .radio { display: flex; gap: 8px; align-items: center; }
.check.small { margin: 0; font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row input { flex: 1; }
.field { margin-bottom: 16px; }
.label { display: block; margin-bottom: 6px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { padding: 5px 12px; border-radius: 999px; font-size: 13px; }
.actions { display: grid; gap: 12px; margin-top: 8px; }

.pulse { width: 64px; height: 64px; margin: 8px auto 20px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(.8); opacity: .5 } 50% { transform: scale(1); opacity: 1 } }

.call-grid { max-width: 1100px; margin: 0 auto; display: grid; gap: 14px; grid-template-columns: 1fr 1.1fr; }
.call-grid .chat { grid-column: 1 / -1; }
@media (max-width: 760px) { .call-grid { grid-template-columns: 1fr; } }

.room-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.room-code { font-size: 22px; font-weight: 700; letter-spacing: 3px; }
.peers { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; }
.peers li { display: flex; align-items: center; gap: 10px; background: var(--panel2); padding: 10px 12px; border-radius: 10px; }
.pinfo { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.nm { font-weight: 600; }
.lvl { --l: 0; width: 14px; height: 14px; border-radius: 50%; flex: none;
  background: var(--ok); opacity: calc(.25 + var(--l) * .75); box-shadow: 0 0 calc(var(--l) * 14px) var(--ok); }
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.controls button { flex: 1; }

.cmd-display { text-align: center; padding: 16px 10px 14px; border-radius: 12px; background: var(--bg); margin-bottom: 12px; border: 1px solid var(--line); }
.cmd-text { font-size: 28px; font-weight: 800; line-height: 1.25; min-height: 36px; }
.cmd-meta { display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; font-variant-numeric: tabular-nums; }
.cmd-meta .beat { width: 14px; height: 14px; }
.cmd-meta .timer { margin-left: 0; font-size: 15px; }
.speed-pips { display: inline-flex; gap: 3px; }
.speed-pips i { width: 14px; height: 6px; border-radius: 3px; background: var(--line); }
.speed-pips i.on { background: var(--accent2); }
.cmd-level { margin-top: 10px; font-size: 13px; font-weight: 700; }
.cmd-level[data-lv="3"] { color: var(--warn); animation: pulse 1s ease-in-out infinite; }

/* role-based controls: the lead commands, the follower reports. "any" sees both. */
body.role-lead .follower-ctl, body.role-follow .lead-ctl { display: none !important; }
body.role-follow .level-meter { display: none; }

.decide { display: grid; gap: 8px; padding: 12px; border-radius: 12px; border: 1px solid var(--accent2); background: rgba(240, 138, 166, .08); margin-bottom: 12px; }
.decide .row button { flex: 1; }
.decide-wait { text-align: center; color: var(--accent2); font-weight: 700; margin-bottom: 12px; }

.level-pick { display: grid; gap: 6px; margin-bottom: 12px; }
.level-pick .seg button { flex: 1; }
.level-meter { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.lv-bar { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.lv-bar i { height: 6px; border-radius: 3px; background: var(--line); }
.lv-bar[data-lv="1"] i:nth-child(-n+1), .lv-bar[data-lv="2"] i:nth-child(-n+2) { background: linear-gradient(90deg, var(--accent2), #b6a3f5); }
.lv-bar[data-lv="3"] i { background: var(--warn); }

.speed-seg { display: grid; gap: 6px; margin-bottom: 12px; }
.seg5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.seg5 button { padding: 8px 0; }
.cmd-display[data-state=stop] { color: var(--danger); }
.cmd-display[data-state=edge] { color: var(--warn); }
.cmd-display[data-state=release] { color: var(--ok); }
.cmd-display.flash { animation: flash .5s; }
@keyframes flash { from { background: var(--accent); } to { background: var(--bg); } }
.beat-row { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.beat { width: 22px; height: 22px; border-radius: 50%; background: var(--line); }
.beat.on { animation: beat .25s; }
@keyframes beat { from { background: var(--accent2); transform: scale(1.3); } to { background: var(--line); transform: scale(1); } }
.timer { margin-left: auto; font-size: 22px; font-variant-numeric: tabular-nums; color: var(--warn); }
.cmds { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; margin-bottom: 12px; }
.slider { display: flex; align-items: center; gap: 10px; }
.slider input { flex: 1; accent-color: var(--accent); }

.chat ul { list-style: none; margin: 0 0 10px; padding: 0; max-height: 220px; overflow-y: auto; }
.chat li { padding: 3px 0; word-break: break-word; }
.chat li.mine b { color: var(--accent2); }
.chat li.sys { color: var(--muted); font-size: 13px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; width: min(380px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 10; max-width: calc(100vw - 32px); }

.doc { max-width: 760px; margin: 24px auto; }
.doc h2 { margin-top: 28px; }

/* nickname */
.nick-row { flex-wrap: nowrap; }
.nick-row button { flex: none; font-size: 18px; padding: 6px 12px; }
.nick-auto { margin-top: 8px; color: var(--muted); }

/* lobby extras */
.row.two > button { flex: 1; }

/* spectate */
.spectate-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.spectate-bar .check { margin: 0; }
.badge { background: var(--accent); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.viewers { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 6px; }
.spectator-only { display: none !important; }
body.spectator .spectator-only { display: flex !important; }
body.spectator .member-only,
body.spectator .cmds,
body.spectator .slider,
body.spectator [data-timer],
body.spectator #muteBtn,
body.spectator #nextBtn,
body.spectator .peers .small-btn { display: none !important; }
.game { position: relative; overflow: hidden; }
.react-layer { position: absolute; inset: 0; pointer-events: none; }
.react-layer span { position: absolute; bottom: 10px; font-size: 26px; animation: floatUp 2.2s ease-out forwards; }
@keyframes floatUp { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-260px); opacity: 0; } }
.reacts { gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.reacts button { font-size: 20px; padding: 6px 10px; }
.cmds .near { border-color: var(--warn); }
.cmd-display[data-state=near] { color: var(--warn); }

.room-list, .rec-list { list-style: none; padding: 0; margin: 12px 0 16px; display: grid; gap: 8px; }
.room-list li, .rec-list li { background: var(--panel2); border-radius: 10px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.room-list .grow, .rec-list .grow { flex: 1; min-width: 0; }
.room-list .names { font-weight: 600; overflow-wrap: anywhere; }
.empty { color: var(--muted); text-align: center; padding: 20px 0; }

/* records */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; }
.stat { background: var(--panel2); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; }
.stat span { color: var(--muted); font-size: 12px; }
.rec-list li { flex-direction: column; align-items: stretch; gap: 2px; }
.rec-list li.clickable { cursor: pointer; }
.rec-list li.clickable:hover { outline: 1px solid var(--accent); }
.rec-head { display: flex; justify-content: space-between; gap: 8px; }
.rec-outcome { font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); margin-left: 6px; }

/* lost button (in call) */
.lost-btn { width: 100%; margin-bottom: 12px; background: transparent; border-color: var(--danger); color: var(--danger); }
.lost-btn:disabled { opacity: .6; }
.cmd-display[data-state=lost] { color: var(--danger); }

/* result screen */
.res-status { display: flex; align-items: center; gap: 8px; color: var(--muted); margin-bottom: 12px; }
.res-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.res-dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.res-dot.busy { background: var(--warn); }
.res-dot.invite { background: var(--accent2); box-shadow: 0 0 10px var(--accent2); }
.res-status.invite { color: var(--accent2); font-weight: 700; }
.res-actions { display: grid; gap: 8px; }
.curve { margin: 20px 0 4px; }
.curve svg { display: block; width: 100%; height: auto; overflow: visible; }
.curve .edge-line { stroke: var(--muted); stroke-dasharray: 6 6; stroke-width: 1; opacity: .6; }
.curve .line { fill: none; stroke: url(#curveGrad); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.curve .g0 { stop-color: var(--accent2); }
.curve .g1 { stop-color: #b6a3f5; }
.curve .end-mark { font-size: 18px; }
.curve .tick { fill: var(--line); }
.curve .tick.e, .curve .tick.n { fill: var(--warn); }
.curve .tick.x { fill: #6fd3c4; }
.curve .tick.l { fill: var(--danger); }
.curve .tick.r { fill: var(--ok); }
.curve-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; margin-bottom: 20px; }
.res-kicker { color: var(--accent2); letter-spacing: 4px; font-size: 13px; font-weight: 600; }
.res-title { font-size: 34px; font-weight: 800; margin: 4px 0 8px; }
.res-sub { color: #d4cadf; margin: 0 0 8px; }
.res-hl { color: var(--accent2); font-weight: 700; margin: 0 0 16px; min-height: 1em; }
.res-outcome { display: grid; gap: 6px; margin-bottom: 20px; }
.res-note { display: grid; gap: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 20px; }
.note-lines { display: grid; gap: 4px; font-weight: 600; }
.note-lines:empty { display: none; }
.note-lines .mine { color: var(--accent2); }

/* target duration (in call) */
.target-row { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; flex-wrap: wrap; }
.target-pick { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; }
.target-pick select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }
.target-bar { flex: 1; min-width: 80px; height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.target-bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent2), #b6a3f5); transition: width .5s linear; }
.target-bar.done span { background: var(--ok); }
.stamp { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.stamp b { font-size: 17px; }
.dots { display: flex; gap: 6px; flex-wrap: wrap; }
.dots span { width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line); }
.dots span.on { background: linear-gradient(135deg, var(--accent2), #b6a3f5); border-color: transparent; }
.res-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.res-stats .stat { text-align: center; }
.res-stats .stat b { font-size: 24px; font-variant-numeric: tabular-nums; }
.res-stats .delta { display: block; font-size: 12px; margin-top: 2px; }
.res-stats .delta.up { color: var(--accent2); }
.res-stats .delta.same { color: var(--muted); }
.res-stats .delta.down { color: #9fb7d9; }

/* connection quality */
.net { font-size: 12px; display: inline-flex; align-items: center; gap: 5px; }
.net:empty { display: none; }
.net::before, .latency::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.net.good::before, .latency.good::before { background: var(--ok); }
.net.fair::before, .latency.fair::before { background: var(--warn); }
.net.poor::before, .latency.poor::before { background: var(--danger); }
.net.poor { color: var(--danger); }
.latency { font-size: 12px; font-weight: 400; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; margin-left: 6px; }
.latency:empty { display: none; }
