:root {
  color-scheme: light;
  --background: #f5f6f8;
  --surface: #ffffff;
  --ink: #15171a;
  --muted: #626872;
  --accent: #2759d8;
  --accent-hover: #1e47b4;
  --line: #e4e7ec;
  --shadow: 0 18px 50px rgba(26, 34, 50, 0.11);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 50% -20%, rgba(101, 141, 245, 0.16), transparent 42rem),
    var(--background);
  color: var(--ink);
}

button {
  font: inherit;
}

.app {
  width: min(100%, 1040px);
  min-height: 100svh;
  margin: 0 auto;
  padding:
    max(24px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  display: grid;
  align-content: center;
  gap: 18px;
}

.intro {
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 6vw, 3rem);
  line-height: 1.08;
  letter-spacing: -0.04em;
}

.subtitle {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: clamp(0.96rem, 2.8vw, 1.1rem);
}

.viewer-shell {
  position: relative;
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 28px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

model-viewer {
  display: block;
  width: 100%;
  height: min(62svh, 650px);
  min-height: 400px;
  background: linear-gradient(145deg, #ffffff, #eef1f5);
  --poster-color: transparent;
  --progress-bar-color: var(--accent);
  --progress-bar-height: 4px;
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  color: var(--muted);
  background: linear-gradient(145deg, #ffffff, #eef1f5);
}

.loading strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid #dfe4ec;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 1.6s; }
}

#ar-button {
  position: absolute;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 100;
  min-width: 180px;
  min-height: 52px;
  padding: 14px 22px;
  border: 0;
  border-radius: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #111827;
  color: #ffffff;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#ar-button:hover {
  background: #1f2937;
}

#ar-button:active {
  transform: translateX(-50%) scale(0.97);
}

.ar-button-icon {
  font-size: 20px;
}

#ar-button:focus-visible,
.zoom-controls button:focus-visible {
  outline: 3px solid #fff;
  box-shadow: 0 0 0 6px var(--accent);
}

.zoom-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 3;
  display: flex;
  gap: 8px;
}

.zoom-controls button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  box-shadow: 0 5px 18px rgba(26, 34, 50, 0.09);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.ar-prompt {
  width: min(86%, 360px);
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(20, 23, 28, 0.84);
  color: #fff;
  text-align: center;
  font-size: 0.9rem;
}

.error-message {
  position: absolute;
  inset: 0;
  z-index: 4;
  padding: 28px;
  place-content: center;
  justify-items: center;
  gap: 8px;
  background: #fff;
  color: var(--ink);
  text-align: center;
}

.error-message:not([hidden]) {
  display: grid;
}

.error-message span {
  max-width: 34ch;
  color: var(--muted);
}

.guidance {
  text-align: center;
}

.instruction {
  margin: 0;
  font-weight: 650;
}

.fallback {
  max-width: 58ch;
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

#ar-message {
  min-height: 1.4em;
  margin: 8px auto 0;
  color: #8d1c1c;
  font-size: 0.88rem;
  font-weight: 650;
}

.fallback[hidden] {
  display: none;
}

.noscript {
  padding: 12px;
  border-radius: 12px;
  background: #fff1f1;
  color: #8d1c1c;
  text-align: center;
}

@media (max-width: 540px) {
  .app {
    align-content: start;
    gap: 16px;
  }

  .viewer-shell {
    border-radius: 22px;
  }

  model-viewer {
    height: max(72dvh, 600px);
    min-height: 600px;
  }

  .zoom-controls {
    top: 12px;
    right: 12px;
  }

  .zoom-controls button {
    width: 42px;
    height: 42px;
  }
}

@media (max-height: 700px) and (orientation: landscape) {
  .app {
    grid-template-columns: minmax(220px, 0.7fr) minmax(420px, 1.3fr);
    align-items: center;
  }

  .intro,
  .guidance {
    text-align: left;
  }

  .viewer-shell {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  model-viewer {
    height: calc(100svh - 32px);
    min-height: 320px;
  }
}
