:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --panel: #ffffff;
  --ink: #151716;
  --muted: #68706b;
  --line: #d8d6cd;
  --accent: #006d77;
  --accent-strong: #004f58;
  --warm: #f2b84b;
  --danger: #b42318;
  --ok: #237a4b;
  --shadow: 0 20px 50px rgba(26, 24, 20, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(180deg, rgba(0, 109, 119, 0.08), transparent 260px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 5vw, 46px);
  line-height: 1;
}

h2 {
  font-size: 22px;
}

.status-pill {
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  padding: 10px 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.status-pill.ok {
  border-color: rgba(35, 122, 75, 0.3);
  color: var(--ok);
}

.status-pill.warn {
  border-color: rgba(180, 35, 24, 0.25);
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.setup-panel,
.stage-panel,
.log-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.setup-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
}

.field-group {
  display: grid;
  gap: 7px;
}

.field-group label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 148px;
  padding: 12px;
  resize: vertical;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 109, 119, 0.14);
}

.room-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
}

.toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toggle-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbf8;
  padding: 0 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.toggle-grid input {
  width: 16px;
  height: 16px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: auto;
}

.monitor-controls {
  margin-top: 0;
}

.stage-panel {
  display: flex;
  flex-direction: column;
  min-height: 560px;
  overflow: hidden;
}

.connection-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 22px;
}

.level-meter {
  position: relative;
  width: 180px;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8e5dc;
}

.level-meter span {
  display: block;
  width: 2%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--ok), var(--warm));
  transition: width 80ms linear;
}

.role-surface {
  position: relative;
  display: grid;
  place-items: center;
  flex: 1;
  min-height: 320px;
  padding: 28px;
  overflow: hidden;
  background:
    radial-gradient(circle at 35% 25%, rgba(242, 184, 75, 0.18), transparent 32%),
    linear-gradient(135deg, rgba(0, 109, 119, 0.12), rgba(255, 255, 255, 0));
}

.listen-button,
.mic-button {
  position: relative;
  z-index: 2;
  min-width: min(260px, 100%);
  min-height: 76px;
  border-color: var(--accent);
  background: var(--ink);
  color: #fff;
  font-size: 18px;
}

.mic-button.live {
  border-color: var(--danger);
  background: var(--danger);
}

.speaker-ring {
  position: absolute;
  inset: auto;
  width: 280px;
  height: 280px;
  border: 1px solid rgba(0, 109, 119, 0.16);
  border-radius: 50%;
}

.speaker-ring span {
  position: absolute;
  inset: 34px;
  border: 1px solid rgba(0, 109, 119, 0.2);
  border-radius: 50%;
}

.speaker-ring span:nth-child(2) {
  inset: 74px;
  border-color: rgba(242, 184, 75, 0.42);
}

.speaker-ring span:nth-child(3) {
  inset: 118px;
  background: rgba(0, 109, 119, 0.1);
}

.phone-surface {
  align-content: center;
  gap: 16px;
}

.phone-surface p {
  position: relative;
  z-index: 2;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.visualizer-panel {
  display: grid;
  gap: 14px;
  border-top: 1px solid var(--line);
  background: #fbfbf8;
  padding: 18px 22px 22px;
}

.visualizer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.visualizer-header h2 {
  font-size: 18px;
}

.signal-readout {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.signal-readout span {
  min-width: 94px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.signal-readout strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 16px;
}

#waveformCanvas {
  display: block;
  width: 100%;
  height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(0, 109, 119, 0.05), transparent),
    #ffffff;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  border-top: 1px solid var(--line);
  background: #fff;
}

.stats-grid div {
  display: grid;
  gap: 4px;
  min-width: 0;
  border-right: 1px solid var(--line);
  padding: 14px;
}

.stats-grid div:last-child {
  border-right: 0;
}

.stats-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stats-grid strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-panel {
  margin-top: 18px;
  overflow: hidden;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
}

.log-header h2 {
  font-size: 18px;
}

.log-header button {
  min-height: 34px;
  padding: 0 12px;
}

#eventLog {
  display: grid;
  gap: 8px;
  max-height: 180px;
  margin: 0;
  overflow: auto;
  padding: 14px 18px 18px 38px;
  color: var(--muted);
  font-size: 13px;
}

#eventLog li::marker {
  color: var(--accent);
  font-weight: 900;
}

@media (max-width: 920px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .stage-panel {
    min-height: 520px;
  }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .topbar,
  .connection-header,
  .visualizer-header {
    align-items: stretch;
    flex-direction: column;
  }

  .signal-readout {
    justify-content: stretch;
  }

  .signal-readout span {
    flex: 1;
  }

  .status-pill,
  .level-meter {
    width: 100%;
  }

  .room-row,
  .button-row,
  .toggle-grid {
    grid-template-columns: 1fr;
  }

  .stage-panel {
    min-height: 480px;
  }

  .role-surface {
    min-height: 260px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
