:root {
  color-scheme: dark;
  --bg: #0E1116;
  --surface: #171C24;
  --surface-2: #212836;
  --text: #EEF1F6;
  --muted: #9AA4B5;
  --accent: #7FB4FF;
  --accent-text: #0E1116;
  --live: #3DDC84;
  --danger: #FF5C5C;
  --warn: #FFB74D;
  --radius: 16px;
  font-family: "Nunito", ui-rounded, "SF Pro Rounded", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
}

body {
  -webkit-text-size-adjust: 100%;
  line-height: 1.45;
}

.screen {
  max-width: 720px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

h1,
h2 {
  margin: 0 0 8px;
  line-height: 1.2;
}

h1 {
  font-size: 1.9rem;
}

h2 {
  font-size: 1.1rem;
}

p {
  margin: 0 0 8px;
}

/* ---- join screen ---- */

.brand {
  text-align: center;
  padding: 24px 0 16px;
}

.logo {
  width: 72px;
  height: 72px;
}

.tagline {
  color: var(--muted);
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card.warn {
  border: 1px solid var(--warn);
}

.notice {
  background: var(--surface-2);
}

.notice p {
  color: var(--muted);
}

label {
  display: block;
  font-weight: 700;
  margin: 8px 0 6px;
}

input:not([type="range"]) {
  width: 100%;
  font: inherit;
  font-size: 1.1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  padding: 12px 14px;
}

#code {
  letter-spacing: 0.12em;
  font-weight: 700;
  text-transform: uppercase;
}

input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  border-radius: 999px;
  padding: 12px 22px;
}

#join-btn {
  width: 100%;
  margin-top: 16px;
  font-size: 1.1rem;
}

button:disabled {
  opacity: 0.5;
}

.error {
  color: var(--danger);
  margin-top: 8px;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 12px;
}

.center {
  text-align: center;
}

/* ---- room screen ---- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.titles {
  flex: 1;
  min-width: 0;
}

.room-title {
  font-weight: 800;
}

.room-info {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

button.icon {
  background: var(--surface);
  border-radius: 999px;
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  flex: none;
}

svg {
  width: 22px;
  height: 22px;
}

.listeners {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
}

.live-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--live);
}

.live-dot::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--live);
}

.live-dot.pulse::before {
  animation: pulse 1.6s ease-out;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.7); transform: scale(1.3); }
  100% { box-shadow: 0 0 0 12px rgba(61, 220, 132, 0); transform: scale(1); }
}

.stage {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
}

.stage canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.stage:fullscreen,
.stage.pseudo-fullscreen {
  border-radius: 0;
  aspect-ratio: auto;
}

.stage.pseudo-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 10;
}

.stage-btn {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background: rgba(14, 17, 22, 0.6);
}

.status {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(14, 17, 22, 0.75);
  border-radius: 12px;
  padding: 10px 16px;
  text-align: center;
  max-width: 90%;
}

.status:empty {
  display: none;
}

.alarm {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  font-weight: 800;
  font-size: 1.2rem;
  padding: 16px;
  animation: flash 1s steps(1) infinite;
}

body.alarm-on {
  animation: flash-body 1s steps(1) infinite;
}

@keyframes flash {
  0% { background: rgba(255, 92, 92, 0.85); }
  50% { background: rgba(14, 17, 22, 0.85); }
}

@keyframes flash-body {
  0% { background: #3A1010; }
  50% { background: var(--bg); }
}

.controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.ctl {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 700;
}

.ctl[aria-pressed="true"],
.ctl[aria-expanded="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

.badge {
  position: absolute;
  top: 4px;
  right: 8px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  line-height: 18px;
  text-align: center;
}

.zoom-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  background: var(--surface);
  border-radius: 14px;
  padding: 8px 14px;
}

.zoom-row label {
  margin: 0;
}

.zoom-row input {
  flex: 1;
  accent-color: var(--accent);
}

.chat {
  margin-top: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  animation: pop 0.18s ease-out;
}

@keyframes pop {
  from { transform: scale(0.96) translateY(6px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

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

.chat-list li {
  background: var(--surface-2);
  border-radius: 14px 14px 14px 4px;
  padding: 8px 12px;
  align-self: flex-start;
  max-width: 85%;
  overflow-wrap: anywhere;
}

.chat-list li.mine {
  align-self: flex-end;
  border-radius: 14px 14px 4px 14px;
  background: #2B4A7A;
}

.chat-list .who {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 700;
}

.chat-form {
  display: flex;
  gap: 8px;
}

.notice-small {
  margin-top: 20px;
}

/* Keeps the screen awake where the Wake Lock API is missing: must stay "visible" to the browser. */
.keep-awake {
  position: fixed;
  width: 1px;
  height: 1px;
  bottom: 0;
  right: 0;
  opacity: 0.01;
  pointer-events: none;
}
