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

:root {
  --bg: #0a0a0f;
  --surface: #14141f;
  --surface-2: #1f1f2e;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --accent: #818cf8;
  --accent-2: #c084fc;
  --accent-glow: rgba(129, 140, 248, 0.45);
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: var(--bg);
  background-image: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(129, 140, 248, 0.15), transparent);
  color: var(--text);
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  min-height: 100dvh;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 1.25rem;
  padding-bottom: calc(1.25rem + var(--safe-bottom));
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.screen.active {
  display: flex;
}

.brand {
  text-align: center;
  margin: 2rem 0 1.5rem;
}

.brand-logo {
  width: 72px;
  height: 72px;
  margin: 0 auto 0.75rem;
}

.brand-logo svg {
  width: 100%;
  height: 100%;
}

.brand h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.875rem;
  color: var(--muted);
}

input {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--surface-2);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

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

.btn {
  border: none;
  border-radius: 12px;
  padding: 0.85rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0a0f;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--surface-2);
}

.btn-sm {
  padding: 0.5rem 0.85rem;
  font-size: 0.875rem;
}

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 1.5rem;
}

.hidden {
  display: none !important;
}

.room-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.room-label {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.room-header h2 {
  margin: 0.15rem 0 0;
  font-size: 1.35rem;
  word-break: break-all;
}

.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.badge {
  font-size: 0.75rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--surface-2);
}

.badge-ok {
  background: rgba(129, 140, 248, 0.12);
  color: var(--accent);
  border-color: rgba(129, 140, 248, 0.25);
}

.badge-warn {
  background: rgba(251, 191, 36, 0.1);
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.2);
}

.badge-error {
  background: rgba(248, 113, 113, 0.1);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.2);
}

.peer-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  flex: 1;
  overflow-y: auto;
}

.peer-list li {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.peer-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface-2);
  flex-shrink: 0;
}

.peer-dot.talking {
  background: var(--accent-2);
  box-shadow: 0 0 8px var(--accent-glow);
}

.peer-dot.you {
  background: var(--accent);
}

.ptt-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin-top: auto;
}

.mode-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.ptt-button {
  position: relative;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 2px solid var(--surface-2);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s, color 0.15s;
}

.ptt-button .ptt-icon {
  width: 48px;
  height: 48px;
  z-index: 1;
  pointer-events: none;
}

.ptt-button .ptt-icon svg {
  width: 100%;
  height: 100%;
}

.ptt-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: border-color 0.15s, box-shadow 0.15s;
  pointer-events: none;
}

.ptt-button.active,
.ptt-button:active {
  border-color: var(--accent);
  background: rgba(129, 140, 248, 0.1);
  color: var(--accent-2);
  box-shadow: 0 0 40px var(--accent-glow);
}

.ptt-button.active .ptt-ring,
.ptt-button:active .ptt-ring {
  border-color: var(--accent);
  box-shadow: 0 0 24px var(--accent-glow);
}

.ptt-button.active .wave-bar,
.ptt-button.latched .wave-bar {
  animation: wave 0.6s ease-in-out infinite alternate;
}

.ptt-button.active .wave-bar:nth-child(2),
.ptt-button.latched .wave-bar:nth-child(2) { animation-delay: 0.1s; }
.ptt-button.active .wave-bar:nth-child(3),
.ptt-button.latched .wave-bar:nth-child(3) { animation-delay: 0.2s; }
.ptt-button.active .wave-bar:nth-child(4),
.ptt-button.latched .wave-bar:nth-child(4) { animation-delay: 0.15s; }

@keyframes wave {
  from { transform: scaleY(0.6); }
  to { transform: scaleY(1.2); }
}

.ptt-button.latched {
  border-color: var(--accent-2);
  background: rgba(192, 132, 252, 0.12);
  color: var(--accent-2);
  box-shadow: 0 0 48px var(--accent-glow);
}

.mode-toggle {
  display: flex;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  padding: 0.35rem;
  border-radius: 12px;
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.55rem 1rem;
  border-radius: 9px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.mode-btn.active {
  background: var(--surface-2);
  color: var(--text);
}

.talking-indicator {
  text-align: center;
  color: var(--accent-2);
  font-size: 0.875rem;
  margin: 0.5rem 0 0;
  min-height: 1.25rem;
}

.mode-help {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
  max-width: 280px;
}

.audio-unlock-btn {
  margin: 0.75rem auto 0;
  display: block;
  width: calc(100% - 2rem);
  max-width: 320px;
  animation: pulse-btn 2s ease-in-out infinite;
}

.audio-unlock-btn.hidden {
  display: none !important;
}

@keyframes pulse-btn {
  0%, 100% { box-shadow: 0 0 0 0 rgba(129, 140, 248, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(129, 140, 248, 0); }
}

@media (max-height: 600px) {
  .ptt-button {
    width: 130px;
    height: 130px;
  }
  .ptt-button .ptt-icon {
    width: 40px;
    height: 40px;
  }
}
