:root {
  color-scheme: light;
  --paper: #f7f0e7;
  --card: #fffbf5;
  --ink: #33241f;
  --muted: #65534a;
  --accent: #9e3d30;
  --accent-dark: #803024;
  --rule: #e2d3c5;
  --serif: "Songti SC", "Noto Serif CJK SC", "Noto Serif SC", SimSun, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --duration: 1300ms;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; }
button:focus-visible, summary:focus-visible, input:focus-visible + span {
  outline: 2px solid var(--accent-dark);
  outline-offset: 4px;
}

h1, h2, p, figure { margin: 0; }

.masthead {
  width: min(1120px, calc(100% - 80px));
  min-height: 76px;
  margin: auto;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { display: inline-flex; gap: 9px; align-items: center; font-size: 24px; font-weight: 800; letter-spacing: -.8px; }
.brand-mark { color: var(--accent); font-size: 27px; line-height: .8; }
.brand-label { font-size: 14px; font-weight: 600; color: var(--muted); letter-spacing: .11em; }

.page { width: min(1040px, calc(100% - 80px)); margin: 56px auto 64px; }

.studio {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, .92fr);
  grid-template-rows: 1fr 1fr;
  grid-template-areas: "photo intro" "photo entry";
  column-gap: clamp(48px, 8vw, 110px);
  min-height: 470px;
}

.intro { grid-area: intro; align-self: end; margin-bottom: 28px; }
.intro h1 {
  font-family: var(--serif);
  font-size: clamp(46px, 5.25vw, 76px);
  font-weight: 700;
  line-height: 1.13;
  letter-spacing: -.075em;
}
.intro h1 em { font-style: normal; color: var(--accent); }
.intro p { color: var(--muted); font-size: clamp(15px, 1.4vw, 18px); line-height: 1.7; margin-top: 20px; }

.photo-frame {
  grid-area: photo;
  position: relative;
  width: 100%;
  aspect-ratio: .9;
  max-height: 570px;
  min-height: 0;
  margin: 0;
  isolation: isolate;
  overflow: hidden;
  align-self: start;
  background: #dac5af;
  border-radius: 24px;
  box-shadow: 0 20px 46px #5d382614;
}

.photo-frame img, .result-portrait img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 44%;
}

body:not([data-stage="idle"]) .photo-frame img {
  object-fit: contain;
  object-position: center;
  background: #e9dcd0;
}

.photo-frame figcaption, .photo-change {
  position: absolute;
  left: 16px;
  bottom: 16px;
  padding: 8px 15px;
  background: #fffaf1f5;
  border-radius: 999px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}
.photo-change { border: 1px solid #ffffffa0; min-height: 44px; }

.entry { grid-area: entry; align-self: start; min-width: 0; }
.entry-controls { max-width: 350px; }
.primary, .secondary {
  display: block;
  width: 100%;
  min-height: 53px;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 13px 22px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}
.primary { background: var(--accent); color: #fffaf5; }
.primary:hover { background: var(--accent-dark); }
.primary:disabled { background: #a57468; }
.secondary { background: transparent; color: var(--accent-dark); border-color: #c8a392; }
.secondary:hover { background: #f2ded4; }

.privacy-note, .report-note { margin: 13px 0 0; font-size: 13px; color: var(--muted); line-height: 1.6; }
.photo-message { color: var(--accent-dark); font-size: 14px; line-height: 1.5; margin-top: 10px; }
.photo-message:empty { margin: 0; }

.style-field { margin: 0 0 15px; padding: 0; border: 0; min-width: 0; }
.style-field legend { padding: 0; font-size: 14px; font-weight: 700; }
.style-field legend span { margin-left: 5px; color: var(--muted); font-size: 13px; font-weight: 400; }
.style-options { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.style-options label { position: relative; cursor: pointer; }
.style-options input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.style-options span {
  display: grid;
  place-items: center;
  min-height: 40px;
  min-width: 57px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid #d8bfb0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.style-options input:checked + span {
  background: #f4e0d6;
  color: var(--accent-dark);
  border-color: #bb7c67;
}

.scan-overlay { position: absolute; inset: 0; overflow: hidden; opacity: 0; pointer-events: none; }
body[data-stage="scanning"] .scan-overlay { opacity: 1; }
.scan-overlay i {
  position: absolute;
  width: 30px;
  height: 30px;
  border: 2px solid #fff1d1;
  border-radius: 7px;
  opacity: .9;
}
.scan-overlay i:nth-child(1) { inset: 16px auto auto 16px; border-right: 0; border-bottom: 0; }
.scan-overlay i:nth-child(2) { inset: 16px 16px auto auto; border-left: 0; border-bottom: 0; }
.scan-overlay i:nth-child(3) { inset: auto auto 16px 16px; border-right: 0; border-top: 0; }
.scan-overlay i:nth-child(4) { inset: auto 16px 16px auto; border-left: 0; border-top: 0; }
.scan-beam {
  position: absolute;
  inset: -66px 0 auto;
  height: 64px;
  border-bottom: 2px solid #fff5dc;
  background: linear-gradient(transparent, #ffd9a559);
  box-shadow: 0 7px 28px #ffcb8f7a;
}
body[data-stage="scanning"] .scan-beam { animation: scan var(--duration) cubic-bezier(.35,.08,.46,1) both; }
@keyframes scan { 0% { top: -66px; opacity: .2; } 12% { opacity: 1; } 92% { opacity: 1; } 100% { top: 100%; opacity: 0; } }
.scan-status { max-width: 350px; color: var(--muted); font-size: 15px; font-weight: 600; }
.scan-status p { margin-top: 10px; }
.scan-track { display: block; height: 3px; overflow: hidden; border-radius: 20px; background: #e8d5c5; }
.scan-track::after { content: ""; display: block; height: 100%; width: 100%; transform-origin: left; background: var(--accent); }
body[data-stage="scanning"] .scan-track::after { animation: progress var(--duration) ease-out both; }
@keyframes progress { from { transform: scaleX(.08); } to { transform: scaleX(1); } }

.report { max-width: 770px; margin: 0 auto; }
.result-card {
  background: var(--card);
  border: 1px solid #e7d7ca;
  border-radius: 26px;
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(0, .8fr) minmax(0, 1fr);
  gap: 26px;
  box-shadow: 0 14px 55px #5d382611;
  animation: reveal .45s ease-out both;
}
.result-portrait { position: relative; overflow: hidden; align-self: stretch; border-radius: 15px; min-height: 280px; background: #eadbcf; }
.result-portrait img { position: absolute; inset: 0; object-fit: contain; }
.result-portrait span { position: absolute; bottom: 11px; right: 13px; color: #fffaf0; font-size: 26px; text-shadow: 0 1px 6px #302218a0; }
.result-copy { min-width: 0; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; padding: 4px 4px 4px 0; }
.result-copy h1 { font-family: var(--serif); font-weight: 700; font-size: clamp(32px, 4.2vw, 47px); letter-spacing: -.05em; line-height: 1.04; }
.result-copy h1:focus { outline: none; }
.result-score { display: flex; gap: 10px; align-items: baseline; color: var(--accent); }
.result-score strong { font-family: Georgia, serif; font-weight: 500; font-size: clamp(65px, 8vw, 106px); line-height: .86; letter-spacing: -.09em; animation: reveal .55s .1s ease-out both; }
.result-score span { font-size: 14px; font-weight: 700; }
.style-tag { padding: 5px 10px; border: 1px solid #ddbaaa; border-radius: 999px; background: #f6e6dd; font-size: 14px; color: var(--accent-dark); font-weight: 700; }
.result-quote { line-height: 1.62; font-size: 17px; font-weight: 600; }
.quick-tip { width: 100%; border-top: 1px solid var(--rule); padding-top: 11px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.quick-tip b { display: block; color: var(--accent-dark); margin-bottom: 2px; }
@keyframes reveal { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.report-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.report .photo-message, .report-note { text-align: center; }
.details { margin-top: 38px; }
.details h2 { font-size: 23px; font-family: var(--serif); line-height: 1.4; margin-bottom: 12px; }
.details details { border-top: 1px solid var(--rule); }
.details details:last-child { border-bottom: 1px solid var(--rule); }
.details summary { display: flex; justify-content: space-between; align-items: center; min-height: 51px; padding: 8px 4px; gap: 12px; font-weight: 700; cursor: pointer; list-style: none; }
.details summary::-webkit-details-marker { display: none; }
.details summary::after {
  content: "";
  width: 9px;
  height: 9px;
  margin-right: 4px;
  border: solid var(--accent);
  border-width: 0 1.5px 1.5px 0;
  transform: translateY(-2px) rotate(45deg);
}
.details details[open] summary::after { transform: translateY(2px) rotate(225deg); }
.detail-body { padding: 1px 4px 15px; color: var(--muted); font-size: 15px; line-height: 1.62; }
.detail-body p + p { margin-top: 5px; }
.detail-lead { color: var(--accent-dark); font-weight: 700; }
.detail-body .detail-note { margin-top: 9px; font-size: 13px; }
.detail-list { margin: 0; }
.detail-list div { display: grid; grid-template-columns: 6em 1fr; gap: 12px; padding: 3px 0; }
.detail-list dt { font-weight: 700; color: var(--ink); }
.detail-list dd { margin: 0; }
.swatches { display: flex; gap: 14px; flex-wrap: wrap; padding: 0; margin: 12px 0 0; list-style: none; font-size: 13px; }
.swatches li { display: flex; align-items: center; gap: 6px; }
.swatches i { width: 15px; height: 15px; border: 1px solid #33241f34; border-radius: 50%; }

.save-dialog {
  width: min(420px, calc(100vw - 28px));
  max-height: calc(100dvh - 36px);
  padding: 17px;
  border: 1px solid var(--rule);
  border-radius: 18px;
  background: var(--card);
  color: var(--ink);
}
.save-dialog::backdrop { background: #3a201cc2; }
.save-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.save-header h2 { font-size: 18px; }
.close-button { min-height: 44px; border: 0; background: none; color: var(--accent-dark); padding: 0 8px; }
.save-dialog p { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.save-dialog img { display: block; max-width: 100%; width: auto; max-height: calc(100dvh - 158px); margin: auto; border-radius: 8px; }

@media (max-width: 710px) {
  .masthead { width: calc(100% - 36px); min-height: 55px; }
  .brand { font-size: 21px; }
  .brand-mark { font-size: 23px; }
  .brand-label { font-size: 13px; }
  .page { width: calc(100% - 36px); max-width: 480px; margin: 23px auto max(40px, env(safe-area-inset-bottom)); }
  .studio { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; grid-template-areas: "intro" "photo" "entry"; gap: 13px; min-height: 0; }
  .intro { margin-bottom: 0; }
  .intro h1 { font-size: clamp(37px, 10vw, 47px); line-height: 1.08; }
  .intro p { font-size: 15px; margin-top: 8px; line-height: 1.5; }
  .photo-frame { aspect-ratio: 1.36; max-height: 30svh; border-radius: 16px; }
  .photo-frame figcaption, .photo-change { bottom: 9px; left: 9px; }
  .entry-controls, .scan-status { max-width: none; }
  .primary, .secondary { padding: 12px 12px; min-height: 49px; font-size: 15px; }
  .privacy-note, .report-note { margin-top: 9px; }
  .style-field { margin: 8px 0 0; }
  .entry-controls { display: flex; flex-direction: column; }
  .style-field { order: 2; }
  .privacy-note { order: 3; }
  .photo-message { order: 4; }
  .style-options { margin-top: 5px; gap: 6px; }
  .style-options span { min-height: 38px; }
  .result-card { gap: 12px; padding: 14px; grid-template-columns: minmax(74px, .66fr) minmax(0, 1fr); border-radius: 19px; }
  .result-portrait { min-height: 0; align-self: start; width: 100%; aspect-ratio: .78; border-radius: 10px; grid-column: 1; grid-row: 1; }
  .result-copy { display: contents; }
  .result-copy h1 { font-size: clamp(26px, 7.3vw, 32px); grid-column: 2; grid-row: 1; align-self: start; }
  .result-score { grid-column: 2; grid-row: 1; align-self: end; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; margin-bottom: 2px; }
  .result-score strong { font-size: clamp(54px, 17vw, 82px); }
  .result-score span { font-size: 13px; }
  .style-tag { grid-column: 1 / -1; justify-self: start; font-size: 13px; }
  .result-quote, .quick-tip { grid-column: 1 / -1; }
  .result-quote { font-size: 16px; }
  .quick-tip { font-size: 14px; }
  .report-actions { margin-top: 12px; gap: 7px; }
  .details { margin-top: 28px; }
  .detail-list div { grid-template-columns: 5em 1fr; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .scan-beam { display: none; }
}
