/* NetMirror 3D design system — shared layer for the MASTER 3D redesign.
 * Reuses the palette variables defined in assets/css/style.css (:root).
 * This file deliberately defines NO :root palette variables and NO typography
 * sizes, so page text, headings, links and SEO markup are untouched.
 * Tasteful, realistic lighting: controlled red/gold on dark surfaces.
 * No neon glow spam, no gaming-style UI.
 * Every animation is disabled under prefers-reduced-motion.
 * Load order: style.css first, then this file (it only adds/overrides
 * 3D-system classes, never base typography or layout).
 */

/* --- Horizontal-overflow safeguard (sticky-header safe) ---
 * overflow-x: clip does NOT create a scroll container, so position:sticky
 * (the .site-header) keeps working — unlike overflow-x: hidden, which
 * breaks sticky in some browsers. Fallback for old browsers that lack
 * `clip` is plain hidden. */
html, body { overflow-x: clip; }
@supports not (overflow: clip) {
  html, body { overflow-x: hidden; }
}

/* --- 3D scene helpers -------------------------------------------------- */
.section-3d {
  position: relative;
  padding: 40px 0;
  perspective: 1200px;
}
.section-3d > * { position: relative; z-index: 1; }

/* Atmospheric glow plane: soft radial red/gold wash behind a section.
 * Purely decorative; pointer-events none so it never blocks clicks. */
.glow-plane {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(55% 45% at 18% 28%, rgba(229, 9, 20, .16), transparent 70%),
    radial-gradient(45% 40% at 84% 30%, rgba(255, 201, 60, .10), transparent 70%),
    radial-gradient(60% 50% at 50% 110%, rgba(229, 9, 20, .08), transparent 70%);
}
.glow-plane--gold {
  background:
    radial-gradient(50% 42% at 50% 30%, rgba(255, 201, 60, .12), transparent 70%),
    radial-gradient(55% 45% at 15% 80%, rgba(229, 9, 20, .10), transparent 70%);
}
.glow-plane--red {
  background:
    radial-gradient(60% 50% at 50% 35%, rgba(229, 9, 20, .18), transparent 70%);
}

/* Three.js scene mount point. Keeps its static gradient background as the
 * CSS fallback when WebGL / THREE is missing — the canvas is layered on
 * top only when a scene actually initialises. */
[data-scene] {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(55% 45% at 20% 25%, rgba(229, 9, 20, .14), transparent 70%),
    radial-gradient(45% 40% at 85% 30%, rgba(255, 201, 60, .09), transparent 70%),
    linear-gradient(180deg, #17141f 0%, var(--bg) 100%);
}
[data-scene] canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

/* --- Glass panel -------------------------------------------------------- */
.glass {
  background: linear-gradient(160deg, rgba(32, 32, 46, .72), rgba(20, 20, 28, .62));
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 16px;
  box-shadow:
    0 18px 44px rgba(0, 0, 0, .45),
    inset 0 1px 0 rgba(255, 255, 255, .07);
}
.glass--red { border-color: rgba(229, 9, 20, .35); }
.glass--gold { border-color: rgba(255, 201, 60, .35); }

/* --- 3D cards / tilt ---------------------------------------------------- */
.card-3d,
.tilt {
  transform-style: preserve-3d;
  will-change: transform;
  transition: transform .35s ease, box-shadow .35s ease, border-color .35s ease;
}
.card-3d {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .35);
}
.card-3d:hover,
.tilt:hover {
  border-color: #3d3d52;
  box-shadow:
    0 22px 48px rgba(0, 0, 0, .5),
    0 0 0 1px rgba(255, 201, 60, .06);
}
/* Inner layer that pops toward the viewer inside a .card-3d / .tilt. */
.card-3d .tilt-inner,
.tilt .tilt-inner { transform: translateZ(24px); }
/* Shine sweep element (see .shine below); positioned by the card. */
.card-3d .shine, .tilt .shine { border-radius: inherit; }

/* Parallax depth layers. translate3d is applied by JS (small, clamped);
 * the classes only set the stacking/transition behaviour. */
.depth-layer { will-change: transform; transition: transform .3s ease-out; }
.depth-layer--back { transform: translateZ(-60px) scale(1.05); }
.depth-layer--mid { transform: translateZ(0); }
.depth-layer--front { transform: translateZ(40px); }

/* --- Scroll reveal ------------------------------------------------------
 * Hidden state applies ONLY once JS has run (html.nm-js, added by
 * 3d-system.js). If JS never loads, content stays visible — never hidden.
 * Elements already in view on load are revealed immediately by the JS. */
html.nm-js .reveal {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity .6s ease, transform .6s cubic-bezier(.22, .61, .36, 1);
  will-change: opacity, transform;
}
html.nm-js .reveal--left { transform: translateX(-18px); }
html.nm-js .reveal--right { transform: translateX(18px); }
html.nm-js .reveal--zoom { transform: scale(.96); }
html.nm-js .reveal--zoom.reveal-visible { transform: scale(1); }
html.nm-js .reveal-visible { opacity: 1; transform: none; }
/* Stagger via inline style="--reveal-delay:.1s" or these helpers. */
html.nm-js .reveal { transition-delay: var(--reveal-delay, 0s); }

/* --- Shine sweep -------------------------------------------------------- */
.shine { position: relative; overflow: hidden; }
.shine::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(112deg, transparent 30%, rgba(255, 255, 255, .10) 48%, rgba(255, 255, 255, .03) 55%, transparent 72%);
  transform: translateX(-120%);
  transition: transform .8s ease;
  pointer-events: none;
}
.shine:hover::after, .shine:focus-visible::after { transform: translateX(120%); }

/* --- Magnetic CTA ------------------------------------------------------- */
.magnetic-btn {
  display: inline-block;
  will-change: transform;
  transition: transform .25s ease, background .15s ease;
}
.magnetic-btn:hover { transform: translateY(-1px); }

/* --- 3D carousel -------------------------------------------------------- */
.carousel-3d {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 6px 2px 14px;
  cursor: grab;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.carousel-3d:active { cursor: grabbing; }
.carousel-3d > * { flex: 0 0 auto; scroll-snap-align: start; }
.carousel-3d::-webkit-scrollbar { height: 8px; }
.carousel-3d::-webkit-scrollbar-thumb { background: #2c2c3a; border-radius: 4px; }
.carousel-3d:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.carousel-3d.is-dragging { scroll-snap-type: none; cursor: grabbing; }
.carousel-3d.is-dragging a, .carousel-3d.is-dragging img { pointer-events: none; }
/* Keep poster cards inside a carousel at a readable width. */
.carousel-3d .card { width: 168px; }
@media (min-width: 640px) { .carousel-3d .card { width: 190px; } }
.carousel-3d__nav { display: flex; gap: 8px; }
.carousel-3d__btn {
  background: var(--card2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 44px;
  min-height: 44px;
  font-size: 1.1rem;
  cursor: pointer;
}
.carousel-3d__btn:hover { background: #2a2a3a; border-color: #3d3d52; }

/* --- Accordion (FAQ) ----------------------------------------------------
 * Progressive enhancement for [data-accordion] blocks built by later
 * workers. Existing native <details> FAQs are untouched. */
.accordion { display: grid; gap: 8px; }
.accordion-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.accordion-button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: none;
  border: 0;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.accordion-button::after {
  content: "+";
  flex: none;
  color: var(--dim);
  font-size: 1.25rem;
  font-weight: 400;
  transition: transform .25s ease;
}
.accordion-item.is-open .accordion-button::after { content: "\2212"; }
.accordion-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height .35s ease;
}
.accordion-panel > * { padding: 0 16px 14px; margin: 0; color: var(--muted); }
.accordion-panel > *:first-child { padding-top: 0; }

/* --- Version timeline --------------------------------------------------- */
.timeline { list-style: none; padding: 0 0 0 22px; margin: 0; position: relative; }
.timeline::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: linear-gradient(180deg, var(--accent), rgba(255, 201, 60, .55), var(--border));
}
.timeline > li { position: relative; padding: 0 0 22px 14px; }
.timeline > li:last-child { padding-bottom: 0; }
.timeline > li::before {
  content: "";
  position: absolute;
  left: -22px;
  top: 6px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 3px rgba(229, 9, 20, .18);
}
.timeline > li.is-latest::before { background: var(--accent); border-color: var(--gold); }
.timeline .timeline-version { font-weight: 800; color: #fff; }
.timeline .timeline-date { color: var(--dim); font-size: .88rem; }

/* --- Floating table of contents ----------------------------------------- */
.toc-panel {
  position: sticky;
  top: 76px;
  background: linear-gradient(160deg, rgba(32, 32, 46, .72), rgba(20, 20, 28, .62));
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
}
.toc-panel h2, .toc-panel h3 { margin-top: 0; }
.toc-panel ul { list-style: none; padding: 0; margin: 0; }
.toc-panel li { margin: 6px 0; }
.toc-panel a {
  color: var(--muted);
  font-size: .93rem;
  border-left: 2px solid transparent;
  padding-left: 10px;
  display: block;
}
.toc-panel a:hover { color: var(--text); text-decoration: none; }
.toc-panel a.is-active {
  color: var(--gold);
  border-left-color: var(--accent);
  font-weight: 700;
}

/* --- Reading progress --------------------------------------------------- */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 60;
  height: 3px;
  width: 100%;
  background: transparent;
  pointer-events: none;
}
.progress-bar__fill {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent), #ff7a3c, var(--gold));
  transform: scaleX(0);
  transform-origin: 0 50%;
}

/* --- Device stage / device selector ------------------------------------- */
.device-stage {
  position: relative;
  perspective: 1200px;
  min-height: 340px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.device-stage [data-device-panel] { display: none; width: 100%; }
.device-stage [data-device-panel].is-active { display: block; }
.device-stage [data-device-panel].is-active .device-frame {
  animation: nm-device-in .5s ease both;
}
@keyframes nm-device-in {
  from { opacity: 0; transform: translateY(14px) rotateX(6deg); }
  to { opacity: 1; transform: none; }
}
.device-frame {
  transform-style: preserve-3d;
  transform: rotateY(-8deg) rotateX(3deg);
  transition: transform .4s ease;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 56px rgba(0, 0, 0, .5);
  padding: 18px;
  max-width: 520px;
  margin: 0 auto;
}
.device-selector { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.device-selector [data-device] {
  background: var(--card2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 16px;
  font: inherit;
  font-size: .92rem;
  font-weight: 700;
  cursor: pointer;
}
.device-selector [data-device]:hover { color: var(--text); border-color: #3d3d52; }
.device-selector [data-device].is-active,
.device-selector [data-device][aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* --- Floating APK package stage ----------------------------------------- */
.apk-stage {
  position: relative;
  perspective: 1200px;
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.apk-stage .apk-float {
  animation: nm-apk-float 6s ease-in-out infinite;
  will-change: transform;
}
@keyframes nm-apk-float {
  0%, 100% { transform: translateY(0) rotateY(-6deg); }
  50% { transform: translateY(-12px) rotateY(6deg); }
}
.apk-stage .apk-shadow {
  position: absolute;
  bottom: 18px;
  left: 50%;
  width: 180px;
  height: 26px;
  transform: translateX(-50%);
  background: radial-gradient(50% 50% at 50% 50%, rgba(0, 0, 0, .55), transparent 70%);
  animation: nm-apk-shadow 6s ease-in-out infinite;
}
@keyframes nm-apk-shadow {
  0%, 100% { transform: translateX(-50%) scaleX(1); opacity: .8; }
  50% { transform: translateX(-50%) scaleX(.82); opacity: .55; }
}

/* --- Reduced motion: everything still, everything visible --------------- */
@media (prefers-reduced-motion: reduce) {
  html.nm-js .reveal,
  html.nm-js .reveal--left,
  html.nm-js .reveal--right,
  html.nm-js .reveal--zoom {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  .card-3d, .tilt, .depth-layer, .magnetic-btn, .shine::after,
  .accordion-panel, .device-frame, .carousel-3d { transition: none !important; }
  .apk-stage .apk-float, .apk-stage .apk-shadow,
  .device-stage [data-device-panel].is-active .device-frame {
    animation: none !important;
  }
  .shine::after { display: none; }
  [data-scene] canvas { display: none; }
}

/* --- Mobile (<=768px): reduce tilt/parallax, never overflow ------------- */
@media (max-width: 768px) {
  .section-3d { padding: 28px 0; perspective: 700px; }
  .card-3d, .tilt { transition-duration: .2s; }
  .card-3d:hover, .tilt:hover {
    box-shadow: 0 12px 28px rgba(0, 0, 0, .4);
  }
  .depth-layer--back { transform: translateZ(-30px) scale(1.02); }
  .depth-layer--front { transform: translateZ(16px); }
  .toc-panel { position: static; margin-bottom: 18px; }
  .device-stage { min-height: 280px; }
  .device-frame { transform: none; }
  .apk-stage { min-height: 240px; }
  .apk-stage .apk-float { animation-duration: 8s; }
  .carousel-3d { gap: 10px; }
  .carousel-3d .card { width: 150px; }
  .glass { border-radius: 14px; }
}
