/* ─── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #fe2c55;
  --accent-yt: #ff0000;
  --accent-tk: #fe2c55;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.25s ease;
  --panel-w: 300px;

  /* Light theme */
  --bg: #f4f5f7;
  --bg2: #ffffff;
  --bg3: #eef0f3;
  --border: #e0e3e8;
  --text: #1a1a2e;
  --text2: #5a6275;
  --text3: #8b929e;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
  --scrollbar: #d0d3db;
}

[data-theme="dark"] {
  --bg: #0d0f14;
  --bg2: #161921;
  --bg3: #1e2230;
  --border: #2a2e3e;
  --text: #e8ecf4;
  --text2: #8892aa;
  --text3: #5a6275;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --scrollbar: #2a2e3e;
}

html { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background var(--transition), color var(--transition);
  -webkit-tap-highlight-color: transparent;
}

/* ─── Header ────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  z-index: 10;
  min-height: 54px;
}

.header-logo {
  font-size: 19px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent) 0%, #ff6b9d 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
  flex-shrink: 0;
}

.header-sse-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(99,102,241,0.15);
  color: #818cf8;
  letter-spacing: 0.5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.header-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg3);
  border-radius: 10px;
  padding: 4px;
  flex-shrink: 0;
}

.tab-btn {
  padding: 7px 16px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  min-height: 36px;
}
.tab-btn.active { background: var(--bg2); color: var(--text); box-shadow: var(--shadow-sm); }
.tab-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.header-spacer { flex: 1; min-width: 0; }

.header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.stats-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  color: var(--text2);
  flex-shrink: 0;
}
.stat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--bg3);
  border-radius: 20px;
  font-weight: 500;
}

.icon-btn {
  width: 36px; height: 36px;
  border: none;
  background: var(--bg3);
  color: var(--text2);
  border-radius: 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
  touch-action: manipulation;
}
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn.active { background: var(--accent); color: #fff; }
.icon-btn svg { width: 18px; height: 18px; }

.lang-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text1);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  outline: none;
  height: 34px;
  flex-shrink: 0;
}
.lang-select:hover { border-color: var(--accent); }

/* ─── Main Layout ───────────────────────────────────────────────────── */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ─── Panel Backdrop (mobile) ───────────────────────────────────────── */
.panel-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 150;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ─── Connect Panel ─────────────────────────────────────────────────── */
.connect-panel {
  width: var(--panel-w);
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
  gap: 10px;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              padding 0.3s ease,
              transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}
.connect-panel.collapsed { width: 0; padding: 0; overflow: hidden; }

.panel-drag-handle {
  display: none;
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 4px;
  flex-shrink: 0;
}

.panel-section {
  background: var(--bg3);
  border-radius: var(--radius);
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  flex-shrink: 0;
}
.panel-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text3);
}

.input-group { display: flex; flex-direction: column; gap: 5px; }
.input-label { font-size: 12px; font-weight: 600; color: var(--text2); }
.input-field {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  font-size: 14px;
  transition: border-color var(--transition);
  outline: none;
  width: 100%;
  min-height: 42px;
}
.input-field:focus { border-color: var(--accent); }
.input-field::placeholder { color: var(--text3); }

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  touch-action: manipulation;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: 0.88; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); opacity: 0.92; }
.btn-danger { background: #ff4444; color: #fff; }
.btn-danger:hover { opacity: 0.88; }
.btn-ghost { background: var(--border); color: var(--text2); }
.btn-ghost:hover { background: var(--text3); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
.btn-sm { padding: 8px 12px; font-size: 13px; min-height: 38px; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.status-badge.connected { background: #d4f7e7; color: #1a7a46; }
.status-badge.disconnected { background: var(--bg3); color: var(--text3); }
.status-badge.connecting { background: #fff3cd; color: #856404; }
[data-theme="dark"] .status-badge.connected { background: #0d3b26; color: #4ade80; }
[data-theme="dark"] .status-badge.connecting { background: #3b2c00; color: #fcd34d; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.status-badge.connected .status-dot { animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* Settings */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
}
.setting-label { font-size: 12px; color: var(--text2); font-weight: 500; flex: 1; line-height: 1.4; }
.setting-control { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

input[type="range"] {
  -webkit-appearance: none;
  width: 80px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.range-val { font-size: 11px; color: var(--text3); width: 32px; text-align: right; }

/* Toggle switch */
.toggle {
  position: relative;
  width: 38px; height: 22px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 22px;
  cursor: pointer;
  transition: background var(--transition);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

select.input-field { cursor: pointer; }

/* ─── Comments Area ─────────────────────────────────────────────────── */
.comments-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.comments-toolbar {
  padding: 8px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  min-width: 120px;
  max-width: 240px;
  flex: 1;
}
.search-box svg {
  position: absolute;
  left: 9px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  color: var(--text3);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 7px 10px 7px 29px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg3);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
  min-height: 36px;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text3); }

.filter-chips {
  display: flex;
  gap: 5px;
  align-items: center;
}
.chip {
  padding: 5px 11px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text2);
  transition: all var(--transition);
  white-space: nowrap;
  touch-action: manipulation;
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.chip.active { border-color: var(--accent); color: var(--accent); background: rgba(254,44,85,0.08); }
.chip-count { opacity: 0.7; }

.toolbar-spacer { flex: 1; min-width: 0; }
.comment-count { font-size: 12px; color: var(--text3); white-space: nowrap; }

.comments-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.comments-list::-webkit-scrollbar { width: 5px; }
.comments-list::-webkit-scrollbar-track { background: transparent; }
.comments-list::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  gap: 12px;
  padding: 40px 24px;
  text-align: center;
}
.empty-state svg { width: 52px; height: 52px; opacity: 0.3; }
.empty-state h3 { font-size: 16px; color: var(--text2); }
.empty-state p { font-size: 13px; line-height: 1.6; }

/* ─── Comment Item ──────────────────────────────────────────────────── */
.comment-item {
  display: flex;
  gap: 10px;
  padding: 11px 13px;
  border-radius: 12px;
  background: var(--bg2);
  border: 1.5px solid transparent;
  transition: all 0.15s ease;
  position: relative;
  animation: slideIn 0.22s ease;
  flex-shrink: 0;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.comment-item:hover { border-color: var(--border); }
.comment-item.speaking {
  border-color: var(--accent);
  background: rgba(254,44,85,0.06);
  box-shadow: 0 0 0 3px rgba(254,44,85,0.14);
}
.comment-item.type-gift {
  background: linear-gradient(135deg, rgba(255,180,0,0.09), rgba(255,120,0,0.06));
  border-color: rgba(255,160,0,0.2);
}
.comment-item.type-superchat {
  background: linear-gradient(135deg, rgba(30,100,255,0.09), rgba(80,180,255,0.06));
  border-color: rgba(30,120,255,0.2);
}
.comment-item.type-join { opacity: 0.65; }
.comment-item.pinned { border-color: #f59e0b; background: rgba(245,158,11,0.07); }

.comment-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.comment-avatar-placeholder {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #ff6b9d);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  flex-shrink: 0;
}

.comment-body { flex: 1; min-width: 0; }
.comment-header { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; flex-wrap: wrap; }
.comment-username {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  letter-spacing: -0.2px;
}
.comment-badge {
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-mod { background: #4CAF50; color: #fff; }
.badge-owner { background: #FFD700; color: #333; }
.badge-member { background: #9C27B0; color: #fff; }
.badge-gift { background: linear-gradient(90deg,#ff9800,#f44336); color:#fff; }
.badge-platform-tiktok { background: #010101; color: #fff; }
.badge-platform-youtube { background: #ff0000; color: #fff; }

.comment-time { font-size: 10px; color: var(--text3); margin-left: auto; flex-shrink: 0; }
.comment-text {
  font-size: 17px;
  color: var(--text);
  line-height: 1.55;
  word-break: break-word;
  font-weight: 400;
}
.comment-item.type-gift .comment-text,
.comment-item.type-superchat .comment-text { font-weight: 700; }
.comment-item.type-join .comment-text { color: var(--text2); font-style: italic; font-size: 14px; }

/* Comment actions — desktop: hover, mobile: always small */
.comment-actions {
  display: none;
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  gap: 3px;
}
.comment-item:hover .comment-actions { display: flex; }
.comment-action-btn {
  width: 28px; height: 28px;
  border: none;
  background: var(--bg2);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text2);
  box-shadow: var(--shadow-sm);
  transition: all 0.15s;
  touch-action: manipulation;
}
.comment-action-btn:hover { color: var(--accent); }
.comment-action-btn svg { width: 13px; height: 13px; }

/* ─── TTS Indicator ─────────────────────────────────────────────────── */
.tts-bar {
  padding: 8px 14px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.tts-bar.hidden { display: none; }
.tts-wave { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.tts-wave span {
  width: 3px; height: 14px;
  background: var(--accent);
  border-radius: 2px;
  animation: wave 0.8s ease-in-out infinite;
}
.tts-wave span:nth-child(2) { animation-delay: 0.12s; height: 20px; }
.tts-wave span:nth-child(3) { animation-delay: 0.24s; height: 16px; }
.tts-wave span:nth-child(4) { animation-delay: 0.36s; height: 22px; }
.tts-wave span:nth-child(5) { animation-delay: 0.48s; height: 12px; }
@keyframes wave {
  0%,100% { transform: scaleY(0.5); opacity: 0.6; }
  50%      { transform: scaleY(1);   opacity: 1;   }
}
.tts-speaking-text {
  flex: 1;
  font-size: 13px;
  color: var(--text2);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}
.tts-speaking-text strong { color: var(--text); }
.tts-queue-count { font-size: 12px; color: var(--text3); flex-shrink: 0; }
.tts-controls { display: flex; gap: 4px; flex-shrink: 0; }

/* ─── Style Picker ──────────────────────────────────────────────────── */
.style-picker {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 5px;
}
.style-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg2);
  color: var(--text2);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  touch-action: manipulation;
}
.style-opt:hover { border-color: var(--accent); color: var(--text); }
.style-opt.active { border-color: var(--accent); background: rgba(254,44,85,0.1); color: var(--accent); }

.weight-btn {
  padding: 5px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text2);
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 30px;
  touch-action: manipulation;
}
.weight-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(254,44,85,0.08); }

/* ─── Comment Style Variants ─────────────────────────────────────────── */
.comments-list[data-comment-style="bubble"] { padding: 10px 14px; gap: 8px; }
.comments-list[data-comment-style="bubble"] .comment-item {
  background: var(--bg3);
  border: none;
  border-radius: 4px 16px 16px 16px;
  padding: 10px 14px;
}
.comments-list[data-comment-style="bubble"] .comment-item::before {
  content: '';
  position: absolute;
  left: -7px; top: 10px;
  border: 7px solid transparent;
  border-right-color: var(--bg3);
  border-left: 0;
}
.comments-list[data-comment-style="bubble"] .comment-item.type-gift { background: rgba(255,160,0,0.14); }
.comments-list[data-comment-style="bubble"] .comment-item.type-gift::before { border-right-color: rgba(255,160,0,0.14); }
.comments-list[data-comment-style="bubble"] .comment-item.type-superchat { background: rgba(30,100,255,0.12); }
.comments-list[data-comment-style="bubble"] .comment-item.type-superchat::before { border-right-color: rgba(30,100,255,0.12); }
.comments-list[data-comment-style="bubble"] .comment-item:hover { background: var(--border); }
.comments-list[data-comment-style="bubble"] .comment-item.speaking {
  box-shadow: 0 0 0 2px var(--accent);
  background: rgba(254,44,85,0.1);
}
.comments-list[data-comment-style="bubble"] .comment-item.speaking::before { border-right-color: rgba(254,44,85,0.1); }

.comments-list[data-comment-style="compact"] { gap: 2px; padding: 6px 10px; }
.comments-list[data-comment-style="compact"] .comment-item { padding: 6px 10px; border-radius: 8px; gap: 8px; }
.comments-list[data-comment-style="compact"] .comment-avatar,
.comments-list[data-comment-style="compact"] .comment-avatar-placeholder { width: 28px; height: 28px; font-size: 11px; }
.comments-list[data-comment-style="compact"] .comment-header { margin-bottom: 1px; }

.comments-list[data-comment-style="minimal"] { gap: 0; padding: 6px 12px; }
.comments-list[data-comment-style="minimal"] .comment-item {
  background: transparent; border: none; border-radius: 0;
  border-bottom: 1px solid var(--border); padding: 8px 4px; gap: 8px;
}
.comments-list[data-comment-style="minimal"] .comment-item:last-child { border-bottom: none; }
.comments-list[data-comment-style="minimal"] .comment-item:hover { background: rgba(128,128,128,0.05); }
.comments-list[data-comment-style="minimal"] .comment-avatar,
.comments-list[data-comment-style="minimal"] .comment-avatar-placeholder { width: 30px; height: 30px; font-size: 12px; }

/* ─── Dynamic flags ──────────────────────────────────────────────────── */
.comments-list[data-hide-time] .comment-time { display: none; }
.comments-list[data-hide-platform] .badge-platform-tiktok,
.comments-list[data-hide-platform] .badge-platform-youtube { display: none; }
.comments-list[data-username-accent] .comment-username { color: var(--accent); }

/* ─── Toast ─────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px; right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  max-width: 300px;
  pointer-events: auto;
}
.toast.success { background: #1a7a46; color: #fff; }
.toast.error { background: #c53030; color: #fff; }
.toast.info { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
@keyframes toastIn  { from { opacity:0; transform: translateX(30px); } to { opacity:1; transform: translateX(0); } }
@keyframes toastOut { from { opacity:1; } to { opacity:0; transform: translateX(20px); } }

/* ─── Scrollbars ─────────────────────────────────────────────────────── */
.connect-panel::-webkit-scrollbar { width: 3px; }
.connect-panel::-webkit-scrollbar-track { background: transparent; }
.connect-panel::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 2px; }

/* ─── Tablet (≤900px) ───────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --panel-w: 270px; }

  .header { padding: 9px 14px; gap: 8px; }
  .stats-bar { display: none; }
  .tab-btn { padding: 6px 12px; font-size: 13px; }
  .header-logo { font-size: 17px; }
}

/* ─── Mobile (≤640px) ───────────────────────────────────────────────── */
@media (max-width: 640px) {

  /* ── Header ─────────────────────────────────────────────────────── */
  .header {
    padding: 8px 12px;
    gap: 6px;
    min-height: 50px;
    flex-wrap: wrap;
    align-items: center;
  }

  .header-logo { font-size: 16px; }
  .header-sse-badge { display: none; }
  .header-spacer { display: none; }

  /* Tab buttons go to second row, full width */
  .header-tabs {
    order: 10;
    width: 100%;
    padding: 3px;
    border-radius: 10px;
  }
  .tab-btn {
    flex: 1;
    justify-content: center;
    padding: 7px 8px;
    font-size: 12px;
    min-height: 34px;
    gap: 5px;
  }
  .tab-btn svg { width: 13px; height: 13px; }

  /* Compact header-actions */
  .header-actions { gap: 4px; margin-left: auto; }
  .icon-btn { width: 34px; height: 34px; border-radius: 8px; }
  .icon-btn svg { width: 16px; height: 16px; }

  /* Language selector: smaller */
  .lang-select { padding: 4px 6px; font-size: 11px; height: 32px; border-radius: 7px; }

  /* ── Main layout ─────────────────────────────────────────────────── */
  .main { position: relative; flex-direction: column; }

  /* ── Panel becomes full-screen bottom drawer ─────────────────────── */
  .connect-panel {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100% !important;
    height: 78vh;
    max-height: 78vh;
    z-index: 200;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    padding: 8px 14px 14px;
    gap: 10px;
    transform: translateY(0);
    box-shadow: 0 -8px 40px rgba(0,0,0,0.3);
    overflow-y: auto;
    overflow-x: hidden;
    /* override desktop transition */
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  }

  .connect-panel.collapsed {
    transform: translateY(100%);
    /* keep width/padding to avoid layout shift */
    width: 100% !important;
    overflow: hidden;
    pointer-events: none;
  }

  /* Drag handle for drawer */
  .panel-drag-handle { display: block; }

  /* ── Toolbar ──────────────────────────────────────────────────────── */
  .comments-toolbar {
    padding: 7px 10px;
    gap: 7px;
  }

  /* Search takes first row full width */
  .search-box {
    order: 1;
    max-width: 100%;
    flex: 1 1 100%;
    min-width: 0;
  }

  /* Chips on second row, horizontal scroll */
  .filter-chips {
    order: 2;
    flex: 1 1 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 1px;
  }
  .filter-chips::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; padding: 5px 10px; font-size: 11px; }

  .toolbar-spacer { display: none; }
  .comment-count { order: 3; font-size: 11px; flex-shrink: 0; }

  /* ── Comments list ─────────────────────────────────────────────── */
  .comments-list { padding: 8px 10px; gap: 5px; }

  /* ── Comment items ─────────────────────────────────────────────── */
  .comment-item { padding: 10px 11px; gap: 9px; border-radius: 11px; }
  .comment-avatar,
  .comment-avatar-placeholder { width: 36px; height: 36px; font-size: 13px; }
  .comment-username { font-size: 13px; }
  .comment-text { font-size: 15px !important; line-height: 1.5; }

  /* Always show action buttons on mobile (no hover) */
  .comment-actions {
    display: flex !important;
    position: static;
    transform: none;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
  }
  /* Show faintly when comment is focused/touched */
  .comment-item:focus-within .comment-actions,
  .comment-item.touch-active .comment-actions {
    opacity: 1;
    pointer-events: auto;
  }

  /* Compact styles stay compact */
  .comments-list[data-comment-style="compact"] .comment-item { padding: 5px 9px; gap: 7px; }
  .comments-list[data-comment-style="minimal"] .comment-item { padding: 7px 4px; }

  /* ── TTS bar ────────────────────────────────────────────────────── */
  .tts-bar { padding: 8px 12px; gap: 8px; }
  .tts-speaking-text { font-size: 12px; }

  /* ── Toast position ─────────────────────────────────────────────── */
  .toast-container { bottom: 12px; right: 10px; left: 10px; }
  .toast { max-width: 100%; font-size: 13px; }

  /* ── Empty state ────────────────────────────────────────────────── */
  .empty-state { padding: 30px 20px; }
  .empty-state svg { width: 44px; height: 44px; }
  .empty-state h3 { font-size: 15px; }
  .empty-state p { font-size: 12px; }

  /* ── Style picker: 2x2 grid on mobile ──────────────────────────── */
  .style-picker { grid-template-columns: 1fr 1fr; gap: 6px; }

  /* ── Panel sections: slightly smaller ──────────────────────────── */
  .panel-section { padding: 11px; gap: 8px; }
  .panel-section-title { font-size: 10px; }
  .setting-label { font-size: 12px; }
  input[type="range"] { width: 70px; }

  /* ── Backdrop visible on mobile ─────────────────────────────────── */
  .panel-backdrop.active { display: block; }

  /* ── Open panel FAB ─────────────────────────────────────────────── */
  .mobile-panel-fab {
    display: flex;
  }
}

/* ── Mobile panel FAB (open settings) ──────────────────────────────── */
.mobile-panel-fab {
  display: none;
  position: fixed;
  bottom: 18px;
  right: 14px;
  height: 46px;
  padding: 0 16px 0 13px;
  border-radius: 23px;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  align-items: center;
  gap: 7px;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(254,44,85,0.5), 0 2px 8px rgba(0,0,0,0.2);
  z-index: 99;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s;
  touch-action: manipulation;
  font-family: inherit;
}
.mobile-panel-fab:active { transform: scale(0.94); box-shadow: 0 2px 10px rgba(254,44,85,0.4); }
.mobile-panel-fab svg { width: 20px; height: 20px; flex-shrink: 0; }
/* Hide FAB when panel is open */
.mobile-panel-open .mobile-panel-fab { display: none !important; }

/* ─── Extra small (≤380px) ──────────────────────────────────────────── */
@media (max-width: 380px) {
  .header-logo { font-size: 14px; }
  .tab-btn { font-size: 11px; gap: 4px; padding: 6px 6px; }
  .tab-btn svg { display: none; }
  .icon-btn { width: 30px; height: 30px; }
  .icon-btn svg { width: 15px; height: 15px; }
  .lang-select { font-size: 10px; padding: 3px 5px; height: 30px; }
  .comment-text { font-size: 14px !important; }
  .comment-avatar,
  .comment-avatar-placeholder { width: 32px; height: 32px; }
}
