:root {
  --bg: #101418;
  --panel: #1a2026;
  --panel-2: #232b33;
  --text: #eef2f5;
  --muted: #8a97a3;
  --accent: #3b82f6;
  --red: #e02424;
  --green: #16a34a;
  --good: #16a34a;
  --bad: #6b7280;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.15s ease;
  overscroll-behavior: none;
}

/* Whole-screen tint follows tally so it is glanceable from across a room. */
body.state-program {
  background: #2a0d0d;
}
body.state-preview {
  background: #0d2419;
}

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

[hidden] {
  display: none !important;
}

/* ───────── Join screen ───────── */
#join {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.join-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

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

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

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

label.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 15px;
}

label.checkbox input {
  width: 20px;
  height: 20px;
}

input[type="text"],
input[type="password"],
select {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  font-size: 16px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid #313b45;
  border-radius: 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
}

button.primary {
  width: 100%;
  padding: 14px;
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border-radius: 10px;
  margin-top: 6px;
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid #313b45;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
}

.error {
  color: #f87171;
  font-size: 14px;
  min-height: 18px;
  margin: 10px 0 0;
}

.warning {
  color: #fbbf24;
  font-size: 13px;
  margin: 10px 4px 0;
}

/* ───────── Top bar ───────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
}

.status-pills {
  display: flex;
  gap: 8px;
}

.pill {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: #fff;
}

.pill-good {
  background: var(--good);
}
.pill-bad {
  background: var(--bad);
}

/* ───────── Tally ───────── */
.tally {
  position: relative;
  flex: 1;
  min-height: 32vh;
  margin: 4px 14px 14px;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 4px solid #2b343d;
  text-align: center;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

/* When the mic is enabled the tally doubles as a big push-to-talk pad. */
.tally.ptt-surface {
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.tally.talking {
  box-shadow: 0 0 0 5px #22c55e, 0 0 40px rgba(34, 197, 94, 0.55);
}

.tally.talking::after {
  content: "● TALKING";
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #fff;
  background: rgba(34, 197, 94, 0.95);
  padding: 4px 10px;
  border-radius: 999px;
}

body.state-program .tally {
  background: var(--red);
  border-color: #ff6b6b;
  box-shadow: 0 0 60px rgba(224, 36, 36, 0.6);
}

body.state-preview .tally {
  background: var(--green);
  border-color: #4ade80;
}

.tally-state {
  font-size: clamp(40px, 12vw, 96px);
  font-weight: 800;
  letter-spacing: 2px;
}

.tally-input {
  margin-top: 8px;
  font-size: 16px;
  opacity: 0.85;
}

/* ───────── Controls ───────── */
.controls {
  padding: 0 14px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 0;
  color: var(--text);
}

.control-row span {
  font-size: 15px;
  white-space: nowrap;
}

.control-row select {
  margin-top: 0;
  max-width: 60%;
}

/* ───────── Intercom ───────── */
.intercom {
  margin: 14px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px;
}

.intercom-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.intercom-head h2 {
  margin: 0;
  font-size: 18px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.peer-list {
  list-style: none;
  margin: 12px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 28vh;
  overflow-y: auto;
}

.peer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
  border-radius: 10px;
}

.peer .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4b5563;
  flex: none;
}

.peer.speaking .dot {
  background: #22c55e;
  box-shadow: 0 0 10px #22c55e;
}

.peer .peer-name {
  flex: 1;
  font-size: 15px;
}

.peer .peer-tag {
  font-size: 12px;
  color: var(--muted);
}

.peer.is-self .peer-name::after {
  content: " (you)";
  color: var(--muted);
}

.intercom-controls {
  display: flex;
  align-items: stretch;
  gap: 12px;
  margin-top: 6px;
}

.round {
  width: 64px;
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 700;
  font-size: 12px;
  border: 2px solid #313b45;
}

.round.muted-on {
  background: #3a1d1d;
  border-color: var(--red);
  color: #fca5a5;
}

.ptt {
  flex: 1;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 16px;
  user-select: none;
  touch-action: none;
}

.ptt small {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.85;
}

.ptt.active {
  background: #22c55e;
  box-shadow: 0 0 24px rgba(34, 197, 94, 0.6);
  transform: scale(0.99);
}

.ptt.disabled {
  background: var(--panel-2);
  color: var(--muted);
  border: 2px solid #313b45;
}

/* ───────── Keep-mic-on toggle ───────── */
.mic-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 0;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 2px solid #313b45;
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.mic-toggle.on {
  background: #102b1a;
  border-color: var(--green);
}

.mic-toggle-label {
  font-size: 15px;
  font-weight: 600;
}

.mic-toggle.on .mic-toggle-label::after {
  content: " · LIVE";
  color: #4ade80;
  font-weight: 700;
}

.mic-toggle.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.switch {
  position: relative;
  flex: none;
  width: 52px;
  height: 30px;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.switch .slider {
  position: absolute;
  inset: 0;
  background: #3a444e;
  border-radius: 999px;
  transition: background-color 0.15s ease;
}

.switch .slider::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s ease;
}

.switch input:checked + .slider {
  background: var(--green);
}

.switch input:checked + .slider::before {
  transform: translateX(22px);
}
