:root {
  --bg: #0f0d14; --panel: #1a1722; --panel2: #231f2e; --line: #322c40;
  --text: #ece8f4; --muted: #9a93ab; --accent: #ff5c8a; --accent2: #8b6cff;
  --warn: #ffb547; --danger: #ff4d5e; --ok: #3ddc97;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans", "Noto Sans CJK SC", "Segoe UI", sans-serif; }
body { display: flex; flex-direction: column; min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: rgba(15,13,20,.9);
  position: sticky; top: 0; z-index: 5; backdrop-filter: blur(8px); }
.brand { font-weight: 700; font-size: 18px; letter-spacing: .5px; display: flex; align-items: center; gap: 8px; }
.brand small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 4px; }
.logo-dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 0 12px var(--accent); animation: beat 1s infinite; }
@keyframes beat { 0%,100% { transform: scale(1);} 15% { transform: scale(1.35);} }
.top-right { display: flex; gap: 10px; align-items: center; }
.online { font-size: 12px; color: var(--ok); }
select, input[type=number], input:not([type]), textarea {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent2); }

main { flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 720px; margin: 0 auto; min-height: 0; }
.view { padding: 20px 16px calc(24px + var(--safe-b)); display: flex; flex-direction: column; gap: 16px; }
h1 { font-size: 22px; margin: 4px 0; } h2, h3 { margin: 0; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.row { display: flex; align-items: center; } .gap { gap: 8px; } .wrap { flex-wrap: wrap; } .center { justify-content: center; }
.grow { flex: 1; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-size: 13px; color: var(--muted); }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin-top: 2px; flex: none; }

.btn { border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 9px 14px; cursor: pointer;
  white-space: nowrap; transition: transform .08s, background .15s; }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: none; color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border: none; color: #fff; font-weight: 600; }
.btn.warn { background: var(--warn); border: none; color: #231a05; font-weight: 700; }
.btn.big { padding: 14px; font-size: 17px; margin-top: 8px; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.icon { padding: 6px 10px; font-size: 18px; line-height: 1; }
.btn.toggle { display: flex; gap: 4px; align-items: center; font-size: 13px; padding: 8px 10px; opacity: .6; }
.btn.toggle.on { opacity: 1; border-color: var(--ok); color: var(--ok); }
.btn.floating { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); z-index: 30; }

.roles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.role-card { display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 12px; border-radius: var(--radius);
  background: var(--panel); border: 1.5px solid var(--line); cursor: pointer; }
.role-card small { color: var(--muted); font-size: 12px; line-height: 1.3; }
.role-card.sel { border-color: var(--accent); background: linear-gradient(160deg, rgba(255,92,138,.16), rgba(139,108,255,.1)); }

.seg { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: none; background: transparent; padding: 8px 4px; border-radius: 9px; cursor: pointer; font-size: 14px; }
.seg button.sel { background: var(--panel2); color: var(--accent); font-weight: 600; box-shadow: inset 0 0 0 1px var(--line); }
.seg.col { flex-direction: column; }

/* Waiting */
#viewWait { align-items: center; text-align: center; padding-top: 60px; }
.radar { position: relative; width: 140px; height: 140px; }
.radar span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--accent); opacity: 0; animation: radar 2.4s infinite; }
.radar span:nth-child(2) { animation-delay: .8s; } .radar span:nth-child(3) { animation-delay: 1.6s; }
@keyframes radar { 0% { transform: scale(.2); opacity: 1; } 100% { transform: scale(1); opacity: 0; } }

/* Room */
.room { flex: 1; padding: 0; gap: 0; min-height: 0; height: calc(100dvh - 52px); }
.room-bar { position: relative; display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.who { display: flex; gap: 10px; align-items: center; }
.who small { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  background: linear-gradient(135deg, var(--accent2), var(--accent)); }
.badge { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; font-size: 11px; color: var(--text); }
.mic-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); animation: beat 1.2s infinite; }
.menu { position: absolute; right: 12px; top: 52px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  display: flex; flex-direction: column; min-width: 170px; z-index: 10; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.menu button { background: none; border: none; text-align: left; padding: 11px 14px; cursor: pointer; }
.menu button:hover { background: var(--panel); }

.stage { position: relative; display: grid; place-items: center; padding: 14px 0 8px; }
.pulse { position: relative; width: 168px; height: 168px; display: grid; place-items: center; }
.ring { position: absolute; inset: 0; border-radius: 50%; border: 3px solid var(--accent2);
  box-shadow: 0 0 30px rgba(139,108,255,.25), inset 0 0 30px rgba(139,108,255,.15); }
.ring.hit { animation: hit .22s ease-out; }
.ring.hit.accent { border-color: var(--accent); }
@keyframes hit { 0% { transform: scale(1.12); box-shadow: 0 0 50px rgba(255,92,138,.6); } 100% { transform: scale(1); } }
.pulse.holding .ring { border-color: var(--warn); box-shadow: 0 0 40px rgba(255,181,71,.4); }
.pulse.idle .ring { opacity: .45; }
.center { text-align: center; z-index: 1; }
.bpm { font-size: 46px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.state { font-size: 13px; color: var(--muted); margin-top: 6px; max-width: 140px; }
.pulse.holding .bpm { color: var(--warn); }
.cue-flash { position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px; font-weight: 800; color: var(--warn);
  background: rgba(15,13,20,.94); pointer-events: none; animation: flash 1.6s forwards; text-align: center; padding: 0 16px; z-index: 2; }
@keyframes flash { 0% { opacity: 0; transform: scale(.8);} 15% { opacity: 1; transform: scale(1);} 75% { opacity: 1;} 100% { opacity: 0; } }

.controls { padding: 6px 14px 8px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
#bpmSlider { flex: 1; accent-color: var(--accent); min-width: 60px; }
#rampTo { width: 64px; } .sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.chips button:active { background: var(--panel2); }
.chips.status button { flex: 1; padding: 10px 8px; border-radius: 12px; font-size: 14px; }
.chips button.hot { border-color: var(--warn); color: var(--warn); font-weight: 700; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; flex: 1; }
.chips.scroll::-webkit-scrollbar { display: none; }

.chat { flex: 1; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; min-height: 80px; }
.msg { max-width: 78%; padding: 7px 11px; border-radius: 14px; background: var(--panel2); word-break: break-word; align-self: flex-start; }
.msg.me { align-self: flex-end; background: linear-gradient(135deg, rgba(255,92,138,.85), rgba(139,108,255,.85)); color: #fff; }
.msg.phrase { font-style: italic; }
.msg.sys { align-self: center; background: none; color: var(--muted); font-size: 12px; text-align: center; max-width: 92%; }
.msg.cue { align-self: center; background: rgba(255,181,71,.12); color: var(--warn); font-size: 13px; border: 1px solid rgba(255,181,71,.3); }

.phrases { display: flex; gap: 6px; align-items: center; padding: 6px 14px; border-top: 1px solid var(--line); }
.composer { display: flex; gap: 6px; padding: 8px 14px calc(10px + var(--safe-b)); align-items: center; }
#msgInput { flex: 1; min-width: 0; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal .card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; width: 100%; max-width: 420px;
  display: flex; flex-direction: column; gap: 14px; max-height: 90dvh; overflow-y: auto; }
.phrase-list { display: flex; flex-direction: column; gap: 6px; }
.phrase-list .item { display: flex; gap: 6px; } .phrase-list input { flex: 1; }

.toast { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line);
  padding: 8px 16px; border-radius: 999px; z-index: 60; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.4); }

@media (max-width: 420px) {
  .roles { grid-template-columns: 1fr; }
  .role-card { flex-direction: row; justify-content: space-between; align-items: center; }
  .pulse { width: 132px; height: 132px; } .bpm { font-size: 40px; }
  .brand small { display: none; }
  .controls .btn { padding: 7px 11px; }
}
