:root {
  --bg: #0d0f14; --card: #161a22; --card2: #1d222c; --line: #262d3a;
  --text: #e8ebf2; --muted: #8b93a7; --accent: #7c5cff; --accent2: #3fd9b8;
  --danger: #ff5d6c; --ok: #3ddc97; --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 600px at 20% -10%, #1b1840 0%, transparent 60%), radial-gradient(900px 500px at 100% 0%, #0f2b2a 0%, transparent 55%), var(--bg);
  color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 16px; line-height: 1.4;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
h1, h2 { margin: 0 0 6px; }
h2 { font-size: 19px; }

.view { min-height: 100dvh; display: flex; flex-direction: column; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }

/* ---------- кнопки и поля ---------- */
button { font: inherit; color: inherit; cursor: pointer; }
.btn { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600; background: var(--card2); color: var(--text); transition: transform .06s, filter .15s, background .15s; }
.btn:hover { filter: brightness(1.12); } .btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #5b8cff); color: #fff; box-shadow: 0 6px 20px rgba(124,92,255,.35); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn.big { padding: 14px 28px; font-size: 18px; }
.btn.wide { width: 100%; margin-top: 12px; }
.btn.danger-text { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { background: transparent; border: 0; width: 38px; height: 38px; border-radius: 10px; font-size: 18px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--card2); }
.chip { background: var(--card2); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-size: 14px; }
.chip b { letter-spacing: 2px; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
input { width: 100%; margin-top: 6px; padding: 13px 14px; font-size: 16px; border-radius: 12px; border: 1px solid var(--line); background: #0f1218; color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,92,255,.25); }
.pw { position: relative; display: block; }
.pw input { padding-right: 48px; }
.pw .icon-btn { position: absolute; right: 4px; top: 10px; height: 34px; }
.error { color: var(--danger); min-height: 20px; margin: 4px 0 10px; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; text-align: center; margin: 14px 0 0; }

/* ---------- вход ---------- */
#view-auth { align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 410px; }
.brand { text-align: center; margin-bottom: 18px; }
.brand-logo { font-size: 44px; filter: drop-shadow(0 6px 18px rgba(124,92,255,.5)); }
.brand h1 { font-size: 26px; background: linear-gradient(90deg, #fff, #b9a8ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tabs { display: flex; background: #0f1218; border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 18px; }
.tab { flex: 1; white-space: nowrap; border: 0; background: transparent; padding: 9px 10px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 15px; }
.tab.active { background: var(--card2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.04) inset; }
.tabs.small { margin: 0; }
.tabs.small .tab { font-size: 13.5px; padding: 8px 6px; }

/* ---------- верхняя панель ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: rgba(13,15,20,.75); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5; }
.topbar-brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.user-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-name { font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 700; font-size: 15px; color: #fff; flex: none; }
.avatar.big { width: 40px; height: 40px; font-size: 17px; }

/* ---------- лобби ---------- */
.lobby { width: 100%; max-width: 920px; margin: 0 auto; padding: 22px 16px 40px; display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.my-room { background: #0f1218; border: 1px dashed var(--line); border-radius: 12px; padding: 14px; margin: 14px 0 0; }
.my-room-code { font-size: 32px; font-weight: 800; letter-spacing: 6px; text-align: center; margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.my-room .row { justify-content: center; }
#btn-create { margin-top: 14px; }
.help { margin-top: 16px; color: var(--muted); font-size: 14px; }
.help summary { cursor: pointer; color: var(--text); }
.help ol { padding-left: 20px; margin: 10px 0 0; } .help li { margin-bottom: 6px; }
.code-input { text-align: center; font-size: 30px; letter-spacing: 12px; font-weight: 700; padding: 14px 8px 14px 20px; margin: 14px 0 0; font-variant-numeric: tabular-nums; }
#join-error { margin-top: 12px; text-align: center; }

/* ---------- комната ---------- */
.room-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.room-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-title span { font-size: 13px; }
.room-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 0; }
.stage { display: flex; flex-direction: column; min-width: 0; padding: 14px 14px 10px 16px; }
.video-wrap { position: relative; width: 100%; aspect-ratio: 16 / 9; max-height: calc(100dvh - 150px); background: #000; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; text-align: center; padding: 20px; background: radial-gradient(circle at 50% 40%, rgba(124,92,255,.18), rgba(0,0,0,.72)); }
.overlay.hidden { display: none; }
#overlay-text { max-width: 360px; color: #d6d9e4; }
.stage-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 2px 0; flex-wrap: wrap; }
#stats { font-size: 12.5px; font-variant-numeric: tabular-nums; }

.panel { border-left: 1px solid var(--line); background: rgba(22,26,34,.6); display: flex; flex-direction: column; min-height: 0; max-height: calc(100dvh - 62px); }
.panel-head { padding: 12px; border-bottom: 1px solid var(--line); }
.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.badge { display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; text-align: center; margin-left: 4px; }
.badge.neutral { background: #2c3342; color: var(--text); }

.people { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.person { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 12px; }
.person:hover { background: var(--card2); }
.person-main { flex: 1; min-width: 0; }
.person-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 3px; }
.tag { white-space: nowrap; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #2c3342; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.tag.host { background: rgba(124,92,255,.22); color: #c9bcff; }
.tag.you { background: rgba(63,217,184,.16); color: var(--accent2); }
.tag.wait { background: rgba(255,200,80,.15); color: #ffd479; }
.pane-actions { padding: 8px 12px 14px; }
.pane-actions .btn { margin-top: 8px; }

.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 86%; padding: 8px 12px; border-radius: 14px; background: var(--card2); align-self: flex-start; word-wrap: break-word; overflow-wrap: anywhere; }
.msg .who { font-size: 12px; font-weight: 700; margin-bottom: 2px; }
.msg .time { font-size: 11px; color: var(--muted); margin-left: 8px; float: right; margin-top: 4px; }
.msg.own { align-self: flex-end; background: linear-gradient(135deg, #6a4df0, #4f7cf5); color: #fff; }
.msg.own .time { color: rgba(255,255,255,.7); }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 12.5px; text-align: center; padding: 2px 8px; }
.hint.left { text-align: left; margin: 8px 2px 12px; }
.chat-empty { margin: auto; color: var(--muted); font-size: 14px; text-align: center; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.chat-form input { margin: 0; }
.chat-form .btn { padding: 0 18px; }

#toast { width: max-content; position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); background: #232938; border: 1px solid var(--line); padding: 11px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { border-color: var(--danger); }

/* ---------- телефон / узкий экран ---------- */
@media (max-width: 899px) {
  .lobby { grid-template-columns: 1fr; padding-top: 16px; }
  .room-body { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .stage { padding: 0; }
  .source-bar { padding: 10px 12px 0; margin: 0 0 10px; flex-wrap: wrap; }
  .source-bar input { flex-basis: 100%; }
  .source-bar .btn { flex: 1; padding: 11px 16px; }
  .embed-head, .controls, .note { padding-left: 12px; padding-right: 12px; }
  .video-wrap { border-radius: 0; border-left: 0; border-right: 0; max-height: 44dvh; }
  .stage-bar { padding: 8px 12px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); max-height: none; }
  .user-name { max-width: 150px; }
}
@media (max-width: 520px) {
  .brand-text { display: none; }
  .topbar { padding: 10px 12px; }
}
@media (max-width: 899px) and (orientation: landscape) {
  .room-body { grid-template-columns: minmax(0, 1fr) 280px; grid-template-rows: none; }
  .video-wrap { max-height: calc(100dvh - 110px); border-radius: 0; }
  .panel { border-top: 0; border-left: 1px solid var(--line); max-height: calc(100dvh - 62px); }
}

/* ---------- общий плеер ---------- */
.source-bar { display: flex; gap: 8px; margin: 0 0 10px; }
.source-bar input { margin: 0; flex: 1; min-width: 0; }
.source-bar .btn { white-space: nowrap; padding: 0 16px; }
#yt-host, #yt-host iframe, .video-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.shield { position: absolute; inset: 0; z-index: 2; }
.video-wrap .overlay { z-index: 3; }
.overlay.static { background: radial-gradient(circle at 50% 40%, rgba(124,92,255,.14), rgba(0,0,0,.6)); }
.banner { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 4; background: rgba(20,22,30,.92); border: 1px solid var(--line); padding: 8px 14px; border-radius: 999px; font-size: 14px; max-width: 92%; text-align: center; }
.controls { display: flex; align-items: center; gap: 8px; padding: 10px 4px 2px; }
.controls .time { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); min-width: 40px; text-align: center; }
.icon-btn.lg { font-size: 22px; width: 44px; height: 44px; background: var(--card2); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.controls input[type=range] { flex: 1; margin: 0; padding: 0; height: 24px; background: transparent; border: 0; accent-color: var(--accent); box-shadow: none; }
.controls input[type=range]:disabled { opacity: .55; }
.note { font-size: 13px; padding: 4px 4px 0; }
.embed-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 0 2px 10px; flex-wrap: wrap; }
.embed-head strong { font-size: 15px; }
.video-wrap.embed { background: #000; }
a.btn { text-decoration: none; display: inline-block; }
#stage-yt:fullscreen, #stage-embed:fullscreen { background: #000; display: flex; flex-direction: column; justify-content: center; padding: 0; }
#stage-yt:fullscreen .video-wrap { max-height: none; border-radius: 0; border: 0; flex: 1; aspect-ratio: auto; }
#stage-yt:fullscreen .controls, #stage-yt:fullscreen .note { padding: 10px 14px; background: #0d0f14; }

/* ---------- меню участника «⋯» ---------- */
.menu-btn { width: 32px; height: 32px; font-size: 20px; line-height: 1; color: var(--muted); flex: none; }
.menu { position: fixed; z-index: 60; min-width: 260px; max-width: 92vw; background: #1d222c; border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: 0 14px 40px rgba(0,0,0,.55); }
.menu button { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 11px 12px; border-radius: 9px; font-size: 14.5px; }
.menu button:hover { background: #262d3a; }
.menu .menu-title { padding: 8px 12px 4px; font-size: 12px; color: var(--muted); }
.tag.ctrl { background: rgba(255,160,70,.16); color: #ffb26b; }

@media (max-width: 899px) {
  .embed-head { padding: 10px 12px; }
  .embed-head .row { width: 100%; }
  .embed-head .btn { flex: 1; text-align: center; }
  .controls { padding: 10px 12px 2px; }
  .note { padding: 6px 12px 0; }
}

/* ---------- громкость, перемотка на 10 секунд, отсчёт ---------- */
.field-hint { display: block; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.vol { width: 96px; margin: 0; padding: 0; height: 24px; background: transparent; border: 0; accent-color: var(--accent); box-shadow: none; flex: none; }
.icon-btn.step { width: 46px; flex-direction: column; font-size: 16px; line-height: 1; gap: 0; }
.icon-btn.step small { font-size: 10.5px; font-weight: 700; color: var(--muted); margin-top: 1px; }
.icon-btn.step:disabled small { color: inherit; }
.controls { flex-wrap: wrap; row-gap: 4px; }
.controls input#yt-seek { flex: 1 1 140px; min-width: 120px; }
#countdown { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(8,9,13,.78); backdrop-filter: blur(6px); text-align: center; pointer-events: none; }
#countdown-num { font-size: clamp(90px, 28vw, 220px); font-weight: 800; line-height: 1; background: linear-gradient(135deg, #fff, #b9a8ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
#countdown-text { margin-top: 14px; font-size: 18px; color: #d6d9e4; padding: 0 20px; }
.ios-only { display: none; }
.ios .ios-only { display: block; }
.ios .vol { display: none; }
@media (max-width: 899px) { .vol { width: 80px; } }

.seekrow { display: flex; align-items: center; gap: 8px; flex: 1 1 240px; min-width: 0; }
.seekrow input[type=range] { flex: 1 1 0; min-width: 60px; }
@media (max-width: 899px) {
  .seekrow { order: 10; flex-basis: 100%; }
  #yt-fs { margin-left: auto; }
  #yt-mute { margin-left: 4px; }
}

/* ---------- выбор плеера для Кинопоиска ---------- */
.embed-choice { padding: 4px 2px 0; }
.embed-lead { margin: 4px 0 14px; color: var(--muted); font-size: 14.5px; }
.choice-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.players { display: grid; gap: 12px; }
.choice { display: block; text-align: left; text-decoration: none; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; width: 100%; }
.choice:hover { border-color: #3a4358; filter: brightness(1.08); }
.choice.primary { background: linear-gradient(135deg, rgba(124,92,255,.22), rgba(63,217,184,.10)); border-color: rgba(124,92,255,.5); }
.choice-title { display: block; font-weight: 700; font-size: 16.5px; }
.choice-sub { display: block; margin-top: 4px; color: var(--muted); font-size: 13.5px; font-weight: 400; }
@media (min-width: 900px) { .choice-grid { grid-template-columns: 1fr 1fr; align-items: start; } }
@media (max-width: 899px) { .embed-choice { padding: 4px 12px 0; } }
