.portal-3d-shell {
  --portal-3d-paper: #f4f1eb;
  --portal-3d-ink: #11110f;
  --portal-3d-line: rgba(17, 17, 15, 0.14);
  --portal-3d-glass: rgba(255, 255, 255, 0.68);
  --portal-3d-ease: cubic-bezier(0.16, 1, 0.3, 1);
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  isolation: isolate;
  color: var(--portal-3d-ink);
  background:
    radial-gradient(circle at 50% 44%, rgba(255, 255, 255, 0.96), transparent 46%),
    linear-gradient(145deg, #f8f6f2 0%, var(--portal-3d-paper) 62%, #ebe6dc 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.portal-3d-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.035'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
  opacity: 0.46;
}

.portal-3d-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.portal-3d-canvas:active,
.portal-3d-shell.is-dragging .portal-3d-canvas {
  cursor: grabbing;
}

.portal-3d-canvas:focus-visible {
  outline: 2px solid rgba(17, 17, 15, 0.72);
  outline-offset: -8px;
}

.portal-3d-fallback {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(72vw, 760px);
  max-height: 70vh;
  object-fit: contain;
  transform: translate(-50%, -50%);
  user-select: none;
  -webkit-user-drag: none;
}

.portal-3d-shell.no-webgl .portal-3d-canvas {
  display: none;
}

.portal-3d-shell.no-webgl .portal-3d-fallback {
  display: block;
}

.portal-3d-controls {
  position: absolute;
  top: calc(24px + env(safe-area-inset-top));
  right: calc(28px + env(safe-area-inset-right));
  z-index: 5;
  display: flex;
  gap: 8px;
}

.portal-3d-controls button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--portal-3d-line);
  border-radius: 999px;
  color: var(--portal-3d-ink);
  background: var(--portal-3d-glass);
  font: 560 12px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 220ms var(--portal-3d-ease),
    border-color 220ms var(--portal-3d-ease),
    background-color 220ms var(--portal-3d-ease);
}

.portal-3d-controls button:hover,
.portal-3d-controls button:focus-visible,
.portal-3d-controls button[aria-pressed="true"] {
  border-color: rgba(17, 17, 15, 0.42);
  background: rgba(255, 255, 255, 0.9);
  transform: translateY(-1px);
}

.portal-3d-controls button:active {
  transform: scale(0.97);
}

.portal-3d-controls button:focus-visible {
  outline: 2px solid rgba(17, 17, 15, 0.75);
  outline-offset: 2px;
}

.portal-3d-loader {
  position: absolute;
  left: 50%;
  bottom: calc(104px + env(safe-area-inset-bottom));
  z-index: 5;
  display: grid;
  gap: 10px;
  width: min(240px, calc(100vw - 48px));
  color: rgba(17, 17, 15, 0.62);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-align: center;
  transform: translateX(-50%);
  transition:
    opacity 520ms var(--portal-3d-ease),
    transform 520ms var(--portal-3d-ease);
}

.portal-3d-loader i {
  position: relative;
  display: block;
  height: 2px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(17, 17, 15, 0.12);
}

.portal-3d-loader i::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--portal-3d-ink);
  transform-origin: left;
  animation: portal3dLoad 1.2s var(--portal-3d-ease) infinite;
}

.portal-3d-loader.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
}

.portal-3d-hint {
  position: absolute;
  left: 50%;
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  color: rgba(17, 17, 15, 0.5);
  font-size: 11px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(-50%);
  pointer-events: none;
  transition: opacity 600ms var(--portal-3d-ease);
}

.portal-3d-hint.is-visible {
  opacity: 1;
}

.portal-3d-mouse {
  position: relative;
  width: 13px;
  height: 19px;
  border: 1px solid currentColor;
  border-radius: 8px;
}

.portal-3d-mouse::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 50%;
  width: 1px;
  height: 4px;
  background: currentColor;
  transform: translateX(-50%);
}

@keyframes portal3dLoad {
  0% { transform: translateX(-105%) scaleX(0.35); }
  55% { transform: translateX(20%) scaleX(0.55); }
  100% { transform: translateX(105%) scaleX(0.35); }
}

@media (max-width: 700px) {
  .portal-3d-controls {
    top: calc(16px + env(safe-area-inset-top));
    right: calc(16px + env(safe-area-inset-right));
  }

  .portal-3d-controls button {
    min-height: 38px;
    padding-inline: 12px;
  }

  .portal-3d-loader {
    bottom: calc(102px + env(safe-area-inset-bottom));
  }

  .portal-3d-hint {
    bottom: calc(78px + env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .portal-3d-shell *,
  .portal-3d-shell *::before,
  .portal-3d-shell *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
