/* LurkerTV — Twitch-dark theme */

:root {
  --bg: #0e0e10;
  --panel: #18181b;
  --panel-2: #1f1f23;
  --line: #2f2f35;
  --text: #efeff1;
  --text-dim: #adadb8;
  --text-faint: #77777f;
  --accent: #9147ff;
  --accent-hi: #a970ff;
  --live: #eb0400;
  --chat-w: 340px;
  font-size: 15px;
}

* { box-sizing: border-box; }

/* author display rules must never defeat the hidden attribute
   (this exact bug left the offline cover covering the live video) */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  overflow: hidden;
}
/* dynamic viewport: keeps the chat bar out from under iOS/Android browser chrome */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}
/* topbar sizes itself; main fills the rest (the topbar height changes on phones) */
body { display: flex; flex-direction: column; }

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

#topbar {
  height: 50px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 800;
  letter-spacing: 0.02em;
  font-size: 17px;
}
.brand::before {
  content: "";
  display: inline-block;
  width: 10px; height: 22px;
  margin-right: 10px;
  vertical-align: -4px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
}
.brand .beta {
  font-weight: 500;
  font-size: 12px;
  color: var(--text-dim);
  margin-left: 8px;
}

#controls { display: flex; align-items: center; gap: 12px; }

select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}

.toggle {
  display: flex; align-items: center; gap: 5px;
  font-size: 13px; color: var(--text-dim);
  cursor: pointer; user-select: none;
}
.toggle input { accent-color: var(--accent); width: 15px; height: 15px; }

button {
  font: inherit;
  border: none;
  border-radius: 6px;
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-hi); }
button.primary:disabled { background: #3b2a63; color: #8f8f98; cursor: wait; }
button.ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--line); }
button.ghost:hover { color: var(--text); }

/* ---------- layout ---------- */

main {
  display: flex;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1720px;   /* ultrawide: center the whole layout instead of stretching */
  margin: 0 auto;
}

#stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 10px;
}

#video-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}

#cam, #demo-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#frame-capture { display: none; }

/* offline cover */
#offline-cover {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1200px 500px at 20% -10%, rgba(145,71,255,.18), transparent 60%),
    radial-gradient(900px 500px at 90% 110%, rgba(145,71,255,.10), transparent 60%),
    #000;
}
.offline-inner { text-align: center; max-width: 560px; padding: 24px; }
.offline-logo {
  font-size: 42px; font-weight: 900; letter-spacing: 0.04em;
  background: linear-gradient(90deg, var(--accent-hi), #fff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 10px;
}
.offline-line { font-size: 16px; margin: 8px 0; }
.offline-line.dim { color: var(--text-dim); font-size: 14px; line-height: 1.5; }
.offline-line.dim2 { color: var(--text-faint); font-size: 13px; }

/* stream overlays */
#overlay {
  position: absolute; top: 12px; left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: center;
  pointer-events: none;
}
#live-badge {
  background: var(--live);
  color: #fff;
  font-size: 12px; font-weight: 800; letter-spacing: 0.08em;
  padding: 4px 10px;
  border-radius: 5px;
  animation: livepulse 2s ease-in-out infinite;
}
@keyframes livepulse { 50% { opacity: .75; } }

#viewers {
  background: rgba(0,0,0,.55);
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 12px; font-weight: 600;
  color: #fff;
}
#viewers span { color: #ff8280; }

#title-card {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 26px 14px 10px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.75));
  font-size: 14px; font-weight: 600;
  text-shadow: 0 1px 2px rgba(0,0,0,.8);
  pointer-events: none;
}

#captions {
  position: absolute;
  left: 50%; bottom: 44px;
  transform: translateX(-50%);
  max-width: 80%;
  background: rgba(0,0,0,.66);
  color: #fff;
  font-size: 15px;
  line-height: 1.4;
  padding: 7px 14px;
  border-radius: 8px;
  text-align: center;
  pointer-events: none;
  transition: opacity .3s;
  opacity: 0;
}
#captions.on { opacity: 1; }

/* status strip */
#status-strip {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--text-dim);
  min-height: 26px;
}
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #55555e; flex: none;
}
.dot.ok { background: #00c78b; }
.dot.busy { background: #faaf19; animation: livepulse 1.2s infinite; }
.dot.err { background: var(--live); }

#load-progress {
  flex: 1; max-width: 380px;
  height: 8px;
  background: var(--panel-2);
  border-radius: 4px;
  overflow: hidden;
}
#load-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hi));
  transition: width .2s;
}
#load-pct { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--text-faint); }

/* ---------- chat ---------- */

#chat-panel {
  width: clamp(300px, 24vw, 420px);
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

#chat-header {
  padding: 10px 14px;
  font-size: 13px; font-weight: 700;
  color: var(--text-dim);
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.msg {
  padding: 4px 14px;
  font-size: 13.5px;
  line-height: 1.45;
  word-wrap: break-word;
  animation: msgin .18s ease-out;
}
@keyframes msgin {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}
.msg .user { font-weight: 700; }
.msg .sep { color: var(--text-dim); }
.msg .text { color: var(--text); }
.msg .emote { font-weight: 700; color: #f5a9ff; }

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

.msg.modmsg {
  color: #ffd8a8;
  background: rgba(250,175,25,.10);
  border-left: 3px solid #faaf19;
  margin-left: 8px;
  padding-left: 11px;
  border-radius: 3px;
  font-size: 12.5px;
}

/* viewer badges (❓ question-askers, golden chat MVP) */
.ubadge {
  display: inline-block;
  font-size: 9px;
  font-weight: 800;
  border-radius: 3px;
  padding: 1px 4px;
  vertical-align: 1px;
  margin-right: 5px;
  letter-spacing: .02em;
}
.ubadge.q { background: #34343c; color: #ffd8a8; }
.ubadge.mvp { background: #faaf19; color: #000; }

/* real emote images (BTTV/FFZ/7TV global sets) */
.msg .emote-img {
  height: 20px;
  vertical-align: -5px;
  margin: 0 1px;
}

.msg .user { cursor: pointer; }
.msg .user:hover { text-decoration: underline; cursor: pointer; }

/* mod card — Twitch-usercard style, draggable by the header */
#modcard {
  position: fixed;
  z-index: 50;
  width: 300px;
  background: #17171a;
  border: 1px solid #3b3b44;
  border-radius: 10px;
  box-shadow: 0 14px 40px rgba(0,0,0,.6);
  overflow: hidden;
  user-select: none;
}
.mc-head {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 8px;
  padding: 12px;
  background: #1f1f23;
  border-bottom: 1px solid #3b3b44;
  cursor: grab;
}
.mc-head:active { cursor: grabbing; }
.mc-title {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
  color: #efeff1;
}
.mc-id { min-width: 0; }
.mc-namerow { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.mc-namerow b { font-size: 14px; }
.mc-chip {
  font-size: 9.5px;
  color: #adadb8;
  background: #2a2a31;
  border-radius: 3px;
  padding: 1px 5px;
  white-space: nowrap;
}
.mc-stat { font-size: 11px; color: #adadb8; line-height: 1.5; white-space: nowrap; }
.mc-close { color: #77777f; cursor: pointer; font-size: 13px; }
.mc-close:hover { color: #efeff1; }

.mc-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid #2a2a31;
}
.mc-pills button {
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #2a2a31;
  border: 1px solid #3b3b44;
  color: #efeff1;
}
.mc-pills button:hover { border-color: #77777f; }
.mc-pills .mc-yell { color: #ffd8a8; border-color: #5c4b2b; }
.mc-pills .mc-warn { color: #ff8280; border-color: #5c2b2b; }

.mc-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 2px;
}
.mc-strip-label {
  flex: 1;
  text-align: center;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #77777f;
}
.mc-unban, .mc-banforever {
  width: 26px; height: 26px;
  border-radius: 50%;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid #3b3b44;
  background: #1f1f23;
}
.mc-unban { color: #00c78b; }
.mc-banforever { color: #ff4f4f; }
.mc-unban:hover, .mc-banforever:hover { border-color: #77777f; }

.mc-durs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 12px 10px;
  border-bottom: 1px solid #2a2a31;
}
.mc-durs button {
  flex: 1;
  min-width: 30px;
  font-size: 11px;
  padding: 4px 0;
  background: #1f1f23;
  border: 1px solid #3b3b44;
  color: #adadb8;
  border-radius: 4px;
}
.mc-durs button:hover { color: #efeff1; border-color: #77777f; }

.mc-msgs {
  max-height: 150px;
  overflow-y: auto;
  padding: 8px 12px;
}
.mc-msg {
  font-size: 12px;
  color: #efeff1;
  padding: 3px 6px;
  border-radius: 4px;
  word-wrap: break-word;
}
.mc-msg.hot { background: #3b1d1f; }
.mc-msg.dim { color: #77777f; font-style: italic; }

.msg.streamer {
  background: rgba(145,71,255,.12);
  border-left: 3px solid var(--accent);
  margin-left: 8px;
  padding-left: 11px;
  border-radius: 3px;
}
.msg.streamer .badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 10px; font-weight: 800;
  border-radius: 3px;
  padding: 1px 5px;
  margin-right: 6px;
  vertical-align: 1px;
}

#chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
}
#chat-input {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
}
#chat-input:focus { outline: none; border-color: var(--accent); }
#chat-form button {
  background: var(--accent); color: #fff;
}
#chat-form button:hover { background: var(--accent-hi); }

#chat-panel.disabled #chat-form { opacity: .45; pointer-events: none; }

/* settings popover */
#settings {
  position: absolute;
  top: calc(100% + 4px); /* below the topbar however tall it has wrapped */
  right: 12px;
  z-index: 60;
  width: 300px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 32px rgba(0,0,0,.55);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#topbar { position: relative; }
.set-head {
  font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-faint);
}
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.set-row label { font-size: 13px; color: var(--text-dim); }
.set-note { font-size: 11.5px; color: var(--text-faint); line-height: 1.45; }
.set-lat { font-size: 12px; color: var(--text-dim); line-height: 1.5; font-variant-numeric: tabular-nums; }

#lat-chip {
  font-size: 11.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* chat memory (facts) */
.fact-list {
  max-height: 150px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.fact-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
}
.fact-text { flex: 1; font-size: 12px; color: var(--text-dim); word-wrap: break-word; }
.fact-del {
  background: none;
  color: var(--text-faint);
  padding: 0 4px;
  font-size: 11px;
}
.fact-del:hover { color: var(--live); }
#fact-input {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
}
#fact-input:focus { outline: none; border-color: var(--accent); }
#fact-add { padding: 4px 10px; }

@media (max-width: 760px) {
  /* phone (e.g. opened over tailscale): stack video over chat */
  main { flex-direction: column; }
  .brand .beta { display: none; }

  /* controls wrap to their own row — a <select> won't shrink below its longest
     option, which used to push Go live and ⚙ off-screen */
  #topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: 50px;
    padding: 8px 12px;
    row-gap: 8px;
  }
  #controls { flex-basis: 100%; gap: 8px; min-width: 0; }
  #model-select { flex: 1; min-width: 0; }

  #stage { padding: 10px; flex: none; height: 56%; }
  #chat-panel {
    width: 100%;
    flex: 1;
    border-left: none;
    border-top: 1px solid var(--line);
  }

  /* settings popover: full-width sheet below the (possibly wrapped) topbar */
  #settings {
    left: 8px;
    right: 8px;
    width: auto;
    max-height: 80vh;
  }
  @supports (height: 100dvh) {
    #settings { max-height: calc(100dvh - 96px); }
  }

  /* 16px stops iOS Safari from zooming the page when a field gains focus */
  #chat-input, #fact-input { font-size: 16px; }
}
