:root {
  --bg: #0d0f12;
  --panel: #14171c;
  --panel-2: #1a1e25;
  --line: #262c35;
  --text: #e6e8ec;
  --muted: #8b94a3;
  --accent: #9147ff;      /* twitch purple */
  --live: #ff4d4f;
  --ok: #3ddc84;
  --sidebar-w: 380px;
  --tile-head: 22px;
  --gap: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

button, input { font: inherit; color: inherit; }
a { color: #b394ff; }

#app {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 100dvh;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-height: 46px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: baseline; gap: 8px; margin-right: 4px; }
.brand__mark { font-weight: 800; letter-spacing: .08em; color: var(--accent); }
.brand__raid { color: var(--muted); font-size: 12px; white-space: nowrap; }

.spacer { flex: 1 1 auto; }

.channels { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { border-color: #3a4350; color: var(--text); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip__dot { width: 7px; height: 7px; border-radius: 50%; background: #4b5563; flex: none; }
.chip__dot--live { background: var(--live); box-shadow: 0 0 0 3px rgba(255, 77, 79, .18); }
.modes { display: flex; }
.modes button {
  padding: 5px 11px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
}
.modes button:first-child { border-radius: 6px 0 0 6px; }
.modes button:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
.modes button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.toggle {
  padding: 5px 11px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.toggle:hover { color: var(--text); }
.toggle[aria-pressed="true"] { border-color: var(--accent); color: #fff; }

/* ---------- race bar ---------- */

.racebar {
  display: flex;
  align-items: stretch;
  gap: 18px;
  padding: 8px 10px 9px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: thin;
}
#app[data-racebar="off"] .racebar { display: none; }

.racebar__section { display: flex; align-items: stretch; gap: 9px; min-width: max-content; }
.racebar__section--standings { border-left: 1px solid var(--line); padding-left: 18px; }
.racebar__heading { width: 112px; display: flex; flex-direction: column; justify-content: center; gap: 3px; flex: none; }
.racebar__label { color: var(--text); font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.racebar__summary { color: var(--muted); font-size: 11px; font-weight: 500; line-height: 1.25; }
.racebar__hint { color: var(--muted); font-size: 11px; line-height: 1.25; }
.racebar__meter { width: 100%; height: 4px; overflow: hidden; border-radius: 999px; background: #303640; }
.racebar__meter > span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--ok); transition: width .3s ease; }

.racebar__bosses { display: flex; gap: 6px; }

.boss {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 8px 4px 4px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  white-space: nowrap;
  opacity: .45;
}
.boss--down { opacity: 1; border-color: #335e45; background: #17231d; }
.boss--next { opacity: 1; border-color: var(--accent); background: #211a31; box-shadow: inset 0 0 0 1px rgba(145, 71, 255, .15); }
.boss img { width: 26px; height: 26px; border-radius: 5px; flex: none; filter: grayscale(1); }
.boss--down img, .boss--next img { filter: none; }
.boss__txt { display: flex; flex-direction: column; line-height: 1.2; }
.boss__name { font-size: 12px; font-weight: 600; }
.boss__meta { font-size: 11px; color: var(--muted); }
.boss__meta b { color: var(--ok); font-weight: 600; }
.boss__meta .boss__current { color: #c7a9ff; text-transform: uppercase; letter-spacing: .04em; }

.racebar__board { display: flex; gap: 6px; }

.rank {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 9px 4px 5px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  white-space: nowrap;
  cursor: default;
}
.rank--clickable { cursor: pointer; }
.rank--clickable:hover { border-color: var(--accent); }
.rank img { width: 24px; height: 24px; border-radius: 4px; object-fit: contain; flex: none; }
.rank__no { font-weight: 800; color: var(--muted); font-size: 12px; width: 16px; text-align: right; }
.rank__txt { display: flex; flex-direction: column; line-height: 1.2; }
.rank__name { font-size: 12px; font-weight: 600; }
.rank__live { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.rank__live b { color: var(--live); font-weight: 600; }

/* ---------- body split ---------- */

.body { display: flex; min-height: 0; }

.wall { position: relative; flex: 1 1 auto; min-width: 0; background: #08090b; }

.stage { position: absolute; inset: 0; }

.stage__empty[hidden] { display: none; }

.stage__empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  margin: 0;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.resizer { width: 6px; cursor: col-resize; background: var(--line); flex: none; }
.resizer:hover, .resizer:focus-visible { background: var(--accent); outline: none; }

.side {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

#app[data-sidebar="off"] .side,
#app[data-sidebar="off"] .resizer { display: none; }

/* ---------- feed ---------- */

.side__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px 6px;
}
.side__title { font-weight: 700; }
.side__title a { text-decoration: none; opacity: .6; }
.side__title a:hover { opacity: 1; }
.side__status { font-size: 11px; color: var(--muted); white-space: nowrap; }
.side__status[data-state="error"] { color: var(--live); }

.newposts {
  margin: 6px 10px 0;
  padding: 5px;
  border-radius: 6px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.feed { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 8px 10px 24px; scrollbar-width: thin; }

.post {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 8px 10px;
  margin-bottom: 8px;
}
.post--priority { border-color: var(--live); }
.post--fresh { animation: flash 2.5s ease-out; }
@keyframes flash { from { border-color: var(--accent); background: #241b3a; } }

.post__head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.post__avatar { width: 20px; height: 20px; border-radius: 4px; flex: none; }
.post__author { font-size: 12px; font-weight: 600; }
.post__time { font-size: 11px; color: var(--muted); margin-left: auto; white-space: nowrap; }

.post__body { font-size: 13px; overflow-wrap: anywhere; }
.post__body img { max-width: 100%; height: auto; border-radius: 6px; display: block; margin: 6px auto; }
.post__body blockquote { margin: 6px 0; padding-left: 10px; border-left: 2px solid var(--line); color: var(--muted); }
.post__body table { width: 100%; border-collapse: collapse; font-size: 12px; }
.post__body td, .post__body th { border: 1px solid var(--line); padding: 3px 5px; }
.post__body > :first-child { margin-top: 0; }
.post__body > :last-child { margin-bottom: 0; }

/* ---------- tiles ---------- */

.tile {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
  transition: transform .18s ease, width .18s ease, height .18s ease;
  will-change: transform;
}
.tile--audio { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.tile__head {
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--tile-head);
  padding: 0 4px 0 8px;
  background: var(--panel);
  font-size: 12px;
  flex: none;
}
.tile__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile__guild { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile__head .grow { flex: 1 1 auto; }
.tile__head button {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  font-size: 13px;
}
.tile__head button:hover { color: var(--text); }
.tile__head button[aria-pressed="true"] { color: var(--accent); }

.tile__player { flex: 1 1 auto; min-height: 0; }
.tile__player iframe { display: block; width: 100%; height: 100%; border: 0; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 8px;
  background: #000c;
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  z-index: 50;
}

@media (max-width: 860px) {
  .side { width: min(var(--sidebar-w), 60vw); }
}
