/* ==========================================================================
   Nevermind Runtime v2 - core stylesheet (nm-deck.css)
   Runtime mechanics only: stage, slide states, steps, camera, morph ghosts,
   chrome, overview, help, print mode, and the legacy motion-graphic classes.
   Pair with nm-deck.js. No emojis. Chrome only.
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. Theme fallbacks (zero specificity: any deck token wins)
   -------------------------------------------------------------------------- */
:where(:root) {
  --nm-paper: var(--slide-bg, #f4f1ea);
  --nm-ink: #1b1a17;
  --nm-muted: #6f6a60;
  --nm-line: rgba(27, 26, 23, 0.16);
  --nm-accent: var(--lp-accent, #c83e37);
  --nm-accent-2: #2f6f8f;
  --nm-surface: #ffffff;
  --nm-radius: 18px;
  --nm-font-display: system-ui, "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif;
  --nm-font-body: system-ui, "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif;
  --nm-stage-bg: var(--stage-bg, #1c1b19);
  --nm-chrome-bg: rgba(22, 21, 19, 0.92);
  --nm-chrome-ink: #f4f1ea;
}

/* --------------------------------------------------------------------------
   1. Fixed 1920x1080 stage
   -------------------------------------------------------------------------- */
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--nm-stage-bg);
}
.deck-viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--nm-stage-bg);
}
.deck-stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 1920px;
  height: 1080px;
  overflow: hidden;
  transform-origin: 0 0;
  background: var(--nm-paper);
}

/* --------------------------------------------------------------------------
   2. Slide states. Never display:none; inactive = hidden but measurable.
   Transitions are driven by the runtime (WAAPI), so CSS transitions on the
   slide and the rig are disabled to keep legacy CSS from fighting them.
   -------------------------------------------------------------------------- */
.deck-stage > .slide {
  position: absolute !important;
  inset: 0;
  width: 1920px;
  height: 1080px;
  overflow: hidden;
  display: block;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  z-index: 0;
  transition: none !important;
}
/* zero specificity so any class the author puts on a slide wins */
:where(.deck-stage > .slide) {
  background: var(--nm-paper);
  color: var(--nm-ink);
}
.deck-stage > .slide.active,
.deck-stage > .slide.visible {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  z-index: 2 !important;
}
.deck-stage > .slide.is-leaving {
  visibility: visible !important;
  opacity: 1;
  pointer-events: none !important;
  z-index: 1 !important;
}
.deck-stage > .slide.is-leaving.nm-on-top { z-index: 3 !important; }
.deck-stage > .slide.nm-flying { will-change: transform, opacity, clip-path; }
.deck-stage > .slide.morph-leaving { visibility: visible !important; pointer-events: none !important; z-index: 1 !important; }

.camera-rig {
  position: relative;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  transform-origin: 0 0;
  transition: none !important;
}

/* measured as a morph target: no transition, so the snapshot reads the resting style */
.nm-morph-measure, .nm-morph-measure * { transition: none !important; }

/* --------------------------------------------------------------------------
   3. Steps and acts
   -------------------------------------------------------------------------- */
.slide [data-step]:not([data-act]):not(.is-on),
.slide [data-step][data-act="reveal"]:not(.is-on),
.slide [data-step][data-act="gsap"]:not(.is-on) {
  visibility: hidden;
  opacity: 0;
}
.slide [data-step][data-act="zoom"],
.slide [data-zoom-step] { cursor: zoom-in; }
.slide [data-step][data-act="highlight"] { cursor: pointer; }

/* dim / blur of siblings while the camera is zoomed */
.slide .nm-dim {
  opacity: 0.22 !important;
  filter: blur(1.4px) grayscale(25%);
  transition: opacity 0.6s cubic-bezier(0.2, 0, 0, 1), filter 0.6s cubic-bezier(0.2, 0, 0, 1);
}
.slide .nm-undim {
  transition: opacity 0.6s cubic-bezier(0.2, 0, 0, 1), filter 0.6s cubic-bezier(0.2, 0, 0, 1);
}
.slide.is-camera-zoomed .zoom-focused {
  cursor: zoom-out;
  z-index: 30;
}

/* highlight act */
.slide .nm-highlighted {
  z-index: 5;
  outline: 3px solid var(--nm-accent);
  outline-offset: 8px;
  border-radius: var(--nm-radius);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18), 0 0 0 10px color-mix(in srgb, var(--nm-accent) 14%, transparent);
  transition: outline-offset 0.45s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.45s cubic-bezier(0.2, 0, 0, 1);
}

/* --------------------------------------------------------------------------
   4. Layers and morph ghosts
   -------------------------------------------------------------------------- */
.nm-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 1920px;
  height: 1080px;
  pointer-events: none;
  overflow: visible;
}
#nmOverlayLayer { z-index: 50; }
#nmGhostLayer { z-index: 60; }
.nm-ghost, .nm-ghost * { pointer-events: none !important; }
.nm-ghost {
  position: absolute;
  box-sizing: border-box;
  margin: 0;
  contain: layout style;
}
.nm-ghost-border {
  position: absolute;
  inset: 0;
  border-style: solid;
  box-sizing: border-box;
  pointer-events: none;
}
.nm-ghost-word { position: absolute; left: 0; top: 0; white-space: pre; margin: 0; transform-origin: 0 0; }
.nm-ghost-svg { position: absolute; left: 0; top: 0; width: 1920px; height: 1080px; overflow: visible; }
.nm-morph-hidden, .nm-morph-hidden * { visibility: hidden !important; }
.nm-morph-hidden-svg { visibility: hidden !important; }

/* --------------------------------------------------------------------------
   5. Chrome: hotzone, controls, progress, counter
   -------------------------------------------------------------------------- */
#controlsHotzone {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 32px;
  z-index: 999;
}
.deck-controls {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--nm-chrome-bg);
  color: var(--nm-chrome-ink);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  font: 600 13px/1.2 var(--nm-font-body);
  backdrop-filter: blur(12px);
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  white-space: nowrap;
}
.deck-controls.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.nm-btn {
  appearance: none;
  border: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: background 0.2s ease, opacity 0.2s ease;
}
.nm-btn:hover { background: rgba(255, 255, 255, 0.12); }
.nm-btn:focus-visible { outline: 2px solid var(--nm-accent); outline-offset: 2px; }
.nm-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nm-btn.nm-primary { background: var(--nm-accent); color: #fff; }
.nm-btn.nm-primary:hover { opacity: 0.88; }
.nm-btn.nm-icon { padding: 6px 8px; }
.nm-sep { width: 1px; height: 18px; background: rgba(255, 255, 255, 0.18); margin: 0 2px; }
#slideCounter { font-variant-numeric: tabular-nums; padding: 0 6px; opacity: 0.9; direction: ltr; unicode-bidi: isolate; }
.nm-progress {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  z-index: 998;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.06);
}
.nm-progress > i {
  position: absolute;
  inset: 0;
  background: var(--nm-accent);
  transform-origin: 100% 50%;
  transform: scaleX(0);
  transition: transform 0.6s cubic-bezier(0.2, 0, 0, 1);
}
[dir="ltr"] .nm-progress > i { transform-origin: 0 50%; }

/* edit mode badge */
.nm-badge {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 1001;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--nm-accent);
  color: #fff;
  font: 700 13px/1.2 var(--nm-font-body);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
body.nm-editing .nm-badge { opacity: 1; }
body.nm-editing [contenteditable="true"] { outline: 1px dashed color-mix(in srgb, var(--nm-accent) 60%, transparent); outline-offset: 4px; cursor: text; }
body.nm-editing [contenteditable="true"]:focus { outline: 2px solid var(--nm-accent); }

/* blackout */
.nm-blackout {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
body.nm-black .nm-blackout { opacity: 1; pointer-events: auto; cursor: none; }

/* key help */
.nm-help {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: grid;
  place-items: center;
  background: rgba(10, 10, 9, 0.55);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  font: 500 15px/1.5 var(--nm-font-body);
}
body.nm-help-open .nm-help { opacity: 1; pointer-events: auto; }
.nm-help-card {
  min-width: 420px;
  max-width: 560px;
  padding: 26px 30px;
  border-radius: 20px;
  background: var(--nm-chrome-bg);
  color: var(--nm-chrome-ink);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
.nm-help-card h2 { margin: 0 0 14px; font-size: 20px; }
.nm-help-card dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; margin: 0; }
.nm-help-card dt { direction: ltr; text-align: left; font: 700 13px/1.6 ui-monospace, Menlo, Consolas, monospace; color: color-mix(in srgb, var(--nm-chrome-ink) 75%, transparent); }
.nm-help-card dd { margin: 0; }
.nm-help-card kbd { display: inline-block; min-width: 18px; padding: 1px 7px; border-radius: 6px; background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.18); text-align: center; }

/* --------------------------------------------------------------------------
   6. Overview grid (lives inside the stage, in stage pixels)
   -------------------------------------------------------------------------- */
.nm-overview {
  position: absolute;
  left: 0;
  top: 0;
  width: 1920px;
  height: 1080px;
  z-index: 100;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--nm-stage-bg);
  box-sizing: border-box;
  scrollbar-width: none;
}
.nm-overview-grid { position: relative; }
.nm-ov-card {
  position: absolute;
  overflow: hidden;
  border-radius: 14px;
  cursor: pointer;
  background: var(--nm-paper);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  outline: 3px solid transparent;
  outline-offset: 5px;
  transition: outline-color 0.2s ease;
}
.nm-ov-card:hover, .nm-ov-card.is-selected { outline-color: var(--nm-accent); }
.nm-ov-card.is-current::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--nm-accent) 70%, transparent);
  pointer-events: none;
}
.nm-ov-num {
  position: absolute;
  bottom: 10px;
  left: 10px;
  z-index: 5;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font: 700 16px/1.3 var(--nm-font-body);
  font-variant-numeric: tabular-nums;
}
.nm-ov-card > .deck-stage {
  position: absolute !important;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  pointer-events: none;
}
.nm-ov-card > .deck-stage > .slide {
  visibility: visible !important;
  opacity: 1 !important;
  z-index: 1 !important;
}

/* --------------------------------------------------------------------------
   7. Print / audit mode (?nm-print) and real printing
   -------------------------------------------------------------------------- */
body.nm-print { overflow: auto; height: auto; }
html.nm-print-root { overflow: auto; height: auto; }
body.nm-print .deck-viewport { position: static; overflow: visible; background: var(--nm-stage-bg); }
body.nm-print .deck-stage { position: static; transform: none !important; width: 1920px; height: auto; overflow: visible; background: none; contain: none; }
body.nm-print .deck-stage > .slide {
  position: relative !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  margin: 0 0 24px;
  break-after: page;
}
body.nm-print .deck-controls, body.nm-print #controlsHotzone, body.nm-print .nm-progress,
body.nm-print .nm-help, body.nm-print .nm-badge, body.nm-print .nm-blackout { display: none !important; }
@page { size: 1920px 1080px; margin: 0; }
@media print {
  html, body { width: 1920px !important; height: auto !important; overflow: visible !important; }
  .deck-viewport { position: static !important; overflow: visible !important; }
  .deck-stage { position: static !important; transform: none !important; height: auto !important; overflow: visible !important; }
  .deck-stage > .slide { position: relative !important; visibility: visible !important; opacity: 1 !important; margin: 0 !important; break-after: page; }
  .deck-controls, #controlsHotzone, .nm-progress, .nm-help, .nm-badge, .nm-blackout, .nm-layer { display: none !important; }
}

/* --------------------------------------------------------------------------
   8. Legacy continuous SVG motion graphics (v1 names, unchanged behaviour)
   -------------------------------------------------------------------------- */
[data-morph] { will-change: auto; }
@keyframes dashFlow { to { stroke-dashoffset: -120; } }
@keyframes dashFlowReverse { to { stroke-dashoffset: 120; } }
@keyframes pulseRing {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.18); opacity: 0.25; }
}
@keyframes radarSweep {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
@keyframes scanLineY {
  0%, 100% { transform: translateY(0px); opacity: 0.75; }
  50% { transform: translateY(270px); opacity: 0.95; }
}
@keyframes driftNode {
  0%, 100% { transform: translate(0px, 0px); }
  50% { transform: translate(-42px, -22px); }
}
.mg-flow { stroke-dasharray: 10 8; animation: dashFlow 3.2s linear infinite; }
.mg-flow-fast { stroke-dasharray: 8 6; animation: dashFlow 1.8s linear infinite; }
.mg-flow-rev { stroke-dasharray: 8 8; animation: dashFlowReverse 2.4s linear infinite; }
.mg-pulse { transform-box: fill-box; transform-origin: center; animation: pulseRing 2.6s ease-in-out infinite; }
.mg-radar { transform-box: fill-box; transform-origin: center; animation: radarSweep 9s linear infinite; }
.mg-radar-reverse { transform-box: fill-box; transform-origin: center; animation: radarSweep 14s linear infinite reverse; }
.mg-scan { animation: scanLineY 4.2s ease-in-out infinite; }
.mg-drift { animation: driftNode 3.6s ease-in-out infinite; }
.mg-bar-fill, .bar-grow {
  transform-origin: right center;
  transform: scaleX(0);
  transition: transform 1.15s cubic-bezier(0.16, 1, 0.3, 1) 0.35s;
}
.slide.visible :is(.mg-bar-fill, .bar-grow) { transform: scaleX(1); }

/* HUD corner brackets (legacy decorative frame) */
.hud-bracket { position: relative; }
.hud-bracket::before, .hud-bracket::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border: 0 solid var(--nm-accent);
  pointer-events: none;
}
.hud-bracket::before { top: -6px; right: -6px; border-top-width: 3px; border-right-width: 3px; }
.hud-bracket::after { bottom: -6px; left: -6px; border-bottom-width: 3px; border-left-width: 3px; }

/* --------------------------------------------------------------------------
   9. Reduced motion: infinite legacy loops stop; runtime goes instant in JS
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .mg-flow, .mg-flow-fast, .mg-flow-rev, .mg-pulse, .mg-radar, .mg-radar-reverse, .mg-scan, .mg-drift { animation: none; }
  .mg-bar-fill, .bar-grow, .deck-controls, .nm-progress > i { transition: none; }
}
body.nm-instant :is(.mg-flow, .mg-flow-fast, .mg-flow-rev, .mg-pulse, .mg-radar, .mg-radar-reverse, .mg-scan, .mg-drift) { animation: none !important; }
body.nm-instant .mg-bar-fill, body.nm-instant .bar-grow, body.nm-instant .nm-progress > i, body.nm-instant .nm-dim, body.nm-instant .nm-undim, body.nm-instant .nm-highlighted { transition: none !important; }
