* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

/* ===== ТЕМЫ ===== */
:root,
[data-theme="midnight"] { --bg: #0e0e12; --card: #1c1c24; --accent: #4f7cff; --text: #fff; --muted: #9aa0b0; --danger: #ff3b5c; }
[data-theme="sunset"]    { --bg: #1a0f1e; --card: #2b1a30; --accent: #ff6b9d; --text: #fff; --muted: #c9a0b8; --danger: #ff3b5c; }
[data-theme="forest"]    { --bg: #0d1512; --card: #182420; --accent: #3ddc97; --text: #eafff5; --muted: #8fb3a5; --danger: #ff6b6b; }
[data-theme="ocean"]     { --bg: #081420; --card: #12283a; --accent: #29b6f6; --text: #eaf6ff; --muted: #8fb0c9; --danger: #ff5c7c; }
[data-theme="crimson"]   { --bg: #16090b; --card: #2a1114; --accent: #ff4757; --text: #fff; --muted: #c99a9f; --danger: #ff3b5c; }
[data-theme="mono"]      { --bg: #000; --card: #161616; --accent: #fff; --text: #fff; --muted: #888; --danger: #ff3b5c; }
[data-theme="grape"]     { --bg: #130a1f; --card: #221436; --accent: #a855f7; --text: #f3eaff; --muted: #a890c9; --danger: #ff5c7c; }
[data-theme="gold"]      { --bg: #14100a; --card: #241d10; --accent: #f5b301; --text: #fff8e6; --muted: #c9b98f; --danger: #ff5c5c; }
[data-theme="mint"]      { --bg: #0a1614; --card: #10241f; --accent: #2ee6c5; --text: #e6fff9; --muted: #8fc9bd; --danger: #ff6b6b; }
[data-theme="rose"]      { --bg: #1e0d13; --card: #301620; --accent: #fb7185; --text: #fff0f3; --muted: #c99aa8; --danger: #ff3b5c; }

/* ===== ШРИФТЫ ===== */
[data-font="system"] body  { font-family: -apple-system, system-ui, sans-serif; }
[data-font="rounded"] body { font-family: "SF Pro Rounded", "Nunito", ui-rounded, system-ui, sans-serif; }
[data-font="serif"] body   { font-family: Georgia, "Times New Roman", serif; }
[data-font="mono"] body    { font-family: "SF Mono", "Menlo", "Consolas", monospace; }
[data-font="condensed"] body { font-family: "Roboto Condensed", "Arial Narrow", system-ui, sans-serif; letter-spacing: 0.3px; }
[data-font="display"] body { font-family: "Impact", "Haettenschweiler", system-ui, sans-serif; letter-spacing: 0.5px; }

html, body { height: 100%; overflow: hidden; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, system-ui, sans-serif; height: 100vh; height: 100dvh; }
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  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; }

#splash { flex-direction: column; background: var(--bg); z-index: 100; }
.splash-inner { text-align: center; animation: fade 0.6s ease; }
.logo { font-size: 64px; color: var(--accent); }
.splash-title { font-size: 24px; margin-top: 12px; letter-spacing: 1px; }
@keyframes fade { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }

.card { width: 90%; max-width: 400px; max-height: 92vh; overflow-y: auto; }
.card h1 { text-align: center; margin-bottom: 8px; }
.hint { text-align: center; color: var(--muted); margin-bottom: 20px; font-size: 14px; }
.hello { text-align: center; margin-bottom: 20px; font-size: 17px; }
.text-btn { width: auto; background: none; color: var(--muted); font-size: 13px; padding: 2px 6px; text-decoration: underline; margin: 0; }

input {
  width: 100%; padding: 16px; margin: 8px 0;
  border-radius: 14px; border: none; font-size: 16px;
  background: var(--card); color: var(--text);
}
button {
  padding: 16px; margin: 8px 0;
  border-radius: 14px; border: none; font-size: 16px; font-weight: 600;
  cursor: pointer; transition: transform 0.15s, opacity 0.15s;
}
.card button { width: 100%; }
.big { padding: 20px; font-size: 17px; }
button:active { transform: scale(0.97); opacity: 0.85; }
.primary { background: var(--accent); color: #fff; }
.secondary { background: var(--card); color: var(--text); }
.divider { text-align: center; color: var(--muted); margin: 14px 0; font-size: 14px; }
.msg { text-align: center; color: #ff6b6b; margin-top: 10px; font-size: 14px; min-height: 20px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; margin: 8px 0; cursor: pointer; }
.checkbox-row input { width: auto; margin: 0; }

/* Список комнат с превью */
.muted { color: var(--muted); text-align: center; padding: 24px; line-height: 1.5; }
.room-item {
  display: flex; flex-direction: column;
  background: var(--card); padding: 12px; border-radius: 16px; margin: 10px 0;
}
.room-top { display: flex; gap: 12px; align-items: center; }
.room-thumb {
  width: 96px; height: 64px; flex-shrink: 0;
  border-radius: 12px; overflow: hidden;
  background: rgba(255,255,255,0.06);
  display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.room-thumb img { width: 100%; height: 100%; object-fit: cover; }
.room-info { flex: 1; min-width: 0; }
.room-name { font-weight: 700; font-size: 16px; margin-bottom: 4px; word-break: break-word; }
.room-meta { color: var(--muted); font-size: 13px; line-height: 1.35; word-break: break-word; }
.room-users { color: var(--accent); font-weight: 600; }
.join-mini {
  width: 100%; margin: 12px 0 0; padding: 13px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600;
}

#room { flex-direction: column; align-items: stretch; padding: 0; }
#videoWrap { position: absolute; inset: 0; background: #000; display: flex; align-items: center; justify-content: center; }
#player { width: 100%; height: 100%; }
#player iframe, #player video { width: 100%; height: 100%; border: none; }
.placeholder { color: var(--muted); text-align: center; padding: 20px; }

#roomCode {
  position: absolute; top: calc(env(safe-area-inset-top) + 10px); left: 12px; z-index: 30;
  background: rgba(0,0,0,0.55); backdrop-filter: blur(4px);
  color: #fff; padding: 6px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer;
}

#topBar {
  position: absolute; left: 12px; bottom: calc(env(safe-area-inset-bottom) + 76px); z-index: 30;
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px; font-size: 13px;
}
#usersLabel { color: #fff; background: rgba(0,0,0,0.55); backdrop-filter: blur(4px); padding: 6px 10px; border-radius: 10px; font-weight: 600; }
.mini { padding: 10px 12px; margin: 0; font-size: 13px; background: rgba(0,0,0,0.55); backdrop-filter: blur(4px); color: #fff; border-radius: 12px; }

.chat-btn-wrap { position: relative; }
#chatBadge {
  position: absolute; top: -6px; right: -6px;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px;
  text-align: center; border-radius: 9px; box-shadow: 0 0 0 2px var(--bg);
  animation: pop 0.3s ease;
}
@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.3); } 100% { transform: scale(1); } }

#controls {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; gap: 8px;
  padding: 12px 12px calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
}
#controls input { margin: 0; flex: 1; padding: 12px; font-size: 14px; }
#controls .mini { padding: 12px 16px; background: var(--accent); border-radius: 12px; }

#toasts { position: absolute; left: 12px; bottom: 90px; z-index: 25; display: flex; flex-direction: column; gap: 6px; max-width: 70%; pointer-events: none; }
.toast { background: rgba(0,0,0,0.72); backdrop-filter: blur(6px); padding: 8px 12px; border-radius: 14px; font-size: 14px; animation: toastIn 0.25s ease, toastOut 0.3s ease 4.2s forwards; border-left: 3px solid var(--accent); }
.toast .who { color: var(--accent); font-weight: 700; margin-right: 4px; }
@keyframes toastIn { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(-20px); } }

#chat {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 40;
  width: min(80%, 340px);
  background: rgba(14,14,18,0.72); backdrop-filter: blur(14px);
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 56px) 12px calc(env(safe-area-inset-bottom) + 12px);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -8px 0 24px rgba(0,0,0,0.4);
}
#chat.open { transform: translateX(0); }
#chatClose { position: absolute; top: calc(env(safe-area-inset-top) + 14px); right: 14px; width: 32px; height: 32px; padding: 0; margin: 0; background: rgba(255,255,255,0.15); border-radius: 50%; font-size: 18px; line-height: 32px; }
#messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.message { font-size: 14px; line-height: 1.4; word-break: break-word; }
.message .who { color: var(--accent); font-weight: 600; }
.message.sys { color: var(--muted); font-style: italic; font-size: 13px; }
#chatInputWrap { display: flex; gap: 8px; margin-top: 8px; }
#chatInput { margin: 0; flex: 1; padding: 12px; }
#sendBtn { width: auto; padding: 12px 18px; margin: 0; background: var(--accent); }

/* Полноэкранный режим (свой, для телефона) */
#room.fs #controls { opacity: 0; pointer-events: none; }
#room.fs #roomCode { opacity: 0; pointer-events: none; }
#room.fs #videoWrap { z-index: 1; }
#room.fs #topBar { bottom: calc(env(safe-area-inset-bottom) + 16px); }
#room:fullscreen #videoWrap { width: 100vw; height: 100vh; }
#room:-webkit-full-screen #videoWrap { width: 100vw; height: 100vh; }

/* Кнопка чата — справа по центру экрана */
.chat-btn-wrap {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%); z-index: 35;
}
#chatToggle {
  width: 52px; height: 52px; padding: 0; font-size: 22px;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(6px);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}
#room.fs .chat-btn-wrap { top: 50%; }

/* В своём фуллскрине — тосты крупнее и заметнее */
#room.fs #toasts { bottom: 20px; left: 50%; transform: translateX(-50%); max-width: 90%; align-items: center; }
#room.fs .toast { font-size: 16px; padding: 12px 18px; background: rgba(0,0,0,0.85); }

/* ===== РЕЖИМ КИНО (видео сверху, чат снизу) ===== */
#theater { display: none; }
#room.theater { flex-direction: column; }
#room.theater #videoWrap {
  position: absolute; top: 0; left: 0; right: 0;
  height: 42vh; height: 42dvh; bottom: auto;
}
#room.theater #theater {
  display: flex; flex-direction: column;
  position: absolute; top: 42vh; top: 42dvh; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  padding: 10px 10px calc(env(safe-area-inset-bottom) + 10px);
  z-index: 15;
}
#theaterMessages {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 8px 4px;
}
#theaterMessages .message { font-size: 15px; line-height: 1.4; word-break: break-word; }
#theaterMessages .message .who { color: var(--accent); font-weight: 700; }
#theaterMessages .message.sys { color: var(--muted); font-style: italic; font-size: 13px; }
#theaterInputWrap { display: flex; gap: 8px; }
#theaterInput { margin: 0; flex: 1; padding: 14px; font-size: 15px; }
#theaterSend { width: auto; padding: 14px 20px; margin: 0; background: var(--accent); font-size: 16px; }

/* В режиме кино прячем нижнюю строку ввода ссылки, всплывашки и боковой чат-оверлей */
#room.theater #controls { display: none; }
#room.theater #toasts { display: none; }
#room.theater .chat-btn-wrap { display: none; }
#room.theater #topBar { bottom: auto; top: calc(42vh - 60px); }
