/* Cinema layer: splash, living background, screen effects and immersive reading. */

html { background: var(--paper); }
body.cinema-bg-on { background: transparent; }

/* ---------------------------------------------------------------- splash */
.splash {
  position: fixed; inset: 0; z-index: 300; display: grid; place-items: center;
  overflow: hidden; background: #0b0c0b; color: #f1f0e8;
  transition: opacity .55s ease, transform .8s cubic-bezier(.76, 0, .24, 1), clip-path .8s cubic-bezier(.76, 0, .24, 1);
}
html.cinema-seen .splash:not(.is-leaving) { display: none !important; }
.splash-aurora span {
  position: absolute; width: 62vmax; height: 62vmax; border-radius: 50%;
  filter: blur(90px); opacity: .4; mix-blend-mode: screen; pointer-events: none;
  animation: splash-aurora 14s ease-in-out infinite alternate;
}
.splash-aurora span:nth-child(1) { background: #23345f; top: -28vmax; left: -18vmax; }
.splash-aurora span:nth-child(2) { background: #154a44; bottom: -34vmax; right: -20vmax; animation-delay: -5s; }
.splash-aurora span:nth-child(3) { background: #5c4220; top: 22vmax; left: 42vmax; opacity: .28; animation-delay: -9s; }
.splash-grain {
  position: absolute; inset: 0; opacity: .06; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
  animation: grain-shift 1.1s steps(4) infinite;
}
.splash-inner { position: relative; z-index: 2; width: min(900px, 88vw); text-align: center; }
.splash-mark {
  display: inline-block; font-size: clamp(64px, 11vw, 132px); line-height: 1;
  color: #f1f0e8; animation: splash-pulse 3.2s ease-in-out infinite;
  text-shadow: 0 0 60px rgba(174, 197, 219, .28);
}
.splash-eyebrow {
  margin: 26px 0 12px; font-size: 11px; letter-spacing: .42em; text-transform: uppercase;
  color: rgba(241, 240, 232, .55); animation: splash-rise .9s .15s both;
}
.splash-eyebrow span { color: rgba(241, 240, 232, .32); }
.splash h1 {
  margin: 0; font-family: var(--serif); font-weight: 400; letter-spacing: -.045em;
  font-size: clamp(58px, 12vw, 148px); line-height: .95; animation: splash-rise 1s .25s both;
}
.splash-intro {
  margin: 22px auto 0; max-width: 520px; color: rgba(241, 240, 232, .64);
  font-size: 14px; line-height: 1.8; animation: splash-rise 1s .4s both;
}
.splash-readout {
  display: flex; justify-content: center; align-items: baseline; gap: 7px;
  margin-top: 34px; color: rgba(241, 240, 232, .5); font-size: 11px; letter-spacing: .18em;
  font-variant-numeric: tabular-nums;
}
.splash-count { color: #f1f0e8; font-size: 13px; letter-spacing: .1em; }
.splash-state { margin-left: 10px; letter-spacing: .14em; }
.splash-percent { color: rgba(241, 240, 232, .32); }
.splash-meter {
  width: min(320px, 58vw); height: 1px; margin: 12px auto 0; background: rgba(241, 240, 232, .18);
  overflow: hidden;
}
.splash-meter span {
  display: block; width: 100%; height: 100%; background: #f1f0e8; transform-origin: left;
  animation: splash-load 2.6s cubic-bezier(.22, 1, .36, 1) both;
}
.splash-actions {
  display: flex; justify-content: center; align-items: center; gap: 18px; margin-top: 30px;
  animation: splash-rise 1s .55s both;
}
.splash-enter {
  border: 1px solid rgba(241, 240, 232, .55); padding: 14px 28px; color: #0b0c0b;
  background: #f1f0e8; font-size: 13px; letter-spacing: .12em; transition: transform .25s ease, background .25s ease;
}
.splash-enter:hover { transform: translateY(-2px); background: #fff; }
.splash-enter span { margin-left: 8px; }
.splash-skip {
  border: 0; padding: 10px 6px; color: rgba(241, 240, 232, .55); font-size: 12px;
  letter-spacing: .1em; text-decoration: underline; text-underline-offset: 5px;
}
.splash-skip:hover { color: #f1f0e8; }
.splash-hint { margin-top: 26px; color: rgba(241, 240, 232, .32); font-size: 11px; letter-spacing: .08em; }
.splash.is-leaving { opacity: 0; transform: scale(1.03); clip-path: inset(0 0 100% 0); pointer-events: none; }
body.splash-lock { overflow: hidden; }

@keyframes splash-rise { from { opacity: 0; transform: translateY(26px); } to { opacity: 1; transform: none; } }
@keyframes splash-pulse { 0%, 100% { transform: scale(1) rotate(0); opacity: .9; } 50% { transform: scale(1.06) rotate(8deg); opacity: 1; } }
@keyframes splash-load { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes splash-aurora { from { transform: translate3d(-4%, -2%, 0) scale(1); } to { transform: translate3d(6%, 5%, 0) scale(1.12); } }
@keyframes grain-shift { 0%, 100% { transform: translate(0, 0); } 25% { transform: translate(-2%, 1%); } 50% { transform: translate(1%, -2%); } 75% { transform: translate(-1%, -1%); } }

/* ---------------------------------------------------------------- living background */
#cinema-bg {
  position: fixed; inset: 0; z-index: -1; width: 100%; height: 100%;
  pointer-events: none; opacity: 0; transition: opacity 1.4s ease;
}
body.cinema-bg-on #cinema-bg { opacity: 1; }

/* ---------------------------------------------------------------- screen effects */
.cinema-spotlight {
  position: fixed; inset: 0; z-index: 3; pointer-events: none; opacity: 0;
  transition: opacity .45s ease;
  background: radial-gradient(520px circle at var(--cx, 50%) var(--cy, 50%),
    color-mix(in srgb, var(--accent) 9%, transparent), transparent 62%);
}
body.cinema-cursor-on .cinema-spotlight { opacity: 1; }
body.cinema-grain::after {
  content: ""; position: fixed; inset: 0; z-index: 4; pointer-events: none; opacity: .028;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.6'/%3E%3C/svg%3E");
  background-size: 180px 180px; animation: grain-shift 1.1s steps(4) infinite;
}
.cinema-progress {
  position: fixed; top: 0; left: 0; z-index: 260; width: 0; height: 2px;
  background: var(--accent); opacity: 0; transition: width .35s ease, opacity .2s ease;
}
body.cinema-navigating .cinema-progress { opacity: 1; }
body.cinema-leaving { opacity: .35; transition: opacity .18s ease; }

/* ---------------------------------------------------------------- curtain transition + context menu */
.cinema-curtain {
  position: fixed; inset: 0; z-index: 290; display: grid; place-items: center; gap: 14px;
  background: #0b0c0b; color: #f1f0e8; text-align: center; opacity: 0; pointer-events: none;
  clip-path: circle(0 at var(--mx, 50%) var(--my, 50%));
  transition: opacity .12s ease, clip-path .32s ease-in;
}
.cinema-curtain.is-active {
  opacity: 1; pointer-events: auto;
  clip-path: circle(150vmax at var(--mx, 50%) var(--my, 50%));
  transition: opacity .12s ease, clip-path .48s cubic-bezier(.76, 0, .24, 1);
}
.cinema-curtain .curtain-mark { font-size: clamp(54px, 9vw, 96px); animation: splash-pulse 1.2s ease-in-out infinite; }
.cinema-curtain .curtain-text { font-size: 11px; letter-spacing: .32em; color: rgba(241, 240, 232, .55); }
.cinema-menu {
  position: fixed; z-index: 280; min-width: 210px; padding: 7px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .22);
  opacity: 0; transform: translateY(6px) scale(.98); pointer-events: none;
  transition: opacity .14s ease, transform .14s ease;
}
.cinema-menu.is-open { opacity: 1; transform: none; pointer-events: auto; }
.cinema-menu button {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  width: 100%; border: 0; padding: 9px 11px; background: transparent; text-align: left;
  font-size: 13px; color: var(--ink);
}
.cinema-menu button:hover, .cinema-menu button:focus-visible { background: var(--panel); outline: none; }
.cinema-menu kbd { color: var(--muted); font-size: 10px; letter-spacing: .08em; border: 0; }
.cinema-menu .menu-note { padding: 7px 11px 3px; color: var(--muted); font-size: 10px; letter-spacing: .16em; text-transform: uppercase; }
.cinema-tilt { transition: transform .18s ease, box-shadow .18s ease; transform-style: preserve-3d; }
.cinema-tilt:hover { box-shadow: 0 18px 40px rgba(0, 0, 0, .10); }

/* ---------------------------------------------------------------- scroll reveal */
html.cinema-reveal .reveal {
  opacity: 0; transform: translateY(22px);
  transition: opacity .8s cubic-bezier(.22, 1, .36, 1), transform .8s cubic-bezier(.22, 1, .36, 1);
  transition-delay: var(--reveal-delay, 0s);
}
html.cinema-reveal .reveal.is-visible { opacity: 1; transform: none; }
.cinema-parallax { transform: translate3d(0, var(--py, 0), 0); will-change: transform; }

/* ---------------------------------------------------------------- immersive reading */
.immersive-toggle {
  margin-top: 14px; border: 1px solid var(--line); padding: 8px 12px;
  background: transparent; font-size: 12px; letter-spacing: .05em;
}
.immersive-toggle:hover { border-color: var(--ink); }
.immersive-exit {
  position: fixed; right: 22px; bottom: 22px; z-index: 130; display: none;
  border: 1px solid var(--line); padding: 10px 16px; background: var(--paper);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .12); font-size: 12px; letter-spacing: .06em;
}
body.immersive { background: var(--paper); }
body.immersive .immersive-exit { display: block; }
body.immersive .header,
body.immersive .footer,
body.immersive .article-toc,
body.immersive .article-share,
body.immersive .bookmark-toggle,
body.immersive .post-navigation,
body.immersive .related-posts,
body.immersive .comments,
body.immersive .back-top,
body.immersive .reading-progress { display: none !important; }
body.immersive .reading-layout { display: block; max-width: 760px; margin: 0 auto; }
body.immersive .prose { font-size: 18px; line-height: 1.95; }
body.immersive .article-header { max-width: 760px; margin-left: auto; margin-right: auto; }
body.immersive main { padding-top: 6vh; }
body.immersive .article-top { max-width: 760px; margin-left: auto; margin-right: auto; }

/* ---------------------------------------------------------------- responsive + reduced motion */
@media (max-width: 640px) {
  .splash h1 { font-size: clamp(48px, 16vw, 76px); }
  .splash-actions { flex-direction: column; gap: 8px; }
  .splash-hint { display: none; }
  .cinema-spotlight { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .splash { display: none !important; }
  .cinema-curtain, .cinema-menu { display: none !important; }
  .cinema-tilt, .cinema-tilt:hover { transition: none; box-shadow: none; }
  .splash-aurora span, .splash-grain, body.cinema-grain::after,
  .splash-mark, .splash-eyebrow, .splash h1, .splash-intro,
  .splash-meter span, .splash-actions { animation: none !important; }
  html.cinema-reveal .reveal { opacity: 1; transform: none; transition: none; }
  body.cinema-leaving { opacity: 1; transition: none; }
  .cinema-spotlight { display: none; }
  .cinema-progress { display: none; }
}

@media print {
  #cinema-bg, .cinema-spotlight, .cinema-progress, .splash,
  body.cinema-grain::after, .immersive-exit { display: none !important; }
  body { background: #fff !important; }
}
