:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e2230;
  --border: #262b36;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #7c8cf8;
  --accent-hover: #939ffa;
  --green: #34d399;
  --red: #f87171;
}

* { box-sizing: border-box; }

/* `hidden` must win over the `display` rules on #room-view / #audio-overlay below */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

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

button {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.danger { color: var(--red); }
button.mic-on { background: var(--green); border-color: var(--green); color: #08281c; font-weight: 600; }

input {
  font: inherit;
  width: 100%;
  padding: 9px 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
input:focus { outline: none; border-color: var(--accent); }

.error { color: var(--red); font-size: 0.9rem; }

/* ---------- join view ---------- */

#join-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
}
.card .subtitle { color: var(--muted); margin: 6px 0 22px; }
.card label { display: block; font-size: 0.85rem; color: var(--muted); margin: 14px 0 6px; }
.card #join-btn { width: 100%; margin-top: 20px; }
.card .error { margin: 10px 0 0; }

.rooms-section { margin-top: 26px; border-top: 1px solid var(--border); padding-top: 18px; }
#rooms-list { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
#rooms-list .empty { color: var(--muted); font-size: 0.9rem; }
#rooms-list li + li { margin-top: 6px; }
#rooms-list button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-2);
}
#rooms-list .count { color: var(--muted); font-size: 0.85rem; }

/* ---------- room view ---------- */

#room-view { display: flex; flex-direction: column; height: 100vh; }

#banner {
  background: #7a5c17;
  color: #ffe9b0;
  text-align: center;
  padding: 6px;
  font-size: 0.9rem;
}

#room-view header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.room-title { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.room-title h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#participant-count { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.controls { display: flex; gap: 10px; }

#room-view main {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 16px;
  padding: 16px 20px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#participants-panel { flex: 1; }
#participants-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#participants-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
}
#participants-list li.speaking { border-color: var(--green); background: rgba(52, 211, 153, 0.08); }
.avatar {
  width: 32px;
  height: 32px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 600;
}
li.speaking .avatar { background: var(--green); color: #08281c; }
#participants-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mic-state { flex: none; }

#chat-panel { width: 360px; flex: none; }
#chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.msg { max-width: 100%; }
.msg .meta { display: flex; gap: 8px; align-items: baseline; font-size: 0.8rem; margin-bottom: 2px; }
.msg .sender { font-weight: 600; }
.msg .time { color: var(--muted); }
.msg .text { background: var(--surface-2); border-radius: 8px; padding: 7px 10px; white-space: pre-wrap; word-break: break-word; }
.msg.own .text { background: rgba(124, 140, 248, 0.18); }
.msg.system { color: var(--muted); font-size: 0.82rem; text-align: center; }

#chat-form { display: flex; gap: 8px; margin-top: 12px; }
#chat-form input { flex: 1; }

#audio-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 17, 21, 0.85);
  z-index: 10;
}

@media (max-width: 800px) {
  #room-view main { flex-direction: column; padding: 12px; }
  #chat-panel { width: auto; flex: 1; }
  #participants-panel { flex: none; max-height: 40vh; }
}
