/* ---------- Watch together (party.js, partylink.js, companion.js) ----------
   A watch party in the player, the page its link or code opens, and the phone companion. Built
   from the player's own controls and menus (.ctl, .player-menu) and the shared buttons, in the
   theme's colours: only what's the party's own is here. */

/* ---------- In the player ---------- */
/* Watch together in the bar is the player's own labelled control (Back's twin). In a party it's
   the people icon, how many are watching and a dot for how the party is doing: green in step,
   amber catching up or reconnecting, grey waiting for others. */
#party-btn svg.people { width: 1.35rem; height: 1.35rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
#party-btn.in-party { width: auto; gap: 0.45rem; padding: 0 0.85rem 0 0.7rem; background: rgba(255, 255, 255, 0.14); font-variant-numeric: tabular-nums; }
#party-btn.in-party:hover, #party-btn.in-party[aria-expanded="true"] { background: rgba(255, 255, 255, 0.24); }
/* A guest can only be in the party they came in with, never start one. */
html[data-guest] #party-btn:not(.in-party) { display: none; }
.party-count { font-weight: 600; }
.party-dot { display: inline-block; flex: none; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--ok-dot); }
.party-dot[data-tone="wait"] { background: var(--warn); animation: party-pulse 1.4s ease-in-out infinite; }
.party-dot[data-tone="idle"] { background: var(--muted); animation: party-pulse 2.2s ease-in-out infinite; }
.party-dot[data-tone="off"] { background: var(--muted); }
@keyframes party-pulse { 50% { opacity: 0.3; } }

/* The party's panel: one of the player's menus, opening from its button at the top. */
#party-panel { top: calc(max(0.75rem, env(safe-area-inset-top, 0px)) + 3.5rem); bottom: auto; width: min(22.5rem, calc(100% - 1.5rem)); max-height: calc(100% - 11rem); gap: 1rem; align-content: start; }
.party-head { display: flex; align-items: flex-start; gap: 0.75rem; }
.party-heading { flex: 1; min-width: 0; display: grid; gap: 0.3rem; }
.party-state { margin: 0; display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.875rem; line-height: 1.35; }
#party-panel .party-close { flex: none; width: 2.5rem; height: 2.5rem; min-height: 2.5rem; padding: 0; margin: -0.35rem -0.45rem 0 0; }
.party-close svg { width: 1.15rem; height: 1.15rem; }

/* Who's here: an initial each (yours in the theme's accent), with who started it, who's a guest,
   who's on a phone and whose video is loading. */
.party-people { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.55rem; }
.party-person { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
.party-avatar { position: relative; flex: none; display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: 50%;
  background: var(--tonal); color: var(--on-tonal); font: 600 0.95rem/1 var(--font-body); }
.party-person.is-me .party-avatar { background: var(--accent); color: var(--on-accent); }
.party-person.is-waiting .party-avatar { outline: 2px solid var(--warn); outline-offset: 2px; animation: party-pulse 1.4s ease-in-out infinite; }
.party-avatar .party-icon { position: absolute; right: -0.3rem; bottom: -0.3rem; display: grid; place-items: center; width: 1.15rem; height: 1.15rem; border-radius: 50%;
  background: var(--surface); color: var(--text); }
.party-avatar .party-icon svg { width: 0.8rem; height: 0.8rem; }
.party-who { display: grid; min-width: 0; line-height: 1.3; }
.party-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.party-tags { color: var(--muted); font-size: 0.8rem; }
.party-person.is-host .party-tags { color: var(--accent); }
.party-line { margin: 0; color: var(--muted); font-size: 0.875rem; line-height: 1.45; }

/* The invite: the code to read out, the link to send, and the QR code a phone scans. */
.party-invite { display: grid; gap: 0.9rem; padding: 0.9rem 1rem; border-radius: var(--radius); background: color-mix(in srgb, var(--text) 6%, transparent); }
.party-code-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem 1rem; }
.party-code-box { margin: 0; display: grid; gap: 0.15rem; min-width: 0; }
.party-label { color: var(--muted); font-size: 0.8rem; line-height: 1.35; }
.party-code { color: var(--text); font: 600 1.4rem/1.2 var(--font-mono); letter-spacing: 0.08em; }
.party-phone { display: flex; align-items: center; gap: 0.9rem; }
.party-qr { flex: none; width: 6.5rem; height: 6.5rem; border-radius: calc(var(--radius) * 0.75); background: #EDE7DA; }
.party-phone p { margin: 0; color: var(--muted); font-size: 0.85rem; line-height: 1.45; }
.party-reactions { justify-content: space-between; }
.party-confirm { display: grid; gap: 0.75rem; }
.party-confirm p { margin: 0; }

/* What happened while the panel's closed, for a moment, under its button. */
.party-note { position: absolute; z-index: 4; top: calc(max(0.75rem, env(safe-area-inset-top, 0px)) + 3.5rem); right: max(clamp(0.75rem, 3vw, 2rem), env(safe-area-inset-right, 0px));
  max-width: min(22.5rem, calc(100% - 1.5rem)); margin: 0; padding: 0.6rem 1rem; border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 94%, transparent); color: var(--text); font-size: 0.9rem; line-height: 1.4;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); pointer-events: none; animation: pop-in 0.16s ease; }

/* A phone: the panel is a sheet from the bottom, over the controls, clear of the picture. */
@media (max-width: 640px) {
  #party-panel { top: auto; right: 0; bottom: 0; left: 0; width: 100%; max-height: min(80%, 36rem); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px)); box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.55); animation: party-up 0.22s var(--ease-out, ease); }
  #party-panel::before { content: ""; justify-self: center; width: 2.25rem; height: 0.25rem; margin: -0.35rem 0 -0.4rem; border-radius: 999px; background: color-mix(in srgb, var(--text) 28%, transparent); }
  #party-btn.in-party { padding: 0 0.7rem 0 0.6rem; }
  /* The invite kept short, so the sheet stays clear of as much of the picture as it can. */
  .party-invite { gap: 0.75rem; padding: 0.8rem 0.9rem; }
  .party-qr { width: 5.5rem; height: 5.5rem; }
}
/* Touch screens: every button in the panel is a comfortable tap (44 px and up). */
@media (pointer: coarse) {
  #party-panel :is(.primary, .ghost) { min-height: 2.75rem; }
  #party-panel .party-close { width: 2.75rem; height: 2.75rem; }
}
/* A phone on its side (or any short screen): a sheet down the right, the picture left clear. */
@media (max-height: 30rem) {
  #party-panel { top: 0; right: 0; bottom: 0; left: auto; width: min(22.5rem, 52%); max-height: none; gap: 0.75rem; border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    padding: max(0.9rem, env(safe-area-inset-top, 0px)) max(1.25rem, env(safe-area-inset-right, 0px)) max(0.9rem, env(safe-area-inset-bottom, 0px)) 1.25rem;
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.55); animation: party-in 0.2s var(--ease-out, ease); }
  #party-panel::before { content: none; }
  .party-invite { gap: 0.6rem; padding: 0.7rem 0.9rem; }
  .party-qr { width: 5rem; height: 5rem; }
  .party-note { top: calc(max(0.5rem, env(safe-area-inset-top, 0px)) + 3rem); }
}
@keyframes party-up { from { transform: translateY(1.5rem); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes party-in { from { transform: translateX(1.5rem); opacity: 0; } to { transform: none; opacity: 1; } }

/* A TV: a panel down the right, read from the sofa. The code and the QR code are its invite (it
   has nothing to paste a link into), both big enough to read and scan across the room. Focus
   starts on Close, so OK never leaves the party by accident. */
html.tv #party-panel { top: 0; right: 0; bottom: 0; left: auto; width: min(26rem, 44%); max-height: none; border-radius: 0; gap: 1.2rem;
  padding: 2rem 2rem 2rem 1.75rem; background: color-mix(in srgb, var(--surface) 97%, transparent); box-shadow: -1rem 0 3rem rgba(0, 0, 0, 0.6); animation: party-in 0.2s var(--ease-out, ease); }
html.tv #party-panel::before { content: none; }
/* It scrolls as focus moves through it, so a scrollbar is only in the way. */
html.tv #party-panel { scrollbar-width: none; }
html.tv #party-panel::-webkit-scrollbar { display: none; }
/* Down goes through the actions one at a time, Leave last: a row would send the remote from Close
   (top right) straight to its rightmost button. */
html.tv #party-panel .player-menu-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
html.tv #party-panel .player-menu-actions > button { width: 100%; }
html.tv .party-code { font-size: 1.75rem; }
html.tv .party-qr { width: 7rem; height: 7rem; }
html.tv .party-close:is(:focus, :focus-visible) { transform: none; }
html.tv .party-note { font-size: 1rem; }

@media (prefers-reduced-motion: reduce) {
  #party-panel, .party-note, .party-dot, .party-avatar, .party-card-who::before { animation: none !important; }
  .party-choice, .party-card-art { transition: none !important; }
}

/* ---------- The party's link and code (partylink.js, auth.js) ---------- */
.auth:has(.party-card) { max-width: 30rem; }
/* A link to a party that has ended has nothing to fill the form with: no empty box. */
#auth-form:empty { display: none; }
.section.party-landing { max-width: 34rem; margin: 0 auto; padding-top: clamp(1.5rem, 6vh, 4rem); display: grid; gap: 1.5rem; }
.party-card { display: grid; grid-template-columns: 6.5rem minmax(0, 1fr); gap: 1.1rem; align-items: center; padding: 1rem; margin-bottom: 1.25rem;
  border-radius: var(--radius-lg); background: color-mix(in srgb, var(--text) 5%, var(--surface)); border: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.party-landing .party-card { margin-bottom: 0; }
.party-card-frame { aspect-ratio: 2 / 3; border-radius: var(--media-radius); overflow: hidden; background: color-mix(in srgb, var(--text) 8%, var(--surface)); box-shadow: 0 12px 24px -14px rgb(0 0 0 / 0.8); }
.party-card-art { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity 0.5s var(--ease-out); }
.party-card-art.loaded { opacity: 1; }
.party-card-text { display: grid; gap: 0.2rem; min-width: 0; }
.party-card-text h2 { margin: 0; font-size: 1.35rem; line-height: 1.25; overflow-wrap: anywhere; }
.party-card-text p { margin: 0; }
.party-card-kicker { color: var(--accent); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; }
.party-card-who { margin-top: 0.4rem !important; font-size: 0.88rem; color: var(--muted); display: flex; align-items: center; gap: 0.45rem; }
.party-card-who::before { content: ""; flex: none; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--ok-dot); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok-dot) 22%, transparent); animation: party-live 2s ease-in-out infinite; }
@keyframes party-live { 50% { box-shadow: 0 0 0 6px rgb(95 208 138 / 0); } }
.party-choices { display: grid; gap: 0.7rem; }
.party-choice { display: grid; grid-template-columns: 2.9rem minmax(0, 1fr); gap: 0.95rem; align-items: center; width: 100%; padding: 1rem 1.1rem; text-align: left; text-decoration: none; white-space: normal;
  border-radius: var(--radius-lg); border: 1px solid color-mix(in srgb, var(--line) 70%, transparent); background: color-mix(in srgb, var(--text) 4%, transparent); color: var(--text); cursor: pointer; font: inherit;
  transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.3s var(--ease-out), box-shadow 0.3s var(--ease-out); }
.party-choice:hover { border-color: color-mix(in srgb, var(--accent) 70%, transparent); background: color-mix(in srgb, var(--accent) 9%, transparent); transform: translateY(-2px); box-shadow: 0 12px 24px -16px rgb(0 0 0 / 0.8); }
.party-choice:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.party-choice-icon { width: 2.9rem; height: 2.9rem; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.party-choice-icon svg { width: 1.45rem; height: 1.45rem; }
.party-choice-text { display: grid; gap: 0.15rem; }
.party-choice-text strong { font-size: 1rem; font-weight: 600; }
.party-choice-text span { font-size: 0.86rem; color: var(--muted); line-height: 1.45; }
.party-ways { margin: 0 0 1rem; color: var(--muted); }
.party-guest { margin-bottom: 1rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.party-guest .primary { width: 100%; }
/* The code, typed as it's shown on the screen that's playing. */
.party-code-input { font-family: var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; }
.party-code-input::placeholder { letter-spacing: 0.08em; }

/* ---------- The phone companion (companion.js) ---------- */
.remote { display: flex; flex-direction: column; gap: 0.9rem; width: min(36rem, 100%); min-height: 100dvh; margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top, 0px)) var(--gutter) max(1rem, env(safe-area-inset-bottom, 0px)); }
.remote-head { display: flex; gap: 0.9rem; align-items: flex-start; }
.remote-poster { flex: none; width: 4.25rem; border-radius: var(--radius); overflow: hidden; }
.remote-poster .art { aspect-ratio: 2 / 3; }
.remote-title { flex: 1; min-width: 0; }
.remote-title h1 { margin: 0; font: var(--title-weight) 1.35rem/1.2 var(--font-display); }
.remote-title p { margin: 0.2rem 0 0; }
.remote-title .party-state { margin-top: 0.35rem; }
.remote-leave { flex: none; }
/* Who's here, in a row: the same people as the party's panel on the screens. */
.remote .party-people { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; }
.remote .party-avatar { width: 2rem; height: 2rem; font-size: 0.85rem; }
.remote-controls { display: flex; justify-content: center; align-items: center; gap: 1.5rem; }
.remote-ctl { display: grid; place-items: center; width: 3.5rem; height: 3.5rem; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--text); cursor: pointer; }
.remote-ctl.is-main { width: 4.5rem; height: 4.5rem; background: var(--text); color: var(--bg); border-color: var(--text); }
.remote-ctl svg { width: 1.7rem; height: 1.7rem; fill: currentColor; }
.remote-ctl svg text { font: 700 6.5px var(--font-body); fill: currentColor; }
.remote-ctl:active { transform: scale(0.94); }
.remote-time { margin: -0.4rem 0 0; text-align: center; font-variant-numeric: tabular-nums; }
.remote-status { margin: -0.6rem 0 0; text-align: center; }
.remote-status:empty { display: none; }
.remote-log { flex: 1; min-height: 8rem; max-height: none; padding: 0.75rem; border: 1px solid var(--line); border-radius: var(--radius-lg); font-size: 0.95rem; }
.remote .talk-reactions { justify-content: space-between; }
/* A reaction sent from the phone rises briefly from its button (companion.js); the picture it
   floats up on is on the other screens. With motion reduced it only fades. */
.remote .talk-reaction { position: relative; }
.react-float { position: absolute; left: 50%; bottom: 55%; transform: translateX(-50%); font-size: 1.5rem; line-height: 1; pointer-events: none; animation: react-rise 0.9s ease-out forwards; }
@keyframes react-rise { from { opacity: 1; transform: translate(-50%, 0) scale(0.9); } to { opacity: 0; transform: translate(-50%, -2.75rem) scale(1.15); } }
@keyframes react-fade { 0%, 50% { opacity: 1; transform: translateX(-50%); } to { opacity: 0; transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .react-float { animation-name: react-fade; } }
.remote-foot { margin: 0; color: var(--muted); font-size: 0.85rem; }
.remote-rate { padding: 0.75rem 1rem; border: 1px solid var(--line); border-radius: var(--radius-lg); }
.remote-rate summary { min-height: 2.25rem; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
.remote-rate[open] summary { margin-bottom: 0.6rem; }
