/* ============================================================
   wuld.ink - theater-mode video overlay (K24k)
   Full-viewport modal containing a 16:9 youtube-nocookie iframe.
   Triggered by any element with [data-theater-video-id].
   Coordinates with ambient-player via custom-event channel
   (wuld:overlay:open / wuld:overlay:close).

   Markup: a single .theater-mode root is injected lazily at
   first open; JS handles construction. CSS here is the
   declarative skeleton.
   ============================================================ */

/* Trigger chip style - usable by any surface that surfaces a
   [ Watch video ] affordance pointing at theater-mode. */
.theater-trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);

  background-color: transparent;
  border: var(--bw-base) solid var(--c-border);
  color: var(--c-fg);

  font-family: var(--font-mono);
  font-size: var(--t-xs, 0.75rem);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-decoration: none;
  text-transform: uppercase;
  line-height: 1;

  cursor: pointer;
  transition:
    color var(--t-fast, 120ms) var(--ease, ease),
    background-color var(--t-fast, 120ms) var(--ease, ease),
    border-color var(--t-fast, 120ms) var(--ease, ease);
}

.theater-trigger::before {
  content: "\25B6";  /* black right-pointing triangle (play glyph) */
  display: inline-block;
  font-size: 0.7em;
  color: var(--c-accent);
}

.theater-trigger:hover,
.theater-trigger:focus-visible {
  background-color: var(--c-accent);
  border-color: var(--c-accent);
  color: var(--c-bg);
}

.theater-trigger:hover::before,
.theater-trigger:focus-visible::before {
  color: var(--c-bg);
}

.theater-trigger:focus-visible {
  outline: var(--bw-base) solid var(--c-focus);
  outline-offset: 2px;
}

/* ---------- Overlay root ---------- */

.theater-mode {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(10, 10, 10, 0.95);
  opacity: 0;
  /* K24m bug fix: backdrop must not intercept clicks when closed.
     Without pointer-events:none on baseline, the fixed/inset:0/z:1000
     overlay continues catching every click on the page after close
     (only opacity transitions; element stays in DOM). */
  pointer-events: none;
  transition: opacity 200ms var(--ease, ease);
}

.theater-mode[data-open="true"] {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- Iframe container ---------- */

.theater-frame-wrap {
  position: relative;
  width: min(90vw, calc((90vh - 4rem) * 16 / 9));
  aspect-ratio: 16 / 9;
  background-color: #000;
  border: var(--bw-base) solid var(--c-fg);
}

.theater-frame-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* ---------- Close affordances ---------- */

.theater-close {
  position: absolute;
  top: -2.25rem;
  right: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  width: 2rem;
  height: 2rem;
  padding: 0;

  background-color: transparent;
  border: var(--bw-thin) solid var(--c-fg-muted);
  color: var(--c-fg);

  font-family: var(--font-mono);
  font-size: var(--t-sm, 0.875rem);
  font-weight: 500;
  line-height: 1;
  cursor: pointer;

  transition:
    color var(--t-fast, 120ms) var(--ease, ease),
    background-color var(--t-fast, 120ms) var(--ease, ease),
    border-color var(--t-fast, 120ms) var(--ease, ease);
}

.theater-close:hover,
.theater-close:focus-visible {
  background-color: var(--c-accent);
  border-color: var(--c-accent);
  color: var(--c-bg);
}

.theater-close:focus-visible {
  outline: var(--bw-base) solid var(--c-focus);
  outline-offset: 2px;
}

/* ---------- Body lock when overlay open ---------- */

body.theater-open {
  overflow: hidden;
}

/* ---------- Reduced-motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .theater-mode { transition: none; }
  .theater-trigger { transition: none; }
  .theater-close { transition: none; }
}

/* ---------- Mobile ---------- */

@media (max-width: 480px) {
  .theater-frame-wrap {
    width: 95vw;
  }
  .theater-close {
    top: -2.5rem;
    width: 2.25rem;
    height: 2.25rem;
  }
  .theater-trigger {
    padding: var(--s-2);
    font-size: 0.6875rem;
  }
}
