/* ==========================================================================
   AGRIYANA — 3D machinery viewer

   The canvas sits inside the existing `.pdp-frame`, so the product page
   layout is untouched whether a model exists or not. See req/js/viewer.js for
   why this exists at all and how its weight is paid for.

   Loads after raitha.css, before mobile.css.
   ========================================================================== */

/* The frame becomes the stage. `.pdp-frame` already supplies the aspect
   ratio, radius and border, so this only adds what 3D needs. */
.pdp-frame.has-3d { position: relative; isolation: isolate; }

.pdp-frame.has-3d canvas,
.pdp-frame.has-3d iframe {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  z-index: 1;
  cursor: grab;
  touch-action: none;
  opacity: 0;
  transition: opacity var(--dur-3) var(--ease-out);
  border: none;
  display: block;
}
.pdp-frame.has-3d.is-viewer-ready canvas,
.pdp-frame.has-3d.is-viewer-ready iframe { opacity: 1; }
.pdp-frame.has-3d.is-dragging canvas,
.pdp-frame.has-3d.is-dragging iframe { cursor: grabbing; }

/* a very soft studio floor, so the machine is standing in a space rather
   than floating on the card */
.pdp-frame.has-3d::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(62% 48% at 50% 34%, color-mix(in srgb, var(--brand) 7%, transparent), transparent 72%),
    linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 78%, var(--bg-3) 100%);
}
[data-theme='dark'] .pdp-frame.has-3d::after {
  background:
    radial-gradient(62% 48% at 50% 34%, color-mix(in srgb, var(--brand) 12%, transparent), transparent 72%),
    linear-gradient(180deg, var(--surface) 0%, var(--surface-sunk) 82%, #04100A 100%);
}

/* the photograph stays in the DOM underneath and is simply hidden, so the
   toggle costs nothing to flip back and nothing is destroyed */
.pdp-frame.has-3d.is-3d > img,
.pdp-frame.has-3d.is-3d > .specimen { visibility: hidden; }

/* PHOTO MODE MUST FULLY HIDE THE CANVAS.

   Reported with a screenshot: the flyer was showing with the 3D model drawn
   straight over it and its shadow on top of the artwork.

   `!important` on all three properties because three.js writes `display`,
   `width` and `height` as INLINE styles on its own canvas — WebGLRenderer
   sets them in the constructor and again on every setSize — and an inline
   style beats any selector. `visibility` and `opacity` are belt and braces:
   a canvas that is merely transparent still sits over the photograph and
   still swallows the pointer, so the flyer could not be dragged or clicked. */
.pdp-frame.has-3d:not(.is-3d) canvas,
.pdp-frame.has-3d:not(.is-3d) iframe {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
/* the studio floor belongs to the 3D view only */
.pdp-frame.has-3d:not(.is-3d)::after { display: none !important; }
/* and so do its controls */
.pdp-frame.has-3d:not(.is-3d) .v3-hint,
.pdp-frame.has-3d:not(.is-3d) .v3-reset { display: none !important; }

/* ==================================================================== hint */

/* Shown until the first drag. A 3D viewer nobody realises is draggable is a
   still image with extra download. */
.v3-hint {
  position: absolute;
  left: 50%;
  bottom: var(--s-5);
  transform: translateX(-50%);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 8px var(--s-4);
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-mono);
  font-size: var(--t-2xs);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--fg-muted);
  white-space: nowrap;
  pointer-events: none;
  transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
}
.v3-hint .ico { width: 15px; height: 15px; color: var(--brand); }
.pdp-frame.has-3d.is-touched .v3-hint { opacity: 0; transform: translateX(-50%) translateY(6px); }

/* a small drift on the hint icon, in the direction the gesture goes */
@keyframes v3-swing {
  0%, 100% { transform: translateX(-3px); }
  50%      { transform: translateX(3px); }
}
.v3-hint .ico { animation: v3-swing 2.6s var(--ease-in-out) infinite; }
@media (prefers-reduced-motion: reduce) { .v3-hint .ico { animation: none; } }

/* ==================================================================== toggle */

.v3-switch {
  position: absolute;
  top: var(--s-4);
  right: var(--s-4);
  z-index: 3;
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
}
.v3-tab {
  appearance: none;
  border: 0;
  background: transparent;
  border-radius: var(--r-pill);
  min-height: 32px;
  padding: 0 var(--s-4);
  font-family: var(--font-mono);
  font-size: var(--t-2xs);
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
}
.v3-tab:hover { color: var(--fg); }
.v3-tab[aria-pressed='true'] { background: var(--fg); color: var(--bg); }
@media (pointer: coarse) { .v3-tab { min-height: 40px; padding-inline: var(--s-5); } }

/* reset view, only useful once the model has been turned */
.v3-reset {
  position: absolute;
  bottom: var(--s-4);
  right: var(--s-4);
  z-index: 3;
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--fg-muted);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-2) var(--ease-out), color var(--dur-1) var(--ease-out);
}
.pdp-frame.has-3d.is-touched .v3-reset { opacity: 1; pointer-events: auto; }
.v3-reset:hover { color: var(--brand-ink); }
@media (pointer: coarse) { .v3-reset { width: 44px; height: 44px; } }

/* ==================================================================== caption

   NOT decoration. These are dimensional models built from the specification
   sheet, not photographs or scans of the exact unit, and the page has to say
   so — decision 4 bans letting a visitor infer a fact that is not established.
   ========================================================================== */
.v3-note {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  margin-top: var(--s-3);
  font-family: var(--font-mono);
  font-size: var(--t-2xs);
  line-height: 1.5;
  letter-spacing: .03em;
  color: var(--fg-faint);
}
.v3-note .ico { width: 14px; height: 14px; flex: none; margin-top: 1px; color: var(--accent-ink); }

@media (max-width: 560px) {
  .v3-switch { top: var(--s-3); right: var(--s-3); }
  .v3-hint { font-size: 9px; padding: 7px var(--s-3); bottom: var(--s-4); }
}
