:root {
  color-scheme: light;
  --paper: #f3f0e9;
  --paper-soft: #faf8f2;
  --ink: #172128;
  --muted: #53666e;
  --line: rgba(23, 33, 40, 0.14);
  --control: rgba(255, 255, 255, 0.78);
  --control-hover: rgba(255, 255, 255, 0.96);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.viewer-shell {
  position: relative;
  display: grid;
  grid-template-rows: 1fr;
  width: 100%;
  height: 100%;
  min-width: 320px;
  isolation: isolate;
}

.product-mark {
  position: fixed;
  top: clamp(18px, 3.4vw, 38px);
  left: clamp(18px, 3.4vw, 48px);
  z-index: 4;
  max-width: min(430px, calc(100vw - 36px));
  pointer-events: none;
}

.product-mark p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 780;
  letter-spacing: 0.18em;
}

.product-mark h1 {
  margin: 0;
  max-width: 14ch;
  color: var(--ink);
  font-size: clamp(1.62rem, 3.5vw, 3rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.viewer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(164px, 17vw, 230px);
  gap: clamp(14px, 2.2vw, 30px);
  align-items: center;
  width: 100%;
  height: 100%;
  padding: clamp(90px, 12vh, 132px) clamp(22px, 4vw, 58px) clamp(86px, 10vh, 110px);
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  width: min(68vw, 820px);
  height: min(72vh, 760px);
  min-height: 360px;
  margin-inline: auto;
  touch-action: none;
  cursor: grab;
  user-select: none;
}

.stage:active {
  cursor: grabbing;
}

.product-frame {
  position: relative;
  z-index: 2;
  display: block;
  width: min(70vh, 60vw, 700px);
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 30px 34px rgba(36, 48, 54, 0.14));
  transform: translate3d(var(--pan-x, 0px), var(--pan-y, 0px), 0) scale(var(--zoom, 1));
  transition: opacity 120ms ease;
  will-change: transform, opacity;
}

.product-frame.is-swapping {
  opacity: 0.72;
}

.shadow {
  position: absolute;
  left: 50%;
  bottom: 10%;
  z-index: 1;
  width: min(50vh, 46vw, 520px);
  height: min(6vh, 52px);
  border-radius: 999px;
  background: radial-gradient(ellipse at center, rgba(38, 46, 48, 0.18), rgba(38, 46, 48, 0) 70%);
  transform: translateX(-50%) scaleX(var(--shadow-scale, 1));
  filter: blur(3px);
  pointer-events: none;
}

.angle-chip {
  position: absolute;
  left: 50%;
  bottom: 4px;
  z-index: 3;
  transform: translateX(-50%);
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 730;
  letter-spacing: 0.02em;
  backdrop-filter: blur(12px);
  white-space: nowrap;
}

.details {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-rows: minmax(120px, 190px) minmax(0, 1fr);
  gap: 10px;
  max-height: min(70vh, 680px);
  min-height: 0;
}

.detail-preview {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
}

.detail-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.detail-button {
  position: relative;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  cursor: pointer;
  aspect-ratio: 1;
}

.detail-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 160ms ease;
}

.detail-button:hover img,
.detail-button[aria-pressed="true"] img {
  transform: scale(1.045);
}

.detail-button[aria-pressed="true"] {
  border-color: rgba(23, 33, 40, 0.42);
}

.toolbar {
  position: fixed;
  right: clamp(14px, 3vw, 34px);
  bottom: clamp(14px, 3vw, 34px);
  z-index: 5;
  display: grid;
  grid-auto-flow: column;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(243, 240, 233, 0.72);
  backdrop-filter: blur(14px);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control);
  color: var(--ink);
  font: 780 1.08rem/1 ui-sans-serif, system-ui, sans-serif;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease, border-color 160ms ease;
}

.icon-button:hover {
  border-color: rgba(23, 33, 40, 0.28);
  background: var(--control-hover);
  transform: translateY(-1px);
}

.icon-button:focus-visible,
.detail-button:focus-visible {
  outline: 2px solid #5d8794;
  outline-offset: 2px;
}

body.capture-mode .product-mark,
body.capture-mode .toolbar,
body.capture-mode .details,
body.capture-mode .angle-chip {
  display: none;
}

body.capture-mode .viewer {
  display: grid;
  grid-template-columns: 1fr;
  padding: 0;
}

body.capture-mode .stage {
  width: 100vw;
  height: 100vh;
  min-height: 0;
}

body.capture-mode .product-frame {
  width: min(78vh, 58vw, 560px);
}

body.capture-mode .shadow {
  bottom: 12%;
  opacity: 0.82;
}

body.compact-mode .product-mark,
body.compact-mode .details,
body.compact-mode .angle-chip {
  display: none;
}

body.compact-mode .viewer {
  grid-template-columns: 1fr;
  padding: 18px 12px 96px;
}

body.compact-mode .stage {
  width: 100%;
  height: calc(100vh - 116px);
  min-height: 340px;
}

body.compact-mode .product-frame {
  width: min(58vh, 86vw, 390px);
  filter: drop-shadow(0 20px 24px rgba(36, 48, 54, 0.12));
}

body.compact-mode .shadow {
  bottom: 7%;
  width: min(36vh, 54vw, 280px);
  height: min(4.5vh, 32px);
  opacity: 0.5;
  filter: blur(2px);
}

body.compact-mode .toolbar {
  right: 10px;
  bottom: 10px;
  gap: 6px;
  padding: 6px;
}

body.compact-mode .icon-button {
  width: 38px;
  height: 38px;
}

@media (max-width: 920px) {
  .viewer {
    grid-template-columns: 1fr;
    align-items: end;
    padding: 128px 12px 94px;
  }

  .stage {
    width: 100%;
    height: min(64vh, 700px);
    min-height: 380px;
  }

  .product-frame {
    width: min(76vh, 94vw, 620px);
  }

  .details {
    position: fixed;
    right: 10px;
    bottom: 74px;
    grid-template-rows: 86px;
    grid-template-columns: 86px minmax(0, 220px);
    max-width: calc(100vw - 20px);
    max-height: 96px;
  }

  .detail-grid {
    grid-auto-flow: column;
    grid-auto-columns: 58px;
    grid-template-columns: none;
    overflow-x: auto;
    overflow-y: hidden;
  }
}

@media (max-width: 560px) {
  .product-mark {
    top: 18px;
    left: 18px;
  }

  .product-mark h1 {
    max-width: 12ch;
    font-size: clamp(1.45rem, 9vw, 2.22rem);
  }

  .viewer {
    padding-top: 132px;
  }

  .stage {
    height: min(68vh, 650px);
    min-height: 430px;
  }

  .toolbar {
    right: 10px;
    bottom: 10px;
    gap: 6px;
    padding: 6px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .details {
    display: none;
  }
}
