:root {
  --bg: #0f1115;
  --card: #181b22;
  --line: #262a33;
  --text: #eceff4;
  --muted: #8b93a3;
  --accent: #ff5d73;
  --ok: #3ecf8e;
  --warn: #f5b942;
  --bad: #ff6b6b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, Tahoma, "Segoe UI", system-ui, sans-serif;
  line-height: 1.7;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.top h1 { margin: 0; font-size: 1.4rem; }

.chip {
  font-size: .78rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  white-space: nowrap;
}
.chip--wait { color: var(--muted); }
.chip--ok   { color: var(--ok);   border-color: rgba(62,207,142,.4); }
.chip--bad  { color: var(--bad);  border-color: rgba(255,107,107,.4); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  text-align: center;
}
.hint { margin: 0 0 12px; font-size: 1.05rem; }
.note { margin: 12px 0 0; font-size: .82rem; color: var(--muted); }

.btn {
  display: inline-block;
  min-height: 48px;
  padding: 11px 28px;
  border-radius: 14px;
  font-size: 1.05rem;
  cursor: pointer;
  user-select: none;
}
.btn--primary { background: var(--accent); color: #fff; font-weight: 700; }
.btn--primary:active { filter: brightness(.9); }

.link { color: var(--accent); font-size: .9rem; cursor: pointer; }

.info-name {
  font-weight: 700;
  word-break: break-all;
  text-align: center;
}
.info-row {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 4px 0 6px;
  color: var(--muted);
  font-size: .9rem;
}

.error {
  background: rgba(255,107,107,.1);
  border: 1px solid rgba(255,107,107,.4);
  color: var(--bad);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: .92rem;
}

/* ---------- player ---------- */
.player {
  position: relative;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.player video {
  display: block;
  width: 100%;
  max-height: 60vh;
  background: #000;
}
.controls {
  background: var(--card);
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.seek-row { display: flex; align-items: center; gap: 10px; }
.time { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 3.4em; text-align: center; }
.seek { flex: 1; min-width: 0; accent-color: var(--accent); height: 28px; }

.btn-row { display: flex; align-items: center; justify-content: center; gap: 8px; }
.ctl {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #1f232c;
  color: var(--text);
  font-size: .95rem;
  cursor: pointer;
}
.ctl:active { background: #2a2f3a; }
.ctl--main { background: var(--accent); border-color: var(--accent); font-size: 1.15rem; min-width: 56px; }
.vol { width: 70px; accent-color: var(--accent); }

/* fullscreen: container is fullscreened (not just <video>) so overlays still work later */
.player:fullscreen { display: flex; flex-direction: column; border-radius: 0; border: 0; }
.player:fullscreen video { flex: 1; max-height: none; min-height: 0; object-fit: contain; }
.player:-webkit-full-screen { display: flex; flex-direction: column; border-radius: 0; border: 0; }
.player:-webkit-full-screen video { flex: 1; max-height: none; min-height: 0; object-fit: contain; }

@media (max-width: 380px) {
  .vol { display: none; }
}

/* ---------- home / room (Phase 2) ---------- */
button.btn { border: 0; font-family: inherit; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--block { display: block; width: 100%; }
.btn--ghost { background: #232733; color: var(--text); border: 1px solid var(--line); }
.btn--ghost:active { background: #2a2f3a; }

#home, #room { display: flex; flex-direction: column; gap: 14px; }
#home[hidden], #room[hidden] { display: none; }

.join-row { display: flex; gap: 10px; }
.code-in {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #0f1115;
  color: var(--text);
  font-size: 1.05rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  text-align: center;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.code-in:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.status { text-align: start; display: flex; flex-direction: column; gap: 10px; }
.status .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.status .row span { color: var(--muted); font-size: .9rem; }
.status .row b { font-size: .98rem; }
#roomCode { letter-spacing: .14em; font-family: ui-monospace, Menlo, Consolas, monospace; }

.ready-msg { text-align: center; font-weight: 700; color: var(--ok); margin: 6px 0; }
.file-check { text-align: center; font-size: .86rem; margin-bottom: 6px; }
.file-check--ok { color: var(--ok); }
.file-check--warn { color: var(--warn); }
.peer-file { text-align: center; font-size: .78rem; color: var(--muted); word-break: break-all; margin-bottom: 10px; }
#fatal[hidden], #readyBox[hidden] { display: none; }

/* ---------- synced playback (Phase 3) ---------- */
.overlay {
  position: absolute; inset: 0 0 auto 0; height: 60vh; max-height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 4rem; font-weight: 700; color: #fff;
  background: rgba(0, 0, 0, .45); pointer-events: none;
}
.player:fullscreen .overlay, .player:-webkit-full-screen .overlay { height: auto; bottom: 0; }
.resume { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); z-index: 2; }
.drift { text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- chat (Phase 6) ---------- */
.chat-float {
  position: absolute; top: 8px; inset-inline: 8px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  pointer-events: none; z-index: 1;
}
.chat-bubble {
  max-width: 92%; padding: 4px 10px; border-radius: 12px;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: .85rem; line-height: 1.5;
  word-break: break-word; transition: opacity .4s;
  animation: chat-in .18s ease-out;
}
.chat-bubble b { opacity: .7; font-weight: 600; margin-inline-end: 6px; }
.chat-bubble--out { opacity: 0; }
@keyframes chat-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.react-float {
  position: absolute; inset: 0 0 auto 0; height: 50vh; max-height: 100%;
  overflow: hidden; pointer-events: none; z-index: 1;
}
.player:fullscreen .react-float, .player:-webkit-full-screen .react-float { height: auto; bottom: 0; }
.react-emoji { position: absolute; bottom: -8%; font-size: 2rem; animation: react-rise 2.6s ease-out forwards; }
@keyframes react-rise {
  0%   { transform: translateY(0) scale(.6); opacity: 0; }
  12%  { opacity: 1; transform: translateY(-8%) scale(1); }
  100% { transform: translateY(-42vh) scale(1.15); opacity: 0; }
}
.react-bar { display: flex; justify-content: center; gap: 6px; }
.react-btn { min-width: 40px; min-height: 40px; padding: 0; font-size: 1.15rem; }

.chat-head {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  background: none; border: 0; color: var(--text); font: inherit; font-weight: 700; padding: 0; cursor: pointer;
}
.badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 9px; font-size: .78rem; }
.chat-list { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow-y: auto; margin: 12px 0; }
.chat-msg { background: #1f232c; border-radius: 12px; padding: 6px 10px; font-size: .92rem; word-break: break-word; }
.chat-msg b { color: var(--muted); font-weight: 600; margin-inline-end: 6px; }
.chat-msg--me { background: rgba(255, 93, 115, .18); }
.chat-row { display: flex; gap: 8px; }
.chat-in {
  flex: 1; min-width: 0; background: #1f232c; border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 10px 12px; font-size: 16px; font-family: inherit;
}

/* ---------- reconnect / buffering (Phase 7) ---------- */
.toast {
  position: fixed; inset-inline: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  margin-inline: auto; width: fit-content; max-width: 90%;
  background: rgba(20, 22, 28, .96); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 12px; font-size: .9rem; text-align: center; z-index: 50;
}
.buf-msg {
  position: absolute; top: 38%; inset-inline: 0; text-align: center;
  background: rgba(0, 0, 0, .5); color: #fff; padding: 6px; font-size: .95rem;
  pointer-events: none; z-index: 1;
}
.buf { text-align: center; color: var(--warn); }
