:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #1a1a1c;
  --muted: #6f6f76;
  --line: #e8e6e1;
  --accent: #3d5a4c;
  --accent-soft: #e8efe9;
  --error: #b44d42;
  --error-soft: #fdf0ee;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 20px 50px rgba(26, 26, 28, 0.06);
  --font: "DM Sans", ui-sans-serif, system-ui, sans-serif;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(20px, 4vw, 40px);
  background: rgba(246, 245, 242, 0.82);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(232, 230, 225, 0.8);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(145deg, #2a2a2e 0%, #4a4a52 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.brand-text strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-text small {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.status-dot::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c4c4c8;
  flex-shrink: 0;
}

.status-dot[data-state="ready"]::before {
  background: #5a9a6e;
  box-shadow: 0 0 0 3px rgba(90, 154, 110, 0.2);
}

.status-dot[data-state="missing"]::before {
  background: #d4786a;
}

.status-dot[data-state="checking"]::before {
  background: #c4a24a;
  animation: pulse-dot 1.2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 0.5;
    transform: scale(0.92);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.app {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: clamp(20px, 3vw, 36px);
  max-width: 1200px;
  margin: 0 auto;
  padding: clamp(20px, 3vw, 36px) clamp(20px, 4vw, 40px) 48px;
  align-items: start;
}

.sidebar__intro h1 {
  margin: 0 0 8px;
  font-size: clamp(1.5rem, 2.5vw, 1.85rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.sidebar__intro p {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 0.92rem;
  max-width: 32ch;
}

.block {
  margin-bottom: 24px;
}

.block__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.block__head h2 {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.block__step {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  opacity: 0.7;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.product-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: inherit;
  text-align: left;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.2s ease;
}

.product-card:hover {
  box-shadow: 0 8px 24px rgba(26, 26, 28, 0.06);
  transform: translateY(-1px);
}

.product-card.is-selected {
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}

.product-card__img {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
  background: #f0eeea;
}

.product-card__img img {
  display: block;
  width: 200%;
  height: 200%;
  max-width: none;
  object-fit: cover;
}

.crop-shirt img {
  transform: translate(0, 0);
}
.crop-jacket img {
  transform: translate(-50%, 0);
}
.crop-sweater img {
  transform: translate(0, -50%);
}
.crop-hoodie img {
  transform: translate(-50%, -50%);
}

.product-card__name {
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.product-card__detail {
  font-size: 0.75rem;
  color: var(--muted);
}

.link-btn {
  display: inline-block;
  margin-bottom: 10px;
  padding: 0;
  background: none;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-btn:hover {
  color: var(--ink);
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 140px;
  padding: 20px;
  border: 1px dashed #d0cdc6;
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition:
    border-color 0.2s,
    background 0.2s;
}

.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.dropzone__icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--line);
  position: relative;
}

.dropzone__icon::before,
.dropzone__icon::after {
  content: "";
  position: absolute;
  background: var(--muted);
  border-radius: 1px;
}

.dropzone__icon::before {
  width: 14px;
  height: 1.5px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.dropzone__icon::after {
  width: 1.5px;
  height: 14px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.dropzone__title {
  font-size: 0.88rem;
  font-weight: 600;
}

.dropzone__meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.thumb {
  position: relative;
  margin-top: 10px;
  overflow: hidden;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

.thumb img {
  display: block;
  width: 100%;
  max-height: 200px;
  object-fit: cover;
}

.thumb__clear {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(26, 26, 28, 0.75);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  backdrop-filter: blur(4px);
}

.stage {
  position: sticky;
  top: 72px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.stage__head {
  margin-bottom: 16px;
}

.stage__eyebrow {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.stage__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.viewport {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: #efede8;
  aspect-ratio: 4 / 5;
}

.viewport__img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.viewport__img.is-shimmer {
  animation: shimmer 1.8s ease-in-out infinite;
}

@keyframes shimmer {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(0.92);
  }
}

.viewport__empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.viewport__empty[hidden],
.viewport__loading[hidden],
.viewport__img[hidden] {
  display: none !important;
}

.viewport__empty p {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
}

.viewport__empty span {
  font-size: 0.8rem;
}

.viewport__placeholder {
  width: 72px;
  height: 96px;
  margin-bottom: 8px;
  border-radius: 36% 36% 20% 20%;
  background: linear-gradient(180deg, #ddd9d2 0%, #e8e5df 100%);
  opacity: 0.7;
}

.viewport__loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px;
  background: rgba(246, 245, 242, 0.88);
  backdrop-filter: blur(12px);
  text-align: center;
}

.loader {
  position: relative;
  width: 52px;
  height: 52px;
}

.loader__ring {
  position: absolute;
  inset: 0;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loader__ring--delayed {
  inset: 8px;
  border-top-color: var(--muted);
  animation-duration: 1.4s;
  animation-direction: reverse;
}

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

.loading__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.loading__step {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  min-height: 1.25em;
  transition: opacity 0.3s ease;
}

.loading__bar {
  width: min(200px, 70%);
  height: 3px;
  margin-top: 4px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.loading__bar-fill {
  display: block;
  height: 100%;
  width: 35%;
  border-radius: inherit;
  background: var(--accent);
  animation: loading-slide 1.6s ease-in-out infinite;
}

@keyframes loading-slide {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(320%);
  }
}

.stage__actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  min-height: 48px;
  padding: 0 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  transition:
    opacity 0.2s,
    transform 0.15s,
    background 0.2s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn--primary {
  background: var(--ink);
  color: #fff;
}

.btn--primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn--ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn--ghost:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn.is-loading .btn__label {
  opacity: 0;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn--primary {
  position: relative;
}

.feedback {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  line-height: 1.45;
}

.feedback[hidden] {
  display: none;
}

.feedback.is-error {
  background: var(--error-soft);
  color: var(--error);
}

.feedback.is-success {
  background: var(--accent-soft);
  color: var(--accent);
}

.feedback.is-info {
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--line);
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .stage {
    position: static;
    order: -1;
  }
}

@media (max-width: 520px) {
  .product-grid {
    grid-template-columns: 1fr;
  }

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
