/* AR demo: shared styles for index.html and track.html. System fonts, no framework. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #151a26;
  --muted: #586074;
  --line: #d9dee7;
  --accent: #2346c8;
  --accent-dark: #1a379f;
  --warn-bg: #fff5e3;
  --warn-line: #e0a033;
  --warn-ink: #573a00;
  --err-bg: #fdeeee;
  --err-line: #eeb1b1;
  --err-ink: #7a1414;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.5;
}

img {
  max-width: 100%;
}

/* ---------- Page frame (index) ---------- */

.page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 60% at 50% 0%, #e7ebf6 0%, rgba(231, 235, 246, 0) 70%),
    var(--bg);
}

.wrap {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
  padding: max(32px, env(safe-area-inset-top)) 20px 24px;
}

.view {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 20px;
  text-align: center;
}

.lead {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 500;
  line-height: 1.45;
}

.foot {
  flex: 0 0 auto;
  margin: 0;
  padding: 20px 20px max(20px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
}

/* ---------- Buttons and links ---------- */

.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 56px;
  margin: 0;
  padding: 12px 20px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-primary {
  position: relative;
  min-height: 60px;
  background: var(--accent);
  color: #fff;
  font-size: 1.15rem;
  box-shadow: 0 6px 18px rgba(35, 70, 200, 0.28);
}

.btn-primary:hover {
  background: var(--accent-dark);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-primary:disabled {
  background: #9aa6c8;
  box-shadow: none;
  cursor: default;
}

.btn-secondary {
  background: var(--surface);
  color: var(--accent);
  border: 1.5px solid var(--line);
}

.btn-secondary:hover {
  border-color: var(--accent);
}

.btn:focus-visible,
.poster-link:focus-visible,
.back-link:focus-visible,
.ar-file:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* A rel="ar" link whose only child is an image of its label (Safari needs the image child). */
.btn-ar {
  padding-left: 0;
  padding-right: 0;
}

.btn-ar img {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Busy state: the label hides behind a spinner, no extra words. */
.btn.is-busy {
  color: transparent;
  pointer-events: none;
}

.btn.is-busy::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 26px;
  height: 26px;
  margin: auto;
  border: 3px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- iPhone view ---------- */

.poster-link {
  display: block;
  width: min(100%, 320px);
  margin: 4px auto 0;
  border-radius: 28px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 14px 36px rgba(21, 26, 38, 0.16), 0 2px 6px rgba(21, 26, 38, 0.08);
  -webkit-tap-highlight-color: transparent;
}

.poster-link img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
}

/* Poster file missing: the image's alt text ("View in AR") shows on an accent tile. */
.poster-link.is-missing {
  background: var(--accent);
  text-decoration: none;
}

.poster-link.is-missing img {
  aspect-ratio: auto;
  height: 160px;
  color: #fff;
  font-size: 1.3rem;
  font-weight: 600;
  line-height: 160px;
  text-align: center;
}

.notice {
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--warn-line);
  border-left-width: 5px;
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 1rem;
  text-align: left;
}

/* ---------- Android and desktop: model-viewer ---------- */

.model-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

model-viewer {
  display: block;
  width: 100%;
  height: 340px;
  border-radius: 20px;
  background: radial-gradient(80% 80% at 50% 35%, #ffffff 0%, #e6e9f0 100%);
  --poster-color: transparent;
}

/* ---------- Desktop view ---------- */

.view-desktop h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.desk-intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.qr-block {
  margin: 0;
  padding: 18px;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(21, 26, 38, 0.1);
}

.qr-block img {
  display: block;
  width: 240px;
  height: 240px;
  object-fit: contain;
}

body.is-desktop .wrap {
  max-width: 1040px;
}

@media (min-width: 860px) {
  .view-desktop {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
    align-items: center;
    gap: 48px;
  }

  .view-desktop model-viewer {
    height: 520px;
  }
}

/* ---------- Debug block (?debug=1) ---------- */

.debug {
  margin-top: 32px;
  padding: 16px;
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-size: 0.9rem;
  text-align: left;
}

.debug h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.debug h3 {
  margin: 18px 0 8px;
  font-size: 0.95rem;
}

.debug dl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 12px;
  margin: 0;
}

.debug dt {
  color: var(--muted);
}

.debug dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.debug ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ar-file {
  display: block;
  padding: 10px 8px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fafbfc;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
}

.ar-file img {
  display: block;
  max-width: 100%;
  height: auto;
}

.asset-status {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.asset-status.bad {
  color: var(--err-ink);
}

/* ?selftest=1 log (headless checks only) */
.selftest {
  margin: 0;
  padding: 10px;
  background: #10131a;
  color: #b8f5c4;
  font: 12px/1.4 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- track.html ---------- */

body.track {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

.ar-container {
  position: fixed;
  inset: 0;
  z-index: 0; /* own stacking context: MindAR puts its video at z-index -2 inside */
  overflow: hidden;
  background: #000;
}

.start-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background:
    radial-gradient(120% 60% at 50% 0%, #e7ebf6 0%, rgba(231, 235, 246, 0) 70%),
    var(--bg);
}

.start-body {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  width: 100%;
  max-width: 26rem;
  margin: 0 auto;
  padding: calc(76px + env(safe-area-inset-top)) 24px 16px;
  text-align: center;
}

.card-thumb {
  display: block;
  width: min(64vw, 240px);
  height: auto;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(21, 26, 38, 0.16), 0 2px 6px rgba(21, 26, 38, 0.08);
  transform: rotate(-3deg);
}

.error {
  width: 100%;
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--err-line);
  border-left-width: 5px;
  border-radius: 12px;
  background: var(--err-bg);
  color: var(--err-ink);
  font-size: 1rem;
  text-align: left;
}

.back-link {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px 8px 12px;
  border-radius: 999px;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.back-link .chev {
  font-size: 1.4rem;
  line-height: 1;
}

body.is-running .back-link {
  color: #fff;
  background: rgba(10, 12, 18, 0.55);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.hint {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  z-index: 30;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 14px 22px;
  border-radius: 18px;
  background: rgba(10, 12, 18, 0.62);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  transform: translateX(-50%);
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 25;
  margin: auto;
  width: 56px;
  height: 56px;
  border: 4px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

/* ?selftest=1 preview of the rig (headless check of orientation and size) */
.preview {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #20242c;
}

.preview canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.preview .selftest {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 34%;
  overflow: auto;
  opacity: 0.92;
}

@media (prefers-reduced-motion: reduce) {
  .btn.is-busy::after,
  .loading {
    animation-duration: 2.4s;
  }
}
