/* ===================== THEME TOKENS ===================== */
:root,
[data-theme="dark"] {
  --bg: #0e0e10;
  --bg-elevated: #18181b;
  --bg-elevated-2: #1f1f23;
  --border: #2d2d33;
  --text: #efeff1;
  --text-muted: #adadb8;
  --text-faint: #71717a;
  --accent: #9147ff;
  --accent-hover: #7d2ff0;
  --accent-soft: rgba(145, 71, 255, 0.15);
  --live-red: #eb0400;
  --online-green: #00c781;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  --chat-bg: #18181b;
  --input-bg: #0e0e10;
  --scrollbar: #3a3a3d;
}

[data-theme="light"] {
  --bg: #f7f7f8;
  --bg-elevated: #ffffff;
  --bg-elevated-2: #f0f0f2;
  --border: #e3e3e6;
  --text: #0e0e10;
  --text-muted: #53535f;
  --text-faint: #8a8a96;
  --accent: #7d2ff0;
  --accent-hover: #6a1fd8;
  --accent-soft: rgba(125, 47, 240, 0.1);
  --live-red: #eb0400;
  --online-green: #00a373;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --chat-bg: #ffffff;
  --input-bg: #f0f0f2;
  --scrollbar: #d4d4d8;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ===================== TOPBAR ===================== */
.topbar {
  height: 56px;
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.2px;
}

.brand__logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
}

.brand__accent { color: var(--accent); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated-2);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.icon-btn--ghost { border: none; background: transparent; width: 28px; height: 28px; }

.icon { width: 18px; height: 18px; }
.icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: inline-flex; }

/* ===================== LAYOUT ===================== */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr 340px;
  min-height: 0;
}

.stage {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.player-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  flex: 0 0 auto;
}
.player-wrap iframe { position: absolute; inset: 0; }

.live-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--live-red);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 4px 8px;
  border-radius: 4px;
  pointer-events: none;
}
.live-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.stream-meta {
  display: flex;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.stream-meta__avatar {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #4f2db8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
}

.stream-meta__title {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 4px;
  line-height: 1.3;
}

.stream-meta__sub {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

.streamer-name { color: var(--accent); font-weight: 600; }

.viewer-count::before {
  content: "●";
  color: var(--online-green);
  margin-right: 5px;
  font-size: 9px;
}

/* ===================== CHAT ===================== */
.chat {
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  border-left: 1px solid var(--border);
  min-height: 0;
}

.chat__header {
  flex: 0 0 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  font-weight: 700;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.chat__messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13.5px;
  line-height: 1.45;
}

.chat-msg { word-wrap: break-word; }
.chat-msg__name { font-weight: 700; margin-right: 4px; }
.chat-msg__name--system { color: var(--text-faint); font-style: italic; font-weight: 500; }
.chat-msg__text { color: var(--text); }

.chat-msg--system { color: var(--text-faint); font-size: 12.5px; }

.chat__status {
  flex: 0 0 auto;
  padding: 4px 14px;
  font-size: 11px;
  color: var(--text-faint);
}

.chat__form {
  flex: 0 0 auto;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat__name,
.chat__input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 10px;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease;
}
.chat__name:focus,
.chat__input:focus { border-color: var(--accent); }

.chat__row { display: flex; gap: 6px; }
.chat__row .chat__input { flex: 1 1 auto; }

.chat__send {
  flex: 0 0 auto;
  width: 40px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.chat__send:hover { background: var(--accent-hover); }
.chat__send svg { width: 16px; height: 16px; }

.chat-expand-btn {
  display: none;
}

.chat__header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn--active {
  color: var(--accent);
}

.mod-popover {
  position: relative;
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated-2);
}
.mod-popover input {
  flex: 1 1 auto;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 9px;
  font-size: 12.5px;
  outline: none;
}
.mod-popover input:focus { border-color: var(--accent); }
.mod-popover button {
  flex: 0 0 auto;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 0 12px;
  cursor: pointer;
}
.mod-popover button:hover { background: var(--accent-hover); }

.mod-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--accent-soft);
  font-size: 11.5px;
}
.mod-bar__label {
  font-weight: 700;
  color: var(--accent);
  margin-right: auto;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.mod-bar__btn {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 5px;
  padding: 4px 9px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
.mod-bar__btn:hover { background: var(--accent); color: #fff; }
.mod-bar__btn--ghost { border-color: var(--border); color: var(--text-muted); }
.mod-bar__btn--ghost:hover { background: var(--bg-elevated-2); color: var(--text); }

.chat-msg {
  position: relative;
  padding-right: 44px;
}
.chat-msg__actions {
  display: none;
  position: absolute;
  right: 0;
  top: 0;
  gap: 3px;
}
.is-mod .chat-msg:hover .chat-msg__actions {
  display: flex;
}
.chat-msg__delete,
.chat-msg__ban {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 4px;
  color: #fff;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.chat-msg__delete { background: var(--live-red); }
.chat-msg__ban { background: #92400e; font-size: 11px; }
.chat-msg.is-removed {
  opacity: 0.4;
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }
  .chat {
    border-left: none;
    border-top: 1px solid var(--border);
    height: 50vh;
  }
  .player-wrap { aspect-ratio: 16 / 9; }
}

@media (max-width: 560px) {
  .stream-meta { padding: 12px 14px; }
  .stream-meta__avatar { width: 40px; height: 40px; font-size: 15px; }
  .stream-meta__title { font-size: 15.5px; }
  .chat { height: 46vh; }
  .brand__name { font-size: 14px; }
}

/* collapsed chat (mobile toggle) */
.chat.is-collapsed { display: none; }
.chat-expand-btn[hidden] { display: none !important; }
@media (max-width: 900px) {
  .chat-expand-btn {
    display: block;
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 60;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 24px;
    padding: 10px 18px;
    font-weight: 700;
    font-size: 13px;
    box-shadow: var(--shadow);
    cursor: pointer;
  }
}
