/* Portrait hooks: local 3:4 teaser with blurred sides; full film opens at 9:16.
   Home and gallery previews retain their own styles and playback behavior. */
.case-study-hook .case-portrait-hook {
  --portrait-poster: url('/assets/img/fkf-rogale-original-720.webp');
  display: grid;
  place-items: center;
  isolation: isolate;
  aspect-ratio: 16 / 9;
  background: #070707;
}

/* One static poster supplies the wide blurred sides: never a second video. */
.case-portrait-hook::before {
  content: '';
  position: absolute;
  z-index: 0;
  inset: -6%;
  background: #0a0a0a var(--portrait-poster) center / cover no-repeat;
  filter: blur(clamp(24px, 3.5vw, 52px)) brightness(.58) saturate(.86);
  transform: scale(1.035);
  pointer-events: none;
}

.case-portrait-hook::after {
  content: '';
  position: absolute;
  z-index: 1;
  inset: 0;
  background: linear-gradient(90deg, rgba(0,0,0,.32), transparent 24%, transparent 76%, rgba(0,0,0,.32));
  pointer-events: none;
}

.case-portrait-hook .case-portrait-back[hidden],
.case-portrait-hook .case-portrait-final-player[hidden] { display: none !important; }

.case-portrait-stage,
.case-portrait-final-player {
  position: relative;
  z-index: 2;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: #080808;
  box-shadow: 0 0 32px rgba(0,0,0,.25);
}

.case-portrait-poster,
.case-portrait-front {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
}

/* The poster stays visible until an actual video frame is available. */
.case-portrait-front {
  opacity: 0;
  pointer-events: none;
  transition: opacity .24s ease;
}
.case-portrait-hook.is-portrait-playing .case-portrait-front { opacity: 1; }

/* Future player: preserve the same 3:4 framing but do not crop its controls. */
.case-portrait-hook[data-portrait-mode='player'] .case-portrait-front {
  opacity: 1;
  pointer-events: auto;
  object-fit: contain;
}
.case-portrait-final-player .case-video-panel,
.case-portrait-final-player iframe {
  width: 100%;
  height: 100%;
}

@media (max-width: 640px) {
  .case-study-hook .case-portrait-hook { aspect-ratio: 4 / 5; }
  .case-portrait-hook::before { filter: blur(28px) brightness(.56) saturate(.86); }
  .case-portrait-stage, .case-portrait-final-player { height: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .case-portrait-front { transition: none; }
}

/* Play sits above the lightweight local teaser. */
.case-portrait-trigger .case-video-play { z-index: 3; }

/* The portrait film reuses the shared modal engine; other dialogs keep their styles. */
.modal-overlay:has(> .portrait-film-modal:not([hidden])) {
  --portrait-room: calc(100svh - 116px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  padding: calc(16px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
  background: rgba(0, 0, 0, .95);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  overscroll-behavior: contain;
}
.modal-content.portrait-film-modal {
  display: grid;
  gap: 8px;
  width: min(520px, 100%, max(200px, calc(var(--portrait-room, 75svh) * 9 / 16)));
  max-height: none;
  padding: 0;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  text-align: center;
  transform: translateY(6px);
}
.portrait-film-modal[hidden] { display: none; }
.portrait-film-toolbar { display: flex; justify-content: flex-end; height: 40px; }
.portrait-film-close {
  display: grid; place-items: center;
  width: 40px; height: 40px; padding: 8px;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 50%;
  background: rgba(255, 255, 255, .035);
  color: var(--text, #fff); cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease;
}
.portrait-film-close svg { width: 22px; height: 22px; }
.portrait-film-close:hover { color: var(--brand); border-color: var(--brand); }
.portrait-film-close:focus-visible, .portrait-film-external:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 4px;
}
.portrait-film-frame {
  position: relative;
  width: 100%; aspect-ratio: 9 / 16;
  overflow: hidden;
  border-radius: 0;
  background: #000;
  box-shadow: none;
}
.portrait-film-frame iframe { display: block; width: 100%; height: 100%; border: 0; }
.portrait-film-external {
  justify-self: center;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 28px;
  color: var(--text-muted, #b8c0cc);
  font-size: .75rem; line-height: 1.4;
  text-decoration: none;
}
.portrait-film-external:hover { color: var(--brand); }
.portrait-film-error { margin: 0; color: var(--text-muted); font-size: .8rem; }
/* Very short landscape windows may scroll the overlay while keeping controls usable. */
@media (max-height: 480px) {
  .modal-overlay:has(> .portrait-film-modal:not([hidden])) { align-items: start; }
}
@media (prefers-reduced-motion: reduce) {
  .modal-content.portrait-film-modal { transition: none; transform: none; }
}

/* Compact hook: fill the preview frame; crop only the local teaser, never embeds. */
@media (max-width: 640px) {
  .case-portrait-hook .case-portrait-stage {
    width: 100%; height: 100%; aspect-ratio: auto;
  }
  .case-portrait-hook .case-portrait-front,
  .case-portrait-hook .case-portrait-poster { object-fit: cover; }
}

/* Facebook SDK owns the embed height: video + actual post + counters. */
.modal-content.portrait-film-modal--social {
  width: min(400px, 100%, max(240px, calc((var(--portrait-room, 75svh) - 140px) * 9 / 16)));
}
.modal-overlay:has(> .portrait-film-modal--social:not([hidden])) {
  align-items: start;
  overflow-y: auto;
}
.portrait-film-modal--social .portrait-film-frame {
  aspect-ratio: auto;
  height: auto;
  min-height: 0;
  padding: 0;
  overflow: visible;
  background: transparent;
}
.portrait-film-modal--social .portrait-film-frame iframe {
  display: block;
  position: static;
  border: 0;
  /* Inline pixel dimensions supplied by Facebook take precedence. */
}

/* Instagram provides the post height via MEASURE; never crop the social UI. */
.modal-content.portrait-film-modal--instagram {
  width: min(400px, 100%);
}
