:root {
  --paper: #f8f7f2;
  --surface: #ffffff;
  --ink: #1c2420;
  --muted: #7d8781;
  --line: #e6e9e3;
  --soft: #f1f3ed;
  --accent: #2f795b;
  --accent-dark: #20553e;
  --accent-soft: #e2f0e6;
  --warm: #f3e8d3;
  --shadow: 0 20px 50px rgba(41, 54, 45, 0.08);
  --radius-lg: 24px;
  --radius-md: 16px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 4% 0%, rgba(226, 240, 230, 0.72), transparent 28rem),
    var(--paper);
}

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

.app-shell { min-height: 100vh; overflow: hidden; }

.topbar {
  width: min(1180px, calc(100% - 40px));
  height: 76px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  gap: 11px;
  align-items: center;
  color: var(--ink);
  text-decoration: none;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 30px;
  height: 30px;
  padding: 5px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  border-radius: 10px;
  background: var(--accent);
  transform: rotate(-7deg);
  box-shadow: 4px 5px 0 rgba(32, 85, 62, 0.12);
}

.brand-mark i { display: block; border-radius: 3px; background: #d7eddf; }
.brand-mark i:nth-child(2) { background: #f4c576; }
.brand-mark i:nth-child(3) { background: #e98b75; }
.brand-mark i:nth-child(4) { background: #fff4d9; }

.prototype-badge {
  padding: 7px 11px;
  border: 1px solid #d9e7dc;
  border-radius: 999px;
  color: var(--accent);
  background: rgba(255, 255, 255, 0.62);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.page-wrap { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }

.hero { max-width: 660px; padding: 66px 0 54px; }

.eyebrow, .section-kicker {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.eyebrow { display: flex; gap: 8px; align-items: center; }
.eyebrow-dot { width: 7px; height: 7px; border-radius: 50%; background: #e78b55; box-shadow: 0 0 0 5px rgba(231, 139, 85, 0.13); }

.hero h1 {
  margin: 20px 0 15px;
  font-size: clamp(40px, 6vw, 68px);
  line-height: 1.05;
  letter-spacing: -0.07em;
  font-weight: 850;
}

.hero h1 em { color: var(--accent); font-style: normal; }
.hero p { max-width: 480px; margin: 0; color: var(--muted); font-size: 15px; line-height: 1.8; }

.workspace { display: grid; grid-template-columns: minmax(330px, 0.8fr) minmax(500px, 1.2fr); gap: 22px; align-items: start; }

.panel { border: 1px solid rgba(218, 224, 216, 0.86); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }
.setup-panel { padding: 27px; }
.result-panel { min-width: 0; padding: 27px; }

.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.panel-heading h2, .legend-heading h3 { margin: 8px 0 0; font-size: 21px; line-height: 1.2; letter-spacing: -0.04em; }
.panel-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; color: var(--accent); background: var(--accent-soft); font-size: 16px; }

.dropzone {
  min-height: 240px;
  margin-top: 23px;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border: 1.5px dashed #c7d6cb;
  border-radius: var(--radius-md);
  color: var(--ink);
  background: linear-gradient(135deg, #fafcf8, #f1f7f1);
  text-align: center;
  transition: 180ms ease;
}

.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: #edf7f0; transform: translateY(-2px); }
.dropzone input { display: none; }
.upload-visual { width: 54px; height: 54px; display: grid; place-items: center; margin-bottom: 16px; border-radius: 17px; color: var(--accent); background: var(--surface); box-shadow: 0 8px 20px rgba(39, 91, 64, 0.1); }
.upload-arrow { font-size: 26px; font-weight: 300; transform: translateY(-2px); }
.dropzone strong { font-size: 15px; }
.dropzone > span { margin-top: 6px; color: var(--muted); font-size: 11px; }
.dropzone .upload-file { max-width: 100%; overflow: hidden; color: var(--accent); font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }

.sample-row { display: flex; align-items: center; justify-content: space-between; margin: 13px 2px 0; }
.text-button { padding: 0; border: 0; color: var(--accent); background: none; font-size: 12px; font-weight: 800; }
.privacy-note { color: var(--muted); font-size: 11px; }
.privacy-note span { color: var(--accent); font-size: 9px; }

.source-preview { display: flex; align-items: center; gap: 12px; margin-top: 18px; padding: 10px; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfa; }
.source-preview[hidden] { display: none; }
.source-preview img { width: 48px; height: 48px; object-fit: cover; border-radius: 9px; }
.source-preview strong { display: block; margin-top: 5px; font-size: 12px; }
.small-label { color: var(--muted); font-size: 10px; }

.divider { height: 1px; margin: 26px 0; background: var(--line); }
.compact-heading { margin-bottom: 19px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-label { color: var(--muted); font-size: 11px; font-weight: 700; }
.field-label span { display: block; margin: 0 0 7px 2px; }
.field-label select { width: 100%; padding: 12px 10px; border: 1px solid var(--line); border-radius: 11px; color: var(--ink); outline: none; background: #fbfcfa; font-size: 12px; }
.field-label select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 121, 91, 0.1); }
.setting-tip { margin: 13px 2px 20px; color: var(--muted); font-size: 11px; line-height: 1.6; }

.primary-button, .secondary-button { border: 0; border-radius: 12px; font-weight: 800; transition: 180ms ease; }
.primary-button { width: 100%; padding: 15px 16px; display: flex; align-items: center; justify-content: space-between; color: white; background: var(--accent); box-shadow: 0 10px 20px rgba(47, 121, 91, 0.2); }
.primary-button:hover { background: var(--accent-dark); transform: translateY(-1px); }
.button-arrow { font-size: 21px; font-weight: 400; }

.result-heading { align-items: center; }
.result-status { display: inline-flex; align-items: center; gap: 7px; color: var(--accent); font-size: 11px; font-weight: 800; }
.result-status i { width: 7px; height: 7px; border-radius: 50%; background: #61bd78; box-shadow: 0 0 0 4px rgba(97, 189, 120, 0.12); }
.result-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin: 25px 0 14px; }
.result-summary span { display: block; font-size: 14px; font-weight: 800; }
.result-summary small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.toolbar-actions { display: flex; gap: 7px; }
.toolbar-download-button { width: auto; padding: 10px 13px; gap: 9px; font-size: 11px; }
.icon-button { padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; color: var(--accent); background: var(--surface); font-size: 15px; font-weight: 700; }
.icon-button span { margin-left: 3px; font-size: 10px; }
.icon-button:hover { border-color: var(--accent); background: var(--accent-soft); }

.canvas-frame { position: relative; overflow: auto; max-height: 620px; padding: 12px; border: 1px solid #dfe5dd; border-radius: 15px; background: #f5f5ef; }
.canvas-frame { touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; }
#gridCanvas { display: block; width: 100%; height: auto; min-width: 380px; image-rendering: pixelated; }
.canvas-tools { display: flex; align-items: center; gap: 11px; margin-top: 9px; }
.canvas-tools .primary-button { width: auto; flex: 0 0 auto; padding: 10px 13px; font-size: 11px; }
.canvas-tools .canvas-tip { margin: 0; }
.canvas-tip { margin: 9px 3px 0; color: var(--muted); font-size: 10px; }

.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 17px; }
.stat-card { padding: 13px 12px; border-radius: 12px; background: var(--soft); }
.stat-card span { display: block; color: var(--muted); font-size: 10px; }
.stat-card strong { display: block; margin-top: 6px; font-size: 18px; letter-spacing: -0.04em; }

.legend-heading { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 28px; }
.legend-heading h3 { font-size: 17px; }
.legend-total { color: var(--muted); font-size: 11px; }
.legend-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 15px; }
.legend-item { min-width: 0; display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 10px; }
.legend-swatch { width: 22px; height: 22px; border: 1px solid rgba(0, 0, 0, 0.11); border-radius: 6px; }
.legend-code { overflow: hidden; color: var(--ink); font-size: 10px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.legend-count { margin-top: 3px; color: var(--muted); font-size: 10px; }

.result-footer-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 19px; padding-top: 17px; border-top: 1px solid var(--line); }
.secondary-button { padding: 11px 13px; color: var(--accent-dark); background: var(--accent-soft); font-size: 11px; white-space: nowrap; }
.secondary-button:hover { background: #d3e9da; }
.result-footer-actions > span { color: var(--muted); font-size: 10px; line-height: 1.4; text-align: right; }

.save-sheet[hidden] { display: none; }
.save-sheet { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 18px; }
.zoom-sheet[hidden] { display: none; }
.zoom-sheet { position: fixed; inset: 0; z-index: 21; display: grid; place-items: center; padding: 18px; }
.save-backdrop { position: absolute; inset: 0; background: rgba(22, 32, 27, 0.52); backdrop-filter: blur(5px); }
.save-dialog { position: relative; width: min(620px, 100%); max-height: calc(100vh - 36px); overflow: auto; padding: 25px; border: 1px solid rgba(255,255,255,0.7); border-radius: 22px; background: var(--surface); box-shadow: 0 24px 70px rgba(0,0,0,0.25); }
.save-dialog h2 { margin: 8px 0 7px; font-size: 24px; letter-spacing: -0.05em; }
.save-dialog > p { margin: 0 0 16px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.save-close { position: absolute; top: 16px; right: 17px; width: 32px; height: 32px; border: 0; border-radius: 50%; color: var(--muted); background: var(--soft); font-size: 24px; line-height: 1; }
.save-close:hover { color: var(--ink); background: var(--accent-soft); }
.save-image-frame { max-height: min(57vh, 520px); overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: 14px; background: #f5f5ef; text-align: center; }
.save-image-frame img { display: block; width: 100%; height: auto; image-rendering: pixelated; }
.save-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; margin-top: 16px; }
.save-link { display: flex; align-items: center; justify-content: space-between; text-decoration: none; }
.view-link { display: flex; align-items: center; justify-content: center; text-decoration: none; }
.save-status { min-height: 17px; margin: 11px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.zoom-controls { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.zoom-controls .field-label { min-width: 150px; }
.zoom-info { padding-bottom: 12px; color: var(--muted); font-size: 11px; text-align: right; }
.zoom-image-frame { overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: 14px; background: #f5f5ef; text-align: center; }
#zoomCanvas { display: inline-block; max-width: 100%; height: auto; image-rendering: pixelated; }
.zoom-actions .primary-button { width: auto; }
body.modal-open { overflow: hidden; }

.print-sheet { display: none; }

.how-it-works { display: flex; align-items: flex-start; justify-content: space-between; gap: 34px; padding: 100px 0 88px; }
.how-it-works h2 { max-width: 230px; margin: 10px 0 0; font-size: 28px; line-height: 1.15; letter-spacing: -0.06em; }
.steps-grid { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.step-card { min-height: 145px; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255, 255, 255, 0.55); }
.step-card > span { color: #d0d9d0; font-size: 26px; font-weight: 850; letter-spacing: -0.08em; }
.step-card strong { display: block; margin-top: 12px; font-size: 14px; }
.step-card p { margin: 6px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.site-footer { padding: 22px 20px 30px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; text-align: center; }

@media (max-width: 880px) {
  .workspace { grid-template-columns: 1fr; }
  .setup-panel { display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; }
  .setup-panel > .panel-heading, .setup-panel > .divider, .setup-panel > .compact-heading, .setup-panel > .settings-grid, .setup-panel > .setting-tip, .setup-panel > .primary-button { grid-column: 1 / -1; }
  .dropzone { margin-top: 23px; }
  .sample-row { margin-bottom: 0; }
  .source-preview { margin-top: 13px; }
}

@media (max-width: 620px) {
  .topbar, .page-wrap { width: min(100% - 28px, 1180px); }
  .topbar { height: 66px; }
  .hero { padding: 43px 0 36px; }
  .hero h1 { font-size: 42px; }
  .hero p { font-size: 14px; }
  .setup-panel, .result-panel { padding: 20px; border-radius: 20px; }
  .setup-panel { display: block; }
  .setup-panel .dropzone { margin-top: 20px; }
  .divider { margin: 23px 0; }
  .result-toolbar { align-items: flex-end; }
  .toolbar-actions { gap: 5px; }
  .icon-button { padding: 8px; }
  .icon-button span { display: none; }
  .canvas-frame { max-height: 510px; padding: 8px; }
  #gridCanvas { min-width: 470px; }
  .settings-grid { grid-template-columns: 1fr; gap: 12px; }
  .canvas-tools { align-items: flex-start; }
  .legend-list { grid-template-columns: repeat(2, 1fr); }
  .result-footer-actions { align-items: flex-start; flex-direction: column; }
  .result-footer-actions > span { text-align: left; }
  .save-dialog { padding: 20px; border-radius: 19px; }
  .save-actions { grid-template-columns: 1fr; }
  .zoom-controls { align-items: stretch; flex-direction: column; gap: 8px; }
  .zoom-controls .field-label { min-width: 0; }
  .zoom-info { padding: 0; text-align: left; }
  .how-it-works { display: block; padding: 68px 0 58px; }
  .how-it-works h2 { max-width: none; font-size: 25px; }
  .steps-grid { grid-template-columns: 1fr; margin-top: 22px; }
  .step-card { min-height: 0; }
}

@media print {
  @page { size: A4 portrait; margin: 10mm; }
  body { background: white; }
  body.printing-pages .app-shell { display: none !important; }
  body.printing-pages .print-sheet { display: block !important; }
  .print-page { width: 100%; min-height: 277mm; break-after: page; page-break-after: always; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 7mm; border-bottom: 1px solid #cfd8d0; padding-bottom: 4mm; }
  .print-page-heading h1 { margin: 0; color: #1c2420; font-size: 17pt; }
  .print-page-heading p { margin: 0; color: #66736a; font-size: 8pt; text-align: right; }
  .print-grid-canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; }
  .print-color-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3mm; align-content: start; }
  .print-color-item { display: flex; align-items: center; gap: 2mm; min-height: 8mm; border-bottom: 1px solid #e5e9e5; color: #1c2420; font-size: 8pt; }
  .print-color-item .legend-swatch { flex: 0 0 7mm; width: 7mm; height: 7mm; }
}
