:root {
  --bg: #0e0e10;
  --panel: #18181b;
  --panel-alt: #1f1f23;
  --border: #2f2f35;
  --text: #f5f5f5;
  --text-dim: #9a9aa2;
  --twitch: #9146ff;
  --youtube: #ff0000;
  --tiktok: #25f4ee;
  --tiktok2: #fe2c55;
  --hearthis: #ff6a00;
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, sans-serif;
  margin: 0;
  height: 100vh;
  overflow: hidden;
}

h1 { color: var(--twitch); margin: 10px 0; text-align: center; font-size: 1.3rem; }

.hidden { display: none !important; }

/* --- Auth Gate --- */
.auth-container {
  background: var(--panel-alt);
  padding: 24px;
  border-radius: 10px;
  text-align: center;
  max-width: 480px;
  margin: 60px auto;
}
.auth-button {
  background: var(--twitch);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  margin-top: 15px;
}
.auth-button:hover { background: #772ce8; }

/* --- Layout --- */
.main-container {
  display: flex;
  height: calc(100vh - 50px);
  padding: 10px;
  gap: 12px;
}
.left-column { flex: 0 0 62%; display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; }
.right-column { flex: 1; display: flex; flex-direction: column; min-width: 320px; min-height: 0; }

/* --- Video tabs --- */
.video-tabs { display: flex; gap: 6px; }
.video-tab {
  background: var(--panel-alt);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.85rem;
}
.video-tab.active { color: var(--text); border-bottom-color: transparent; background: var(--panel); }
.video-tab .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: #555; }
.video-tab.live .dot { background: #2ecc71; }

.stream-container {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  background: var(--panel);
  border-radius: 0 8px 8px 8px;
  overflow: hidden;
}
.stream-container.vertical { padding-top: 130%; max-width: 320px; }
.stream-container.audio { padding-top: 150px; height: 0; }
.stream-iframe { width: 100%; height: 100%; border: none; position: absolute; top: 0; left: 0; }
.loading-container { display: flex; justify-content: center; align-items: center; height: 100%; color: var(--text-dim); }

.external-container {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
}
.external-link-btn {
  background: var(--tiktok2);
  color: #fff;
  text-decoration: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}
.external-link-btn:hover { opacity: 0.9; }

/* --- Activity feed --- */
.panel-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.panel-tab {
  flex: 1;
  text-align: center;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
  color: var(--text-dim);
}
.panel-tab.active { color: var(--text); border-color: var(--twitch); }

.panel-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#panel-activity { flex: 1; min-height: 0; display: flex; flex-direction: column; }

#feed {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.event {
  background: var(--panel-alt);
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  animation: fadeIn 0.3s ease-in-out;
}
.event.historical { opacity: 0.7; border-left: 3px solid #555; }
.event-content { display: flex; align-items: center; gap: 8px; }
.event-time { font-size: 0.7em; color: var(--text-dim); margin-top: 4px; }
.follow .icon { color: var(--twitch); }
.sub .icon { color: #ffd700; }
.cheer .icon { color: #00b3ff; }
.reward .icon { color: #ff69b4; }
.raid .icon { color: #ff4444; }
.like .icon { color: var(--hearthis); }
.info .icon { color: #2ecc71; }
.error .icon { color: #e74c3c; }

/* --- Chat status row --- */
.chat-status-row { display: flex; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.status-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.75rem;
  color: var(--text-dim);
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #555; }
.status-pill.connected .dot { background: #2ecc71; }
.status-pill.connected { color: var(--text); }

/* --- Unified chat --- */
#chat-feed {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
  padding: 10px;
  overflow-y: auto;
  min-height: 0;
}
.chat-msg {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 4px 4px;
  border-radius: 6px;
  font-size: 0.88rem;
  line-height: 1.35;
  word-break: break-word;
  animation: fadeIn 0.25s ease-in-out;
}
.chat-msg:hover { background: rgba(255,255,255,0.03); }
.platform-badge {
  flex: 0 0 auto;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  color: #0e0e10;
  margin-top: 2px;
}
.platform-badge.twitch { background: var(--twitch); color: #fff; }
.platform-badge.youtube1 { background: var(--youtube); color: #fff; }
.platform-badge.youtube2 { background: var(--youtube); color: #fff; }
.platform-badge.tiktok { background: linear-gradient(90deg, var(--tiktok), var(--tiktok2)); color: #111; }
.platform-badge.hearthis { background: var(--hearthis); color: #fff; }

.chat-author { font-weight: 700; margin-right: 4px; }
.chat-text img.emote { height: 1.6em; vertical-align: middle; margin: 0 1px; }

/* --- Chat input bar --- */
.chat-input-bar {
  display: flex;
  gap: 6px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 10px 10px;
  padding: 8px;
}
#chat-target {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 8px;
  font-size: 0.85rem;
  flex: 0 0 auto;
  max-width: 40%;
}
#chat-input {
  flex: 1;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.9rem;
}
#chat-send {
  background: var(--twitch);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0 16px;
  cursor: pointer;
  font-size: 0.9rem;
}
#chat-send:disabled { background: #444; cursor: not-allowed; }
.chat-input-hint { font-size: 0.7rem; color: var(--text-dim); padding: 2px 4px 0; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
