:root {
  color-scheme: light;
  --bg: #f2f4f9;
  --panel: #fff;
  --soft: #e9efff;
  --line: #e0e5f0;
  --ink: #171a24;
  --muted: #555f72;
  --accent: #284fcf;
  --primary: #2e55dc;
  --on-primary: #fff;
  --shadow: #1d275c16;
  --error: #a0322e;
  font-family: system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) { color-scheme: dark; --bg: #14161b; --panel: #22252d; --soft: #30374e; --line: #353b4a; --ink: #f3f5fa; --muted: #bbc1ce; --accent: #b0beff; --primary: #a4b5ff; --on-primary: #182654; --shadow: #0005; --error: #ffaba6; }
}
:root[data-theme="dark"] { color-scheme: dark; --bg: #14161b; --panel: #22252d; --soft: #30374e; --line: #353b4a; --ink: #f3f5fa; --muted: #bbc1ce; --accent: #b0beff; --primary: #a4b5ff; --on-primary: #182654; --shadow: #0005; --error: #ffaba6; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { overflow-x: hidden; touch-action: manipulation; }
body { margin: 0; min-height: 100dvh; overflow-x: clip; color: var(--ink); background: var(--bg); }
.app { max-width: 620px; min-height: 100dvh; margin: auto; padding: max(16px, env(safe-area-inset-top)) clamp(14px, 4vw, 28px) 0; }
.symbols { position: absolute; width: 0; height: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.top { display: flex; align-items: center; justify-content: space-between; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.mark { align-self: center; display: grid; min-height: 44px; place-items: center; }
.icon-button { width: 46px; padding: 0; border-radius: 50%; color: var(--ink); background: var(--panel); border: 1px solid var(--line); }
.source-thumb { border-radius: 14px; }
.source-thumb img { display: block; border-radius: 9px; object-fit: cover; background: var(--soft); }
h1 { font-size: clamp(2.45rem, 8vw, 3.1rem); line-height: 1.05; letter-spacing: -.055em; margin: 21px 0 20px; font-weight: 775; }
.app:has(#edit-tools:not([hidden])) #editor-title { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip-path: inset(50%); }
.app:has(#edit-tools:not([hidden])) #edit-tools { margin-top: 12px; }
h2 { margin: 0; font-size: 1.35rem; letter-spacing: -.035em; }
small { color: var(--muted); font-size: .82rem; }
button { min-height: 46px; border: 0; border-radius: 14px; padding: 0 15px; font: inherit; font-weight: 690; color: inherit; cursor: pointer; display: inline-flex; gap: 7px; align-items: center; justify-content: center; touch-action: manipulation; }
button:disabled { opacity: .48; cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.primary { background: var(--primary); color: var(--on-primary); }
.secondary { background: var(--soft); color: var(--accent); }
.ghost { background: none; color: var(--accent); }
.compact { min-height: 44px; padding-inline: 10px; font-size: .9rem; }
.full { width: 100%; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; }
.empty { text-align: center; min-height: 285px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 17px; padding: 24px; }
.image-icon { width: 64px; height: 64px; border-radius: 20px; background: var(--soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 5px; }
.image-icon svg { width: 32px; height: 32px; }
.stage { position: relative; width: min(100%, calc(min(75svh, 780px) * var(--image-ratio, 1))); margin: 0 auto; isolation: isolate; }
.stage > img { display: block; width: 100%; height: auto; border-radius: 14px; user-select: none; }
.guides { position: absolute; inset: 0; }
.guide-line, .grip { position: absolute; }
.guide-line { min-height: 0; padding: 0; background: none; border-radius: 0; z-index: 1; }
.guide-line.is-selected { z-index: 2; }
.guide-line::after { content: ""; position: absolute; pointer-events: none; background: var(--guide-stroke, var(--guide-color)); box-shadow: 0 0 1px 1px #171b28aa; }
.guide-line::before { content: ""; position: absolute; pointer-events: none; background: var(--guide-color); opacity: .35; }
.guide-line.is-selected::after { box-shadow: 0 0 1px 1px #131723, 0 0 6px 1px var(--guide-color); }
.guide-line.behind-guide::after { visibility: hidden; }
.guide-line.horizontal { left: 0; width: 100%; height: 24px; transform: translateY(-50%); }
.guide-line.horizontal::after { width: 100%; height: 2px; top: calc(50% - 1px); }
.guide-line.horizontal::before { left: 0; top: calc(50% + var(--band-offset)); width: 100%; height: var(--band-width); }
.guide-line.vertical { top: 0; height: 100%; width: 24px; transform: translateX(-50%); }
.guide-line.vertical::after { width: 2px; height: 100%; left: calc(50% - 1px); }
.guide-line.vertical::before { top: 0; left: calc(50% + var(--band-offset)); height: 100%; width: var(--band-width); }
.tether { position: absolute; pointer-events: none; z-index: 3; color: var(--guide-color); filter: drop-shadow(0 0 1px #141521); }
.tether.horizontal { border-left: 2px dashed; }
.tether.vertical { border-top: 2px dashed; }
.grip { z-index: 4; width: 46px; min-height: 46px; padding: 0; color: #131825; background: var(--guide-color); border: 2px solid #fff; border-radius: 50%; transform: translate(-50%, -50%); box-shadow: 0 3px 11px #0d163d75; touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; cursor: grab; }
.grip svg { width: 23px; height: 23px; pointer-events: none; }
.grip:active { cursor: grabbing; }
.guide-lens { position: fixed; z-index: 6; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); width: 118px; height: 118px; border: 2px solid var(--guide-color); border-radius: 50%; overflow: hidden; background: #202531; box-shadow: 0 0 0 2px #101522, 0 5px 18px #10152280; pointer-events: none; }
.guide-lens.is-left { left: max(10px, env(safe-area-inset-left)); right: auto; }
.guide-lens.is-snapped { box-shadow: 0 0 0 2px #101522, 0 0 0 4px var(--guide-color), 0 5px 18px #10152280; }
.guide-lens canvas { display: block; width: 100%; height: 100%; }
.lens-band { position: absolute; background: color-mix(in srgb, var(--guide-color) 30%, transparent); border: solid var(--guide-color); }
.guide-lens.horizontal .lens-band { top: calc(50% + var(--band-offset)); left: 0; height: var(--band-width); width: 100%; border-width: 1px 0; }
.guide-lens.vertical .lens-band { left: calc(50% + var(--band-offset)); top: 0; width: var(--band-width); height: 100%; border-width: 0 1px; }
.guide-tools, .guide-buttons, .guide-actions { display: flex; gap: 5px; }
.guide-buttons button { width: 44px; min-height: 44px; padding: 0; border-radius: 12px; }
.guide-buttons svg { stroke-width: 2.7; }
.thickness { display: flex; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.thickness button { width: 30px; min-height: 42px; padding: 0; font-size: 1.05rem; }
.thickness-entry { display: flex; align-items: center; gap: 2px; font-size: .78rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.thickness-entry input { appearance: textfield; width: 21px; height: 40px; padding: 0; border: 0; border-radius: 5px; color: var(--ink); background: transparent; text-align: right; font: inherit; }
.thickness-entry input::-webkit-inner-spin-button, .thickness-entry input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.guide-summary, .select-row { display: flex; justify-content: space-between; align-items: center; gap: 7px; min-height: 48px; margin: 2px 0; }
.guide-summary { margin: 7px 0 4px; }
.guide-actions .compact { width: 44px; padding: 0; }
@media (max-width: 330px) {
  .guide-buttons button, .guide-actions .compact { width: 40px; }
}
.settings { display: flex; justify-content: space-between; align-items: center; gap: 7px; padding: 3px 8px; border-radius: 14px; font-size: .84rem; }
.segments { display: grid; grid-template-columns: repeat(3, 1fr); padding: 2px; border-radius: 10px; background: var(--bg); gap: 2px; }
.segments label, .sharpen { position: relative; cursor: pointer; }
.segments input, .sharpen input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segments span { display: grid; min-height: 38px; min-width: 37px; place-items: center; border-radius: 8px; font-weight: 720; }
.segments input:checked + span { color: var(--on-primary); background: var(--primary); }
.segments input:focus-visible + span, .sharpen input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.segments input:disabled + span, .sharpen input:disabled + span { opacity: .5; }
.sharpen { min-height: 42px; display: flex; gap: 5px; align-items: center; font-weight: 690; }
.track { width: 36px; height: 22px; background: var(--muted); border-radius: 20px; padding: 3px; }
.track::before { content: ""; display: block; width: 16px; height: 16px; border-radius: 50%; background: #fff; }
.sharpen input:checked + .track { background: var(--primary); }
.sharpen input:checked + .track::before { transform: translateX(14px); }
.actions { position: sticky; z-index: 5; bottom: 0; padding: 11px 0 max(12px, env(safe-area-inset-bottom)); background: var(--bg); margin-top: 5px; }
.actions:empty, .actions:not(:has(> :not([hidden]))) { display: none; }
.actions .primary, .actions .secondary { min-height: 51px; }
.status { margin-bottom: 9px; padding: 10px 13px; }
.status p { margin: 0; font-size: .9rem; line-height: 1.35; font-weight: 650; }
.status[data-kind="error"] { color: var(--error); }
progress { display: block; width: 100%; height: 10px; margin-top: 8px; accent-color: var(--primary); }
.export-detail { color: var(--muted); margin: -9px 0 8px; }
.gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.tile { position: relative; overflow: hidden; }
.tile-preview { padding: 0; width: 100%; display: block; color: var(--ink); background: var(--panel); text-align: left; }
.tile-preview img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: var(--soft); display: block; }
.tile-preview strong, .tile-preview small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-inline: 10px; }
.tile-preview strong { padding-top: 7px; font-size: .89rem; }
.tile-preview small { padding-bottom: 9px; padding-top: 2px; }
.tile-preview:focus-visible { outline-offset: -4px; }
.tile-check { display: grid; place-items: center; position: absolute; top: 3px; right: 3px; width: 44px; height: 44px; cursor: pointer; }
.tile-check, .tile-check input { touch-action: manipulation; }
.tile-check input { width: 24px; height: 24px; margin: 0; accent-color: var(--primary); cursor: pointer; }
.export-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.export-options { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 3px 10px; }
dialog { width: min(100% - 20px, 690px); max-height: 94dvh; padding: 12px; border-radius: 22px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
dialog[open] { display: flex; flex-direction: column; gap: 11px; }
dialog::backdrop { background: #101521bd; }
.viewer-bar, .viewer-actions { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.viewer-image { display: flex; align-items: center; justify-content: center; min-height: 100px; overflow: auto; background: var(--bg); border-radius: 12px; }
.viewer-image img { display: block; max-width: 100%; max-height: 66dvh; object-fit: contain; }
.viewer-image.zoomed { display: block; max-height: 66dvh; }
.viewer-image.zoomed img { max-width: none; max-height: none; }
.viewer-loading { padding: 16px 12px; color: var(--muted); text-align: center; }
