:root {
  --paper: #f5f8f7;
  --glass: #dce9e5;
  --frame: #245b50;
  --ink: #243b36;
  --muted: #596e67;
  --border: #b7cbc3;
  --display: "Songti TC", "Hiragino Mincho ProN", "Noto Serif TC", "LiSong Pro", serif;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
  font-size: 16px;
  line-height: 1.65;
}
* { box-sizing: border-box; }
body { margin: 0; }
.page { max-width: 1280px; margin: auto; padding: 0 18px; }
header { min-height: 80px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--frame); text-decoration: none; font: 700 27px var(--display); white-space: nowrap; }
.brand-icon { font: 36px sans-serif; }
.brand-en { font: 13px "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", sans-serif; margin-left: 8px; color: var(--muted); }
.header-note { display: none; font-size: 13px; color: var(--muted); }
main { margin: 30px 0 40px; }
h1 { font: 500 clamp(32px, 4vw, 50px)/1.45 var(--display); letter-spacing: .04em; margin: 0 0 16px; }
.intro { margin: 0 0 12px; color: var(--muted); max-width: 48ch; }
.privacy { font-size: 13px; margin: 0 0 26px; color: var(--frame); }
.drop-zone { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; padding: 20px; background: var(--glass); border: 1px solid var(--border); border-radius: 4px 20px 4px 4px; }
.drop-zone.dragging { border: 2px solid var(--frame); background: #c9ded6; }
.upload-symbol { width: 40px; height: 40px; display: grid; place-items: center; font-size: 30px; color: var(--frame); border: 1px solid var(--frame); }
.drop-zone>div:nth-child(2) { flex: 1; min-width: 180px; }
.drop-zone h2 { font-size: 17px; margin: 0 0 4px; }
.drop-zone p { font-size: 13px; color: var(--muted); margin: 0; max-width: 55ch; }
.drop-zone button { width: 100%; }
button, input, select { font: inherit; }
button { cursor: pointer; min-height: 44px; padding: 10px 16px; border-radius: 5px; font-size: 14px; font-weight: 600; }
button, a { -webkit-tap-highlight-color: transparent; }
.primary { background: var(--frame); color: #fff; border: 1px solid var(--frame); }
.primary:hover { background: #19493f; }
.secondary { border: 1px solid var(--border); background: transparent; color: var(--frame); }
.secondary:hover { background: var(--glass); }
button:disabled { opacity: .45; cursor: default; }
:where(button, a, input, select, summary):focus-visible { outline: 3px solid var(--frame); outline-offset: 4px; }
#status { font-size: 13px; color: var(--muted); min-height: 22px; margin: 14px 0 20px; overflow-wrap: anywhere; }
#status.error { color: #a2343f; }
.workspace { display: grid; gap: 30px; align-items: start; }
.preview-card { min-width: 0; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-heading h2 { font: 600 20px var(--display); margin: 0; }
.preview-actions { display: flex; align-items: center; gap: 12px; }
.badge { font-size: 12px; color: var(--muted); white-space: nowrap; }
.preview-stage { display: flex; align-items: center; justify-content: center; min-height: 280px; overflow: hidden; background: #e6eeeb; border: 7px solid var(--frame); border-radius: 3px; box-shadow: inset 0 0 0 2px var(--paper), 7px 7px 0 var(--glass); }
#empty-preview { text-align: center; padding: 40px 14px; width: 100%; background: linear-gradient(115deg, #f5f8f7 12%, #e0ebe6 60%, #f5f8f7); }
#empty-preview h3 { font: 500 21px var(--display); margin: 24px 0 8px; }
#empty-preview p { font-size: 13px; color: var(--muted); margin: 0; }
.sample-lattice { width: 138px; height: 138px; margin: auto; display: grid; place-items: center; border: 3px solid var(--frame); background: repeating-linear-gradient(45deg, transparent 0 31px, #94b6a8 32px 34px, transparent 35px 65px), repeating-linear-gradient(135deg, transparent 0 31px, #94b6a8 32px 34px, transparent 35px 65px); }
.sample-lattice span { background: #e6eeeb; color: var(--frame); font: 22px var(--display); padding: 4px 8px; }
canvas { display: block; max-width: 100%; max-height: 560px; width: auto; height: auto; object-fit: contain; }
#preview { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.8; margin: 10px 0 0; }
.image-info { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; margin: 14px 0 8px; }
.quick-presets { margin: 16px 0 0; }
.quick-presets h3 { font-size: 13px; font-weight: 500; margin: 0 0 8px; color: var(--muted); }
#quick-presets { display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 8px; padding: 4px 4px 10px; margin: -4px; scrollbar-width: thin; }
#quick-presets button { flex: 0 0 auto; border-radius: 24px; padding: 8px 14px; font-size: 13px; background: var(--glass); border-color: transparent; }
#quick-presets button:hover { border-color: var(--frame); }
.thumbnails { list-style: none; padding: 6px 0; margin: 12px 0 18px; display: flex; gap: 12px; overflow-x: auto; }
.thumbnails:empty { display: none; }
.thumbnail { width: 88px; flex: 0 0 88px; position: relative; }
.thumb-select { display: block; width: 88px; height: 78px; padding: 3px; border: 2px solid transparent; background: var(--glass); }
.thumb-select[aria-pressed="true"] { border-color: var(--frame); }
.thumb-select img { width: 100%; height: 100%; object-fit: cover; }
.thumb-name { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 4px; }
.thumb-remove { position: absolute; top: 0; right: 0; min-height: 32px; width: 32px; padding: 0; border: 1px solid var(--border); background: var(--paper); color: var(--ink); border-radius: 50%; font-size: 20px; }
.export-area { border-top: 1px solid var(--border); margin-top: 20px; padding-top: 18px; }
.share-action .primary { width: 100%; min-height: 50px; font-size: 16px; }
.share-action .hint { margin: 7px 0 12px; }
.export-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.export-actions button { flex: 1; }
.usage { display: flex; flex-wrap: wrap; gap: 12px 28px; margin: 20px 0 4px; }
.usage>div { display: flex; align-items: baseline; gap: 10px; }
.usage dt { font-size: 12px; color: var(--muted); }
.usage dd { margin: 0; font-size: 18px; font-variant-numeric: tabular-nums; }
.usage-caption { font-size: 11px; color: var(--muted); margin: 0; max-width: 65ch; }
.settings { min-width: 0; background: #eaf0ed; border-radius: 16px 4px 4px 4px; padding: 20px; border-top: 3px solid var(--border); }
.text-button { border: 0; background: transparent; color: var(--frame); padding: 4px 8px; text-decoration: underline; text-underline-offset: 4px; }
.settings label, legend { font-size: 14px; font-weight: 600; }
.source { border: 0; padding: 0; margin: 0 0 22px; }
.source legend { margin-bottom: 8px; }
.mode-toggle { display: flex; border: 1px solid var(--border); border-radius: 5px; padding: 3px; gap: 4px; }
.mode-toggle label { flex: 1; position: relative; cursor: pointer; }
.mode-toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; }
.mode-toggle span { display: block; text-align: center; border-radius: 3px; min-height: 40px; padding: 8px; }
.mode-toggle input:checked+span { background: var(--paper); color: var(--frame); }
.mode-toggle input:focus-visible+span { outline: 3px solid var(--frame); }
input[type="text"], select { display: block; width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 4px; background: var(--paper); color: var(--ink); margin-top: 8px; }
.control { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 8px; margin-top: 22px; }
.control output { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.control input { grid-column: 1/-1; width: 100%; height: 32px; margin: 3px 0 0; accent-color: var(--frame); cursor: pointer; }
.color-field { margin-top: 20px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.color-field>div { display: flex; align-items: center; gap: 7px; }
.color-field output { font-size: 12px; color: var(--muted); }
.color-field input { width: 40px; height: 40px; padding: 3px; border: 1px solid var(--border); border-radius: 3px; background: var(--paper); cursor: pointer; }
.select-label { display: block; margin-top: 22px; }
.settings-note { font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 18px; margin: 22px 0 0; }
.full { width: 100%; }
.presets { border-top: 1px solid var(--border); margin-top: 24px; padding-top: 14px; }
.presets label { display: block; margin-top: 12px; }
.presets button { margin-top: 8px; }
.privacy-note { margin-top: 24px; padding: 12px 16px; border-left: 3px solid var(--frame); background: var(--glass); display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; font-size: 13px; }
.privacy-note p { flex: 1; min-width: 200px; margin: 0; }
.disclaimer { margin-top: 28px; max-width: 72ch; font-size: 13px; color: var(--muted); }
.disclaimer summary { width: fit-content; min-height: 44px; padding: 10px 0; cursor: pointer; color: var(--frame); }
footer { border-top: 1px solid var(--border); padding: 24px 0 30px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--muted); }
footer a { color: var(--frame); text-underline-offset: 4px; }
.muted { padding: 0 6px; }
[hidden] { display: none !important; }
@media (min-width: 760px) {
  .page { padding: 0 40px; }
  header { min-height: 96px; }
  .header-note { display: block; }
  main { margin-top: 38px; }
  .drop-zone { flex-wrap: nowrap; padding: 22px 26px; }
  .drop-zone button { width: auto; margin-left: auto; }
  .workspace { grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; }
  .preview-stage { min-height: 390px; }
  .settings { padding: 22px; }
}
@media (min-width: 1100px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 320px; gap: 40px; }
  .preview-stage { min-height: 440px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

.matte-toggle { display: flex; align-items: center; gap: 8px; margin-top: 18px; min-height: 44px; cursor: pointer; }
.matte-toggle input { width: 18px; height: 18px; accent-color: var(--frame); }
.matte-previews { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.matte-previews figure { margin: 0; min-width: 0; }
.matte-previews figcaption { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.matte-checker { height: 96px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--border); background-color: #fff; background-image: conic-gradient(#d4dcd8 25%, transparent 0 50%, #d4dcd8 0 75%, transparent 0); background-size: 16px 16px; }
.matte-checker canvas { max-width: 100%; max-height: 94px; }

.preview-surface { position: relative; max-width: 100%; min-width: 0; }
#crop-overlay { position: absolute; inset: 0; width: 100%; height: 100%; max-height: none; touch-action: none; cursor: move; }
#crop-overlay:focus-visible { outline: 3px solid var(--frame); outline-offset: -3px; }
.crop-controls { border: 0; padding: 0; margin: 20px 0 0; min-width: 0; }
.crop-controls legend { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.crop-aspects { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.crop-aspects label { position: relative; cursor: pointer; }
.crop-aspects input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.crop-aspects span { display: grid; place-items: center; min-width: 48px; min-height: 44px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 22px; font-size: 13px; }
.crop-aspects input:checked + span { background: var(--frame); border-color: var(--frame); color: #fff; }
.crop-aspects input:focus-visible + span { outline: 3px solid var(--frame); outline-offset: 3px; }
