/* ==========================================================================
   Section 6 — Green Open-Air Cinema Modal Dialog
   Implements light-dismiss, overscroll containment, and top-layer entry/exit
   ========================================================================== */

/* Full-viewport screening room */
dialog.film-dialog {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  inset: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  scrollbar-gutter: stable;
  background-color: var(--bg);
  background-image: var(--bg-tex);
  background-size: 320px 320px;
  color: var(--ink);
  box-shadow: 0 28px 80px rgba(7, 26, 17, 0.28);
  overflow-x: hidden;
  overflow-y: auto;
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: 0.28s;
  transition-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
  transition-behavior: allow-discrete;
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) dialog.film-dialog {
  background-color: #0b1e14;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.6);
}

@media (prefers-reduced-motion: no-preference) {
  dialog.film-dialog {
    transform: translateY(16px);
  }
}

dialog.film-dialog:modal {
  overscroll-behavior: contain;
}

dialog.film-dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background-color: rgba(7, 19, 13, 0);
  backdrop-filter: blur(0px);
  transition-property: background-color, backdrop-filter, display, overlay;
  transition-duration: 0.28s;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

:is(dialog.film-dialog[open]):where(:not([data-closing])) {
  opacity: 1;
}

:is(dialog.film-dialog[open]):where(:not([data-closing])) {
  @starting-style {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  :is(dialog.film-dialog[open]):where(:not([data-closing])) {
    transform: translateY(0);
  }

  :is(dialog.film-dialog[open]):where(:not([data-closing])) {
    @starting-style {
      transform: translateY(16px);
    }
  }
}

:is(dialog.film-dialog[open]):where(:not([data-closing]))::backdrop {
  background-color: rgba(7, 19, 13, 0.78);
  backdrop-filter: blur(14px) saturate(0.9);
}

:is(dialog.film-dialog[open]):where(:not([data-closing]))::backdrop {
  @starting-style {
    background-color: rgba(7, 19, 13, 0);
    backdrop-filter: blur(0px);
  }
}

@media (prefers-reduced-motion: reduce) {
  dialog.film-dialog,
  dialog.film-dialog::backdrop {
    transition-duration: 0.01s;
  }
}

.dialog-shell {
  max-width: 1440px;
  margin: 0 auto;
  min-height: 100%;
  padding: 0 clamp(16px, 3vw, 48px) clamp(24px, 3vw, 40px);
  display: flex;
  flex-direction: column;
  gap: 28px;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

/* --- Dialog Top Utility Bar --- */
.dialog-topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 calc(-1 * clamp(16px, 3vw, 48px));
  padding: 12px clamp(16px, 3vw, 48px);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-meta-line {
  font-size: 12px;
  color: var(--green);
  text-transform: uppercase;
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dialog-btn {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(15, 42, 30, 0.06);
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) .dialog-btn {
  border-color: rgba(180, 224, 106, 0.25);
  background: rgba(15, 42, 30, 0.8);
  color: var(--on-forest);
}

.dialog-btn:hover {
  border-color: var(--green);
  color: var(--green);
}

.dialog-btn.is-copied {
  background: var(--lime);
  color: var(--on-lime);
  border-color: var(--lime);
}

.dialog-close {
  width: 44px;
  padding: 0;
}

/* --- Clean Adaptive Video Stage (ZERO dither/overlays on video!) --- */
.player-stage {
  position: relative;
  margin-inline: auto;
  width: min(1280px, 100%, calc((100dvh - 190px) * 16 / 9));
  background: #050f0a;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(180, 224, 106, 0.16);
  display: flex;
  flex-direction: column;
}

.player-video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #050f0a;
}

.player-stage.is-vertical {
  width: fit-content;
  max-width: 100%;
}

.player-stage.is-vertical .player-video-wrap {
  width: auto;
  height: min(calc(100dvh - 200px), 820px);
  max-width: 100%;
  aspect-ratio: 9 / 16;
  margin-inline: auto;
}

.player-video-wrap img.player-poster,
.player-video-wrap video,
.player-video-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  object-fit: cover;
  background: #050f0a;
}

.player-video-wrap video {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.player-video-wrap video.is-ready {
  opacity: 1;
}

/* Custom Green Cinema Controls Bar */
.player-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(15, 42, 30, 0.94);
  border-top: 1px solid rgba(180, 224, 106, 0.16);
}

.player-controls[hidden] {
  display: none;
}

.ctrl-btn {
  min-width: 36px;
  min-height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--on-forest);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ctrl-btn.ctrl-play {
  background: var(--lime);
  color: var(--on-lime);
}

.ctrl-btn:hover {
  opacity: 0.88;
}

.ctrl-seek {
  flex: 1 1 auto;
  min-width: 60px;
  height: 6px;
  accent-color: var(--lime);
  cursor: pointer;
}

.ctrl-time {
  font-size: 11px;
  color: rgba(232, 245, 212, 0.85);
  white-space: nowrap;
}

/* --- Two-Column Film Metadata & Toolchain --- */
.dialog-info-grid {
  width: min(1280px, 100%);
  margin-inline: auto;
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 28px 48px;
  align-items: start;
  padding-top: 4px;
}

.dialog-title {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(30px, 3.8vw, 52px);
  line-height: 1.12;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.dialog-summary {
  margin: 0;
  font-size: 15px;
  line-height: 1.75;
  color: var(--muted);
  max-width: 38em;
}

.toolchain-box {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.toolchain-heading {
  margin: 0 0 12px;
  font-size: 11px;
  color: var(--green);
}

.toolchain-list {
  margin: 0;
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px 16px;
  font-size: 13px;
}

.toolchain-list dt {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  align-self: center;
}

.toolchain-list dd {
  margin: 0;
  color: var(--ink);
}

/* --- Optional BEHIND THE FRAMES Horizontal Stills Strip --- */
.stills-section {
  width: min(1280px, 100%);
  margin-inline: auto;
  border-top: 1px solid var(--line);
  padding-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stills-section[hidden] {
  display: none;
}

.stills-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stills-heading {
  margin: 0;
  font-size: 12px;
  color: var(--green);
}

.stills-nav {
  display: flex;
  gap: 8px;
}

.stills-arrow {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 15px;
  transition: border-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.stills-arrow:hover:not(:disabled) {
  border-color: var(--green);
  color: var(--green);
}

.stills-arrow:disabled {
  opacity: 0.3;
  cursor: default;
}

.stills-track {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scroll-behavior: smooth;
  scrollbar-width: none;
  cursor: grab;
  -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 64px), transparent);
  mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 64px), transparent);
}

.stills-track::-webkit-scrollbar {
  display: none;
}

.stills-track.is-dragging {
  cursor: grabbing;
  scroll-behavior: auto;
  scroll-snap-type: none;
}

.still-item {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: zoom-in;
  text-align: left;
  scroll-snap-align: start;
}

.still-item img {
  height: 240px;
  width: auto;
  max-width: none;
  border-radius: 6px;
  background: var(--card);
  box-shadow: 0 0 0 1px var(--hair);
  transition: box-shadow 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

.still-item:hover img,
.still-item:focus-visible img {
  box-shadow: 0 0 0 2px var(--lime);
}

.still-caption {
  font-size: 12px;
}

/* Character-sheet lightbox (inside the dialog's top layer) */
.still-lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
  gap: 8px;
  padding: 56px 16px 24px;
  background: rgba(5, 14, 9, 0.94);
  backdrop-filter: blur(6px);
}
.still-lightbox[hidden] {
  display: none;
}
.lightbox-figure {
  margin: 0;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.lightbox-figure img {
  max-width: 100%;
  max-height: calc(100% - 32px);
  object-fit: contain;
  border-radius: 6px;
}
.lightbox-figure figcaption {
  font-size: 13px;
  color: rgba(232, 245, 212, 0.8);
  white-space: pre;
}
.lightbox-arrow,
.lightbox-close {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(180, 224, 106, 0.3);
  background: rgba(15, 42, 30, 0.7);
  color: #e8f5d4;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
}
.lightbox-arrow:hover,
.lightbox-close:hover {
  border-color: var(--lime);
  color: var(--lime);
}
.lightbox-close {
  position: absolute;
  top: 12px;
  right: 16px;
}
@media (max-width: 760px) {
  .still-lightbox {
    grid-template-columns: 44px 1fr 44px;
    padding: 56px 4px 16px;
  }
  .still-item img {
    height: 170px;
  }
}

/* --- Bottom Prev / Next Bar --- */
.dialog-nav-bar {
  width: min(1280px, 100%);
  margin: auto auto 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.dialog-nav-hint {
  font-size: 11px;
  color: var(--muted);
}

.dialog-nav-btn {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.dialog-nav-btn:hover:not(:disabled) {
  border-color: var(--green);
  color: var(--green);
}

.dialog-nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

@media (max-width: 760px) {
  .player-stage {
    width: 100%;
  }

  .player-stage.is-vertical .player-video-wrap {
    height: min(58dvh, 520px);
  }

  .dialog-info-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .dialog-nav-hint {
    display: none;
  }

  .still-item {
    height: 140px;
  }
}

/* SVG elements ignore the HTML [hidden] UA rule in Chrome — hide explicitly */
.player-controls svg[hidden],
.dialog-shell svg[hidden] {
  display: none;
}
