/* Then & now comparison slider. Pair with compare.js (plain <script defer>).
   Markup:
     <figure class="compare" style="--aspect: 16/9" data-then="2013 · Unreal 3" data-now="2026 · WebGL">
       <img class="compare-then" src="old.png" alt="…" style="--focus: 50% 40%">
       <img class="compare-now"  src="new.png" alt="…">
       <figcaption>…</figcaption>
     </figure>
   Wrap several figures in <div class="compare-set"> to get one slider with tabs.
   Theme with --compare-accent / --compare-on-accent / --compare-radius. */

@property --pos { syntax: "<percentage>"; inherits: true; initial-value: 50%; }

.compare {
  --compare-accent: var(--green, #85c36a);
  --compare-on-accent: #07100a;
  --compare-radius: 14px;
  margin: 0;
  min-width: 0;
}
.compare img { max-width: 100%; display: block; }
.compare figcaption { margin-top: 12px; color: var(--muted, #9aa5ae); font-size: 14px; line-height: 1.5; }

/* ---------- without JS: the two shots side by side, labels from the data attributes ---------- */
.compare:not(.is-live) {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.compare:not(.is-live) > img {
  grid-row: 1; width: 100%; height: auto; aspect-ratio: var(--aspect, 16 / 9);
  object-fit: var(--fit, cover); object-position: var(--focus, 50% 50%);
  border-radius: var(--compare-radius); background: #000;
}
.compare:not(.is-live) > .compare-then { grid-column: 1; }
.compare:not(.is-live) > .compare-now { grid-column: 2; }
.compare:not(.is-live) > figcaption { grid-column: 1 / -1; margin-top: 4px; }
.compare:not(.is-live)::before,
.compare:not(.is-live)::after {
  grid-row: 1; align-self: start; justify-self: start; z-index: 1; margin: 10px;
  font: 800 12px/1 var(--pixel, ui-monospace, monospace); letter-spacing: .1em; text-transform: uppercase;
  padding: 6px 8px; border-radius: 6px;
}
.compare:not(.is-live)::before { content: attr(data-then); grid-column: 1; background: rgba(0,0,0,.72); color: #fff; }
.compare:not(.is-live)::after { content: attr(data-now); grid-column: 2; background: var(--compare-accent); color: var(--compare-on-accent); }
@media (max-width: 520px) {
  .compare:not(.is-live) { grid-template-columns: 1fr; }
  .compare:not(.is-live) > .compare-now, .compare:not(.is-live)::after { grid-column: 1; grid-row: 2; }
  .compare:not(.is-live) > figcaption { grid-column: 1; }
}
.compare-set:not(.is-live) { display: grid; gap: 28px; }

/* ---------- enhanced ---------- */
.compare-frame {
  --pos: 50%;
  position: relative; overflow: hidden; isolation: isolate;
  aspect-ratio: var(--aspect, 16 / 9);
  border-radius: var(--compare-radius); background: #000;
  touch-action: pan-y; cursor: ew-resize;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.compare-frame img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: var(--fit, cover); object-position: var(--focus, 50% 50%);
  pointer-events: none; -webkit-user-drag: none;
}
.compare-then-layer { position: absolute; inset: 0; z-index: 1; clip-path: inset(0 calc(100% - var(--pos)) 0 0); }
.compare-now-layer { position: absolute; inset: 0; z-index: 1; pointer-events: none; clip-path: inset(0 0 0 var(--pos)); }
.compare-frame.is-jumping { transition: --pos .28s cubic-bezier(.2,.8,.2,1); }

.compare-label {
  position: absolute; top: 12px; z-index: 3; pointer-events: none;
  max-width: calc(50% - 18px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font: 800 13px/1 var(--pixel, ui-monospace, monospace); letter-spacing: .12em; text-transform: uppercase;
  padding: 7px 9px 6px; border-radius: 6px;
}
.compare-label.then { left: 12px; background: rgba(0,0,0,.72); color: #fff; box-shadow: inset 0 0 0 1px rgba(255,255,255,.14); }
.compare-label.now { right: 12px; background: var(--compare-accent); color: var(--compare-on-accent); box-shadow: 0 2px 0 rgba(0,0,0,.45); }

.compare-handle { position: absolute; top: 0; bottom: 0; left: var(--pos); z-index: 2; width: 0; }
.compare-handle::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: -1.5px; width: 3px;
  background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35), 0 0 16px var(--compare-accent);
}
.compare-knob {
  position: absolute; top: 50%; left: 0; transform: translate(-50%, -50%);
  width: 52px; height: 52px; padding: 0; border: 0; border-radius: 50%; cursor: ew-resize;
  display: grid; place-items: center;
  background: var(--compare-accent); color: var(--compare-on-accent);
  box-shadow: 0 0 0 4px rgba(0,0,0,.35), 0 0 0 7px rgba(255,255,255,.9), 0 10px 28px rgba(0,0,0,.6);
  transition: transform .15s, background .2s;
  touch-action: none;
}
.compare-knob svg { width: 26px; height: 26px; }
.compare-knob:hover { background: var(--green-hi, #b5e79c); }
.compare-knob:focus-visible { outline: 3px solid #fff; outline-offset: 8px; }
.compare-frame.is-dragging .compare-knob { transform: translate(-50%, -50%) scale(1.1); }

/* ---------- a set of pairs: one slider plus a thumbnail strip ---------- */
.compare-set.is-live > .compare[hidden] { display: none; }
.compare-tabs {
  display: flex; gap: 10px; margin: 14px 0 0; padding: 2px 2px 6px;
  overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: thin;
}
.compare-tab {
  flex: 0 0 auto; scroll-snap-align: start;
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 14px 6px 6px;
  border: 0; border-radius: 12px; cursor: pointer;
  background: rgba(255,255,255,.04); color: var(--muted, #9aa5ae);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
  font: 600 14px/1.2 var(--sans, system-ui, sans-serif); text-align: left;
  transition: background .2s, box-shadow .2s, color .2s;
}
.compare-tab:hover { color: var(--ink, #eef2f4); background: rgba(255,255,255,.07); }
.compare-tab[aria-selected="true"] { color: var(--ink, #eef2f4); background: rgba(133,195,106,.12); box-shadow: inset 0 0 0 2px var(--green, #85c36a); }
.compare-tab:focus-visible { outline: 3px solid var(--green-hi, #b5e79c); outline-offset: 2px; }
.compare-thumb { position: relative; width: 72px; aspect-ratio: 16 / 10; border-radius: 7px; overflow: hidden; background: #000; flex: none; }
.compare-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: var(--focus, 50% 50%); }
.compare-thumb img:first-child { clip-path: inset(0 50% 0 0); z-index: 1; }
.compare-thumb::after { content: ""; position: absolute; top: 0; bottom: 0; left: calc(50% - 1px); width: 2px; background: #fff; z-index: 2; }
.compare-tab .n { display: block; font: 800 11px/1 var(--pixel, ui-monospace, monospace); letter-spacing: .14em; color: var(--green, #85c36a); margin-bottom: 4px; }

@media (max-width: 520px) {
  .compare-label { top: 8px; font-size: 11px; padding: 6px 7px 5px; max-width: calc(50% - 12px); }
  .compare-label.then { left: 8px; } .compare-label.now { right: 8px; }
  .compare-knob { width: 46px; height: 46px; }
  .compare-thumb { width: 60px; }
}
@media (prefers-reduced-motion: reduce) {
  .compare-frame.is-jumping, .compare-knob, .compare-tab { transition: none; }
}
