/* enhance.css: loaded after styles.css. Progressive, theme-aware, RTL-safe. All motion gated by html.motion. */

:root { --fx-sweep: rgba(234, 242, 255, .055); --fx-c: var(--rule); --fx-len: 10px; }
:root[data-theme="white"] { --fx-sweep: rgba(255, 255, 255, .6); }

/* ---------- type refinement (system stacks only) ---------- */
body { text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; font-kerning: normal; }
.h1-top { letter-spacing: -.025em; }
h2 { letter-spacing: .015em; text-wrap: balance; }
h3 { letter-spacing: .06em; }
.sheet-note, .step, .level p, .pstep p, .notes li { text-wrap: pretty; }
.label, .cell .k { letter-spacing: .22em; }
.sheet-no { letter-spacing: .16em; font-variant-numeric: tabular-nums; }
.pkg .price, .pn, .lvl, .g, .pct, #ts-count, #ts-no, #hero-pct, #raised, #goal-of { font-variant-numeric: tabular-nums; }
:lang(ar) h2, :lang(ar) h3, :lang(ar) .label, :lang(ar) .cell .k, :lang(ar) .sheet-no { letter-spacing: 0; }
::selection { background: var(--mark); color: var(--mark-ink); }

/* ---------- focus: precise, visible, AA ---------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--mark); outline-offset: 3px; border-radius: 1px;
}
.skip:focus-visible { outline-offset: 2px; }

/* ---------- corner registers on frames/cards (static, additive) ---------- */
.frame, .invoice-card, .support-card, .level, .pstep, .channel, .cell, .goal, .direct {
  --fx-g: linear-gradient(var(--fx-c), var(--fx-c));
  background-image:
    var(--fx-g), var(--fx-g), var(--fx-g), var(--fx-g),
    var(--fx-g), var(--fx-g), var(--fx-g), var(--fx-g);
  background-repeat: no-repeat;
  background-size:
    var(--fx-len) 1px, 1px var(--fx-len), var(--fx-len) 1px, 1px var(--fx-len),
    var(--fx-len) 1px, 1px var(--fx-len), var(--fx-len) 1px, 1px var(--fx-len);
  background-position:
    left top, left top, right top, right top,
    left bottom, left bottom, right bottom, right bottom;
}
:is(.frame, .invoice-card, .support-card, .level, .pstep, .channel, .cell, .goal, .direct):where(:not([class*="x"]), [class]) { background-origin: border-box; }
.hero, .hero.sheet, .sheet-head, .process-stage { background-image: none; }

/* ---------- sheet header: dimension ticks ---------- */
.sheet-head { position: relative; }
.sheet-head::after {
  content: ""; position: absolute; inset-inline: 0; inset-block-end: -1px; height: 7px; pointer-events: none;
  background:
    repeating-linear-gradient(90deg, var(--rule-soft) 0 1px, transparent 1px 12px) bottom / 100% 4px no-repeat,
    repeating-linear-gradient(90deg, var(--rule) 0 1px, transparent 1px 60px) bottom / 100% 7px no-repeat;
  opacity: .7;
}
:root[dir="rtl"] .sheet-head::after, [dir="rtl"] .sheet-head::after { transform: scaleX(-1); }
.sheet-no { color: var(--mark); }
.kicker .sheet-no { padding-inline-end: .4em; }

/* ---------- surfaces & interaction (static parts) ---------- */
.btn {
  position: relative; transition: background-color .3s var(--ease), color .3s var(--ease), border-color .3s var(--ease), transform .35s var(--ease);
  will-change: auto;
}
.btn.primary { box-shadow: inset 0 0 0 1px var(--mark-ink); }
.btn:active { transform: translateY(1px) scale(.985); }
.btn:hover { border-color: var(--mark); }
.chip, .opt, .radio, .seg { transition: background-color .25s var(--ease), border-color .25s var(--ease), color .25s var(--ease); }
.chip:hover, .opt:hover, .radio:hover { border-color: var(--mark); }
:where(input, select, textarea):focus { border-color: var(--mark); background-color: var(--mark-soft); }
.stamp.on { color: var(--mark); }
.layer .tag text { paint-order: stroke; stroke: var(--paper); stroke-width: 3px; stroke-linejoin: round; }
.section-cut { opacity: .9; }
.progress, .goal-bar, .rod { overflow: hidden; }

/* ---------- RTL safety ---------- */
[dir="rtl"] .btn .icon, [dir="rtl"] .scroll-hint span { transform: scaleX(-1); }
[dir="rtl"] .iso, [dir="rtl"] .vdim-text { direction: ltr; }
[dir="rtl"] .ticker-track { direction: ltr; }
[dir="rtl"] .ch-x, [dir="rtl"] .ch-y { direction: ltr; }

/* ---------- MOTION (gated) ---------- */
@media (prefers-reduced-motion: no-preference) {

  /* light sweep over drafting table */
  html.motion body::before {
    content: ""; position: fixed; inset: -20% -50%; z-index: 0; pointer-events: none;
    background: linear-gradient(105deg, transparent 42%, var(--fx-sweep) 50%, transparent 58%);
    transform: translate3d(-60%, 0, 0);
    animation: fx-sweep 14s var(--ease) 1.2s infinite;
  }
  html.motion main { position: relative; z-index: 1; }
  @keyframes fx-sweep {
    0% { transform: translate3d(-60%, 0, 0); }
    55%, 100% { transform: translate3d(60%, 0, 0); }
  }
  [dir="rtl"].motion body::before, html.motion[dir="rtl"] body::before { animation-direction: reverse; }

  /* reveal: plotter-like arrival (opacity/transform only) */
  html.motion .reveal, html.motion .frame {
    transition: opacity .9s var(--ease), transform .9s var(--ease);
    transition-delay: var(--d, 0s);
  }
  html.motion .reveal:not(.in), html.motion .frame:not(.in) { opacity: 0; transform: translate3d(0, 14px, 0); }
  html.motion .reveal.in, html.motion .frame.in { opacity: 1; transform: none; }

  /* registers draw in on reveal via scale of a pseudo hairline */
  html.motion .sheet-head::before {
    content: ""; position: absolute; inset-inline: 0; inset-block-end: 0; height: 1px; background: var(--rule);
    transform-origin: left center; animation: fx-draw 1.4s var(--ease) both; pointer-events: none;
  }
  [dir="rtl"] .sheet-head::before { transform-origin: right center; }
  @keyframes fx-draw { from { transform: scaleX(0); } to { transform: scaleX(1); } }

  /* hero draws on */
  html.motion .h1-top { display: inline-block; animation: fx-rise 1.1s var(--ease) .1s both; }
  html.motion .h1-sub { display: inline-block; animation: fx-rise 1.1s var(--ease) .3s both; }
  html.motion .kicker { animation: fx-rise .9s var(--ease) both; }
  html.motion .hero .cta { animation: fx-rise 1s var(--ease) .5s both; }
  @keyframes fx-rise { from { opacity: 0; transform: translate3d(0, 12px, 0); } to { opacity: 1; transform: none; } }

  html.motion .iso svg { animation: fx-iso 1.6s var(--ease) .2s both; }
  @keyframes fx-iso { from { opacity: 0; transform: translate3d(0, 18px, 0) scale(.985); } to { opacity: 1; transform: none; } }

  /* step transitions */
  html.motion .step { transition: opacity .5s var(--ease), transform .5s var(--ease); }
  html.motion .step:not(.on) { opacity: 0; }
  html.motion .step.on { transform: translate3d(4px, 0, 0); }
  [dir="rtl"].motion .step.on, html.motion[dir="rtl"] .step.on { transform: translate3d(-4px, 0, 0); }

  /* layers & tags settle */
  html.motion .layer .tag { transition: opacity .6s var(--ease), transform .6s var(--ease); }
  html.motion .layer .tag:not(.on) { opacity: 0; transform: translate3d(-6px, 0, 0); }
  html.motion .layer .tag.on { opacity: 1; transform: none; }
  html.motion .stamp { transition: opacity .6s var(--ease), transform .7s var(--ease); transform-origin: center; transform-box: fill-box; }
  html.motion .stamp:not(.on) { opacity: 0; transform: scale(1.12); }
  html.motion .stamp.on { opacity: 1; transform: none; }

  /* scroll hint pulse */
  html.motion .scroll-hint span { animation: fx-hint 2.2s var(--ease) infinite; }
  @keyframes fx-hint { 0%, 100% { transform: translate3d(0, 0, 0); opacity: .6; } 50% { transform: translate3d(0, 5px, 0); opacity: 1; } }
  [dir="rtl"] .scroll-hint span { animation-name: fx-hint; }

  /* buttons lean toward the hand */
  html.motion .btn:hover { transform: translate3d(2px, -2px, 0); }
  [dir="rtl"].motion .btn:hover, html.motion[dir="rtl"] .btn:hover { transform: translate3d(-2px, -2px, 0); }
  html.motion .btn:active { transform: translate3d(0, 1px, 0) scale(.985); }
  html.motion .btn.primary::after {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, .35) 50%, transparent 60%);
    transform: translate3d(-120%, 0, 0); transition: transform .8s var(--ease);
  }
  html.motion .btn.primary { overflow: hidden; }
  html.motion .btn.primary:hover::after { transform: translate3d(120%, 0, 0); }

  /* cards lift */
  html.motion .invoice-card, html.motion .support-card, html.motion .level, html.motion .channel, html.motion .cell {
    transition: transform .5s var(--ease), opacity .9s var(--ease);
  }
  html.motion .invoice-card.in:hover, html.motion .support-card.in:hover, html.motion .level.in:hover, html.motion .channel.in:hover {
    transform: translate3d(0, -3px, 0);
  }

  /* chips / ticker */
  html.motion .chip:hover { transform: translate3d(0, -1px, 0); }
  html.motion .pulse, html.motion .dot.pulse { animation: fx-pulse 2.4s ease-in-out infinite; }
  @keyframes fx-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .55; transform: scale(.82); } }

  /* numbers settle */
  html.motion .reveal.in .pn, html.motion .reveal.in .lvl, html.motion .reveal.in .price {
    animation: fx-settle .9s var(--ease) .15s both;
  }
  @keyframes fx-settle { from { opacity: 0; transform: translate3d(0, .4em, 0); } to { opacity: 1; transform: none; } }

  /* crosshair eases in */
  html.motion .crosshair { transition: opacity .3s var(--ease); }

  /* dialog */
  html.motion .dlg[open], html.motion dialog[open] { animation: fx-dlg .45s var(--ease) both; }
  html.motion dialog[open]::backdrop { animation: fx-fade .45s var(--ease) both; }
  @keyframes fx-dlg { from { opacity: 0; transform: translate3d(0, 16px, 0) scale(.985); } to { opacity: 1; transform: none; } }
  @keyframes fx-fade { from { opacity: 0; } to { opacity: 1; } }
}

/* ---------- reduced motion: same clean sheet ---------- */
@media (prefers-reduced-motion: reduce) {
  html.motion body::before { display: none; }
  html.motion .reveal, html.motion .frame, html.motion .step, html.motion .layer .tag, html.motion .stamp {
    opacity: 1; transform: none; transition: none; animation: none;
  }
  html.motion .sheet-head::before { animation: none; }
  html.motion .btn, html.motion .btn::after { transition: none; animation: none; }
}

/* ---------- print ---------- */
@media print {
  body::before, .crosshair { display: none; }
  .reveal, .frame { opacity: 1; transform: none; }
}
