:root {
  color-scheme: light;
  --paper: #f4f1e9;
  --surface: #fffcf5;
  --surface-soft: #e9ebe3;
  --ink: #252720;
  --muted: #6f7169;
  --line: #d9d5ca;
  --moss: #435343;
  --moss-dark: #2f3c31;
  --clay: #b66f4c;
  --clay-soft: #efd8c9;
  --focus: #1769aa;
  --danger: #9a3f34;
  --radius: 22px;
  --shadow: 0 24px 60px rgb(43 48 38 / 8%);
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--paper); color: var(--ink); }
button, input, select { font: inherit; }
button, select, input[type="range"], summary, .drop-zone { touch-action: manipulation; }
a { color: inherit; text-decoration: none; }
button { color: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 72%, transparent); outline-offset: 3px; }
[hidden] { display: none !important; }

.skip-link { position: fixed; inset-block-start: 10px; inset-inline-start: 10px; z-index: 100; translate: 0 -150%; padding: 10px 14px; border-radius: 8px; background: var(--ink); color: white; }
.skip-link:focus { translate: 0; }

.site-header { width: min(1440px, calc(100% - 32px)); min-height: 82px; margin: auto; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-block-end: 1px solid var(--line); }
.site-brand { display: flex; align-items: center; gap: 11px; flex: none; }
.site-mark { display: grid; width: 37px; aspect-ratio: 1; place-items: center; border: 1px solid var(--ink); font-family: ui-serif, "Noto Serif TC", serif; font-size: 19px; }
.site-brand strong, .site-brand small { display: block; }
.site-brand strong { font-family: ui-serif, "Noto Serif TC", serif; font-size: 16px; }
.site-brand small { margin-block-start: 3px; color: var(--muted); font-size: 10px; }
.site-nav { display: flex; gap: clamp(14px, 2vw, 28px); color: var(--muted); font-size: 13px; white-space: nowrap; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--ink); }

.tool-hero { width: min(1440px, calc(100% - 32px)); margin: auto; padding-block: clamp(52px, 8vw, 110px) clamp(38px, 6vw, 76px); display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr); gap: clamp(36px, 8vw, 130px); align-items: end; }
.eyebrow, .step-label { margin: 0; color: var(--clay); font-size: 10px; font-weight: 750; letter-spacing: .16em; text-transform: uppercase; }
.tool-hero h1 { margin: 15px 0 22px; max-width: 850px; font-family: ui-serif, "Noto Serif TC", serif; font-size: clamp(44px, 6.8vw, 92px); font-weight: 550; letter-spacing: -.055em; line-height: 1.08; }
.tool-hero h1 em { color: var(--clay); font-style: normal; }
.hero-copy { max-width: 650px; margin: 0; color: var(--muted); font-size: clamp(14px, 1.5vw, 17px); line-height: 1.9; }
.privacy-card { display: flex; gap: 14px; padding: 22px; border: 1px solid #cbd1c5; border-radius: 16px; background: var(--surface-soft); }
.privacy-dot { width: 10px; height: 10px; flex: none; margin-block-start: 5px; border-radius: 50%; background: #56815b; box-shadow: 0 0 0 5px rgb(86 129 91 / 13%); }
.privacy-card strong { font-size: 13px; }
.privacy-card p { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.7; }

.studio { width: min(1500px, calc(100% - 24px)); margin: auto; display: grid; grid-template-columns: 350px minmax(0, 1fr); align-items: start; gap: 14px; }
.control-panel, .canvas-card, .preview-card, .results-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.control-panel { position: sticky; inset-block-start: 12px; padding: 26px; }
.panel-intro h2, .card-header h2, .results-header h2 { margin: 7px 0 0; font-family: ui-serif, "Noto Serif TC", serif; font-weight: 600; }
.panel-intro h2 { font-size: 25px; }

.drop-zone { min-height: 154px; margin-block: 22px 10px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 7px; border: 1px dashed #aeb5a8; border-radius: 16px; background: #f3f2ea; cursor: pointer; text-align: center; transition: border-color .18s ease, background .18s ease, transform .18s ease; }
.drop-zone:hover, .drop-zone.is-dragging { border-color: var(--moss); background: #e9ede4; transform: translateY(-1px); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.upload-mark { display: grid; width: 34px; aspect-ratio: 1; place-items: center; border-radius: 50%; background: var(--moss); color: white; font-size: 22px; font-weight: 300; }
.drop-zone strong { font-size: 13px; }
.drop-zone small { color: var(--muted); font-size: 11px; }
.source-list { display: grid; gap: 6px; }
.source-item { min-width: 0; display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: white; }
.source-select { min-width: 0; padding: 0; border: 0; background: transparent; text-align: start; cursor: pointer; }
.source-select strong, .source-select small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-select strong { font-size: 11px; }
.source-select small { margin-block-start: 2px; color: var(--muted); font-size: 9px; }
.source-item[aria-current="true"] { border-color: var(--moss); background: var(--surface-soft); }
.source-remove { width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.source-remove:hover { background: var(--clay-soft); color: var(--danger); }

.control-group { min-width: 0; margin: 24px 0 0; padding: 22px 0 0; border: 0; border-block-start: 1px solid var(--line); }
.control-group legend { padding: 0 8px 0 0; font-size: 12px; font-weight: 750; }
.control-group legend span { margin-inline-end: 8px; color: var(--clay); font-size: 10px; }
.segment-control { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-block-start: 14px; padding: 4px; border-radius: 12px; background: #ebe8df; }
.segment-control button { min-height: 40px; padding: 5px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 11px; cursor: pointer; }
.segment-control button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 3px 12px rgb(50 46 38 / 10%); }
.select-label { display: block; margin: 14px 0 7px; color: var(--muted); font-size: 10px; }
select, input[type="number"] { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: white; padding-inline: 12px; color: var(--ink); }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-block-start: 9px; }
.field-pair label { color: var(--muted); font-size: 10px; }
.field-pair input { display: block; margin-block-start: 5px; }
.format-note { margin: 9px 0 0; color: var(--muted); font-size: 10px; line-height: 1.6; }

.finish-controls { display: grid; gap: 16px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; cursor: pointer; }
.toggle-row span strong, .toggle-row span small { display: block; }
.toggle-row span strong { font-size: 12px; }
.toggle-row span small { margin-block-start: 3px; color: var(--muted); font-size: 9px; }
.toggle-row input { position: absolute; opacity: 0; }
.toggle-row i { position: relative; width: 42px; height: 24px; flex: none; border-radius: 99px; background: #c9c8c0; transition: background .18s ease; }
.toggle-row i::after { content: ""; position: absolute; inset-block-start: 3px; inset-inline-start: 3px; width: 18px; aspect-ratio: 1; border-radius: 50%; background: white; box-shadow: 0 2px 5px rgb(0 0 0 / 18%); transition: translate .18s ease; }
.toggle-row input:checked + i { background: var(--moss); }
.toggle-row input:checked + i::after { translate: 18px 0; }
.toggle-row input:focus-visible + i { outline: 3px solid color-mix(in srgb, var(--focus) 72%, transparent); outline-offset: 3px; }
.range-row { display: grid; gap: 7px; }
.range-row span { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.range-row output { color: var(--ink); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--moss); }

.primary-action, .download-all { min-height: 52px; border: 0; border-radius: 13px; background: var(--moss); color: white; font-weight: 700; cursor: pointer; }
.primary-action { width: 100%; margin-block-start: 25px; display: flex; align-items: center; justify-content: space-between; padding-inline: 18px; }
.primary-action:hover:not(:disabled), .download-all:hover { background: var(--moss-dark); }
.primary-action:disabled { cursor: not-allowed; opacity: .42; }
.progress-wrap { margin-block-start: 18px; }
.progress-copy { display: flex; justify-content: space-between; margin-block-end: 7px; color: var(--muted); font-size: 10px; }
progress { width: 100%; height: 6px; border: 0; border-radius: 99px; overflow: hidden; background: #ddd9cf; }
progress::-webkit-progress-bar { background: #ddd9cf; }
progress::-webkit-progress-value { background: var(--clay); }
progress::-moz-progress-bar { background: var(--clay); }
.app-status { margin: 12px 0 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.app-status.is-error { color: var(--danger); }

.workbench { min-width: 0; display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(270px, .55fr); gap: 14px; }
.canvas-card, .preview-card { padding: clamp(18px, 2.3vw, 30px); }
.card-header, .results-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.card-header h2 { font-size: clamp(22px, 3vw, 30px); }
.card-header output { color: var(--muted); font-size: 10px; }
.quiet-button { min-height: 40px; padding-inline: 14px; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--muted); font-size: 11px; cursor: pointer; }
.quiet-button:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }
.quiet-button:disabled { opacity: .35; cursor: not-allowed; }
.canvas-help { margin: 12px 0 16px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.canvas-stage { position: relative; min-height: 460px; border-radius: 15px; overflow: hidden; background: #d9d7cf; background-image: linear-gradient(45deg,#cac8c0 25%,transparent 25%),linear-gradient(-45deg,#cac8c0 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#cac8c0 75%),linear-gradient(-45deg,transparent 75%,#cac8c0 75%); background-position: 0 0,0 9px,9px -9px,-9px 0; background-size: 18px 18px; }
#grid-canvas { display: block; width: 100%; height: clamp(460px, 58vh, 700px); cursor: crosshair; }
#grid-canvas.is-dragging { cursor: grabbing; }
.canvas-empty, .preview-empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 7px; color: var(--muted); text-align: center; pointer-events: none; }
.canvas-empty span { display: grid; width: 45px; aspect-ratio: 1; place-items: center; border: 1px solid var(--muted); font-size: 22px; }
.canvas-empty strong { color: var(--ink); font-family: ui-serif, "Noto Serif TC", serif; }
.canvas-empty small { font-size: 10px; }
.precision-panel { margin-block-start: 14px; border: 1px solid var(--line); border-radius: 12px; background: #f3f1e9; }
.precision-panel summary { padding: 13px 15px; cursor: pointer; color: var(--muted); font-size: 11px; }
.precision-fields { display: grid; grid-template-columns: minmax(150px, .7fr) minmax(180px, 1.3fr); gap: 12px; padding: 0 14px 14px; }
.precision-fields label { color: var(--muted); font-size: 10px; }
.precision-fields select, .precision-fields input { display: block; margin-block-start: 5px; }
.precision-fields output { float: right; color: var(--ink); }

.preview-card { align-self: start; }
.preview-stage { position: relative; min-height: 320px; margin-block-start: 22px; display: grid; place-items: center; border-radius: 15px; overflow: hidden; background-color: #e9e7e0; background-image: linear-gradient(45deg,#d7d4cb 25%,transparent 25%),linear-gradient(-45deg,#d7d4cb 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#d7d4cb 75%),linear-gradient(-45deg,transparent 75%,#d7d4cb 75%); background-position: 0 0,0 10px,10px -10px,-10px 0; background-size: 20px 20px; }
#live-preview { display: block; max-width: calc(100% - 30px); max-height: 360px; object-fit: contain; filter: drop-shadow(0 10px 16px rgb(31 32 28 / 12%)); }
.preview-empty { padding: 20px; font-family: ui-serif, "Noto Serif TC", serif; font-size: 15px; line-height: 1.7; }
.preview-note { margin: 13px 2px 0; color: var(--muted); font-size: 10px; line-height: 1.65; }

.results-card { grid-column: 1 / -1; padding: clamp(20px, 3vw, 34px); }
.results-header h2 { font-size: clamp(28px, 4vw, 42px); }
.results-header p:not(.step-label) { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.download-all { padding-inline: 20px; }
.result-grid { margin-block-start: 25px; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.result-item { min-width: 0; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: #f2f0e8; }
.result-image { aspect-ratio: 370 / 320; display: grid; place-items: center; overflow: hidden; border-radius: 9px; background-color: white; background-image: linear-gradient(45deg,#eceae3 25%,transparent 25%),linear-gradient(-45deg,#eceae3 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#eceae3 75%),linear-gradient(-45deg,transparent 75%,#eceae3 75%); background-position: 0 0,0 6px,6px -6px,-6px 0; background-size: 12px 12px; }
.result-image img { width: 100%; height: 100%; object-fit: contain; }
.result-meta { min-width: 0; margin-block-start: 10px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; }
.result-meta span { min-width: 0; }
.result-meta strong, .result-meta small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-meta strong { font-size: 10px; }
.result-meta small { margin-block-start: 2px; color: var(--muted); font-size: 8px; }
.single-download { display: grid; width: 34px; aspect-ratio: 1; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--moss); font-size: 15px; }
.single-download:hover { background: var(--moss); color: white; }

.guide-section, .seo-section { width: min(1120px, calc(100% - 40px)); margin: clamp(90px, 12vw, 160px) auto 0; }
.guide-intro { max-width: 680px; }
.guide-intro h2, .seo-section h2 { margin: 12px 0 0; font-family: ui-serif, "Noto Serif TC", serif; font-size: clamp(32px, 5vw, 58px); font-weight: 550; letter-spacing: -.04em; line-height: 1.25; }
.guide-steps { margin: 45px 0 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); border-block: 1px solid var(--line); }
.guide-steps li { min-width: 0; display: flex; gap: 20px; padding: 30px 25px; }
.guide-steps li + li { border-inline-start: 1px solid var(--line); }
.guide-steps li > span { color: var(--clay); font-size: 10px; font-weight: 750; }
.guide-steps h3 { margin: 0 0 10px; font-family: ui-serif, "Noto Serif TC", serif; font-size: 20px; }
.guide-steps p, .seo-section p, .faq-list p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.9; }
.seo-section { display: grid; grid-template-columns: minmax(0, .9fr) minmax(300px, 1.1fr); gap: clamp(45px, 9vw, 120px); align-items: start; }
.seo-section h2 { margin-block-end: 24px; font-size: clamp(30px, 4.5vw, 50px); }
.seo-section > div:first-child > p + p { margin-block-start: 15px; }
.faq-list { border-block-start: 1px solid var(--line); }
.faq-list details { border-block-end: 1px solid var(--line); }
.faq-list summary { padding-block: 20px; font-family: ui-serif, "Noto Serif TC", serif; font-size: 17px; cursor: pointer; }
.faq-list p { padding-block-end: 20px; }

.site-footer { margin-block-start: clamp(90px, 12vw, 160px); padding: 48px max(20px, calc((100vw - 1120px) / 2)) 24px; background: #292a25; color: #eee; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 20px; color: #c1c1b9; font-size: 12px; }
.site-footer a:hover { color: white; }
.site-footer p { color: #aaa; font-size: 11px; }
.site-footer small { display: block; margin-block-start: 28px; padding-block-start: 16px; border-block-start: 1px solid #4b4b44; color: #888; font-size: 10px; }

@media (max-width: 1100px) {
  .studio { grid-template-columns: 310px minmax(0, 1fr); }
  .workbench { grid-template-columns: 1fr; }
  .results-card { grid-column: auto; }
  .preview-stage { min-height: 280px; }
}

@media (max-width: 820px) {
  .site-header { align-items: flex-start; flex-direction: column; padding-block: 16px; }
  .site-nav { width: 100%; padding-block: 4px; overflow-x: auto; }
  .tool-hero { grid-template-columns: 1fr; }
  .privacy-card { max-width: 520px; }
  .studio { grid-template-columns: 1fr; }
  .control-panel { position: static; }
  .guide-steps { grid-template-columns: 1fr; }
  .guide-steps li + li { border-inline-start: 0; border-block-start: 1px solid var(--line); }
  .seo-section { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .site-header, .tool-hero { width: min(100% - 24px, 1440px); }
  .site-brand small { max-width: 210px; white-space: normal; }
  .tool-hero h1 { font-size: clamp(39px, 13vw, 56px); }
  .studio { width: calc(100% - 12px); }
  .control-panel, .canvas-card, .preview-card, .results-card { border-radius: 17px; }
  .control-panel { padding: 20px; }
  .workbench { gap: 8px; }
  .canvas-stage { min-height: 390px; }
  #grid-canvas { height: 390px; }
  .precision-fields { grid-template-columns: 1fr; }
  .results-header { align-items: flex-start; flex-direction: column; }
  .download-all { width: 100%; }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .guide-section, .seo-section { width: calc(100% - 32px); }
  .guide-steps li { padding-inline: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --paper: #20221e; --surface: #292b26; --surface-soft: #343a32; --ink: #f2eee3; --muted: #b6b7ae; --line: #464940; --moss: #78957b; --moss-dark: #68836c; --clay: #d39270; --clay-soft: #513b32; --shadow: 0 24px 60px rgb(0 0 0 / 15%); }
  .drop-zone, .precision-panel, .result-item { background: #252822; }
  select, input[type="number"], .source-item { background: #2c2f29; }
  .segment-control { background: #20221e; }
  .segment-control button[aria-pressed="true"] { background: #3a3d36; }
  .preview-stage, .canvas-stage { filter: brightness(.85); }
}
