/* ============================================================
   The Tee Family House — css/transform.css
   «التحوّلات» / Transformations — the before/after comparison
   gallery (transformations.html only). Consumes the tokens and
   shells from css/base.css and reuses the story-page shells
   from css/pages.css (.pages-header, .story-cta, .pages-footer)
   — never redefines a token, never restyles a shared class.

   Every box below is written in LOGICAL properties only
   (inset-inline-*, margin-inline, padding-block, border-start-*)
   so the whole page mirrors for free between Arabic (rtl) and
   English (ltr). The single unavoidable physical value is the
   clip-path inset() on .cmp-clip — clip-path has no logical
   form — so it is branched explicitly on [dir] at the bottom of
   the component block.
   ============================================================ */

/* ---------------- Hero strip ----------------
   The cream/light page language of the story pages. The shared
   .eyebrow is pink-on-dark by default; on cream it needs the
   deepened pink to stay readable, scoped to this hero so no
   other page's eyebrow is touched. */
.tf-hero { padding-block: clamp(28px, 6vh, 56px) clamp(36px, 6vh, 64px); }
/* base.css makes .eyebrow inline-flex, and pages.css makes .story-back
   inline-flex too — two inline-level boxes, so on this page (the only
   one that stacks them) they share a line and read as one run of text.
   Promoting the back link to a block-level flex box, shrunk to its own
   content, puts it back on its own line without touching either shared
   rule. */
.tf-hero .story-back { display: flex; inline-size: fit-content; }
.tf-hero .eyebrow { color: var(--pink-deep); }
.tf-hero .eyebrow::before { background: var(--pink-deep); }
.tf-hero h1 { font-size: clamp(2rem, 5.2vw, 3.4rem); max-width: 20ch; }
.tf-hero .lead { margin-block-start: 14px; }

/* A one-line "how to use it" hint under the lead, carrying the same
   double-chevron glyph as the handle so the connection is obvious
   before the visitor has touched anything. */
.tf-hint {
  display: inline-flex; align-items: center; gap: 10px;
  margin-block-start: 22px; padding: 8px 16px; border-radius: 999px;
  font-size: 0.85rem; color: var(--ink-soft);
  background: var(--card);
  border: 1px solid var(--hairline-light);
  box-shadow: 0 1px 0 var(--hairline-light), 0 10px 24px -20px rgba(44, 33, 38, 0.4);
}
.tf-hint svg { flex: none; color: var(--pink-deep); }

/* ---------------- Pair layout ----------------
   Media column + text column, alternating sides down the page.
   `order` (not row/column placement) does the alternation, so the
   DOM order stays media-then-text — which is also the order a
   screen reader and a no-CSS visitor get. */
.tf-pairs { padding-block: clamp(24px, 4vh, 48px) clamp(64px, 10vh, 120px); }
.tf-pairs-list { display: flex; flex-direction: column; gap: clamp(56px, 9vh, 110px); }

.tf-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.92fr);
  gap: clamp(24px, 4vw, 56px);
  align-items: center;
}
.tf-pair:nth-child(even) .tf-pair-media { order: 2; }

.tf-pair-media { margin: 0; }
.tf-pair-body { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; }

.tf-pair-name {
  font-family: var(--font-accent); font-style: italic; font-weight: 700;
  font-size: clamp(1.8rem, 3.6vw, 2.6rem); color: var(--pink-deep);
  line-height: 1.2;
}
html[lang='en'] .tf-pair-name { font-family: var(--font-accent-en); font-weight: 500; }

.tf-pair-line {
  font-size: clamp(1.05rem, 1.9vw, 1.35rem);
  line-height: 1.75; color: var(--ink); max-width: 26ch;
}

/* Index number as a quiet counter, not a decoration that competes. */
.tf-pair-index {
  font-size: 0.78rem; letter-spacing: 0.22em; font-weight: 500;
  color: var(--muted-on-light);
}

.tf-pair-link {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.95rem; font-weight: 500; color: var(--pink-deep);
  border-block-end: 1px solid transparent;
  padding-block-end: 3px;
  transition: border-color 0.25s var(--ease-soft), gap 0.25s var(--ease-soft);
}
.tf-pair-link:hover { border-block-end-color: var(--pink-deep); gap: 14px; }
/* Direction-aware "forward" arrow: decided by [dir], not by the text
   swap, so it always points along the reading direction — ← in Arabic,
   → in English — exactly like pages.css's .back-arrow does in reverse. */
.tf-arrow::before { content: '\2192'; }
[dir='rtl'] .tf-arrow::before { content: '\2190'; }

@media (max-width: 900px) {
  .tf-pair { grid-template-columns: 1fr; gap: 22px; }
  /* The alternation is meaningless in one column and would put half
     the captions above their own photo — reset it. */
  .tf-pair:nth-child(even) .tf-pair-media { order: 0; }
  .tf-pair-line { max-width: none; }
}

/* ============================================================
   The comparison component (.cmp)
   ============================================================
   Stacking order inside .cmp-frame, bottom → top:
     1. .cmp-after   — the "after" photo, full bleed, always whole
     2. .cmp-clip    — the "before" photo, revealed by clip-path
     3. .cmp-chip    — the قبل / بعد labels
     4. .cmp-cursor  — the divider line + the drag handle
   Only two properties ever change while dragging: clip-path on
   .cmp-clip and a translate3d on .cmp-cursor. Nothing reflows. */

.cmp {
  --tf-pos: 50%;      /* how much of the frame the "before" photo covers */
  --tf-dir: 1;        /* +1 ltr, -1 rtl — mirrors the rail without any JS */
  --tf-op-before: 1;  /* chip opacities, faded by JS as the handle nears */
  --tf-op-after: 1;
  position: relative;
}
[dir='rtl'] .cmp { --tf-dir: -1; }

.cmp-frame {
  position: relative;
  aspect-ratio: var(--tf-ar, 3 / 4);
  inline-size: 100%;
  max-inline-size: 520px;
  margin-inline: auto;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--cream-2);
  cursor: ew-resize;
  /* Vertical page scrolling must keep working over the photo on a
     phone; only the horizontal axis is ours. */
  touch-action: pan-y;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    0 1px 0 var(--hairline-light),
    0 18px 40px -24px rgba(44, 33, 38, 0.45),
    0 44px 90px -50px rgba(217, 83, 138, 0.4);
}

/* Copper-into-pink hairline, drawn as an overlay ring so it sits above
   both photos and never shifts the layout the way a real border would. */
.cmp-frame::after {
  content: '';
  position: absolute; inset: 0; pointer-events: none;
  z-index: 2;
  border-radius: inherit;
  border: 1px solid rgba(193, 130, 100, 0.5);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.3),
    inset 0 0 40px -18px rgba(217, 83, 138, 0.55);
}

.cmp-img {
  position: absolute; inset: 0;
  inline-size: 100%; block-size: 100%;
  object-fit: cover;
  /* Per-pair object-position is set inline on each <img>: the two
     photos in a pair rarely share an aspect ratio, so each side gets
     its own focal point inside the shared frame (documented in
     .claude/handoff/opus-transform-report.md). */
  filter: saturate(1.04) sepia(0.06) brightness(1.01);
  -webkit-user-drag: none; user-select: none;
  pointer-events: none;
}

.cmp-clip {
  position: absolute; inset: 0;
  /* Physical by necessity — clip-path has no logical form. Both
     branches are declared below so the reveal always grows from the
     inline-start (reading-start) edge. */
  clip-path: inset(0 calc(100% - var(--tf-pos)) 0 0);
  will-change: clip-path;
}
[dir='rtl'] .cmp-clip { clip-path: inset(0 0 0 calc(100% - var(--tf-pos))); }

/* ---------------- قبل / بعد chips ----------------
   Pinned to the two inline edges, so they swap sides automatically
   between Arabic and English. Each fades out as the handle sweeps
   toward it (opacity driven by JS) — the label never fights the
   divider for the same few pixels. */
.cmp-chip {
  position: absolute; inset-block-start: 14px;
  padding: 6px 14px; border-radius: 999px;
  font-size: 0.74rem; font-weight: 600; letter-spacing: 0.06em;
  color: var(--text-on-dark);
  background: rgba(18, 13, 16, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(10px) saturate(150%);
  -webkit-backdrop-filter: blur(10px) saturate(150%);
  pointer-events: none;
  transition: opacity 0.18s linear;
}
.cmp-chip-before { inset-inline-start: 14px; opacity: var(--tf-op-before); }
.cmp-chip-after {
  inset-inline-end: 14px; opacity: var(--tf-op-after);
  background: rgba(217, 83, 138, 0.5);
  border-color: rgba(255, 255, 255, 0.3);
}

/* ---------------- Divider + handle ----------------
   .cmp-cursor is a rail pinned to the inline-start edge, exactly as wide
   as the frame, and moved by translating a PERCENTAGE of its own width —
   which is therefore a percentage of the frame. That is the whole reason
   it is 100% wide and not 0: a percentage translate needs no measured
   pixel value, so the rail can never drift out of step with the
   clip-path after a resize, a font swap or a rotation, and JS never has
   to read layout to paint a frame. Both the rail and the clip read the
   same single --tf-pos; --tf-dir mirrors the rail in Arabic.
   Its children hang off its inline-start edge, so the line and the
   handle ride one transform between them. */
.cmp-cursor {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  inline-size: 100%;
  z-index: 3;
  /* The rail spans the frame, so it must not swallow pointer events
     meant for the photo; only the handle itself takes input. */
  pointer-events: none;
  transform: translate3d(calc(var(--tf-dir) * var(--tf-pos)), 0, 0);
  will-change: transform;
  /* The rail is placed by a translate3d in px, which only transform.js
     can compute. Until it has run — or if it never runs — the rail
     would sit welded to the frame's edge, promising a control that
     cannot move. Hidden until .is-ready, so a JS-less visitor gets a
     clean 50/50 diptych with its قبل/بعد labels instead of a dead
     handle. */
  opacity: 0;
  transition: opacity 0.4s var(--ease-soft);
}
.cmp.is-ready .cmp-cursor { opacity: 1; }

.cmp-line {
  position: absolute; inset-block: 0;
  inset-inline-start: -1px;
  inline-size: 2px;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.55),
    rgba(255, 255, 255, 0.95) 22%,
    rgba(255, 255, 255, 0.95) 78%,
    rgba(255, 255, 255, 0.55)
  );
  box-shadow: 0 0 12px rgba(217, 83, 138, 0.55), 0 0 2px rgba(18, 13, 16, 0.5);
  pointer-events: none;
}

.cmp-handle {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: -22px;
  inline-size: 44px; block-size: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--pink-deep);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(217, 83, 138, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow:
    0 2px 6px rgba(44, 33, 38, 0.28),
    0 10px 26px -12px rgba(217, 83, 138, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  /* translateY only — the horizontal placement comes from the parent
     rail's transform, so this never has to be direction-aware. */
  transform: translateY(-50%);
  pointer-events: auto;
  cursor: grab;
  transition: box-shadow 0.25s var(--ease-soft), background 0.25s var(--ease-soft);
  touch-action: none;
}
.cmp-handle:hover {
  background: #fff;
  box-shadow:
    0 2px 8px rgba(44, 33, 38, 0.32),
    0 14px 34px -12px rgba(217, 83, 138, 0.75),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}
.cmp-handle:focus-visible {
  outline: 2px solid var(--pink-deep);
  outline-offset: 3px;
}
.cmp.is-dragging .cmp-handle { cursor: grabbing; }
/* No transition on the chips mid-drag: a 0.18s fade lagging a 60fps
   drag reads as a stutter, not a fade. */
.cmp.is-dragging .cmp-chip { transition: none; }

/* A slow breathing ring on the handle until the visitor first touches
   it — the "this moves" cue. Removed by JS on first interaction; the
   global reduced-motion rule in base.css already flattens it, and the
   .reduce-motion guard below removes it outright. */
.cmp-handle::before {
  content: '';
  position: absolute; inset: -6px;
  border-radius: 50%;
  border: 1px solid rgba(217, 83, 138, 0.45);
  opacity: 0;
  animation: tf-pulse 2.8s var(--ease-soft) infinite;
}
.cmp.is-touched .cmp-handle::before,
html.reduce-motion .cmp-handle::before { display: none; }

@keyframes tf-pulse {
  0%   { opacity: 0.7; transform: scale(0.86); }
  70%  { opacity: 0;   transform: scale(1.22); }
  100% { opacity: 0;   transform: scale(1.22); }
}

/* No-JS / failed-JS fallback: without transform.js the rail never
   moves and clip-path holds its 50% default, so the component still
   reads as a legible half-and-half diptych rather than a dead photo. */

@media (max-width: 900px) {
  .cmp-frame { max-inline-size: 460px; }
}
@media (max-width: 480px) {
  .cmp-chip { inset-block-start: 10px; padding: 5px 11px; font-size: 0.68rem; }
  .cmp-chip-before { inset-inline-start: 10px; }
  .cmp-chip-after { inset-inline-end: 10px; }
}

/* ---------------- CTA band tail ----------------
   .story-cta / .story-cta-line / .story-cta-actions all come from
   pages.css untouched; only this trailing "browse everything" link is
   ours, and pages.css has no rule for it. */
.tf-more {
  display: inline-flex; align-items: center; gap: 8px;
  margin-block-start: 26px;
  font-size: 0.92rem; color: var(--pink);
  border-block-end: 1px solid transparent; padding-block-end: 3px;
  transition: border-color 0.25s var(--ease-soft), gap 0.25s var(--ease-soft);
}
.tf-more:hover { border-block-end-color: var(--pink); gap: 14px; }

/* ---------------- Closing note above the CTA ---------------- */
.tf-note {
  margin-block-start: clamp(48px, 8vh, 88px);
  padding-block-start: clamp(28px, 5vh, 44px);
  border-block-start: 1px solid var(--hairline-light);
  text-align: center;
}
.tf-note p {
  font-family: var(--font-hand); font-size: clamp(1.3rem, 2.6vw, 1.7rem);
  color: var(--ink-soft); max-width: 34ch; margin-inline: auto; line-height: 1.5;
}
