/* ==========================================================
   VoiceServer — modern dark UI
   ========================================================== */

:root {
  --bg-0: #07090f;
  --bg-1: rgba(17, 20, 27, .72);
  --bg-2: rgba(22, 26, 35, .78);
  --bg-3: rgba(29, 34, 45, .85);
  --bg-4: rgba(37, 43, 56, .9);
  --line: rgba(124,92,255,.22);
  --line-strong: rgba(124,92,255,.45);
  --text: #e6e9ef;
  --text-dim: #a0a7b7;
  --text-mute: #6c7388;

  /* Neon accent palette */
  --neon-purple: #b46aff;
  --neon-cyan: #00e5ff;
  --neon-pink: #ff4dd2;
  --neon-green: #00ff9d;
  --neon-yellow: #ffd93d;
  --neon-red: #ff3b6b;

  --accent: var(--neon-purple);
  --accent-2: var(--neon-cyan);
  --accent-grad: linear-gradient(135deg, var(--neon-purple) 0%, var(--neon-cyan) 100%);
  --accent-grad-3: linear-gradient(135deg, var(--neon-pink) 0%, var(--neon-purple) 50%, var(--neon-cyan) 100%);

  --green: var(--neon-green);
  --red: var(--neon-red);
  --yellow: var(--neon-yellow);

  --glow-purple: 0 0 18px rgba(180,106,255,.55), 0 0 38px rgba(180,106,255,.25);
  --glow-cyan: 0 0 16px rgba(0,229,255,.5), 0 0 32px rgba(0,229,255,.2);
  --glow-green: 0 0 14px rgba(0,255,157,.55), 0 0 30px rgba(0,255,157,.2);
  --glow-pink: 0 0 16px rgba(255,77,210,.55), 0 0 30px rgba(255,77,210,.2);

  --shadow-1: 0 4px 14px rgba(0,0,0,.45);
  --shadow-2: 0 10px 40px rgba(0,0,0,.65);

  --radius: 12px;
  --radius-sm: 8px;
  --veil-hot: rgba(20,184,166,.16);
  --veil-cool: rgba(74,107,255,.14);
  --veil-top: rgba(7,9,15,.55);
  --veil-mid: rgba(7,9,15,.85);
  --veil-bottom: rgba(7,9,15,.95);
  --art-saturation: 1.12;
  --art-contrast: 1.05;
  --art-brightness: .92;

  /* Font families */
  --font-ui: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --font-game: 'Orbitron', 'Rajdhani', sans-serif;
  --font-tactical: 'Rajdhani', 'Inter', sans-serif;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
/* solid fallback lives on html only — body must stay transparent so the
   .bg-layer at z-index -3 paints through */
html { background: var(--bg-0); }
body { background: transparent; }

/* ===== Background layers (theme artwork lives under public/assets/themes) ===== */
.bg-layer {
  position: fixed; inset: 0;
  z-index: -3;
  background: var(--bg-0);
  background-size: cover;
  background-position: center;
  transition: opacity 1.2s ease, background-image 1.2s ease;
  filter: saturate(var(--art-saturation)) contrast(var(--art-contrast)) brightness(var(--art-brightness));
  transform: scale(1.04);
}
.bg-veil {
  position: fixed; inset: 0;
  z-index: -2; pointer-events: none;
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--veil-hot), transparent 55%),
    radial-gradient(900px 500px at 110% 110%, var(--veil-cool), transparent 55%),
    linear-gradient(180deg, var(--veil-top), var(--veil-mid) 65%, var(--veil-bottom));
}
body.has-bg .bg-layer { animation: bgPulse 12s ease-in-out infinite; }
@keyframes bgPulse {
  0%, 100% { transform: scale(1.04); filter: saturate(var(--art-saturation)) contrast(var(--art-contrast)) brightness(var(--art-brightness)); }
  50%      { transform: scale(1.07); filter: saturate(calc(var(--art-saturation) + .08)) contrast(calc(var(--art-contrast) + .04)) brightness(calc(var(--art-brightness) + .06)); }
}

.hidden { display: none !important; }

/* Section headings get the game font */
h1, h2, h3 { font-family: var(--font-tactical); letter-spacing: .02em; }

/* ===================================================================
   THEME BAR (always visible, hot-swap any theme)
   =================================================================== */
.theme-bar {
  position: fixed;
  top: 12px;
  left: 420px;
  z-index: 1100;
}
.theme-trigger {
  display: inline-flex; align-items: center; gap: 10px;
  background: rgba(17,20,27,.72);
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-tactical);
  font-weight: 700; font-size: 12px;
  letter-spacing: .12em; text-transform: uppercase;
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  box-shadow: var(--shadow-1);
  transition: border-color .15s, box-shadow .2s, transform .12s;
}
.theme-trigger:hover { transform: translateY(-1px); box-shadow: var(--shadow-1), var(--glow-purple); border-color: var(--accent); }
.theme-swatch {
  width: 14px; height: 14px; border-radius: 4px;
  background: var(--accent-grad);
  box-shadow: var(--glow-purple);
}
.theme-caret { font-size: 10px; opacity: .75; }

.theme-menu {
  position: absolute; top: calc(100% + 8px); left: 0;
  min-width: 220px;
  background: linear-gradient(180deg, rgba(22,26,35,.95), rgba(17,20,27,.98));
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 6px;
  box-shadow: var(--shadow-2), var(--glow-purple);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  animation: fadeUp .14s ease;
}
.theme-menu button {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-family: var(--font-tactical);
  font-size: 13px; font-weight: 600;
  letter-spacing: .05em;
  cursor: pointer;
  text-align: left;
  transition: background .12s, border-color .12s, transform .1s;
}
.theme-menu button:hover { background: var(--bg-3); border-color: var(--line); transform: translateX(2px); }
.theme-menu button.active {
  background: rgba(124,92,255,.12);
  border-color: var(--line-strong);
  color: var(--accent);
}
.theme-menu .tm-swatch {
  width: 18px; height: 18px; border-radius: 5px;
  flex-shrink: 0;
}
.theme-notice {
  position: absolute;
  top: 0;
  left: calc(100% + 10px);
  width: min(300px, calc(100vw - 24px));
  background: linear-gradient(180deg, rgba(22,26,35,.96), rgba(12,15,22,.98));
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 12px;
  box-shadow: var(--shadow-2), var(--glow-cyan);
  color: var(--text);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  animation: fadeUp .16s ease;
}
.theme-notice::before {
  content: '';
  position: absolute;
  top: 14px;
  left: -6px;
  width: 10px;
  height: 10px;
  background: inherit;
  border-left: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  transform: rotate(45deg);
}
.theme-notice-title {
  font-family: var(--font-tactical);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent-2);
  margin-bottom: 5px;
}
.theme-notice-body {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.theme-notice button {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--accent-grad);
  color: #fff;
  font-family: var(--font-tactical);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 7px 10px;
  cursor: pointer;
}

/* ===================================================================
   PER-THEME OVERRIDES
   Each theme remaps the design tokens. Every component that uses these
   tokens automatically restyles on theme change — no per-component CSS.
   =================================================================== */

/* ----- DEFAULT (modern, no background artwork) ----- */
body[data-theme="default"] {
  --bg-0: #0a0f17;
  --bg-1: rgba(15, 23, 34, .76);
  --bg-2: rgba(20, 29, 42, .82);
  --bg-3: rgba(29, 40, 56, .88);
  --bg-4: rgba(39, 52, 70, .92);
  --neon-purple: #4f7cff;
  --neon-cyan:   #14b8a6;
  --neon-pink:   #8b5cf6;
  --neon-green:  #22c55e;
  --neon-yellow: #fbbf24;
  --neon-red:    #fb7185;
  --accent:      #14b8a6;
  --accent-2:    #7dd3fc;
  --accent-grad: linear-gradient(135deg, #14b8a6 0%, #4f7cff 100%);
  --accent-grad-3: linear-gradient(135deg, #14b8a6, #4f7cff, #8b5cf6);
  --line:        rgba(125,211,252,.22);
  --line-strong: rgba(20,184,166,.48);
  --glow-purple: 0 0 16px rgba(79,124,255,.42), 0 0 34px rgba(79,124,255,.16);
  --glow-cyan:   0 0 16px rgba(20,184,166,.48), 0 0 32px rgba(20,184,166,.18);
  --font-game:     'Inter', system-ui, sans-serif;
  --font-tactical: 'Rajdhani', 'Inter', sans-serif;
  --veil-hot: rgba(20,184,166,.14);
  --veil-cool: rgba(79,124,255,.12);
  --veil-top: rgba(10,15,23,.62);
  --veil-mid: rgba(10,15,23,.86);
  --veil-bottom: rgba(10,15,23,.96);
  --art-saturation: 1;
  --art-contrast: 1;
  --art-brightness: 1;
  --radius: 10px; --radius-sm: 7px;
}

/* ----- HALO (UNSC blue / Spartan orange / sharp military) ----- */
body[data-theme="halo"] {
  --bg-1: rgba(8, 16, 25, .76);
  --bg-2: rgba(10, 25, 40, .82);
  --bg-3: rgba(14, 35, 55, .88);
  --bg-4: rgba(20, 49, 74, .92);
  --neon-purple: #4a9fff;
  --neon-cyan:   #00d4ff;
  --neon-pink:   #ff7733;
  --neon-green:  #7fff66;
  --neon-yellow: #ffd66e;
  --neon-red:    #ff3333;
  --accent:      var(--neon-purple);
  --accent-2:    var(--neon-cyan);
  --accent-grad: linear-gradient(135deg, #4a9fff 0%, #00d4ff 60%, #ff7733 100%);
  --accent-grad-3: linear-gradient(135deg, #ff7733, #4a9fff, #00d4ff);
  --line:        rgba(74,159,255,.28);
  --line-strong: rgba(74,159,255,.55);
  --glow-purple: 0 0 16px rgba(74,159,255,.55), 0 0 36px rgba(74,159,255,.22);
  --glow-cyan:   0 0 14px rgba(0,212,255,.55), 0 0 30px rgba(0,212,255,.22);
  --font-game:     'Share Tech Mono', 'Orbitron', monospace;
  --font-tactical: 'Share Tech Mono', 'Rajdhani', monospace;
  --veil-hot: rgba(74,159,255,.20);
  --veil-cool: rgba(255,119,51,.12);
  --veil-top: rgba(4,9,15,.58);
  --veil-mid: rgba(4,9,15,.86);
  --veil-bottom: rgba(4,9,15,.96);
  --art-saturation: 1.08;
  --art-contrast: 1.08;
  --art-brightness: .88;
  --radius: 4px; --radius-sm: 2px;
}

/* ----- RUST (industrial orange / rugged / sharp) ----- */
body[data-theme="rust"] {
  --bg-1: rgba(23, 15, 9, .78);
  --bg-2: rgba(34, 22, 13, .84);
  --bg-3: rgba(50, 31, 18, .9);
  --bg-4: rgba(65, 40, 22, .94);
  --neon-purple: #c4621a;
  --neon-cyan:   #d4a017;
  --neon-pink:   #8a3a14;
  --neon-green:  #7a8a3a;
  --neon-yellow: #d4a017;
  --neon-red:    #b81a1a;
  --accent:      #c4621a;
  --accent-2:    #d4a017;
  --accent-grad:   linear-gradient(135deg, #c4621a 0%, #5a2a08 100%);
  --accent-grad-3: linear-gradient(135deg, #d4a017, #c4621a, #5a2a08);
  --line:        rgba(196,98,26,.25);
  --line-strong: rgba(196,98,26,.55);
  --glow-purple: 0 0 14px rgba(196,98,26,.5), 0 0 28px rgba(196,98,26,.2);
  --glow-cyan:   0 0 14px rgba(212,160,23,.5), 0 0 28px rgba(212,160,23,.18);
  --font-game:     'Bebas Neue', 'Oswald', 'Impact', sans-serif;
  --font-tactical: 'Oswald', 'Bebas Neue', sans-serif;
  --veil-hot: rgba(196,98,26,.20);
  --veil-cool: rgba(212,160,23,.10);
  --veil-top: rgba(12,8,5,.60);
  --veil-mid: rgba(12,8,5,.87);
  --veil-bottom: rgba(12,8,5,.97);
  --art-saturation: 1.08;
  --art-contrast: 1.12;
  --art-brightness: .84;
  --radius: 3px; --radius-sm: 2px;
}

/* ----- FORTNITE (bouncy purple/blue/yellow) ----- */
body[data-theme="fortnite"] {
  --bg-1: rgba(20, 12, 38, .76);
  --bg-2: rgba(29, 18, 52, .82);
  --bg-3: rgba(43, 27, 75, .88);
  --bg-4: rgba(57, 36, 96, .92);
  --neon-purple: #b46aff;
  --neon-cyan:   #2ec4ff;
  --neon-pink:   #ff4dd2;
  --neon-green:  #2ed573;
  --neon-yellow: #ffd84d;
  --neon-red:    #ff4d4d;
  --accent:      var(--neon-purple);
  --accent-2:    var(--neon-cyan);
  --accent-grad:   linear-gradient(135deg, #b46aff 0%, #2ec4ff 50%, #ffd84d 100%);
  --accent-grad-3: linear-gradient(135deg, #ff4dd2, #b46aff, #2ec4ff);
  --glow-purple: 0 0 22px rgba(180,106,255,.6), 0 0 44px rgba(180,106,255,.25);
  --glow-cyan:   0 0 18px rgba(46,196,255,.55), 0 0 36px rgba(46,196,255,.22);
  --font-game:     'Fredoka', 'Rajdhani', sans-serif;
  --font-tactical: 'Fredoka', 'Inter', sans-serif;
  --veil-hot: rgba(180,106,255,.18);
  --veil-cool: rgba(46,196,255,.16);
  --veil-top: rgba(10,8,20,.58);
  --veil-mid: rgba(10,8,20,.86);
  --veil-bottom: rgba(10,8,20,.96);
  --art-saturation: 1.16;
  --art-contrast: 1.04;
  --art-brightness: .86;
  --radius: 16px; --radius-sm: 10px;
}

/* ----- LEGO FORTNITE (primary colors, chunky) ----- */
body[data-theme="lego-fortnite"] {
  --bg-1: rgba(15, 22, 34, .76);
  --bg-2: rgba(22, 32, 48, .82);
  --bg-3: rgba(30, 43, 63, .88);
  --bg-4: rgba(41, 57, 82, .92);
  --neon-purple: #e53935;
  --neon-cyan:   #1e88e5;
  --neon-pink:   #ec407a;
  --neon-green:  #43a047;
  --neon-yellow: #fdd835;
  --neon-red:    #e53935;
  --accent:      #fdd835;
  --accent-2:    #1e88e5;
  --accent-grad:   linear-gradient(135deg, #fdd835 0%, #e53935 50%, #1e88e5 100%);
  --accent-grad-3: linear-gradient(135deg, #fdd835, #43a047, #1e88e5, #e53935);
  --line:        rgba(253,216,53,.32);
  --line-strong: rgba(253,216,53,.6);
  --glow-purple: 0 0 14px rgba(253,216,53,.55), 0 0 28px rgba(229,57,53,.2);
  --glow-cyan:   0 0 14px rgba(30,136,229,.55), 0 0 28px rgba(30,136,229,.2);
  --font-game:     'Fredoka', 'Comic Sans MS', sans-serif;
  --font-tactical: 'Fredoka', sans-serif;
  --veil-hot: rgba(253,216,53,.15);
  --veil-cool: rgba(30,136,229,.18);
  --veil-top: rgba(8,12,18,.58);
  --veil-mid: rgba(8,12,18,.86);
  --veil-bottom: rgba(8,12,18,.96);
  --art-saturation: 1.12;
  --art-contrast: 1.06;
  --art-brightness: .86;
  --radius: 14px; --radius-sm: 8px;
}

/* ----- HOGWARTS LEGACY (purple/gold/parchment/ornate) ----- */
body[data-theme="hogwarts"] {
  --bg-1: rgba(20, 12, 26, .78);
  --bg-2: rgba(31, 20, 37, .84);
  --bg-3: rgba(45, 29, 52, .9);
  --bg-4: rgba(61, 39, 69, .94);
  --neon-purple: #8a3da0;
  --neon-cyan:   #d4af37;
  --neon-pink:   #c44a8a;
  --neon-green:  #4a8a3a;
  --neon-yellow: #f0d870;
  --neon-red:    #b03030;
  --accent:      #8a3da0;
  --accent-2:    #d4af37;
  --accent-grad:   linear-gradient(135deg, #8a3da0 0%, #d4af37 100%);
  --accent-grad-3: linear-gradient(135deg, #8a3da0, #6a2c8a, #d4af37);
  --line:        rgba(212,175,55,.28);
  --line-strong: rgba(212,175,55,.55);
  --glow-purple: 0 0 18px rgba(138,61,160,.55), 0 0 36px rgba(138,61,160,.22);
  --glow-cyan:   0 0 16px rgba(212,175,55,.55), 0 0 32px rgba(212,175,55,.22);
  --font-game:     'MedievalSharp', 'Cinzel', serif;
  --font-tactical: 'Cinzel', 'Times New Roman', serif;
  --veil-hot: rgba(138,61,160,.18);
  --veil-cool: rgba(212,175,55,.12);
  --veil-top: rgba(11,8,14,.60);
  --veil-mid: rgba(11,8,14,.88);
  --veil-bottom: rgba(11,8,14,.97);
  --art-saturation: 1.06;
  --art-contrast: 1.08;
  --art-brightness: .84;
  --radius: 6px; --radius-sm: 3px;
}

/* ----- WINDROSE (brass / teal / nautical sunset) ----- */
body[data-theme="windrose"] {
  --bg-1: rgba(11, 22, 27, .78);
  --bg-2: rgba(15, 33, 40, .84);
  --bg-3: rgba(21, 47, 57, .9);
  --bg-4: rgba(28, 62, 74, .94);
  --neon-purple: #d49b00;
  --neon-cyan:   #4ab3b3;
  --neon-pink:   #c44a1a;
  --neon-green:  #5a8a4a;
  --neon-yellow: #f0c060;
  --neon-red:    #b03a1a;
  --accent:      #d49b00;
  --accent-2:    #4ab3b3;
  --accent-grad:   linear-gradient(135deg, #d49b00 0%, #c44a1a 60%, #4ab3b3 100%);
  --accent-grad-3: linear-gradient(135deg, #4ab3b3, #d49b00, #c44a1a);
  --line:        rgba(212,155,0,.28);
  --line-strong: rgba(212,155,0,.55);
  --glow-purple: 0 0 16px rgba(212,155,0,.55), 0 0 32px rgba(212,155,0,.22);
  --glow-cyan:   0 0 14px rgba(74,179,179,.55), 0 0 28px rgba(74,179,179,.22);
  --font-game:     'Cinzel', 'Orbitron', serif;
  --font-tactical: 'Cinzel', 'Rajdhani', serif;
  --veil-hot: rgba(212,155,0,.18);
  --veil-cool: rgba(74,179,179,.16);
  --veil-top: rgba(6,12,15,.60);
  --veil-mid: rgba(6,12,15,.88);
  --veil-bottom: rgba(6,12,15,.97);
  --art-saturation: 1.08;
  --art-contrast: 1.08;
  --art-brightness: .84;
  --radius: 8px; --radius-sm: 4px;
}

/* Smooth fades when switching themes */
.app, .sidebar, .main, .settings, .voice-cta, .server-icon, .send-btn,
.msg-author, .avatar, .overlay-card, .pill, .meter-fill, .reaction-pill,
.sticker-tray, .theme-menu, .theme-trigger {
  transition: background .35s ease, border-color .35s ease, color .35s ease, box-shadow .35s ease;
}

/* ===== Overlay: username gate ===== */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(8px);
  background: radial-gradient(800px 400px at 50% 30%, rgba(124,92,255,.10), transparent 60%), rgba(8,10,14,.65);
}
.overlay-card {
  position: relative;
  width: 420px; max-width: calc(100vw - 32px);
  background:
    linear-gradient(180deg, rgba(22,26,35,.85), rgba(17,20,27,.92));
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  padding: 32px 28px 22px;
  box-shadow: var(--shadow-2), var(--glow-purple);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
}
.overlay-card::before {
  content: ''; position: absolute; inset: -1px;
  border-radius: 18px;
  padding: 1px;
  background: var(--accent-grad-3);
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  opacity: .55;
  pointer-events: none;
  animation: borderShift 6s linear infinite;
}
@keyframes borderShift {
  0%, 100% { filter: hue-rotate(0deg); }
  50%      { filter: hue-rotate(40deg); }
}
.overlay-logo {
  display: flex; align-items: center; gap: 12px; margin-bottom: 6px;
}
.overlay-logo h1 {
  font-family: var(--font-game);
  font-size: 22px; font-weight: 800; letter-spacing: .14em;
  margin: 0; text-transform: uppercase;
  background: var(--accent-grad);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  text-shadow: 0 0 24px rgba(180,106,255,.35);
}
.logo-dot {
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent-grad);
  box-shadow: var(--glow-purple);
  animation: logoPulse 3s ease-in-out infinite;
}
@keyframes logoPulse {
  0%, 100% { box-shadow: var(--glow-purple); }
  50%      { box-shadow: var(--glow-cyan); }
}
.overlay-sub { color: var(--text-dim); margin: 0 0 22px; font-size: 14px; }
.input-wrap {
  position: relative;
  display: flex; align-items: center;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  transition: border-color .15s, box-shadow .15s;
}
.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124,92,255,.15);
}
.input-wrap i { color: var(--text-mute); margin-right: 8px; font-size: 16px; }
#username-input {
  background: transparent; border: 0; outline: 0;
  color: var(--text); font: inherit; font-size: 15px;
  padding: 14px 0; flex: 1;
}
.status-line {
  font-size: 12px; color: var(--text-mute); margin: 10px 2px 18px;
  display: flex; align-items: center; gap: 6px; min-height: 16px;
}
.status-line.ok { color: var(--green); }
.status-line.bad { color: var(--red); }
.status-line .spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.15); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#username-submit {
  position: relative; overflow: hidden;
  width: 100%;
  background: var(--accent-grad);
  color: white; border: 0; border-radius: var(--radius);
  padding: 14px 16px; font: inherit; font-weight: 700; font-size: 15px;
  letter-spacing: .04em; text-transform: uppercase;
  font-family: var(--font-tactical);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer;
  box-shadow: var(--glow-purple);
  transition: transform .12s, opacity .12s, box-shadow .2s, filter .2s;
}
#username-submit:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.1); box-shadow: var(--glow-cyan); }
#username-submit:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
#username-submit::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 35%, rgba(255,255,255,.35) 50%, transparent 65%);
  transform: translateX(-100%);
  transition: transform .8s;
}
#username-submit:hover:not(:disabled)::after { transform: translateX(100%); }
.overlay-foot {
  margin-top: 18px; font-size: 12px; color: var(--text-mute); text-align: center;
}

/* ===== Auth tabs / panels ===== */
.auth-tabs {
  display: flex; gap: 4px;
  margin: 8px 0 18px;
  padding: 4px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.auth-tab {
  flex: 1; padding: 8px 10px;
  background: transparent; border: 0; cursor: pointer;
  color: var(--text-dim); font: inherit; font-size: 13px; font-weight: 600;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.active {
  color: white;
  background: var(--accent-grad);
  box-shadow: var(--glow-purple);
}

.auth-panel .input-wrap { margin-bottom: 10px; }
.auth-panel .input-wrap:last-of-type { margin-bottom: 0; }
.auth-panel input[type="text"],
.auth-panel input[type="password"] {
  background: transparent; border: 0; outline: 0;
  color: var(--text); font: inherit; font-size: 15px;
  padding: 14px 0; flex: 1; min-width: 0;
}
.auth-panel .status-line { margin: 10px 2px 14px; }

.auth-submit {
  position: relative; overflow: hidden;
  width: 100%;
  background: var(--accent-grad);
  color: white; border: 0; border-radius: var(--radius);
  padding: 14px 16px; font: inherit; font-weight: 700; font-size: 15px;
  letter-spacing: .04em; text-transform: uppercase;
  font-family: var(--font-tactical);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer;
  box-shadow: var(--glow-purple);
  transition: transform .12s, opacity .12s, box-shadow .2s, filter .2s;
}
.auth-submit:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.1); box-shadow: var(--glow-cyan); }
.auth-submit:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.auth-submit::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 35%, rgba(255,255,255,.35) 50%, transparent 65%);
  transform: translateX(-100%);
  transition: transform .8s;
}
.auth-submit:hover:not(:disabled)::after { transform: translateX(100%); }

/* ===== One-time safekey display ===== */
.safekey-panel .safekey-headline {
  color: var(--text); font-size: 14px; line-height: 1.5;
  margin: 8px 0 16px;
}
.safekey-display {
  display: flex; align-items: stretch; gap: 8px;
  margin-bottom: 14px;
}
.safekey-display code {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 14px 12px;
  font-family: 'Share Tech Mono', ui-monospace, monospace;
  font-size: 15px; letter-spacing: .04em;
  color: var(--text);
  user-select: all;
  word-break: break-all;
  text-align: center;
}
.safekey-copy {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text-dim); font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.safekey-copy:hover { color: var(--text); border-color: var(--accent); }
.safekey-ack {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 0 18px;
  font-size: 13px; color: var(--text-dim);
  cursor: pointer;
}
.safekey-ack input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent, #7c5cff);
  cursor: pointer;
}

/* ===== Settings drawer: sign out ===== */
.account-sign-out {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text-dim); font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.account-sign-out:hover {
  color: var(--red, #ff5b5b);
  border-color: var(--red, #ff5b5b);
  background: rgba(255, 91, 91, .08);
}

/* ===== App layout ===== */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}
.app.with-settings { grid-template-columns: 280px 1fr 340px; }

/* ===== Sidebar ===== */
.sidebar {
  background: var(--bg-1);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-width: 0;
  position: relative;
}
.sidebar::after {
  content: ''; position: absolute;
  top: 0; right: 0; bottom: 0; width: 1px;
  background: linear-gradient(180deg, transparent, var(--neon-purple), var(--neon-cyan), transparent);
  opacity: .55;
  pointer-events: none;
}
.server-head {
  padding: 16px 16px 14px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--line);
}
.server-icon {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 18px;
  box-shadow: var(--glow-purple);
  position: relative;
}
.server-icon::after {
  content: ''; position: absolute; inset: -2px;
  border-radius: 13px;
  background: conic-gradient(from 0deg, var(--neon-purple), var(--neon-cyan), var(--neon-pink), var(--neon-purple));
  z-index: -1;
  filter: blur(6px); opacity: .5;
  animation: spin 4s linear infinite;
}
.server-title {
  font-family: var(--font-game);
  font-weight: 700; font-size: 14px;
  letter-spacing: .1em; text-transform: uppercase;
}
.server-sub { color: var(--text-mute); font-size: 11px; letter-spacing: .04em; }

.section-label {
  display: flex; align-items: center; gap: 8px;
  padding: 16px 16px 8px;
  color: var(--neon-cyan); text-transform: uppercase;
  font-family: var(--font-tactical);
  font-size: 11px; letter-spacing: .16em; font-weight: 700;
  text-shadow: 0 0 8px rgba(0,229,255,.4);
}

.voice-cta-wrap { padding: 0 12px 6px; }
.voice-cta {
  position: relative; overflow: hidden;
  width: 100%;
  background: var(--accent-grad);
  color: white; border: 0; border-radius: 10px;
  padding: 11px 14px; cursor: pointer;
  font-family: var(--font-tactical);
  font-size: 13px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: var(--glow-purple);
  transition: transform .12s, box-shadow .2s, background .2s, filter .2s;
}
.voice-cta:hover { transform: translateY(-1px); filter: brightness(1.1); }
.voice-cta::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 35%, rgba(255,255,255,.35) 50%, transparent 65%);
  transform: translateX(-100%); transition: transform .8s;
}
.voice-cta:hover::after { transform: translateX(100%); }
.voice-cta.connecting { opacity: .8; cursor: progress; }
.voice-cta.connected {
  background: linear-gradient(135deg, var(--neon-green), #00b370);
  box-shadow: var(--glow-green);
}
.voice-cta.connected:hover {
  background: linear-gradient(135deg, var(--neon-red), #c2002e);
  box-shadow: 0 0 18px rgba(255,59,107,.55), 0 0 38px rgba(255,59,107,.25);
}
.voice-cta-hint {
  font-size: 11px; color: var(--text-mute);
  margin-top: 6px; padding: 0 2px; line-height: 1.4;
}

.user-list { flex: 1; overflow-y: auto; padding: 0 8px 10px; }
.user-row .user-sub { transition: color .2s; }
.user-row.in-voice .user-sub { color: var(--green); }
.user-row.away .avatar { filter: grayscale(.6) brightness(.7); }
.user-row.away .user-name { opacity: .65; }
.user-row.away .user-sub { color: var(--yellow); }

/* ===== Theme badge next to usernames ===== */
.theme-badge {
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: 6px;
  vertical-align: middle;
  line-height: 0;
  transform: translateY(-1px);
  transition: filter .2s;
}
.theme-badge svg { width: 14px; height: 14px; display: block; }
.msg-author .theme-badge { margin-left: 4px; transform: translateY(-1px); }

.theme-badge.t-default   { color: #b46aff; filter: drop-shadow(0 0 4px rgba(180,106,255,.55)); }
.theme-badge.t-halo      { color: #4a9fff; filter: drop-shadow(0 0 4px rgba(74,159,255,.55)); }
.theme-badge.t-rust      { color: #c4621a; filter: drop-shadow(0 0 4px rgba(196,98,26,.55)); }
.theme-badge.t-windrose  { color: #d49b00; filter: drop-shadow(0 0 4px rgba(212,155,0,.55)); }
.theme-badge.t-fortnite  { color: #ffd84d; filter: drop-shadow(0 0 4px rgba(255,216,77,.55)); }
.theme-badge.t-lego-fortnite { color: #fdd835; filter: drop-shadow(0 0 4px rgba(253,216,53,.55)); }
.theme-badge.t-hogwarts  { color: #d4af37; filter: drop-shadow(0 0 4px rgba(212,175,55,.55)); }

.user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: default;
  transition: background .12s;
}
.user-row:hover { background: var(--bg-2); }

.voice-ring {
  position: relative;
  width: 38px; height: 38px;
  border-radius: 50%;
  padding: 2px;
  background: transparent;
  transition: background .15s, box-shadow .2s;
  flex-shrink: 0;
}
.voice-ring.speaking {
  background: var(--neon-green);
  box-shadow: var(--glow-green);
  animation: speakingPulse 1.2s ease-in-out infinite;
}
@keyframes speakingPulse {
  0%, 100% { box-shadow: var(--glow-green); }
  50%      { box-shadow: 0 0 22px rgba(0,255,157,.85), 0 0 44px rgba(0,255,157,.35); }
}
.avatar {
  width: 100%; height: 100%; border-radius: 50%;
  background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white; font-size: 13px;
  letter-spacing: .04em; font-family: var(--font-tactical);
  text-shadow: 0 0 8px rgba(0,0,0,.4);
}
.user-row.in-voice .voice-ring {
  background: linear-gradient(135deg, var(--neon-purple), var(--neon-cyan));
  box-shadow: 0 0 10px rgba(180,106,255,.4);
}
.user-meta { min-width: 0; flex: 1; }
.user-name {
  font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-sub { font-size: 11px; color: var(--text-mute); }
.user-icons { display: flex; gap: 6px; color: var(--text-mute); font-size: 14px; }
.user-icons .muted-icon { color: var(--red); }

/* ===== Me bar ===== */
.me-bar {
  margin-top: auto;
  padding: 10px 12px;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
}
.me-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.me-info .avatar { width: 36px; height: 36px; }
.me-name {
  font-family: var(--font-tactical);
  font-size: 14px; font-weight: 700;
  letter-spacing: .03em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 110px;
}
.me-status { font-size: 11px; color: var(--text-mute); display: flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-mute); display: inline-block; }
.dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.connecting { background: var(--yellow); }
.dot.offline { background: var(--red); }

.me-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--text-dim);
  border: 0; cursor: pointer; transition: background .12s, color .12s;
  font-size: 16px;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.icon-btn.ghost { background: transparent; }
.icon-btn.active { color: var(--red); background: rgba(255,84,112,.12); }
.icon-btn.on { color: var(--accent); }

/* ===== Main: chat ===== */
.main {
  display: flex; flex-direction: column;
  min-width: 0;
  background: transparent;
  position: relative;
}
.chat-head {
  height: 56px; padding: 0 18px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-1);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
}
.chat-title { font-family: var(--font-tactical); letter-spacing: .04em; }
.chat-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.chat-title i { color: var(--text-mute); }
.chat-head-right { display: flex; align-items: center; gap: 10px; }
.pill {
  background: var(--bg-3);
  border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; color: var(--text-dim);
  display: inline-flex; align-items: center; gap: 6px;
}

/* ===== Messages ===== */
.messages {
  flex: 1 1 0;
  min-height: 0;        /* critical: lets the flex child actually clip + scroll */
  overflow-y: auto;
  padding: 18px 18px 0;
  display: flex; flex-direction: column; gap: 14px;
}
.message {
  display: flex; gap: 12px;
  padding: 4px 6px; border-radius: 8px;
  transition: background .1s;
}
.message:hover { background: var(--bg-1); }
.message.compact { padding-left: 58px; }
.message.compact .msg-avatar, .message.compact .msg-head { display: none; }
.msg-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white; font-size: 14px;
  flex-shrink: 0;
}
.msg-body { min-width: 0; flex: 1; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-author {
  font-family: var(--font-tactical);
  font-weight: 700; font-size: 14px;
  letter-spacing: .02em;
  background: var(--accent-grad);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.msg-time { font-size: 11px; color: var(--text-mute); }
.msg-text { font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.msg-text a { color: var(--accent-2); }
.msg-image { margin-top: 6px; max-width: 420px; }
.msg-image img {
  max-width: 100%; max-height: 360px;
  border-radius: 8px; border: 1px solid var(--line);
  cursor: zoom-in;
}

.system-msg {
  text-align: center; color: var(--text-mute); font-size: 12px;
  padding: 6px 0; opacity: .85;
}
.system-msg .name { color: var(--text-dim); font-weight: 600; }

.typing-indicator {
  height: 20px; padding: 0 22px;
  font-size: 12px; color: var(--text-mute); font-style: italic;
  display: flex; align-items: center;
}

/* ===== Composer ===== */
.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 18px 16px;
  background: transparent;
}
.composer-input-wrap {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  display: flex; flex-direction: column; gap: 8px;
  transition: border-color .12s, box-shadow .12s;
}
.composer-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124,92,255,.12);
}
#chat-input {
  background: transparent; border: 0; outline: 0; resize: none;
  color: var(--text); font: inherit; font-size: 14px;
  max-height: 160px; min-height: 22px; line-height: 1.45;
}
.preview {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; background: var(--bg-3);
  border-radius: 10px; border: 1px solid var(--line);
}
.preview img { width: 60px; height: 60px; border-radius: 6px; object-fit: cover; }
.preview .filename { font-size: 12px; color: var(--text-dim); flex: 1; }
.preview .remove {
  background: var(--bg-4); color: var(--text); border: 0;
  border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 12px;
}
.send-btn {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--accent-grad); color: white;
  border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  box-shadow: var(--glow-purple);
  transition: transform .1s, box-shadow .2s, filter .2s;
}
.send-btn:hover { transform: translateY(-1px) scale(1.04); box-shadow: var(--glow-cyan); filter: brightness(1.1); }
.send-btn:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; }

/* Inline SVG icons */
.icon { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }
.svg-icon { display: block; width: 18px; height: 18px; }
.icon-btn .svg-icon { width: 18px; height: 18px; }
.icon-btn:hover .svg-icon { filter: drop-shadow(0 0 6px var(--neon-cyan)); }
.send-btn .svg-icon { width: 22px; height: 22px; transform: rotate(-12deg); transition: transform .2s, filter .2s; }
.send-btn:hover .svg-icon { transform: rotate(-22deg) translate(2px,-2px); filter: drop-shadow(0 0 10px #fff); }
.voice-cta .svg-icon { width: 16px; height: 16px; }
.voice-cta.connecting .svg-icon { animation: spin 1.1s linear infinite; }
.section-label .svg-icon { width: 13px; height: 13px; }
.server-icon .svg-icon { width: 22px; height: 22px; color: #fff; }
.input-wrap .svg-icon { width: 16px; height: 16px; color: var(--text-mute); margin-right: 8px; }
.input-wrap:focus-within .svg-icon { color: var(--neon-cyan); }
#username-submit .svg-icon { width: 16px; height: 16px; }
.chat-title .svg-icon { color: var(--neon-purple); }
.user-icons .svg-icon { width: 14px; height: 14px; }
.user-icons .muted-icon { color: var(--neon-red); }

/* ===== Stickers + reactions ===== */
.sticker-tray {
  position: absolute;
  left: 18px; right: 18px; bottom: 86px;
  max-width: 720px; margin: 0 auto;
  background: linear-gradient(180deg, rgba(22,26,35,.92), rgba(17,20,27,.96));
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 12px 14px 14px;
  box-shadow: var(--shadow-2), var(--glow-purple);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  z-index: 20;
}
.sticker-tray-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.tray-tabs { display: flex; gap: 4px; }
.tray-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-mute);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-tactical);
  font-weight: 700; font-size: 12px;
  letter-spacing: .14em; text-transform: uppercase;
  display: inline-flex; align-items: center; gap: 6px;
  transition: color .15s, background .15s, border-color .15s;
}
.tray-tab .svg-icon { width: 14px; height: 14px; }
.tray-tab:hover { color: var(--text); background: var(--bg-3); }
.tray-tab.active {
  color: var(--neon-cyan);
  border-color: var(--line-strong);
  background: rgba(0,229,255,.08);
  text-shadow: 0 0 8px rgba(0,229,255,.4);
}
.tray-panel { animation: fadeUp .18s ease; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== GIF panel ===== */
.gif-search-row {
  display: flex; align-items: center;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  gap: 8px;
  margin-bottom: 10px;
  transition: border-color .15s, box-shadow .15s;
}
.gif-search-row:focus-within {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 0 3px rgba(0,229,255,.12);
}
.gif-search-row .svg-icon { color: var(--text-mute); width: 16px; height: 16px; }
.gif-search-row:focus-within .svg-icon { color: var(--neon-cyan); }
#gif-search {
  flex: 1; background: transparent; border: 0; outline: 0;
  color: var(--text); font: inherit; font-size: 14px;
}
.gif-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-height: 280px; overflow-y: auto;
}
.gif-btn {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  /* Padding-bottom hack creates a guaranteed-square box regardless of
     aspect-ratio support (Safari <15, some WebViews). The image is then
     absolutely positioned inside, so nothing can leak out of the tile and
     start stacking. */
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 100%;
  display: block;
  transition: transform .12s, border-color .12s, box-shadow .15s;
}
.gif-btn:hover {
  transform: scale(1.04);
  border-color: var(--neon-cyan);
  box-shadow: var(--glow-cyan);
  z-index: 1;
}
.gif-btn img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gif-loading, .gif-empty {
  grid-column: 1 / -1;
  color: var(--text-mute);
  font-size: 12px;
  padding: 24px 8px;
  text-align: center;
  line-height: 1.5;
}
.gif-empty code {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
}
.gif-attrib {
  font-size: 10px; color: var(--text-mute);
  text-align: right; margin-top: 6px;
  letter-spacing: .12em; text-transform: uppercase;
}

/* ===== Delete action ===== */
.msg-actions .danger { color: var(--text-mute); }
.msg-actions .danger:hover { color: var(--neon-red); background: rgba(255,59,107,.12); }
.msg-actions .danger:hover .svg-icon { filter: drop-shadow(0 0 6px var(--neon-red)); }
.message.deleting { opacity: 0; transform: translateX(-12px); transition: opacity .2s, transform .2s; }
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 8px;
  max-height: 280px; overflow-y: auto;
}
.sticker-btn {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  cursor: pointer;
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 100%;
  display: block;
  overflow: hidden;
  transition: transform .12s, border-color .12s, box-shadow .2s;
}
.sticker-btn:hover {
  transform: scale(1.08) rotate(-2deg);
  border-color: var(--neon-purple);
  box-shadow: var(--glow-purple);
}
.sticker-btn img {
  position: absolute;
  /* 6px inset matches the visual padding the old `padding: 6px` provided. */
  inset: 6px;
  width: calc(100% - 12px);
  height: calc(100% - 12px);
  object-fit: contain;
  display: block;
}
.sticker-empty {
  color: var(--text-mute); font-size: 12px;
  padding: 14px; text-align: center;
  grid-column: 1 / -1;
}

/* Sticker messages display larger and without frame */
.sticker-img { width: 140px !important; height: 140px !important; max-height: 140px !important; max-width: 140px !important; border: 0 !important; background: transparent !important; cursor: default !important; }
.sticker-msg .msg-image { background: transparent; }

/* Reaction picker */
.reaction-picker {
  position: fixed;
  background: linear-gradient(180deg, rgba(22,26,35,.95), rgba(17,20,27,.98));
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 6px; z-index: 100;
  box-shadow: var(--shadow-2), var(--glow-purple);
  backdrop-filter: blur(20px);
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px;
  max-width: 260px;
}
.rp-btn {
  background: transparent; border: 0;
  width: 38px; height: 38px;
  font-size: 22px; line-height: 1;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, transform .12s;
}
.rp-btn:hover { background: var(--bg-4); transform: scale(1.2); }

/* Reaction pills under messages */
.msg-reactions {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 6px;
}
.reaction-pill {
  background: rgba(124,92,255,.1);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
  font: inherit; color: var(--text);
  font-size: 12px;
  transition: border-color .15s, background .15s, transform .1s;
}
.reaction-pill:hover { transform: scale(1.07); border-color: var(--neon-cyan); }
.reaction-pill.mine {
  background: rgba(0,229,255,.18);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 8px rgba(0,229,255,.35);
}
.r-emoji { font-size: 14px; }
.r-count { color: var(--text-dim); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Message hover: show actions */
.message { position: relative; }
.msg-actions {
  position: absolute; top: -10px; right: 10px;
  background: linear-gradient(180deg, rgba(22,26,35,.96), rgba(17,20,27,.98));
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 2px;
  opacity: 0; transform: translateY(-4px);
  transition: opacity .15s, transform .15s;
  box-shadow: var(--shadow-1);
  pointer-events: none;
  display: flex;
}
.message:hover .msg-actions { opacity: 1; transform: translateY(0); pointer-events: auto; }
.msg-actions .icon-btn { width: 26px; height: 26px; }
.msg-actions .svg-icon { width: 15px; height: 15px; }

/* ===== Settings drawer ===== */
.settings {
  background: var(--bg-1);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  overflow-y: auto;
  position: relative;
}
.settings::before {
  content: ''; position: absolute;
  top: 0; left: 0; bottom: 0; width: 1px;
  background: linear-gradient(180deg, transparent, var(--neon-cyan), var(--neon-purple), transparent);
  opacity: .6;
}
.settings-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.settings-head h2 {
  font-family: var(--font-game);
  font-size: 14px; margin: 0;
  display: flex; gap: 8px; align-items: center;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--neon-cyan);
  text-shadow: 0 0 8px rgba(0,229,255,.4);
}
.settings-section {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.settings-section h3 {
  font-family: var(--font-tactical);
  font-size: 11px; text-transform: uppercase; letter-spacing: .14em;
  color: var(--neon-purple); margin: 0 0 10px;
  text-shadow: 0 0 6px rgba(180,106,255,.4);
}
.settings-row {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px;
}
.settings-row label { font-size: 12px; color: var(--text-dim); }
.settings-row select {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); font: inherit; font-size: 13px;
  padding: 8px 10px;
}

.slider-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.slider-row label {
  font-size: 12px; color: var(--text-dim);
  display: flex; justify-content: space-between;
}
.slider-row .hint { font-size: 11px; color: var(--text-mute); }
.slider-row input[type=range],
.puv-range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border-radius: 6px;
  background: var(--bg-3);
  outline: 0;
}
.slider-row input[type=range]::-webkit-slider-thumb,
.puv-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid white;
  cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.5);
}
.slider-row input[type=range]::-moz-range-thumb,
.puv-range::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid white; cursor: pointer;
}

.meter-row { margin-bottom: 14px; }
.meter-row label { font-size: 12px; color: var(--text-dim); display: block; margin-bottom: 6px; }
.meter {
  width: 100%; height: 10px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  border-radius: 6px; overflow: hidden;
  box-shadow: inset 0 0 8px rgba(0,0,0,.4);
}
.meter-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--neon-green), var(--neon-yellow) 70%, var(--neon-red));
  box-shadow: 0 0 12px rgba(0,255,157,.6);
  transition: width .05s linear;
}

/* ===== Test mic button ===== */
.voice-test-row { margin-bottom: 14px; }
.test-btn {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font: inherit; font-size: 13px; font-weight: 500;
  padding: 10px 12px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
  margin-bottom: 6px;
}
.test-btn i { font-size: 14px; }
.test-btn:hover { background: var(--bg-4); }
.test-btn.active {
  background: rgba(46, 204, 113, .15);
  border-color: var(--green);
  color: var(--green);
}
.voice-test-row .hint { font-size: 11px; color: var(--text-mute); }

/* ===== Toggle switches ===== */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 8px 0;
}
.toggle-row > label:first-child {
  font-size: 13px; color: var(--text); flex: 1;
  display: flex; flex-direction: column; gap: 2px;
}
.toggle-row > label:first-child .hint {
  font-size: 11px; color: var(--text-mute);
}
.switch {
  position: relative;
  width: 38px; height: 22px;
  display: inline-block;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 22px;
  transition: background .2s, border-color .2s;
}
.switch .slider::before {
  position: absolute; content: "";
  height: 16px; width: 16px;
  left: 2px; top: 2px;
  background: white;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch input:checked + .slider {
  background: var(--accent-grad);
  border-color: transparent;
}
.switch input:checked + .slider::before { transform: translateX(16px); }

/* ===== Keybind capture ===== */
.kbd-row {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: 10px;
}
.kbd-row label { font-size: 12px; color: var(--text-dim); }
.kbd-btn {
  background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px;
  font: inherit; color: var(--text); cursor: pointer;
  align-self: flex-start;
  transition: border-color .12s, background .12s;
  min-width: 120px; text-align: left;
}
.kbd-btn:hover { border-color: var(--accent); }
.kbd-btn.binding {
  border-color: var(--accent);
  background: rgba(124,92,255,.12);
  animation: kbdpulse 1.2s infinite;
}
@keyframes kbdpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(124,92,255,.45); }
  50% { box-shadow: 0 0 0 6px rgba(124,92,255,0); }
}
kbd {
  background: var(--bg-4); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 8px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px; color: var(--text);
}

.per-user-volumes { display: flex; flex-direction: column; gap: 12px; }
.puv-row { display: grid; grid-template-columns: 90px 1fr 44px; gap: 10px; align-items: center; }
.puv-name {
  font-size: 13px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.puv-val { font-size: 12px; color: var(--text-mute); text-align: right; font-variant-numeric: tabular-nums; }

/* ===== Scrollbars ===== */
.user-list::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.settings::-webkit-scrollbar { width: 8px; }
.user-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.settings::-webkit-scrollbar-thumb {
  background: var(--bg-3); border-radius: 8px;
}
.user-list::-webkit-scrollbar-thumb:hover,
.messages::-webkit-scrollbar-thumb:hover,
.settings::-webkit-scrollbar-thumb:hover { background: var(--bg-4); }

/* ===== Mobile chrome: hidden on desktop by default ===== */
.btn-mobile-menu {
  display: none;
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 8px;
  margin-right: 4px;
  cursor: pointer;
  border-radius: 8px;
}
.btn-mobile-menu:hover { background: var(--bg-3); }
.btn-mobile-menu .svg-icon { width: 22px; height: 22px; }
.mobile-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  z-index: 55;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* ===== Tablet: tighter columns, no layout change ===== */
@media (max-width: 900px) and (min-width: 801px) {
  .app { grid-template-columns: 220px 1fr; }
  .app.with-settings { grid-template-columns: 220px 1fr 300px; }
  .theme-bar { left: 320px; }
}

/* =====================================================================
   MOBILE / iOS — full overhaul. Scoped entirely inside this @media block,
   so desktop is untouched. Switches the 3-column grid to a single full
   width pane with slide-in drawers for the user list and audio settings.
   Uses 100dvh + env(safe-area-inset-*) so it renders correctly on iOS.
   ===================================================================== */
@media (max-width: 800px) {
  html, body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    /* Prevent the elastic horizontal bounce some iOS pages get. */
    overscroll-behavior-x: none;
  }

  /* Show the hamburger; the desktop welcome page never sees it. */
  .btn-mobile-menu { display: inline-flex; align-items: center; justify-content: center; }

  /* Single full-width column, no third settings column. */
  .app,
  .app.with-settings {
    display: block;
    height: 100dvh;        /* dynamic viewport height — handles iOS toolbar */
    width: 100vw;
    max-width: 100vw;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .main {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    min-width: 0;
  }

  /* ---------- Sidebar drawer (left) ---------- */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 8px 0 24px rgba(0, 0, 0, .35);
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-bottom: env(safe-area-inset-bottom);
    overflow-y: auto;
  }
  .sidebar.mobile-open { transform: translateX(0); }

  /* ---------- Settings drawer (right) ---------- */
  .settings {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 340px;
    max-width: 90vw;
    z-index: 60;
    box-shadow: -8px 0 24px rgba(0, 0, 0, .35);
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-bottom: env(safe-area-inset-bottom);
    overflow-y: auto;
  }

  /* ---------- Backdrop (toggled by JS) ---------- */
  .mobile-backdrop.active { display: block; }

  /* ---------- Chat header ---------- */
  .chat-head {
    padding-top: calc(8px + env(safe-area-inset-top));
    gap: 4px;
  }
  .chat-title { font-size: 14px; }

  /* ---------- Messages: kill any overflow ---------- */
  .messages {
    padding: 12px 12px 0;
    width: 100%;
    min-width: 0;
  }
  .message,
  .system-msg,
  .typing-indicator {
    max-width: 100%;
    min-width: 0;
  }
  .msg-body { min-width: 0; }
  .msg-text,
  .msg-author {
    overflow-wrap: anywhere;     /* break long URLs / pasted strings */
    word-break: break-word;
  }
  .msg-image { max-width: 100%; }
  .msg-image img {
    max-width: 100%;
    max-height: 60vh;
    height: auto;
  }

  /* ---------- Composer ---------- */
  .composer {
    padding: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    gap: 6px;
  }
  .composer-input-wrap {
    min-width: 0;
    flex: 1 1 auto;
  }

  /* ---------- Theme bar: stash it small in the corner, opens as a menu ---------- */
  .theme-bar {
    top: calc(env(safe-area-inset-top) + 8px);
    right: 12px;
    left: auto;
    z-index: 40;
  }
  .theme-trigger { padding: 6px 10px; font-size: 12px; }
  .theme-label { max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .theme-notice {
    top: calc(100% + 10px);
    left: auto;
    right: 0;
    width: min(280px, calc(100vw - 24px));
  }
  .theme-notice::before {
    top: -6px;
    left: auto;
    right: 24px;
    border-left: 1px solid var(--line-strong);
    border-top: 1px solid var(--line-strong);
    border-bottom: 0;
    border-right: 0;
  }

  /* ---------- Sticker tray / GIF picker ---------- */
  .sticker-tray {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 60dvh;
    border-radius: 12px 12px 0 0;
    z-index: 45;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* ---------- Reaction picker ---------- */
  .reaction-picker {
    max-width: calc(100vw - 24px);
  }

  /* ---------- Auth overlay ---------- */
  .overlay-card {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    padding: 22px 18px 18px;
    /* Push down to clear the iOS status bar */
    margin-top: env(safe-area-inset-top);
    margin-bottom: env(safe-area-inset-bottom);
  }
  .safekey-display code { font-size: 13px; padding: 12px 8px; }

  /* ---------- Per-user volumes inside settings ---------- */
  .puv-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
