/* ============================================================================
   "See it folded" (owner, Oct 24) — js/fold-viewer.js.
   A modal 3D model of the customer's own folded flyer: a dim scrim, the stage
   centred, the controls under it. The model is plain CSS 3D (perspective on the
   stage, preserve-3d down the tree, backface-visibility on the faces); the
   script only sets transforms. Every colour is a studio token (css/app.css
   :root, set per tenant by js/tenant.js) — nothing here is a brand colour.
   ========================================================================== */

.fv {
  position: fixed;
  inset: 0;
  /* over the pages (35) and the print-ready sheet (80); under the tour (90) */
  z-index: 82;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  transition: opacity 180ms var(--ease);
}
.fv[hidden] { display: none; }
.fv.is-in { opacity: 1; }

.fv__scrim {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--ink) 42%, transparent);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.fv__card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(980px, 100%);
  height: min(780px, 100%);
  min-width: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  overscroll-behavior: contain;
  transform: translateY(8px);
  transition: transform var(--dur) var(--ease);
}
.fv.is-in .fv__card { transform: none; }

/* ---------------------------------------------------------------- header */

.fv__head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px 20px;
  border-bottom: 1px solid var(--line-soft);
}
.fv__words { min-width: 0; padding-top: 2px; }
.fv__title {
  font-size: var(--fs-lead);
  font-weight: 700;
  letter-spacing: -0.005em;
  line-height: 1.3;
  color: var(--ink);
}
.fv__sub {
  font-size: var(--fs-small);
  line-height: 1.45;
  color: var(--muted);
  padding-top: 2px;
}
.fv__close {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-70);
  font-size: var(--fs-small);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.fv__close:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

/* ----------------------------------------------------------------- stage */

.fv__stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  /* the workspace the card was designed on, dots and all */
  background-color: var(--workspace, var(--surface));
  background-image: radial-gradient(circle, var(--workspace-dot) 1px, transparent 1.5px);
  background-size: 18px 18px;
  /* a finger on the model turns it; it never scrolls the page behind */
  touch-action: none;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
  /* perspective is set by the script (it follows the stage's size) */
}
.fv__stage.is-dragging { cursor: grabbing; }
.fv__stage:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; border-radius: 0; }

/* the 3D model: world (centre + spin + zoom) > sheet (the flat sheet's origin) > pieces */
.fv__world {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}
.fv__sheet {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}
.fv-piece {
  position: absolute;
  transform-style: preserve-3d;
}
.fv-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--paper);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
/* the slice of the page this panel shows: the page is a CSS background, sized and
   moved by the script, so the face is only ever painted, never read (the proofs
   come from another origin without CORS, and carry bleed this box crops away) */
.fv-face__img {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
}
/* the paper's edge, so a white page on the dotted workspace still has an outline */
.fv-face::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 1px var(--line);
  pointer-events: none;
}
/* the light falling off a panel as it swings: darkest near the crease, never opaque */
.fv-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: var(--fv-shade, 0);
  background: linear-gradient(var(--fv-dir, to right),
    color-mix(in srgb, var(--ink) 30%, transparent),
    color-mix(in srgb, var(--ink) 5%, transparent));
}

/* what you are looking at, over the top of the stage */
.fv__where {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 2;
  max-width: calc(100% - 24px);
  transform: translateX(-50%);
  padding: 6px 14px;
  text-align: center;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-float);
  font-size: var(--fs-small);
  line-height: 1.35;
  color: var(--muted);
  pointer-events: none;
}
.fv__where[hidden] { display: none; }
.fv__where strong { font-weight: 700; color: var(--ink); }
.fv__hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  z-index: 2;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: var(--fs-micro);
  color: var(--muted);
  pointer-events: none;
  transition: opacity 400ms var(--ease);
}
.fv.has-dragged .fv__hint { opacity: 0; }

.fv__msg {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  font-size: var(--fs-small);
  line-height: 1.5;
  color: var(--ink-70);
  background: color-mix(in srgb, var(--workspace, var(--surface)) 72%, transparent);
  pointer-events: none;
}
.fv__msg[hidden] { display: none; }
.fv__msg[data-kind="error"] { color: var(--warn-ink, var(--ink)); pointer-events: auto; }

/* -------------------------------------------------------------- controls */

.fv__bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line-soft);
  background: var(--paper);
}
.fv__btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--paper);
  color: var(--ink-70);
  font-size: var(--fs-small);
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.fv__btn:hover:not(:disabled) { border-color: var(--accent-line); background: var(--accent-soft); color: var(--ink); }
.fv__btn:disabled { opacity: .45; cursor: default; }
.fv__btn--accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.fv__btn--accent:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); opacity: .92; }
.fv__btn:focus-visible,
.fv__close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ----------------------------------------------------------------- phone */

@media (max-width: 640px) {
  .fv { padding: 0; }
  .fv__card {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
  }
  .fv__head { padding: calc(10px + env(safe-area-inset-top)) 10px 10px 16px; }
  .fv__bar { gap: 6px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .fv__btn { flex: 1 1 0; padding: 0 8px; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  .fv, .fv__card, .fv__hint, .fv__btn, .fv__close { transition: none; }
  .fv__card { transform: none; }
}
