:root {
  --bg: #08080d;
  --panel: #12121b;
  --panel-2: #191926;
  --line: #26263a;
  --text: #ececf5;
  --muted: #8e8ea8;
  --accent: #6d5efc;
  --accent-2: #8b7dff;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 14px;
  --sub-size: 30px;
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

/* The `hidden` attribute comes from the UA stylesheet, so ANY author rule that
 * sets `display` (.gate, .layout, .spinner all set grid) silently overrides it
 * and the element stays on screen. Make hidden actually mean hidden. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, "Vazirmatn", "Noto Sans Arabic", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* ---------------------------------------------------------------- buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: background .15s, border-color .15s, transform .06s;
}
.btn:hover { background: #22223a; border-color: #35355a; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 20px -8px var(--accent);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 9px; }

/* ---------------------------------------------------------------- landing */
.landing { display: grid; place-items: center; padding: 32px 18px; overflow-y: auto; }
.landing::before {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(900px 500px at 12% -8%, #2a1c6b55, transparent 60%),
    radial-gradient(800px 460px at 96% 8%, #16305e55, transparent 60%);
}
.shell { width: min(560px, 100%); }
.hero { text-align: center; margin-bottom: 26px; }
.logo { font-size: 44px; line-height: 1; }
.hero h1 { margin: 10px 0 6px; font-size: 32px; letter-spacing: -.02em; }
.sub { margin: 0; color: var(--muted); line-height: 1.6; font-size: 15px; }

.card {
  background: linear-gradient(180deg, #14141f, #101019);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 26px;
  box-shadow: 0 30px 70px -30px #000;
}
.field { display: block; margin-bottom: 18px; }
.label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; }
.label em { color: var(--muted); font-style: normal; font-weight: 500; margin-left: 6px; font-size: 12px; }
.field input, .join input, .panel input[type=url] {
  width: 100%;
  padding: 12px 14px;
  background: #0b0b12;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .join input:focus, .panel input[type=url]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px #6d5efc33;
}
.hint { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); }
.card .btn.primary { width: 100%; }

.probe { font-size: 13px; padding: 10px 12px; border-radius: 10px; margin-bottom: 16px; background: #0b0b12; border: 1px solid var(--line); color: var(--muted); }
.probe.ok { color: var(--ok); border-color: #34d39944; }
.probe.warn { color: var(--warn); border-color: #fbbf2444; }
.err { color: var(--err); font-size: 13px; margin: 12px 0 0; }

.divider { display: flex; align-items: center; gap: 12px; margin: 22px 0; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.join { display: flex; gap: 10px; }
.join input { flex: 1; }
.foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 20px; }

/* ------------------------------------------------------------------- gate */
.gate { position: fixed; inset: 0; display: grid; place-items: center; background: #05050a; z-index: 50; padding: 18px; }
.gate-card {
  width: min(420px, 100%); text-align: center;
  background: linear-gradient(180deg, #14141f, #101019);
  border: 1px solid var(--line); border-radius: 20px; padding: 30px;
}
.gate-card h1 { margin: 10px 0 6px; font-size: 24px; }
.gate-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.gate-card input {
  padding: 12px 14px; background: #0b0b12; border: 1px solid var(--line);
  border-radius: 10px; outline: none; text-align: center;
}
.gate-card input:focus { border-color: var(--accent); }
.gate-status { margin: 12px 0 0; font-size: 12px; color: var(--muted); min-height: 15px; }

/* stream vs local-file choice */
.seg-group { display: flex; gap: 6px; background: #0b0b12; border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.seg {
  flex: 1; background: transparent; border: 0; color: var(--muted);
  padding: 9px 8px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.seg:hover { color: var(--text); }
.seg.on { background: var(--accent); color: #fff; }

.local-pick { text-align: left; border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #0b0b12; }
.local-pick .btn { width: 100%; margin-bottom: 8px; }
.local-pick .hint { margin: 6px 0 0; }
.local-pick a { color: var(--accent-2); text-decoration: underline; }
.picked { margin: 0; font-size: 12px; color: var(--ok); overflow-wrap: anywhere; min-height: 15px; }
.dl-cmd {
  width: 100%; margin-top: 8px; font-family: ui-monospace, monospace; font-size: 11px;
  background: #05050a; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; resize: vertical;
}

/* mismatched-file / codec warnings over the player */
.warnbar {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  max-width: min(560px, calc(100% - 28px));
  background: #3a2a08ee; border: 1px solid #fbbf2455; color: #fde68a;
  padding: 9px 14px; border-radius: 10px; font-size: 13px; line-height: 1.45;
  text-align: center; backdrop-filter: blur(8px); z-index: 6;
}

.player.dropping::after {
  content: "Drop the video file to play it from your disk";
  position: absolute; inset: 10px; z-index: 8;
  border: 2px dashed var(--accent-2); border-radius: 14px;
  background: #0b0b12cc; color: var(--text);
  display: grid; place-items: center; font-size: 15px; font-weight: 600;
}

/* ----------------------------------------------------------------- layout */
.room { overflow: hidden; }
.layout {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-rows: 56px minmax(0, 1fr);
  grid-template-areas: "top top" "stage chat";
}
.layout.no-chat { grid-template-columns: minmax(0, 1fr) 0; }
.layout.no-chat .chat { display: none; }

.topbar {
  grid-area: top; display: flex; align-items: center; gap: 14px;
  padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.back { font-size: 20px; color: var(--muted); padding: 4px 8px; border-radius: 8px; }
.back:hover { background: var(--panel-2); color: var(--text); }
.room-meta { display: flex; flex-direction: column; min-width: 0; }
.room-meta strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.code { font-size: 11px; color: var(--muted); font-family: ui-monospace, monospace; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.conn { font-size: 11px; padding: 4px 9px; border-radius: 20px; border: 1px solid var(--line); color: var(--muted); }
.conn[data-state="live"] { color: var(--ok); border-color: #34d39944; }
.conn[data-state="live"]::before { content: "● "; }
.conn[data-state="lost"] { color: var(--err); border-color: #f8717144; }

/* ----------------------------------------------------------------- player */
.stage { grid-area: stage; display: grid; place-items: center; background: #000; min-width: 0; min-height: 0; }
.player { position: relative; width: 100%; height: 100%; background: #000; overflow: hidden; }
video { width: 100%; height: 100%; display: block; background: #000; object-fit: contain; }

.spinner { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.spinner div {
  width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid #ffffff22; border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.center-toast {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: #000000cc; border: 1px solid var(--line); padding: 12px 20px;
  border-radius: 12px; font-size: 14px; backdrop-filter: blur(8px); pointer-events: none;
}

/* subtitles: rendered by us so RTL, size and delay are all controllable */
.subs {
  position: absolute; left: 4%; right: 4%; bottom: 92px;
  text-align: center; pointer-events: none;
  font-size: var(--sub-size); line-height: 1.35; font-weight: 600;
  text-shadow: 0 2px 5px #000, 0 0 12px #000c;
  transition: bottom .25s;
}
.subs p { margin: 0 auto; display: table; padding: 2px 10px; background: #00000055; border-radius: 6px; }
.player.idle .subs { bottom: 42px; }
.subs:empty { display: none; }

.reactions { position: absolute; right: 22px; bottom: 110px; pointer-events: none; }
.float-e { position: absolute; right: 0; bottom: 0; font-size: 34px; animation: floatUp 2.4s ease-out forwards; }
@keyframes floatUp {
  0% { opacity: 0; transform: translateY(0) scale(.5); }
  15% { opacity: 1; transform: translateY(-16px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-190px) scale(1); }
}

/* ---------------------------------------------------------------- controls */
.controls {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 30px 14px 10px;
  background: linear-gradient(transparent, #000000e6 55%);
  transition: opacity .25s, transform .25s;
}
.player.idle .controls { opacity: 0; transform: translateY(8px); pointer-events: none; }
.player.idle { cursor: none; }

.scrub { position: relative; padding: 8px 2px; cursor: pointer; }
.track { position: relative; height: 5px; border-radius: 4px; background: #ffffff26; transition: height .15s; }
.scrub:hover .track { height: 8px; }
.buffered, .played { position: absolute; inset: 0 auto 0 0; border-radius: 4px; }
.buffered { background: #ffffff33; width: 0; }
.played { background: linear-gradient(90deg, var(--accent-2), var(--accent)); width: 0; }
.knob {
  position: absolute; top: 50%; left: 0; width: 13px; height: 13px; border-radius: 50%;
  background: #fff; transform: translate(-50%, -50%) scale(0); transition: transform .15s;
  box-shadow: 0 2px 6px #000a;
}
.scrub:hover .knob { transform: translate(-50%, -50%) scale(1); }
.scrub-time {
  position: absolute; bottom: 26px; transform: translateX(-50%);
  background: #000000dd; padding: 3px 8px; border-radius: 6px; font-size: 12px;
  font-variant-numeric: tabular-nums; pointer-events: none; border: 1px solid var(--line);
}

.row { display: flex; align-items: center; gap: 6px; }
.ctl {
  background: transparent; border: 0; cursor: pointer; padding: 7px 10px;
  border-radius: 8px; font-size: 15px; color: #fff; opacity: .9; white-space: nowrap;
}
.ctl:hover { background: #ffffff1a; opacity: 1; }
.ctl.active { color: var(--accent-2); background: #6d5efc22; }
.spacer { flex: 1; }
.time { font-size: 13px; font-variant-numeric: tabular-nums; color: #e6e6f5; margin-left: 6px; }
.time i { color: var(--muted); font-style: normal; }
.drift { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 8px; }
.drift.bad { color: var(--warn); }

.vol { display: flex; align-items: center; gap: 4px; }
.vol input { width: 0; opacity: 0; transition: width .2s, opacity .2s; }
.vol:hover input, .vol input:focus { width: 84px; opacity: 1; }
input[type=range] { -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: #ffffff33; border-radius: 3px; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%;
  background: #fff; margin-top: -4.5px;
}
input[type=range]::-moz-range-track { height: 4px; background: #ffffff33; border-radius: 3px; }
input[type=range]::-moz-range-thumb { width: 13px; height: 13px; border: 0; border-radius: 50%; background: #fff; }

/* ------------------------------------------------------------------ panel */
.panel {
  position: absolute; right: 14px; bottom: 76px; width: min(320px, calc(100% - 28px));
  background: #0d0d16f2; border: 1px solid var(--line); border-radius: 14px;
  padding: 8px; backdrop-filter: blur(14px); box-shadow: 0 24px 60px -20px #000;
  max-height: 70%; overflow-y: auto;
}
.panel-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 10px; font-size: 13px; }
.panel-row + .panel-row { border-top: 1px solid var(--line); }
.panel-row.col { flex-direction: column; align-items: stretch; }
.panel-row.col span { margin-bottom: 4px; }
.panel-row.col input { margin-bottom: 8px; }
.panel-row input[type=range] { width: 130px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper b { font-variant-numeric: tabular-nums; min-width: 42px; text-align: center; font-weight: 600; }
.chip {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 5px 9px; border-radius: 8px; font-size: 12px; cursor: pointer;
}
.chip:hover { background: #26263c; }
.chip.on { background: var(--accent); border-color: transparent; color: #fff; }

/* ------------------------------------------------------------------- chat */
.chat {
  grid-area: chat; display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-left: 1px solid var(--line);
}
.people { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.person {
  display: flex; align-items: center; gap: 6px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--line); padding: 4px 9px; border-radius: 20px;
}
.person .dot { width: 7px; height: 7px; border-radius: 50%; }
.person.buffering { color: var(--warn); border-color: #fbbf2455; }

.messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 9px; scrollbar-width: thin; }
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: #2a2a40; border-radius: 8px; }
.msg { font-size: 14px; line-height: 1.5; }
.msg .who { font-weight: 700; font-size: 12px; margin-bottom: 2px; display: block; }
.msg .body {
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 7px 11px; border-radius: 12px; border-top-left-radius: 4px;
  display: inline-block; max-width: 100%; overflow-wrap: anywhere; white-space: pre-wrap;
}
.msg.mine { align-self: flex-end; text-align: right; max-width: 88%; }
.msg.mine .body { background: #2b2560; border-color: #3d3480; border-radius: 12px; border-top-right-radius: 4px; }
.msg.system { text-align: center; font-size: 12px; color: var(--muted); }
.msg time { font-size: 10px; color: var(--muted); margin-left: 6px; }

.typing { height: 18px; padding: 0 14px; font-size: 11px; color: var(--muted); }
.composer { border-top: 1px solid var(--line); padding: 10px; }
.emoji-row { display: flex; gap: 4px; margin-bottom: 8px; }
.emoji-row button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 3px 7px; font-size: 16px; cursor: pointer; line-height: 1.3;
}
.emoji-row button:hover { background: #26263c; transform: scale(1.08); }
#chat-form { display: flex; gap: 8px; }
#chat-input {
  flex: 1; min-width: 0; padding: 11px 13px; background: #0b0b12;
  border: 1px solid var(--line); border-radius: 10px; outline: none;
}
#chat-input:focus { border-color: var(--accent); }
#chat-form .btn { padding: 11px 14px; }

/* ----------------------------------------------------------------- mobile */
@media (max-width: 860px) {
  :root { --sub-size: 21px; }
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 52px auto minmax(0, 1fr);
    grid-template-areas: "top" "stage" "chat";
  }
  .layout.no-chat { grid-template-rows: 52px minmax(0, 1fr); }
  .stage { aspect-ratio: 16 / 9; height: auto; }
  .chat { border-left: 0; border-top: 1px solid var(--line); }
  .subs { bottom: 76px; }
  .vol input { width: 60px; opacity: 1; }
  .top-actions #copy-link { display: none; }
  .drift { display: none; }
}

@media (display-mode: fullscreen) { .subs { bottom: 100px; } }
