.portal-link {
  --portal-photo: url('/portal-studio.jpg');
  --portal-focus: 61%;
  position: relative;
  isolation: isolate;
  container: portal-card / inline-size;
  display: inline-flex;
  align-items: end;
  width: min(100%, 18rem);
  min-height: 90px;
  padding: 14px 47px 14px 15px;
  overflow: hidden;
  border: 1px solid #527aa6;
  border-radius: 12px;
  background: #112b4b;
  box-shadow: inset 0 1px #b8ddff52, 0 3px 0 #0c223c, 0 8px 18px #132d4d25;
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 750;
  line-height: 1.2;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 150ms, box-shadow 150ms;
}

.portal-link--library {
  --portal-photo: url('/portal-library.jpg');
  --portal-focus: 65%;
}

.portal-link--owner {
  --portal-photo: url('/portal-owner.jpg');
  --portal-focus: 55%;
}

.portal-link::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, #071b32 1%, #0c2343ed 31%, #0b234947 81%),
    linear-gradient(0deg, #041327e8, transparent 82%),
    var(--portal-photo) var(--portal-focus) 53% / cover;
  transition: transform 230ms ease-out;
}

.portal-link::after {
  content: '';
  position: absolute;
  pointer-events: none;
  right: 12px;
  bottom: 12px;
  width: 26px;
  height: 26px;
  border: 1px solid #99cbf095;
  border-radius: 50%;
  background:
    linear-gradient(#e0f2ff, #e0f2ff) 6px 11px / 11px 2px no-repeat,
    linear-gradient(45deg, transparent 43%, #e0f2ff 44% 66%, transparent 67%) 12px 7px / 6px 6px no-repeat,
    linear-gradient(135deg, transparent 43%, #e0f2ff 44% 66%, transparent 67%) 12px 12px / 6px 6px no-repeat,
    #0b2a4bcc;
}

.portal-link__label {
  color: inherit;
  text-shadow: 0 1px 6px #041327;
  white-space: nowrap;
  font-size: clamp(.625rem, 14cqi, 1em);
}

@container portal-card (max-width: 14.5rem) {
  .portal-link__brand { display: none; }
}

.portal-link:focus-visible {
  color: #fff;
  border-color: #6dabdf;
  box-shadow: inset 0 1px #b8ddff72, 0 3px 0 #0c223c, 0 8px 20px #153e6856;
}

.portal-link:disabled { cursor: wait; opacity: .7; }
.portal-link[hidden] { display: none; }

.portal-link--studio {
  --portal-focus: 72%;
  border-color: #688ba9;
  background: linear-gradient(135deg, #7798b8, #233e5d 21%, #142841 67%, #527493);
}

.portal-link--studio::before {
  inset: 5px 6px;
  border: 1px solid #a2c6e6a6;
  border-radius: 6px;
  background:
    linear-gradient(90deg, #e4f3ff, #63809d) left 3px top 10px / 3px 9px no-repeat,
    linear-gradient(90deg, #e4f3ff, #63809d) left 3px bottom 10px / 3px 9px no-repeat,
    linear-gradient(154deg, transparent 15%, #daeeff4d 30%, #c0e2ff0a 55%, transparent 56%),
    linear-gradient(0deg, #04152cee 0%, #081d3670 48%, #578bb025 100%),
    var(--portal-photo) var(--portal-focus) 51% / cover;
  box-shadow: inset 0 1px 3px #d2ecff58, inset 0 -2px 8px #071a33a3, 0 1px 2px #081729;
  transition: filter 150ms;
}

.portal-link--studio::after {
  right: 19px;
  bottom: auto;
  top: 50%;
  width: 8px;
  height: 36px;
  border: 1px solid #c4d6e8a8;
  border-radius: 4px;
  background: linear-gradient(90deg, #647f9d, #f0f8ff 37%, #b8cde0 58%, #4a6988);
  box-shadow: 2px 2px 4px #06182ccb;
  transform: translateY(-50%);
}

.portal-link--studio:focus-visible::before {
  filter: brightness(1.13);
}

@media (hover: hover) and (pointer: fine) {
  .portal-link:hover:not(:disabled) {
    color: #fff;
    border-color: #6dabdf;
    box-shadow: inset 0 1px #b8ddff72, 0 3px 0 #0c223c, 0 8px 20px #153e6856;
  }

  .portal-link:not(.portal-link--studio):hover:not(:disabled)::before { transform: scale(1.045); }
  .portal-link--studio:hover:not(:disabled)::before { filter: brightness(1.13); }
}

.portal-row {
  display: flex;
  flex-wrap: nowrap;
  gap: clamp(6px, 1.6vw, 16px);
  container: portal-row / inline-size;
}

.portal-row > .portal-link {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
}

.account-studio .portal-row,
#home-portal-row { margin-top: 16px; }

#home-portal-row:not([hidden]) + .hero-actions { margin-top: 16px; }

.portal-row:not(:has(> .portal-link:not([hidden]) ~ .portal-link:not([hidden]))) > .portal-link {
  max-width: 18rem;
}

@container portal-row (max-width: 580px) {
  :is(.portal-row, .profile-destinations) > .portal-link {
    justify-content: center;
    min-height: 82px;
    padding: 8px 5px;
    border-radius: 8px;
    font-size: clamp(12px, 3vw, 15px);
    text-align: center;
  }

  :is(.portal-row, .profile-destinations) > .portal-link::after { display: none; }

  .portal-row > .portal-link--studio::after {
    display: block;
    right: 12px;
    top: 26px;
    height: 25px;
    width: 6px;
  }
}

.portal-library-art {
  position: relative;
  display: grid;
  align-content: end;
  isolation: isolate;
  min-height: clamp(184px, 26vw, 244px);
  padding: clamp(18px, 3vw, 32px);
  overflow: hidden;
  color: #fff;
  border: 1px solid #577ba1;
  border-radius: 16px;
  background: #102743;
  box-shadow: 0 12px 22px #163c6424;
}

.portal-library-art__scene {
  position: absolute;
  z-index: -1;
  inset: 0;
  background:
    linear-gradient(90deg, #06172ee8, #071b35a6 45%, #0a214c28 90%),
    linear-gradient(0deg, #041225de, transparent 78%),
    url('/portal-library.jpg') 57% 48% / cover;
}

.account-intro.portal-library-art h1 {
  max-width: 16ch;
  color: #fff;
  font-size: clamp(29px, 5vw, 54px);
  text-wrap: balance;
}

.account-intro.portal-library-art > p { color: #e0edfe; }

.portal-intro {
  --portal-entry-time: 1260ms;
  --portal-entry-focus: 62%;
  --portal-room-start: -50%;
  --portal-room-finish: -62%;
  --portal-door-left: 39%;
  --portal-door-right: 94%;
  --portal-door-swing: -2%;
  position: fixed;
  inset: 0;
  z-index: 1000;
  isolation: isolate;
  overflow: hidden;
  pointer-events: none;
  container-type: size;
  background: #071426;
  color: #fff;
  animation: portal-arrival var(--portal-entry-time) ease-in both;
}

.portal-intro[data-portal-intro='library'] {
  --portal-entry-time: 1560ms;
  --portal-entry-focus: 48.5%;
  --portal-room-finish: -48.5%;
  --library-room-middle: 2.06;
  --library-room-finish: 4.45;
  --portal-door-left: 15%;
  --portal-door-right: 72%;
  --portal-door-swing: 2%;
  animation-name: portal-library-arrival;
}

.portal-intro[data-portal-intro='owner'] {
  --portal-entry-focus: 50%;
  --portal-room-finish: -51%;
  --portal-door-left: 20%;
  --portal-door-right: 95%;
}

.portal-intro__frame {
  position: absolute;
  inset: 50% auto auto 50%;
  width: max(100vw, 177.778dvh);
  width: max(100cqw, 177.778cqh);
  aspect-ratio: 16 / 9;
  animation: portal-enter-room var(--portal-entry-time) linear both;
  transform-origin: var(--portal-entry-focus) 50%;
}

.portal-intro[data-portal-intro='library'] .portal-intro__frame {
  animation-name: portal-walk-to-rack;
  transform-origin: var(--portal-entry-focus) 54%;
}

.portal-intro__image {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.portal-intro__doorway {
  /* Keep the foreground door on its own plane as the room approaches. */
  mask-image: linear-gradient(90deg,
    #000 var(--portal-door-left), transparent calc(var(--portal-door-left) + 1%),
    transparent calc(var(--portal-door-right) - 1%), #000 var(--portal-door-right));
  transform-origin: var(--portal-entry-focus) center;
  animation: portal-pass-doorway 960ms cubic-bezier(.45, .09, .28, 1) both;
}

.portal-intro__frame::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at var(--portal-entry-focus) 45%, transparent 20%, #040f2362 96%);
}

.portal-intro__label {
  position: absolute;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  left: max(24px, env(safe-area-inset-left));
  width: fit-content;
  max-width: calc(100% - 48px);
  padding: 9px 14px;
  border: 1px solid #b7dcff80;
  border-radius: 8px;
  background: #061a34ed;
  color: #f0f7ff;
  font-size: clamp(12px, 4vw, 19px);
  font-weight: 730;
  line-height: 1.25;
  white-space: nowrap;
  box-shadow: 0 5px 16px #04122257;
}

.portal-intro[data-portal-intro='library'] .portal-intro__label {
  animation: portal-library-label var(--portal-entry-time) ease-out both;
}

@keyframes portal-arrival {
  0%, 67% { opacity: 1; }
  to { opacity: 0; }
}

@keyframes portal-enter-room {
  from {
    transform: translate(var(--portal-room-start), -50%) scale(1.06);
    animation-timing-function: ease-in;
  }
  25% { transform: translate(var(--portal-room-start), -50.8%) scale(1.12) rotate(-.22deg); }
  52% { transform: translate(var(--portal-room-finish), -49.4%) scale(1.34) rotate(.24deg); }
  76% { transform: translate(var(--portal-room-finish), -50.6%) scale(1.60) rotate(-.15deg); }
  to { transform: translate(var(--portal-room-finish), -50%) scale(1.78); }
}

@keyframes portal-library-arrival {
  0%, 69% { opacity: 1; }
  to { opacity: 0; }
}

@keyframes portal-walk-to-rack {
  from {
    transform: translate(var(--portal-room-start), -50%) scale(1.02);
    animation-timing-function: cubic-bezier(.45, .02, .68, .8);
  }
  55% {
    transform: translate(var(--portal-room-finish), -53%) scale(var(--library-room-middle));
    animation-timing-function: cubic-bezier(.3, .12, .45, 1);
  }
  to { transform: translate(var(--portal-room-finish), -54%) scale(var(--library-room-finish)); }
}

@keyframes portal-library-label {
  0%, 33% { opacity: 1; }
  64%, to { opacity: 0; }
}

@keyframes portal-pass-doorway {
  0%, 7% { transform: none; opacity: 1; }
  65% { opacity: 1; }
  to { transform: translateX(var(--portal-door-swing)) scaleX(1.40); opacity: 0; }
}

@media (max-width: 580px) {
  .portal-link { min-height: 80px; }
  .portal-library-art__scene { background-position: center, center, 52% 48%; }
}

@media (orientation: portrait) and (max-aspect-ratio: 3 / 4) {
  .portal-intro[data-portal-intro='studio'] { --portal-room-start: -40%; }
  .portal-intro[data-portal-intro='library'] {
    --portal-room-start: -57%;
    --library-room-middle: 1.61;
    --library-room-finish: 2.42;
  }
  .portal-intro[data-portal-intro='owner'] { --portal-room-start: -25%; }
}

@media (prefers-reduced-motion: reduce) {
  .portal-link, .portal-link::before { transition: none; }
  .portal-link:hover::before { transform: none; }
  .portal-intro { display: none; }
}
