/* treibervisuals — 3D-Karussell auf /work
   Wird nur auf /work geladen, alle Regeln hängen an .g3d bzw. .g3d-view (Großansicht).
   Ohne JavaScript oder ohne 3D: normale Galerie in Spalten. Mit .is-3d (gallery.js): Ring. */

.g3d {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding: calc(var(--header-h) + clamp(28px, 6svh, 72px)) var(--pad) clamp(20px, 3.4svh, 36px);
}

/* ---------- Seite festhalten: Scrollen dreht den Ring (nur mit 3D, von gallery.js gesetzt) ---------- */

html.g3d-lock, html.g3d-lock body { height: 100%; overflow: hidden; overscroll-behavior: none; }
.g3d--work.is-3d { height: 100vh; height: 100svh; min-height: 0; overflow: hidden; padding-top: calc(var(--header-h) + clamp(8px, 2svh, 24px)); }
.g3d--work.is-3d .g3d__stage { touch-action: none; }

/* ---------- Galerie-Auswahl ---------- */

.g3d__picks {
  position: relative;
  z-index: 3;
  margin: 0 calc(var(--pad) * -1) clamp(18px, 3svh, 36px);
  padding: 0 var(--pad);
  overflow-x: auto;
  scrollbar-width: none;
  touch-action: pan-x;
}
.g3d__picks::-webkit-scrollbar { display: none; }
.g3d__picks ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px clamp(14px, 1.8vw, 28px); }
.g3d__pick-link {
  display: inline-block;
  padding: 8px 0;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  color: var(--muted);
  text-decoration: none;
  background-image: linear-gradient(currentColor, currentColor);
  background-size: 0% 1.5px;
  background-repeat: no-repeat;
  background-position: 0 calc(100% - 4px);
  transition: color 0.3s var(--ease), background-size 0.45s var(--ease);
}
.g3d__pick-link:hover, .g3d__pick-link[aria-current] { color: var(--ink); }
.g3d__pick-link[aria-current] { background-size: 100% 1.5px; }
.g3d__pick-link sup { font-size: 0.62em; margin-left: 0.2em; font-weight: 500; vertical-align: 0.7em; }
.g3d__noscript { margin-top: 24px; }

/* ---------- Kopf: Weg zurück, Titel, Eckdaten ---------- */

.g3d__head {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: clamp(16px, 2vw, 32px);
  row-gap: 14px;
}
.g3d__crumb { flex: 1 0 100%; color: var(--muted); }
.g3d__crumb a { color: var(--ink); }
.g3d__title {
  font-size: clamp(34px, 3.6vw, 60px);
  line-height: 0.9;
  letter-spacing: -0.055em;
  margin-left: -0.03em;
}
.g3d__facts { color: var(--muted); }

/* ---------- Ersatz: normale Galerie (ohne JS, ohne 3D, bei einem Fehler) ---------- */

.g3d__stage { position: relative; z-index: 2; margin-top: clamp(40px, 6vw, 88px); }
.g3d__ring {
  list-style: none;
  margin: 0;
  padding: 0;
  columns: 3 260px;
  column-gap: var(--gap);
}
.g3d__item { break-inside: avoid; margin: 0 0 var(--gap); }
.g3d__card { position: relative; display: block; cursor: zoom-in; }
.g3d__card img { display: block; width: 100%; height: auto; background: var(--placeholder); }
/* Fokusrahmen innen, auf hellen und dunklen Bildern sichtbar */
.g3d__card:focus-visible { outline: none; }
/* Video-Karte: Standbild mit Abspielzeichen */
.g3d__play {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22%;
  max-width: 56px;
  min-width: 28px;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.92);
  background: rgba(0, 0, 0, 0.42);
  pointer-events: none;
}
.g3d__play::after {
  content: "";
  position: absolute;
  inset: 30% 26% 30% 38%;
  background: #fff;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}
.g3d__card:focus-visible::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 3px solid #fff;
  box-shadow: inset 0 0 0 4.5px #000;
}

.g3d__controls[hidden] { display: none; }
.g3d__item.is-lifted { visibility: hidden; }

/* ---------- 3D-Ring ---------- */

.g3d.is-3d .g3d__stage {
  transition: opacity 0.26s var(--ease);
  flex: 1 1 auto;
  min-height: 300px;
  margin: clamp(8px, 2svh, 24px) calc(var(--pad) * -1) 0;
  overflow: hidden;
  perspective: var(--g3d-persp, 1800px);
  perspective-origin: 50% 38%;
  /* senkrechtes Wischen scrollt weiter die Seite, waagrechtes dreht den Ring */
  touch-action: pan-y;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.g3d.is-dragging .g3d__stage, .g3d.is-dragging .g3d__card { cursor: grabbing; }
.g3d.is-switching .g3d__stage { opacity: 0; }

.g3d.is-3d .g3d__ring {
  columns: auto;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  transform: rotateX(var(--g3d-tilt, -20deg));
}
.g3d.is-3d .g3d__item {
  /* Breite × Höhe = s², Seitenverhältnis bleibt erhalten (--rt = Wurzel aus dem Seitenverhältnis) */
  --w: calc(var(--g3d-s, 140px) * var(--rt));
  --h: calc(var(--g3d-s, 140px) / var(--rt));
  position: absolute;
  left: 0;
  top: 0;
  width: var(--w);
  height: var(--h);
  margin: calc(var(--h) * -0.5) 0 0 calc(var(--w) * -0.5);
  transform-style: preserve-3d;
  backface-visibility: visible;
}
.g3d.is-3d .g3d__card {
  width: 100%;
  height: 100%;
  -webkit-user-drag: none;
  transition: transform 0.5s var(--ease);
}
/* Karte hat exakt das Seitenverhältnis des Bildes: nichts wird beschnitten oder verzerrt */
.g3d.is-3d .g3d__card img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; -webkit-user-drag: none; }

/* Aktuelles Bild: hebt sich leicht an, feine Linie darunter */
.g3d.is-3d .g3d__item.is-active .g3d__card { transform: translateY(-16%); }
.g3d.is-3d .g3d__item.is-active .g3d__card::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -10px;
  height: 3px;
  background: var(--ink);
}
.g3d.is-3d .g3d__card:focus-visible::after { border-width: 2px; box-shadow: inset 0 0 0 3.5px #000; }

/* ---------- Bedienung ---------- */

.g3d__controls {
  position: relative;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 4px;
  padding-top: 12px;
}
.g3d__btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
  border: 1px solid var(--line);
  border-radius: 50%;
  transition: border-color 0.3s, background-color 0.3s;
}
.g3d__btn:hover { border-color: var(--ink); }
.g3d__count { min-width: 5.2em; text-align: center; }
.g3d__count span { color: var(--ink); }
.g3d__open {
  margin-left: 14px;
  min-height: 44px;
  padding: 0 4px;
  background-image: linear-gradient(currentColor, currentColor);
  background-size: 0% 1.5px;
  background-repeat: no-repeat;
  background-position: 0 calc(50% + 0.85em);
  transition: background-size 0.45s var(--ease);
}
.g3d__open:hover { background-size: 100% 1.5px; }
.g3d__hint { margin-left: 18px; color: var(--muted); }
.g3d__hint-touch { display: none; }
@media (hover: none), (pointer: coarse) {
  .g3d__hint-fine { display: none; }
  .g3d__hint-touch { display: inline; }
}

/* ---------- Impressum / Datenschutz (Seite hat keine Fußzeile) ---------- */

.g3d__legal { position: relative; z-index: 3; align-self: flex-start; display: flex; gap: 18px; margin-top: 10px; color: var(--muted); }
.g3d__legal a { color: inherit; text-decoration: none; }
.g3d__legal a:hover, .g3d__legal a:focus-visible { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
@media (max-width: 699px) { .g3d__legal { align-self: center; margin-top: 6px; } }

/* ---------- Vorschau unten rechts (nur Desktop mit Maus oder Tastatur) ---------- */

.g3d__preview {
  position: fixed;
  right: var(--pad);
  bottom: clamp(20px, 3.4svh, 36px);
  z-index: 4;
  margin: 0;
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s var(--ease), transform 0.4s var(--ease);
}
.g3d__preview.is-on { opacity: 1; transform: none; }
.g3d__preview img { display: block; width: 100%; height: auto; background: var(--placeholder); }
.g3d__preview figcaption { display: flex; justify-content: space-between; gap: 16px; margin-top: 8px; }
.g3d__preview figcaption span:last-child { color: var(--muted); }

/* ---------- Kleine Bildschirme ---------- */

@media (max-width: 699px) {
  .g3d { padding-top: calc(var(--header-h) + 24px); }
  .g3d--work.is-3d { padding-top: calc(var(--header-h) + 4px); }
  .g3d__picks { margin-bottom: 14px; }
  .g3d__picks ul { flex-wrap: nowrap; }
  .g3d__title { font-size: 30px; }
  .g3d.is-3d .g3d__stage { min-height: 260px; }
  .g3d__controls { justify-content: center; padding-top: 8px; }
  .g3d__open { margin-left: 8px; }
  .g3d__hint { flex: 1 0 100%; margin: 4px 0 0; text-align: center; }
}
@media (max-width: 899px), (hover: none) {
  .g3d__preview { display: none; }
}

/* ---------- Großansicht: Bild aus dem Ring gehoben, Rest dunkel und unscharf ---------- */

.g3d-view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #ececea;
  overflow: hidden;
}
.g3d-view::backdrop { background: transparent; }
.g3d-view__veil {
  position: absolute;
  inset: 0;
  background: rgba(8, 8, 8, 0.62);
  -webkit-backdrop-filter: blur(16px) saturate(0.85);
  backdrop-filter: blur(16px) saturate(0.85);
  opacity: 0;
  transition: opacity 0.45s var(--ease);
}
.g3d-view.is-open .g3d-view__veil { opacity: 1; }

.g3d-view__hit, .g3d-view__video {
  position: fixed;
  z-index: 1;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  transform-origin: 0 0;
  transition: left 0.6s var(--ease), top 0.6s var(--ease), width 0.6s var(--ease), height 0.6s var(--ease), opacity 0.18s;
}
.g3d-view__hit { cursor: zoom-in; box-shadow: 0 28px 80px rgba(0, 0, 0, 0.5); }
.g3d-view.is-details .g3d-view__hit { cursor: zoom-out; }
.g3d-view__hit:focus-visible { outline: 2px solid #fff; outline-offset: 4px; }
.g3d-view__img { display: block; width: 100%; height: 100%; object-fit: cover; background: #1a1a1a; }
.g3d-view__video { background: #000; object-fit: contain; }
.g3d-view.has-video .g3d-view__hit { visibility: hidden; }
.g3d-view.is-swapping .g3d-view__hit { opacity: 0; }
.g3d-view.no-trans .g3d-view__hit, .g3d-view.no-trans .g3d-view__video, .g3d-view.no-trans .g3d-view__info { transition: none !important; }

/* Details: neben dem Bild (Desktop) bzw. darunter (Handy) */
.g3d-view__info {
  position: fixed;
  z-index: 2;
  right: var(--pad);
  top: 50%;
  width: min(34vw, 440px);
  max-height: calc(100% - 180px);
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transform: translate(32px, -50%);
  transition: opacity 0.4s var(--ease), transform 0.6s var(--ease), visibility 0s linear 0.6s;
}
.g3d-view.is-details .g3d-view__info {
  opacity: 1;
  visibility: visible;
  transform: translate(0, -50%);
  transition: opacity 0.45s var(--ease) 0.12s, transform 0.6s var(--ease) 0.12s, visibility 0s;
}
.g3d-view__num { color: rgba(236, 236, 234, 0.62); }
.g3d-view__title { margin-top: 10px; font-size: clamp(28px, 2.6vw, 44px); line-height: 0.95; letter-spacing: -0.05em; }
.g3d-view__alt { margin-top: 16px; font-size: 16px; line-height: 1.42; color: rgba(236, 236, 234, 0.82); }
.g3d-view__facts { margin: 24px 0 0; display: grid; gap: 6px; font-size: 15px; font-weight: 700; }
.g3d-view__facts div { display: grid; grid-template-columns: 8.5em minmax(0, 1fr); gap: 12px; padding-top: 6px; border-top: 1px solid rgba(236, 236, 234, 0.16); }
.g3d-view__facts dt { color: rgba(236, 236, 234, 0.62); }
.g3d-view__facts dd { margin: 0; }

.g3d-view__close {
  position: fixed;
  z-index: 3;
  top: 0;
  right: var(--pad);
  height: var(--header-h);
  padding: 0 4px;
  font-size: 15px;
  font-weight: 700;
  color: inherit;
}
.g3d-view__bar {
  position: fixed;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: 18px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}
.g3d-view__close, .g3d-view__bar { opacity: 0; transition: opacity 0.35s var(--ease); }
.g3d-view.is-open .g3d-view__close, .g3d-view.is-open .g3d-view__bar { opacity: 1; transition-delay: 0.25s; }
.g3d-view .g3d__btn { color: inherit; border-color: rgba(236, 236, 234, 0.32); }
.g3d-view .g3d__btn:hover { border-color: #ececea; }
.g3d-view__more {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid rgba(236, 236, 234, 0.32);
  border-radius: 999px;
  color: inherit;
  font-weight: 700;
  transition: background-color 0.3s, color 0.3s;
}
.g3d-view__more:hover, .g3d-view__more[aria-expanded="true"] { background: #ececea; color: #111; }

@media (max-width: 899px) {
  .g3d-view__info {
    left: var(--pad);
    right: var(--pad);
    top: auto;
    bottom: 76px;
    width: auto;
    max-height: calc(58% - 96px);
    transform: translateY(24px);
  }
  .g3d-view.is-details .g3d-view__info { transform: none; }
  .g3d-view__title { font-size: 26px; }
  .g3d-view__alt { font-size: 15px; margin-top: 10px; }
  .g3d-view__facts { margin-top: 16px; font-size: 14px; }
  .g3d-view__facts div { grid-template-columns: 7.5em minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .g3d.is-3d .g3d__card, .g3d__preview, .g3d__open, .g3d__btn, .g3d.is-3d .g3d__stage,
  .g3d-view__veil, .g3d-view__hit, .g3d-view__video, .g3d-view__info, .g3d-view__close, .g3d-view__bar { transition: none; }
}
