:root {
  --world-base: #171a17;
  --world-depth: #25251f;
  --world-ink: #f4ede1;
  --world-champagne: #c9b89a;
  --world-line: rgba(216, 208, 194, 0.14);
  --world-line-strong: rgba(216, 208, 194, 0.28);
  --world-signal: #8fa39c;
  --world-panel: rgba(33, 31, 26, 0.82);
}

:focus-visible {
  outline: 1px solid var(--champagne);
  outline-offset: 3px;
}

body[data-view-active]:not([data-view-active="home"]) {
  background: var(--world-base);
}

/* -------- Portal hero (normal document flow, no scroll sequence) -------- */
.portal-story {
  position: relative;
  height: auto;
}
.portal-stage {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--near-black);
  display: flex;
  align-items: center;
}
.portal-media {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 6vw 0 0;
}
.portal-video-frame {
  width: min(86vh, 52vw, 820px);
  aspect-ratio: 1 / 1;
  position: relative;
  overflow: hidden;
  z-index: 0;
  background: var(--near-black);
}
.portal-poster {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  pointer-events: none;
  z-index: 0;
}
.portal-poster[hidden] {
  display: none !important;
}
.portal-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  display: block;
  pointer-events: none;
  background: transparent;
  position: relative;
  z-index: 1;
}
body.video-autoplay-blocked .portal-video,
html.prefers-reduced-motion .portal-video,
.portal-video.is-fallback {
  display: none !important;
}
body.video-autoplay-blocked .portal-poster:not([hidden]),
html.prefers-reduced-motion .portal-poster:not([hidden]) {
  display: block;
  z-index: 1;
}
body.video-autoplay-blocked .portal-video-frame {
  background: var(--near-black) url("/assets/portal-poster.jpg") center / cover no-repeat;
}
.portal-video-frame::before,
.portal-video-frame::after {
  content: none;
}
body.video-autoplay-blocked .portal-video-frame::before,
body.video-autoplay-blocked .portal-video-frame::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
body.video-autoplay-blocked .portal-poster {
  animation: avs-portal-drift 32s ease-in-out infinite alternate;
  transform-origin: 58% 46%;
}
body.video-autoplay-blocked .portal-video-frame::before {
  inset: -18%;
  z-index: 2;
  background:
    radial-gradient(ellipse at 48% 42%, rgba(244, 237, 225, 0.16) 0%, transparent 42%),
    radial-gradient(ellipse at 62% 58%, rgba(201, 184, 154, 0.12) 0%, transparent 48%);
  animation: avs-portal-glow 8s ease-in-out infinite;
}
body.video-autoplay-blocked .portal-video-frame::after {
  inset: -8%;
  z-index: 3;
  background:
    linear-gradient(115deg, transparent 20%, rgba(232, 223, 209, 0.07) 46%, transparent 72%);
  mix-blend-mode: screen;
  animation: avs-portal-mist 18s ease-in-out infinite;
}
@keyframes avs-portal-drift {
  0% { transform: scale(1) translate3d(0, 0, 0); }
  100% { transform: scale(1.06) translate3d(-1.4%, -1%, 0); }
}
@keyframes avs-portal-glow {
  0%, 100% { opacity: 0.32; }
  50% { opacity: 0.62; }
}
@keyframes avs-portal-mist {
  0% { transform: translate3d(-4%, 2%, 0); opacity: 0.2; }
  50% { transform: translate3d(5%, -3%, 0); opacity: 0.42; }
  100% { transform: translate3d(-4%, 2%, 0); opacity: 0.2; }
}
.portal-video::-webkit-media-controls,
.portal-video::-webkit-media-controls-enclosure,
.portal-video::-webkit-media-controls-start-playback-button,
.portal-video::-webkit-media-controls-overlay-play-button,
.portal-video::-webkit-media-controls-panel,
.portal-video::-moz-media-controls {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
  -webkit-appearance: none;
  appearance: none;
}
body.video-autoplay-blocked .portal-video::-webkit-media-controls,
body.video-autoplay-blocked .portal-video::-webkit-media-controls-start-playback-button,
body.video-autoplay-blocked .portal-video::-webkit-media-controls-overlay-play-button {
  display: none !important;
  opacity: 0 !important;
}
.portal-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgba(13, 12, 10, 0.94) 0%,
    rgba(13, 12, 10, 0.78) 22%,
    rgba(13, 12, 10, 0.42) 42%,
    rgba(13, 12, 10, 0.12) 68%,
    rgba(13, 12, 10, 0.04) 100%
  );
  z-index: 2;
}
.portal-ambient-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background: radial-gradient(ellipse at 72% 48%, transparent 18%, rgba(13, 12, 10, 0.35) 70%);
  opacity: 1;
}
.portal-stage .hero {
  position: relative;
  z-index: 4;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  background: transparent;
  padding: 8rem var(--page-gutter) 5rem;
  justify-content: flex-start;
}
.portal-stage .hero__ambient,
.portal-stage .hero__glow { display: none; }
.portal-stage .hero__inner {
  max-width: none;
  width: min(72rem, calc(100% - 0px));
  margin: 0;
  margin-inline: 0;
  text-align: left;
}

@media (min-width: 1400px) {
  .portal-stage .hero {
    padding-left: clamp(40px, 2.5vw, 48px);
    padding-right: var(--page-gutter);
  }
}

@media (max-width: 1024px) {
  .portal-stage .hero {
    padding-left: 24px;
    padding-right: 24px;
  }
}

@media (max-width: 480px) {
  .portal-stage .hero {
    padding-left: 20px;
    padding-right: 20px;
  }
}

@media (max-width: 900px) {
  .portal-media {
    justify-content: center;
    padding: 0;
    align-items: flex-start;
    padding-top: 18vh;
  }
  .portal-video-frame {
    width: min(92vw, 78vh);
  }
  .portal-shade {
    background: linear-gradient(
      180deg,
      rgba(13, 12, 10, 0.2) 0%,
      rgba(13, 12, 10, 0.72) 42%,
      rgba(13, 12, 10, 0.92) 100%
    );
  }
  .portal-stage .hero {
    align-items: flex-end;
    padding: 7rem 24px 4.5rem;
  }
  .portal-stage .hero__side { display: none; }
}

@media (max-width: 480px) {
  .portal-stage .hero {
    padding: 6.5rem 20px 4rem;
  }
}

/* -------- System world (inner views; not gated by a portal sequence) -------- */
.system-world {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.9s var(--ease-quiet);
}
body[data-view-active]:not([data-view-active="home"]) .system-world {
  opacity: 1;
}

.system-network {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  mix-blend-mode: screen;
}
.system-equations {
  position: absolute;
  inset: 0;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}
.system-equations span {
  position: absolute;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(0.78rem, 1.15vw, 1.05rem);
  color: #C9B89A;
  opacity: 0.3;
  white-space: nowrap;
  pointer-events: none;
  letter-spacing: 0.02em;
  mix-blend-mode: screen;
}
.system-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 28%, rgba(13, 12, 10, 0.18) 0%, transparent 46%),
    radial-gradient(ellipse at 50% 72%, rgba(13, 12, 10, 0.12) 0%, transparent 42%);
}

.system-net__line {
  fill: none;
  stroke: #9D8FC7;
  stroke-opacity: 0.35;
  stroke-width: 1;
}
.system-net__line--signal {
  stroke: #9D8FC7;
  stroke-opacity: 0.4;
  stroke-width: 1.15;
  stroke-dasharray: 6 28;
  animation: signalFlow 18s linear infinite;
}
.system-net__node {
  fill: #E8DFD1;
  opacity: 0.45;
}
.system-net__node-halo {
  fill: #E8DFD1;
  opacity: 0.16;
  pointer-events: none;
}
.system-net__node--pulse,
.system-net__node--glow {
  animation: nodePulse 7s var(--ease-quiet) infinite;
  filter: url(#nodeGlow) drop-shadow(0 0 2.4px rgba(232, 223, 209, 0.5)) drop-shadow(0 0 7px rgba(232, 223, 209, 0.22));
}
.system-net__layer--far { opacity: 0.72; }
.system-net__layer--mid { opacity: 0.9; }
.system-net__layer--near { opacity: 1; }

@keyframes signalFlow {
  to { stroke-dashoffset: -220; }
}
@keyframes nodePulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.58; }
}

@media (prefers-reduced-motion: reduce) {
  .system-net__line--signal,
  .system-net__node--pulse,
  .system-net__node--glow { animation: none; }
}

/* -------- Inner reading surfaces -------- */
body[data-view-active]:not([data-view-active="home"]) .intro,
body[data-view-active]:not([data-view-active="home"]) .approach,
body[data-view-active]:not([data-view-active="home"]) .why,
body[data-view-active]:not([data-view-active="home"]) .about-story,
body[data-view-active]:not([data-view-active="home"]) .service-section--alt {
  background: linear-gradient(90deg,
    rgba(13, 12, 10, 0.08) 0%,
    rgba(13, 12, 10, 0.28) 8%,
    rgba(13, 12, 10, 0.5) 16%,
    rgba(13, 12, 10, 0.56) 50%,
    rgba(13, 12, 10, 0.5) 84%,
    rgba(13, 12, 10, 0.28) 92%,
    rgba(13, 12, 10, 0.08) 100%);
}
body[data-view-active]:not([data-view-active="home"]) .services,
body[data-view-active]:not([data-view-active="home"]) .work,
body[data-view-active]:not([data-view-active="home"]) .work-page,
body[data-view-active]:not([data-view-active="home"]) .founder,
body[data-view-active]:not([data-view-active="home"]) .aside-quote,
body[data-view-active]:not([data-view-active="home"]) .cta-final,
body[data-view-active]:not([data-view-active="home"]) .service-meta,
body[data-view-active]:not([data-view-active="home"]) .connection {
  background: linear-gradient(90deg,
    rgba(23, 26, 23, 0.1) 0%,
    rgba(23, 26, 23, 0.32) 8%,
    rgba(23, 26, 23, 0.52) 16%,
    rgba(23, 26, 23, 0.58) 50%,
    rgba(23, 26, 23, 0.52) 84%,
    rgba(23, 26, 23, 0.32) 92%,
    rgba(23, 26, 23, 0.1) 100%);
}
body[data-view-active]:not([data-view-active="home"]) .footer {
  background: rgba(13, 12, 10, 0.92);
}
body[data-view-active]:not([data-view-active="home"]) .service-hero,
body[data-view-active]:not([data-view-active="home"]) .page-intro,
body[data-view-active]:not([data-view-active="home"]) .contact-page {
  background: linear-gradient(90deg,
    rgba(23, 26, 23, 0.06) 0%,
    rgba(23, 26, 23, 0.22) 7%,
    rgba(23, 26, 23, 0.38) 14%,
    rgba(23, 26, 23, 0.46) 50%,
    rgba(23, 26, 23, 0.38) 86%,
    rgba(23, 26, 23, 0.22) 93%,
    rgba(23, 26, 23, 0.06) 100%);
}
body[data-view-active]:not([data-view-active="home"]) .service-card,
body[data-view-active]:not([data-view-active="home"]) .work__item,
body[data-view-active]:not([data-view-active="home"]) .contact-form,
body[data-view-active]:not([data-view-active="home"]) .work-page__item,
body[data-view-active]:not([data-view-active="home"]) .why__item,
body[data-view-active]:not([data-view-active="home"]) .service-list__item {
  background: var(--world-panel);
}

.contact-form,
.contact-form__input,
.contact-form__textarea,
.contact-form__select,
.contact-form__submit {
  position: relative;
  z-index: 2;
  pointer-events: auto;
}
.contact-form__turnstile {
  margin: 0;
  min-height: 65px;
  width: 100%;
  max-width: 100%;
  overflow: visible;
  position: relative;
  z-index: 2;
  pointer-events: auto;
}
.contact-form__field--turnstile {
  margin: 1.25rem 0 0.75rem;
}
.contact-form__turnstile iframe {
  max-width: 100%;
}

/* -------- Ecosystem -------- */
.ecosystem {
  padding: 10rem 2rem;
  background: rgba(13, 12, 10, 0.72);
  position: relative;
}
.ecosystem__header {
  max-width: var(--max-w);
  margin: 0 auto 4.5rem;
  text-align: center;
}
.ecosystem__header h2 { margin-top: 1.5rem; }
.ecosystem__lead {
  margin: 1.5rem auto 0;
  max-width: 720px;
  color: var(--ivory-dim);
  font-size: clamp(1.0625rem, 1.5vw, 1.25rem);
  line-height: 1.55;
  font-weight: 300;
}
.ecosystem__stage {
  max-width: var(--max-w-wide);
  margin: 0 auto;
  position: relative;
  min-height: 520px;
}
.ecosystem__svg {
  width: 100%;
  height: auto;
  display: block;
}
.eco-path {
  fill: none;
  stroke: var(--world-champagne);
  stroke-opacity: 0.28;
  stroke-width: 1;
}
.eco-path--flow {
  stroke: var(--world-signal);
  stroke-opacity: 0.5;
  stroke-dasharray: 5 22;
  animation: signalFlow 14s linear infinite;
}
.eco-node {
  fill: var(--world-depth);
  stroke: var(--world-line-strong);
  stroke-width: 1;
}
.eco-node--ai { stroke: var(--violet-soft); }
.eco-label {
  fill: var(--world-ink);
  font-family: var(--serif);
  font-size: 15px;
}

a.work__item {
  display: block;
  color: inherit;
  text-decoration: none;
}
a.work__item:focus-visible,
.work-page__item-title-link:focus-visible,
.work-page__item-cta:focus-visible,
.project-gallery__btn:focus-visible {
  outline: 1px solid var(--champagne);
  outline-offset: 4px;
}
.work-page__item-title-link {
  color: inherit;
  text-decoration: none;
}
.work-page__item-title-link:hover { color: var(--champagne); }
.work-page__item-cta {
  display: inline-block;
  margin-top: 1.75rem;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--champagne);
  border-bottom: 1px solid transparent;
  padding-bottom: 0.15rem;
  transition: border-color 0.4s var(--ease-quiet), color 0.4s var(--ease-quiet);
}
.work-page__item-cta:hover,
.work-page__item-cta:focus-visible {
  border-bottom-color: var(--champagne);
}

.device-frame {
  background: #1a1814;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.device-frame__chrome {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  background: #2a2620;
  border-bottom: 1px solid var(--line);
}
.device-frame__chrome span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(244, 237, 225, 0.18);
}
.project-gallery {
  position: relative;
}
.project-gallery__viewport {
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.project-gallery__viewport::-webkit-scrollbar { display: none; }
.project-gallery__track {
  display: flex;
  margin: 0;
  padding: 0;
  list-style: none;
}
.project-gallery__slide {
  flex: 0 0 100%;
  scroll-snap-align: start;
  margin: 0;
  background: #12110e;
}
.project-gallery__slide a {
  display: block;
  line-height: 0;
}
.project-gallery__slide img {
  width: 100%;
  height: auto;
  max-height: 62vh;
  object-fit: contain;
  object-position: top center;
  display: block;
  background: #12110e;
}
.device-frame.is-showing-cover .device-frame__chrome {
  display: none;
}
.project-gallery__slide--cover img {
  aspect-ratio: 3 / 2;
  object-position: center;
}
.project-gallery__bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.85rem;
}
.project-gallery__btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line-2);
  color: var(--ivory);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  transition: border-color 0.35s var(--ease-quiet), color 0.35s var(--ease-quiet);
}
.project-gallery__btn:hover {
  border-color: var(--champagne);
  color: var(--champagne);
}
.project-gallery__btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.project-gallery__status {
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--stone);
  font-variant-numeric: tabular-nums;
}

.system-diagram {
  position: relative;
  margin-top: 4rem;
  padding: 3.5rem 1.5rem 2.5rem;
  border: 1px solid var(--line);
  background: rgba(13, 12, 10, 0.45);
  overflow: hidden;
}
.system-diagram__bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.55;
}
.system-diagram__stages {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 2.5rem;
}
.system-diagram__connector {
  position: absolute;
  z-index: 0;
  top: 4.35rem;
  left: 12%;
  right: 12%;
  height: 1px;
  background: var(--line-2);
  overflow: hidden;
  pointer-events: none;
}
.system-diagram__connector-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--champagne);
}
.system-diagram.can-play .system-diagram__connector-fill { width: 0; }
.system-diagram__signal {
  position: absolute;
  top: 4.2rem;
  left: 12%;
  width: 9px;
  height: 9px;
  margin-left: -4px;
  border-radius: 50%;
  background: var(--world-signal);
  opacity: 0;
  pointer-events: none;
}
.system-diagram__stage {
  text-align: left;
}
.system-diagram__node {
  width: 36px;
  height: 36px;
  border: 1px solid var(--champagne);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 0.8125rem;
  color: var(--champagne);
  background: var(--near-black);
  margin-bottom: 1.25rem;
  position: relative;
  z-index: 2;
}
.system-diagram__stage h3 {
  font-family: var(--serif);
  font-size: clamp(1.375rem, 2vw, 1.75rem);
  font-weight: 400;
  color: var(--ivory);
  margin-bottom: 0.75rem;
}
.system-diagram__stage p {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--ivory-dim);
  font-weight: 300;
}
.system-diagram__keys {
  margin-top: 1.25rem;
  font-size: 0.6875rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--stone);
  line-height: 1.6;
}
.system-diagram.can-play .system-diagram__stage {
  opacity: 0;
  transform: translateY(16px);
}
.system-diagram.is-in .system-diagram__connector-fill {
  animation: diagramDraw 0.7s var(--ease-quiet) forwards;
}
.system-diagram.is-in .system-diagram__stage:nth-child(1) {
  animation: diagramStage 0.55s var(--ease-quiet) 0.25s forwards;
}
.system-diagram.is-in .system-diagram__stage:nth-child(2) {
  animation: diagramStage 0.55s var(--ease-quiet) 0.45s forwards;
}
.system-diagram.is-in .system-diagram__stage:nth-child(3) {
  animation: diagramStage 0.55s var(--ease-quiet) 0.65s forwards;
}
.system-diagram.is-in .system-diagram__signal {
  animation: diagramSignal 1.4s var(--ease-quiet) 0.85s forwards;
}
@keyframes diagramDraw {
  to { width: 100%; }
}
@keyframes diagramStage {
  to { opacity: 1; transform: none; }
}
@keyframes diagramSignal {
  0% { opacity: 0; left: 12%; }
  12% { opacity: 1; }
  100% { opacity: 0; left: 88%; }
}

@media (prefers-reduced-motion: reduce) {
  .eco-path--flow { animation: none; }
  .portal-story { height: auto; }
  .portal-stage { position: relative; height: 100vh; height: 100dvh; }
  .system-diagram__stage { opacity: 1; transform: none; }
  .system-diagram__connector-fill { width: 100%; animation: none; }
  .system-diagram__signal { display: none; }
}

@media (max-width: 900px) {
  .work-page__item-link {
    grid-template-columns: 1fr;
    gap: 2rem;
    direction: ltr !important;
  }
  .system-diagram {
    padding: 2.25rem 1.25rem;
  }
  .system-diagram__stages {
    grid-template-columns: 1fr;
    gap: 2.25rem;
  }
  .system-diagram__connector {
    top: 2.25rem;
    bottom: 2.25rem;
    left: calc(1.25rem + 17px);
    right: auto;
    width: 1px;
    height: auto;
  }
  .system-diagram__connector-fill {
    width: 100%;
    height: 0;
  }
  .system-diagram.can-play .system-diagram__connector-fill {
    width: 100%;
    height: 0;
  }
  .system-diagram.is-in .system-diagram__connector-fill {
    animation: diagramDrawY 0.7s var(--ease-quiet) forwards;
  }
  .system-diagram__signal { display: none; }
}

@keyframes diagramDrawY {
  to { height: 100%; }
}

@media (max-width: 768px) {
  .ecosystem__stage { min-height: 0; }
  .system-equations span {
    font-size: 0.72rem;
    opacity: 0.3;
  }
  .system-equations span:nth-child(3),
  .system-equations span:nth-child(4) {
    display: none;
  }
  body[data-view-active]:not([data-view-active="home"]) .intro,
  body[data-view-active]:not([data-view-active="home"]) .approach,
  body[data-view-active]:not([data-view-active="home"]) .why,
  body[data-view-active]:not([data-view-active="home"]) .about-story,
  body[data-view-active]:not([data-view-active="home"]) .service-section--alt {
    background: rgba(13, 12, 10, 0.42);
  }
  body[data-view-active]:not([data-view-active="home"]) .services,
  body[data-view-active]:not([data-view-active="home"]) .work,
  body[data-view-active]:not([data-view-active="home"]) .work-page,
  body[data-view-active]:not([data-view-active="home"]) .founder,
  body[data-view-active]:not([data-view-active="home"]) .aside-quote,
  body[data-view-active]:not([data-view-active="home"]) .cta-final,
  body[data-view-active]:not([data-view-active="home"]) .service-meta,
  body[data-view-active]:not([data-view-active="home"]) .connection {
    background: rgba(23, 26, 23, 0.44);
  }
  body[data-view-active]:not([data-view-active="home"]) .service-hero,
  body[data-view-active]:not([data-view-active="home"]) .page-intro,
  body[data-view-active]:not([data-view-active="home"]) .contact-page {
    background: rgba(23, 26, 23, 0.3);
  }
}
