/* =============================================================
   THE NIGHT MERCHANT — ATELIER LAYER (added 2026-09-26)
   The dynamic layer, requested by Richard 2026-09-26 ("as dynamic
   as possible, real wow factor"). Everything here is additive: no
   existing selector is overridden except where noted. Loaded after
   night-merchant.css by a <link> in _theme.face; behavior lives in
   js/nm-atelier.js.

   Motion is OFF under prefers-reduced-motion and when the visitor
   turns it off (html.nm-still, shared with the homepage toggle).
   Pointer-only effects (tilt, gaslight, loupe) require a fine
   pointer; touch devices get the static, still-beautiful version.

   Contents
     1. Page-turn transitions (cross-document View Transitions)
     2. Gaslight (lamplight that follows the pointer)
     3. Reading rule (scroll progress under the header)
     4. Engraved plates: tilt + gilt sheen
     5. "Examine" quick view (button + dialog)
     6. Loupe (magnifying lens on the product photo)
     7. Purchase bar (sticky add-to-cart)
     8. Wax seal (confirmation when the cart count rises)
     9. Ledger ("Recently examined")
    10. Homepage: dust motes + ink-bleed title
    11. Staggered plate entrance
    12. Reduced motion / still mode
   ============================================================= */

/* 1. PAGE-TURN TRANSITIONS ---------------------------------------
   Same-origin navigations cross-fade through a sepia ink wash.
   Browsers without cross-document View Transitions ignore this. */
@view-transition { navigation: auto; }

.nm-header { view-transition-name: nm-header; }

::view-transition-old(root) {
  animation: nm-page-out 0.28s cubic-bezier(0.4, 0, 1, 1) both;
}
::view-transition-new(root) {
  animation: nm-page-in 0.5s cubic-bezier(0, 0, 0.2, 1) both;
}
@keyframes nm-page-out {
  to { opacity: 0; filter: sepia(0.7) blur(3px); }
}
@keyframes nm-page-in {
  from { opacity: 0; filter: sepia(0.7) blur(3px); }
}

/* 2. GASLIGHT ------------------------------------------------------
   One composited layer moved with transform: cheap to animate. */
.nm-gaslight {
  position: fixed;
  top: 0;
  left: 0;
  width: 1100px;
  height: 1100px;
  margin: -550px 0 0 -550px;
  pointer-events: none;
  z-index: 950;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 206, 128, 0.2) 0%, rgba(255, 190, 110, 0.08) 32%, rgba(255, 190, 110, 0) 62%);
  mix-blend-mode: soft-light;
  opacity: 0;
  transition: opacity 0.8s ease;
  will-change: transform;
}
html.nm-gas-on .nm-gaslight { opacity: 1; }

/* 3. READING RULE ------------------------------------------------- */
.nm-reading-rule {
  position: fixed;
  left: 0;
  top: var(--nm-rule-top, var(--nm-header-height, 80px));
  width: 100%;
  height: 2px;
  z-index: 1001;
  pointer-events: none;
  transform-origin: 0 50%;
  transform: scaleX(var(--nm-progress, 0));
  background: linear-gradient(90deg, var(--nm-antique-gold, #9B7D3A), var(--nm-crimson-ink, #8B1F1F));
  box-shadow: 0 0 6px rgba(155, 125, 58, 0.45);
  opacity: 0;
  transition: opacity 0.3s ease;
}
html.nm-reading .nm-reading-rule { opacity: 1; }

/* 4. ENGRAVED PLATES: TILT + GILT SHEEN ---------------------------- */
.nm-product-image-frame::after,
.nm-plate-image-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background:
    radial-gradient(circle at var(--nm-sx, 50%) var(--nm-sy, 50%), rgba(255, 234, 180, 0.34), rgba(255, 234, 180, 0) 42%),
    linear-gradient(115deg, rgba(255, 255, 255, 0) 40%, rgba(255, 240, 200, 0.12) 50%, rgba(255, 255, 255, 0) 60%);
  mix-blend-mode: overlay;
  opacity: 0;
  transition: opacity 0.45s ease;
}
.nm-plate-image-frame { position: relative; }

@media (hover: hover) and (pointer: fine) {
  html:not(.nm-still) .nm-product-image-frame,
  html:not(.nm-still) .nm-plate-image-frame {
    transform: perspective(900px) rotateX(var(--nm-rx, 0deg)) rotateY(var(--nm-ry, 0deg));
    transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1), border-color 0.25s ease;
  }
  html:not(.nm-still) .nm-tilting {
    transition: transform 0.08s linear, border-color 0.25s ease;
  }
  html:not(.nm-still) .nm-tilting::after { opacity: 1; }
}

/* 5. EXAMINE QUICK VIEW ------------------------------------------- */
.nm-product-plate { position: relative; }

.nm-examine {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  font-family: var(--nm-font-body);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--nm-parchment, #EDE4CC);
  background: rgba(26, 18, 9, 0.86);
  border: 1px solid var(--nm-antique-gold, #9B7D3A);
  border-radius: 0;
  cursor: pointer;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.25s ease, transform 0.25s ease, background-color 0.2s ease;
}
.nm-examine svg { width: 14px; height: 14px; }
.nm-product-plate:hover .nm-examine,
.nm-product-plate:focus-within .nm-examine,
.nm-examine:focus-visible {
  opacity: 1;
  transform: none;
}
.nm-examine:hover { background: var(--nm-crimson-ink, #8B1F1F); }
.nm-examine:focus-visible { outline: 2px solid var(--nm-antique-gold, #9B7D3A); outline-offset: 2px; }
@media (hover: none) {
  .nm-examine { opacity: 1; transform: none; padding: 6px 10px; }
}

.nm-examine-dialog {
  /* Zoho's style.css resets dialog margins; re-centre explicitly */
  position: fixed;
  inset: 0;
  margin: auto;
  height: fit-content;
  width: min(980px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--nm-antique-gold, #9B7D3A);
  background-color: var(--nm-aged-paper, #C8B89A);
  background-image: url('../images/textures/paper-grain.png');
  color: var(--nm-ink-night, #1A1209);
  box-shadow: 0 30px 80px rgba(10, 6, 2, 0.6);
  overflow: auto;
}
.nm-examine-dialog::backdrop {
  background: radial-gradient(circle at 50% 40%, rgba(26, 18, 9, 0.62), rgba(10, 6, 2, 0.88));
}
.nm-examine-dialog[open] { animation: nm-dialog-in 0.4s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.nm-examine-dialog[open]::backdrop { animation: nm-fade-in 0.4s ease both; }
@keyframes nm-dialog-in {
  from { opacity: 0; transform: translateY(18px) scale(0.98); filter: sepia(0.6); }
}
@keyframes nm-fade-in { from { opacity: 0; } }

.nm-ex-inner {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 36px;
  padding: 40px;
  outline: 1px solid rgba(155, 125, 58, 0.35);
  outline-offset: -12px;
}
.nm-ex-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  font: 28px/1 var(--nm-font-display);
  color: var(--nm-ink-night, #1A1209);
  background: transparent;
  border: 0;
  cursor: pointer;
}
.nm-ex-close:hover { color: var(--nm-crimson-ink, #8B1F1F); }
.nm-ex-close:focus-visible { outline: 2px solid var(--nm-crimson-ink, #8B1F1F); }
.nm-ex-stage {
  position: relative;
  border: 1px solid rgba(155, 125, 58, 0.45);
  padding: 8px;
  background: var(--nm-ink-night, #1A1209);
  line-height: 0;
}
.nm-ex-main {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  transition: opacity 0.3s ease;
}
.nm-ex-main.nm-loading { opacity: 0.35; }
.nm-ex-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.nm-ex-thumb {
  width: 64px;
  height: 64px;
  padding: 0;
  border: 1px solid rgba(155, 125, 58, 0.4);
  background: var(--nm-ink-night, #1A1209);
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s ease, border-color 0.2s ease;
}
.nm-ex-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.nm-ex-thumb[aria-current="true"],
.nm-ex-thumb:hover { opacity: 1; border-color: var(--nm-antique-gold, #9B7D3A); }
.nm-ex-thumb:focus-visible { outline: 2px solid var(--nm-crimson-ink, #8B1F1F); outline-offset: 2px; }
.nm-ex-info { display: flex; flex-direction: column; justify-content: center; }
.nm-ex-kicker {
  margin: 0 0 10px;
  font-family: var(--nm-font-body);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--nm-antique-gold, #9B7D3A);
}
.nm-ex-title {
  margin: 0;
  font-family: var(--nm-font-display);
  font-size: clamp(1.6rem, 3vw, 2.3rem);
  font-weight: 400;
  line-height: 1.15;
}
.nm-ex-rule {
  width: 72px;
  height: 1px;
  margin: 18px 0;
  border: 0;
  background: var(--nm-crimson-ink, #8B1F1F);
}
.nm-ex-price {
  margin: 0 0 18px;
  font-family: var(--nm-font-body);
  font-size: 1.3rem;
  color: var(--nm-crimson-ink, #8B1F1F);
}
.nm-ex-desc {
  margin: 0 0 26px;
  font-family: var(--nm-font-body);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--nm-press-charcoal, #2D2416);
  max-height: 11em;
  overflow: auto;
}
.nm-ex-desc:empty { display: none; }
.nm-ex-cta {
  align-self: flex-start;
  display: inline-block;
  padding: 14px 26px;
  font-family: var(--nm-font-body);
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--nm-parchment, #EDE4CC);
  background: var(--nm-crimson-ink, #8B1F1F);
  border: 1px solid var(--nm-crimson-ink, #8B1F1F);
  transition: background-color 0.2s ease, color 0.2s ease;
}
.nm-ex-cta:hover { background: var(--nm-ink-night, #1A1209); color: var(--nm-parchment, #EDE4CC); text-decoration: none; }
.nm-ex-cta:focus-visible { outline: 2px solid var(--nm-antique-gold, #9B7D3A); outline-offset: 3px; }
@media (max-width: 760px) {
  .nm-ex-inner { grid-template-columns: 1fr; gap: 22px; padding: 56px 20px 28px; }
  .nm-ex-desc { max-height: none; }
}
html.nm-dialog-open { overflow: hidden; }

/* 6. LOUPE ---------------------------------------------------------- */
.nm-loupe-host { position: relative; cursor: zoom-in; }
.nm-loupe {
  position: absolute;
  top: 0;
  left: 0;
  width: 200px;
  height: 200px;
  margin: -100px 0 0 -100px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 5;
  background-color: var(--nm-ink-night, #1A1209);
  background-repeat: no-repeat;
  border: 3px solid #b8964d;
  box-shadow:
    0 0 0 1px #5a4520,
    0 0 0 6px rgba(155, 125, 58, 0.55),
    0 14px 34px rgba(10, 6, 2, 0.55),
    inset 0 0 22px rgba(10, 6, 2, 0.45);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.nm-loupe::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0) 38%);
}
.nm-loupe.nm-on { opacity: 1; transform: scale(1); }
.nm-loupe-hint {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 4;
  padding: 5px 10px;
  font-family: var(--nm-font-body);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--nm-parchment, #EDE4CC);
  background: rgba(26, 18, 9, 0.78);
  border: 1px solid rgba(155, 125, 58, 0.6);
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.nm-loupe-host:hover .nm-loupe-hint { opacity: 0; }
@media (hover: none), (pointer: coarse) {
  .nm-loupe, .nm-loupe-hint { display: none; }
  .nm-loupe-host { cursor: auto; }
}

/* 7. PURCHASE BAR --------------------------------------------------- */
.nm-buybar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1100;
  background-color: var(--nm-ink-night, #1A1209);
  color: var(--nm-parchment, #EDE4CC);
  border-top: 1px solid var(--nm-antique-gold, #9B7D3A);
  box-shadow: 0 -10px 30px rgba(10, 6, 2, 0.35);
  transform: translateY(110%);
  transition: transform 0.4s cubic-bezier(0.2, 0.7, 0.2, 1);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nm-buybar.nm-on { transform: none; }
.nm-buybar-inner {
  max-width: var(--nm-max-width, 1200px);
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.nm-buybar-thumb {
  width: 48px;
  height: 48px;
  flex: none;
  object-fit: cover;
  border: 1px solid rgba(155, 125, 58, 0.5);
}
.nm-buybar-text { flex: 1; min-width: 0; }
.nm-buybar-name {
  display: block;
  font-family: var(--nm-font-display);
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nm-buybar-price { font-family: var(--nm-font-body); font-size: 0.95rem; color: #d9b36a; }
.nm-buybar-btn {
  flex: none;
  min-height: 44px;
  padding: 10px 24px;
  font-family: var(--nm-font-body);
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--nm-parchment, #EDE4CC);
  background: var(--nm-crimson-ink, #8B1F1F);
  border: 1px solid var(--nm-crimson-ink, #8B1F1F);
  border-radius: 0;
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.nm-buybar-btn:hover { background: #a42626; }
.nm-buybar-btn:focus-visible { outline: 2px solid var(--nm-antique-gold, #9B7D3A); outline-offset: 2px; }
@media (max-width: 600px) {
  .nm-buybar-inner { padding: 10px 16px; gap: 12px; }
  .nm-buybar-thumb { width: 40px; height: 40px; }
  .nm-buybar-btn { padding: 10px 16px; }
}

/* 8. WAX SEAL -------------------------------------------------------- */
.nm-seal-toast {
  position: fixed;
  right: 24px;
  top: calc(var(--nm-header-height, 80px) + 18px);
  z-index: 1300;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 14px 20px 14px 14px;
  background-color: var(--nm-aged-paper, #C8B89A);
  background-image: url('../images/textures/paper-grain.png');
  border: 1px solid var(--nm-antique-gold, #9B7D3A);
  box-shadow: 0 18px 40px rgba(10, 6, 2, 0.4);
  font-family: var(--nm-font-body);
  color: var(--nm-ink-night, #1A1209);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
}
.nm-seal-toast.nm-on { opacity: 1; transform: none; pointer-events: auto; }
.nm-seal-toast a { color: var(--nm-crimson-ink, #8B1F1F); }
.nm-seal {
  width: 58px;
  height: 58px;
  flex: none;
  filter: drop-shadow(0 3px 3px rgba(40, 6, 6, 0.45));
}
.nm-seal-toast.nm-on .nm-seal { animation: nm-stamp 0.55s cubic-bezier(0.3, 1.6, 0.5, 1) both; }
@keyframes nm-stamp {
  0% { transform: scale(2.2) rotate(-24deg); opacity: 0; }
  60% { transform: scale(0.92) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) rotate(-8deg); }
}
.nm-seal-title { display: block; font-family: var(--nm-font-display); font-size: 1.1rem; }
.nm-seal-sub { display: block; font-size: 0.9rem; margin-top: 2px; }
.nm-cart-bump { animation: nm-bump 0.6s ease; }
@keyframes nm-bump {
  30% { transform: scale(1.35); }
  60% { transform: scale(0.92); }
}

/* 9. LEDGER: RECENTLY EXAMINED -------------------------------------- */
.nm-ledger {
  max-width: var(--nm-max-width, 1200px);
  margin: 72px auto 48px;
  padding: 0 24px;
}
.nm-ledger-head {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 22px;
}
.nm-ledger-title {
  margin: 0;
  font-family: var(--nm-font-display);
  font-size: 1.6rem;
  font-weight: 400;
  white-space: nowrap;
}
.nm-ledger-head::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, rgba(155, 125, 58, 0.7), rgba(155, 125, 58, 0));
}
.nm-ledger-clear {
  order: 3;
  font-family: var(--nm-font-body);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--nm-press-charcoal, #2D2416);
  background: none;
  border: 0;
  cursor: pointer;
  min-height: 44px;
}
.nm-ledger-clear:hover { color: var(--nm-crimson-ink, #8B1F1F); }
.nm-ledger-list {
  list-style: none;
  margin: 0;
  padding: 4px 2px 14px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(150px, 170px);
  gap: 24px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: var(--nm-antique-gold, #9B7D3A) transparent;
}
.nm-ledger-item { scroll-snap-align: start; }
.nm-ledger-link { display: block; color: inherit; text-decoration: none; }
.nm-ledger-link:hover { text-decoration: none; }
.nm-ledger-frame {
  display: block;
  padding: 5px;
  background: var(--nm-ink-night, #1A1209);
  border: 1px solid rgba(155, 125, 58, 0.35);
  line-height: 0;
  transition: border-color 0.25s ease, transform 0.25s ease;
}
.nm-ledger-frame img { width: 100%; height: auto; aspect-ratio: 1 / 1; object-fit: cover; display: block; }
.nm-ledger-link:hover .nm-ledger-frame,
.nm-ledger-link:focus-visible .nm-ledger-frame { border-color: var(--nm-crimson-ink, #8B1F1F); transform: translateY(-3px); }
.nm-ledger-name {
  display: block;
  margin-top: 10px;
  font-family: var(--nm-font-body);
  font-size: 0.95rem;
  line-height: 1.35;
}
.nm-ledger-price { display: block; margin-top: 4px; font-family: var(--nm-font-body); font-size: 0.9rem; color: var(--nm-crimson-ink, #8B1F1F); }

/* 10. HOMEPAGE: DUST MOTES + INK-BLEED TITLE ------------------------ */
.nm-motes {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: screen;
}
.nm-ink-letter {
  display: inline-block;
  white-space: pre;
  animation: nm-ink-bleed 1.1s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  animation-delay: calc(var(--i) * 55ms + 150ms);
}
@keyframes nm-ink-bleed {
  0% { opacity: 0; filter: blur(10px); transform: translateY(8px) scale(1.06); }
  55% { opacity: 1; filter: blur(1.5px); }
  100% { opacity: 1; filter: none; transform: none; }
}
.nm-inked { animation: none !important; }

/* 11. STAGGERED PLATE ENTRANCE -------------------------------------
   The existing scroll reveal (.nm-reveal -> .nm-in, _theme.face) fades
   plates up; JS sets --nm-d to each plate's column so a row arrives
   left to right, like plates laid out on a table. */
html:not(.nm-still) .nm-product-plate.nm-reveal,
html:not(.nm-still) .nm-plate.nm-reveal {
  transition-delay: calc(var(--nm-d, 0) * 90ms);
}
html:not(.nm-still) .nm-product-plate.nm-reveal.nm-in:hover {
  transition-delay: 0s;
}

/* 404: OTHER WAYS IN ------------------------------------------------ */
.nm-error-paths { margin-top: 44px; }
.nm-error-paths-label {
  margin: 0 0 14px;
  font-family: var(--nm-font-body);
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--nm-antique-gold, #9B7D3A);
}
.nm-error-paths ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 26px;
}
.nm-error-paths a {
  display: inline-block;
  padding: 8px 0;
  font-family: var(--nm-font-display);
  font-size: 1.1rem;
  color: var(--nm-ink-night, #1A1209);
  text-decoration: none;
  background-image: linear-gradient(var(--nm-crimson-ink, #8B1F1F), var(--nm-crimson-ink, #8B1F1F));
  background-size: 0 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size 0.3s ease, color 0.2s ease;
}
.nm-error-paths a:hover,
.nm-error-paths a:focus-visible { color: var(--nm-crimson-ink, #8B1F1F); background-size: 100% 1px; }

/* 12. REDUCED MOTION / STILL MODE ----------------------------------- */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none; }
  .nm-gaslight, .nm-motes, .nm-reading-rule { display: none; }
  .nm-ink-letter, .nm-seal-toast.nm-on .nm-seal,
  .nm-examine-dialog[open], .nm-examine-dialog[open]::backdrop { animation: none; }
  .nm-product-image-frame, .nm-plate-image-frame { transform: none !important; }
}
html.nm-still .nm-gaslight,
html.nm-still .nm-motes { display: none; }
html.nm-still .nm-ink-letter { animation: none; }
html.nm-still ::view-transition-old(root),
html.nm-still ::view-transition-new(root) { animation-duration: 0.01s; }
