/*
 * NextVision Image Variations - frontend styles.
 *
 * Design goals:
 *   The widget must read like a native WordPress image block: a big
 *   image, a thin caption beneath it, maybe a discreet strip of
 *   secondary thumbnails. No panel chrome, no coloured walls, no
 *   promotional copy. The slicer and the reactions are the *only*
 *   interactive affordances, and they keep a low profile until the
 *   reader actually engages.
 *
 *   Adaptive aspect ratio:
 *     The original <img> is rendered INLINE (not absolutely positioned)
 *     so the frame inherits the real aspect ratio of the hero image.
 *     Variants sit absolutely on top of that image. This removes the
 *     white gutter bar that a fixed 16:9 stage used to produce on
 *     portrait / square images.
 *
 *   Performance:
 *     - `content-visibility: auto` skips layout/paint work on offscreen
 *       widgets.
 *     - `contain: layout paint` isolates the widget from the rest of
 *       the page so a re-layout inside (e.g. vote click) cannot cascade
 *       into the article / ad container.
 *     - No @import, no web fonts, no external resources in the stylesheet.
 *
 *   Mediavine / ad-stack friendliness:
 *     - No position:fixed elements that could overlap in-content ads.
 *     - No observer attached to `.entry-content` / `.content` selectors
 *       (that's JS territory anyway).
 *     - No transform/filter on ancestors of ad slots (stays contained
 *       inside the widget's own tree).
 *
 *   Everything is scoped to `.nv-iv`.
 */

.nv-iv {
  /* ---- Tokens --------------------------------------------------------
     Hard-coded near-black so the widget is legible on every WordPress
     theme. We intentionally do NOT honour `prefers-color-scheme`: the
     reader's OS being in dark mode must never flip our palette to white
     on a light WordPress site. Sites that actually run a dark theme can
     opt in via `[data-nv-iv-theme="dark"]` (handled further down). */
  --nv-iv-fg: #0b1220;
  --nv-iv-fg-muted: #0b1220;
  --nv-iv-fg-soft: #111827;
  --nv-iv-fg-on-dark: #f8fafc;
  --nv-iv-up: #166534;
  --nv-iv-down: #991b1b;
  --nv-iv-surface: rgba(15, 23, 42, 0.08);
  --nv-iv-surface-strong: rgba(15, 23, 42, 0.14);
  --nv-iv-border: rgba(15, 23, 42, 0.28);
  --nv-iv-border-strong: rgba(15, 23, 42, 0.52);
  --nv-iv-radius: 4px;
  --nv-iv-radius-lg: 10px;
  --nv-iv-transition: 200ms cubic-bezier(0.22, 1, 0.36, 1);

  /* Base image is rendered inline, so the frame inherits the hero's real
     aspect ratio. Varianten sitzen absolut drüber. Eine dezente Skalierung
     (`--nv-iv-zoom`) kaschiert subpixel-Rounding/Linheight-Gaps, die sonst
     unter dem Bild einen weissen Streifen erzeugen können, und stellt
     gleichzeitig sicher, dass Varianten mit leicht abweichendem Aspect
     Ratio den Frame immer lückenlos füllen. */
  --nv-iv-zoom: 1.035;

  /* Slicer position (0..100). Default 75% so readers mostly see the
     original hero and get hinted at the variant on the right. */
  --nv-iv-pos: 75%;

  /* ---- Layout as a figure block -------------------------------------- */
  box-sizing: border-box;
  margin: 2rem 0;
  padding: 0;
  background: transparent;
  color: var(--nv-iv-fg);
  font-family: inherit;
  line-height: 1.5;
  isolation: isolate;
  /* Skip work on offscreen widgets; browsers that don't support this
     simply ignore the declarations. The `contain-intrinsic-size` hint
     gives the engine a size to reserve before the section is painted,
     which prevents layout shift next to ad slots. */
  content-visibility: auto;
  contain-intrinsic-size: 900px 600px;
  contain: layout paint;
}

.nv-iv *,
.nv-iv *::before,
.nv-iv *::after {
  box-sizing: inherit;
}

/* --- Stage ------------------------------------------------------------ */

.nv-iv__stage {
  position: relative;
  margin: 0;
  overflow: hidden;
  border-radius: var(--nv-iv-radius);
  background: transparent;
}

.nv-iv__frame {
  position: relative;
  width: 100%;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  line-height: 0; /* kill inline-img baseline gap */
  background: #0b1220; /* fallback behind the images while loading */
  /* We handle panning ourselves (both horizontal slicing AND vertical page
     scrolling via a scroll emulation in JS). The browser only keeps pinch-
     zoom so two-finger zoom still works over the widget.
     Previously we used `pan-y pinch-zoom`, but once Mobile Safari committed
     the gesture to "vertical scroll" it refused to re-hand it back to the
     slicer until the reader lifted and re-tapped — the user-reported
     "horizontales Slicing ist dann nicht mehr möglich" bug. With
     `pinch-zoom` we keep full authority over single-finger movement and
     decide horizontal-vs-vertical ourselves. */
  touch-action: pinch-zoom;
}

/* Base image is the sizing element. It stays in the normal flow so
   its intrinsic aspect ratio drives the frame height. A tiny zoom via
   `--nv-iv-zoom` hides any subpixel/rounding gap at the bottom of the
   frame and keeps the composition matched with the variants, which sit
   absolutely on top with object-fit: cover. */
.nv-iv__img--base {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  vertical-align: bottom;
  transform: scale(var(--nv-iv-zoom, 1.035));
  transform-origin: center center;
  z-index: 1;
}

.nv-iv__overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  clip-path: inset(0 0 0 var(--nv-iv-pos, 75%));
  transition: clip-path 60ms linear;
  will-change: clip-path;
}

/* While the reader is actively dragging, remove the tiny easing transitions
   so the clip-path and the divider line track the pointer position 1:1.
   Without this the slider looks smooth on desktop but stutters on iOS /
   Android because every pointermove re-triggers the 60ms easing. */
.nv-iv.is-dragging .nv-iv__overlay,
.nv-iv.is-dragging .nv-iv__divider {
  transition: none;
}

.nv-iv__img--variant {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 220ms ease-out;
  display: block;
  transform: scale(var(--nv-iv-zoom, 1.035));
  transform-origin: center center;
}

.nv-iv__img--variant.is-active {
  opacity: 1;
}

.nv-iv__corner {
  position: absolute;
  z-index: 4;
  top: 0.55rem;
  padding: 0.22rem 0.55rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 240ms ease, transform 240ms ease;
  line-height: 1;
}

.nv-iv__corner--left  { left: 0.55rem; }
.nv-iv__corner--right { right: 0.55rem; }

/* Corners appear only while the reader is interacting with the slicer,
   so the "peaceful" first impression matches a normal figure. */
.nv-iv:hover .nv-iv__corner,
.nv-iv:focus-within .nv-iv__corner,
.nv-iv.is-touched .nv-iv__corner {
  opacity: 1;
  transform: translateY(0);
}

/* --- Likes badge (small heart + count, bottom-left) ------------------ */

.nv-iv__likes-badge {
  position: absolute;
  z-index: 4;
  left: 0.55rem;
  bottom: 0.55rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 999px;
  pointer-events: none;
  line-height: 1;
  transition: transform 240ms ease, opacity 240ms ease;
}

.nv-iv__likes-badge svg {
  color: #fca5a5;
}

.nv-iv__likes-badge[data-nv-iv-zero="true"] {
  opacity: 0; /* hide the badge on variants with 0 likes */
  transform: translateY(4px);
}

.nv-iv__likes-badge.is-bumped {
  animation: nv-iv-like-pop 460ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes nv-iv-like-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.22); }
  100% { transform: scale(1); }
}

/* --- Divider + handle ------------------------------------------------ */

.nv-iv__divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--nv-iv-pos, 75%);
  width: 1px;
  background: rgba(255, 255, 255, 0.85);
  transform: translateX(-50%);
  z-index: 3;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.15);
  transition: left 60ms linear, width 200ms ease;
  pointer-events: none;
}

.nv-iv:hover .nv-iv__divider,
.nv-iv.is-touched .nv-iv__divider {
  width: 2px;
}

.nv-iv__handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  color: #0f172a;
  cursor: ew-resize;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.25),
    0 0 0 1px rgba(0, 0, 0, 0.04);
  transition: transform 200ms ease, box-shadow 200ms ease;
  touch-action: none;
}

.nv-iv__handle:hover,
.nv-iv__handle:focus-visible {
  transform: translate(-50%, -50%) scale(1.05);
  outline: none;
  box-shadow:
    0 4px 14px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(0, 0, 0, 0.08);
}

.nv-iv__handle-bar {
  position: relative;
  display: inline-block;
  width: 20px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.nv-iv__handle-bar::before,
.nv-iv__handle-bar::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 7px;
  height: 7px;
  border: 2px solid currentColor;
  border-right: none;
  border-bottom: none;
  transform-origin: center;
}

.nv-iv__handle-bar::before {
  left: -4px;
  transform: translateY(-50%) rotate(-45deg);
}

.nv-iv__handle-bar::after {
  right: -4px;
  transform: translateY(-50%) rotate(135deg);
}

.nv-iv__range {
  position: absolute;
  inset: 0;
  margin: 0;
  z-index: 5;
  cursor: ew-resize;
}

.nv-iv__range-input {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: ew-resize;
  appearance: none;
  background: transparent;
}

.nv-iv__range-input::-webkit-slider-thumb {
  appearance: none;
  width: 80px;
  height: 100%;
}

.nv-iv__range-input::-moz-range-thumb {
  width: 80px;
  height: 100%;
  border: none;
  background: transparent;
}

.screen-reader-text {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Peek hint ("Slide") --------------------------------------------- */

.nv-iv__peek {
  position: absolute;
  z-index: 6;
  top: calc(50% - 50px);
  left: var(--nv-iv-pos, 75%);
  transform: translate(-50%, 0);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.55rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  opacity: 0;
  transition: opacity 260ms ease, left 60ms linear;
}

.nv-iv__peek-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #0f172a;
  animation: nv-iv-peek-dot 1.4s ease-in-out infinite;
}

@keyframes nv-iv-peek-dot {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50%      { transform: scale(1.3); opacity: 1; }
}

.nv-iv.is-peeking .nv-iv__peek {
  opacity: 1;
}

.nv-iv.is-touched .nv-iv__peek {
  opacity: 0;
}

/* --- Caption + reactions ---------------------------------------------- */

.nv-iv .nv-iv__caption,
.nv-iv figcaption.nv-iv__caption {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  margin: 0.65rem 0 0;
  padding: 0;
  font-size: 0.92rem;
  /* `!important` guards against aggressive theme rules like
     `.entry-content figcaption { color: #888; }` that would otherwise
     make this widget's caption unreadable. */
  color: #0b1220 !important;
  line-height: 1.55;
  text-align: left;
}

.nv-iv .nv-iv__caption-text {
  flex: 1 1 16rem;
  min-width: 0;
  font-style: italic;
  color: #0b1220 !important;
  font-weight: 500;
  opacity: 1 !important;
}

.nv-iv__caption-text--empty {
  flex: 1 1 0;
  min-width: 0;
}

.nv-iv__caption-text a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  font-weight: 600;
}

.nv-iv__reactions {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  flex: 0 0 auto;
  padding: 0.15rem;
  background: var(--nv-iv-surface);
  border: 1px solid var(--nv-iv-border);
  border-radius: 999px;
}

.nv-iv .nv-iv__react {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 34px;
  padding: 0.28rem 0.8rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  /* Hardcoded near-black with !important - never inherit from WP theme
     to stay readable on light backgrounds even when the OS reports a
     dark-mode preference AND when themes ship aggressive button resets. */
  color: #000000 !important;
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: color var(--nv-iv-transition),
              background var(--nv-iv-transition);
}

.nv-iv .nv-iv__react:hover,
.nv-iv .nv-iv__react:focus-visible {
  color: #000000 !important;
  background: var(--nv-iv-surface-strong);
  outline: none;
}

.nv-iv__react-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  transition: transform 260ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nv-iv__react-count {
  font-variant-numeric: tabular-nums;
  min-width: 1ch;
  text-align: left;
  transition: transform 260ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nv-iv__react.is-bumped .nv-iv__react-icon {
  transform: scale(1.35) rotate(-6deg);
}

.nv-iv__react--down.is-bumped .nv-iv__react-icon {
  transform: scale(1.35) rotate(6deg);
}

.nv-iv__react.is-bumped .nv-iv__react-count {
  transform: translateY(-2px) scale(1.15);
}

.nv-iv__react[data-voted="true"] {
  cursor: default;
}

.nv-iv .nv-iv__react--up[data-voted="true"] {
  color: var(--nv-iv-up) !important;
  background: rgba(21, 128, 61, 0.12);
}

.nv-iv .nv-iv__react--down[data-voted="true"] {
  color: var(--nv-iv-down) !important;
  background: rgba(185, 28, 28, 0.12);
}

/* Fly-up ripple when a vote is committed. */
.nv-iv__react::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: 0 0 0 0 currentColor;
  opacity: 0;
}

.nv-iv__react.is-bumped::after {
  animation: nv-iv-react-ring 500ms ease-out;
}

@keyframes nv-iv-react-ring {
  0%   { box-shadow: 0 0 0 0  rgba(15, 23, 42, 0.22); opacity: 0.85; }
  100% { box-shadow: 0 0 0 14px rgba(15, 23, 42, 0);    opacity: 0;    }
}

/* --- Variant strip ---------------------------------------------------- */

.nv-iv__strip {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.nv-iv .nv-iv__chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 34px;
  padding: 0.22rem 0.75rem 0.22rem 0.28rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  /* Hardcoded near-black with !important - see .nv-iv__react comment. */
  color: #000000 !important;
  background: transparent;
  border: 1px solid var(--nv-iv-border);
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: color var(--nv-iv-transition),
              background var(--nv-iv-transition),
              border-color var(--nv-iv-transition);
}

.nv-iv .nv-iv__chip:hover,
.nv-iv .nv-iv__chip:focus-visible {
  color: #000000 !important;
  background: var(--nv-iv-surface);
  border-color: var(--nv-iv-border-strong);
  outline: none;
}

.nv-iv .nv-iv__chip.is-active {
  color: #000000 !important;
  background: var(--nv-iv-surface-strong);
  border-color: var(--nv-iv-border-strong);
  font-weight: 800;
}

.nv-iv__chip-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #0b1220 center/cover no-repeat;
  border: 1px solid rgba(15, 23, 42, 0.18);
  flex: 0 0 auto;
}

.nv-iv__chip-label {
  white-space: nowrap;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Dark-site opt-in -----------------------------------------------
   IMPORTANT: we do NOT use `@media (prefers-color-scheme: dark)` anymore.
   That media query fires based on the VISITOR'S OS, not the website's
   theme. A reader with macOS dark-mode on a light WordPress post would
   end up with white text on a white background. Instead we only flip
   the palette when the shortcode or an editor opts in explicitly with
   <figure class="nv-iv" data-nv-iv-theme="dark">. */

.nv-iv[data-nv-iv-theme="dark"],
.nv-iv .is-dark-theme-scope {
  --nv-iv-fg: #f8fafc;
  --nv-iv-fg-muted: #f1f5f9;
  --nv-iv-fg-soft: #e2e8f0;
  --nv-iv-up: #4ade80;
  --nv-iv-down: #f87171;
  --nv-iv-surface: rgba(226, 232, 240, 0.14);
  --nv-iv-surface-strong: rgba(226, 232, 240, 0.22);
  --nv-iv-border: rgba(226, 232, 240, 0.34);
  --nv-iv-border-strong: rgba(226, 232, 240, 0.56);
}

.nv-iv[data-nv-iv-theme="dark"] .nv-iv__caption,
.nv-iv[data-nv-iv-theme="dark"] .nv-iv__caption-text,
.nv-iv[data-nv-iv-theme="dark"] .nv-iv__react,
.nv-iv[data-nv-iv-theme="dark"] .nv-iv__react:hover,
.nv-iv[data-nv-iv-theme="dark"] .nv-iv__react:focus-visible,
.nv-iv[data-nv-iv-theme="dark"] .nv-iv__chip,
.nv-iv[data-nv-iv-theme="dark"] .nv-iv__chip:hover,
.nv-iv[data-nv-iv-theme="dark"] .nv-iv__chip:focus-visible,
.nv-iv[data-nv-iv-theme="dark"] .nv-iv__chip.is-active {
  color: #ffffff;
}

.nv-iv[data-nv-iv-theme="dark"] .nv-iv__chip-thumb {
  border-color: rgba(226, 232, 240, 0.42);
}

.nv-iv[data-nv-iv-theme="dark"] .nv-iv__react--up[data-voted="true"] {
  background: rgba(74, 222, 128, 0.28);
  color: #bbf7d0;
}

.nv-iv[data-nv-iv-theme="dark"] .nv-iv__react--down[data-voted="true"] {
  background: rgba(248, 113, 113, 0.28);
  color: #fecaca;
}

.nv-iv[data-nv-iv-theme="dark"] .nv-iv__handle {
  background: rgba(241, 245, 249, 0.96);
  color: #0f172a;
}

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

@media (prefers-reduced-motion: reduce) {
  .nv-iv__handle,
  .nv-iv__peek-dot,
  .nv-iv__react-icon,
  .nv-iv__react-count,
  .nv-iv__likes-badge {
    animation: none !important;
    transition: none !important;
  }
  .nv-iv__overlay,
  .nv-iv__divider,
  .nv-iv__img--variant,
  .nv-iv__corner,
  .nv-iv__chip,
  .nv-iv__react {
    transition: none;
  }
}

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

@media (max-width: 560px) {
  .nv-iv {
    margin: 1.5rem 0;
    contain-intrinsic-size: 560px 720px;
  }

  .nv-iv__corner {
    font-size: 0.55rem;
    padding: 0.18rem 0.45rem;
  }

  .nv-iv__likes-badge {
    font-size: 0.68rem;
    padding: 0.18rem 0.45rem;
  }

  /* Bigger, thumb-friendly handle on touch devices. */
  .nv-iv__handle {
    width: 56px;
    height: 56px;
  }

  .nv-iv__caption {
    font-size: 0.82rem;
    gap: 0.55rem;
  }

  .nv-iv__caption-text {
    flex-basis: 100%;
  }

  .nv-iv__reactions {
    flex: 0 0 auto;
  }

  .nv-iv__react {
    min-height: 44px;
    padding: 0.4rem 0.8rem;
  }

  /* Variant chips were previously a horizontal scroll-strip that clipped
     all but the first chip on narrow phones — readers reported seeing
     only one variant option. On small viewports we now stack them into
     a proper vertical list so every variant is visible and tappable
     without horizontal scrolling. */
  .nv-iv__strip {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0.4rem;
    overflow: visible;
    margin-right: 0;
    padding-right: 0;
    padding-bottom: 0;
  }

  .nv-iv .nv-iv__chip {
    width: 100%;
    min-height: 48px;
    padding: 0.5rem 0.85rem 0.5rem 0.35rem;
    border-radius: 12px;
    justify-content: flex-start;
    gap: 0.6rem;
  }

  .nv-iv__chip-label {
    max-width: none;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.3;
  }

  .nv-iv__chip-thumb {
    width: 32px;
    height: 32px;
  }
}
