:root {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  font-synthesis: none;
  color-scheme: light;
  --text: #172334;
  --muted: #52647a;
  --blue: #1262cb;
  --blue-active: #0b509f;
  --blue-ink: #1256ae;
  --blue-soft: #e9f3ff;
  --blue-line: #a8c8ef;
  --blue-strong-line: #6c99d4;
  --paper: #fff;
  --line: #e2e6ed;
  --line-control: #c6cfdb;
  --chip: #f7f8fa;
  --canvas: #f5f5f7;
  --checkerboard: conic-gradient(#edf0f4 25%, #fafbfd 0 50%, #edf0f4 0 75%, #fafbfd 0) 0 0 / 18px 18px;
  --crop-guide: rgb(255 255 255 / .88);
  --crop-guide-edge: rgb(23 35 52 / .5);
  color: var(--text);
  background: var(--canvas);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
button, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .53; }
h1, h2, p { margin: 0; }
[hidden], .icon-library { display: none !important; }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
.skip-link {
  position: absolute;
  z-index: 3;
  top: 8px;
  left: 12px;
  padding: 10px 14px;
  border-radius: 9px;
  background: var(--blue);
  color: var(--paper);
  font-weight: 650;
}

.icon {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.site-header { background: var(--paper); border-bottom: 1px solid var(--line); }
.header-inner, .page { width: min(1180px, calc(100% - clamp(32px, 7vw, 96px))); margin-inline: auto; }
.header-inner { min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 18px; font-weight: 760; letter-spacing: -.03em; text-decoration: none; }
.brand-mark { display: block; flex: none; width: 32px; height: 32px; object-fit: contain; }
.local-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid var(--blue-line);
  border-radius: 8px;
  background: var(--blue-soft);
  color: var(--blue-ink);
  font-size: .81rem;
  font-weight: 650;
}
.local-status .icon, .page-footer .icon { width: 14px; height: 14px; }

.page { padding: clamp(25px, 4vw, 42px) 0 24px; }
.intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin-bottom: 20px; }
.intro h1 { font-size: clamp(30px, 4vw, 42px); line-height: 1.15; font-weight: 750; letter-spacing: -.035em; }
.intro p { color: var(--muted); font-size: .875rem; line-height: 1.6; margin-top: 7px; }
.tool-modes {
  display: grid;
  width: max-content;
  max-width: 100%;
  grid-template-columns: repeat(3, minmax(104px, 1fr));
  gap: 4px;
  margin-bottom: 13px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--paper);
}
.tool-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 44px;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-size: .875rem;
  font-weight: 680;
  line-height: 1.25;
  white-space: nowrap;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease;
}
.tool-mode .icon { width: 16px; height: 16px; }
.tool-mode:hover { background: var(--chip); color: var(--blue-ink); }
.tool-mode[aria-pressed="true"] { border-color: var(--blue-line); background: var(--blue-soft); color: var(--blue-ink); }
.tool-mode:focus-visible { outline-offset: 1px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  min-height: 44px;
  padding: 9px 15px;
  white-space: nowrap;
  font-size: .875rem;
  font-weight: 680;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease;
}
.import-button, .empty-button { color: var(--blue-ink); background: var(--blue-soft); border-color: var(--blue-line); }
.import-button:enabled:hover, .empty-button:enabled:hover { background: #ddebff; border-color: var(--blue-strong-line); }
.error { margin-bottom: 12px; padding: 11px 16px; border: 1px solid #e9c4b8; color: #742e1b; background: #fff2ed; border-radius: 8px; line-height: 1.5; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) clamp(320px, 32%, 366px); gap: 16px; align-items: start; }
.canvas-panel, .settings { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 2px 5px rgb(19 35 60 / 4%); min-width: 0; }
.canvas-panel { overflow: hidden; }
.canvas-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 56px; padding: 6px 14px 6px 16px; }
.canvas-title { display: flex; align-items: center; gap: 9px; }
.canvas-title .icon { color: var(--blue-ink); }
.canvas-title h2 { font-size: 1rem; font-weight: 740; }
.canvas-actions { display: flex; align-items: center; gap: 6px; margin-inline-start: auto; }
.reset-button { color: var(--blue-ink); background: transparent; font-size: .875rem; padding-inline: 10px; }
.reset-button:enabled:hover { background: var(--blue-soft); }
.reset-button .icon { width: 16px; height: 16px; }

.stage {
  min-height: 250px;
  height: clamp(345px, 34vw, 455px);
  margin: 0 14px;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid #dce5f0;
  border-radius: 9px;
  background-color: #f3f7fc;
  background-image: radial-gradient(#bdcfe7 1px, transparent 1.2px);
  background-size: 17px 17px;
}
.stage:has(.empty-state:not([hidden])) { border-color: var(--blue-line); border-style: dashed; }
.stage-content { position: absolute; inset: 20px; display: grid; place-items: center; }
.image-frame { position: relative; overflow: hidden; background: var(--checkerboard); user-select: none; }
.image-frame img { display: block; width: 100%; height: 100%; pointer-events: none; }
.crop-box {
  position: absolute;
  top: 0;
  left: 0;
  border: 1px solid var(--blue);
  box-shadow: inset 0 0 0 1px var(--paper), 0 0 0 9999px rgb(18 34 56 / 55%);
  cursor: grab;
  touch-action: none;
  background:
    linear-gradient(to right,
      transparent calc(33.333% - 1px), var(--crop-guide-edge) calc(33.333% - 1px) 33.333%,
      var(--crop-guide) 33.333% calc(33.333% + 1px), transparent calc(33.333% + 1px) calc(66.667% - 1px),
      var(--crop-guide-edge) calc(66.667% - 1px) 66.667%, var(--crop-guide) 66.667% calc(66.667% + 1px),
      transparent calc(66.667% + 1px)),
    linear-gradient(to bottom,
      transparent calc(33.333% - 1px), var(--crop-guide-edge) calc(33.333% - 1px) 33.333%,
      var(--crop-guide) 33.333% calc(33.333% + 1px), transparent calc(33.333% + 1px) calc(66.667% - 1px),
      var(--crop-guide-edge) calc(66.667% - 1px) 66.667%, var(--crop-guide) 66.667% calc(66.667% + 1px),
      transparent calc(66.667% + 1px));
}
.crop-box:active { cursor: grabbing; }
.crop-box:focus-visible { outline: 2px dashed var(--paper); outline-offset: -5px; box-shadow: inset 0 0 0 3px var(--blue), 0 0 0 9999px rgb(18 34 56 / 55%); }
.crop-box.wechat-cover { background-image: none; }
.crop-box.wechat-cover::after {
  position: absolute;
  inset: 0 auto 0 70.1492537%;
  border-left: 1px dashed var(--paper);
  filter: drop-shadow(0 0 1px #163866) drop-shadow(0 0 1px #163866);
  content: "";
  pointer-events: none;
}
.handle {
  position: absolute;
  width: 28px;
  height: 28px;
  max-width: var(--handle-width, 44px);
  max-height: var(--handle-height, 44px);
  z-index: 1;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--paper);
  touch-action: none;
}
.handle::after { position: absolute; width: 14px; height: 14px; max-width: 100%; max-height: 100%; content: ""; border: 0 solid currentColor; filter: drop-shadow(0 0 1px var(--blue-active)) drop-shadow(0 0 1px var(--blue-active)); }
.handle.nw { top: -1px; left: -1px; cursor: nwse-resize; }
.handle.ne { top: -1px; right: -1px; cursor: nesw-resize; }
.handle.sw { bottom: -1px; left: -1px; cursor: nesw-resize; }
.handle.se { bottom: -1px; right: -1px; cursor: nwse-resize; }
.handle.nw::after { top: 0; left: 0; border-top-width: 3px; border-left-width: 3px; }
.handle.ne::after { top: 0; right: 0; border-top-width: 3px; border-right-width: 3px; }
.handle.sw::after { bottom: 0; left: 0; border-bottom-width: 3px; border-left-width: 3px; }
.handle.se::after { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; }
.handle:focus-visible { outline: 2px solid var(--blue); outline-offset: -3px; box-shadow: inset 0 0 0 2px var(--paper); }

.empty-state { display: grid; justify-items: center; gap: 14px; color: var(--muted); font-size: .875rem; text-align: center; }
.empty-state > .icon { width: 36px; height: 36px; color: var(--blue); }
.drop-message { position: absolute; inset: 0; display: grid; place-items: center; color: var(--blue-ink); background: rgb(233 243 255 / 94%); border: 2px dashed var(--blue); border-radius: inherit; font-size: 1.05rem; font-weight: 720; pointer-events: none; }
.canvas-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; column-gap: 12px; row-gap: 6px; min-height: 46px; padding: 8px 16px; color: var(--muted); font-size: .8125rem; }
.file-details { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sample-label { color: var(--blue-ink); background: var(--blue-soft); border-radius: 4px; font-weight: 700; padding: 3px 5px; white-space: nowrap; }
.file-name { color: var(--text); font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-size { font-variant-numeric: tabular-nums; white-space: nowrap; }
.crop-help { display: flex; align-items: center; gap: 5px; }
.crop-help .icon { width: 14px; height: 14px; }
.source-format-note { width: 100%; line-height: 1.5; }

.image-list { border-top: 1px solid var(--line); padding: 11px 12px 8px; }
.image-list-header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding-inline: 4px; }
.image-list-header h3 { margin: 0; font-size: .875rem; font-weight: 740; }
.image-list-header span { color: var(--muted); font-size: .8125rem; text-align: end; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.image-items { display: flex; gap: 8px; overflow-x: auto; margin: 3px 0 0; padding: 5px 4px 7px; list-style: none; }
.image-item {
  display: flex;
  flex: 0 0 min(175px, 85%);
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--chip);
}
.image-select, .image-remove { display: flex; align-items: center; min-height: 44px; border: 0; background: transparent; }
.image-select {
  flex: 1;
  gap: 7px;
  min-width: 0;
  padding: 5px 7px;
  border-radius: 8px 0 0 8px;
  color: var(--text);
  font-size: .8125rem;
  font-weight: 680;
  text-align: start;
}
.image-select:hover, .image-remove:hover { background: var(--blue-soft); color: var(--blue-ink); }
.image-select[aria-pressed="true"] { color: var(--blue-ink); background: var(--blue-soft); box-shadow: inset 0 0 0 1px var(--blue-line); }
.image-select:focus-visible, .image-remove:focus-visible { outline-offset: -2px; }
.image-select img { flex: 0 0 auto; width: 30px; height: 30px; border-radius: 4px; object-fit: cover; background: var(--chip); }
.image-select span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-remove {
  flex: 0 0 44px;
  justify-content: center;
  padding: 0;
  border-left: 1px solid var(--line);
  border-radius: 0 8px 8px 0;
  color: var(--muted);
}
.image-remove .icon { width: 15px; height: 15px; }

.settings { padding: 16px; }
.settings fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.settings legend { padding: 0; margin-bottom: 11px; font-size: 1rem; font-weight: 750; }
.presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.preset {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-height: 70px;
  padding: 8px 3px;
  color: var(--text);
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 9px;
  line-height: 1.18;
  transition: background-color .16s ease, border-color .16s ease;
}
.preset:hover { border-color: var(--blue-line); background: var(--blue-soft); }
.preset[aria-pressed="true"] { border-color: var(--blue-strong-line); background: var(--blue-soft); color: var(--blue-ink); }
.ratio-shape, .free-shape { align-self: center; color: var(--muted); }
.preset[aria-pressed="true"] :is(.ratio-shape, .free-shape) { color: var(--blue-ink); }
.ratio-shape { width: var(--frame-width); height: var(--frame-height); border: 1.5px solid currentColor; border-radius: 2px; }
.free-shape { width: 18px; height: 18px; }
.ratio-name { font-size: .96rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.ratio-use { color: var(--muted); font-size: .8125rem; white-space: nowrap; }
.preset.wechat-wide {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 8px;
}
.wechat-wide .ratio-shape, .wechat-wide .ratio-name { flex: 0 0 auto; }
.wechat-wide .ratio-use { text-align: start; white-space: normal; }
.settings .ratio-settings { padding-bottom: 16px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.export-settings legend { padding-top: 1px; }
.export-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 7px; }
.export-row label, .output-size { color: var(--muted); font-size: .875rem; }
.select-wrap { position: relative; width: 54%; min-width: 125px; }
.select-wrap select {
  appearance: none;
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 6px 29px 6px 9px;
  border: 1px solid var(--line-control);
  border-radius: 9px;
  color: var(--text);
  background: var(--paper);
  font-size: .875rem;
  cursor: pointer;
}
.select-wrap select:enabled:hover { border-color: var(--blue-strong-line); }
.select-wrap .icon { width: 15px; height: 15px; position: absolute; right: 9px; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--muted); }
.output-size { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 10px; }
.output-size output { color: var(--text); font-weight: 720; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mode-settings { min-width: 0; }
.quality-control { margin-top: 14px; }
.quality-heading, .quality-labels { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; color: var(--muted); }
.quality-heading { font-size: .875rem; }
.quality-heading output { color: var(--text); font-weight: 720; font-variant-numeric: tabular-nums; }
.quality-control input[type="range"] { display: block; width: 100%; min-height: 44px; margin: 0; accent-color: var(--blue); }
.quality-control input[type="range"]:enabled { cursor: pointer; }
.quality-labels { font-size: .8125rem; }
.quality-labels > :last-child { text-align: end; }
.mode-results {
  display: grid;
  gap: 8px;
  margin: 16px 0 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--muted);
  background: var(--chip);
  font-size: .875rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.result-row { display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 5fr); gap: 8px; align-items: baseline; }
.result-row > :where(:last-child) { margin: 0; color: var(--text); text-align: end; font-weight: 720; font-variant-numeric: tabular-nums; }
.size-change { color: var(--muted); font-weight: 680; overflow-wrap: anywhere; }
.size-change[data-direction="smaller"] { color: var(--blue-ink); }
.size-change[data-direction="larger"] { color: #742e1b; }
.settings-note { margin-top: 10px; color: var(--muted); font-size: .8125rem; line-height: 1.5; overflow-wrap: anywhere; }
.target-size { margin-top: 12px; border: 1px solid var(--line-control); border-radius: 9px; background: var(--paper); }
.target-size summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 7px;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--blue-ink);
  font-size: .875rem;
  font-weight: 680;
  line-height: 1.35;
  list-style: none;
  cursor: pointer;
}
.target-size summary::-webkit-details-marker { display: none; }
.target-size summary::after {
  content: "";
  grid-column: 3;
  grid-row: 1;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}
.target-size summary:hover, .target-size[open] summary { background: var(--blue-soft); }
.target-size summary:focus-visible { outline-offset: 1px; }
.target-size[open] summary { border-radius: 8px 8px 0 0; }
.target-size[open] summary::after { transform: translateY(2px) rotate(225deg); }
.target-size-label {
  grid-column: 2;
  max-width: 82px;
  color: var(--text);
  font-size: .8125rem;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
  text-align: end;
}
.settings .target-size-fields { padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.target-size-fields > label { display: block; margin-bottom: 5px; color: var(--muted); font-size: .875rem; }
.target-size-inputs { display: grid; grid-template-columns: minmax(0, 1fr) 74px; gap: 8px; }
.target-size-inputs .select-wrap { width: 100%; min-width: 0; }
.target-size-inputs input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 6px 9px;
  border: 1px solid var(--line-control);
  border-radius: 9px;
  color: var(--text);
  background: var(--paper);
  font: inherit;
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}
.target-size-inputs input:enabled:hover { border-color: var(--blue-strong-line); }
.target-size-inputs :is(input, select):disabled { background: var(--chip); color: var(--muted); cursor: default; }
.target-size-inputs input:is([aria-invalid="true"], :user-invalid) { border-color: #bc5e49; }
.target-size-feedback {
  margin-top: 8px;
  padding: 7px 9px;
  border: 1px solid var(--blue-line);
  border-radius: 7px;
  color: var(--blue-ink);
  background: var(--blue-soft);
  font-size: .8125rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.target-size-feedback[data-state="error"] { border-color: #e9c4b8; color: #742e1b; background: #fff2ed; }
.download-button { width: 100%; min-height: 44px; background: var(--blue); color: var(--paper); }
.download-button:enabled:hover { background: var(--blue-active); }
.download-button:disabled { background: #dae4f1; color: #505f72; opacity: 1; }
.download-actions { display: grid; gap: 8px; margin-top: 17px; }
.target-size:not([hidden]) + .download-actions { margin-top: 10px; }
.download-actions .download-button { white-space: normal; }
.download-actions .download-button:not([hidden]) + .download-button { background: var(--blue-soft); border-color: var(--blue-line); color: var(--blue-ink); }
.download-actions .download-button:not([hidden]) + .download-button:enabled:hover { background: #ddebff; border-color: var(--blue-strong-line); }
.download-actions .download-button:not([hidden]) + .download-button:disabled { background: var(--chip); border-color: var(--line); color: var(--muted); }
.download-progress { color: var(--muted); font-size: .8125rem; line-height: 1.5; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.download-progress:empty { display: none; }
.page-footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: .8125rem; padding: 14px 1px 0; }
.page-footer span:first-child { display: flex; align-items: center; gap: 6px; }
.page-footer span:last-child { line-height: 1.5; }
.sr-only, .skip-link:not(:focus-visible) { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (min-width: 900px) and (max-height: 800px) {
  .header-inner { min-height: 58px; }
  .page { padding-top: clamp(16px, calc(4vw - 20px), 22px); }
  .intro { margin-bottom: 11px; }
  .intro h1 { font-size: clamp(30px, 3.6vw, 38px); }
  .tool-modes { margin-bottom: 10px; }
  .stage { height: clamp(300px, min(34vw, 49vh), 390px); }
  .settings { padding-block: 13px; }
  .settings legend { margin-bottom: 8px; }
  .settings .ratio-settings { padding-bottom: 11px; margin-bottom: 10px; }
  .preset:not(.wechat-wide) { min-height: 56px; gap: 2px; padding-block: 4px; }
  .export-settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 10px; }
  .export-settings .export-row { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 4px; margin-bottom: 0; }
  .export-settings .select-wrap { width: 100%; min-width: 0; }
  .output-size { grid-column: 1 / -1; margin-top: 7px; }
  .target-size, .target-size:not([hidden]) + .download-actions { margin-top: 8px; }
  .download-actions { margin-top: 13px; }
}
@media (max-width: 760px) {
  .header-inner { min-height: 57px; }
  .intro { align-items: flex-start; flex-wrap: wrap; margin-bottom: 15px; }
  .tool-modes { width: 100%; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 12px; }
  .tool-mode { padding-inline: 5px; }
  .editor { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .canvas-header { flex-wrap: wrap; gap: 3px 8px; padding-inline: 11px; }
  .canvas-actions .button { padding-inline: 7px; gap: 5px; }
  .canvas-actions .icon { width: 16px; height: 16px; }
  .stage { height: clamp(240px, 65vw, 390px); min-height: 0; margin-inline: 9px; }
  .stage-content { inset: 10px; }
  .canvas-footer { padding-inline: 12px; }
}
@media (max-width: 330px) {
  .target-size summary { column-gap: 5px; padding-inline: 8px; }
  .tool-mode { gap: 3px; padding-inline: 2px; font-size: .8125rem; }
  .tool-mode .icon { width: 14px; height: 14px; }
  .preset { padding-inline: 1px; }
  .ratio-use { font-size: .75rem; }
}
@media (pointer: coarse) {
  .handle { width: 44px; height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
