:root {
  --bg: #0e0f13;
  --panel: #171920;
  --panel-2: #1f222b;
  --line: #2a2e39;
  --text: #e8e9ee;
  --muted: #9097a6;
  --accent: #7c9cff;
  --live: #ff3b4e;
  --mod: #3ccf91;
  --error: #ff7a85;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); display: flex; flex-direction: column; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* Desktop: video top-left, two rider panels under it, chat full height on the right. */
.layout {
  flex: 1; min-height: 0; height: 100vh;
  display: grid; gap: 8px; padding: 8px;
  grid-template-columns: minmax(220px, 1fr) minmax(0, 3fr) clamp(290px, 21vw, 380px);
  grid-template-rows: minmax(0, 2.25fr) minmax(0, 1fr);
  grid-template-areas:
    "video   video   chat"
    "search  watcher chat";
}
.video { grid-area: video; position: relative; min-width: 0; background: #000; border-radius: var(--radius); overflow: hidden; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.rider-search { grid-area: search; }
.rider-watcher { grid-area: watcher; }
.chat { grid-area: chat; }

.panel {
  min-width: 0; min-height: 0; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem .9rem; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: .95rem; font-weight: 650; }
.panel-body { flex: 1; min-height: 0; overflow: auto; padding: .8rem .9rem; display: flex; flex-direction: column; gap: .6rem; }
.panel-body input[type="search"] { flex: none; }
.placeholder-note { margin: 0; color: var(--muted); font-size: .82rem; }
.tag {
  font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--accent); border: 1px solid currentColor; border-radius: 999px; padding: .1rem .5rem; white-space: nowrap;
}
.rider-card {
  max-width: 460px; padding: .6rem .75rem; border-radius: 8px;
  background: var(--panel-2); border: 1px dashed var(--line);
}
.rider-name { font-weight: 650; font-size: .85rem; color: var(--muted); }
.rider-meta { display: flex; gap: 1rem; font-size: .75rem; color: var(--muted); margin-top: .15rem; }
.rider-bar { height: 2.2rem; margin-top: .5rem; border-radius: 6px; background: linear-gradient(90deg, var(--line), var(--panel-2)); }

.pill {
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  padding: .15rem .5rem; border-radius: 999px; background: var(--panel-2); color: var(--muted);
}
.pill.live { background: var(--live); color: #fff; }
.meta { color: var(--muted); font-size: .8rem; }
.stream-title { margin: .35rem 0 0; font-size: .85rem; font-weight: 500; overflow-wrap: anywhere; }

.chat {
  min-height: 0; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.chat-head { padding: .6rem .9rem; border-bottom: 1px solid var(--line); }
.chat-head-row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.chat-head-row.meta { margin-top: .2rem; }
.chat-label { font-weight: 650; font-size: .95rem; }
.messages { flex: 1; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: .5rem 0; }
.msg { padding: .3rem .9rem; line-height: 1.4; font-size: .92rem; overflow-wrap: anywhere; position: relative; }
.msg:hover { background: var(--panel-2); }
.msg .time { color: var(--muted); font-size: .72rem; margin-right: .4rem; font-variant-numeric: tabular-nums; }
.msg .name { font-weight: 650; margin-right: .35rem; }
.msg .text { white-space: pre-wrap; }
.msg.system { color: var(--muted); font-style: italic; font-size: .85rem; }
.msg.system.err { color: var(--error); font-style: normal; }
.badge {
  display: inline-block; font-size: .62rem; font-weight: 800; letter-spacing: .05em;
  background: var(--mod); color: #062; border-radius: 4px; padding: .05rem .3rem; margin: 0 .35rem 0 .25rem; vertical-align: 1px;
}
.mod-actions { display: none; position: absolute; right: .5rem; top: .2rem; gap: .25rem; }
body.is-mod .msg:hover .mod-actions { display: flex; }
.mod-actions button { font-size: .72rem; padding: .15rem .45rem; background: var(--panel); border: 1px solid var(--line); color: var(--text); }
.mod-actions button.danger { color: var(--error); }

.conn { padding: .4rem .9rem; font-size: .8rem; color: var(--muted); border-top: 1px solid var(--line); }
.composer { border-top: 1px solid var(--line); padding: .7rem .9rem; margin: 0; }
.row { display: flex; gap: .5rem; align-items: flex-end; }
input, textarea {
  flex: 1; min-width: 0; font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: .5rem .65rem; resize: none; max-height: 7.5rem;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
button {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 8px;
  padding: .5rem .9rem; background: var(--accent); color: #0b1020;
}
button:disabled { opacity: .55; cursor: default; }
button.link { background: none; color: var(--accent); padding: 0; font-weight: 600; border-radius: 0; }
button.link:hover { text-decoration: underline; }
.hint { color: var(--muted); font-size: .85rem; margin: 0 0 .45rem; display: block; }
.hint.small { font-size: .78rem; margin: .45rem 0 0; }
.error { color: var(--error); font-size: .82rem; margin: .4rem 0 0; min-height: 1em; }
.error:empty { display: none; }

/* Narrow screens: stack video, chat, then the rider panels. */
@media (max-width: 900px) {
  .layout { display: flex; flex-direction: column; height: auto; padding: 6px; gap: 6px; }
  .video { flex: none; width: 100%; aspect-ratio: 16 / 9; border-radius: 6px; }
  .chat { flex: none; height: 70vh; min-height: 360px; }
  .chat { order: 1; }
  .rider-search { order: 2; flex: none; }
  .rider-watcher { order: 3; flex: none; }
  .panel-body { overflow: visible; }
}
