*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #121212;
  --card: rgba(30, 30, 30, 0.6);
  --card-solid: #1e1e1e;
  --accent: #f59e0b;
  --accent-dim: rgba(245, 158, 11, 0.15);
  --accent-glow: rgba(245, 158, 11, 0.4);
  --tx-active: #f59e0b;
  --rx-active: #22c55e;
  --lock: #ef4444;
  --text: #ffffff;
  --text-dim: #888888;
  --border: rgba(255, 255, 255, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* ═══ PIN Screen ═══ */
.pin-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-container {
  width: 100%;
  max-width: 320px;
  text-align: center;
  padding: 0 24px;
}

.pin-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 36px;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--text-dim);
  background: transparent;
  transition: background 0.15s, border-color 0.15s;
}

.dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}

.pin-error {
  color: var(--lock);
  font-size: 14px;
  height: 20px;
  margin-bottom: 8px;
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 20px;
}

.key {
  aspect-ratio: 1.4;
  max-height: 64px;
  border: none;
  border-radius: 12px;
  background: var(--card-solid);
  color: var(--text);
  font-size: 26px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
  user-select: none;
}

.key:active { background: #333; }
.key-empty { background: transparent; cursor: default; }
.key-del { font-size: 22px; color: var(--text-dim); background: transparent; }
.key-del:active { background: rgba(255, 255, 255, 0.05); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-6px); }
  80%      { transform: translateX(6px); }
}
.pin-dots.shake { animation: shake 0.4s ease; }

/* ═══ Main App ═══ */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  gap: 12px;
}

/* ─── Channel tabs ─── */
.channel-tabs {
  display: flex;
  gap: 4px;
  background: var(--card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}

.channel-tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s, color 0.2s;
  letter-spacing: 0.02em;
  text-transform: lowercase;
}

.channel-tab.active {
  background: var(--accent);
  color: var(--bg);
}

.channel-tab:not(.active):hover {
  color: var(--text);
}

/* ─── Hot-mic toggle ─── */
.hotmic-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s, border-color 0.2s;
}

.hotmic-toggle.active {
  color: var(--accent);
  border-color: var(--accent);
}

.hotmic-switch {
  width: 26px;
  height: 14px;
  border-radius: 999px;
  background: #333;
  position: relative;
  transition: background 0.2s;
}

.hotmic-toggle.active .hotmic-switch { background: var(--accent); }

.hotmic-knob {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.hotmic-toggle.active .hotmic-knob { transform: translateX(12px); }

.hotmic-timer {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--accent);
  margin-left: 2px;
}

/* ─── Stage (PTT + presence) ─── */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: 20px;
  gap: 32px;
  min-height: 0;
}

.ptt-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

/* ─── PTT button ─── */
.ptt {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--accent);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  box-shadow: 0 0 0 0 var(--accent-glow);
}

.ptt::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: all 0.2s;
  pointer-events: none;
}

.ptt-icon {
  width: 64px;
  height: 64px;
  transition: transform 0.15s;
}

/* State: TX (holding / hot-mic / locked) */
.ptt.tx {
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 0 40px var(--accent-glow);
  animation: pttPulse 1.2s ease-in-out infinite;
}
.ptt.tx .ptt-icon { transform: scale(1.1); }

@keyframes pttPulse {
  0%, 100% { box-shadow: 0 0 30px var(--accent-glow); }
  50%      { box-shadow: 0 0 60px var(--accent-glow); }
}

/* State: TX_LOCKED (distinct red ring) */
.ptt.locked::before {
  inset: -8px;
  border-color: var(--accent);
}

/* State: BUSY (other user transmitting) */
.ptt.busy {
  border-color: var(--text-dim);
  color: var(--text-dim);
  cursor: not-allowed;
  opacity: 0.5;
  background: rgba(30, 30, 30, 0.3);
}

/* State: RX (someone else transmitting to us, but we can still TX) */
.ptt.rx::before {
  inset: -6px;
  border-color: var(--rx-active);
  animation: rxPulse 0.8s ease-in-out infinite;
}
@keyframes rxPulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}

.status-label {
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
  min-height: 20px;
  letter-spacing: 0.02em;
}

.status-label.error { color: var(--lock); }
.status-label.active { color: var(--accent); }

/* ─── Presence list ─── */
.presence {
  width: 100%;
  max-width: 320px;
  background: var(--card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

.presence-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 12px;
}

.presence-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.presence-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px;
  border-radius: 8px;
  transition: background 0.15s;
}

.presence-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  position: relative;
}

.presence-avatar.tx {
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 0 12px var(--accent-glow);
}

.presence-avatar .tx-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--rx-active);
  border: 2px solid var(--bg);
  opacity: 0;
  transition: opacity 0.2s;
}

.presence-item.tx .presence-avatar .tx-dot { opacity: 1; }
.presence-item.tx .presence-avatar { background: var(--accent); color: var(--bg); }

.presence-name {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  text-transform: capitalize;
}

.presence-tag {
  font-size: 10px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.08em;
  opacity: 0;
  transition: opacity 0.2s;
}

.presence-item.tx .presence-tag { opacity: 1; }

.presence-empty {
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
  padding: 12px 0;
}

/* ─── Desktop layout (wider screens) ─── */
@media (min-width: 720px) {
  .ptt {
    width: 240px;
    height: 240px;
  }
  .ptt-icon {
    width: 88px;
    height: 88px;
  }
  .stage {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 48px;
  }
  .presence {
    max-width: 280px;
  }
}
