/*
------------------------------------------------------------------------------
THE DARKNET DISTRICT — IMMERSIVE HUD

Purpose: optional AR visor layer for approved pages.
Activation: add data-hud="immersive" to a page's body.
------------------------------------------------------------------------------ 
*/

:root {
  /* CENTRAL HUD CONTROLS */
  --tdnd-hud-opacity: 0.62;
  --tdnd-hud-coordinate-opacity: 0.42;
  --tdnd-hud-coordinate-drift-duration: 72s;
  --tdnd-hud-scroll-parallax-strength: 0.012;
  --tdnd-hud-scanline-intensity: 0.5;
  --tdnd-hud-glow-intensity: 0.52;
  --tdnd-hud-animation-speed: 1;
  --tdnd-hud-mobile-effect-intensity: 0.4;
  --tdnd-hud-pov-parallax-strength: 8;
  --tdnd-hud-pov-settle: 0.1;
  /* Head-mounted sway on the LAT/LON tapes. 1 is about 3-5px of idle drift;
     it calms while scrolling. 0.5 is gentler, 1.5 more pronounced. */
  --tdnd-hud-sway-strength: 1;
}

/* The HUD stays isolated until a page explicitly opts in. */
body[data-hud="immersive"] {
  isolation: isolate;
  /* style.css hints will-change: transform on body, which would pin the
     screen-fixed flight tapes to the page instead of the screen. */
  will-change: auto;
}

body[data-hud="immersive"] > :not(.tdnd-hud-layer):not(.tdnd-hud-tapes) {
  position: relative;
  z-index: 2;
}

body[data-hud="immersive"] .tdnd-hud-layer {
  /* Absolute so the full HUD graphic scrolls with the document; hud.js keeps
     its explicit height synchronized with the measured document height. */
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--tdnd-hud-document-height, 100vh);
  min-height: 100%;
  z-index: 1;
  pointer-events: none;
  opacity: var(--tdnd-hud-opacity);
  transform: translate3d(var(--tdnd-hud-pov-x, 0px), var(--tdnd-hud-pov-y, 0px), 0);
  will-change: transform;
}

body[data-hud="immersive"] .tdnd-hud-viewport {
  position: absolute;
  inset: 18px 26px;
  border: 1px solid rgba(115, 255, 218, 0.12);
  box-shadow: inset 0 0 28px rgba(0, 255, 157, 0.035);
  /* Sub-pixel idle drift on the visor frame; the `translate` property composes
     with the pointer-parallax transform applied to the parent .tdnd-hud-layer. */
  animation: tdnd-hud-idle-drift calc(47s * var(--tdnd-hud-animation-speed)) ease-in-out infinite;
}

body[data-hud="immersive"] .tdnd-hud-bracket {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: rgba(126, 255, 222, 0.9);
  border-style: solid;
  filter: drop-shadow(0 0 4px rgba(0, 255, 157, var(--tdnd-hud-glow-intensity)));
  animation: tdnd-hud-breathe calc(12s * var(--tdnd-hud-animation-speed)) ease-in-out infinite alternate;
}

body[data-hud="immersive"] .tdnd-hud-bracket--top-left {
  top: -1px;
  left: -1px;
  border-width: 2px 0 0 2px;
}

body[data-hud="immersive"] .tdnd-hud-bracket--top-right {
  top: -1px;
  right: -1px;
  border-width: 2px 2px 0 0;
}

body[data-hud="immersive"] .tdnd-hud-bracket--bottom-left {
  bottom: -1px;
  left: -1px;
  border-width: 0 0 2px 2px;
}

body[data-hud="immersive"] .tdnd-hud-bracket--bottom-right {
  right: -1px;
  bottom: -1px;
  border-width: 0 2px 2px 0;
}

body[data-hud="immersive"] .tdnd-hud-coordinates,
body[data-hud="immersive"] .tdnd-hud-status {
  position: absolute;
  color: rgba(118, 255, 216, var(--tdnd-hud-coordinate-opacity));
  font: 10px/1 "Courier New", monospace;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  white-space: nowrap;
  text-shadow: 0 0 5px rgba(0, 255, 157, 0.08);
}

body[data-hud="immersive"] .tdnd-hud-coordinates {
  left: 50%;
  transform: translateX(-50%) translateY(var(--tdnd-hud-scroll-offset, 0px));
  animation: tdnd-hud-drift calc(var(--tdnd-hud-coordinate-drift-duration) * var(--tdnd-hud-animation-speed)) ease-in-out infinite alternate;
}

body[data-hud="immersive"] .tdnd-hud-coordinates--top {
  top: 13px;
}

body[data-hud="immersive"] .tdnd-hud-coordinates--bottom {
  bottom: 14px;
  animation-delay: -24s;
}

body[data-hud="immersive"] .tdnd-hud-coordinates span {
  display: inline-block;
  margin: 0 42px;
}

body[data-hud="immersive"] .tdnd-hud-status {
  right: 42px;
  bottom: 35px;
  padding: 6px 8px;
  border: 1px solid rgba(95, 255, 205, 0.14);
  animation: tdnd-hud-drift calc(56s * var(--tdnd-hud-animation-speed)) ease-in-out infinite alternate-reverse;
}

body[data-hud="immersive"] .tdnd-hud-status::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 6px;
  border-radius: 50%;
  background: #00ff9d;
  box-shadow: 0 0 6px rgba(0, 255, 157, var(--tdnd-hud-glow-intensity));
  animation: tdnd-hud-breathe calc(8s * var(--tdnd-hud-animation-speed)) ease-in-out infinite alternate;
}

body[data-hud="immersive"] .tdnd-hud-layer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 4px,
    rgba(94, 255, 204, 0.025) 5px,
    transparent 6px
  );
  opacity: var(--tdnd-hud-scanline-intensity);
  animation: tdnd-hud-scan calc(22s * var(--tdnd-hud-animation-speed)) linear infinite;
}

body[data-hud="immersive"] .scanlines::before {
  opacity: var(--tdnd-hud-scanline-intensity);
  animation-duration: calc(18s * var(--tdnd-hud-animation-speed));
}

body[data-hud="immersive"] .nav-button,
body[data-hud="immersive"] .resource-card,
body[data-hud="immersive"] .intro-text {
  position: relative;
}

body[data-hud="immersive"] .nav-button::after,
body[data-hud="immersive"] .resource-card::after,
body[data-hud="immersive"] .intro-text::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(121, 255, 219, 0.19);
  clip-path: polygon(0 10px, 10px 0, calc(100% - 10px) 0, 100% 10px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 10px 100%, 0 calc(100% - 10px));
  opacity: 0.45;
  pointer-events: none;
  transition: opacity 0.4s ease, filter 0.4s ease;
}

body[data-hud="immersive"] .nav-button:hover::after,
body[data-hud="immersive"] .resource-card:hover::after {
  opacity: 0.88;
  filter: drop-shadow(0 0 6px rgba(0, 255, 157, var(--tdnd-hud-glow-intensity)));
}

@keyframes tdnd-hud-drift {
  0% { translate: -3px -2px; }
  100% { translate: 3px 2px; }
}

@keyframes tdnd-hud-breathe {
  0% { opacity: 0.52; }
  100% { opacity: 0.88; }
}

/* Slow, irregular sub-pixel drift for the document-height HUD (< 1px amplitude). */
@keyframes tdnd-hud-idle-drift {
  0% { translate: 0 0; }
  13% { translate: 0.35px -0.2px; }
  29% { translate: -0.15px 0.4px; }
  47% { translate: 0.45px 0.3px; }
  61% { translate: -0.4px -0.1px; }
  78% { translate: 0.2px -0.45px; }
  91% { translate: -0.3px 0.25px; }
  100% { translate: 0 0; }
}

@keyframes tdnd-hud-scan {
  0% { transform: translateY(-2%); }
  100% { transform: translateY(2%); }
}

@media (max-width: 768px) {
  /* Wrapped mobile navigation remains in flow instead of covering page content. */
  body[data-hud="immersive"] {
    padding-top: 0;
  }

  body[data-hud="immersive"] .top-nav {
    position: sticky;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 0;
  }

  body[data-hud="immersive"] .top-nav a {
    margin: 0 4px;
  }

  body[data-hud="immersive"] .tdnd-hud-layer {
    opacity: var(--tdnd-hud-mobile-effect-intensity);
  }

  :root {
    --tdnd-hud-pov-parallax-strength: 5;
  }

  body[data-hud="immersive"] .tdnd-hud-viewport {
    inset: 12px 14px;
  }

  body[data-hud="immersive"] .tdnd-hud-bracket {
    width: 18px;
    height: 18px;
  }

  body[data-hud="immersive"] .tdnd-hud-coordinates,
  body[data-hud="immersive"] .tdnd-hud-status {
    display: none;
  }

  body[data-hud="immersive"] .nav-button::after,
  body[data-hud="immersive"] .resource-card::after,
  body[data-hud="immersive"] .intro-text::after {
    inset: 4px;
    opacity: 0.34;
  }
}

@media (prefers-reduced-motion: reduce) {

  body[data-hud="immersive"] .tdnd-hud-layer {
    transform: none !important;
    will-change: auto;
  }

  body[data-hud="immersive"] .tdnd-hud-layer *,
  body[data-hud="immersive"] .tdnd-hud-layer::after,
  body[data-hud="immersive"] .scanlines::before {
    animation: none !important;
    transition: none !important;
  }

  /* The idle drift is fully disabled together with other HUD motion. */
  body[data-hud="immersive"] .tdnd-hud-viewport {
    translate: none !important;
  }

  body[data-hud="immersive"] .tdnd-hud-coordinates {
    transform: translateX(-50%);
  }
}

/* -------------------------------------------------------------------------- */
/* CONCEPT C — VISOR PRESENCE AND UNIFORM RESOURCE PANELS                     */
/* -------------------------------------------------------------------------- */

body[data-hud="immersive"] .tdnd-hud-layer {
  opacity: 0.62;
}

body[data-hud="immersive"] .tdnd-hud-viewport {
  border-color: rgba(115, 255, 218, 0.3);
  box-shadow: inset 0 0 42px rgba(0, 255, 157, 0.07);
}

body[data-hud="immersive"] .tdnd-hud-bracket {
  width: 32px;
  height: 32px;
  border-color: rgba(126, 255, 222, 0.95);
}

body[data-hud="immersive"] .tdnd-hud-coordinates,
body[data-hud="immersive"] .tdnd-hud-status,
body[data-hud="immersive"] .tdnd-hud-top-status {
  color: rgba(118, 255, 216, 0.42);
  text-shadow: 0 0 7px rgba(0, 255, 157, 0.16);
}

body[data-hud="immersive"] .tdnd-hud-top-status {
  position: absolute;
  top: 28px;
  right: 48px;
  font: 10px/1 "Courier New", monospace;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  white-space: nowrap;
}

body[data-hud="immersive"] .tdnd-hud-connector {
  position: absolute;
  height: 1px;
  border-top: 1px solid rgba(114, 255, 214, 0.38);
  box-shadow: 0 0 7px rgba(0, 255, 157, 0.16);
}

body[data-hud="immersive"] .tdnd-hud-connector::before,
body[data-hud="immersive"] .tdnd-hud-connector::after {
  content: "";
  position: absolute;
  top: -4px;
  width: 7px;
  height: 7px;
  border: 1px solid rgba(114, 255, 214, 0.6);
  background: rgba(0, 0, 0, 0.25);
}

body[data-hud="immersive"] .tdnd-hud-connector::before {
  left: 0;
}

body[data-hud="immersive"] .tdnd-hud-connector::after {
  right: 0;
}

body[data-hud="immersive"] .tdnd-hud-connector--left {
  top: 42%;
  left: -1px;
  width: 18%;
}

body[data-hud="immersive"] .tdnd-hud-connector--right {
  top: 66%;
  right: -1px;
  width: 16%;
}

body[data-hud="immersive"] .tdnd-hud-viewport::before,
body[data-hud="immersive"] .tdnd-hud-viewport::after {
  content: "";
  position: absolute;
  /* Fixed insets keep these rails continuous through the document frame. */
  top: 60px;
  bottom: 60px;
  width: 8px;
  opacity: 0.48;
  background: repeating-linear-gradient(
    to bottom,
    rgba(118, 255, 216, 0.56) 0 1px,
    transparent 1px 34px
  );
}

body[data-hud="immersive"] .tdnd-hud-viewport::before {
  left: 10px;
}

body[data-hud="immersive"] .tdnd-hud-viewport::after {
  right: 10px;
}

body[data-hud="immersive"] .tdnd-hud-layer::after {
  opacity: 0.5;
}

body[data-hud="immersive"] .nav-button::after,
body[data-hud="immersive"] .resource-card::after,
body[data-hud="immersive"] .intro-text::after {
  border-color: rgba(121, 255, 219, 0.36);
  opacity: 0.66;
}

body[data-hud="immersive"] .resource-card:hover::after,
body[data-hud="immersive"] .nav-button:hover::after {
  opacity: 1;
}

body[data-hud="immersive"] /* The supporting resource panels intentionally follow the top category-card rhythm. */
.additional-resources-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 30px;
  width: 90%;
  max-width: 600px;
  margin: 40px auto 80px;
}

body[data-hud="immersive"] .additional-resources-grid .resource-card {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  min-height: 260px;
  margin: 0;
  padding: 30px 50px;
  border-radius: 15px;
}

body[data-hud="immersive"] .additional-resources-grid .resource-card h2 {
  margin: 0 0 12px;
  min-height: 0;
}

body[data-hud="immersive"] .additional-resources-grid .resource-card p {
  margin: 0 0 15px;
}

body[data-hud="immersive"] .additional-resources-grid .resource-card .curious-link {
  margin-top: auto;
  padding-top: 16px;
}

@media (max-width: 768px) {
  body[data-hud="immersive"] .tdnd-hud-layer {
    opacity: 0.4;
  }

  body[data-hud="immersive"] .tdnd-hud-bracket {
    width: 23px;
    height: 23px;
  }

  body[data-hud="immersive"] .tdnd-hud-connector,
  body[data-hud="immersive"] .tdnd-hud-viewport::before,
  body[data-hud="immersive"] .tdnd-hud-viewport::after,
  body[data-hud="immersive"] .tdnd-hud-top-status {
    display: none;
  }

  body[data-hud="immersive"] .additional-resources-grid {
    gap: 30px;
    width: 90%;
    margin: 30px auto 60px;
  }

  body[data-hud="immersive"] .additional-resources-grid .resource-card {
    min-height: 0;
    padding: 25px 30px;
  }
}

@media (min-width: 769px) and (max-width: 900px) {
  body[data-hud="immersive"] .tdnd-hud-coordinates span { margin: 0 18px; }
  body[data-hud="immersive"] .tdnd-hud-top-status { right: 34px; font-size: 8px; }
}

@media (max-width: 600px) {
  body[data-hud="immersive"] .tdnd-hud-viewport { inset: 8px; }
  body[data-hud="immersive"] .tdnd-hud-bracket { width: 16px; height: 16px; }
}

/* -------------------------------------------------------------------------- */
/* FLIGHT TAPES — LAT/LON instrument tapes fixed to the screen edges          */
/* -------------------------------------------------------------------------- */
/* The tapes stay on screen like a flight HUD. Their ticks are spaced in page
   pixels, so each page gets a tape exactly as long as its content, and they
   glide past a fixed caret as the page scrolls. hud.js adds a slight
   unsteady sway, like a head-mounted display. */

body[data-hud="immersive"] .tdnd-hud-tapes {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: var(--tdnd-hud-tape-opacity, 0.9);
  transform: translate3d(var(--tdnd-hud-sway-x, 0px), var(--tdnd-hud-sway-y, 0px), 0) rotate(var(--tdnd-hud-sway-r, 0deg));
  will-change: transform;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, transparent 70px, #000 150px, #000 calc(100% - 70px), transparent calc(100% - 16px));
  mask-image: linear-gradient(to bottom, transparent 0, transparent 70px, #000 150px, #000 calc(100% - 70px), transparent calc(100% - 16px));
}

body[data-hud="immersive"] .tdnd-hud-tape {
  position: absolute;
  top: 0;
  bottom: 0;
  width: var(--tdnd-hud-tape-width, 96px);
}

body[data-hud="immersive"] .tdnd-hud-tape--left { left: 34px; }
body[data-hud="immersive"] .tdnd-hud-tape--right { right: 34px; }

body[data-hud="immersive"] .tdnd-hud-tape canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Fixed caret: the boxed live value the tape slides behind. */
body[data-hud="immersive"] .tdnd-hud-caret {
  position: absolute;
  top: 50%;
  display: flex;
  align-items: center;
  gap: 6px;
  transform: translateY(-50%);
  color: rgba(214, 255, 241, 0.92);
  font: 10px/1 "Courier New", monospace;
  letter-spacing: 0.12em;
  white-space: nowrap;
  text-shadow: 0 0 6px rgba(0, 255, 157, 0.45);
}

body[data-hud="immersive"] .tdnd-hud-caret b {
  font-weight: normal;
  padding: 5px 7px;
  border: 1px solid rgba(126, 255, 222, 0.55);
  background: rgba(0, 12, 8, 0.55);
  box-shadow: 0 0 12px rgba(0, 255, 157, 0.12), inset 0 0 8px rgba(0, 255, 157, 0.08);
}

body[data-hud="immersive"] .tdnd-hud-caret small {
  font-size: 8px;
  letter-spacing: 0.24em;
  color: rgba(126, 255, 222, 0.6);
}

body[data-hud="immersive"] .tdnd-hud-caret::before {
  content: "";
  width: 0;
  height: 0;
  border: 5px solid transparent;
}

body[data-hud="immersive"] .tdnd-hud-tape--left .tdnd-hud-caret { left: 0; }
body[data-hud="immersive"] .tdnd-hud-tape--left .tdnd-hud-caret::before { border-left-color: rgba(126, 255, 222, 0.9); }
body[data-hud="immersive"] .tdnd-hud-tape--right .tdnd-hud-caret { right: 0; flex-direction: row-reverse; }
body[data-hud="immersive"] .tdnd-hud-tape--right .tdnd-hud-caret::before { border-right-color: rgba(126, 255, 222, 0.9); }

@media (max-width: 900px) {
  :root { --tdnd-hud-tape-width: 64px; }
  body[data-hud="immersive"] .tdnd-hud-tape--left { left: 14px; }
  body[data-hud="immersive"] .tdnd-hud-tape--right { right: 14px; }
  body[data-hud="immersive"] .tdnd-hud-caret small { display: none; }
}

/* Phones: content runs edge to edge, so the tapes shrink to a thin tick strip. */
@media (max-width: 600px) {
  :root { --tdnd-hud-tape-width: 18px; --tdnd-hud-tape-opacity: 0.55; }
  body[data-hud="immersive"] .tdnd-hud-tape--left { left: 2px; }
  body[data-hud="immersive"] .tdnd-hud-tape--right { right: 2px; }
  body[data-hud="immersive"] .tdnd-hud-caret { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  body[data-hud="immersive"] .tdnd-hud-tapes {
    transform: none !important;
  }
}
