:root {
  --bg: #0a0908;
  --bg-2: #131110;
  --surface: rgba(20, 18, 16, 0.72);
  --surface-2: rgba(28, 25, 22, 0.85);
  --border: rgba(255, 255, 255, 0.08);
  --border-2: rgba(255, 255, 255, 0.14);
  --fg: #f5efe7;
  --fg-2: #c9c1b6;
  --dim: #7d756a;
  --accent: #e26a4d;
  --ok: #7ed27a;
  --warn: #f0a64a;
  --danger: #e54a4a;
  --shadow: 0 24px 60px -20px rgba(0,0,0,0.65), 0 4px 14px -6px rgba(0,0,0,0.4);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Inter", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", monospace;
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font-family: inherit; color: inherit; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ────────────── app shell ────────────── */
.app { display: flex; flex-direction: column; height: 100%; }
.app.layout-comfortable .stage-wrap { padding: 20px 20px 20px 20px; gap: 0; background: var(--bg); }
.app.layout-comfortable .stage { border-radius: 16px; overflow: hidden; box-shadow: 0 18px 50px -22px rgba(0,0,0,0.8), 0 0 0 1px rgba(255,255,255,0.06); }
.app.layout-comfortable .control-panel { left: 36px; bottom: 36px; }
.app.layout-comfortable .chat { right: 36px; bottom: 36px; }
.app.layout-comfortable .chat-fab { right: 36px; bottom: 36px; }

.glass {
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.mono { font-family: var(--mono); letter-spacing: 0.02em; }
.small { font-size: 11px; }
.dim { color: var(--dim); }

/* ────────────── top bar ────────────── */
.topbar {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 10px 16px;
  background: linear-gradient(180deg, rgba(10,9,8,0.95), rgba(10,9,8,0.7));
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 56px; height: 56px; object-fit: contain; display: block; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: linear-gradient(140deg, #221d18, #131110); border: 1px solid var(--border); }
.brand-title { font-weight: 600; font-size: 16px; letter-spacing: 0.01em; font-family: "Inter", system-ui, sans-serif; text-transform: uppercase; letter-spacing: 0.06em; }
.brand-sub { font-size: 11px; color: var(--dim); letter-spacing: 0.02em; }

.pills { display: flex; gap: 8px; align-items: center; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--fg-2);
  white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); box-shadow: 0 0 0 0 currentColor; }
.pill .dot.ok { background: var(--ok); }
.pill .dot.warn { background: var(--warn); }
.pill.live { color: #fff; }
.pill.live .dot { background: var(--danger); animation: pulse 1.6s ease-in-out infinite; }
.pill.turn { background: color-mix(in oklab, var(--accent) 16%, transparent); border-color: color-mix(in oklab, var(--accent) 45%, transparent); color: #fff; }
.pill.turn .mono { color: var(--accent); font-weight: 600; }

.pill.status { color: #fff; padding-left: 11px; background: transparent; border-color: transparent; cursor: default; }
.pill.status strong { font-weight: 600; }
.pill.status.is-live .dot { background: var(--ok); animation: pulse 1.6s ease-in-out infinite; }
.pill.status.is-down { color: var(--fg-2); }
.pill.status.is-down .dot { background: var(--danger); animation: none; }

.pill.watchers-wrap { position: relative; padding: 0; overflow: visible; background: rgba(255,255,255,0.06); border-color: var(--border-2); }
.pill-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: transparent; border: 0; cursor: pointer;
  padding: 6px 11px 6px 12px;
  border-radius: 999px;
  color: inherit;
  font: inherit;
  font-size: 12px;
}
.pill-btn:hover { background: rgba(255,255,255,0.1); }
.pill-btn strong { font-weight: 600; color: var(--fg); }

/* ────────────── viewers popover ────────────── */
.viewers-pop {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 320px;
  max-height: 480px;
  border-radius: 12px;
  z-index: 50;
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: pop-in 0.14s ease-out;
}
@keyframes pop-in { from { opacity: 0; transform: translate(-50%, -4px); } to { opacity: 1; transform: translate(-50%, 0); } }
.vp-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.vp-title { display: flex; align-items: center; gap: 8px; }
.vp-count { font-family: var(--mono); font-size: 14px; font-weight: 600; }
.vp-search {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--dim);
}
.vp-search input {
  flex: 1; background: transparent; border: 0; outline: none;
  font-family: inherit; font-size: 12px; color: var(--fg);
}
.vp-search input::placeholder { color: var(--dim); }
.vp-list { flex: 1; overflow-y: auto; padding: 6px 6px; }
.vp-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px;
  border-radius: 8px;
  position: relative;
}
.vp-row:hover { background: rgba(255,255,255,0.04); }
.vp-av { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #1a0e0a; }
.vp-info { flex: 1; min-width: 0; }
.vp-name { font-size: 13px; font-weight: 500; color: var(--fg); }
.vp-meta { font-size: 11px; line-height: 1.2; }
.vp-actions { position: relative; }
.vp-actions .icon-btn { opacity: 0; }
.vp-row:hover .vp-actions .icon-btn { opacity: 1; }
.vp-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 160px;
  padding: 4px;
  border-radius: 8px;
  display: flex; flex-direction: column;
  z-index: 5;
}
.vp-menu button {
  background: transparent; border: 0; color: var(--fg-2);
  padding: 7px 10px; border-radius: 6px; cursor: pointer;
  font-size: 12px; text-align: left; font-family: inherit;
}
.vp-menu button:hover { background: rgba(255,255,255,0.06); color: var(--fg); }
.vp-menu button.danger { color: #ff8a7a; }
.vp-menu button.danger:hover { background: rgba(229,74,74,0.14); color: #ff9d8e; }
.vp-empty { padding: 16px; text-align: center; font-size: 12px; }
.vp-foot { padding: 8px 14px; border-top: 1px solid var(--border); }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(229,74,74,0.5); }
  50% { box-shadow: 0 0 0 6px rgba(229,74,74,0); }
}

.user { display: flex; align-items: center; gap: 10px; justify-self: end; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, #e26a4d, #b8472a); display: grid; place-items: center; font-size: 12px; font-weight: 600; }
.avatar-img { object-fit: cover; background: none; }
.user-info { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.user-name { font-size: 12px; }
.logout { background: none; border: 0; color: var(--dim); padding: 0; font-size: 11px; cursor: pointer; white-space: nowrap; }
.logout:hover { color: var(--fg-2); }

/* ────────────── stage ────────────── */
.stage-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

.stage { position: absolute; inset: 0; overflow: hidden; }
.feed { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: contrast(1.02) saturate(1.05); }

.vignette {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.55) 100%),
    linear-gradient(180deg, rgba(0,0,0,0.45) 0%, transparent 18%, transparent 65%, rgba(0,0,0,0.75) 100%);
}

.hud { position: absolute; color: rgba(255,255,255,0.85); text-shadow: 0 1px 3px rgba(0,0,0,0.7); pointer-events: none; }
.hud-tl { top: 14px; left: 18px; display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.hud-tr { top: 14px; right: 18px; text-align: right; display: flex; flex-direction: column; gap: 3px; align-items: flex-end; font-size: 11px; }
.bars { display: inline-flex; gap: 2px; vertical-align: middle; }
.bars i { width: 3px; height: 8px; background: rgba(255,255,255,0.25); display: inline-block; border-radius: 1px; }
.bars i.on { background: var(--ok); }
.bars i:nth-child(1).on { height: 4px; }
.bars i:nth-child(2).on { height: 6px; }
.bars i:nth-child(3).on { height: 8px; }
.bars i:nth-child(4).on { height: 10px; }

.crosshair { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ────────────── control panel ────────────── */
.control-panel {
  position: absolute;
  left: 24px;
  bottom: 24px;
  width: 320px;
  padding: 14px;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cp-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  /* Graceful fallback: if the status pill and hold button ever can't
     both fit (e.g. a double-digit takeover timer), let the button drop
     to its own line rather than clip. The panel is sized (stream-swap
     .ss-control-panel) so the normal case stays on one line; combined
     with .q-btn-hold's flex:none this guarantees the label is never
     flex-shrunk under .is-hold's overflow:hidden and truncated. */
  flex-wrap: wrap;
}
.cp-title { display: flex; flex-direction: column; gap: 2px; }
.cp-state {
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  border: 1px solid transparent;
}
.cp-state .cp-time {
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.02em;
}
.cp-state .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); display: inline-block; }
.cp-state .dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.cp-state .dot.warn { background: var(--warn); }

.q-btn {
  border: 0;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border-2);
  color: var(--fg);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.06s, filter 0.15s, background 0.15s, border-color 0.15s;
}
/* Never shrink a hold button below its label; .is-hold clips overflow
   for the progress fill, so a shrunk button would truncate its text. */
.q-btn-hold { flex: none; }
.q-btn:hover { background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.22); }
.q-btn.primary { color: #fff; border-color: transparent; box-shadow: 0 6px 18px -8px var(--accent); }
.q-btn.primary:hover { background: var(--accent); filter: brightness(1.1); }
.q-btn:active { transform: scale(0.97); }

.cp-body { display: flex; flex-direction: column; gap: 14px; }

/* dpad */
/* position:relative anchors the .dpad-lock scrim (stream-swap.css) that
   covers the button grid while the pad is locked out. */
.dpad { position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.dpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
}
.dpad-btn {
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border: 1px solid var(--border-2);
  border-radius: 12px;
  display: grid; place-items: center;
  color: var(--fg);
  cursor: pointer;
  transition: transform 0.06s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.dpad-btn:hover { background: rgba(255,255,255,0.1); }
.dpad-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a0e0a;
  transform: scale(0.94);
  box-shadow: 0 0 24px -4px var(--accent);
}
.dpad-center { display: grid; place-items: center; border: 1px dashed var(--border); border-radius: 12px; }
.key-hints { display: flex; align-items: center; gap: 4px; }
kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 6px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--fg-2);
}

/* joystick */
.joystick {
  position: relative;
  width: 184px; height: 184px; align-self: center;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 40%, rgba(255,255,255,0.08), rgba(255,255,255,0.02) 50%),
    rgba(0,0,0,0.3);
  border: 1px solid var(--border-2);
  touch-action: none;
  user-select: none;
}
.joy-ring { position: absolute; inset: 14px; border-radius: 50%; border: 1px dashed rgba(255,255,255,0.12); }
.joy-cross { position: absolute; inset: 0; }
.joy-cross span { position: absolute; background: rgba(255,255,255,0.08); }
.joy-cross span:nth-child(1) { left: 50%; top: 20%; bottom: 20%; width: 1px; }
.joy-cross span:nth-child(2) { top: 50%; left: 20%; right: 20%; height: 1px; }
.joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 56px; height: 56px;
  background: radial-gradient(circle at 50% 30%, #e9886e, var(--accent));
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(0,0,0,0.5), 0 0 24px -4px var(--accent), inset 0 -2px 6px rgba(0,0,0,0.4);
  cursor: grab;
  display: grid; place-items: center;
}
.joy-knob:active { cursor: grabbing; }
.joy-grip { width: 14px; height: 14px; border-radius: 50%; background: rgba(0,0,0,0.18); }
.joy-label { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); pointer-events: none; }

/* meters */
.cp-meters { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.meter-head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.meter-bar { width: 100%; height: 6px; background: rgba(255,255,255,0.07); border-radius: 999px; overflow: hidden; }
.meter-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--ok), #b0e3a4); border-radius: 999px; }
.meter-range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; background: transparent;
  background-image: linear-gradient(90deg, var(--accent) 0%, var(--accent) var(--v), rgba(255,255,255,0.07) var(--v), rgba(255,255,255,0.07) 100%);
  border-radius: 999px;
  cursor: pointer;
}
.meter-range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 14px; height: 14px; background: var(--fg); border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.5); margin-top: 0; }
.meter-range::-moz-range-thumb { width: 14px; height: 14px; background: var(--fg); border-radius: 50%; border: 0; }

/* ────────────── chat ────────────── */
.chat {
  position: absolute;
  right: 24px;
  bottom: 24px;
  width: 340px;
  height: min(520px, calc(100% - 48px));
  max-height: calc(100% - 48px);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.chat-resize {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 10px;
  cursor: ns-resize;
  display: flex; align-items: center; justify-content: center;
  z-index: 2;
}
.chat-resize-grip {
  width: 36px; height: 3px;
  border-radius: 999px;
  background: rgba(255,255,255,0.18);
  transition: background 0.15s;
}
.chat-resize:hover .chat-resize-grip { background: rgba(255,255,255,0.35); }
.chat-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
}
.chat-title { display: flex; align-items: center; gap: 8px; }
.chat-count {
  font-size: 10px;
  padding: 1px 6px;
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  color: var(--fg-2);
}
.icon-btn { background: none; border: 0; color: var(--fg-2); cursor: pointer; padding: 4px; border-radius: 6px; }
.icon-btn:hover { background: rgba(255,255,255,0.06); color: var(--fg); }

.chat-list { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; gap: 10px; }
.msg-system { width: 100%; text-align: center; color: var(--dim); padding: 4px 0; }
.msg-avatar { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600; color: #1a0e0a; }
.msg-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.msg-meta { display: flex; gap: 8px; align-items: baseline; }
.msg-user { font-size: 12px; font-weight: 600; color: var(--fg); }
.msg-time { font-size: 10px; white-space: nowrap; }
.msg-text { font-size: 13px; color: var(--fg-2); line-height: 1.4; word-wrap: break-word; }

.chat-compose {
  display: flex; gap: 8px; padding: 10px;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.2);
}
.chat-compose input {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.chat-compose input::placeholder { color: var(--dim); }
.chat-compose input:focus { border-color: var(--accent); background: rgba(255,255,255,0.07); }
.send-btn { background: var(--accent); border: 0; border-radius: 8px; padding: 0 12px; color: #1a0e0a; cursor: pointer; display: grid; place-items: center; }
.send-btn:hover { filter: brightness(1.08); }

.chat-fab {
  position: absolute; right: 24px; bottom: 24px;
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border-2);
  display: grid; place-items: center;
  cursor: pointer;
  color: var(--fg);
}
.chat-fab:hover { background: var(--surface-2); }
.chat-fab-count {
  position: absolute; top: -4px; right: -4px;
  font-size: 10px; min-width: 18px; height: 18px;
  background: var(--accent); color: #1a0e0a;
  border-radius: 999px; padding: 0 5px;
  display: grid; place-items: center; font-weight: 600;
  border: 2px solid var(--bg);
}

/* ────────────── small screens ────────────── */
@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr auto; }
  .pills { display: none; }
  .control-panel { width: calc(100% - 32px); left: 16px; right: 16px; bottom: 16px; }
  .chat { right: 16px; bottom: 16px; }
}
