/* ==========================================================================
   paper-craft.css — a paper-cut / origami material system for the web
   v0.1 · Edgi Design

   Mental model: every surface is a sheet of card. Sheets have a colour,
   a grain, a cut edge that catches light, and a height above the sheet
   below it. Height is the ONLY thing that produces a shadow. Light comes
   from one direction for the whole page (top, slightly left).

   Layers of this file
   1. Theme tokens       (swap a theme with data-pc-theme on <html>/<body>)
   2. Material           (.pc-sheet, grain, edge, lift)
   3. Techniques         (.pc-slot, .pc-emboss, .pc-deboss, .pc-cut,
                          .pc-stack, .pc-popup, .pc-unfold)
   4. Motion + a11y      (reduced motion, focus)
   ========================================================================== */

/* ---------- 0. Registered properties (so lift + fill can animate) -------- */
@property --lift   { syntax: "<number>"; inherits: true;  initial-value: 1; }
@property --fill   { syntax: "<number>"; inherits: true;  initial-value: 0; }
@property --pc-open{ syntax: "<number>"; inherits: false; initial-value: 0; }
@property --pc-slosh{ syntax: "<number>"; inherits: false; initial-value: 0; }

/* ---------- 1. Theme tokens ---------------------------------------------- */
:root {
  /* light: shadows fall down and very slightly right */
  --pc-light-dx: .18;          /* x offset as a fraction of y offset          */
  --pc-shadow-rgb: 70 48 20;   /* shadows are tinted, never pure black        */
  --pc-shadow-k: 1;            /* global shadow strength                      */
  --pc-edge: rgb(255 255 255 / .55); /* lit cut edge (top of each sheet)      */

  /* surfaces */
  --pc-ground: #F3EDE2;        /* the table / cutting mat everything sits on  */
  --pc-sheet:  #FBF8F2;        /* default card stock                          */
  --pc-sheet-2:#F1EADC;        /* a second, slightly darker stock             */
  --pc-ink:    #26323A;        /* text                                        */
  --pc-ink-2:  #66737A;        /* secondary text                              */

  /* colour ramp — light to dark, used for stacks (1 = front/lightest)       */
  --pc-r1:#FFE806; --pc-r2:#F4CE3D; --pc-r3:#FAC03B; --pc-r4:#FFA509;
  --pc-r5:#FD8103; --pc-r6:#EE7500; --pc-r7:#FE6B0C; --pc-r8:#E85205;
  --pc-accent: var(--pc-r5);
  --pc-accent-ink: #2A1500;
  --pc-accent-text: #C94300;   /* brand orange dark enough for text on paper (4.2:1) */

  /* motion tokens: one hover feel everywhere; UI enters/exits on the strong ease-out */
  --pc-ease-out: cubic-bezier(.23, 1, .32, 1);
  --pc-ease-lift: cubic-bezier(.3, .7, .2, 1.2);   /* a hint of paper spring */
  --pc-dur-hover: .2s;
  --pc-radius: 14px;           /* paper is cut with a knife: small radii      */
  --pc-font: "Plus Jakarta Sans", ui-sans-serif, system-ui, sans-serif;
  --pc-mono: "JetBrains Mono", ui-monospace, monospace;

  /* fibre grain — tiny turbulence tile, multiplied over every sheet */
  --pc-grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .35  0 0 0 0 .3  0 0 0 0 .25  0 0 0 .09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  --pc-tooth: linear-gradient(165deg, rgb(255 255 255 / .10), rgb(0 0 0 / .035));
}

/* Edgi · cutting mat (dark) */
[data-pc-theme="mat"] {
  --pc-shadow-rgb: 0 6 14;
  --pc-shadow-k: 1.5;
  --pc-edge: rgb(255 255 255 / .10);
  --pc-ground: #0B2032;
  --pc-sheet:  #12304A;
  --pc-sheet-2:#0F2A40;
  --pc-ink:    #F4EFE6;
  --pc-ink-2:  #9FB0BC;
  --pc-accent-text: #FFA509;   /* 8.4:1 on the navy mat */
  --pc-grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .05 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* ---------- 2. Material -------------------------------------------------- */
/* elevation: --lift 0 (glued flat) … 6 (floating high). One formula for all. */
.pc-sheet, .pc-lift {
  --lift: 1;
  box-shadow:
    inset 0 1px 0 var(--pc-edge),                                   /* cut edge  */
    calc(var(--lift) * var(--pc-light-dx) * 1px) calc(min(var(--lift),1) * 1px)
        calc(min(var(--lift),1) * 1.5px) rgb(var(--pc-shadow-rgb) / calc(.22 * var(--pc-shadow-k))),      /* contact */
    calc(var(--lift) * var(--pc-light-dx) * 3px) calc(var(--lift) * 3px)
        calc(var(--lift) * 6px)  rgb(var(--pc-shadow-rgb) / calc(.10 * var(--pc-shadow-k))),               /* near    */
    calc(var(--lift) * var(--pc-light-dx) * 8px) calc(var(--lift) * 9px)
        calc(var(--lift) * 16px) rgb(var(--pc-shadow-rgb) / calc(.06 * var(--pc-shadow-k)));              /* ambient */
  transition: --lift var(--pc-dur-hover) var(--pc-ease-lift), transform var(--pc-dur-hover) var(--pc-ease-lift);
}
.pc-sheet {
  background: var(--pc-grain), var(--pc-tooth), var(--pc-fill, var(--pc-sheet));
  border-radius: var(--pc-radius);
  color: var(--pc-ink);
}
.pc-ground { background: var(--pc-grain), var(--pc-ground); color: var(--pc-ink); }

/* interactive sheets rise toward the light; they never scale or glow */
.pc-hover:focus-visible { --lift: calc(var(--lift-base, 1) + 2); transform: translateY(-2px); }
@media (hover: hover) and (pointer: fine) {
.pc-hover:hover { --lift: calc(var(--lift-base, 1) + 2); transform: translateY(-2px); }
}
.pc-hover:active { --lift: .4; transform: translateY(1px); }

/* a lift scale you can use as utility classes */
.pc-l0{--lift:0} .pc-l1{--lift:1} .pc-l2{--lift:2} .pc-l3{--lift:3} .pc-l4{--lift:4} .pc-l6{--lift:6}

/* ---------- 3a. Slot / aperture: a hole cut in the sheet ----------------- */
/* The sheet above casts its shadow INTO the hole, from the top edge.        */
.pc-slot {
  --depth: 6;
  border-radius: calc(var(--pc-radius) * .5);
  background: var(--pc-grain), var(--pc-fill, var(--pc-r4));
  box-shadow:
    inset calc(var(--depth) * var(--pc-light-dx) * 1px) calc(var(--depth) * 1px) calc(var(--depth) * 1.6px)
          rgb(var(--pc-shadow-rgb) / calc(.38 * var(--pc-shadow-k))),
    inset 0 1px 1px rgb(var(--pc-shadow-rgb) / calc(.3 * var(--pc-shadow-k))),
    0 1px 0 var(--pc-edge);                                   /* lit lower lip */
}

/* ---------- 3b. Type that is part of the paper --------------------------- */
/* raised: letters cut from the same stock and glued on top (RUTH poster)    */
.pc-emboss {
  color: var(--pc-emboss-fill, var(--pc-sheet));
  text-shadow:
    0 -1px 0 var(--pc-edge),
    .2px 1px 1px  rgb(var(--pc-shadow-rgb) / calc(.25 * var(--pc-shadow-k))),
    .6px 3px 5px  rgb(var(--pc-shadow-rgb) / calc(.14 * var(--pc-shadow-k))),
    1.6px 9px 16px rgb(var(--pc-shadow-rgb) / calc(.10 * var(--pc-shadow-k)));
}
/* on dark stock the lit edge must be stronger or raised type disappears */
[data-pc-theme="mat"] .pc-emboss { --pc-emboss-fill: #1A3D5C; text-shadow:
    0 -1px 0 rgb(255 255 255 / .22), .2px 1px 1px rgb(0 6 14 / .5), .6px 3px 5px rgb(0 6 14 / .35), 1.6px 9px 16px rgb(0 6 14 / .3); }
/* pressed: letters pushed into the sheet (blind deboss) */
.pc-deboss {
  color: var(--pc-deboss-fill, var(--pc-sheet-2));
  text-shadow: 0 1px 0 var(--pc-edge), 0 -1px 1px rgb(var(--pc-shadow-rgb) / calc(.28 * var(--pc-shadow-k)));
}
/* cut-through (.pc-cut) is built by paper-craft.js as inline SVG: a sheet with
   letter-shaped holes, a drop shadow cast into the holes, and a fill layer
   behind that can rise like water (see the 97% reference). Short words only. */
.pc-cut { display: inline-block; line-height: 1; }
.pc-cut svg { display: block; overflow: visible; max-width: 100%; height: auto; }
/* liquid inside cut letters: the wave flows sideways and the surface bobs */
.is-in-view .pc-cut-wave { animation: pc-wave-flow var(--wd, 5s) linear infinite; }
.is-in-view .pc-cut-wave .pc-cut-fill { animation: pc-wave-slosh var(--sd, 3s) ease-in-out infinite alternate; }
@keyframes pc-wave-flow { to { transform: translateX(calc(-1 * var(--ww, 0px))); } }
@keyframes pc-wave-slosh { from { --pc-slosh: -1; } to { --pc-slosh: 1; } }

/* ---------- 3c. Stack: contour layers (built by JS into an <svg>) -------- */
.pc-stack { position: relative; overflow: hidden; isolation: isolate; }
.pc-stack > svg.pc-stack-art { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; }
.pc-stack-art path { will-change: transform; }

/* ---------- 3d. Pop-up: flaps that stand up from a flat card ------------- */
.pc-popup { perspective: 900px; perspective-origin: 50% 20%; }
.pc-popup .pc-flap {
  transform-origin: 50% 100%;
  transform: rotateX(calc((1 - var(--pc-open)) * 88deg));
  transition: --pc-open .9s cubic-bezier(.25,1.45,.4,1), --lift .9s ease;
  transition-delay: calc(var(--i, 0) * 90ms);
  --lift: calc(.2 + var(--pc-open) * 2.2);
}
.pc-popup.is-open .pc-flap { --pc-open: 1; }

/* ---------- 3e. Unfold: a sheet that opens on a hinge -------------------- */
.pc-unfold { perspective: 1200px; }
.pc-unfold > * {
  transform-origin: 50% 0;
  transform: rotateX(calc((1 - var(--pc-open)) * -92deg));
  opacity: calc(.2 + var(--pc-open));
  transition: --pc-open 1s cubic-bezier(.2,1.2,.3,1);
  transition-delay: calc(var(--i, 0) * 110ms);
}
.pc-unfold.is-open > * { --pc-open: 1; }

/* ---------- 3f. Shards: facets that fold into a form (origami assemble) -- */
.pc-shard {
  transform-box: fill-box; transform-origin: center;
  transform: translate(var(--sx,0), var(--sy,0)) rotate(var(--sr,0)) scale(.6, .08);
  opacity: 0;
  transition: transform 1.1s cubic-bezier(.2,1.25,.35,1), opacity .5s ease;
  transition-delay: calc(var(--i,0) * 70ms + 150ms);
}
.is-built .pc-shard { transform: none; opacity: 1; }

/* ---------- 3g. Pointer depth: children with --z drift opposite the cursor */
[data-pc-tilt] [style*="--z"] {
  translate: calc(var(--px,0) * var(--z) * -5px) calc(var(--py,0) * var(--z) * -4px);
  transition: translate .5s cubic-bezier(.2,.8,.2,1);
}

/* ---------- 4. Motion + accessibility ------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .pc-sheet, .pc-lift, .pc-popup .pc-flap, .pc-unfold > * { transition: none !important; }
  .pc-popup .pc-flap, .pc-unfold > * { --pc-open: 1 !important; }
  .pc-stack-art path { transform: none !important; }
  .pc-shard { transform: none !important; opacity: 1 !important; transition: none !important; }
  [data-pc-tilt] [style*="--z"] { translate: none !important; }
  .pc-cut-wave, .pc-cut-wave .pc-cut-fill { animation: none !important; }
}
.pc-sheet:focus-visible, .pc-hover:focus-visible { outline: 2px solid var(--pc-accent); outline-offset: 3px; }
.pc-sr { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }
