.primary-button,
.ghost-button,
.icon-button,
.body-card,
.garment-chip {
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.primary-button:active,
.ghost-button:active,
.icon-button:active,
.body-card:active,
.garment-chip:active {
  transform: translateY(1px);
}

.primary-button {
  min-height: 48px;
  padding: 0 20px;
  color: #fff;
  background: var(--jade);
  border-color: rgba(18, 44, 39, 0.2);
  border-radius: var(--radius);
  box-shadow: 0 12px 24px rgba(64, 111, 102, 0.24);
  font-weight: 700;
}

.ghost-button {
  min-height: 38px;
  padding: 0 12px;
  color: var(--jade);
  background: rgba(255, 255, 255, 0.72);
  border-color: var(--line);
  border-radius: var(--radius);
  white-space: nowrap;
}

.ghost-button.compact {
  min-height: 34px;
  padding: 0 9px;
  font-size: 13px;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
  border-radius: var(--radius);
  font-size: 32px;
  line-height: 1;
}

.preview-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.preview-strip article {
  min-height: 82px;
  padding: 12px 10px;
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.preview-strip strong,
.preview-strip span {
  display: block;
}

.preview-strip strong {
  font-size: 16px;
}

.preview-strip span {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.workbench-header {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: -14px -14px 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
  background: rgba(251, 250, 245, 0.88);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(222, 217, 205, 0.78);
  flex-wrap: nowrap;
}

.workbench-title,
.workbench-brand {
  min-width: 0;
  flex: 0 0 auto;
}

.workbench-brand {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-family: var(--brand-kai-font);
  font-size: 17px;
  font-weight: 600;
  justify-self: start;
  white-space: nowrap;
}

.workbench-header p {
  color: var(--muted);
  font-size: clamp(10px, 2.7vw, 12px);
}

.workbench-header h1 {
  margin-top: 2px;
  overflow: hidden;
  font-size: clamp(14px, 4vw, 18px);
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.body-segment {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  gap: 6px;
  padding: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.body-segment::-webkit-scrollbar {
  display: none;
}

.look-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.look-summary p {
  color: var(--muted);
  font-size: 12px;
}

.look-summary strong {
  font-size: 15px;
  line-height: 1.35;
}

.look-summary span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.save-look-button {
  min-width: max-content;
}

.stage-actions {
  display: flex;
  justify-content: flex-end;
}

.save-look-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.save-page {
  width: min(100%, 1160px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(18px, env(safe-area-inset-bottom));
}

.save-page-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -12px -12px 10px;
  padding: max(12px, env(safe-area-inset-top)) 12px 10px;
  background: rgba(251, 250, 245, 0.9);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(222, 217, 205, 0.78);
}

.save-image-stage {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.save-image-preview {
  display: block;
  width: min(100%, 520px);
  height: auto;
  background: #fff;
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}

.save-image-stage p {
  margin: 0 0 18px;
  color: #8a918b;
  font-size: 14px;
  text-align: center;
}

.site-footer {
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 22px 0 4px;
  color: #8a918b;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.site-footer a:hover,
.site-footer a:focus-visible {
  text-decoration: underline;
}

.renderer-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  height: auto;
  min-height: 0;
}

.look-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.wardrobe-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: repeat(3, 218px);
  gap: 8px;
}

.controls {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.control-group {
  display: grid;
  gap: 12px;
}

.section-heading {
  display: grid;
  gap: 4px;
}

.section-heading h2 {
  font-size: 18px;
}

.section-heading span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.body-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.body-card {
  display: inline-grid;
  min-width: max-content;
  min-height: clamp(30px, 8vw, 34px);
  place-items: center;
  padding: 0 clamp(7px, 2.2vw, 10px);
  text-align: center;
  background: rgba(255, 255, 255, 0.76);
  border-color: var(--line);
  border-radius: var(--radius);
}

.body-card[aria-pressed="true"],
.garment-chip[aria-pressed="true"] {
  background: #fff;
  border-color: var(--jade);
  box-shadow: 0 8px 20px rgba(64, 111, 102, 0.14);
}

.body-card:disabled {
  cursor: not-allowed;
  color: rgba(24, 33, 31, 0.42);
  background: rgba(239, 237, 231, 0.74);
  border-color: rgba(222, 217, 205, 0.72);
  box-shadow: none;
}

.body-card:disabled span {
  font-weight: 600;
}

.body-card span {
  font-size: clamp(11px, 3.1vw, 13px);
  font-weight: 700;
  white-space: nowrap;
}

.body-card small,
.garment-chip small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.catalog-section {
  display: grid;
  min-height: 0;
  gap: 8px;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 9px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.catalog-title {
  display: grid;
  gap: 10px;
}

.catalog-title h3 {
  font-size: 15px;
}

.catalog-title span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.catalog-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.garment-chip {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 62px;
  padding: 8px;
  text-align: left;
  background: rgba(255, 255, 255, 0.76);
  border-color: var(--line);
  border-radius: var(--radius);
}

.garment-chip strong {
  display: block;
  font-size: 13px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.garment-kind {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
}

.swatch {
  position: relative;
  width: 34px;
  height: 34px;
  background: var(--swatch);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  overflow: hidden;
}

.swatch::after {
  position: absolute;
  inset: auto 0 0;
  height: 38%;
  background: var(--swatch-accent);
  content: "";
}

@media (max-width: 560px) {
  .workbench-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
  }

  .workbench-title,
  .workbench-brand {
    min-width: 0;
  }

  .body-segment {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    overflow: visible;
  }

  .body-card {
    min-width: 0;
    width: 100%;
    padding: 0 6px;
  }

  .body-card span {
    width: 100%;
    overflow: hidden;
    font-size: clamp(11px, 3.4vw, 13px);
    text-overflow: ellipsis;
  }

  .ghost-button.compact {
    max-width: 64px;
    padding: 0 7px;
    overflow: hidden;
    font-size: 12px;
    text-overflow: ellipsis;
  }

  .look-summary {
    grid-template-columns: 1fr;
  }

  .save-look-button {
    width: 100%;
  }

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

@media (max-width: 979px) {
  .look-panel {
    display: contents;
  }

  .look-summary {
    position: sticky;
    top: 72px;
    z-index: 9;
    box-shadow: 0 10px 24px rgba(40, 46, 42, 0.1);
  }

  .wardrobe-panel {
    grid-template-rows: none;
  }

  .catalog-section {
    grid-template-rows: auto auto;
  }

  .catalog-row {
    grid-auto-columns: minmax(148px, 46%);
    grid-auto-flow: column;
    grid-template-columns: none;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    overscroll-behavior-y: auto;
    padding: 0 2px 4px 0;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .garment-chip {
    min-width: 0;
    scroll-snap-align: start;
  }
}

@media (max-width: 560px) {
  .look-summary {
    top: calc(max(12px, env(safe-area-inset-top)) + 92px);
  }
}

@media (min-width: 760px) {
  .look-panel {
    grid-template-areas:
      "summary actions"
      "stage stage";
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .look-summary {
    grid-area: summary;
  }

  .stage-actions {
    grid-area: actions;
    align-items: stretch;
  }

  .stage {
    grid-area: stage;
  }

  .save-look-button {
    height: 100%;
  }

  .workbench-header {
    margin: 0 0 16px;
    padding: 0;
    background: transparent;
    border-bottom: 0;
    backdrop-filter: none;
  }

  .controls {
    grid-template-columns: minmax(260px, 0.45fr) minmax(360px, 1fr);
    gap: 22px;
  }

  .body-card {
    min-height: 38px;
    padding: 0 14px;
  }

  .garment-chip {
    grid-template-columns: 36px 1fr;
    align-items: center;
    min-height: 62px;
  }

  .catalog-title {
    display: flex;
    align-items: end;
    justify-content: space-between;
  }

  .catalog-title span {
    text-align: right;
  }
}

@media (max-width: 979px) {
  /* On phones, keep the save action directly between the mirror and wardrobe. */
  .stage {
    grid-area: auto;
    order: 1;
  }

  .stage-actions {
    grid-area: auto;
    order: 2;
  }

  .wardrobe-panel {
    grid-area: auto;
    order: 3;
  }
}

@media (min-width: 980px) {
  .renderer-layout {
    grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
    height: calc(100vh - 88px);
    min-height: 640px;
    gap: 16px;
  }

  .wardrobe-panel {
    grid-template-rows: repeat(3, minmax(0, 1fr));
  }
}
