/* ============================================================
   Derick James — polish layer styles (pairs with magic.js)
   Everything is prefixed .mj- and only shows once magic.js
   has added html.mj.
   ============================================================ */

/* ---------- top scroll-progress line ---------- */
.mj-progress {
  position: fixed; top: 0; left: 0; height: 2px; width: 100%;
  transform: scaleX(0); transform-origin: 0 50%;
  background: linear-gradient(90deg, rgba(148, 163, 184, 0.9), var(--accent));
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.55);
  z-index: 260; pointer-events: none; will-change: transform;
}

/* ---------- soft cursor glow (desktop only) ---------- */
.mj-spot {
  position: fixed; top: 0; left: 0; width: 520px; height: 520px;
  margin: -260px 0 0 -260px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, rgba(0, 229, 255, 0.075), rgba(0, 229, 255, 0.025) 45%, transparent 70%);
  z-index: 5; opacity: 0; transition: opacity 0.6s ease; will-change: transform;
}
html.mj-cursor-live .mj-spot { opacity: 1; }

/* ---------- hero: neural canvas + headline mask ---------- */
.mj-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 1; opacity: 0.85;
  -webkit-mask-image: radial-gradient(ellipse 78% 72% at 50% 46%, #000 30%, transparent 88%);
  mask-image: radial-gradient(ellipse 78% 72% at 50% 46%, #000 30%, transparent 88%);
}
.hero-title .mj-line { display: block; overflow: hidden; padding-bottom: 0.08em; margin-bottom: -0.08em; }
.hero-title .mj-line > span { display: block; will-change: transform, opacity; }

/* ---------- glass panels: pointer glow ---------- */
html.mj .mj-glow { position: relative; isolation: isolate; }
html.mj .mj-glow > .mj-glow-layer {
  position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: -1;
  background: radial-gradient(360px circle at var(--mj-mx, 50%) var(--mj-my, 50%), rgba(0, 229, 255, 0.12), transparent 62%);
  opacity: 0; transition: opacity 0.5s var(--ease);
}
html.mj .mj-glow:hover > .mj-glow-layer { opacity: 1; }

/* ---------- 3D cover tilt + sheen (book cards) ---------- */
html.mj .mj-tilt3d {
  transform: perspective(1100px) rotateX(var(--mj-rx, 0deg)) rotateY(var(--mj-ry, 0deg));
  transition: transform 0.55s var(--ease), box-shadow 0.5s var(--ease);
}
html.mj .mj-tilt3d.mj-tilt-active { box-shadow: 0 36px 70px rgba(0, 0, 0, 0.65), 0 0 40px rgba(0, 229, 255, 0.3); }
html.mj .mj-host { position: relative; }
.mj-sheen {
  position: absolute; pointer-events: none; border-radius: 12px; opacity: 0;
  background: linear-gradient(115deg, transparent 32%, rgba(234, 239, 245, 0.16) 46%, rgba(0, 229, 255, 0.22) 52%, transparent 68%);
  background-size: 260% 260%; background-position: var(--mj-sheen-x, 0%) var(--mj-sheen-y, 0%);
  transition: opacity 0.55s var(--ease); z-index: 4;
}
.mj-sheen.mj-sheen-on { opacity: 1; }

/* ---------- page fade ---------- */
.mj-fade {
  position: fixed; inset: 0; z-index: 9990; pointer-events: none;
  background: var(--bg); opacity: 0; transition: opacity 0.26s ease;
}
html.mj-leaving .mj-fade { opacity: 1; }

/* ---------- toast ---------- */
.mj-toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 24px);
  z-index: 9994; pointer-events: none; opacity: 0; max-width: calc(100vw - 32px); text-align: center;
  background: rgba(9, 12, 18, 0.9); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 229, 255, 0.35); border-radius: 12px; padding: 12px 18px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 11.5px; letter-spacing: 0.1em;
  color: var(--text); box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5), 0 0 30px rgba(0, 229, 255, 0.18);
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}
.mj-toast.mj-toast-on { opacity: 1; transform: translate(-50%, 0); }
.mj-toast.mj-toast-err { border-color: rgba(255, 138, 155, 0.5); }

/* ---------- easter egg ---------- */
.mj-egg { position: fixed; inset: 0; z-index: 9995; display: grid; place-items: center; pointer-events: none; opacity: 0; transition: opacity 0.6s ease; }
.mj-egg.mj-egg-on { opacity: 1; }
.mj-egg-scan {
  position: absolute; left: 0; right: 0; height: 34vh; top: -34vh;
  background: linear-gradient(180deg, transparent, rgba(0, 229, 255, 0.14), transparent);
  border-top: 1px solid rgba(0, 229, 255, 0.5); border-bottom: 1px solid rgba(0, 229, 255, 0.5);
}
.mj-egg.mj-egg-on .mj-egg-scan { animation: mjScan 1.6s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
@keyframes mjScan { to { top: 100vh; } }
.mj-egg-text {
  font-family: var(--display); font-weight: 700; font-size: clamp(18px, 3.2vw, 34px); letter-spacing: 0.3em;
  text-transform: uppercase; color: var(--accent); text-align: center; padding: 0 24px;
  text-shadow: 0 0 30px rgba(0, 229, 255, 0.6);
}
.mj-egg-text small { display: block; margin-top: 10px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px; letter-spacing: 0.3em; color: rgba(234, 239, 245, 0.7); }

html.mj-touch .mj-spot { display: none; }
@media (prefers-reduced-motion: reduce) {
  .mj-spot, .mj-egg-scan { display: none; }
}

/* ============================================================================
   HARDCOVER — the cover opens on its spine (built by assets/book-open.js)
   ============================================================================ */
@keyframes mjBookFloat {
  0%, 100% { transform: translateY(0) rotateY(-4deg) rotateX(2deg); }
  50%      { transform: translateY(-14px) rotateY(4deg) rotateX(-2deg); }
}

html.mj .mj-book {
  position: relative; width: 320px; max-width: 100%; aspect-ratio: 604 / 820;
  flex: none; align-self: center;
  transform-style: preserve-3d; cursor: pointer;
  animation: mjBookFloat 7s ease-in-out infinite;
}
/* hold still while the visitor is interacting, so the hover never flickers */
html.mj .mj-book:hover, html.mj .mj-book.mj-book-open { animation-play-state: paused; }
html.mj .mj-book-inner {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transform: scale(1) translateX(0);
  transition: transform 1.05s var(--ease);
}
html.mj .mj-book-open .mj-book-inner { transform: scale(0.88) translateX(6%); }

html.mj .mj-book-pages,
html.mj .mj-book-flap { position: absolute; inset: 0; }
html.mj .mj-book-pages {
  inset: 2px 5px 2px 2px; border-radius: 0 8px 8px 0;
  background: linear-gradient(178deg, #f4f1ea, #e4e0d6 52%, #cfcbc0);
  box-shadow: 0 22px 44px rgba(0, 0, 0, 0.5);
  transition: box-shadow 0.9s ease;
}
html.mj .mj-book-open .mj-book-pages {
  box-shadow: 0 26px 54px rgba(0, 0, 0, 0.6), inset 34px 0 46px -24px rgba(0, 0, 0, 0.75);
}
html.mj .mj-book-stack {
  position: absolute; top: 3px; bottom: 3px; right: 0; width: 5px; border-radius: 0 4px 4px 0;
  background: repeating-linear-gradient(90deg, #cdc9be 0 1px, #f7f5ef 1px 2px);
  box-shadow: 1px 0 0 rgba(255, 255, 255, 0.35);
}
html.mj .mj-book-page {
  position: absolute; inset: 0 8px 0 0; border-radius: 0 6px 6px 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 24px 20px;
  background: linear-gradient(120deg, #fbfaf6 0%, #efece4 58%, #dedad0 100%);
  box-shadow: inset 20px 0 30px -20px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(0, 0, 0, 0.04);
}
html.mj .mj-book-kicker { margin: 0 0 12px; font-family: var(--body); font-size: 8.5px; font-weight: 600; letter-spacing: 0.34em; text-transform: uppercase; color: #8d8779; }
html.mj .mj-book-title { margin: 0; font-family: var(--display); font-size: 25px; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; color: #141a22; }
html.mj .mj-book-rule { width: 46px; height: 1px; margin: 14px auto; background: linear-gradient(90deg, transparent, #b9b3a5, transparent); }
html.mj .mj-book-author { margin: 0; font-family: var(--body); font-size: 10.5px; font-weight: 700; letter-spacing: 0.4em; text-transform: uppercase; color: #3d4650; }
html.mj .mj-book-folio { margin: 16px 0 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 8.5px; letter-spacing: 0.3em; text-transform: uppercase; color: #918b7e; }
html.mj .mj-book-emblem { width: 82px; height: auto; margin: 0 0 16px; opacity: 0.5; filter: grayscale(1) brightness(0.35) contrast(1.3); }

html.mj .mj-book-leaf {
  position: absolute; inset: 0 6px 0 0; border-radius: 0 4px 4px 0;
  background: linear-gradient(100deg, #f8f6f0, #e9e5db);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.16);
  transform-origin: left center; transform: rotateY(0deg);
  transition: transform 0.85s var(--ease) 0.22s;
}
html.mj .mj-book-leaf-b { background: linear-gradient(100deg, #f5f2ec, #e3dfd5); }
html.mj .mj-book-open .mj-book-leaf   { transform: rotateY(-21deg); transition-delay: 0.3s; }
html.mj .mj-book-open .mj-book-leaf-b { transform: rotateY(-13deg); transition-delay: 0.46s; }

html.mj .mj-book-flap {
  transform-origin: left center; transform-style: preserve-3d;
  transform: rotateY(var(--mj-open, 0deg));
  transition: transform 1.1s var(--ease);
}
html.mj .mj-book-open .mj-book-flap { --mj-open: -118deg; }
html.mj .mj-book-flap .book-cover {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  border-radius: 3px 10px 10px 3px; backface-visibility: hidden;
}
html.mj .mj-book-endpaper {
  position: absolute; inset: 0; border-radius: 10px 3px 3px 10px;
  transform: rotateY(180deg); backface-visibility: hidden;
  display: grid; place-items: center;
  background:
    radial-gradient(120% 90% at 78% 22%, rgba(0, 229, 255, 0.10), transparent 62%),
    linear-gradient(160deg, #0c121b, #06090e 72%);
  border: 1px solid rgba(0, 229, 255, 0.16);
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.8);
}
html.mj .mj-book-endpaper::before {
  content: ""; position: absolute; inset: 0; opacity: 0.5;
  background:
    repeating-linear-gradient(0deg, rgba(0, 229, 255, 0.055) 0 1px, transparent 1px 44px),
    repeating-linear-gradient(90deg, rgba(0, 229, 255, 0.055) 0 1px, transparent 1px 44px);
}
html.mj .mj-book-emblem-ghost { position: relative; width: 108px; margin: 0; opacity: 0.32; filter: none; }

html.mj .mj-book:focus-visible { outline: 1px solid var(--accent); outline-offset: 12px; border-radius: 10px; }
html.mj .mj-book-hint {
  position: absolute; left: 50%; bottom: -30px; transform: translateX(-50%);
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 10px; letter-spacing: 0.28em; text-transform: uppercase;
  color: rgba(234, 239, 245, 0.5); white-space: nowrap;
  transition: opacity 0.6s ease;
}
html.mj .mj-book-seen .mj-book-hint { opacity: 0; }

@media (max-width: 1200px) {
  html.mj .mj-book-open .mj-book-flap { --mj-open: -104deg; }
  html.mj .mj-book-open .mj-book-inner { transform: scale(0.86) translateX(14%); }
}
@media (max-width: 900px) {
  html.mj .mj-book { animation: none; }
  html.mj .mj-book-open .mj-book-inner { transform: scale(0.92) translateX(8%); }
}
@media (max-width: 560px) {
  html.mj .mj-book-open .mj-book-inner { transform: scale(0.8) translateX(6%); }
}
@media (prefers-reduced-motion: reduce) {
  html.mj .mj-book { animation: none; }
  html.mj .mj-book-flap, html.mj .mj-book-inner, html.mj .mj-book-leaf { transition-duration: 0.01s; transition-delay: 0s; }
}
