: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 { touch-action: manipulation; }
body { margin: 0; min-height: 100dvh; 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; }
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; }
.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); }
h1 { font-size: clamp(2.45rem, 8vw, 3.1rem); line-height: 1.05; letter-spacing: -.055em; margin: 21px 0 20px; font-weight: 775; }
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: 390px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; }
.empty p { color: var(--muted); line-height: 1.5; max-width: 30ch; margin: 0 0 5px; }
.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; }
.file-row { display: flex; align-items: center; gap: 11px; padding: 8px 10px; margin-bottom: 12px; }
.file-row img { object-fit: cover; border-radius: 8px; background: var(--soft); }
.file-details { display: grid; gap: 2px; flex: 1; min-width: 0; }
.file-details strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.stage { position: relative; width: fit-content; max-width: 100%; margin: 0 auto; isolation: isolate; }
.stage > img { display: block; max-width: 100%; max-height: min(52svh, 620px); width: auto; 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: white; filter: drop-shadow(0 0 2px #16213e); }
.guide-line.is-selected::after { background: #79f6ff; filter: drop-shadow(0 0 3px #007a87); }
.guide-line.horizontal { left: 0; width: 100%; height: 14px; transform: translateY(-50%); }
.guide-line.horizontal::after { width: 100%; height: 2px; top: calc(50% - 1px); }
.guide-line.vertical { top: 0; height: 100%; width: 14px; transform: translateX(-50%); }
.guide-line.vertical::after { width: 2px; height: 100%; left: calc(50% - 1px); }
.tether { position: absolute; pointer-events: none; z-index: 3; color: #adf9ff; }
.tether.horizontal { border-left: 2px dashed; }
.tether.vertical { border-top: 2px dashed; }
.grip { z-index: 4; width: 46px; min-height: 46px; padding: 0; color: #fff; background: #284fd7; border: 2px solid #fff; border-radius: 50%; transform: translate(-50%, -50%); box-shadow: 0 3px 11px #0d163d75; touch-action: none; user-select: none; font-size: 1.45rem; cursor: grab; }
.grip:active { cursor: grabbing; }
.guide-buttons, .export-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 13px; }
.guide-buttons span { font-size: 1.25em; font-weight: 500; }
.guide-picker { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: .9rem; font-weight: 690; }
.guide-picker select { min-width: 0; min-height: 44px; max-width: 78%; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0 9px; font: inherit; }
.guide-summary, .select-row { display: flex; justify-content: space-between; align-items: center; gap: 7px; min-height: 48px; margin: 2px 0; }
.guide-summary > div { display: flex; }
.settings { padding: 13px 14px 0; margin-top: 3px; }
fieldset { border: 0; margin: 0; padding: 0; }
legend { padding: 0; margin-bottom: 8px; font-weight: 740; }
.segments { display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; border-radius: 13px; background: var(--bg); gap: 3px; }
.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: 43px; place-items: center; border-radius: 10px; 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: 57px; display: flex; align-items: center; justify-content: space-between; font-weight: 690; }
.track { width: 49px; height: 28px; background: var(--muted); border-radius: 20px; padding: 3px; }
.track::before { content: ""; display: block; width: 22px; height: 22px; border-radius: 50%; background: #fff; }
.sharpen input:checked + .track { background: var(--primary); }
.sharpen input:checked + .track::before { transform: translateX(21px); }
.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 { margin: 0; }
.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; }
