/* ambient.css — page-wide atmosphere (js/ambient*.js). Decorative layers never take pointer
   events, never take part in layout, and sit under the page content unless they are the pen. */

/* ---------- layers ---------- */
.amb-layer { position: absolute; left: 0; top: 0; width: 100%; height: 0; pointer-events: none; z-index: 1; }
/* marginalia and the pen never widen the page: clip sideways, never vertically
   (a phone would otherwise zoom out to fit a note that strays past the right edge) */
.amb-layer { overflow-x: clip; overflow-y: visible; }
.amb-layer > * { position: absolute; left: 0; top: 0; pointer-events: none; }
.amb-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.amb-note canvas { display: block; }

/* ---------- the pen as cursor ---------- */
/* the trace: fixed, painted over the paper but under every word (z-index -1 in the root context) */
.amb-trace { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: -1; pointer-events: none; }
.amb-nib { position: fixed; left: 0; top: 0; z-index: 2147483000; pointer-events: none; opacity: 0; transition: opacity .16s ease; will-change: transform; filter: drop-shadow(3px 5px 2.5px rgba(var(--shadow-rgb), .16)); }
.amb-nib canvas { display: block; }
/* the system cursor gives way to the nib over bare paper and figures; text and controls keep theirs */
html.amb-pen, html.amb-pen body { cursor: none; }
html.amb-pen :is(p, li, dd, dt, h1, h2, h3, h4, figcaption, address, blockquote, td, th, .amb-txt, .say, .bubble) { cursor: text; }
html.amb-pen :is(a, button, [role=button], [role=tab], label, summary, select) { cursor: pointer; }
html.amb-pen :is(input, textarea) { cursor: text; }
html.amb-pen :is(a, button, [role=button], [role=tab]) * { cursor: inherit; }

/* ---------- headings soaking in ---------- */
.amb-inking { will-change: filter; }

/* ---------- rubber-stamped sheet labels ---------- */
.amb-stamp {
  position: relative; display: inline-block; color: var(--ink);
  transform: translateX(var(--dx, 0)) rotate(var(--rot, -1deg)); transform-origin: 40% 60%;
  filter: url(#amb-stamp-ink); letter-spacing: .2em; font-weight: 500;
  margin-left: 8px; /* the frame (::before) reaches 8px left of the text: keep it on the column edge, not in the margin */
}
.amb-stamp::before {
  content: ""; position: absolute; inset: -5px -9px -4px -8px; border: 1.6px solid currentColor; border-radius: 3px;
  box-shadow: inset 0 0 0 2.5px transparent, inset 0 0 0 3.3px currentColor; opacity: .82;
}
.amb-stamp-wait { opacity: 0; }
.amb-stamping { animation: amb-thump .42s cubic-bezier(.3, .7, .3, 1) both; }
.amb-stamping::after {
  /* the squash of ink at the moment of contact */
  content: ""; position: absolute; inset: -8px -12px -7px -11px; border-radius: 4px;
  background: radial-gradient(closest-side, rgba(var(--ink-rgb), .16), transparent); animation: amb-squash .5s ease-out both;
}
@keyframes amb-thump {
  0% { opacity: 0; transform: translateX(var(--dx, 0)) translateY(-3px) rotate(calc(var(--rot, -1deg) - 7deg)) scale(1.85); }
  45% { opacity: .7; }
  62% { opacity: 1; transform: translateX(var(--dx, 0)) rotate(var(--rot, -1deg)) scale(.95); }
  80% { transform: translateX(var(--dx, 0)) rotate(var(--rot, -1deg)) scale(1.015); }
  100% { opacity: 1; transform: translateX(var(--dx, 0)) rotate(var(--rot, -1deg)) scale(1); }
}
@keyframes amb-squash { 0%, 55% { opacity: 0; transform: scale(.9); } 65% { opacity: 1; } 100% { opacity: 0; transform: scale(1.12); } }

/* ---------- a pen that writes the marginalia and rules the dividers ---------- */
.amb-ghost { z-index: 3; transition: opacity .5s ease, translate .6s cubic-bezier(.2, .7, .3, 1); filter: drop-shadow(2px 4px 2px rgba(var(--shadow-rgb), .14)); }
.amb-ghost canvas { display: block; }
.amb-ghost.lift { opacity: 0; translate: 26px -30px; }

/* ---------- sheets: seams, vignette ---------- */

.amb-seam { width: 100%; height: 30px; margin-top: -1px; transform-origin: 50% 0;
  background:
    linear-gradient(rgba(var(--shadow-seam-rgb), .085), rgba(var(--shadow-seam-rgb), .028) 9px, transparent 30px),
    linear-gradient(90deg, transparent, rgba(var(--ink-rgb), .12) 8%, rgba(var(--ink-rgb), .12) 92%, transparent) top / 100% 1px no-repeat;
}
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* the sheet above lifts a little as its edge passes: a scroll-driven shadow, no JavaScript */
    .amb-seam { animation: amb-lift linear both; animation-timeline: view(); animation-range: cover 0% cover 100%; }
    @keyframes amb-lift { from { opacity: .35; transform: scaleY(.55); } 55% { opacity: 1; transform: scaleY(1.25); } to { opacity: .55; transform: scaleY(.8); } }
  }
}
.amb-vignette { position: fixed; inset: 0; z-index: -1; pointer-events: none; box-shadow: inset 0 0 140px rgba(var(--shadow-vignette-rgb), .075), inset 0 0 36px rgba(var(--shadow-vignette-rgb), .04); }
@media (max-width: 640px) { .amb-vignette { box-shadow: inset 0 0 60px rgba(var(--shadow-vignette-rgb), .06); } }

/* ---------- 404: the pen that keeps trying ---------- */
.amb-404 .lost .cv { max-width: 560px; cursor: pointer; border-radius: 4px; }
.amb-attempt { transition: opacity .9s ease, filter .9s ease; }
.amb-attempt.gone { opacity: 0; filter: blur(1.2px); }
.amb-rest { position: absolute; left: 30%; top: 80%; width: 0; height: 0; transform: rotate(-112deg); transition: opacity .4s ease, transform .4s ease; filter: drop-shadow(-4px 3px 2px rgba(var(--shadow-rgb), .18)); }
.amb-rest canvas { position: absolute; left: -12px; top: -2px; }
.amb-rest.up { opacity: 0; transform: rotate(-100deg) translate(-10px, 10px); }

/* ---------- reduced motion: static marks only ---------- */
@media (prefers-reduced-motion: reduce) {
  .amb-stamp-wait { opacity: 1; }
  .amb-stamping, .amb-stamping::after { animation: none; }
  .amb-ghost, .amb-nib, .amb-trace { display: none; }
}
@media print { .amb-layer, .amb-trace, .amb-nib, .amb-vignette { display: none; } .amb-stamp { filter: none; } }
