:root {
  --bg: #0b0d12;
  --surface: #141821;
  --surface-2: #1b2030;
  --surface-3: #252c40;
  --border: #262c3b;
  --text: #e9ecf3;
  --muted: #8b93a7;
  --accent: #7c5cff;
  --accent-2: #4f8cff;
  --ok: #3ecf8e;
  --warn: #f5b84d;
  --bad: #ff6b6b;
  --radius: 14px;
  --header-h: 60px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

button {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background .12s, border-color .12s, opacity .12s;
}
button:hover { background: var(--surface-3); }
button:active, button.pressed { background: var(--accent); border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0;
  font-weight: 600;
}
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: var(--surface-2); }
button.chip { padding: 6px 12px; font-size: 13px; border-radius: 999px; }
button.chip.on { background: var(--accent); border-color: var(--accent); }

input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

/* --- brand ------------------------------------------------------------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.logo {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 13px; color: #fff;
}
.brand-lg { font-size: 26px; justify-content: center; }
.brand-lg .logo { width: 42px; height: 42px; border-radius: 12px; font-size: 18px; }

/* --- login ------------------------------------------------------------- */
.login-body {
  display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 50% -10%, #1d1840 0%, var(--bg) 60%);
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 32px 24px;
}
.login-sub { color: var(--muted); text-align: center; margin: 8px 0 24px; }
.login-card form { display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card button { padding: 12px; margin-top: 4px; }
.login-error { color: var(--bad); min-height: 1.2em; margin: 0; font-size: 13px; }
.login-card .field-hint { font-size: 11px; }

/* --- header ------------------------------------------------------------ */
.top {
  height: var(--header-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 13, 18, .85);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.viewers {
  flex: 1; display: flex; justify-content: flex-end; gap: 4px; min-width: 0;
  overflow: hidden; padding: 3px;   /* room for the remote-holder ring */
}
.avatar {
  display: grid; place-items: center; flex: none;
  width: 30px; height: 30px; border-radius: 50%;
  font-size: 13px; font-weight: 700; color: #fff;
  border: 2px solid var(--bg);
  text-transform: uppercase;
}
.avatar.holder { border-color: var(--ok); box-shadow: 0 0 0 1px var(--ok); }
.me { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }

/* --- layout ------------------------------------------------------------ */
.layout {
  display: grid; gap: 16px; padding: 16px;
  grid-template-columns: 1fr;
  max-width: 1600px; margin: 0 auto;
}
@media (min-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr) 360px; height: calc(100vh - var(--header-h)); }
}
/* (the desktop side column's sizing is at the end of this file, so it wins over the base rules) */

/* --- player ------------------------------------------------------------ */
.stage { min-width: 0; }
.player {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.player video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.badge {
  position: absolute; top: 12px; left: 12px;
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(0, 0, 0, .6); font-size: 12px; font-weight: 600; letter-spacing: .3px;
}
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.badge.live .pulse { background: var(--bad); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.player-controls {
  position: absolute; right: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.player-controls button { background: rgba(0, 0, 0, .6); border-color: transparent; }
.icon-btn { padding: 6px 10px; font-size: 16px; }

/* Your own volume: speaker button + slider in one pill */
.volume {
  display: flex; align-items: center; gap: 4px;
  background: rgba(0, 0, 0, .6); border-radius: 10px; padding-right: 10px;
}
.volume .icon-btn { background: transparent; }
.unmute-hint { font-size: 13px; cursor: pointer; padding-right: 2px; }
.volume input[type=range] {
  width: 90px; padding: 0; border: 0; background: transparent; cursor: pointer;
  -webkit-appearance: none; appearance: none; height: 18px;
}
.volume input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, #fff var(--fill, 100%), rgba(255, 255, 255, .3) var(--fill, 100%));
}
.volume input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px;
  border-radius: 50%; background: #fff; border: 0;
}
.volume input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .3); }
.volume input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: #fff; }
.volume input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 0; }
.volume input[type=range]:focus { outline: none; }
.volume input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--accent); }

/* Auto-hide: fade the overlays when the mouse is idle (but never hide the unmute hint) */
.badge, .player-controls, .player-controls > * { transition: opacity .25s; }
.player.idle { cursor: none; }
.player.idle .badge,
.player.idle .player-controls > :not(.volume.hint) { opacity: 0; pointer-events: none; }
.player.idle .volume.hint input { opacity: 0; pointer-events: none; }

/* --- reactions --------------------------------------------------------- */
.reactions {
  display: flex; justify-content: center; flex-wrap: wrap; gap: 6px;
  margin-top: 10px;
}
.reactions button {
  font-size: 20px; line-height: 1; padding: 8px 10px;
  border-radius: 999px; background: var(--surface); border-color: var(--border);
  transition: transform .1s, background .12s;
}
.reactions button:hover { transform: translateY(-2px); background: var(--surface-2); }
.reactions button:active { transform: scale(.9); background: var(--surface-3); }

.float-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.floater {
  position: absolute; bottom: 6%;
  display: flex; flex-direction: column; align-items: center;
  animation: float-up var(--dur, 3s) ease-out forwards;
}
.floater-emoji { font-size: clamp(28px, 4.5vw, 52px); filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .5)); }
.floater-name {
  font-size: 11px; font-weight: 600; padding: 1px 6px; margin-top: 2px;
  border-radius: 999px; background: rgba(0, 0, 0, .55); color: #fff;
}
/* Rises by a share of the player's height, so it looks the same on a phone or in fullscreen. */
@keyframes float-up {
  0%   { bottom: 6%;  transform: translateX(-50%) scale(.6); opacity: 0; }
  12%  { bottom: 16%; transform: translateX(-50%) scale(1.1); opacity: 1; }
  70%  { opacity: 1; }
  100% { bottom: 78%; transform: translateX(calc(-50% + var(--drift, 0px))) scale(1); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .floater { animation-name: fade-out; }
  @keyframes fade-out { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
}

/* --- side cards -------------------------------------------------------- */
.side { display: flex; flex-direction: column; gap: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card-head h2 { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }

.bt { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
.bt.on .dot { background: var(--ok); }
.bt.pairing .dot { background: var(--warn); }

/* --- baton ------------------------------------------------------------- */
.baton {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 14px;
}
.baton .who { display: flex; align-items: center; gap: 8px; }
.baton .who .avatar { width: 24px; height: 24px; font-size: 11px; border: 0; }
.baton .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.baton.mine { background: rgba(62, 207, 142, .12); }
.baton.locked { background: rgba(245, 184, 77, .12); }
.requests { width: 100%; display: grid; gap: 6px; }
.request { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }

/* --- pad --------------------------------------------------------------- */
.pad { display: grid; gap: 10px; user-select: none; transition: opacity .15s; }
.pad.disabled { opacity: .45; }
.row { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.row button { padding: 10px 0; }
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 52px);
  gap: 6px; width: 200px; margin: 4px auto;
}
.dpad button { padding: 0; font-size: 18px; }
.dpad .ok {
  border-radius: 50%; border: 0; font-weight: 700; font-size: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.dpad .up { grid-area: 1 / 2; } .dpad .left { grid-area: 2 / 1; } .dpad .ok { grid-area: 2 / 2; }
.dpad .right { grid-area: 2 / 3; } .dpad .down { grid-area: 3 / 2; }

.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }

.admin {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding-top: 12px; border-top: 1px dashed var(--border);
}
.admin-label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--warn); margin-right: 4px; }

/* --- chat -------------------------------------------------------------- */
.chat { flex: 1; min-height: 320px; }
.messages {
  list-style: none; margin: 0; padding: 0 2px;
  flex: 1; overflow-y: auto; min-height: 120px;
  display: flex; flex-direction: column; gap: 8px;
}
.msg { display: flex; gap: 8px; align-items: flex-start; }
.msg .avatar { width: 26px; height: 26px; font-size: 11px; border: 0; margin-top: 2px; }
.msg .body { min-width: 0; }
.msg .meta { font-size: 12px; color: var(--muted); }
.msg .meta b { color: var(--text); font-weight: 600; margin-right: 6px; }
.msg .text { overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.system { justify-content: center; font-size: 12px; color: var(--muted); font-style: italic; }

/* --- dialog (admin) ---------------------------------------------------- */
.dialog {
  width: min(560px, calc(100% - 32px));
  max-height: calc(100% - 48px);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.dialog::backdrop { background: rgba(5, 6, 10, .7); backdrop-filter: blur(3px); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 14px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-section { padding: 16px 20px; display: grid; gap: 10px; }
.dialog-section + .dialog-section { border-top: 1px solid var(--border); }
.dialog-section h3 {
  margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted);
}
.link-box { display: grid; gap: 8px; padding: 12px; border-radius: 10px; background: var(--surface-2); }
.link-label { margin: 0; font-size: 14px; }
.link-box input { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.field-hint { font-size: 12px; color: var(--muted); margin: 0; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border-radius: 10px; background: var(--surface-2);
}
.list-main { display: flex; flex-direction: column; min-width: 0; font-size: 14px; }
.list-main.person { flex-direction: row; align-items: center; gap: 8px; }
.list-main .avatar { width: 26px; height: 26px; font-size: 11px; border: 0; }
.list-sub { font-size: 12px; color: var(--muted); }
.list-empty { font-size: 13px; color: var(--muted); padding: 4px 2px; }
.badge-admin {
  font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--warn);
  border: 1px solid rgba(245, 184, 77, .4); border-radius: 999px; padding: 1px 6px;
}
.person .dot { flex: none; }
.person-row { flex-direction: column; align-items: stretch; }
.person-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.person-actions .chip { font-size: 12px; padding: 5px 10px; }
.badge-flag {
  font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--bad);
  border: 1px solid rgba(255, 107, 107, .4); border-radius: 999px; padding: 1px 6px;
}
.reactions button:disabled { opacity: .35; transform: none; }
input:disabled { opacity: .6; }
.dot.on { background: var(--ok); }

/* --- toast ------------------------------------------------------------- */
.toast {
  position: fixed; inset: auto auto 24px 50%; margin: 0; transform: translateX(-50%);
  color: var(--text);
  max-width: calc(100% - 32px);
  background: var(--surface-3); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
}

/* Desktop: the remote shrinks with the window's height and the chat takes
   whatever is left, so the side column fits without a scrollbar down to
   roughly 650px-tall windows. */
@media (min-width: 1000px) {
  .side { min-height: 0; overflow-y: auto; gap: clamp(10px, 1.6vh, 16px); }
  .remote { gap: clamp(6px, 1.2vh, 12px); padding: clamp(10px, 1.4vh, 14px); }
  .remote .pad { gap: clamp(6px, 1vh, 10px); }
  .remote .row button { padding: clamp(5px, .9vh, 10px) 0; }
  .remote .baton { padding: clamp(6px, 1vh, 10px) 12px; }
  .remote .inline-form input, .remote .inline-form button { padding-block: clamp(6px, 1vh, 10px); }
  .remote .admin { padding-top: clamp(6px, 1.2vh, 12px); }
  .dpad {
    grid-template-rows: repeat(3, clamp(34px, 5.2vh, 52px));
    width: clamp(150px, 19vh, 200px);
    gap: clamp(4px, .6vh, 6px); margin: 0 auto;
  }
  .chat { min-height: 160px; }
  .messages { min-height: 60px; }
}

@media (max-width: 600px) {
  .top { gap: 10px; padding: 0 12px; }
  .me-name { display: none; }
  .layout { padding: 12px; gap: 12px; }
  .player { border-radius: 10px; }
  .chat { min-height: 50vh; }
}
