:root {
  --portal-fallback: #080a09;
  --portal-ink: #f3f6f4;
  --portal-safe-top: env(safe-area-inset-top, 0px);
  --portal-safe-right: env(safe-area-inset-right, 0px);
  --portal-safe-bottom: env(safe-area-inset-bottom, 0px);
  --portal-safe-left: env(safe-area-inset-left, 0px);
}

html:has(body.portal-body),
body.portal-body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--portal-fallback);
}

body.portal-body {
  padding: 0;
  color: var(--portal-ink);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

.portal-body button {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

.portal-body a {
  color: inherit;
  letter-spacing: 0;
  text-decoration: none;
}

.portal-scroll {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow-x: clip;
  overflow-y: auto;
  overscroll-behavior-y: none;
  background: var(--portal-fallback);
  scrollbar-width: none;
}

.portal-scroll::-webkit-scrollbar { display: none; }

.portal-track { height: 100%; }
.portal-enhanced .portal-track { height: 450vh; height: 450dvh; }
.portal-track.is-static { height: 100%; }

.portal-frame {
  --portal-opening: 1;
  --portal-word-scale: 1;
  --portal-mask-opacity: 0;
  --portal-wash-opacity: 1;
  --portal-menu-opacity: 1;
  --portal-menu-shift: 0px;
  position: sticky;
  top: var(--portal-scene-top, 0px);
  isolation: isolate;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--portal-fallback);
}

/* Cover the parser-to-deferred-script frame without hiding the no-JS fallback. */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
  html:not(.portal-enhanced) .portal-frame {
    --portal-opening: 0;
    --portal-mask-opacity: 1;
    --portal-menu-opacity: 0;
    animation: portal-bootstrap-release 50ms linear 3s forwards;
  }
  html:not(.portal-enhanced) .portal-destinations {
    visibility: hidden;
    animation: portal-bootstrap-links 50ms linear 3s forwards;
  }
}
@keyframes portal-bootstrap-release {
  to { --portal-opening: 1; --portal-mask-opacity: 0; --portal-menu-opacity: 1; }
}
@keyframes portal-bootstrap-links { to { visibility: visible; } }

.portal-photo {
  position: absolute;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 84% 88%;
  transform: scale(1.1);
  transform-origin: 50% 0;
  background: var(--portal-fallback);
}

.portal-frame[data-image-failed="true"] .portal-photo { visibility: hidden; }

.portal-wash {
  position: absolute;
  z-index: 1;
  inset: 0;
  background: linear-gradient(
    90deg,
    rgb(var(--hx-theme-portal-tint-rgb) / 64%) 0%,
    rgb(var(--hx-theme-portal-tint-rgb) / 54%) 42%,
    rgb(var(--hx-theme-portal-tint-rgb) / 12%) 78%,
    rgb(var(--hx-theme-portal-tint-rgb) / 8%) 100%
  );
  opacity: var(--portal-wash-opacity);
  pointer-events: none;
}

.portal-mask {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: var(--portal-mask-opacity);
  pointer-events: none;
}

.portal-mask mask { mask-type: luminance; }

/* Local comparison only; remove with the isolated preview. */
@view-transition { navigation: none; }
.portal-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  background: #080a09;
  opacity: 0;
  pointer-events: none;
  transition: opacity 450ms ease;
}
.portal-leaving::after { opacity: 0.94; }
.portal-destination {
  transition: opacity 450ms ease;
  /* Prepare row opacity compositing before the transformed menu departs. */
  will-change: opacity;
}
.portal-leaving .portal-destination:not(.portal-selected),
.portal-leaving .portal-label { opacity: 0; }
@media (prefers-reduced-motion: reduce) {
  .portal-frame::after, .portal-destination { transition: none; }
}

.portal-word-window {
  opacity: var(--portal-opening);
  transform: scale(var(--portal-word-scale));
  transform-origin: 50% 45%;
}

.portal-destinations {
  --portal-entry-top: max(90px, calc(var(--portal-safe-top) + 40px));
  position: absolute;
  z-index: 3;
  top: var(--portal-entry-top);
  left: max(8%, calc(var(--portal-safe-left) + 24px));
  width: min(480px, calc(84% - var(--portal-safe-left) - var(--portal-safe-right)));
  max-height: calc(100dvh - var(--portal-entry-top) - var(--portal-safe-bottom) - 32px);
  padding: 5px;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--portal-ink);
  text-shadow: 0 1px 8px rgb(0 0 0 / 18%);
  opacity: var(--portal-menu-opacity);
  transform: translateY(var(--portal-menu-shift));
}

.portal-label {
  margin: 0 0 20px;
  font-size: 14px;
  font-weight: 700;
}

.portal-destinations nav { display: grid; }

.portal-destination {
  --portal-arrow-shift: 0px;
  --portal-arrow-opacity: 1;
  --portal-arrow-duration: 180ms;
  display: flex;
  min-width: 0;
  min-height: 68px;
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid rgb(243 246 244 / 34%);
  font-size: 44px;
  font-weight: 600;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.portal-number {
  width: 20px;
  flex: 0 0 20px;
  font-size: 12px;
  font-weight: 500;
}

.portal-destination svg {
  width: 26px;
  height: 26px;
  margin-left: auto;
  flex: 0 0 26px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  transform: translate(var(--portal-arrow-shift), calc(-1 * var(--portal-arrow-shift)));
  opacity: var(--portal-arrow-opacity);
  transition: transform var(--portal-arrow-duration) ease, opacity var(--portal-arrow-duration) ease;
}

.portal-destination:hover {
  color: #fff;
  border-bottom-color: rgb(255 255 255 / 80%);
}
.portal-destination:hover { --portal-arrow-shift: 3px; }
.portal-leaving .portal-selected {
  --portal-arrow-shift: 8px;
  --portal-arrow-opacity: 0;
  --portal-arrow-duration: 450ms;
}

.portal-destination:focus-visible,
.portal-scroll:focus-visible {
  outline: 3px solid #f5ca43;
  outline-offset: 4px;
}

.portal-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
}

@media (orientation: portrait) {
  .portal-photo { object-position: 88% 91%; }
  .portal-destinations { --portal-entry-top: max(140px, calc(var(--portal-safe-top) + 48px)); }
}

@media (orientation: portrait) and (max-width: 600px) {
  .portal-photo { object-position: 55% 93%; }
  .portal-destinations {
    --portal-entry-top: max(80px, calc(var(--portal-safe-top) + 36px));
    left: calc(24px + var(--portal-safe-left));
    width: calc(100% - 48px - var(--portal-safe-left) - var(--portal-safe-right));
  }
  .portal-destination { min-height: 57px; gap: 8px; font-size: 30px; }
  .portal-destination svg { width: 20px; flex-basis: 20px; }
  .portal-label { margin-bottom: 12px; }
  .portal-number { width: 17px; flex-basis: 17px; font-size: 11px; }
  .portal-wash {
    background: linear-gradient(
      180deg,
      rgb(var(--hx-theme-portal-tint-rgb) / 64%) 0%,
      rgb(var(--hx-theme-portal-tint-rgb) / 57%) 54%,
      rgb(var(--hx-theme-portal-tint-rgb) / 18%) 78%,
      rgb(var(--hx-theme-portal-tint-rgb) / 8%) 100%
    );
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  .portal-destinations {
    --portal-entry-top: max(45px, calc(var(--portal-safe-top) + 20px));
    width: min(620px, calc(84% - var(--portal-safe-left) - var(--portal-safe-right)));
  }
  .portal-destinations nav { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 38px; }
  .portal-destination { min-height: 60px; gap: 10px; font-size: 30px; }
  .portal-label { margin-bottom: 8px; }
  .portal-wash {
    background: linear-gradient(
      90deg,
      rgb(var(--hx-theme-portal-tint-rgb) / 64%) 0%,
      rgb(var(--hx-theme-portal-tint-rgb) / 54%) 78%,
      rgb(var(--hx-theme-portal-tint-rgb) / 14%) 100%
    );
  }
}

@media (orientation: landscape) and (max-width: 600px),
  (orientation: landscape) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  .portal-photo { object-position: 55% 90%; }
}

@media (prefers-reduced-motion: reduce) {
  .portal-enhanced .portal-track { height: 100%; }
  .portal-destination svg { transition: none; transform: none; opacity: 1; }
}
