:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #667085;
  --line: #d9dee7;
  --panel: #ffffff;
  --shadow: none;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: #f5f5f2;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.page-surface {
  position: relative;
  min-height: 100%;
  overflow: hidden;
}

.cursor-layer {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.cursor {
  position: absolute;
  left: 50%;
  top: 50%;
  pointer-events: none;
  transform: translate(-4px, -2px);
  transition: left 80ms linear, top 80ms linear;
}

.cursor-mark {
  width: 18px;
  height: 22px;
  background: var(--cursor-color);
  clip-path: polygon(0 0, 0 100%, 7px 76%, 13px 91%, 17px 89%, 11px 72%, 18px 72%);
  filter: drop-shadow(0 7px 10px rgba(15, 23, 42, 0.2));
}

.cursor-label {
  position: absolute;
  left: 14px;
  top: 17px;
  max-width: min(180px, 40vw);
  padding: 4px 8px;
  color: #ffffff;
  background: var(--cursor-color);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: none;
}

.cursor.is-self {
  opacity: 0.65;
}

.cursor.is-speaking .cursor-label::after {
  content: " live";
  font-weight: 800;
}

.roster,
.chat-panel,
.toolbar,
.voice-panel {
  position: fixed;
  z-index: 8;
  border: 1px solid #e5e5e1;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.roster {
  top: 18px;
  left: 18px;
  width: min(420px, calc(100vw - 36px));
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.status-row {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #f59e0b;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.16);
}

.status-dot.is-online {
  background: #16a34a;
  box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.15);
}

.user-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.user-chip {
  position: relative;
  display: block;
  width: 74px;
  height: 74px;
  min-width: 74px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  overflow: visible;
}

.user-chip svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.user-circle-ring {
  fill: none;
  stroke: var(--user-color);
  stroke-width: 1.5;
}

.user-circle-copy {
  fill: var(--ink);
  font-size: 7px;
  font-weight: 800;
  letter-spacing: 0.8px;
}

.user-chip.is-in-voice .user-dot {
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--user-color) 15%, transparent);
}

.user-chip.is-speaking {
  background: transparent;
  box-shadow: none;
}

.user-chip.is-speaking .user-circle-ring {
  stroke: #22c55e;
  stroke-width: 2.5;
}

.user-chip.is-speaking .user-circle-copy {
  fill: #15803d;
}

.user-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--user-color);
  color: #ffffff;
  font-size: 10px;
  font-weight: 800;
  transform: translate(-50%, -50%);
}

.user-chip.is-speaking .user-dot {
  background: #22c55e;
}

.user-details {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.user-name,
.user-position {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-position {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  font-weight: 800;
}

.voice-panel {
  position: fixed;
  left: 18px;
  bottom: 90px;
  z-index: 8;
  width: 102px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: var(--shadow);
}

.voice-levels-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.voice-levels-title {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.voice-circle-wrap {
  display: grid;
  justify-items: center;
  gap: 2px;
}

.voice-circle-wrap > strong,
.voice-self-label,
#receiverPanel {
  display: none;
}

.voice-button {
  position: relative;
  display: block;
  width: 102px;
  height: 102px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: #111827;
  background: transparent;
  transition: opacity 160ms ease;
}

.voice-button:hover {
  background: transparent;
  opacity: 0.72;
}

.voice-button svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.voice-ring {
  fill: none;
  stroke: #111827;
  stroke-width: 1.5;
}

.voice-ring-copy {
  fill: currentColor;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.7px;
}

.voice-radial-eq {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 65px;
  height: 65px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.radial-bar {
  position: absolute;
  left: calc(50% - 0.65px);
  top: calc(50% - var(--radial-length, 26px));
  display: block;
  width: 1.3px;
  height: var(--radial-length, 26px);
  border-radius: 999px;
  background: #111827;
  transform-origin: 50% 100%;
  transition: transform 55ms linear, opacity 55ms linear, background 160ms ease;
}

.voice-radial-eq::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #111827;
  transform: translate(-50%, -50%);
}

.voice-self-label {
  display: none;
  gap: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.voice-button.is-live {
  color: #15803d;
  background: transparent;
}

.voice-button.is-live:hover {
  background: transparent;
}

.voice-button.is-live .voice-ring {
  stroke: #22c55e;
}

.voice-button.is-live .radial-bar,
.voice-button.is-live .voice-radial-eq::after {
  background: #22c55e;
}

.voice-button.is-warning {
  color: #b45309;
  background: transparent;
}

.voice-button.is-warning .voice-ring {
  stroke: #d97706;
}

.voice-button.is-warning .radial-bar,
.voice-button.is-warning .voice-radial-eq::after {
  background: #d97706;
}

.voice-button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
  transform: none;
}

.voice-hint,
.receiver-empty {
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.voice-hint {
  display: none;
}

.receiver-empty[hidden] {
  display: none;
}

.voice-divider {
  height: 1px;
  margin: 12px 0;
  background: #ecece8;
}

.voice-levels-title {
  margin-bottom: 8px;
}

.receiver-meters {
  display: grid;
  gap: 7px;
  margin-top: 7px;
}

.enable-audio-button {
  width: 100%;
  height: 34px;
  margin-top: 10px;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  color: #ffffff;
  background: #059669;
  font-size: 13px;
  font-weight: 800;
}

.enable-audio-button[hidden] {
  display: none;
}

.enable-audio-button:hover {
  background: #047857;
}

.receiver-meter {
  display: grid;
  grid-template-columns: minmax(90px, 112px) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: #f6f6f3;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.voice-person {
  display: grid;
  grid-template-columns: minmax(90px, 112px) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: #f6f6f3;
  --user-color: #2563eb;
}

.voice-person.is-speaking,
.receiver-meter.is-speaking {
  box-shadow: inset 3px 0 #22c55e;
}

.voice-person-meta {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.receiver-name {
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-person-state {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.is-speaking .voice-person-state {
  color: #15803d;
}

.receiver-eq {
  display: grid;
  grid-template-columns: repeat(14, minmax(3px, 1fr));
  align-items: end;
  gap: 2px;
  height: 26px;
  min-width: 0;
}

.receiver-bar {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 3px;
  border-radius: 999px;
  background: var(--user-color);
  transform: scaleY(0.08);
  transform-origin: bottom;
  transition: transform 55ms linear, opacity 55ms linear;
}

.sender-eq {
  margin-top: 0;
}

.chat-panel {
  top: 18px;
  right: 18px;
  display: grid;
  grid-template-rows: auto 1fr;
  width: min(360px, calc(100vw - 36px));
  height: min(380px, calc(100vh - 120px));
  border-radius: 12px;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 0 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.32);
}

.chat-header span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: 14px;
  overflow-y: auto;
}

.message {
  display: grid;
  gap: 3px;
}

.message-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.message-bubble {
  width: fit-content;
  max-width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  background: #f4f4f1;
  border: 0;
  color: var(--ink);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.message.is-self {
  justify-items: end;
}

.message.is-self .message-bubble {
  color: #ffffff;
  background: #2563eb;
  border-color: #2563eb;
}

.message.is-system .message-bubble {
  color: var(--muted);
  background: rgba(241, 245, 249, 0.78);
}

.toolbar {
  left: 50%;
  bottom: 18px;
  display: grid;
  grid-template-columns: minmax(110px, 160px) minmax(180px, 360px) auto;
  gap: 8px;
  align-items: center;
  width: min(680px, calc(100vw - 36px));
  padding: 6px;
  border-radius: 12px;
  transform: translateX(-50%);
}

.toolbar input {
  min-width: 0;
  height: 42px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 12px;
  outline: none;
  color: var(--ink);
  background: #f6f6f3;
}

.toolbar input:focus {
  border-color: #9ca3af;
  box-shadow: none;
}

.toolbar button {
  height: 42px;
  border: 0;
  border-radius: 7px;
  padding: 0 14px;
  cursor: pointer;
  color: #ffffff;
  background: #111827;
  font-weight: 800;
}

.toolbar button:hover {
  background: #1f2937;
}

.send-button {
  background: #2563eb;
}

.send-button:hover {
  background: #1d4ed8;
}

@media (max-width: 820px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }

  .page-surface {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 100vh;
    padding: 12px;
    overflow: visible;
  }

  .roster,
  .chat-panel,
  .voice-panel,
  .toolbar {
    position: static;
    inset: auto;
    width: 100%;
    transform: none;
  }

  .chat-panel {
    order: 3;
    height: min(42vh, 360px);
    min-height: 260px;
  }

  .roster {
    order: 1;
  }

  .voice-panel {
    order: 2;
    width: 102px;
    align-self: center;
  }

  .toolbar {
    order: 4;
    grid-template-columns: 1fr 1fr;
    margin-bottom: env(safe-area-inset-bottom);
  }

  .receiver-meter {
    grid-template-columns: minmax(74px, 104px) minmax(0, 1fr);
  }

  .receiver-eq {
    height: 30px;
  }

  .name-input {
    order: 1;
    grid-column: 1 / -1;
  }

  .message-input {
    order: 2;
    grid-column: 1 / -1;
  }

  .send-button {
    order: 3;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .page-surface {
    padding: 10px;
  }

  .status-row {
    grid-template-columns: auto 1fr;
  }

  #onlineCount {
    grid-column: 2;
  }

  .chat-header {
    min-height: 44px;
  }

  .messages {
    padding: 12px;
  }

  .receiver-meter,
  .voice-person {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .toolbar {
    gap: 7px;
    padding: 8px;
  }

  .toolbar input,
  .toolbar button {
    height: 44px;
  }
}

/* Voice-first layout */
.voice-panel {
  position: fixed;
  inset: auto;
  left: 50%;
  top: auto;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
}

.chat-panel,
.toolbar {
  display: none;
}

.status-row {
  display: none;
}
