/* The viewer-facing board: the video overlay and the panel share this. */

:root {
  --bg: rgba(14, 12, 20, 0.92);
  --card: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f1eef7;
  --muted: #a39db3;
  --accent: #b78cff;
  --accent-soft: rgba(169, 112, 255, 0.2);
  --accent-line: rgba(169, 112, 255, 0.5);
  --hot: #ff7a6e;
  --hot-soft: rgba(255, 107, 94, 0.16);
  --lead: #3ddc97;
  --lead-soft: rgba(61, 220, 151, 0.14);
}

/* Panels follow the viewer's Twitch theme. The overlay is always dark. */
:root[data-theme='light'] body.mode-panel {
  --bg: #ffffff;
  --card: #f4f2f8;
  --line: #dcd7e6;
  --text: #1f1a2b;
  --muted: #655e75;
  --accent: #6a35c9;
  --accent-soft: #ece2ff;
  --accent-line: #b79af0;
  --hot: #c4352a;
  --hot-soft: #ffe6e2;
  --lead: #0a7d4d;
  --lead-soft: #dff6ea;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font: 12px/1.35 Inter, Roobert, 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
}

button {
  font: inherit;
  color: inherit;
}

/* ---- placement -------------------------------------------------------------- */

body.mode-overlay {
  background: transparent;
  overflow: hidden;
  pointer-events: none; /* clicks outside the card reach the video */
}

body.mode-panel {
  background: var(--bg);
}

.board {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--line);
  overflow: hidden;
  pointer-events: auto;
}

.mode-overlay .board {
  position: absolute;
  top: 4.5rem; /* clear of the player's own top and bottom controls */
  right: 0.75rem;
  width: min(250px, 42vw);
  max-height: calc(100% - 9rem);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.mode-overlay .board--left {
  left: 0.75rem;
  right: auto;
}

.mode-panel .board {
  height: 100%;
  border: 0;
}

/* ---- header: tabs and collapse ------------------------------------------------ */

.board__head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
}

.tabs {
  display: flex;
  flex: 1;
  gap: 2px;
  min-width: 0;
}

.tab {
  flex: 1;
  min-width: 0;
  padding: 5px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
}

.tab[aria-selected='true'] {
  color: var(--text);
  background: var(--accent-soft);
}

.tab:focus-visible,
.collapse:focus-visible,
.vote:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.collapse {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.collapse:hover {
  color: var(--text);
  background: var(--card);
}

.collapse svg {
  transition: transform 0.15s ease;
}

.mode-panel .collapse {
  display: none;
}

.board.is-collapsed .collapse svg {
  transform: rotate(-90deg);
}

.board.is-collapsed .board__body {
  display: none;
}

.board.is-collapsed .tabs {
  display: none;
}

.board.is-collapsed .board__head::before {
  content: 'Chat Upvotes';
  flex: 1;
  padding: 0 6px;
  font-weight: 600;
}

/* ---- lists --------------------------------------------------------------------- */

.board__body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  border-top: 1px solid var(--line);
}

.list {
  flex: 1;
  margin: 0;
  padding: 6px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.list:empty {
  display: none;
}

.mode-overlay .list {
  overflow: hidden;
}

/* A message and its vote button. */
.msg {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.msg__body {
  flex: 1;
  min-width: 0;
}

.msg__meta {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.msg__user {
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg__hot {
  flex: none;
  padding: 0 4px;
  border-radius: 4px;
  border: 1px solid var(--hot);
  font-size: 9px;
  font-weight: 600;
  color: var(--hot);
  background: var(--hot-soft);
}

/* Streamer and moderator only: drawn by board.js, never for viewers. */
.trash {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: none;
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.trash:hover,
.trash:focus-visible {
  color: var(--hot);
  background: var(--hot-soft);
  outline: none;
}

.trash:disabled {
  opacity: 0.5;
  cursor: wait;
}

.msg__text {
  margin: 1px 0 0;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.mode-panel .msg__text {
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

/* The vote box: an arrow over the count. */
.vote {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 32px;
  height: 36px;
  flex: none;
  padding: 0;
  border-radius: 7px;
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 11px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.vote::before {
  content: '';
  border: 4px solid transparent;
  border-top-width: 0;
  border-bottom: 5px solid currentColor;
}

button.vote {
  cursor: pointer;
}

button.vote:hover {
  background: var(--accent);
  color: #14111c;
}

button.vote:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.vote.is-voted {
  background: var(--accent);
  color: #14111c;
}

.msg:first-child .vote:not(.is-voted) {
  color: var(--lead);
  background: var(--lead-soft);
  border-color: var(--lead);
}

.vote.is-bumped {
  animation: bump 0.35s ease;
}

@keyframes bump {
  40% {
    transform: scale(1.18);
  }
}

/* A chatter and their total. */
.chatter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chatter__rank {
  width: 1.2em;
  flex: none;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chatter:nth-child(1) .chatter__rank {
  color: var(--lead);
}

.chatter__name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chatter__score {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.chatter__score::after {
  content: '';
  border: 4px solid transparent;
  border-top-width: 0;
  border-bottom: 5px solid currentColor;
}

/* ---- footer hint ------------------------------------------------------------------ */

.hint {
  margin: 0;
  padding: 6px 8px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  text-align: center;
  color: var(--muted);
}

.list:empty + .hint {
  border-top: 0;
  padding: 14px 10px;
  font-size: 11px;
}

.hint.is-alert {
  color: var(--hot);
}

@media (prefers-reduced-motion: reduce) {
  .vote.is-bumped {
    animation: none;
  }
  .collapse svg {
    transition: none;
  }
}
