:root {
  --bg: #0b1120;
  --panel: #121b2f;
  --panel-2: #1a2742;
  --line: #27344f;
  --text: #e6edf7;
  --muted: #8e9db6;
  --accent: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: radial-gradient(1200px 600px at 50% -10%, #16233f 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font: 16px/1.45 system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
}

.top-pills {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.perm {
  cursor: pointer;
  border: 0;
  font: inherit;
}

.perm[data-state="wait"] {
  color: var(--muted);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.pill {
  font-size: 14px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}

.pill[data-state="good"] {
  background: var(--accent);
  color: #052e16;
}

.pill[data-state="warn"] {
  background: var(--warn);
  color: #1f1300;
}

.pill[data-state="bad"] {
  background: var(--danger);
  color: #fff;
}

.pill[data-state="connecting"] {
  background: #a5b4fc;
  color: #1e1b4f;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

.card {
  max-width: 420px;
  margin: 8vh auto 0;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.card h1 {
  margin: 0 0 6px;
  font-size: 26px;
}

.lead {
  margin: 0 0 22px;
  color: var(--muted);
}

label {
  display: block;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--muted);
}

input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 13px;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

button:hover {
  background: #22314f;
}

button:active {
  transform: translateY(1px);
}

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

#join-btn {
  width: 100%;
  padding: 12px;
  font-weight: 600;
  color: #052e16;
  background: var(--accent);
  border-color: transparent;
}

#join-btn:hover {
  background: #34d970;
}

.btn {
  font-size: 15px;
}

.btn[data-on="off"] {
  border-color: var(--warn);
  color: var(--warn);
}

.btn.danger {
  margin-left: auto;
  color: #fca5a5;
  border-color: #5b2333;
}

.btn.danger:hover {
  background: #3a1722;
}

.error {
  margin: 16px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #3a1722;
  color: #fecaca;
}

.note {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.note a,
.hint a {
  color: #86efac;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hint {
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.people {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.person {
  padding: 18px 14px 14px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
}

.person.speaking {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 26px rgba(34, 197, 94, 0.3);
  transform: translateY(-2px);
}

.person.muted {
  opacity: 0.72;
}

.avatar {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: var(--panel-2);
  font-size: 24px;
  font-weight: 700;
}

.person.me .avatar {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tags {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
}

.person.me .tag:not(.state) {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
}

/* Personal loudness, one row per remote participant. */
.volrow {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.volmute {
  padding: 2px 6px;
  font-size: 15px;
  line-height: 1.3;
  border-radius: 8px;
}

.volmute[data-on="off"] {
  border-color: var(--warn);
}

.volrow input[type="range"] {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  background: transparent;
  border: 0;
}

.volval {
  min-width: 42px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  text-align: right;
}

/* Toolbar icons: the microphone state and the settings popover. */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  padding: 10px 0;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

#mic-btn .mic-slash {
  display: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

#mic-btn[data-on="on"] {
  color: #052e16;
  background: var(--accent);
  border-color: transparent;
}

#mic-btn[data-on="on"]:hover {
  background: #34d970;
}

#mic-btn[data-on="off"] {
  color: #f87171;
  border-color: #5b2333;
}

#mic-btn[data-on="off"]:hover {
  background: #3a1722;
}

#mic-btn[data-on="off"] .mic-slash {
  display: block;
}

.settings {
  position: relative;
}

.settings-pop {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  width: 320px;
  max-width: 90vw;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

.settings-title {
  margin-bottom: 6px;
  font-weight: 700;
}

.settings-note {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.settings-pop input[type="range"] {
  width: 100%;
  margin: 0;
  padding: 0;
  accent-color: var(--warn);
  background: transparent;
  border: 0;
}

.ducktag {
  background: #3a2a12;
  color: #fde68a;
}

/* Text chat under the participants grid. */
.chat {
  margin-top: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

#chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  font-weight: 600;
  text-align: left;
  background: none;
  border: 0;
}

#chat-head::after {
  content: "▾";
  color: var(--muted);
  font-size: 13px;
}

.chat[data-open="0"] #chat-head::after {
  content: "▸";
}

.chat[data-open="0"] #chat-body {
  display: none;
}

.chat-unread {
  margin-left: auto;
  margin-right: 24px;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--warn);
  color: #1f1300;
  font-size: 13px;
  font-weight: 700;
}

#chat-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  padding: 0 16px;
  scroll-behavior: smooth;
}

.chat-msg {
  font-size: 15px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.chat-msg .who {
  margin-right: 6px;
  font-weight: 600;
  color: #93c5fd;
}

.chat-msg.mine .who {
  color: #86efac;
}

.chat-msg .when {
  margin-left: 6px;
  font-size: 12px;
  color: var(--muted);
}

.chat-msg.sys {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

#chat-form {
  display: flex;
  gap: 10px;
  padding: 12px 16px 14px;
}

#chat-form input {
  flex: 1;
  margin: 0;
}

#chat-form .icon-btn {
  flex: 0 0 auto;
  width: 40px;
}

.chat-img {
  display: block;
  max-width: 240px;
  max-height: 180px;
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: zoom-in;
}

/* The in-room microphone check (a compact modal). */
.mm-wrap {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
}

/* "display: grid" above would defeat the hidden attribute; this restores it. */
.mm-wrap[hidden] {
  display: none;
}

.mm-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 16, 0.7);
}

.mm {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 18px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.mm-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.mm-head h2 {
  margin: 0;
  font-size: 19px;
}

.mm-x {
  padding: 4px 10px;
  font-size: 15px;
}

.checks {
  display: grid;
  gap: 6px;
  margin: 8px 0 12px;
  padding: 0;
  list-style: none;
}

.chk {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 0 8px;
  align-items: baseline;
  font-size: 14px;
}

.chk::before {
  display: inline-block;
  width: 20px;
  font-weight: 700;
  text-align: center;
  content: "·";
  color: var(--muted);
}

.chk[data-status="ok"]::before { content: "✓"; color: var(--accent); }
.chk[data-status="warn"]::before { content: "!"; color: var(--warn); }
.chk[data-status="fail"]::before { content: "✕"; color: #f87171; }
.chk[data-status="run"]::before { content: "…"; color: #a5b4fc; }
.chk[data-status="skip"]::before { content: "—"; }

.chk .name {
  font-weight: 600;
}

.chk .detail {
  grid-column: 2;
  color: var(--muted);
}

.chk .detail:empty {
  display: none;
}

.meter {
  height: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

#mm-fill {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 60ms linear;
}

#mm-fill.hot { background: var(--warn); }
#mm-fill.clip { background: var(--danger); }

.level {
  margin: 6px 0 10px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.mm-device {
  display: block;
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--muted);
}

.mm-device select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.mm-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.mm .check {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  font-size: 14px;
}

.mm .check input {
  width: 16px;
  height: 16px;
  margin: 0;
}

#mm-wave {
  display: block;
  width: 100%;
  height: 48px;
  border-radius: 8px;
  background: var(--panel-2);
}

#mm-player {
  display: block;
  width: 100%;
  margin-top: 8px;
}

.mm-foot {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 10;
  max-width: min(92vw, 560px);
  padding: 12px 18px;
  transform: translateX(-50%);
  background: #1f2a44;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

@media (max-width: 560px) {
  .card {
    margin-top: 4vh;
    padding: 22px;
  }

  .toolbar .btn {
    flex: 1 1 40%;
  }

  .btn.danger {
    margin-left: 0;
  }

  .hint {
    display: none;
  }
}

/* Room themes, switched from the settings popover. The classic palette is
   :root above; every other look overrides the variables and the few rules
   with hardcoded colors. */

.settings-sep {
  height: 1px;
  margin: 14px -16px;
  background: var(--line);
}

.theme-picker {
  display: grid;
  gap: 8px;
  margin: 4px 0 8px;
}

.theme-opt {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 12px;
  font-size: 14px;
  text-align: left;
  border-radius: 8px;
}

.theme-opt::after {
  content: "✓";
  visibility: hidden; /* hidden keeps the width and stays out of the accessible name */
  color: var(--accent);
}

.theme-opt.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.theme-opt.active::after {
  visibility: visible;
}

/* ---------- Deep Rock Galactic ---------- */

body[data-theme="drg"] {
  --bg: #0d0a07;
  --panel: #191309;
  --panel-2: #251b10;
  --line: #4a3820;
  --text: #f3e7d3;
  --muted: #a89170;
  --accent: #f0862b;
  --warn: #f2b544;
  --danger: #e4572e;
  background-color: #0a0704;
  /* The picture is busy on the right (the planet), so the gradient layers
     keep the left half and the bottom calm enough to read the cards. */
  background-image:
    linear-gradient(180deg, rgba(10, 7, 4, 0.45), rgba(10, 7, 4, 0.86) 80%),
    linear-gradient(90deg, rgba(10, 7, 4, 0.70), rgba(10, 7, 4, 0.05) 48%, rgba(10, 7, 4, 0.25)),
    url("drg.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

body[data-theme="drg"] .brand,
body[data-theme="drg"] .card h1,
body[data-theme="drg"] .settings-title,
body[data-theme="drg"] .mm-head h2 {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Panels: metal with a warm sheen on top and a bronze edge. The settings
   popover is deliberately absent here: it must stay position: absolute, or
   it joins the toolbar's flex row and stretches every button to its height. */
body[data-theme="drg"] .card,
body[data-theme="drg"] .person,
body[data-theme="drg"] .chat,
body[data-theme="drg"] .mm {
  position: relative;
  border-color: var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(240, 134, 43, 0.05), rgba(240, 134, 43, 0) 36%),
    var(--panel);
  box-shadow: inset 0 1px 0 rgba(255, 196, 128, 0.06), 0 10px 26px rgba(0, 0, 0, 0.42);
}

body[data-theme="drg"] .card,
body[data-theme="drg"] .chat,
body[data-theme="drg"] .settings-pop,
body[data-theme="drg"] .mm {
  border-top: 2px solid rgba(240, 134, 43, 0.4);
}

/* Buttons: dark metal, the primary ones in corporate orange. */
body[data-theme="drg"] button {
  border-radius: 6px;
  border-color: var(--line);
  background: linear-gradient(180deg, #2b2113, #20180c);
}

body[data-theme="drg"] button:hover {
  background: linear-gradient(180deg, #382a15, #2a1e0d);
}

body[data-theme="drg"] input,
body[data-theme="drg"] .mm-device select {
  border-radius: 6px;
  border-color: var(--line);
  background: #100b05;
}

body[data-theme="drg"] #join-btn,
body[data-theme="drg"] #mic-btn[data-on="on"] {
  color: #221103;
  border-color: #8a4d12;
  background: linear-gradient(180deg, #ff9a3d, #e07a1e);
}

body[data-theme="drg"] #join-btn:hover,
body[data-theme="drg"] #mic-btn[data-on="on"]:hover {
  background: linear-gradient(180deg, #ffab59, #ef8828);
}

body[data-theme="drg"] #mic-btn[data-on="off"],
body[data-theme="drg"] .btn.danger {
  color: #ff8f7a;
  border-color: #6e2c1a;
}

body[data-theme="drg"] #mic-btn[data-on="off"]:hover,
body[data-theme="drg"] .btn.danger:hover {
  background: #3d1710;
}

body[data-theme="drg"] .error {
  background: #3d1710;
  color: #ffc4b3;
}

body[data-theme="drg"] .pill[data-state="good"] {
  background: var(--accent);
  color: #221103;
}

body[data-theme="drg"] .pill[data-state="connecting"] {
  background: #e8c98a;
  color: #3a2a0c;
}

/* Participant cards: the strip along the top edge is a dim lamp normally and
   hazard tape while the dwarf is talking. */
body[data-theme="drg"] .person {
  overflow: hidden;
}

body[data-theme="drg"] .person::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: rgba(240, 134, 43, 0.18);
}

body[data-theme="drg"] .person.speaking {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(240, 134, 43, 0.75), 0 0 30px rgba(240, 134, 43, 0.3);
  transform: translateY(-2px);
}

body[data-theme="drg"] .person.speaking::before {
  background: repeating-linear-gradient(-45deg, #f0862b 0 12px, #1a1207 12px 24px);
}

body[data-theme="drg"] .avatar {
  border-radius: 10px;
  background: radial-gradient(circle at 35% 30%, #3a2c15, #221808 70%);
  box-shadow: inset 0 0 0 1px rgba(240, 134, 43, 0.35);
}

body[data-theme="drg"] .person.me .avatar {
  outline-color: var(--accent);
}

body[data-theme="drg"] .person.me .tag:not(.state) {
  background: rgba(240, 134, 43, 0.16);
  color: #ffc894;
}

body[data-theme="drg"] .ducktag {
  background: #3a2a10;
  color: #ffdf9e;
}

body[data-theme="drg"] .chat-msg .who {
  color: #ffc36b;
}

body[data-theme="drg"] .chat-msg.mine .who {
  color: #7fd8c6;
}

body[data-theme="drg"] .note a,
body[data-theme="drg"] .hint a {
  color: #ffc894;
}

body[data-theme="drg"] .chat-unread {
  background: repeating-linear-gradient(-45deg, #f0862b 0 8px, #b05f10 8px 16px);
  color: #221103;
}

/* The chat header is a button, but must not look like a metal slab. */
body[data-theme="drg"] #chat-head {
  border: 0;
  background: none;
}

body[data-theme="drg"] .toast {
  background: #251b0f;
}

body[data-theme="drg"] .mm-backdrop {
  background: rgba(8, 5, 2, 0.76);
}
