:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --line: #262b38;
  --text: #e8eaf0;
  --muted: #8b92a3;
  --accent: #7c5cff;
  --accent2: #9b82ff;
  --danger: #ff6b6b;
  --warn: #ffb347;
  --ok: #4ade80;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; }
.brand span { color: var(--accent2); }
.room-badge { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.room-badge strong {
  color: var(--text);
  font-family: ui-monospace, Consolas, monospace;
  letter-spacing: 2px;
}

main { padding: 16px; max-width: 1280px; margin: 0 auto; }

/* Home card */
.card {
  max-width: 420px;
  margin: 6vh auto 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; }
.card p { margin: 0; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

input[type="text"] {
  width: 100%;
  background: var(--panel2);
  border: 1px solid #2c3242;
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
}
input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#joinCodeInput { font-family: ui-monospace, Consolas, monospace; letter-spacing: 3px; text-transform: uppercase; }

.row { display: flex; gap: 8px; }

.btn {
  appearance: none;
  border: 1px solid #2c3242;
  background: var(--panel2);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
}
.btn:hover { border-color: #3a4256; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
label.btn { display: inline-block; color: #fff; font-size: 15px; }

.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.error { color: var(--danger); font-size: 14px; }

.warning {
  background: rgba(255, 179, 71, .08);
  border: 1px solid rgba(255, 179, 71, .35);
  color: #ffd59a;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
}
.warning code, .card code {
  display: inline-block;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12.5px;
  background: rgba(0, 0, 0, .35);
  padding: 2px 6px;
  border-radius: 6px;
  word-break: break-all;
}

/* Room layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }
.player-col { min-width: 0; }

/* Player */
.player {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  container-type: size; /* lets captions scale with the player (cqh units) */
}
.player video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }
.player:fullscreen { border-radius: 0; aspect-ratio: auto; width: 100vw; height: 100vh; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  text-align: center;
  background: rgba(10, 12, 16, .88);
  z-index: 3;
}
.overlay p { margin: 0; }

.controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 28px 12px 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .85));
  transition: opacity .25s;
  z-index: 2;
}
.player.idle .controls { opacity: 0; pointer-events: none; }
.player.idle { cursor: none; }

.controls-row { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  background: none;
  border: 0;
  color: #fff;
  font: 600 14px/1 system-ui, sans-serif;
  padding: 8px 10px;
  min-width: 42px;
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .12); }
.icon-btn.big { font-size: 18px; }
.time { font-variant-numeric: tabular-nums; font-size: 13px; color: #ddd; margin-left: 6px; white-space: nowrap; }
@media (max-width: 480px) { #volumeBar { display: none; } .icon-btn { min-width: 36px; padding: 8px 5px; } }
.spacer { flex: 1; }

input[type="range"] { accent-color: var(--accent); cursor: pointer; }
#seekBar { width: 100%; margin: 0 0 4px; }
#volumeBar { width: 90px; }
@media (pointer: coarse) { #volumeBar { display: none; } }

.toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90%;
  background: rgba(20, 22, 30, .92);
  border: 1px solid #333a4d;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  z-index: 4;
}

/* Side panel */
.side-col {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  align-self: start;
}
.members { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.members li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  background: var(--panel2);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
}
.members .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.members .status { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.members .status.bad { color: var(--warn); }

.status-line { color: var(--muted); margin: 0 0 10px; }
.status-line.ok { color: var(--ok); }
.status-line.warn { color: var(--warn); }

/* Captions */
.captions {
  --cap-scale: 1;
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 6%;
  text-align: center;
  pointer-events: none;
  z-index: 1;
  transition: bottom .25s;
  font-size: calc(clamp(13px, 4.6cqh, 46px) * var(--cap-scale));
  line-height: 1.45;
  font-weight: 500;
}
.player:not(.idle) .captions { bottom: min(104px, 44cqh); }
.captions span {
  background: rgba(0, 0, 0, .72);
  color: #fff;
  padding: .08em .35em;
  border-radius: 4px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  text-shadow: 0 1px 2px #000;
}
.icon-btn.on { color: var(--accent2); box-shadow: inset 0 -2px 0 var(--accent2); }

/* Subtitles / audio menu */
.menu {
  position: absolute;
  right: 10px;
  bottom: 96px;
  width: min(320px, calc(100% - 20px));
  max-height: calc(100% - 110px);
  overflow-y: auto;
  background: rgba(22, 25, 33, .97);
  border: 1px solid #333a4d;
  border-radius: 12px;
  padding: 8px;
  z-index: 5;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.menu h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin: 6px 8px 4px;
}
.menu .opt {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: 0;
  color: var(--text);
  font: inherit;
  text-align: left;
  padding: 9px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.menu .opt:hover:not(:disabled) { background: rgba(255, 255, 255, .07); }
.menu .opt:disabled { color: var(--muted); cursor: default; }
.menu .opt .check { width: 16px; flex: none; color: var(--accent2); font-weight: 700; }
.menu .opt .sub { display: block; color: var(--muted); font-size: 12px; }
.menu .row-ctl { display: flex; align-items: center; gap: 6px; padding: 6px 8px; }
.menu .row-ctl .label { flex: 1; color: var(--muted); font-size: 13px; }
.menu .row-ctl button {
  background: var(--panel2);
  border: 1px solid #2c3242;
  color: var(--text);
  border-radius: 7px;
  padding: 5px 9px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  min-width: 34px;
}
.menu .row-ctl button.on { border-color: var(--accent); color: var(--accent2); }
.menu .row-ctl .val { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; font-size: 13px; }
.menu .note {
  margin: 6px 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 179, 71, .08);
  border: 1px solid rgba(255, 179, 71, .3);
  color: #ffd59a;
  font-size: 13px;
  line-height: 1.45;
}
.menu .note code {
  display: block;
  margin: 6px 0;
  padding: 6px 8px;
  background: rgba(0, 0, 0, .4);
  border-radius: 6px;
  font: 12px ui-monospace, Consolas, monospace;
  word-break: break-all;
  color: var(--text);
  user-select: all;
}
.menu .note button {
  background: var(--panel2);
  border: 1px solid #3a4256;
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.menu .progress { color: var(--muted); font-size: 13px; padding: 4px 8px 8px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }
/* Phone portrait: menu as a bottom sheet */
.menu.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: auto;
  max-height: 75vh;
  border-radius: 16px 16px 0 0;
  padding: 10px 10px calc(12px + env(safe-area-inset-bottom));
  z-index: 50;
  font-size: 15px;
}
.menu.sheet .opt { padding: 12px 10px; }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 49; }
@media (max-width: 480px) {
  .time { font-size: 12px; margin-left: 2px; }
  #audioBtn { font-size: 13px; }
}

/* ---------------- Chat ---------------- */
.chat {
  position: relative;
  margin-top: 12px;
  height: 360px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
@media (max-width: 860px) { .chat { height: min(420px, 55vh); min-height: 280px; } }
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: 14px;
}
.chat-close {
  display: none;
  background: rgba(0, 0, 0, .35);
  border: 1px solid rgba(255, 255, 255, .2);
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
}
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overscroll-behavior: contain;
}
.chat-empty { margin: auto; color: var(--muted); font-size: 13px; }
.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 85%; }
.msg.first { margin-top: 8px; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .who { font-size: 12px; font-weight: 600; margin: 0 4px 2px; }
.bubble {
  background: var(--panel2);
  padding: 6px 10px 5px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.mine .bubble { background: var(--accent); color: #fff; }
.bubble .time { float: right; font-size: 10.5px; opacity: .6; margin: 6px 0 0 10px; line-height: 1; }
.bubble.big, .msg.mine .bubble.big { background: none; font-size: 34px; line-height: 1.15; padding: 0 2px; }
.bubble.big .time { float: none; display: block; font-size: 10.5px; margin: 2px 0 0; text-align: right; color: var(--muted); }
.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--line);
}
#chatInput {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 110px;
  background: var(--panel2);
  border: 1px solid #2c3242;
  color: var(--text);
  border-radius: 20px;
  padding: 9px 14px;
  font: inherit;
  line-height: 1.35;
}
#chatInput:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.chat-icon, .chat-send {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: none;
  font-size: 21px;
  cursor: pointer;
  color: #fff;
}
.chat-icon:hover { background: rgba(255, 255, 255, .08); }
.chat-send { background: var(--accent); font-size: 16px; }
.emoji-panel {
  position: absolute;
  left: 8px;
  bottom: 60px;
  width: min(336px, calc(100% - 16px));
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 8px;
  background: var(--panel2);
  border: 1px solid #333a4d;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  z-index: 6;
}
.emoji-panel button {
  background: none;
  border: 0;
  font-size: 22px;
  line-height: 1;
  padding: 6px 0;
  border-radius: 8px;
  cursor: pointer;
}
.emoji-panel button:hover { background: rgba(255, 255, 255, .1); }

/* Fullscreen: see-through panel on the right, the movie stays visible behind it */
.chat.floating {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(40%, 420px);
  height: auto;
  min-height: 0;
  margin: 0;
  padding-left: 7%;
  border: 0;
  border-radius: 0;
  background: linear-gradient(to right, rgba(8, 10, 14, 0) 0%, rgba(8, 10, 14, .5) 25%, rgba(8, 10, 14, .72) 100%);
  z-index: 3;
  transition: bottom .25s;
}
.player:not(.idle) .chat.floating { bottom: 96px; }
.chat.floating .chat-head { border: 0; padding-top: 14px; text-shadow: 0 1px 3px #000; }
.chat.floating .chat-close { display: inline-block; }
.chat.floating .chat-list {
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 36px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 36px);
}
.chat.floating .bubble { background: rgba(255, 255, 255, .14); text-shadow: 0 1px 2px rgba(0, 0, 0, .6); }
.chat.floating .msg.mine .bubble { background: rgba(124, 92, 255, .62); }
.chat.floating .bubble.big { background: none; }
.chat.floating .who { text-shadow: 0 1px 2px #000; }
.chat.floating .chat-form { border: 0; }
.chat.floating #chatInput { background: rgba(0, 0, 0, .45); border-color: rgba(255, 255, 255, .2); }
.chat.floating .emoji-panel { background: rgba(22, 25, 33, .96); }
.player.chat-open .captions { right: calc(min(40%, 420px) + 2%); }

.chat-fab {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 4;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .22);
  background: rgba(20, 22, 30, .7);
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  transition: opacity .25s;
}
.player.idle .chat-fab:not(.unread) { opacity: .35; }
.chat-fab.unread { border-color: var(--accent2); }
.chat-fab .badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 21px;
  height: 21px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--danger);
  color: #fff;
  font: 700 12px/21px system-ui, sans-serif;
}
