/* =========================================================
   Watch Party — tungsten cinema theme
   Palette: warm near-black room, projector-bulb amber,
   parchment ink. Display face: Fraunces. UI face: Outfit.
   ========================================================= */

:root {
  --bg: #131010;
  --bg-deep: #0d0b0a;
  --surface: #1d1815;
  --surface-2: #262019;
  --line: #38302a;
  --ink: #f2e9dd;
  --ink-dim: #a5988a;
  --amber: #e9a13b;
  --amber-hot: #f5b95e;
  --amber-soft: rgba(233, 161, 59, 0.14);
  --red: #e06a55;
  --green: #7fb87a;
  --radius: 14px;
  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-weight: 300;
  letter-spacing: 0.01em;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(233, 161, 59, 0.07), transparent 60%),
    var(--bg);
}

.hidden { display: none !important; }

h1, h2 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.005em;
  margin: 0;
}

.hint { color: var(--ink-dim); font-size: 0.82rem; line-height: 1.45; margin: 0.4rem 0 0; }
.error { color: var(--red); font-size: 0.85rem; margin: 0.6rem 0 0; }

.icon { width: 1.15em; height: 1.15em; vertical-align: -0.22em; }

/* ---------------- buttons & inputs ---------------- */
.btn {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { background: #2e2620; border-color: #4a3f34; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #241a0c;
}
.btn.primary:hover { background: var(--amber-hot); border-color: var(--amber-hot); }
.btn.ghost { background: transparent; }
.btn.big { padding: 0.8rem 1.2rem; font-size: 1rem; width: 100%; }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
  border-radius: 6px;
}

input[type="text"], input[type="url"], input[type="password"], input[type="search"] {
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  padding: 0.6rem 0.75rem;
}
input::placeholder { color: #6d6156; }
input:focus { outline: none; border-color: var(--amber); }

#room-input { text-transform: uppercase; letter-spacing: 0.12em; font-weight: 500; }

.field { display: block; margin-bottom: 0.9rem; }
.field > span {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  margin-bottom: 0.35rem;
}
.field-row { display: flex; gap: 0.5rem; }
.field-row input { flex: 1; }
.field-row .btn { white-space: nowrap; }

input[type="range"] {
  width: 100%;
  accent-color: var(--amber);
  cursor: pointer;
}

.check { display: flex; align-items: center; gap: 0.45rem; font-size: 0.85rem; color: var(--ink); }
.check input { accent-color: var(--amber); }

/* =========================================================
   Join screen — the ticket
   ========================================================= */
#join-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.ticket {
  position: relative;
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ticket-head {
  padding: 2rem 2rem 1.6rem;
  background:
    radial-gradient(340px 160px at 50% -30%, rgba(233, 161, 59, 0.22), transparent 70%),
    var(--surface);
  text-align: center;
}

.ticket-eyebrow {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.34em;
  color: var(--amber);
  border: 1px solid rgba(233, 161, 59, 0.4);
  border-radius: 999px;
  padding: 0.3rem 0.85rem 0.26rem;
  margin-bottom: 1rem;
}

.ticket-title { font-size: 2.3rem; line-height: 1.05; }
.ticket-sub { color: var(--ink-dim); font-size: 0.92rem; line-height: 1.5; margin: 0.7rem 0 0; }

/* perforated tear line with side notches */
.ticket-tear {
  position: relative;
  height: 0;
  border-top: 2px dashed #43392f;
  margin: 0 1.1rem;
}
.ticket-tear::before, .ticket-tear::after {
  content: "";
  position: absolute;
  top: -11px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--line);
}
.ticket-tear::before { left: -2.2rem; }
.ticket-tear::after { right: -2.2rem; }

.ticket-body { padding: 1.6rem 2rem 2rem; }
.ticket-body .hint { text-align: center; margin-top: 0.9rem; }

/* =========================================================
   Room screen
   ========================================================= */
#room-screen {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#topbar {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg-deep);
  flex-wrap: wrap;
}

.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--amber);
  margin-right: 0.3rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--ink);
  cursor: default;
}
button.chip { cursor: pointer; }
button.chip:hover { border-color: var(--amber); }
.chip-label { color: var(--ink-dim); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.12em; }
.chip-code { font-weight: 600; letter-spacing: 0.14em; }

.chip.status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-dim);
}
.chip.status.waiting .dot { background: var(--amber); animation: pulse 1.6s ease-in-out infinite; }
.chip.status.on .dot { background: var(--green); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.topbar-actions { margin-left: auto; display: flex; gap: 0.5rem; }

#stage {
  flex: 1;
  display: flex;
  min-height: 0;
  gap: 0.9rem;
  padding: 0.9rem;
}

/* ---------------- player ---------------- */
#player-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
}

#movie { width: 100%; height: 100%; object-fit: contain; background: #000; }

#movie-titlebar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 3;
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  padding: 0.7rem 1rem 1.6rem;
  background: linear-gradient(rgba(0, 0, 0, 0.75), transparent);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
}
#player-wrap:hover #movie-titlebar { opacity: 1; }
.now-showing {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  color: var(--amber);
}
#movie-title { font-family: var(--font-display); font-size: 1.05rem; }

#empty-state {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  text-align: center;
  padding: 1rem;
  background:
    radial-gradient(500px 260px at 50% 30%, rgba(233, 161, 59, 0.1), transparent 70%),
    var(--bg-deep);
}
#empty-state p { margin: 0; font-family: var(--font-display); font-size: 1.25rem; }
.empty-mark {
  width: 64px; height: 44px;
  border: 2px solid var(--amber);
  border-radius: 8px;
  position: relative;
  opacity: 0.9;
}
.empty-mark::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-40%, -50%);
  border-left: 14px solid var(--amber);
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
}

#autoplay-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  background: rgba(13, 11, 10, 0.82);
  backdrop-filter: blur(3px);
  text-align: center;
  padding: 1rem;
}
#autoplay-overlay .btn { width: auto; }

/* ---------------- side rail ---------------- */
#side {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-height: 0;
  overflow-y: auto;
}

.cam {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg-deep);
  aspect-ratio: 4 / 3;
  flex-shrink: 0;
}
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam.local { aspect-ratio: 16 / 10; }
.cam.local video { transform: scaleX(-1); } /* mirror your own preview */
.cam.local.cam-off video { visibility: hidden; }

.cam-label {
  position: absolute;
  left: 0.55rem;
  bottom: 0.5rem;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  background: rgba(13, 11, 10, 0.72);
  border: 1px solid rgba(242, 233, 221, 0.12);
  border-radius: 999px;
  padding: 0.18rem 0.6rem;
}

.cam-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-dim);
  font-size: 0.85rem;
  padding: 1rem;
  text-align: center;
}

#call-controls {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.round-btn {
  position: relative;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, border-color 0.15s;
}
.round-btn:hover { border-color: var(--amber); }
.round-btn .icon { width: 20px; height: 20px; }
.round-btn .slash { display: none; position: absolute; inset: 0; margin: auto; color: var(--red); }
.round-btn.off { background: rgba(224, 106, 85, 0.15); border-color: var(--red); }
.round-btn.off .slash { display: block; }

#call-status { font-size: 0.78rem; color: var(--ink-dim); line-height: 1.35; }

.vol {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.85rem 0.85rem;
}
.vol label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--ink);
  margin-bottom: 0.45rem;
}
.vol label .icon { color: var(--amber); }

.side-hint { margin-top: auto; }

/* =========================================================
   Modal — Jellyfin picker
   ========================================================= */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(9, 7, 6, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-card {
  position: relative;
  width: min(860px, 100%);
  max-height: min(88vh, 780px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1.6rem 1.8rem 1.8rem;
}
#jf-login { max-width: 400px; margin: 0 auto; }
#jf-login h2 { text-align: center; margin-bottom: 0.4rem; }
#jf-login .hint { text-align: center; margin-bottom: 1.2rem; }

.modal-close {
  position: absolute;
  top: 0.8rem; right: 0.9rem;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.9rem;
}
.modal-close:hover { border-color: var(--amber); }

.library-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.9rem; padding-right: 2.4rem; }
.library-tools { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.library-tools input[type="search"] { flex: 1; min-width: 200px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 0.9rem;
}

.card {
  border: 1px solid var(--line);
  background: var(--bg-deep);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  color: var(--ink);
  font-family: var(--font-ui);
  transition: transform 0.12s, border-color 0.12s;
}
.card:hover { transform: translateY(-2px); border-color: var(--amber); }
.card .poster {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
}
.card .poster.missing {
  display: grid;
  place-items: center;
  color: var(--ink-dim);
  font-size: 0.72rem;
  padding: 0.4rem;
  text-align: center;
}
.card .meta { padding: 0.5rem 0.6rem 0.6rem; }
.card .title { font-size: 0.82rem; font-weight: 500; line-height: 1.25; display: block; }
.card .sub { font-size: 0.72rem; color: var(--ink-dim); }

/* =========================================================
   Toasts
   ========================================================= */
#toasts {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--amber);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.5rem 1.1rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
  max-width: min(520px, 90vw);
  text-align: center;
}
.toast.in { opacity: 1; transform: translateY(0); }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 820px) {
  #stage { flex-direction: column; overflow-y: auto; }
  #player-wrap { flex: none; aspect-ratio: 16 / 9; }
  #side {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .cam.remote { width: calc(58% - 0.35rem); }
  .cam.local { width: calc(42% - 0.35rem); aspect-ratio: 4/3; }
  #call-controls { width: 100%; }
  .vol { flex: 1 1 240px; }
  .side-hint { display: none; }
  .brand { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
