:root {
  --ink: #17202b;
  --muted: #627184;
  --line: #d8e0e8;
  --soft: #f4f7fa;
  --panel: #ffffff;
  --blue: #1b6cae;
  --blue-dark: #124f83;
  --teal: #137a67;
  --amber: #ae680c;
  --red: #b83b34;
  --shadow: 0 18px 42px rgba(23, 32, 43, .11);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: #f6f8fa;
  color: var(--ink);
}

button, input, select { font: inherit; }
button { border: 0; cursor: pointer; }

.app { min-height: 100vh; }

.header {
  min-height: 72px;
  background: rgba(255,255,255,.97);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #e8f2fb;
  border: 1px solid #c8def0;
  position: relative;
}

.brand-mark::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 8px;
  width: 15px;
  height: 20px;
  border: 2px solid var(--blue);
  border-radius: 8px 8px 4px 4px;
  background: white;
}

.brand strong { display: block; font-size: 15px; line-height: 1.15; }
.brand span { color: var(--muted); font-size: 12px; }
.header-actions { display: flex; gap: 10px; }

.button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 15px;
  font-weight: 760;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: inherit;
  white-space: nowrap;
}

.button.primary { background: var(--blue); color: white; }
.button.primary:hover { background: var(--blue-dark); }
.button.secondary { background: #edf2f6; color: var(--ink); }
.button.full { width: 100%; }

main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 26px 22px 38px;
}

.intro {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 18px;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
  letter-spacing: 0;
}

.intro p {
  margin: 0;
  max-width: 760px;
  color: var(--muted);
  line-height: 1.5;
}

.trust {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.trust span {
  border-radius: 999px;
  background: #eaf5f1;
  color: #245b50;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  font-size: 12px;
  font-weight: 760;
}

.steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.step {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 76px;
  padding: 11px 13px;
  text-align: left;
  color: var(--ink);
}

.step.active {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.step small {
  display: block;
  color: var(--muted);
  margin-bottom: 4px;
}

.step strong {
  display: block;
  font-size: 15px;
  margin-bottom: 3px;
}

.step span { color: var(--muted); font-size: 13px; }

.screen {
  display: none;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.screen.active { display: grid; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel h2 { margin: 0; font-size: 16px; letter-spacing: 0; }
.panel-head {
  min-height: 62px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 15px 18px;
}

select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 0 10px;
}

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

.template-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  min-height: 246px;
  padding: 15px;
  text-align: left;
  display: grid;
  gap: 12px;
  color: inherit;
}

.template-card.active {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.template-art {
  height: 108px;
  border-radius: 8px;
  border: 1px solid #d4dce4;
  background:
    linear-gradient(90deg, transparent 49.5%, rgba(27,108,174,.22) 50%, transparent 50.5%),
    linear-gradient(180deg, #f8fafc, #eef3f7);
  display: grid;
  place-items: center;
}

.photo-icon {
  border: 2px solid #8196aa;
  background: white;
  position: relative;
}

.photo-icon.china { width: 58px; height: 84px; }
.photo-icon.us { width: 76px; height: 76px; }

.photo-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 21%;
  width: 26%;
  aspect-ratio: 1;
  transform: translateX(-50%);
  border-radius: 50%;
  background: #aebed0;
}

.photo-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 14%;
  width: 52%;
  height: 28%;
  transform: translateX(-50%);
  border-radius: 50% 50% 4px 4px;
  background: #aebed0;
}

.template-card h3 { margin: 0; font-size: 16px; }
.template-card p { margin: 0; color: var(--muted); line-height: 1.45; font-size: 13px; }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chips span {
  background: var(--soft);
  border: 1px solid #dce4ec;
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 720;
  color: #4c5c6c;
}

.side-panel {
  padding: 18px;
  display: grid;
  gap: 13px;
}

.detail-list {
  display: grid;
  gap: 9px;
  color: #3f4d5c;
  font-size: 13px;
  line-height: 1.4;
}

.detail-list div {
  padding-bottom: 9px;
  border-bottom: 1px solid #eef2f5;
}

.notice {
  border: 1px solid #ecd7ae;
  background: #fff8eb;
  border-radius: 8px;
  color: #61420d;
  padding: 12px;
  font-size: 13px;
  line-height: 1.45;
}

.dropzone {
  margin: 18px;
  min-height: 430px;
  border: 2px dashed #b8c5d3;
  border-radius: 8px;
  background: #fbfcfd;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 28px;
  color: var(--muted);
}

.dropzone input { display: none; }
.dropzone strong { display: block; color: var(--ink); font-size: 20px; margin: 8px 0 6px; }

.upload-confirmation {
  margin: 0 18px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfd;
  padding: 12px;
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.upload-confirmation[hidden] {
  display: none;
}

.upload-confirmation img {
  width: 74px;
  height: 74px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #cbd7e2;
  background: white;
}

.upload-confirmation strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
}

.upload-confirmation span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.upload-icon {
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background: #e8f2fb;
  border: 1px solid #c8def0;
  display: inline-block;
  position: relative;
}

.upload-icon::before {
  content: "";
  position: absolute;
  left: 31px;
  top: 30px;
  width: 18px;
  height: 18px;
  border-top: 4px solid var(--blue);
  border-left: 4px solid var(--blue);
  transform: rotate(45deg);
}

.upload-icon::after {
  content: "";
  position: absolute;
  left: 39px;
  top: 31px;
  width: 4px;
  height: 30px;
  border-radius: 2px;
  background: var(--blue);
}

.status {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 9px;
  color: #455464;
  font-size: 13px;
  line-height: 1.35;
}

.status span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 4px;
}

.status.good span { background: var(--teal); }
.status.warn span { background: var(--amber); }
.status.bad span { background: var(--red); }

.editor-panel { grid-column: 1 / 2; }
.head-actions { display: flex; gap: 10px; }
.editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
  min-height: 640px;
}

.canvas-wrap {
  background: #e7edf3;
  display: grid;
  place-items: center;
  padding: 28px;
  position: relative;
}

#previewCanvas {
  width: min(420px, 88%);
  height: auto;
  background: white;
  border: 3px solid #1b6cae;
  box-shadow: 0 18px 38px rgba(23, 32, 43, .18);
}

.guide-overlay {
  position: absolute;
  width: min(420px, 88%);
  aspect-ratio: var(--photo-ratio, 0.6875);
  pointer-events: none;
  border: 2px solid rgba(27,108,174,.75);
}

.guide { position: absolute; }
.final-crop-label {
  left: 8px;
  top: 8px;
  background: rgba(27,108,174,.9);
  color: white;
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 11px;
  font-weight: 760;
}
.center-x { top: 0; bottom: 0; left: 50%; border-left: 1px dashed rgba(27,108,174,.9); }
.eye-line { left: 0; right: 0; top: var(--eye-line, 42%); border-top: 1px dashed rgba(19,122,103,.95); }
.head-height-ruler {
  left: calc(var(--head-min-left, 27.3%) - 5%);
  top: var(--top-min, 6.25%);
  height: calc(var(--chin-target-bottom, 79.16%) - var(--top-min, 6.25%));
  border-left: 2px solid rgba(184,59,52,.9);
}
.head-height-ruler::before,
.head-height-ruler::after {
  content: "";
  position: absolute;
  left: -7px;
  width: 14px;
  border-top: 2px solid rgba(184,59,52,.9);
}
.head-height-ruler::before { top: 0; }
.head-height-ruler::after { bottom: 0; }
.head-width-min {
  top: var(--head-top, 6.25%);
  bottom: calc(100% - var(--chin-target-bottom, 79.16%));
  left: var(--head-min-left, 27.3%);
  width: var(--head-min-width, 45.4%);
  border-left: 1px dashed rgba(184,59,52,.75);
  border-right: 1px dashed rgba(184,59,52,.75);
}
.head-width-max {
  top: var(--head-top, 6.25%);
  bottom: calc(100% - var(--chin-target-bottom, 79.16%));
  left: var(--head-max-left, 16.7%);
  width: var(--head-max-width, 66.6%);
  border-left: 1px solid rgba(184,59,52,.75);
  border-right: 1px solid rgba(184,59,52,.75);
}
.top-min { left: 0; right: 0; top: var(--top-min, 6.25%); border-top: 1px solid rgba(174,104,12,.9); }
.top-max { left: 0; right: 0; top: var(--top-max, 10.4%); border-top: 1px dashed rgba(174,104,12,.8); }
.chin-target-top { left: 0; right: 0; top: var(--chin-target-top, 64.6%); border-top: 1px dashed rgba(19,122,103,.85); }
.chin-target-bottom { left: 0; right: 0; top: var(--chin-target-bottom, 79.2%); border-top: 1px solid rgba(19,122,103,.95); }
.clearance-line { left: 0; right: 0; top: var(--clearance-line, 85.4%); border-top: 1px solid rgba(174,104,12,.95); }
.label {
  right: 8px;
  background: rgba(255,255,255,.82);
  border: 1px solid rgba(141,160,178,.55);
  border-radius: 6px;
  padding: 4px 6px;
  color: #445261;
  font-size: 11px;
}
.top-label { top: calc(var(--top-min, 6.25%) + 4px); }
.eye-label { top: calc(var(--eye-line, 42%) + 4px); left: 8px; right: auto; }
.head-label { top: calc(var(--top-min, 6.25%) + 34px); left: calc(var(--head-min-left, 27.3%) - 4%); right: auto; }
.width-label { top: calc(var(--chin-target-bottom, 79.2%) - 28px); left: calc(var(--head-max-left, 16.7%) + 4px); right: auto; }
.chin-target-label { top: calc(var(--chin-target-top, 64.6%) + 4px); }
.clearance-label { top: calc(var(--clearance-line, 85.4%) + 4px); }

.controls {
  border-left: 1px solid var(--line);
  padding: 16px;
  display: grid;
  gap: 13px;
  align-content: start;
}

.fit-score {
  border: 1px solid #c8e5dc;
  background: #eef8f5;
  border-radius: 8px;
  padding: 13px;
}

.fit-score strong { display: block; color: #126a57; font-size: 22px; margin-bottom: 4px; }
.fit-score span { color: #315d55; font-size: 12px; line-height: 1.35; }
.controls label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

.controls input[type="range"] { width: 100%; accent-color: var(--blue); }

.control-group {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  display: grid;
  gap: 4px;
}

.control-group strong {
  font-size: 13px;
  color: var(--ink);
}

.control-group p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-transform: none;
  font-weight: 500;
}

.export-grid {
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 18px;
  align-items: start;
}

#sheetCanvas {
  width: 100%;
  max-width: 620px;
  height: auto;
  display: block;
  margin: 0 auto;
  background: white;
  border: 1px solid #91a2b3;
  box-shadow: 0 18px 38px rgba(23, 32, 43, .16);
}

.download-card {
  display: grid;
  gap: 10px;
}

@media (max-width: 980px) {
  .header { align-items: flex-start; flex-direction: column; padding: 14px 16px; }
  .header-actions { width: 100%; }
  .header-actions .button { flex: 1; }
  main { padding: 20px 16px 32px; }
  .intro { display: grid; }
  .trust { justify-content: flex-start; }
  .steps, .screen, .screen.active, .template-grid, .editor, .export-grid {
    grid-template-columns: 1fr;
  }
  .controls { border-left: 0; border-top: 1px solid var(--line); }
}
