/* ============================================================
   Multi-state precision cursor + gold-leaf card illumination
   Controlled by <body data-portfolio-mode="deep-dive|quick-scan|xray">.
   Desktop fine-pointer only. The only text on the cursor is the opt-in
   data-cursor-label pill (e.g. "Open Website").

   Design constraints applied:
   - 4-point spatial scale (4, 8, 12, 16, 20, 24, 32px). The brief's
     off-scale numbers were snapped: 6->8 dot, 26->24 ring, 38->32 hover,
     7->8 diamond, 28->32 reticle, 14->16 HUD offset.
   - WCAG AA: every cursor stroke/fill holds >= 3:1 on both the light
     canvas and the dark card previews. Gold alone fails on white, so
     strokes use a deeper champagne (--pc-gold-ui) and bright gold
     (#D4AF37 / #C59B27) is always cased in ink.
   ============================================================ */

:root {
  --pc-ink: #1a1a1a;
  --pc-gold: #c59b27;          /* brand warm gold (fills, always cased) */
  --pc-gold-lux: #d4af37;      /* luminous gold (X-Ray crosshair, cased) */
  --pc-gold-ui: #b08420;       /* 3.2:1 on #faf9f6, 5.3:1+ on dark previews */
  --pc-gold-tint: rgba(197, 155, 39, 0.12);

  /* Live cursor colours. Defaults are the portfolio gold; each case study
     overrides them below from body[data-accent]. */
  --pc-text: #7a5a14;              /* label text: the nav's selected gold, 5.9:1 on paper */
  --pc-ui: #b08420;                /* strokes on light grounds (>= 3:1 on white) */
  --pc-ui-dk: #b08420;             /* strokes on dark grounds (>= 5:1 on replicas) */
  --pc-fill: var(--pc-gold);       /* Quick Scan diamond */
  --pc-tint: rgba(197, 155, 39, 0.12);  /* hover wash */
  --pc-halo: rgba(255, 255, 255, 0.9);
  --pc-z: 2147483000;          /* above .dex-modal (z-index 999999) */
  --pc-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --pc-leaf: 260px;
}

/* Per case study colour, matching each page's --accent.
   Light shade = raw accent (5.4:1+ on white). Dark shade = 70% accent mixed
   with white (5.2:1+ on the dark replica backgrounds). */
body[data-accent="secureid"]   { --pc-text: #7a5a14; --pc-ui: #7a5a14; --pc-ui-dk: #a28c5a; --pc-fill: #7a5a14; --pc-tint: color-mix(in srgb, #7a5a14 12%, transparent); }
body[data-accent="honda"]      { --pc-text: #a33d1b; --pc-ui: #a33d1b; --pc-ui-dk: #bf775f; --pc-fill: #a33d1b; --pc-tint: color-mix(in srgb, #a33d1b 12%, transparent); }
body[data-accent="vextaro"]    { --pc-text: #1e6e94; --pc-ui: #1e6e94; --pc-ui-dk: #629ab4; --pc-fill: #1e6e94; --pc-tint: color-mix(in srgb, #1e6e94 12%, transparent); }
body[data-accent="devtective"]  { --pc-text: #6044a6; --pc-ui: #6044a6; --pc-ui-dk: #907cc1; --pc-fill: #6044a6; --pc-tint: color-mix(in srgb, #6044a6 12%, transparent); }
body[data-accent="studybuddy"] { --pc-text: #6b46b8; --pc-ui: #6b46b8; --pc-ui-dk: #977ecd; --pc-fill: #6b46b8; --pc-tint: color-mix(in srgb, #6b46b8 12%, transparent); }

/* Hidden everywhere except desktop fine pointers. */
.pc { display: none; }

@media (min-width: 900px) and (hover: hover) and (pointer: fine) {

  /* ---------- Native cursor: hidden only once the script is live ---------- */
  html.pc-active,
  html.pc-active *,
  html.pc-active *::before,
  html.pc-active *::after { cursor: none !important; }

  /* Keep the OS cursor where it carries meaning (text entry, embeds). */
  html.pc-active :is(
    input:not([type="range"]):not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="file"]):not([type="color"]):not([type="image"]),
    textarea, [contenteditable=""], [contenteditable="true"]) { cursor: text !important; }
  html.pc-active :is(select, iframe, embed, object, video[controls], audio[controls]) { cursor: auto !important; }

  /* ---------- Root: zero-size anchor, never intercepts input ---------- */
  .pc {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    z-index: var(--pc-z);
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  .pc[data-visible="true"] { opacity: 1; }
  .pc[data-hover="native"] { opacity: 0; }
  .pc *, .pc *::before, .pc *::after { pointer-events: none !important; box-sizing: border-box; }

  /* Layers are zero-size anchors; children centre on them. */
  .pc-ring, .pc-core { position: absolute; top: 0; left: 0; width: 0; height: 0; will-change: transform; }
  .pc-ring > *, .pc-core > .pc-dot, .pc-core > .pc-cross {
    position: absolute;
    top: 0;
    left: 0;
    translate: -50% -50%;   /* individual property: composes outside rotate/scale */
  }

  /* ============ Layer 2: ring / reticle (lerped in JS) ============ */
  .pc-ring-shape {
    width: 24px;
    height: 24px;
    border: 1px solid var(--pc-ui);
    border-radius: 50%;
    background: transparent;
    transition: width 0.28s var(--pc-ease), height 0.28s var(--pc-ease),
      border-radius 0.28s var(--pc-ease), background-color 0.2s ease,
      border-color 0.2s ease, opacity 0.2s ease, scale 0.12s ease;
  }
  .pc-ticks, .pc-brackets {
    width: 32px;
    height: 32px;
    opacity: 0;
    transition: opacity 0.2s ease, scale 0.28s var(--pc-ease);
    scale: 0.75;
  }
  /* Cardinal ticks: four 4px marks, 2px thick, inside the ring edge. */
  .pc-ticks {
    --t: var(--pc-ui);
    background:
      linear-gradient(var(--t), var(--t)) 50% 0 / 2px 4px no-repeat,
      linear-gradient(var(--t), var(--t)) 50% 100% / 2px 4px no-repeat,
      linear-gradient(var(--t), var(--t)) 0 50% / 4px 2px no-repeat,
      linear-gradient(var(--t), var(--t)) 100% 50% / 4px 2px no-repeat;
  }
  /* L-shaped corner brackets: 8 gradients (2 per corner), 8px arms, 2px thick. */
  .pc-brackets {
    --b: var(--pc-ui);
    background:
      linear-gradient(var(--b), var(--b)) 0 0 / 8px 2px no-repeat,
      linear-gradient(var(--b), var(--b)) 0 0 / 2px 8px no-repeat,
      linear-gradient(var(--b), var(--b)) 100% 0 / 8px 2px no-repeat,
      linear-gradient(var(--b), var(--b)) 100% 0 / 2px 8px no-repeat,
      linear-gradient(var(--b), var(--b)) 0 100% / 8px 2px no-repeat,
      linear-gradient(var(--b), var(--b)) 0 100% / 2px 8px no-repeat,
      linear-gradient(var(--b), var(--b)) 100% 100% / 8px 2px no-repeat,
      linear-gradient(var(--b), var(--b)) 100% 100% / 2px 8px no-repeat;
  }

  /* ============ Layer 1: core pointer (exact, zero lag) ============ */
  .pc-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--pc-ink);
    box-shadow: 0 0 0 1px var(--pc-halo);   /* keeps it visible on dark previews */
    transition: opacity 0.2s ease, border-radius 0.28s var(--pc-ease),
      background-color 0.2s ease, rotate 0.28s var(--pc-ease), scale 0.12s ease;
  }
  .pc-cross {
    width: 24px;
    height: 24px;
    overflow: visible;
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  .pc-cross .case { stroke: var(--pc-ink); stroke-width: 3.5; fill: none; }
  .pc-cross .gold { stroke: var(--pc-gold-lux); stroke-width: 1.5; fill: none; }

  /* Over dark replicas, swap to the lighter shade of the same hue. */
  .pc[data-ground="dark"] { --pc-ui: var(--pc-ui-dk); --pc-text: var(--pc-ui-dk); }

  /* ============ State 1: Deep Dive (default) ============ */
  .pc[data-mode="deep-dive"][data-hover="interactive"] .pc-ring-shape {
    width: 32px;
    height: 32px;
    background: var(--pc-tint);
    border-color: var(--pc-ui);
  }
  .pc[data-mode="deep-dive"][data-hover="interactive"] .pc-dot { scale: 0.75; }

  /* ============ State 2: Quick Scan ============ */
  .pc[data-mode="quick-scan"] .pc-dot {
    background: var(--pc-fill);
    border-radius: 0;
    rotate: 45deg;
    box-shadow: 0 0 0 1px var(--pc-ink), 0 0 0 2px var(--pc-halo);   /* ink + white casing: reads on light and dark */
  }
  .pc[data-mode="quick-scan"] .pc-ring-shape { width: 32px; height: 32px; }
  .pc[data-mode="quick-scan"] .pc-ticks { opacity: 1; scale: 1; }
  .pc[data-mode="quick-scan"][data-hover="interactive"] .pc-ring-shape {
    background: var(--pc-tint);
  }
  .pc[data-mode="quick-scan"][data-hover="interactive"] .pc-ticks { opacity: 0; }
  /* Metric hover: ring dissolves into corner brackets. */
  .pc[data-mode="quick-scan"][data-hover="metric"] .pc-ring-shape { opacity: 0; border-radius: 0; }
  .pc[data-mode="quick-scan"][data-hover="metric"] .pc-ticks { opacity: 0; }
  .pc[data-mode="quick-scan"][data-hover="metric"] .pc-brackets { opacity: 1; scale: 1; }

  /* ============ Snap: clickable -> square box edges ============ */
  /* Corner brackets are drawn on the hovered element's own bounds (JS sets
     translate + size every frame). The round ring steps aside. */
  .pc-snap {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-radius: 0;
    background:
      linear-gradient(var(--pc-ui), var(--pc-ui)) 0 0 / 12px 2px no-repeat,
      linear-gradient(var(--pc-ui), var(--pc-ui)) 0 0 / 2px 12px no-repeat,
      linear-gradient(var(--pc-ui), var(--pc-ui)) 100% 0 / 12px 2px no-repeat,
      linear-gradient(var(--pc-ui), var(--pc-ui)) 100% 0 / 2px 12px no-repeat,
      linear-gradient(var(--pc-ui), var(--pc-ui)) 0 100% / 12px 2px no-repeat,
      linear-gradient(var(--pc-ui), var(--pc-ui)) 0 100% / 2px 12px no-repeat,
      linear-gradient(var(--pc-ui), var(--pc-ui)) 100% 100% / 12px 2px no-repeat,
      linear-gradient(var(--pc-ui), var(--pc-ui)) 100% 100% / 2px 12px no-repeat,
      var(--pc-tint);
    opacity: 0;
    will-change: transform, width, height;
    transition: opacity 0.16s ease;
  }
  .pc-snap[data-settle="true"] {
    transition: opacity 0.16s ease, transform 0.28s var(--pc-ease), width 0.28s var(--pc-ease), height 0.28s var(--pc-ease);
  }
  .pc[data-snap="box"] .pc-snap { opacity: 1; }
  .pc[data-snap="box"] .pc-ring-shape,
  .pc[data-snap="box"] .pc-ticks { opacity: 0; }

  /* Labelled target (Open Website): the ring grows into a horizontal rectangle. */
  .pc-ring-shape { display: grid; place-items: center; overflow: hidden; }
  .pc-label {
    color: var(--pc-text);                    /* the same gold as selected nav text */
    font: 600 14px/20px 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.12s ease;
  }
  .pc[data-snap="label"][data-hover="interactive"] .pc-ring-shape {
    width: 144px;
    height: 40px;
    border-radius: 4px;
    border-color: var(--pc-ui);
    background: rgba(250, 249, 246, 0.94);     /* light paper, so the gold text stays readable over the row */
  }
  .pc[data-snap="label"][data-ground="dark"] .pc-ring-shape { background: rgba(13, 17, 23, 0.92); }
  .pc[data-snap="label"] .pc-label { opacity: 1; transition-delay: 0.12s; }
  .pc[data-snap="label"] .pc-ticks { opacity: 0; }
  .pc[data-snap="label"] .pc-dot { opacity: 0; }
  .pc[data-snap="label"][data-pressed="true"] .pc-ring-shape { scale: 0.96; }

  /* ============ State 3: X-Ray Dev (CAD crosshair) ============ */
  .pc[data-mode="xray"] .pc-ring { visibility: hidden; }
  .pc[data-mode="xray"] .pc-dot { opacity: 0; }
  .pc[data-mode="xray"] .pc-cross { opacity: 1; }

  /* Pressed: a quiet 1-step squeeze, no colour change. */
  .pc[data-pressed="true"] .pc-ring-shape { scale: 0.88; }
  .pc[data-pressed="true"] .pc-dot { scale: 0.75; }

  /* ---------- X-Ray Spec HUD: bottom-right quadrant (+16 / +16) ---------- */
  .pc-hud {
    position: absolute;
    top: 16px;
    left: 16px;
    width: max-content;
    max-width: 288px;
    display: grid;
    gap: 4px;
    padding: 8px 12px;
    border: 1px solid var(--pc-gold-lux);
    border-radius: 4px;
    background: var(--pc-ink);
    color: #f5f1e8;                          /* 15.4:1 on ink */
    font: 500 12px/16px 'Space Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    letter-spacing: 0;
    text-align: left;
    opacity: 0;
    scale: 0.96;
    transform-origin: 0 0;
    transition: opacity 0.16s ease, scale 0.16s var(--pc-ease);
  }
  .pc-hud[data-flip-x="true"] { left: auto; right: 16px; transform-origin: 100% 0; }
  .pc-hud[data-flip-y="true"] { top: auto; bottom: 16px; }
  .pc-hud[data-flip-x="true"][data-flip-y="true"] { transform-origin: 100% 100%; }
  .pc[data-mode="xray"][data-hover="inspect"] .pc-hud { opacity: 1; scale: 1; }
  .pc-hud .hud-sel { color: var(--pc-gold-lux); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }  /* 8.3:1 on ink */
  .pc-hud .hud-row { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
  .pc-hud .hud-sw {
    flex: none;
    width: 12px;
    height: 12px;
    border: 1px solid #f5f1e8;
    border-radius: 4px;
  }
  .pc-hud .hud-ok { color: #7fd99a; }       /* 10.2:1 on ink */
  .pc-hud .hud-bad { color: #ff9a8a; }      /* 8.5:1 on ink */
  .pc-hud .hud-dim { color: #c9c2b4; }      /* 9.8:1 on ink */
  .pc-hud .hud-row:empty { display: none; }

  /* ============ Gold-leaf card border illumination ============ */
  :is(.gold-card, .case-study-card, .featured-card) { position: relative; }
  :is(.gold-card, .case-study-card, .featured-card)::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 2;
    padding: 1px;
    border-radius: inherit;
    background: radial-gradient(var(--pc-leaf) circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
      rgba(212, 175, 55, 0.65), transparent 100%);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask-composite: exclude;
    opacity: var(--leaf-o, 0);
    transition: opacity 0.28s ease;
    pointer-events: none;
  }
  /* Off while X-Ray wireframe mode is active. */
  body[data-portfolio-mode="xray"] :is(.gold-card, .case-study-card, .featured-card)::before,
  body.xray-mode :is(.gold-card, .case-study-card, .featured-card)::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .pc, .pc *, .pc *::before, .pc *::after,
  :is(.gold-card, .case-study-card, .featured-card)::before { transition-duration: 0.01ms !important; }
  .pc-snap, .pc-snap[data-settle="true"], .pc-label { transition-duration: 0.01ms !important; }
}
