:root {
  color-scheme: light;
  --paper: #eee9e1;
  --paper-soft: #faf7f1;
  --ink: #161d1f;
  --muted: #616865;
  --line: rgba(22, 29, 31, 0.14);
  --control: rgba(255, 255, 255, 0.82);
  --control-hover: rgba(255, 255, 255, 0.98);
}

* {
  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;
  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: 12ch;
  color: var(--ink);
  font-size: clamp(1.6rem, 3.4vw, 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(24px, 5vh, 52px) clamp(22px, 4vw, 58px) clamp(94px, 11vh, 118px);
}

.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(62vh, 45vw, 430px);
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: none;
  transform: translate3d(0, 0, 0) scale(var(--zoom, 1));
  transition: opacity 140ms ease, transform 140ms ease;
  will-change: transform, opacity;
}

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

.status-stack {
  position: absolute;
  left: 50%;
  bottom: 4px;
  z-index: 3;
  display: grid;
  grid-auto-flow: column;
  gap: 6px;
  transform: translateX(-50%);
  white-space: nowrap;
}

.color-chip,
.angle-chip {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 730;
  letter-spacing: 0.02em;
  backdrop-filter: blur(12px);
}

.color-chip {
  color: var(--ink);
}

.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(22, 29, 31, 0.42);
}

.color-picker {
  position: fixed;
  left: 50%;
  bottom: clamp(15px, 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(238, 233, 225, 0.78);
  backdrop-filter: blur(14px);
  transform: translateX(-50%);
}

.swatch-button {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(22, 29, 31, 0.22);
  border-radius: 999px;
  background: var(--swatch);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.46);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.swatch-button:hover,
.swatch-button[aria-pressed="true"] {
  border-color: rgba(22, 29, 31, 0.52);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.7), 0 0 0 2px rgba(22, 29, 31, 0.12);
  transform: translateY(-1px);
}

.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(238, 233, 225, 0.78);
  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(22, 29, 31, 0.28);
  background: var(--control-hover);
  transform: translateY(-1px);
}

.icon-button:focus-visible,
.detail-button:focus-visible,
.swatch-button:focus-visible {
  outline: 2px solid #6e8179;
  outline-offset: 2px;
}

body.capture-mode .product-mark,
body.capture-mode .toolbar,
body.capture-mode .details,
body.capture-mode .color-picker,
body.capture-mode .status-stack {
  display: none;
}

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

body.compact-mode .product-mark,
body.compact-mode .details,
body.compact-mode .status-stack {
  display: none;
}

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

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

body.compact-mode .product-frame {
  width: min(56vh, 88vw, 390px);
}

body.compact-mode .color-picker {
  left: 12px;
  bottom: 72px;
  transform: none;
}

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

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

body.compact-mode .swatch-button {
  width: 30px;
  height: 30px;
}

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

body.capture-mode .product-frame {
  width: min(68vh, 54vw, 430px);
}

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

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

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

  .details {
    position: fixed;
    right: 10px;
    bottom: 84px;
    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;
  }

  .color-picker {
    left: 12px;
    bottom: 12px;
    transform: none;
  }
}

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

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

  .viewer {
    padding-top: 24px;
    padding-bottom: 104px;
  }

  .stage {
    height: min(66vh, 640px);
    min-height: 392px;
  }

  .status-stack {
    bottom: -3px;
    grid-auto-flow: row;
    justify-items: center;
    gap: 4px;
  }

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

  .color-picker {
    bottom: 70px;
  }

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

  .swatch-button {
    width: 30px;
    height: 30px;
  }

  .details {
    display: none;
  }
}
