/* WatchParty PoC — тёмная адаптивная вёрстка: слева плеер, справа чат. */

:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c232c;
  --line: #2a323d;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --ok: #2ea043;
  --warn: #d29922;
  --err: #f85149;
  --host: #a371f7;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 7px 12px;
  transition: background .12s, border-color .12s;
}
button:hover { background: #26303b; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent-2); }
button.primary:hover { background: var(--accent-2); }
button.ghost { background: transparent; }
button.small { padding: 4px 8px; font-size: 12px; }
button.big { padding: 14px 22px; font-size: 16px; }

input[type="text"], input:not([type]) {
  font: inherit;
  color: var(--text);
  background: #0d1117;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
input:focus { border-color: var(--accent); }

/* ---------------- Экран входа ---------------- */
.gate {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2635, var(--bg));
  z-index: 50;
}
.gate-card {
  width: min(380px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.gate-card h1 { margin: 0 0 4px; font-size: 22px; }
.gate-card p { margin: 0 0 10px; font-size: 13px; }
.gate-card label { font-size: 12px; color: var(--muted); margin-top: 6px; }
.gate-card button { margin-top: 16px; }
.gate-err { color: var(--err); min-height: 16px; font-size: 12px; }

/* ---------------- Каркас ---------------- */
/* 100dvh, а не 100vh: в мобильном Safari 100vh включает высоту адресной строки,
   из-за чего страница оказывается выше экрана и верхняя панель уезжает вверх. */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: .3px; white-space: nowrap; }

.url-form { display: flex; gap: 8px; flex: 1 1 380px; min-width: 260px; }
.url-form input { flex: 1; }

.status { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.badge {
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.badge.dim { opacity: .8; }
.badge-link { text-decoration: none; cursor: pointer; }
.badge-link:hover { background: #26303b; color: var(--text); }
.role-host { background: rgba(163,113,247,.15); border-color: var(--host); color: #d2b7ff; font-weight: 600; }
.role-guest { background: rgba(59,130,246,.12); border-color: var(--accent); color: #9ec5ff; font-weight: 600; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; background: var(--err); }
.conn-on .dot { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.conn-on { color: #7ee2a8; }
.conn-off .dot { background: var(--err); }

/* ---------------- Две колонки ---------------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 340px;
  min-height: 0;
}

.stage { display: flex; flex-direction: column; min-width: 0; background: #000; }

.player-wrap { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }
.player-slot { position: absolute; inset: 0; }
.player-slot iframe, .player-slot video {
  width: 100%; height: 100%; border: 0; display: block; background: #000;
}

.placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; text-align: center; padding: 20px;
}
.ph-icon { font-size: 46px; opacity: .5; }

/* Прозрачный щит поверх iframe: гость не может кликнуть по чужому плееру */
.shield {
  position: absolute; inset: 0;
  z-index: 4;
  background: transparent;
  cursor: not-allowed;
}

.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(2px);
  z-index: 5;
  padding: 12px;
  text-align: center;
}

/* Режим "нажмите на самом плеере": оверлей не должен перехватывать тап,
   иначе на телефоне запустить чужой плеер вообще нечем. */
.overlay.pass-through {
  pointer-events: none;
  background: transparent;
  backdrop-filter: none;
  justify-content: flex-start;
}
.overlay.pass-through > * { pointer-events: auto; }

.hint-box {
  background: rgba(0,0,0,.8);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 0;
  max-width: 90%;
  font-size: 13px;
  line-height: 1.4;
}

.open-link {
  color: #9ec5ff;
  font-size: 13px;
  background: rgba(0,0,0,.8);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  text-decoration: none;
}
.open-link:hover { background: #26303b; }

.controls {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.ctl-left, .ctl-right { display: flex; align-items: center; gap: 8px; }
.ctl-mid { display: flex; align-items: center; gap: 6px; flex: 1; justify-content: center; }
.hint { font-size: 12px; }
.vol { width: 90px; accent-color: var(--accent); }

/* ---------------- Сайдбар ---------------- */
.sidebar {
  display: flex; flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  min-height: 0;
  position: relative;
}

.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px;
  font-size: 12px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.users { list-style: none; margin: 0; padding: 6px 12px; max-height: 132px; overflow-y: auto; }
.users li { display: flex; align-items: center; gap: 7px; padding: 3px 0; font-size: 13px; }
.users .tag { font-size: 10px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.users .tag.host { border-color: var(--host); color: #d2b7ff; }
.users .me { color: #9ec5ff; }

.chat { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 7px; min-height: 0; }

.msg { display: flex; flex-direction: column; gap: 1px; word-break: break-word; }
.msg .head { font-size: 11px; color: var(--muted); display: flex; gap: 6px; align-items: baseline; }
.msg .who { font-weight: 600; color: #9ec5ff; }
.msg.host-msg .who { color: #d2b7ff; }
.msg.mine .who { color: #7ee2a8; }
.msg .body { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; }
.msg.mine .body { background: #1b2a3d; border-color: #27415e; }

.sys {
  font-size: 12px; color: var(--muted);
  text-align: center; padding: 2px 6px;
  border-top: 1px dashed transparent;
}
.sys b { color: #b9c4cf; font-weight: 600; }

.jump {
  position: absolute; bottom: 62px; left: 50%; transform: translateX(-50%);
  font-size: 12px; padding: 5px 10px; background: var(--accent); border-color: var(--accent-2);
  z-index: 3;
}

.chat-form { display: flex; gap: 6px; padding: 9px; padding-bottom: calc(9px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); }
.chat-form input { flex: 1; }

/* ---------------- Адаптив: узкий экран — колонки друг под другом ---------------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: minmax(200px, 46dvh) 1fr; }
  .sidebar { border-left: 0; border-top: 1px solid var(--line); }
  .users { max-height: 90px; }
  .status { order: 3; width: 100%; }
  /* На телефоне прячем самый длинный абзац-пояснение, чтобы он не налезал на контролы */
  .placeholder { padding: 12px; gap: 6px; }
  .placeholder p:last-child { display: none; }
  .ph-icon { font-size: 38px; }
}
