:root {
  --bg: #ffffff;
  --ink: #21191c;
  --muted: #776b70;
  --soft: #f7f2f3;
  --line: #eadfe2;
  --rose: #c64f6a;
  --rose-deep: #9f344f;
  --sage: #7d9b8a;
  --sage-soft: #e9f0eb;
  --shadow: 0 18px 48px rgba(88, 57, 67, 0.14);
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, #fff 0%, #fff 56%, #f8f5f5 100%);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  position: relative;
  width: min(100vw, 430px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px 18px 108px;
  background: var(--bg);
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 10px;
  align-items: center;
  padding: 4px 0 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  font-weight: 760;
  text-align: center;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
}

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

.icon-button svg,
.secondary-action svg,
.tile-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.preview-stage {
  padding-top: 2px;
}

.preview-toolbar {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  height: 30px;
  min-width: 58px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.chip.is-active {
  border-color: rgba(198, 79, 106, 0.24);
  background: #fff0f3;
  color: var(--rose-deep);
}

.preview-canvas {
  position: relative;
  display: grid;
  min-height: 330px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 10%, rgba(233, 240, 235, 0.9), transparent 42%),
    linear-gradient(180deg, #fbfaf9, #fff);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.preview-canvas img {
  width: 100%;
  height: 100%;
  min-height: 330px;
  object-fit: cover;
}

.empty-face {
  display: grid;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.empty-face svg {
  width: 150px;
  height: 170px;
  fill: none;
  stroke: #d7c8cd;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-face svg path:first-child {
  fill: #fff;
}

.generation-mask {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.74);
  backdrop-filter: blur(8px);
  color: var(--rose-deep);
}

.generation-mask span {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(198, 79, 106, 0.2);
  border-top-color: var(--rose);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

.generation-mask strong {
  font-size: 15px;
  font-weight: 720;
}

.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.single-upload {
  grid-template-columns: 1fr;
}

.catalog-section {
  margin-top: 14px;
}

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

.section-heading strong {
  font-size: 15px;
  line-height: 1.2;
}

.section-heading span {
  color: var(--muted);
  font-size: 12px;
}

.catalog-search {
  display: grid;
  grid-template-columns: 20px 1fr 30px;
  gap: 8px;
  align-items: center;
  height: 42px;
  margin-bottom: 10px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf9;
  color: var(--muted);
}

.catalog-search > svg,
.catalog-clear-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.catalog-search input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
}

.catalog-search input::placeholder {
  color: #a99da2;
}

.catalog-clear-button {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.catalog-filters {
  display: flex;
  gap: 8px;
  margin: 0 -18px 10px;
  padding: 0 18px 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.catalog-filters::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  flex: 0 0 auto;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.filter-chip.is-active {
  border-color: rgba(198, 79, 106, 0.55);
  background: #fff0f3;
  color: var(--rose-deep);
}

.wig-catalog {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(124px, 1fr));
  gap: 10px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 2px;
}

.wig-card {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  text-align: left;
}

.wig-card.is-selected {
  border-color: rgba(198, 79, 106, 0.7);
  box-shadow: 0 10px 24px rgba(198, 79, 106, 0.14);
}

.wig-card img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  background: var(--soft);
  object-fit: cover;
}

.wig-card span {
  display: grid;
  gap: 3px;
}

.wig-card strong {
  overflow: hidden;
  font-size: 13px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wig-card em,
.catalog-empty {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.3;
}

.catalog-empty {
  width: 260px;
  margin: 0;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
}

.catalog-load-more {
  width: 100%;
  height: 38px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 760;
}

.catalog-load-more:disabled {
  color: #b7aeb2;
  background: #faf8f8;
}

.library-upload {
  position: relative;
  display: grid;
  width: 100%;
  grid-template-columns: 38px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 68px;
  margin-top: 10px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  overflow: hidden;
  text-align: left;
}

.library-upload img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.14;
}

.upload-tile {
  position: relative;
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  text-align: left;
  overflow: hidden;
}

.upload-tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.22;
}

.tile-icon {
  position: relative;
  z-index: 1;
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  background: var(--sage-soft);
  color: #557262;
}

.tile-copy {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 4px;
}

.tile-copy strong {
  font-size: 14px;
  line-height: 1.2;
}

.tile-copy em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.2;
}

.selfie-quality {
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf9;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.selfie-quality.ok {
  border-color: rgba(85, 114, 98, 0.24);
  background: #f5faf7;
  color: #557262;
}

.selfie-quality.warn,
.selfie-quality.blocked {
  border-color: rgba(198, 79, 106, 0.22);
  background: #fff7f8;
  color: var(--rose-deep);
}

.control-panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.slider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.slider-row span {
  display: grid;
  gap: 4px;
}

.slider-row strong {
  font-size: 14px;
  line-height: 1.2;
}

.slider-row em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.slider-row output {
  min-width: 42px;
  padding: 6px 8px;
  border-radius: 8px;
  background: #fff0f3;
  color: var(--rose-deep);
  font-size: 14px;
  font-weight: 760;
  text-align: center;
}

input[type="range"] {
  width: 100%;
  margin: 14px 0 10px;
  accent-color: var(--rose);
}

textarea {
  width: 100%;
  resize: none;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  color: var(--ink);
  background: #fbfaf9;
  font-size: 13px;
  line-height: 1.45;
}

textarea:focus {
  border-color: rgba(198, 79, 106, 0.6);
  background: #fff;
}

.compare-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.compare-strip article {
  display: grid;
  gap: 8px;
}

.compare-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.compare-strip div {
  display: grid;
  min-height: 86px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  overflow: hidden;
}

.compare-strip img {
  width: 100%;
  height: 86px;
  object-fit: cover;
}

.result-disclaimer,
.result-retention {
  margin: 10px 2px 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.55;
}

.result-disclaimer {
  border: 1px solid rgba(198, 79, 106, 0.22);
  background: #fff8fa;
  color: var(--muted);
}

.result-retention {
  border: 1px solid rgba(125, 155, 138, 0.34);
  background: #f5faf7;
  color: #557262;
  font-weight: 680;
}

.consult-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin: 10px 2px 0;
  padding: 12px;
  border: 1px solid rgba(125, 155, 138, 0.34);
  border-radius: 8px;
  background: #f8fbf8;
}

.consult-card div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.consult-card strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.2;
}

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

.consult-card button {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  background: #557262;
  color: #fff;
  font-size: 13px;
  font-weight: 760;
  white-space: nowrap;
}

.consult-card button:disabled {
  background: #b8c7bd;
}

.privacy-consent {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 9px;
  align-items: start;
  margin: 14px 2px 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  cursor: pointer;
  user-select: none;
}

.privacy-consent input {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  accent-color: var(--rose);
  cursor: pointer;
}

.privacy-consent span {
  min-width: 0;
}

.privacy-consent a {
  color: var(--rose-deep);
  font-weight: 760;
  text-decoration: none;
}

.diagnostic-note {
  display: grid;
  gap: 8px;
  margin: 10px 2px 0;
  padding: 10px 12px;
  border: 1px solid rgba(184, 126, 42, 0.28);
  border-radius: 8px;
  background: #fff7e9;
  color: #7d551b;
  font-size: 12px;
  font-weight: 680;
  line-height: 1.55;
  word-break: break-word;
}

.diagnostic-note button {
  justify-self: start;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  background: #fff;
  color: #7d551b;
  font-size: 12px;
  font-weight: 760;
}

.privacy-page {
  padding-bottom: 28px;
}

.privacy-page .icon-button {
  text-decoration: none;
}

.privacy-content {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.privacy-content h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.3;
}

.privacy-content p {
  margin: -6px 0 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.action-bar {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  display: grid;
  width: min(100vw, 430px);
  grid-template-columns: 78px 78px 1fr;
  gap: 10px;
  padding: 12px 18px 18px;
  background: rgba(255, 255, 255, 0.92);
  border-top: 1px solid var(--line);
  transform: translateX(-50%);
  backdrop-filter: blur(12px);
}

.primary-action,
.secondary-action {
  height: 48px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 760;
}

.primary-action {
  background: linear-gradient(180deg, #d7617b, var(--rose));
  color: #fff;
  box-shadow: 0 12px 26px rgba(198, 79, 106, 0.28);
}

.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.secondary-action:disabled {
  color: #b7aeb2;
  background: #faf8f8;
}

.danger-action {
  color: var(--rose-deep);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 48px));
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(33, 25, 28, 0.92);
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  transform: translateX(-50%);
  box-shadow: 0 12px 26px rgba(33, 25, 28, 0.18);
}

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

@media (min-width: 720px) {
  body {
    display: grid;
    place-items: start center;
    padding: 24px 0;
    background: #f4eeee;
  }

  .app-shell {
    min-height: calc(100vh - 48px);
    border: 1px solid rgba(234, 223, 226, 0.9);
    border-radius: 22px;
    box-shadow: 0 28px 90px rgba(88, 57, 67, 0.18);
  }

  .action-bar {
    position: static;
    width: auto;
    margin: 18px -18px -108px;
    transform: none;
  }
}
