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

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #22c55e;
  --accent-glow: rgba(34, 197, 94, 0.45);
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  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-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
}

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

.card {
  background: var(--surface);
  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: var(--accent);
  color: #052e16;
}

.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.05em;
}

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

.status-bar {
  display: flex;
  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);
}

.badge-ok {
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent);
}

.badge-warn {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warn);
}

.badge-error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.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-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);
  box-shadow: 0 0 8px var(--accent-glow);
}

.peer-dot.you {
  background: #60a5fa;
}

.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: 3px solid var(--surface-2);
  background: var(--surface);
  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;
}

.ptt-button .ptt-icon {
  font-size: 3rem;
  z-index: 1;
  pointer-events: none;
}

.ptt-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 3px 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(34, 197, 94, 0.12);
  box-shadow: 0 0 30px var(--accent-glow);
}

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

.ptt-button.latched {
  border-color: var(--accent);
  background: rgba(34, 197, 94, 0.2);
  box-shadow: 0 0 40px var(--accent-glow);
}

.mode-toggle {
  display: flex;
  gap: 0.5rem;
  background: var(--surface);
  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);
  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(34, 197, 94, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
}

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