*{box-sizing:border-box}html{color-scheme:light;background:#fff}body{margin:0;color:#18253a;background:#fff;font:16px system-ui,-apple-system,BlinkMacSystemFont,sans-serif;min-height:100vh;min-height:100dvh}main{min-height:100vh;min-height:100dvh}.screen[hidden]{display:none!important}.screen{min-height:100vh;min-height:100dvh;display:grid;place-items:center;padding: max(16px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) max(16px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left))}.card{width:min(100%,460px);min-width:0;border:1px solid #dce3eb;border-radius:16px;background:#fff;padding:clamp(16px,5vw,28px)}h1{font-size:26px;margin:4px 0 12px;line-height:1.25}.eyebrow{color:#526174;font-size:14px;margin:0}.description{color:#526174;margin:0 0 24px;line-height:1.6}.note{font-size:13px;color:#526174;line-height:1.6;margin:14px 0 0}button{width:100%;min-height:44px;display:block;font:inherit;color:#18253a;background:#fff;border:1px solid #ccd5e1;border-radius:9px;padding:12px;margin-top:12px;cursor:pointer}button.primary{background:#243e60;color:#fff;border-color:#243e60}button:disabled{background:#edf1f5;color:#626e7e;cursor:default}button:focus-visible{outline:3px solid #2563eb;outline-offset:2px}.back{width:auto;min-height:44px;margin:0 0 20px}.placeholder{border:1px dashed #aab8c8;border-radius:8px;padding:20px 10px;text-align:center;line-height:1.6;color:#526174}@media(max-height:420px){.screen{padding:10px}.card{padding:16px}.description{margin-bottom:10px}.back{margin-bottom:10px}h1{font-size:22px}.note{margin-top:8px}}

/* Stage 02: image import and background setup */
[hidden]{display:none!important}.file-label{display:block;margin-top:12px;font-weight:600}input[type=file]{display:block;width:100%;max-width:100%;margin:8px 0 12px;font:inherit;font-size:14px;color:#18253a}input[type=file]::file-selector-button{font:inherit;color:#18253a;border:1px solid #ccd5e1;border-radius:7px;background:#fff;padding:10px;margin-right:8px;cursor:pointer}.image-preview{margin:12px 0 0;background:transparent;display:flex;justify-content:center;align-items:center;min-height:0}.image-preview img{display:block;max-width:100%;max-height:min(38vh,300px);max-height:min(38dvh,300px);width:auto;height:auto;object-fit:contain}.status{color:#a32828;font-size:14px;line-height:1.5;overflow-wrap:anywhere;margin:6px 0}.status:empty{display:none}.bg-options{margin:14px 0 0;border:1px solid #dce3eb;border-radius:8px;display:grid;grid-template-columns:1fr 1fr;gap:8px;padding:10px;min-width:0}.bg-options label{display:flex;align-items:center;justify-content:center;gap:8px;border:1px solid #ccd5e1;border-radius:8px;min-height:44px;cursor:pointer}.bg-options input{accent-color:#243e60}.swatch{width:19px;height:19px;border:1px solid #9aa7b8;border-radius:4px}.swatch.white{background:#fff}.swatch.black{background:#000}.placeholder{margin-top:12px}@media(max-height:420px){.image-preview img{max-height:100px}.screen{align-items:start}}

/* Stage 03: cover geometry is tied to the source image, never to its container. */
.cover-board{position:relative;flex:none;min-width:0;width:min(100%,var(--preview-w,100%));overflow:hidden;aspect-ratio:var(--ratio,1)}.cover-board img{width:100%;height:100%;max-width:none;max-height:none;object-fit:fill}.cover-layer{position:absolute;inset:0;background-size:100% 100%;background-repeat:no-repeat;pointer-events:none}.settings{margin:14px 0 0;border:1px solid #dce3eb;border-radius:8px;padding:10px;min-width:0}.choice-row{display:flex;flex-wrap:wrap;gap:6px}.choice-row label{flex:1 1 auto;display:flex;align-items:center;justify-content:center;gap:4px;border:1px solid #ccd5e1;border-radius:8px;min-height:44px;padding:5px;font-size:14px;cursor:pointer}.choice-row input{accent-color:#243e60;margin:0}.field-title{font-weight:600;font-size:14px;margin:14px 0 8px}.palette{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:6px}.palette button{margin:0;padding:0;min-height:36px;aspect-ratio:1.25;border-radius:6px;border:1px solid #9aa7b8;position:relative}.palette button[aria-pressed=true]{outline:2px solid #2563eb;outline-offset:1px}.palette button[aria-pressed=true]::after{content:'✓';position:absolute;inset:0;display:grid;place-items:center;color:var(--check,#000);font-weight:bold;text-shadow:0 0 2px #888}.palette button:focus-visible{outline:3px solid #2563eb;outline-offset:2px}#border-sample{margin-top:10px;height:30px;background:#b5c9ff;border-radius:3px;display:grid;place-items:center}#border-sample::after{content:'';width:80%;height:var(--sample-width,3px);background:var(--sample-color,#000)}
/* Stage 04: a bounded workspace and exact source-sized SVG overlay. */
.division-card{width:min(100%,1100px)}.division-header{display:flex;align-items:center;gap:12px;margin-bottom:12px}.division-header .back{margin:0;flex:none}.division-header h1{margin:2px 0}.division-layout{display:grid;grid-template-columns:minmax(0,1fr);gap:14px;align-items:start}.division-stage{display:flex;align-items:center;justify-content:center;width:100%;height:clamp(140px,42vh,460px);height:clamp(140px,42dvh,460px);min-width:0;background:#fff;overflow:hidden}.division-stage .cover-board{width:0;height:0;aspect-ratio:auto;flex:none;touch-action:manipulation;cursor:crosshair;user-select:none;-webkit-user-select:none}.division-stage img{pointer-events:none;-webkit-user-drag:none}.division-stage svg{position:absolute;inset:0;width:100%;height:100%;overflow:hidden;pointer-events:none}.division-stage svg line{stroke:#243e60;stroke-width:2.5;stroke-linecap:round}.division-stage svg circle{fill:#2563eb;stroke:#fff;stroke-width:1;vector-effect:non-scaling-stroke}.division-controls{min-width:0}.opacity-settings{margin:0}.opacity-settings input{display:block;width:100%;margin:12px 0;accent-color:#243e60}.opacity-buttons{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px}.opacity-buttons button{margin:0;padding:8px}.opacity-buttons button[aria-pressed=true]{background:#243e60;color:white;border-color:#243e60}.coordinate-tools{margin-top:12px}.coordinate-tools .note{margin-top:6px;overflow-wrap:anywhere}@media(min-width:768px){.division-layout{grid-template-columns:minmax(0,1fr) minmax(240px,300px)}.division-stage{height:clamp(220px,65vh,720px);height:clamp(220px,65dvh,720px)}}@media(max-height:420px) and (orientation:landscape){.division-layout{grid-template-columns:minmax(0,1fr) minmax(210px,280px)}.division-stage{height:clamp(110px,62vh,280px);height:clamp(110px,62dvh,280px)}}

/* Stage 05 */
.snap-tools{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px}.snap-tools button{margin:0;padding:8px;font-size:14px}.snap-tools button[aria-pressed=true]:not(:disabled){background:#243e60;color:#fff;border-color:#243e60}.division-stage svg .snap-marker{fill:#d97706;stroke:#fff;stroke-width:1.5}.division-stage svg .snap-marker.selected{stroke:#2563eb;stroke-width:2.5}.division-stage svg .snap-marker.connected{fill:#15803d}

/* Stage 06: construction lines stay opaque; only freehand captures touch gestures. */
.division-stage .cover-board[data-tool=freehand]{touch-action:none}.division-stage svg #division-outline{stroke:#243e60;stroke-width:2;pointer-events:none}.division-stage svg polyline{stroke:#243e60;stroke-width:2;stroke-linejoin:round;stroke-linecap:round}.division-stage svg #line-draft{stroke:#2563eb;stroke-dasharray:4 2}.division-stage svg #snap-markers{pointer-events:none}

/* Stage 6.1: fixed markers stay blue even when connected. */
.division-stage svg .snap-marker.fixed,.division-stage svg .snap-marker.fixed.connected{fill:#2563eb;stroke:#fff;stroke-width:1.5}

/* Stage 6.2: curve draft and handle */
.division-stage .cover-board[data-tool=curve]{touch-action:none}.curve-actions{display:grid;grid-template-columns:1fr 1fr;gap:6px}.curve-actions button{padding:8px;font-size:14px}.division-stage svg #curve-handle{fill:#fff;stroke:#2563eb;stroke-width:2.5}.division-stage svg #curve-end{fill:#2563eb}.division-stage svg #line-draft.invalid{stroke:#dc2626}.division-stage svg #curve-handle.invalid{stroke:#dc2626}

/* Stage 6.3: clip only the workspace; page zoom and scroll outside it remain available. */
.division-workspace{min-width:0}.division-stage{touch-action:none;overscroll-behavior:contain}.division-stage .cover-board{touch-action:none!important;transform-origin:center center}.zoom-tools{display:flex;align-items:center;flex-wrap:wrap;gap:6px 10px;margin-top:6px;font-size:14px}.zoom-tools button{width:auto;min-height:44px;margin:0 0 0 auto;padding:8px 12px;font-size:14px}.zoom-tools .note{width:100%;margin:0}.division-stage svg{touch-action:none}
/* Stage 7: shape controls and opaque construction outlines. */
#shape-controls{margin-top:10px;padding:8px;border:1px solid #dce3eb;border-radius:8px}.shape-types,.shape-size-buttons{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px}.shape-types button,.shape-size-buttons button,.shape-dpad button{margin:0;padding:8px;font-size:14px}.shape-types button[aria-pressed=true]{background:#243e60;color:#fff}#shape-select{grid-column:1/-1}#shape-size{display:block;width:100%;margin:8px 0;accent-color:#243e60}.shape-dpad{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:4px;margin:8px auto;max-width:170px}.shape-dpad [data-shape-dir=up]{grid-area:1/2}.shape-dpad [data-shape-dir=left]{grid-area:2/1}.shape-dpad [data-shape-dir=right]{grid-area:2/3}.shape-dpad [data-shape-dir=down]{grid-area:3/2}.division-stage svg .preset-shape.selected{stroke:#2563eb;stroke-width:3}.division-stage svg .preset-shape.selected.locked{stroke:#15803d}

/* Stage 8 */
#unfinished-lines polyline{stroke:#dc2626;stroke-width:3.5;stroke-dasharray:5 3}#division-validation{color:#b91c1c;font-weight:600}.confirmed-preview{display:flex;align-items:center;justify-content:center;width:100%;height:clamp(140px,65dvh,720px);overflow:hidden}.confirmed-preview .cover-board{flex:none;width:0;height:0;aspect-ratio:auto}.confirmed-preview svg{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}#confirmed-selection{stroke:#2563eb;stroke-width:3;vector-effect:non-scaling-stroke;fill:#2563eb;fill-opacity:.10}#confirmed-board{cursor:pointer}

/* Stage 9 */
#division-lines .selected-line{stroke:#dc2626;stroke-width:3.5}.edit-history-tools{display:grid;grid-template-columns:1fr 1fr;gap:6px;margin-top:10px}.edit-history-tools button{margin:0;padding:8px;font-size:14px}#division-reset{grid-column:1/-1;color:#b91c1c;border-color:#e4b4b4}
