:root {
  --cream: #FFF8ED;
  --teal: #1B4B5A;
  --teal-light: #2E6B7C;
  --yellow: #FFC93C;
  --coral: #FF5A4E;
  --coral-dark: #E14536;
  --ink: #1A1A1A;
  --bubble: #E4F1F0;
  --line: rgba(27, 75, 90, 0.12);
  font-family: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--cream);
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; cursor: pointer; border: none; }
input { font-family: inherit; }

.screen { height: 100dvh; width: 100%; }
.hidden { display: none !important; }

/* ---------- Setup ---------- */
#setup {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 0%, var(--teal-light) 0%, var(--teal) 60%);
}

.setup-card {
  width: 100%;
  max-width: 420px;
  background: var(--cream);
  border-radius: 28px;
  padding: 32px 28px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  text-align: center;
}

.setup-logo { display: flex; align-items: center; justify-content: center; gap: 10px; }
.logo-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 0 5px rgba(255,90,78,0.18);
}
.setup-logo h1 {
  font-family: 'Baloo 2', sans-serif;
  font-size: 32px;
  font-weight: 800;
  color: var(--teal);
  margin: 0;
}
.setup-sub { color: var(--teal-light); font-weight: 700; margin: 4px 0 24px; }

.setup-step { display: flex; flex-direction: column; gap: 10px; }

.big-choice {
  display: flex; align-items: center; gap: 14px;
  background: white;
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 18px 20px;
  font-size: 17px;
  font-weight: 800;
  color: var(--teal);
  text-align: left;
  transition: transform .12s ease, border-color .12s ease;
}
.big-choice:active { transform: scale(0.97); border-color: var(--yellow); }
.choice-emoji { font-size: 26px; }

label {
  text-align: left;
  font-size: 13px;
  font-weight: 800;
  color: var(--teal-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 8px;
}

input[type="text"] {
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  background: white;
  outline: none;
}
input[type="text"]:focus { border-color: var(--yellow); }
#join-code { text-transform: uppercase; letter-spacing: 0.15em; text-align: center; }

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-top: 6px;
}
.avatar-option {
  font-size: 22px;
  padding: 8px 0;
  border-radius: 12px;
  background: white;
  border: 2px solid var(--line);
}
.avatar-option.selected { border-color: var(--coral); background: #FFEDEA; }

.color-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
  margin-top: 6px;
}
.color-option {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid transparent;
  padding: 0;
}
.color-option.selected {
  border-color: var(--ink);
  transform: scale(1.12);
}

.primary-btn {
  margin-top: 14px;
  background: var(--coral);
  color: white;
  font-weight: 800;
  font-size: 17px;
  padding: 16px;
  border-radius: 16px;
  box-shadow: 0 8px 20px rgba(255,90,78,0.35);
}
.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { opacity: 0.5; box-shadow: none; }

.text-btn {
  background: none;
  color: var(--teal-light);
  font-weight: 700;
  padding: 8px;
}

.setup-error {
  color: var(--coral-dark);
  font-weight: 700;
  font-size: 14px;
  margin-top: 10px;
}

.reveal-label { font-weight: 800; color: var(--teal-light); margin-bottom: 4px; }
.code-display {
  font-family: 'Baloo 2', sans-serif;
  font-size: 44px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--teal);
  background: var(--yellow);
  border-radius: 16px;
  padding: 14px 0;
  margin: 8px 0;
}
.reveal-hint { color: var(--teal-light); font-weight: 600; font-size: 14px; }

/* ---------- Main app ---------- */
#app {
  display: flex;
  flex-direction: column;
  background: var(--cream);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px;
  background: var(--user-color, var(--teal));
  color: white;
  border-radius: 0 0 20px 20px;
  transition: background .25s ease;
}
.whoami-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  border: 2px solid rgba(255,255,255,0.55);
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.whoami-btn:active { transform: scale(0.92); }
.channel-info { display: flex; align-items: center; gap: 8px; font-family: 'Baloo 2', sans-serif; font-weight: 700; font-size: 16px; flex: 1; justify-content: center; }
.channel-dot {
  width: 10px; height: 10px; border-radius: 50%; background: #6EE7B7;
  box-shadow: 0 0 0 4px rgba(110,231,183,0.25);
}
.member-chips { display: flex; gap: 4px; font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.settings-btn {
  background: rgba(255,255,255,0.12);
  border-radius: 50%;
  width: 34px; height: 34px;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.settings-btn:active { transform: scale(0.92); }

.feed {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.feed-empty {
  margin: auto;
  text-align: center;
  color: var(--teal-light);
  font-weight: 700;
  padding: 0 30px;
}
.feed-empty-emoji { font-size: 40px; display: block; margin-bottom: 8px; }

.bubble {
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  border-radius: 18px;
  padding: 12px 14px;
  max-width: 82%;
  box-shadow: 0 2px 8px rgba(27,75,90,0.08);
}
.bubble.mine {
  align-self: flex-end;
  background: var(--bubble);
  border-left: 4px solid var(--user-color, var(--coral));
}
.bubble-avatar { font-size: 26px; }
.bubble-body { flex: 1; min-width: 0; }
.bubble-name { font-weight: 800; font-size: 13px; color: var(--teal); }
.bubble-play {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--teal);
  color: white;
  font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.bubble-play.playing { background: var(--coral); }
.bubble-meta { font-size: 11px; color: var(--teal-light); font-weight: 700; margin-top: 2px; }
.bubble-target-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  color: var(--teal);
  background: var(--yellow);
  border-radius: 8px;
  padding: 1px 7px;
  margin-top: 3px;
}
.bubble.for-me { box-shadow: 0 0 0 2px var(--yellow), 0 2px 8px rgba(27,75,90,0.08); }

.bubble { position: relative; }
.bubble.unread { background: #FFFDF5; }
.unread-dot {
  position: absolute;
  top: 10px; left: -5px;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 0 3px rgba(255,90,78,0.22);
}
.bubble-delete {
  background: none;
  color: var(--teal-light);
  opacity: 0.45;
  font-size: 15px;
  font-weight: 800;
  padding: 4px 8px;
  flex-shrink: 0;
}
.bubble-delete:active { opacity: 1; color: var(--coral-dark); }

.unread-badge {
  background: var(--coral);
  color: white;
  font-size: 12px;
  font-weight: 800;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
}
.unread-badge.hidden { display: none; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 15px;
  color: var(--teal);
  margin-top: 0;
}
.toggle-hint {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--teal-light);
  text-transform: none;
  letter-spacing: 0;
  margin-top: 2px;
}
#autoplay-toggle {
  width: 24px; height: 24px;
  accent-color: var(--coral);
  flex-shrink: 0;
}

/* ---------- Recipient row ---------- */
.recipient-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 16px 2px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.recipient-row::-webkit-scrollbar { display: none; }
.recipient-chip {
  display: flex; align-items: center; gap: 6px;
  flex-shrink: 0;
  background: white;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px 6px 8px;
  font-weight: 800;
  font-size: 13px;
  color: var(--teal-light);
}
.recipient-chip .chip-emoji { font-size: 16px; }
.recipient-chip.selected {
  border-color: var(--coral);
  background: #FFEDEA;
  color: var(--coral-dark);
}

/* ---------- PTT dock ---------- */
.ptt-dock {
  padding: 18px 0 max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: linear-gradient(to top, var(--cream) 60%, transparent);
}

.ptt-wrap {
  position: relative;
  width: 132px;
  height: 132px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ptt-rings {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}
.ptt-rings::before, .ptt-rings::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--coral);
  opacity: 0;
}
.recording .ptt-rings::before {
  animation: ring-pulse 1.4s ease-out infinite;
}
.recording .ptt-rings::after {
  animation: ring-pulse 1.4s ease-out infinite;
  animation-delay: 0.5s;
}
@keyframes ring-pulse {
  0% { transform: scale(0.9); opacity: 0.55; }
  100% { transform: scale(1.6); opacity: 0; }
}

.ptt-btn {
  position: relative;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--user-color-light, var(--teal-light)), var(--user-color, var(--teal)) 70%);
  box-shadow: 0 10px 24px rgba(27,75,90,0.35), inset 0 0 0 5px rgba(255,255,255,0.08);
  transition: transform .1s ease, background .25s ease;
}
.ptt-btn:active { transform: scale(0.95); }
.recording .ptt-btn {
  background: radial-gradient(circle at 35% 30%, var(--coral), var(--coral-dark) 70%);
}

.ptt-grille {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
}
.ptt-grille span {
  width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255,255,255,0.35);
}
.recording .ptt-grille span { background: rgba(255,255,255,0.85); }

.ptt-hint {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  color: var(--teal-light);
  font-size: 14px;
}
.recording ~ .ptt-hint,
.ptt-dock.recording .ptt-hint { color: var(--coral-dark); }

/* ---------- Settings sheet ---------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(27,75,90,0.45);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
.sheet-overlay.hidden { display: none; }

.sheet {
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--cream);
  border-radius: 24px 24px 0 0;
  padding: 12px 24px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sheet-handle {
  width: 40px; height: 5px;
  background: var(--line);
  border-radius: 3px;
  margin: 0 auto 10px;
}
.sheet h2 {
  font-family: 'Baloo 2', sans-serif;
  color: var(--teal);
  margin: 0 0 4px;
}
.sheet-divider {
  height: 1px;
  background: var(--line);
  margin: 14px 0;
}
.code-display.small { font-size: 28px; padding: 10px 0; }
.saved-msg { color: #2E9E5B; font-weight: 800; text-align: center; margin: 6px 0 0; }

.danger-btn {
  background: white;
  border: 2px solid var(--coral);
  color: var(--coral-dark);
  font-weight: 800;
  padding: 14px;
  border-radius: 14px;
}
.danger-btn:active { transform: scale(0.98); }

.profile-list { display: flex; flex-direction: column; gap: 8px; }
.profile-row {
  display: flex; align-items: center;
  background: white;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 4px 6px 4px 14px;
}
.profile-row.active { border-color: var(--coral); background: #FFEDEA; }
.profile-row-main {
  display: flex; align-items: center; gap: 12px;
  flex: 1;
  background: none;
  padding: 8px 0;
  font-weight: 800;
  color: var(--teal);
  text-align: left;
}
.profile-avatar { font-size: 24px; }
.profile-active-tag {
  margin-left: auto;
  font-size: 11px;
  background: var(--coral);
  color: white;
  padding: 3px 8px;
  border-radius: 8px;
}
.profile-row-remove {
  background: none;
  color: var(--teal-light);
  opacity: 0.45;
  font-size: 14px;
  font-weight: 800;
  padding: 8px 10px;
  flex-shrink: 0;
}
.profile-row-remove:active { opacity: 1; color: var(--coral-dark); }
