:root {
  color-scheme: light;
  --ink: #161616;
  --muted: #63615d;
  --line: #ddd8cf;
  --panel: #ffffff;
  --surface: #f7f4ee;
  --accent: #0f766e;
  --accent-strong: #0b5d57;
  --gold: #c1912c;
  --danger: #a63838;
  --shadow: 0 16px 45px rgba(22, 22, 22, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #fbfaf7 0%, #efe9dd 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
.file-button,
.nav-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  min-height: 42px;
  padding: 0 14px;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

button:hover,
.file-button:hover,
.nav-button:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.nav-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px clamp(16px, 3vw, 34px);
}

.topbar h1,
.panel h2,
.gallery-section h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(1.55rem, 2.4vw, 2.4rem);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.file-button input {
  display: none;
}

.capture-guide[hidden] {
  display: none;
}

.capture-guide {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(18, 28, 25, 0.46);
}

.capture-guide-card {
  position: relative;
  width: min(100%, 520px);
  padding: 26px;
  border: 1px solid rgba(221, 216, 207, 0.95);
  border-radius: 12px;
  background: #fffdf9;
  box-shadow: 0 24px 70px rgba(22, 22, 22, 0.26);
}

.capture-guide-card h2 {
  margin: 0 42px 8px 0;
  font-size: 1.45rem;
}

.capture-guide-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 1.7rem;
  line-height: 1;
}

.capture-guide-intro {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.capture-pose-preview {
  position: relative;
  display: grid;
  place-items: center;
  height: 122px;
  margin: 18px 0;
  overflow: hidden;
  border: 1px dashed rgba(15, 118, 110, 0.42);
  border-radius: 8px;
  background: linear-gradient(135deg, #eaf4ef, #f9eee3);
}

.pose-hand {
  font-size: 4.6rem;
  filter: grayscale(1) saturate(0.25);
  transform: rotate(-14deg);
}

.pose-target {
  position: absolute;
  top: 25px;
  left: calc(50% + 18px);
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-size: 0;
}

.capture-guide-steps {
  display: grid;
  gap: 9px;
  margin: 0;
  padding-left: 24px;
  color: var(--ink);
  line-height: 1.45;
}

.capture-guide-steps li::marker {
  color: var(--accent-strong);
  font-weight: 800;
}

.capture-guide-retry {
  margin: 16px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--danger);
  background: #fff1ef;
  color: var(--danger);
  line-height: 1.4;
}

.capture-guide-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

#cameraButton {
  background: #1c2830;
  border-color: #1c2830;
  color: #fff;
}

#autoFitButton,
.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 800;
}

#autoFitButton,
.controls-panel {
  display: none;
}

.gallery-section {
  display: none;
}

.segmented {
  grid-template-columns: 1fr;
}

.hint-bar:empty {
  display: none;
}

#downloadButton {
  background: var(--gold);
  border-color: var(--gold);
  color: #fff;
  font-weight: 800;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(360px, 1fr) minmax(260px, 330px);
  gap: 16px;
  padding: 0 clamp(16px, 3vw, 34px) 18px;
}

.panel,
.gallery-section {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(221, 216, 207, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  min-height: 0;
  padding: 16px;
}

.panel-heading,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel h2,
.gallery-section h2 {
  font-size: 1.05rem;
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 1.25rem;
}

.danger-button {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin: 14px 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.segmented button {
  min-height: 34px;
  padding: 0 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
}

.segmented button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 3px 12px rgba(22, 22, 22, 0.08);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-height: calc(100vh - 240px);
  overflow: auto;
  padding-right: 2px;
}

.product-card {
  display: grid;
  grid-template-rows: 136px auto;
  gap: 8px;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.product-card.active {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 118, 110, 0.15);
}

.product-card img {
  width: 100%;
  height: 136px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface);
}

.product-card span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.studio-area {
  min-width: 0;
}

.studio-area.is-empty .canvas-wrap,
.studio-area.is-empty .hint-bar {
  display: none;
}

.zoom-controls {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(221, 216, 207, 0.95);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 24px rgba(22, 22, 22, 0.14);
}

.zoom-controls button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
}

.zoom-controls span {
  min-width: 48px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

.canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: calc(100vh - 172px);
  overflow: hidden;
  border: 1px solid rgba(221, 216, 207, 0.9);
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.86) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.86) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.86) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.86) 75%);
  background-color: #e7e0d3;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  box-shadow: var(--shadow);
}

#cameraFeed {
  display: none;
}

#tryOnCanvas {
  display: block;
  width: 100%;
  max-width: min(100%, 760px);
  max-height: calc(100vh - 172px);
  aspect-ratio: 4 / 5;
  background: rgba(255, 255, 255, 0.7);
  touch-action: none;
}

.empty-state {
  position: absolute;
  inset: auto 24px 24px;
  display: grid;
  gap: 4px;
  max-width: 420px;
  padding: 14px 16px;
  border: 1px solid rgba(221, 216, 207, 0.95);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  box-shadow: 0 12px 28px rgba(22, 22, 22, 0.12);
}

.empty-state:empty {
  display: none;
}

.empty-state strong {
  color: var(--ink);
}

.fit-status {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 9px 13px;
  border: 1px solid rgba(221, 216, 207, 0.95);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 10px 24px rgba(22, 22, 22, 0.12);
}

.fit-status[data-tone="ok"] {
  border-color: rgba(15, 118, 110, 0.36);
  color: var(--accent-strong);
}

.fit-status[data-tone="busy"] {
  border-color: rgba(193, 145, 44, 0.45);
  color: #7b5c19;
}

.fit-status[data-tone="warn"] {
  border-color: rgba(166, 56, 56, 0.3);
  color: var(--danger);
}

.hint-bar {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.control-row {
  display: grid;
  gap: 8px;
  margin-top: 15px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.control-row input,
.control-row select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 18px;
}

.button-grid .primary-button {
  grid-column: 1 / -1;
}

.button-grid button {
  padding: 0 10px;
}

.mini-help {
  margin-top: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.mini-help code {
  color: var(--ink);
  font-weight: 800;
}

.approval-shell {
  padding: 0 clamp(16px, 3vw, 34px) 34px;
}

.approval-note {
  margin: 0 0 14px;
  background: #fff;
}

.approval-status {
  margin-bottom: 14px;
  color: var(--muted);
  font-weight: 700;
}

.approval-grid {
  display: grid;
  gap: 16px;
}

.approval-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.approval-card[data-approved="true"] {
  border-color: rgba(15, 118, 110, 0.55);
}

.approval-card-heading,
.approval-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.approval-card h2,
.approval-card p {
  margin: 0;
}

.approval-card h2 {
  font-size: 1rem;
}

.approval-card p {
  color: var(--muted);
  font-size: 0.86rem;
}

.approval-pill {
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.approval-card[data-approved="true"] .approval-pill {
  background: rgba(15, 118, 110, 0.12);
  color: var(--accent-strong);
}

.approval-compare {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.approval-image-panel {
  display: grid;
  grid-template-rows: auto minmax(210px, 1fr);
  gap: 8px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.approval-image-panel span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.approval-image-panel img {
  width: 100%;
  height: 260px;
  object-fit: contain;
  border-radius: 6px;
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%),
    linear-gradient(-45deg, #eee 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eee 75%),
    linear-gradient(-45deg, transparent 75%, #eee 75%);
  background-color: #fff;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.approval-missing {
  display: grid;
  min-height: 260px;
  place-items: center;
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
}

.gallery-section {
  margin: 0 clamp(16px, 3vw, 34px) 34px;
  padding: 16px;
}

#galleryStatus {
  color: var(--muted);
  font-size: 0.9rem;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.result-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.result-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
}

.result-card a {
  display: block;
  padding: 10px;
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: none;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: minmax(260px, 0.85fr) minmax(360px, 1.15fr);
  }

  .controls-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .topbar,
  .app-shell {
    display: grid;
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions > * {
    flex: 1 1 150px;
  }

  .product-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-height: none;
  }

  .product-card {
    grid-template-rows: 96px auto;
  }

  .product-card img {
    height: 96px;
  }

  .canvas-wrap {
    min-height: 72vh;
  }

  .capture-guide-card {
    padding: 22px 18px;
  }

  #tryOnCanvas {
    max-height: 72vh;
  }

  .approval-compare {
    grid-template-columns: 1fr;
  }

  .approval-card-heading,
  .approval-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .approval-image-panel img,
  .approval-missing {
    height: 220px;
    min-height: 220px;
  }
}
