/**
 * Infiniview Wiki — drag-to-reveal Wikipedia → Infini-View Titanic
 */

:root {
  --mal-brand-dark: #1e293b;
  --mal-brand-light: #f1f5f9;
  --mal-logo: #ffae00;
  --mal-btn1: #00c6e0;
  --mal-btn1-hover: #22d3ee;
  --iv-blue: var(--mal-btn1);
  --iv-blue-hover-bg: rgba(0, 198, 224, 0.12);
  --iv-text: #1e293b;
  --iv-text-secondary: #64748b;
  --iv-border: #e2e8f0;
  --iv-surface: #ffffff;
  --iv-font-header: "DM Sans", ui-sans-serif, sans-serif;
  --iv-font-body: "DM Sans", ui-sans-serif, sans-serif;
  --iv-font: var(--iv-font-body);
  --mal-banner-height: 3.5rem;
  --iv-vh: 100vh;
  --reveal: 5;
  --wiki-blur: 13.3px;
  --iv-cursor-blur: 14px;
  --iv-cursor-blur-spot: 170px;
  --compare-handle-size: 52px;
}

@supports (height: 100svh) {
  :root {
    --iv-vh: 100svh;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body.iv-wiki {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body.iv-wiki {
  font-family: var(--iv-font);
  color: var(--iv-text);
  background: #0b1420;
}

#app {
  position: relative;
  width: 100%;
  height: var(--iv-vh);
  overflow: hidden;
}

/* —— Preloaded 3D iframe —— */
#infini-view-container {
  position: fixed;
  inset: 0;
  z-index: 1;
  opacity: calc(var(--reveal) / 100 * 0.35 + 0.05);
  pointer-events: none;
  transition: opacity 0.15s linear;
}

#infini-view-container.is-active {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.6s ease;
}

#store-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* —— Compare shell (wiki overlay) —— */
#compare-shell {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: auto;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

#compare-shell.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

#compare-wiki-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  clip-path: inset(0 calc(var(--reveal) * 1%) 0 0);
  will-change: clip-path;
}

#compare-wiki-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
  filter: blur(var(--wiki-blur)) saturate(0.88) brightness(0.92);
  transform: scale(1.04);
  transition: filter 0.12s linear;
}

#compare-wiki-layer.iv-cursor-blur-active #compare-wiki-img {
  filter: saturate(0.88) brightness(0.92);
}

#compare-wiki-layer.iv-cursor-blur-host {
  --iv-blur-x: 50%;
  --iv-blur-y: 50%;
}

#compare-wiki-layer .iv-cursor-blur {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  backdrop-filter: blur(var(--iv-cursor-blur));
  -webkit-backdrop-filter: blur(var(--iv-cursor-blur));
  opacity: 0;
  transition: opacity 0.35s ease;
}

#app[data-state="compare"] #compare-wiki-layer.iv-cursor-blur-active .iv-cursor-blur {
  opacity: 1;
}

#compare-wiki-layer.iv-cursor-blur-host.iv-cursor-blur-live .iv-cursor-blur {
  mask-image: radial-gradient(
    circle var(--iv-cursor-blur-spot) at var(--iv-blur-x) var(--iv-blur-y),
    transparent 0,
    transparent 64px,
    #000 var(--iv-cursor-blur-spot)
  );
  -webkit-mask-image: radial-gradient(
    circle var(--iv-cursor-blur-spot) at var(--iv-blur-x) var(--iv-blur-y),
    transparent 0,
    transparent 64px,
    #000 var(--iv-cursor-blur-spot)
  );
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  #compare-wiki-layer.iv-cursor-blur-active #compare-wiki-img {
    filter: blur(var(--wiki-blur)) saturate(0.88) brightness(0.92);
  }

  #compare-wiki-layer .iv-cursor-blur {
    display: none;
  }
}

.iv-reduced-motion #compare-wiki-layer.iv-cursor-blur-active #compare-wiki-img {
  filter: blur(var(--wiki-blur)) saturate(0.88) brightness(0.92);
}

.iv-reduced-motion #compare-wiki-layer .iv-cursor-blur {
  display: none;
}

#compare-wiki-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(11, 20, 32, 0.55) 0%,
    rgba(11, 20, 32, 0.2) 38%,
    rgba(11, 20, 32, 0.45) 100%
  );
  pointer-events: none;
}

/* Divider + handle */
#compare-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(100% - var(--reveal) * 1%);
  z-index: 4;
  width: 3px;
  margin-left: -1.5px;
  background: linear-gradient(
    180deg,
    transparent 0%,
    var(--mal-btn1) 12%,
    var(--mal-btn1) 88%,
    transparent 100%
  );
  box-shadow: 0 0 18px rgba(0, 198, 224, 0.55);
  pointer-events: none;
  opacity: calc(1 - min(var(--reveal) / 98, 1));
}

#compare-handle {
  position: absolute;
  top: 50%;
  left: calc(100% - var(--reveal) * 1%);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--compare-handle-size);
  height: var(--compare-handle-size);
  border: 2px solid var(--mal-btn1);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.96);
  color: var(--mal-btn1);
  box-shadow:
    0 4px 22px rgba(0, 0, 0, 0.28),
    0 0 0 0 rgba(0, 198, 224, 0.45);
  cursor: ew-resize;
  touch-action: none;
  animation: iv-wiki-handle-pulse 1.6s ease-in-out infinite;
  transform: translate(-50%, -50%);
  transition: background-color 0.15s ease, box-shadow 0.15s ease, opacity 0.3s ease;
}

#compare-handle:hover {
  background: var(--mal-btn1);
  color: #fff;
  transform: translate(-50%, -50%) scale(1.06);
}

#compare-handle:focus-visible {
  outline: 2px solid var(--mal-btn1);
  outline-offset: 3px;
}

#compare-handle.is-dragging {
  animation: none;
  transform: translate(-50%, -50%) scale(1.08);
  background: var(--mal-btn1);
  color: #fff;
}

#compare-handle svg {
  width: 26px;
  height: 26px;
}

#app[data-state="experience"] #compare-divider,
#app[data-state="experience"] #compare-handle,
#app[data-state="transition"] #compare-divider,
#app[data-state="transition"] #compare-handle {
  opacity: 0;
  pointer-events: none;
}

@keyframes iv-wiki-handle-pulse {
  0%,
  100% {
    box-shadow:
      0 4px 22px rgba(0, 0, 0, 0.28),
      0 0 0 0 rgba(0, 198, 224, 0.5);
  }
  50% {
    box-shadow:
      0 6px 28px rgba(0, 198, 224, 0.35),
      0 0 0 16px rgba(0, 198, 224, 0);
  }
}

/* Hero copy */
.compare-hero {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.compare-hero.is-faded {
  opacity: 0;
  transform: translateY(-8px);
}

.compare-hero h1 {
  margin: 0 0 16px;
  max-width: 900px;
  font-family: var(--iv-font-header);
  font-size: clamp(36px, 7vw, 72px);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.12;
  color: #fff;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.45);
}

.compare-hero p {
  margin: 0;
  max-width: 720px;
  font-size: clamp(20px, 3.2vw, 32px);
  font-weight: 400;
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.88);
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.35);
}

.compare-hint {
  position: absolute;
  left: calc(100% - var(--reveal) * 1%);
  top: calc(50% - 54px);
  z-index: 3;
  margin: 0;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  transform: translate(calc(-100% - 14px), -100%);
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.compare-hint.is-hidden {
  opacity: 0;
}

/* Hidden range input for a11y */
#compare-range {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#compare-enter-btn {
  position: absolute;
  top: 68%;
  left: 50%;
  z-index: 6;
  padding: 12px 28px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--mal-brand-dark);
  background: var(--mal-btn1);
  border: none;
  border-radius: 999px;
  box-shadow: 0 4px 18px rgba(0, 198, 224, 0.35);
  cursor: pointer;
  transform: translate(-50%, -50%);
  transition: background-color 0.15s ease, opacity 0.3s ease, transform 0.15s ease;
}

#compare-enter-btn:hover {
  background: var(--mal-btn1-hover);
  transform: translate(-50%, calc(-50% - 1px));
}

#compare-enter-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

#app[data-state="experience"] #compare-enter-btn,
#app[data-state="transition"] #compare-enter-btn {
  opacity: 0;
  pointer-events: none;
}

/* Lang switch */
.iv-lang {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 20;
  margin: 0;
  font-size: 13px;
  font-weight: 500;
}

.iv-lang a {
  color: var(--iv-blue);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.iv-lang a:hover {
  background: var(--iv-blue-hover-bg);
}

#app[data-state="experience"] .iv-lang {
  top: calc(var(--mal-banner-height) + 8px);
}

/* MAL banner */
#mal-footer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 11;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: var(--mal-banner-height);
  padding: 10px 16px;
  font-family: var(--iv-font-header);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  color: rgba(30, 41, 59, 0.85);
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid var(--iv-border);
  backdrop-filter: blur(8px);
}

#mal-footer a {
  font-weight: 600;
  color: var(--mal-btn1);
  text-decoration: none;
}

#mal-footer a:hover {
  color: var(--mal-btn1-hover);
  text-decoration: underline;
}

#mal-footer[hidden] {
  display: none !important;
}

/* Toast */
#cta-toast {
  position: fixed;
  top: var(--mal-banner-height);
  left: 50%;
  z-index: 12;
  width: min(92vw, 420px);
  padding: 20px 24px;
  font-family: var(--iv-font-header);
  background: var(--iv-surface);
  border: 1px solid rgba(30, 41, 59, 0.25);
  border-radius: 12px;
  box-shadow:
    0 8px 30px rgba(30, 41, 59, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.06);
  transform: translateX(-50%) translateY(calc(-100% - var(--mal-banner-height) - 16px));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    transform 0.4s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.35s ease,
    visibility 0s linear 0.4s;
}

#cta-toast.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition:
    transform 0.4s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.35s ease,
    visibility 0s;
}

.mal-toast__text {
  margin: 0 0 16px;
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.45;
  color: rgba(30, 41, 59, 0.85);
}

.mal-toast__btn {
  display: block;
  margin: 0 auto;
  padding: 10px 24px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--mal-brand-dark);
  background: var(--mal-btn1);
  border: none;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  cursor: default;
}

#transition-mask {
  position: fixed;
  inset: 0;
  z-index: 8;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

#transition-mask.is-visible {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 767px) {
  :root {
    --compare-handle-size: 46px;
    --wiki-blur: 10px;
  }

  .compare-hero {
    padding: 20px 16px;
  }

  .compare-hint {
    top: calc(50% - 46px);
    transform: translate(calc(-100% - 10px), -100%);
    font-size: 13px;
    max-width: min(240px, calc(100% - var(--reveal) * 1% - 32px));
    white-space: normal;
    text-align: left;
  }

  #compare-enter-btn {
    top: 70%;
  }

  .iv-lang {
    top: auto;
    bottom: 12px;
    right: 12px;
  }

  #app[data-state="experience"] .iv-lang {
    top: auto;
    bottom: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #compare-handle {
    animation: none;
  }

  #infini-view-container,
  #compare-shell,
  #compare-wiki-img,
  #cta-toast,
  #transition-mask,
  .compare-hero,
  .compare-hint {
    transition: none;
  }
}
