/* WatchParty: Late night living room.
   Tokens and principles live in DESIGN.md at the repo root. */

@font-face {
  font-family: 'Bricolage Grotesque';
  font-style: normal;
  font-weight: 200 800;
  font-stretch: 100%;
  font-display: swap;
  src: url('/app/fonts/BricolageGrotesque.woff2') format('woff2');
}

:root {
  --ink: #151210;
  --sofa: #1E1915;
  --cushion: #28211B;
  --line: rgba(255, 255, 255, 0.08);
  --line-bright: rgba(255, 255, 255, 0.16);
  --text: #F5EFE6;
  --muted: #A79B8D;
  --accent: #FFB43A;
  --accent-soft: rgba(255, 180, 58, 0.14);
  --accent-ink: #201808;
  --presence: #4CD471;
  --presence-soft: rgba(76, 212, 113, 0.14);
  --coral: #FF6B5E;
  --coral-soft: rgba(255, 107, 94, 0.14);
  --glow: rgba(255, 180, 58, 0.35);
  --font-display: 'Bricolage Grotesque', -apple-system, 'Segoe UI', system-ui, sans-serif;
  --font-body: -apple-system, 'SF Pro Text', 'Segoe UI', Roboto, system-ui, sans-serif;
  --font-code: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --r-pill: 999px;
  --r-sheet: 16px;
  --r-big: 24px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--text);
  font: 16px/1.5 var(--font-body);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* ---- top bar ---- */

#bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(21, 18, 16, 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
#menu {
  background: none;
  border: none;
  color: var(--text);
  padding: 6px;
  margin-left: -6px;
  cursor: pointer;
  border-radius: var(--r-pill);
  opacity: 0.85;
}
#menu:active { opacity: 0.5; }
#bar-title {
  font: 700 18px var(--font-display);
  letter-spacing: -0.2px;
  display: flex;
  align-items: baseline;
  gap: 5px;
}
.bulb {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px 2px var(--glow);
  display: inline-block;
}
.bulb.big { width: 9px; height: 9px; }
#status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
}
#count { color: var(--muted); font-size: 12.5px; font-weight: 550; }

/* host crown: the room creator wears it */
.member .crown {
  color: var(--accent);
  flex-shrink: 0;
  margin-left: 1px;
  filter: drop-shadow(0 0 4px rgba(255, 180, 58, 0.45));
}

/* resync: one tap re-anchor next to the playing strip */
#resync {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(255, 180, 58, 0.3);
  border-radius: var(--r-pill);
  padding: 7px 14px;
  font: 600 12.5px var(--font-body);
  cursor: pointer;
  white-space: nowrap;
}
#dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4A423A;
  display: inline-block;
  transition: background 0.3s, box-shadow 0.3s;
}
#dot.on {
  background: var(--presence);
  box-shadow: 0 0 8px rgba(76, 212, 113, 0.5);
}

/* ---- video ---- */

#player-wrap { position: relative; background: #000; aspect-ratio: 16 / 9; flex-shrink: 0; }
#player-wrap[hidden], #nowplaying[hidden], #call[hidden], #reactions[hidden] { display: none !important; }
#player, #player iframe { width: 100%; height: 100%; display: block; }
#player:empty::before {
  content: 'Loading the video...';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  background: #0B0908;
}
#companion {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(120% 90% at 50% 0%, #241D15 0%, #151210 62%);
  text-align: center;
  padding: 24px;
}
.companion-bulb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 18px 5px var(--glow);
  margin: 0 auto 14px;
}
.companion-inner h2 {
  margin: 0 0 8px;
  font: 600 21px var(--font-display);
  letter-spacing: -0.3px;
}
.companion-inner p { margin: 6px 0; color: var(--muted); font-size: 14px; line-height: 1.5; }

#nowplaying {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
#playing-label {
  color: var(--muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#switch-mode {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(255, 180, 58, 0.3);
  border-radius: var(--r-pill);
  padding: 7px 14px;
  font: 600 12.5px var(--font-body);
  cursor: pointer;
  white-space: nowrap;
}

/* ---- buttons ---- */

button {
  font-family: var(--font-body);
  background: var(--cushion);
  color: var(--text);
  border: 1px solid var(--line-bright);
  border-radius: var(--r-pill);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.2s, border-color 0.2s;
}
button:active { transform: scale(0.97); }
button:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}
button.primary:active { transform: scale(0.98); }
button.big {
  border-radius: var(--r-big);
  padding: 15px 20px;
  font: 600 16px var(--font-display);
  letter-spacing: 0.1px;
  box-shadow: 0 6px 24px rgba(255, 180, 58, 0.22);
}
button.pill { padding: 8px 14px; font-size: 13px; border-radius: var(--r-pill); }
button.ghost { background: none; border-color: transparent; color: var(--muted); }
button.ghost:active { color: var(--text); }

#call-btn.on {
  background: var(--presence-soft);
  border-color: rgba(76, 212, 113, 0.4);
  color: var(--presence);
  font-weight: 650;
}
#mute-btn.round {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  padding: 0;
  flex-shrink: 0;
  font-size: 13px;
}
#mute-btn.muted {
  background: var(--coral-soft);
  border-color: rgba(255, 107, 94, 0.4);
  color: var(--coral);
  font-weight: 650;
}

/* ---- voice ---- */

#call {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.call-row { display: flex; gap: 10px; align-items: center; }
#call-btn { flex: 1; padding: 13px 18px; font: 600 15px var(--font-display); }
#call-btn.on::before { content: ''; }
.voice-more summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 8px;
}
.voice-more summary::-webkit-details-marker { display: none; }
.voice-more summary::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 1.6px solid var(--muted);
  border-bottom: 1.6px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.2s;
  margin-top: -3px;
}
.voice-more[open] summary::after { transform: rotate(-135deg); margin-top: 3px; }
.voice-more[open] summary { margin-bottom: 8px; }
.slider-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.slider-row input[type="range"] { flex: 1; accent-color: var(--accent); height: 28px; }
.slider-row b { font-weight: 500; min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.check input { accent-color: var(--accent); width: 18px; height: 18px; }

/* ---- reactions ---- */

#reactions { display: flex; gap: 8px; padding: 10px 16px; }
.react {
  background: var(--cushion);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 9px 0;
  font-size: 25px;
  cursor: pointer;
  flex: 1;
  line-height: 1.3;
  transition: transform 0.12s, background 0.15s, box-shadow 0.2s;
}
.react:active {
  transform: scale(0.85);
  background: var(--accent-soft);
  box-shadow: 0 0 14px 2px rgba(255, 180, 58, 0.25);
}

/* ---- setup and room ---- */

#panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px;
}
#setup[hidden], #room[hidden], #companion[hidden] { display: none !important; }

#setup { display: flex; flex-direction: column; gap: 12px; padding-top: 8px; }
.hero { padding: 34px 0 18px; text-align: center; }
.wordmark {
  margin: 0;
  font: 750 clamp(34px, 9vw, 44px) var(--font-display);
  letter-spacing: -1px;
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
}
.tagline { margin: 10px auto 0; color: var(--muted); font-size: 15.5px; max-width: 34ch; line-height: 1.55; }

.seg {
  display: flex;
  background: var(--sofa);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 4px;
  gap: 4px;
}
.seg-btn {
  flex: 1;
  background: none;
  border: none;
  border-radius: var(--r-pill);
  color: var(--muted);
  padding: 9px 10px;
  font-size: 13.5px;
  font-weight: 550;
}
.seg-btn.on { background: var(--cushion); color: var(--accent); font-weight: 650; }

.hint { color: var(--muted); font-size: 13.5px; margin: -4px 0 0; line-height: 1.5; }
.muted { color: var(--muted); font-size: 14px; margin: 0; line-height: 1.5; }
label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 550;
  margin-top: 8px;
}
input {
  background: var(--sofa);
  color: var(--text);
  border: 1px solid var(--line-bright);
  border-radius: var(--r-sheet);
  padding: 13px 15px;
  font-size: 16px;
  font-family: var(--font-body);
  width: 100%;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
input:focus { border-color: var(--accent); background: var(--cushion); }
input::placeholder { color: #6E6459; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }

.join-alt {
  margin-top: 2px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.join-alt summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 550;
  list-style: none;
  border-radius: 8px;
}
.join-alt summary::-webkit-details-marker { display: none; }
.join-alt summary::before { content: '+ '; color: var(--accent); font-weight: 700; }
.join-alt[open] summary::before { content: 'x '; }
.join-alt .row { margin-top: 10px; }

/* room */

#room { display: flex; flex-direction: column; flex: 1; min-height: 0; padding-top: 12px; }
.room-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.ticket {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  background: var(--accent-soft);
  border: 1.5px solid rgba(255, 180, 58, 0.45);
  border-radius: 12px;
  padding: 7px 14px;
  position: relative;
}
.ticket-label { font-size: 11px; color: var(--muted); font-weight: 550; letter-spacing: 0.4px; }
#room-code {
  font: 700 16px var(--font-display);
  color: var(--accent);
  letter-spacing: 2.5px;
  text-transform: uppercase;
}
#copy, #leave { margin-left: 0; }
#leave { margin-left: auto; }

#members {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.member {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--sofa);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 5px 12px 5px 6px;
  font-size: 13.5px;
  color: var(--text);
}
.member .avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 700 12px var(--font-display);
  color: var(--ink);
  background: var(--c, var(--accent));
  flex-shrink: 0;
}
.member.speaking { border-color: rgba(76, 212, 113, 0.45); }
.member.speaking .avatar { animation: ring 1.2s ease-in-out infinite; }
.member.buf { border-color: rgba(255, 180, 58, 0.4); }
.member.buf .avatar { background: var(--cushion); color: var(--muted); animation: ring 1.2s ease-in-out infinite; }
@keyframes ring {
  0%, 100% { box-shadow: 0 0 0 0 rgba(76, 212, 113, 0.55); }
  50% { box-shadow: 0 0 0 5px rgba(76, 212, 113, 0); }
}

#chat {
  flex: 1;
  min-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-sheet);
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--sofa);
  scroll-behavior: smooth;
}
.msg { margin: 7px 0; word-break: break-word; font-size: 15px; line-height: 1.45; }
.msg .who { font-weight: 650; margin-right: 8px; }
.sys {
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
  margin: 5px 0;
}
#chat-form { display: flex; gap: 8px; padding-bottom: 8px; }
#chat-input { flex: 1; border-radius: var(--r-pill); }
button.send { border-radius: var(--r-pill); font-weight: 600; }

/* ---- floating reactions ---- */

.float-reaction {
  position: fixed;
  z-index: 2147483646;
  pointer-events: none;
  text-align: center;
  animation: float-up 2.6s ease-out forwards;
}
.float-reaction .fr-emoji { font-size: 38px; line-height: 1.2; filter: drop-shadow(0 2px 10px rgba(0,0,0,0.6)); }
.float-reaction .fr-name {
  font-size: 12px;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0,0,0,.9);
  margin-top: 2px;
  font-weight: 550;
}
@keyframes float-up {
  0% { transform: translateY(0) scale(0.4); opacity: 0; }
  8% { transform: translateY(-6px) scale(1.25); opacity: 1; }
  16% { transform: translateY(-14px) scale(1); opacity: 1; }
  100% { transform: translateY(-210px) translateX(14px) scale(0.65); opacity: 0; }
}

/* ---- toast ---- */

#toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(40, 33, 27, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 180, 58, 0.35);
  border-radius: var(--r-pill);
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 550;
  max-width: 90vw;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  box-shadow: 0 10px 34px rgba(0,0,0,0.5), 0 0 0 1px rgba(0,0,0,0.3);
  z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ---- setup entrance: the one orchestrated moment ---- */

@media (prefers-reduced-motion: no-preference) {
  .hero .wordmark, .hero .tagline, .hero .bulb {
    animation: arrive 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
  }
  .hero .tagline { animation-delay: 0.12s; }
}
@keyframes arrive {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .float-reaction { animation: float-fade 2.6s ease-out forwards; }
  .member.speaking .avatar, .member.buf .avatar { animation: none; }
}
@keyframes float-fade {
  0% { opacity: 0; }
  10% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---- desktop: the movie keeps the whole left side, social lives in the rail.
   Only while a party is live; the setup screen centers itself instead of
   reserving an empty video column. ---- */

@media (min-width: 900px) {
  body.in-room { height: 100dvh; overflow: hidden; }
  body.in-room {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 408px;
    grid-template-rows: auto auto auto auto minmax(0, 1fr);
    padding-bottom: 0;
  }
  body.in-room #bar { grid-column: 1 / -1; grid-row: 1; }
  body.in-room #player-wrap {
    grid-column: 1;
    grid-row: 2 / 6;
    aspect-ratio: auto;
    min-height: 0;
    height: auto;
  }
  body.in-room #nowplaying { grid-column: 2; grid-row: 2; }
  body.in-room #call { grid-column: 2; grid-row: 3; }
  body.in-room #reactions { grid-column: 2; grid-row: 4; }
  body.in-room #panel {
    grid-column: 2;
    grid-row: 5;
    min-height: 0;
    overflow-y: auto;
    margin: 0;
    max-width: none;
  }
  body.in-room #panel #room { height: 100%; }

  /* Setup screen: a calm centered column, no dead space either side. */
  body:not(.in-room) #panel {
    margin: 0 auto;
    padding-top: 4vh;
  }
  body:not(.in-room) .hero { padding-top: 6vh; padding-bottom: 22px; }
}
