/* ==========================================================================
   MAGIX WEB-AR — public WebAR experience.
   Brand tokens: Deep Aubergine #3A0F34 · Ice Silver #DDE3E8 · Marigold #EAAA00

   Application-style, mobile-first, full-viewport. No page scrolling, no
   rubber-banding, no double-tap zoom, no accidental text selection: the page
   behaves like a native screen. Safe-area insets are honoured for notches,
   cutouts and home bars.
   ========================================================================== */

:root {
  --ice: #dde3e8;
  --aubergine: #3a0f34;
  --aubergine-lift: #3f1140;
  --aubergine-deep: #2a0a26;
  --aubergine-abyss: #20071f;
  --marigold: #eaaa00;
  --marigold-deep: #c89000;
  --text: #ffffff;
  --body-text: rgba(221, 227, 232, 0.82);
  --muted: rgba(221, 227, 232, 0.6);
  --line: rgba(255, 255, 255, 0.12);
  --good: #2fd39a;
  --danger: #ff8e8e;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  --inset-top: env(safe-area-inset-top, 0px);
  --inset-right: env(safe-area-inset-right, 0px);
  --inset-bottom: env(safe-area-inset-bottom, 0px);
  --inset-left: env(safe-area-inset-left, 0px);

  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Author `display` rules outrank the UA [hidden] rule, so make it explicit. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--aubergine);
  color: var(--text);
  font: 16px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* No page scrolling, pull-to-refresh or rubber-banding behind the app shell. */
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* During the AR session the surface owns the gestures entirely. */
html.is-ar, html.is-ar body { touch-action: none; }

.stage-root {
  position: fixed;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
  height: 100%;
  height: 100dvh; /* dynamic viewport: tracks collapsing mobile browser bars */
  background: var(--aubergine);
}

/* The AR container MindAR fills with the camera video + WebGL canvas. */
#ar-container { position: absolute; inset: 0; overflow: hidden; }
#ar-container video,
#ar-container canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

/* ------------------------------------------------------------ launch splash */
/* Painted by the HTML alone (no JS/CSS dependency) so MAGIX branding appears
   the instant the QR URL opens, before any script has run. */
.splash {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background:
    radial-gradient(70% 45% at 20% 8%, rgba(234, 170, 0, 0.18), transparent 62%),
    radial-gradient(75% 55% at 85% 100%, rgba(32, 7, 31, 0.75), transparent 62%),
    linear-gradient(180deg, var(--aubergine-lift) 0%, var(--aubergine) 55%, var(--aubergine-deep) 100%);
  transition: opacity 0.45s var(--ease);
}
.splash.is-hidden { opacity: 0; pointer-events: none; }
.splash__logo {
  width: 116px;
  height: 116px;
  border-radius: 28px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.4);
  animation: brandIn 0.6s var(--ease) both;
}
.splash__wordmark {
  font-size: 15px;
  font-weight: 750;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--ice);
  animation: brandIn 0.6s var(--ease) 0.08s both;
}
.splash__wordmark span { color: var(--marigold); }
.splash__rule {
  width: 46px;
  height: 3px;
  border-radius: 999px;
  background: var(--marigold);
  opacity: 0.7;
  animation: brandIn 0.6s var(--ease) 0.14s both;
}
/* Self-dismissing variant for pages without a controller (the landing page). */
.splash--auto { animation: splashAuto 1.2s var(--ease) forwards; }

/* ------------------------------------------------------------------ shell */
.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  /* Safe areas: nothing important sits under a notch, cutout or home bar. */
  padding: calc(24px + var(--inset-top)) calc(20px + var(--inset-right))
           calc(24px + var(--inset-bottom)) calc(20px + var(--inset-left));
  background:
    radial-gradient(70% 45% at 20% 8%, rgba(234, 170, 0, 0.16), transparent 62%),
    radial-gradient(75% 55% at 85% 100%, rgba(32, 7, 31, 0.72), transparent 62%),
    linear-gradient(180deg, var(--aubergine-lift) 0%, var(--aubergine) 55%, var(--aubergine-deep) 100%);
  transition: opacity 0.4s var(--ease);
  /* Safety valve for very short viewports only — the page itself never scrolls. */
  overflow-y: auto;
  overscroll-behavior: contain;
}
.screen.is-leaving { opacity: 0; pointer-events: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(221, 227, 232, 0.78);
}
.brand img { width: 30px; height: 30px; border-radius: 8px; }

h1 { font-size: clamp(22px, 6.2vw, 28px); font-weight: 780; margin: 0; letter-spacing: -0.015em; line-height: 1.18; }
h2 { font-size: 18px; font-weight: 700; margin: 0; }
p { margin: 0; color: var(--body-text); max-width: 34ch; }
.muted { color: var(--muted); font-size: 13.5px; }

.card {
  width: min(430px, 100%);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* ---------------------------------------------------------------- buttons */
/* Touch-friendly: comfortably above the 44px minimum target size. */
.btn {
  appearance: none;
  border: 0;
  border-radius: 16px;
  padding: 15px 22px;
  min-height: 54px;
  font: inherit;
  font-weight: 750;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-decoration: none;
  transition: transform 0.16s var(--ease), opacity 0.16s var(--ease), box-shadow 0.2s var(--ease);
  touch-action: manipulation;
}
.btn:active { transform: scale(0.975); }
.btn--accent { background: linear-gradient(180deg, var(--marigold), var(--marigold-deep)); color: var(--aubergine); box-shadow: 0 14px 34px rgba(234, 170, 0, 0.3); }
.btn--ghost { background: rgba(255, 255, 255, 0.12); color: #fff; border: 1px solid var(--line); }
.btn--block { width: 100%; }
.btn svg { width: 20px; height: 20px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.icon-badge { width: 68px; height: 68px; border-radius: 20px; display: grid; place-items: center; background: rgba(234, 170, 0, 0.16); border: 1px solid rgba(234, 170, 0, 0.22); color: var(--marigold); }
.icon-badge svg { width: 32px; height: 32px; }
.icon-badge--danger { background: rgba(201, 59, 59, 0.18); border-color: rgba(255, 142, 142, 0.24); color: var(--danger); }

/* ------------------------------------------------------------------- steps */
.points { display: flex; flex-direction: column; gap: 12px; width: min(430px, 100%); text-align: left; }
.point { display: flex; gap: 12px; align-items: flex-start; font-size: 14.5px; color: var(--body-text); animation: rise 0.5s var(--ease) both; }
.point:nth-child(1) { animation-delay: 0.05s; }
.point:nth-child(2) { animation-delay: 0.12s; }
.point:nth-child(3) { animation-delay: 0.19s; }
.point b { display: grid; place-items: center; flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%; background: var(--marigold); color: var(--aubergine); font-size: 12.5px; }

/* ------------------------------------------------- pre-camera entry screen */
/* The visitor's first real screen on a gallery QR link: brand mark, one line of
   reassurance, and the button whose tap is the user gesture that lets us go
   fullscreen and start the camera together. */
.screen__logo {
  width: 104px;
  height: 104px;
  border-radius: 26px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.4);
  animation: brandIn 0.6s var(--ease) both;
}
.screen__lead {
  max-width: 30ch;
  font-size: 16px;
  color: var(--body-text);
  animation: brandIn 0.6s var(--ease) 0.08s both;
}
[data-screen="start"] .btn {
  width: min(340px, 100%);
  animation: brandIn 0.6s var(--ease) 0.16s both;
}

/* -------------------------------------------------------------------- hint */
.hint {
  position: absolute;
  left: 50%;
  bottom: calc(20px + var(--inset-bottom));
  transform: translateX(-50%);
  z-index: 14;
  background: rgba(32, 7, 31, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: min(92vw, 520px);
  text-align: center;
  pointer-events: none;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--marigold); animation: pulse 1.5s infinite ease-in-out; flex: 0 0 auto; }
.hint.is-tracking .dot { background: var(--good); animation: none; }
.hint.is-error .dot { background: var(--danger); animation: none; }

/* ---------------------------------------------------------------- scanning */
/* Shown while the camera is running but the printed target is not yet in view. */
.reticle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(62vw, 280px);
  aspect-ratio: 1 / 1;
  z-index: 5; /* above the camera, below any shell screen */
  pointer-events: none;
  animation: fadeIn 0.5s var(--ease) both;
}
.reticle__corner { position: absolute; width: 46px; height: 46px; border: 3px solid var(--marigold); }
.reticle__corner--tl { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 14px; }
.reticle__corner--tr { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 14px; }
.reticle__corner--bl { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 14px; }
.reticle__corner--br { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 14px; }
.reticle__line {
  position: absolute;
  left: 8%;
  right: 8%;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--marigold), transparent);
  animation: scan 2.6s ease-in-out infinite;
}
.reticle__dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--marigold);
  animation: pulse 1.6s infinite ease-in-out;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--inset-top)) calc(16px + var(--inset-right)) 12px calc(16px + var(--inset-left));
  background: linear-gradient(180deg, rgba(32, 7, 31, 0.72), transparent);
  pointer-events: none;
}
.topbar strong { font-size: 14.5px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .brand { margin-right: auto; }

/* Trailing controls: the optional install pill, then the exit button. */
.topbar__actions {
  pointer-events: auto;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

/* "Install" pill — only rendered when a native install prompt is available. */
.topbar__install {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(234, 170, 0, 0.5);
  background: rgba(32, 7, 31, 0.55);
  color: var(--ice);
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  touch-action: manipulation;
}
.topbar__install svg { width: 17px; height: 17px; }
.topbar__install:active { transform: scale(0.95); }

/* Minimal in-app exit: the touch-friendly equivalent of a back affordance. */
.topbar__exit {
  pointer-events: auto;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(32, 7, 31, 0.55);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  touch-action: manipulation;
}
.topbar__exit svg { width: 20px; height: 20px; }
.topbar__exit:active { transform: scale(0.94); }

/* -------------------------------------------------- fullscreen affordance */
/* Subtle MAGIX-branded pill, offered only when the automatic start could not
   enter fullscreen (no user gesture). Anchored top-left so it never sits over
   the reticle's centre or the interactive media regions on the printed target. */
.fs-tip {
  position: absolute;
  top: calc(58px + var(--inset-top));
  left: calc(16px + var(--inset-left));
  z-index: 16; /* above the topbar gradient, whose controls stay tappable */
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(234, 170, 0, 0.5);
  background: rgba(32, 7, 31, 0.62);
  color: var(--ice);
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.32);
  touch-action: manipulation;
  /* fadeIn only animates opacity, so :active transform below still applies. */
  animation: fadeIn 0.4s var(--ease) both, fsTipPulse 3s ease-in-out 1.4s infinite;
}
.fs-tip__mark { width: 18px; height: 18px; border-radius: 5px; flex: 0 0 auto; }
.fs-tip:active { transform: scale(0.96); }

@keyframes fsTipPulse {
  0%, 100% { box-shadow: 0 10px 26px rgba(0, 0, 0, 0.32), 0 0 0 0 rgba(234, 170, 0, 0); }
  50% { box-shadow: 0 10px 26px rgba(0, 0, 0, 0.32), 0 0 0 6px rgba(234, 170, 0, 0.12); }
}

/* ---------------------------------------------------------------- spinner */
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.18); border-top-color: var(--marigold); animation: spin 0.9s linear infinite; }
.progress-bar { width: min(320px, 80vw); height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); overflow: hidden; }
.progress-bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--marigold-deep), var(--marigold)); transition: width 0.25s var(--ease); }

/* -------------------------------------------------------------- animations */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.45; transform: scale(0.82); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes brandIn { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes splashAuto { 0%, 55% { opacity: 1; visibility: visible; } 100% { opacity: 0; visibility: hidden; } }
@keyframes scan { 0%, 100% { top: 12%; } 50% { top: 88%; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .reticle__line { top: 50%; }
}

/* Landscape / short viewports: tighten spacing so nothing is clipped. */
@media (max-height: 560px) {
  .screen { gap: 12px; padding-top: calc(14px + var(--inset-top)); padding-bottom: calc(14px + var(--inset-bottom)); }
  .icon-badge { width: 52px; height: 52px; border-radius: 16px; }
  .icon-badge svg { width: 26px; height: 26px; }
  h1 { font-size: 20px; }
  .point { font-size: 13.5px; }
  .splash__logo { width: 84px; height: 84px; border-radius: 22px; }
}

@media (min-width: 720px) {
  .card { padding: 28px; }
}
