/* ==========================================================================
   Base variables
   ========================================================================== */
:root {
  /* Layout */
  --sidebar-width: clamp(220px, 25vw, 320px);
  --content-radius: 8px;
  --content-shadow: 0 0 12px 2px #79d0ff50;

  /* Colors */
  --color-text-primary: #ffffff;
  --color-text-muted: #b6c6d8;
  --color-surface: rgba(4, 15, 26, 0.3);
  --color-overlay: rgba(0, 0, 0, .45);

  /* Accent palette (navigation + highlights) */
  --color-accent: #79d0ff;
  --color-accent-hover: #ffffff0e;
  --color-accent-active: #0c2f51aa;
  --color-accent-outline: #81d7ff33;

  /* Scroll fades */
  --fade-top: clamp(16px, 3vh, 72px);
  --fade-bottom: clamp(16px, 3vh, 72px);

  /* Motion */
  --fade-duration: .36s;
  --fade-easing: cubic-bezier(.22, .61, .36, 1);

  /* Legacy (for nav.css) */
  --link: #e9f3ff;
  --link-hover-bg: #ffffff0e;
  --link-active-bg: #0c2f51aa;
  --link-outline: #81d7ff33;
  --dot: #79d0ff55;
  --dot-active: #79d0ff;
}

/* ==========================================================================
   Global element defaults
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  color-scheme: dark;
  height: 100%;
}

body {
  height: 100%;
  margin: 0;
  color: var(--color-text-primary);
  font-family: "Montserrat", sans-serif;
  font-optical-sizing: auto;
  font-weight: 300;
  font-style: normal;
  line-height: 1.6;
  letter-spacing: min(0.025em, calc((100vw - 768px) * 0.001));
  background-color: #07182a;
  overflow-x: hidden;
}

img,
svg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ==========================================================================
   Layout shell
   ========================================================================== */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
  position: relative;
  z-index: 1;
}

.content {
  position: relative;
  display: flex;
  justify-content: center;
  overflow: hidden;
  scroll-snap-type: y proximity;
  scrollbar-width: thin;
  scrollbar-color: #0c2f51 rgba(10, 25, 50, .88);
  scrollbar-gutter: stable;
}

.content::-webkit-scrollbar {
  width: 10px;
}

.content::-webkit-scrollbar-track {
  background: rgba(10, 25, 50, .6);
  border-left: 1px solid #ffffff12;
}

.content::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #5ec6ff, #2b80d4);
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: 10px;
}

/* ==========================================================================
   Content card / viewport
   ========================================================================== */
.contentWrap {
  width: min(96ch, 90vw);
  max-width: 1200px;
  min-width: 32ch;
  height: calc(100vh - 40px);
  margin: auto 20px;
  padding: clamp(1ch, 1.5vw, 3ch) clamp(2ch, 3vw, 6ch);
  position: relative;
  z-index: 0;
  isolation: isolate;
  color: inherit;
  background-color: rgba(11, 34, 58, 0.45);
  border-radius: var(--content-radius);
  box-shadow: inset 0 0 1px 1px rgba(181, 230, 255, 0.1), 0 0 24px 0px rgba(121, 208, 255, 0.25);
  backdrop-filter: blur(12px);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
  overscroll-behavior: contain;
}

.contentWrap *:not(.vthumb) {
  overscroll-behavior: contain;
}

.contentWrap::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, #0af 0%, #79d0ff 50%, #2b80d4 100%);
  background-size: 200% 200%;
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 1;
  animation: border-flow 8s ease-in-out infinite;
}

/* ==========================================================================
   Scroll viewport & effects
   ========================================================================== */
.scrollport {
  position: relative;
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  -ms-overflow-style: none;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient( to bottom, transparent 0, #000 var(--fade-top), #000 calc(100% - var(--fade-bottom)), transparent 100% );
          mask-image: linear-gradient( to bottom, transparent 0, #000 var(--fade-top), #000 calc(100% - var(--fade-bottom)), transparent 100% );
}

.scrollport::-webkit-scrollbar {
  display: none;
}

.scroll-inner {
  position: relative;
}

.edge-fx {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 3;
  pointer-events: none;
  border-radius: inherit;
  -webkit-backdrop-filter: blur(6px);
          backdrop-filter: blur(6px);
}

.edge-fx.fx-top {
  top: 0;
  height: var(--fade-top);
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000a 40%, transparent 100%);
          mask-image: linear-gradient(to bottom, #000 0, #000a 40%, transparent 100%);
}

.edge-fx.fx-bottom {
  bottom: 0;
  height: var(--fade-bottom);
  -webkit-mask-image: linear-gradient(to top, #000 0, #000a 40%, transparent 100%);
          mask-image: linear-gradient(to top, #000 0, #000a 40%, transparent 100%);
}

.edge-fx.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ==========================================================================
   Custom scrollbar thumb
   ========================================================================== */
.vthumb {
  position: absolute;
  top: 0;
  height: 40px;
  width: 5px;
  z-index: 4;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: radial-gradient(ellipse at center, #bfe8ff 0, #79d0ff 60%, #3aa6ea 100%);
  box-shadow: 0 0 10px #79d0ff66, 0 2px 10px #79d0ff66;
  pointer-events: auto;
  cursor: grab;
  opacity: .5;
  transition: opacity .2s ease;
}

.vthumb.left { left: -2px; }
.vthumb.right { right: -2px; }
.vthumb:active { cursor: grabbing; }
.vthumb.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ==========================================================================
   Page loader & transitions
   ========================================================================== */
#doc-scroll {
  position: relative;
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  -ms-overflow-style: none;
  scrollbar-width: none;
  --fade-dur: var(--fade-duration);
  --fade-ease: var(--fade-easing);
}

#doc-scroll::-webkit-scrollbar {
  display: none;
}

#doc-scroll,
#doc-scroll :where(*):focus,
#doc-scroll :where(*):focus-visible {
  outline: none !important;
  box-shadow: none !important;
  border: none !important;
}

#doc-scroll .scroll-inner {
  position: relative;
  min-height: calc(100% - 20px);
  will-change: opacity, filter;
  transition: opacity var(--fade-dur) var(--fade-ease),
              filter  var(--fade-dur) var(--fade-ease);
}

#doc-scroll .scroll-inner.phase-out {
  opacity: 0;
  filter: blur(8px);
}

#doc-scroll .scroll-inner.phase-in {
  opacity: 1;
  filter: blur(0);
}

#doc-scroll::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 120% at 50% 10%, rgba(7, 24, 42, 0), rgba(7, 24, 42, .35));
  opacity: 0;
  transition: opacity var(--fade-dur) var(--fade-ease);
}

#doc-scroll.is-transitioning::before,
#doc-scroll.is-loading::before {
  opacity: 1;
}

#doc-scroll.is-loading .scroll-inner {
  pointer-events: none;
}

#doc-scroll.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(#07182a40, #07182a40);
  pointer-events: none;
}

#doc-scroll.is-loading::before {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border-radius: 50%;
  border: 3px solid #79d0ff55;
  border-top-color: var(--color-accent);
  animation: xorSpin .8s linear infinite;
  pointer-events: none;
}

@keyframes xorSpin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   Background canvas & UI
   ========================================================================== */
#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.bg-toggle-btn {
  position: fixed;
  left: 20px;
  bottom: 20px;
  z-index: 9999;
  display: block;
  width: 200px;
  padding: 6px 12px;
  font: 600 12px/1 "Jura", ui-sans-serif, system-ui;
  text-align: center;
  color: var(--color-accent);
  background: var(--color-overlay);
  border: 1px solid var(--color-accent-outline);
  border-radius: 6px;
  cursor: pointer;
  transition: color .2s ease, border-color .2s ease, opacity .2s ease;
}

.bg-toggle-btn[aria-pressed="true"] {
  color: #9fe870;
  border-color: #9fe87033;
}

.bg-toggle-btn:disabled {
  opacity: .6;
  cursor: not-allowed;
}

.bg-toggle-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ==========================================================================
   Utilities & media queries
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }

  #doc-scroll::before,
  #doc-scroll .scroll-inner {
    transition: none !important;
    filter: none !important;
  }
}

@keyframes border-flow {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ==========================================================================
   Section Scroller
   ========================================================================== */
.section-scroll-indicator {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 24px;
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  z-index: 100;
}
.section-scroll-indicator.visible {
  opacity: 0.6;
  pointer-events: auto;
}
.section-scroll-indicator:hover {
  opacity: 1 !important;
}
.section-scroll-indicator::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 12px;
  height: 12px;
  border-bottom: 2px solid var(--color-accent);
  border-right: 2px solid var(--color-accent);
  transform: translateX(-50%) rotate(45deg);
  animation: section-bounce 2s infinite;
}
@keyframes section-bounce {
  0%, 20%, 50%, 80%, 100% { transform: translateX(-50%) translateY(0) rotate(45deg); }
  40% { transform: translateX(-50%) translateY(10px) rotate(45deg); }
  60% { transform: translateX(-50%) translateY(5px) rotate(45deg); }
}