/* TwoCities — late-night cinema for two.
   Mobile-first: big touch targets, safe-area aware, landscape theatre mode. */

:root {
  --bg: #0b0812;
  --panel: #171021;
  --panel-2: #211732;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f6eff8;
  --muted: #a094b3;
  --rose: #ff5c8a;
  --gold: #ffb86b;
  --peer: #c77dff;
  --good: #5ce0a1;
  --amber: #ffcf6b;
  --grad: linear-gradient(135deg, #ff5c8a, #ffb86b);
  --radius: 20px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100dvh;
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background:
    radial-gradient(1100px 560px at 18% -12%, rgba(255, 92, 138, 0.16), transparent 60%),
    radial-gradient(900px 480px at 92% -6%, rgba(199, 125, 255, 0.12), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
button { cursor: pointer; }
.mono { font-family: "IBM Plex Mono", monospace; }

/* ---- Top bar ---------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top)) clamp(14px, 4vw, 28px) 10px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 34px; height: 26px; display: block; }
.logo.big { width: 72px; height: 54px; margin: 0 auto 6px; }

.brandname {
  font-family: "Fraunces", serif;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.brandname em, .name-card h1 em {
  font-style: normal;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.link-info { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.room b, .link-quality b { font-family: "IBM Plex Mono", monospace; color: var(--text); font-weight: 500; }
.link-quality::before { content: "❤"; color: var(--rose); margin-right: 5px; font-size: 11px; }

/* ---- Buttons ---------------------------------------------------------- */
.ghost {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.2s, background 0.2s;
}
.ghost:active { transform: translateY(1px); }
.ghost.muted  { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 45%, transparent); }
.ghost.active { color: var(--good);  border-color: color-mix(in srgb, var(--good) 45%, transparent); }

.primary {
  min-height: 48px;
  padding: 10px 18px;
  border: none;
  border-radius: 14px;
  background: var(--grad);
  color: #2b0d18;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(255, 92, 138, 0.28);
}
.primary:active { transform: translateY(1px); }

/* ---- Layout ------------------------------------------------------------ */
.layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: 6px clamp(12px, 3.5vw, 26px) calc(28px + env(safe-area-inset-bottom));
  display: grid;
  gap: 14px;
}
@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr) 370px; align-items: start; }
}

/* ---- Stage ------------------------------------------------------------- */
.stage {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
#videoEl, #ytMount, .stage iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.stage-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px 26px;
  background: linear-gradient(rgba(5, 3, 10, 0.75), transparent);
  pointer-events: none;
  transition: opacity 0.35s;
}
.stage.empty .stage-top { display: none; }
.now-title {
  font-family: "Fraunces", serif;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
}

.placeholder {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 4px;
  padding: 20px;
  background:
    radial-gradient(500px 260px at 50% 20%, rgba(255, 92, 138, 0.12), transparent 70%),
    var(--panel);
}
.stage.empty .placeholder { display: flex; }
.ph-title { font-family: "Fraunces", serif; font-size: 22px; margin: 0; }
.ph-sub { color: var(--muted); margin: 0; max-width: 34ch; font-size: 14px; }

/* Tap-to-join: shown when autoplay is blocked for a late joiner */
.tap-join {
  position: absolute;
  z-index: 7;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  border: none;
  border-radius: 999px;
  padding: 16px 26px;
  font-size: 16px;
  font-weight: 600;
  background: var(--grad);
  color: #2b0d18;
  box-shadow: 0 10px 40px rgba(255, 92, 138, 0.45);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 10px 40px rgba(255, 92, 138, 0.45); }
  50%      { box-shadow: 0 10px 56px rgba(255, 92, 138, 0.75); }
}

/* In-stage chat toast: reply without leaving the movie */
.chat-toast {
  position: absolute;
  z-index: 8;
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 24px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid color-mix(in srgb, var(--rose) 35%, var(--line));
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  animation: toast-in 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-14px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.toast-msg { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.toast-who { font-size: 11px; font-weight: 600; color: var(--rose); }
.toast-text { font-size: 14px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.toast-reply { display: flex; gap: 6px; }
.toast-reply input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  outline: none;
}
.toast-reply input:focus { border-color: color-mix(in srgb, var(--rose) 55%, transparent); }
.toast-reply button {
  width: 40px;
  min-height: 40px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
}
#toastSend { background: var(--grad); color: #2b0d18; }
#toastClose { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); font-size: 18px; }

/* ---- Transport --------------------------------------------------------- */
.transport {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  transition: opacity 0.35s;
}
.play {
  width: 54px;
  height: 54px;
  flex: none;
  border: none;
  border-radius: 50%;
  background: var(--grad);
  color: #2b0d18;
  font-size: 19px;
  box-shadow: 0 8px 26px rgba(255, 92, 138, 0.35);
  display: grid;
  place-items: center;
}
.play:active { transform: scale(0.96); }

.scrubber { flex: 1; min-width: 0; }
.track { position: relative; height: 28px; cursor: pointer; touch-action: manipulation; }
.track::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 6px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: var(--panel-2);
}
.fill {
  position: absolute;
  left: 0; top: 50%;
  height: 6px;
  width: 0%;
  transform: translateY(-50%);
  border-radius: 999px;
  background: var(--grad);
}
.peer-layer { position: absolute; inset: 0; pointer-events: none; }
.dot {
  position: absolute;
  top: 50%;
  width: 14px; height: 14px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.dot-me { background: #fff; box-shadow: 0 0 0 3px color-mix(in srgb, var(--rose) 55%, transparent); z-index: 2; }
.dot-peer { background: var(--peer); box-shadow: 0 0 12px color-mix(in srgb, var(--peer) 80%, transparent); }
.times { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: -2px; }

.voice, .fs { width: 46px; height: 46px; padding: 0; flex: none; font-size: 17px; display: grid; place-items: center; }

/* Drift pill */
.drift {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10.5px;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid transparent;
  flex: none;
}
.drift.locked    { color: var(--good);  background: color-mix(in srgb, var(--good) 16%, rgba(0,0,0,.4)); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.drift.adjusting { color: var(--amber); background: color-mix(in srgb, var(--amber) 16%, rgba(0,0,0,.4)); border-color: color-mix(in srgb, var(--amber) 40%, transparent); }
.drift.resyncing { color: var(--peer);  background: color-mix(in srgb, var(--peer) 16%, rgba(0,0,0,.4)); border-color: color-mix(in srgb, var(--peer) 40%, transparent); }
.drift.buffering { color: var(--amber); background: color-mix(in srgb, var(--amber) 16%, rgba(0,0,0,.4)); border-color: color-mix(in srgb, var(--amber) 40%, transparent); }
.drift.paused    { color: var(--muted); background: rgba(0, 0, 0, 0.4); border-color: var(--line); }

.presence {
  color: var(--muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 4px;
}
.presence b { color: var(--text); font-weight: 600; }

.theatre { display: grid; gap: 12px; }

/* ---- Side: tabs, list, chat -------------------------------------------- */
.side {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  overflow: hidden;
}

.tabs { display: flex; padding: 8px; gap: 6px; }
.tab {
  flex: 1;
  min-height: 44px;
  border: none;
  border-radius: 13px;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
}
.tab.on { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px; height: 17px;
  padding: 0 5px;
  background: var(--rose);
  color: #fff;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  margin-left: 4px;
  vertical-align: middle;
}

.panel { display: none; padding: 6px 12px 12px; }
.panel.on { display: flex; flex-direction: column; gap: 10px; }

/* Watchlist */
.add { display: flex; flex-direction: column; gap: 8px; }
.add input, .chat-compose input, .add select {
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  outline: none;
  width: 100%;
}
.add input:focus, .chat-compose input:focus { border-color: color-mix(in srgb, var(--rose) 55%, transparent); }
.add input::placeholder, .chat-compose input::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
.add-row { display: flex; gap: 8px; }
.add-row select { flex: 1; appearance: none; }
.add-row .primary { flex: none; }

.wl-list { display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 26px 12px; margin: 0; }
.wl-row { display: flex; gap: 8px; }
.wl-pick {
  flex: 1;
  min-width: 0;
  min-height: 54px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-2);
  color: var(--text);
  text-align: left;
  transition: border-color 0.2s;
}
.wl-pick:active { border-color: color-mix(in srgb, var(--rose) 55%, transparent); }
.wl-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.wl-kind { font-size: 11px; color: var(--muted); font-family: "IBM Plex Mono", monospace; }
.wl-del {
  width: 44px;
  flex: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 14px;
  font-size: 20px;
}

/* Chat */
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 220px;
  max-height: 46vh;
  padding: 4px 2px;
  overscroll-behavior: contain;
}
.chat-row { max-width: 84%; padding: 8px 13px; border-radius: 17px; word-break: break-word; }
.chat-row.mine {
  align-self: flex-end;
  background: var(--grad);
  color: #2b0d18;
  border-bottom-right-radius: 6px;
}
.chat-row.theirs {
  align-self: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.chat-row.chat-system { align-self: center; background: transparent; color: var(--muted); font-size: 12px; padding: 2px; }
.chat-who { display: block; font-size: 10.5px; margin-bottom: 1px; opacity: 0.75; font-weight: 600; }
.chat-row.mine .chat-who { display: none; }
.chat-text { font-size: 14px; }
.chat-compose { display: flex; gap: 8px; }
.chat-compose input { flex: 1; min-width: 0; }
.chat-compose .primary { flex: none; padding: 10px 16px; }

/* ---- Name overlay ------------------------------------------------------- */
.name-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.name-card {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  padding: 30px 26px calc(26px + env(safe-area-inset-bottom));
  border-radius: 24px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.name-card h1 { font-family: "Fraunces", serif; font-size: 30px; font-weight: 600; margin: 0; }
.name-card p { color: var(--muted); margin: -6px 0 6px; font-size: 14px; }
.name-card input {
  min-height: 50px;
  padding: 10px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  outline: none;
  text-align: center;
  font-size: 16px;
}
.name-card input:focus { border-color: color-mix(in srgb, var(--rose) 55%, transparent); }

/* ---- Theatre mode: phone rotated to landscape --------------------------- */
body.theatre .topbar,
body.theatre .side,
body.theatre .presence { display: none; }
body.theatre .layout { max-width: none; padding: 0; }
body.theatre .stage {
  position: fixed;
  inset: 0;
  z-index: 60;
  border-radius: 0;
  border: none;
  aspect-ratio: auto;
}
body.theatre .transport {
  position: fixed;
  left: calc(12px + env(safe-area-inset-left));
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 61;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
body.theatre .reactions {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 61;
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 4px 10px;
  transition: opacity 0.35s;
}
/* Controls fade away while you watch; any touch brings them back */
body.theatre.idle .transport { opacity: 0; pointer-events: none; }
body.theatre.idle .stage-top { opacity: 0; }
body.theatre.idle .reactions { opacity: 0; pointer-events: none; }

/* ---- Floating emoji reactions ------------------------------------------- */
.reactions {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.reactions button {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  border-radius: 50%;
  font-size: 23px;
  line-height: 1;
  transition: transform 0.12s;
}
.reactions button:active { transform: scale(1.35); }

.reaction-layer {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  overflow: hidden;
}
.reaction-float {
  position: absolute;
  bottom: 6%;
  font-size: 34px;
  line-height: 1;
  will-change: transform, opacity;
  animation: float-up 2.4s ease-out forwards;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.4));
}
@keyframes float-up {
  0%   { transform: translateY(0) scale(0.5); opacity: 0; }
  12%  { transform: translateY(-8%) scale(1.15); opacity: 1; }
  100% { transform: translateY(-72vh) translateX(var(--drift, 0px)) scale(0.9); opacity: 0; }
}

/* ---- "Wait for me" banner ------------------------------------------------ */
.wait-banner {
  position: absolute;
  z-index: 7;
  top: 46px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--amber);
  border: 1px solid color-mix(in srgb, var(--amber) 40%, transparent);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: wait-pulse 1.6s ease-in-out infinite;
}
@keyframes wait-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.65; }
}

/* ---- Typing indicator ----------------------------------------------------- */
.chat-typing {
  min-height: 16px;
  font-size: 12px;
  font-style: italic;
  color: var(--muted);
  padding: 0 6px;
}
