/* Map import bench · a survey bench on the lab's tokens (proposed).
   The map lies on a registration mat (warm grey in light, near black in dark) with its own instrument strip above (what the next click does, the engine's
   status) and a mark legend below. Beside it, a calibration ledger: one numbered register per fact, then creating as
   its own last act. The engine keeps its ids and draws the canvas; this sheet only places and dresses them.
   Type is fixed rem throughout; letter-spacing stays 0. */

:root {
  color-scheme: light;
  --paper: #ecebe6; --plate: #f7f6f2; --plate-2: #dddcd5; --field: #fff;
  --ink: #121412; --ink-2: #3d403a; --ink-3: #5f625b;
  --rule: rgb(18 20 18 / .11); --rule-2: rgb(18 20 18 / .26);
  --slab: #121412; --on-slab: #edece5; --on-slab-2: #b9b8b0; --signal: #c4ee2c; --on-signal: #121412;
  --alert: #b93a0b; --ok: #12704f; --warn: #855300;
  --mat: #d4d3cb; --mat-dot: rgb(18 20 18 / .1); --mat-dot-2: rgb(18 20 18 / .22); --mat-ink: #121412; --mat-ink-2: #4a4d47; --mat-warn: #855300;
  /* the canvas marks' own colours (engine-drawn); the legend and diagram repeat them exactly */
  --k-scale: #0975b7; --k-origin: #e17000; --k-area: #00884a;
  --lift: 0 .75rem 2rem rgb(18 20 18 / .16);
  --f-display: Bahnschrift, "DIN Alternate", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --f-ui: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Microsoft YaHei UI", sans-serif;
  --f-num: "Cascadia Mono", "JetBrains Mono", ui-monospace, Consolas, monospace;
  --ease: cubic-bezier(.2, .9, .25, 1);
  --hit: 2.75rem; --r: .375rem;
  --pad-l: max(.75rem, env(safe-area-inset-left)); --pad-r: max(.75rem, env(safe-area-inset-right));
  --im-top: var(--im-top-h, 3.5rem);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0d0e0d; --plate: #151715; --plate-2: #1f221f; --field: #0f110f;
  --ink: #edece5; --ink-2: #c6c5bd; --ink-3: #93948c;
  --rule: rgb(237 236 229 / .1); --rule-2: rgb(237 236 229 / .24);
  --slab: #232623; --on-slab: #edece5; --on-slab-2: #a9a8a0; --signal: #d4f347; --on-signal: #121412;
  --alert: #ff7a2e; --ok: #4ade9a; --warn: #ffc23d;
  --mat: #070807; --mat-dot: rgb(237 236 229 / .09); --mat-dot-2: rgb(237 236 229 / .18); --mat-ink: #edece5; --mat-ink-2: #a9a8a0; --mat-warn: #ffc23d;
  --lift: 0 .75rem 2rem rgb(0 0 0 / .5);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--paper); scroll-padding-block: calc(var(--im-top) + .5rem) 1.5rem; }
/* The desk is surveyor's tracing paper: a fine metric tick border runs along the top edge, nothing behind the data. */
body.im {
  margin: 0; min-height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr);
  background-color: var(--paper);
  background-image:
    repeating-linear-gradient(90deg, var(--rule-2) 0 1px, transparent 1px 7.5rem),
    repeating-linear-gradient(90deg, var(--rule) 0 1px, transparent 1px .75rem);
  background-size: 100% .75rem, 100% .375rem; background-repeat: no-repeat; background-position: 0 var(--im-top), 0 var(--im-top);
  color: var(--ink); font: 400 .9375rem/1.5 var(--f-ui); letter-spacing: 0;
}
:lang(ja) body.im, :lang(zh-CN) body.im { line-height: 1.6; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; letter-spacing: 0; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.im-i { width: 1.125rem; height: 1.125rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.im-sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.im-skip { position: absolute; left: var(--pad-l); top: .5rem; z-index: 40; padding: .5rem .875rem; border-radius: var(--r); background: var(--slab); color: var(--on-slab); text-decoration: none; transform: translateY(-200%); }
.im-skip:focus { transform: none; }
.im-eyebrow { margin: 0; font: 600 .6875rem/1.25 var(--f-num); text-transform: uppercase; color: var(--ink-3); }
:lang(ja) .im-eyebrow, :lang(zh-CN) .im-eyebrow { font-family: var(--f-ui); font-size: .75rem; }

/* ---- header: escape, the room's name, the draft's protection state, the library, display settings */
.im-top {
  position: sticky; top: 0; z-index: 12; display: flex; flex-wrap: wrap; align-items: center; gap: .375rem .5rem;
  padding: .375rem var(--pad-r) .375rem var(--pad-l); background: var(--plate); border-bottom: 1px solid var(--rule);
}
.im-home {
  flex: none; display: inline-flex; align-items: center; justify-content: center; gap: .4375rem;
  min-width: var(--hit); min-height: var(--hit); padding: 0 .6875rem; border-radius: 999px;
  background: var(--slab); color: var(--on-slab); font: 600 .875rem/1 var(--f-ui); text-decoration: none;
}
.im-home > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.im-home .im-i { color: var(--signal); }
.im-home:hover { background: color-mix(in oklab, var(--slab) 88%, var(--signal)); }
.im-title { flex: 1 1 auto; display: flex; align-items: center; gap: .5rem; min-width: 0; }
.im-title > div { min-width: 0; }
.im-title .im-eyebrow { display: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.im-title h1 { margin: 0; font: 600 1.125rem/1.15 var(--f-display); overflow-wrap: anywhere; }
.im-mark { flex: none; display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: var(--r); background: var(--slab); color: var(--signal); }
.im-mark .im-i { width: 1rem; height: 1rem; }
.im-quiet {
  display: inline-flex; align-items: center; justify-content: center; gap: .375rem; min-height: var(--hit); min-width: var(--hit);
  padding: 0 .75rem; border: 1px solid var(--rule-2); border-radius: 999px; background: transparent; color: var(--ink);
  font: 600 .8125rem/1.1 var(--f-ui); text-decoration: none; white-space: nowrap;
}
.im-quiet:hover { background: var(--plate-2); }
.im-lib { flex: none; }
.im-prefs-toggle { flex: none; padding: 0 .75rem 0 .625rem; }
.im-prefs-toggle[aria-expanded="true"] { background: var(--plate-2); border-color: var(--ink-3); }
.im-prefs { display: none; }
.im-lang { position: relative; display: inline-flex; align-items: center; }
.im-lang .im-i { position: absolute; left: .625rem; pointer-events: none; color: var(--ink-2); }
.im-lang select {
  min-height: var(--hit); padding: 0 .5rem 0 2rem; border: 1px solid var(--rule-2); border-radius: 999px;
  background: transparent; color: var(--ink); font: 600 1rem/1 var(--f-ui);
}
.im-lang select option { background: var(--plate); color: var(--ink); }
/* the draft mark: unsaved work is visible from anywhere, before any way out is taken */
.im-draft {
  flex: none; display: inline-flex; align-items: center; gap: .4375rem; min-height: 1.75rem; padding: 0 .625rem 0 .5rem;
  border-radius: 999px; background: var(--plate-2); font: 600 .75rem/1.2 var(--f-ui); color: var(--ink-2); white-space: nowrap;
}
.im-draft::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: var(--warn); }
.im-draft[data-k="saved"]::before { background: var(--ok); }
.im-draft:is([data-k="loading"], [data-k="creating"])::before { background: var(--ink-2); animation: im-blink 1.1s ease-in-out infinite; }
@media (max-width: 29.99rem) {
  .im-draft { width: 1.75rem; padding: 0; justify-content: center; }
  .im-draft > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .im-top > .im-lib > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
.im-top[data-prefs="open"] .im-prefs {
    position: absolute; top: calc(100% - .25rem); right: var(--pad-r); z-index: 30;
    display: flex; flex-direction: column; align-items: stretch; gap: .375rem; min-width: 13.5rem; padding: .5rem;
    border: 1px solid var(--rule-2); border-radius: .5rem; background: var(--plate); box-shadow: var(--lift);
}
.im-top[data-prefs="open"] .im-prefs :is(.im-quiet, .im-lang select) { width: 100%; justify-content: flex-start; }
.im-top[data-prefs="open"] .im-prefs .im-quiet .im-sr { position: static !important; width: auto; height: auto; overflow: visible; clip-path: none; }

/* ---- desk. Phone is the base: the bench first, the ledger beneath it, one column. */
.im-desk { display: grid; grid-template-columns: minmax(0, 1fr); gap: .75rem; align-items: start; min-width: 0; padding: 1.25rem var(--pad-r) 2rem var(--pad-l); }

/* ---- the bench */
.im-stage {
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0;
  border: 1px solid var(--rule-2); border-radius: .5rem; background: var(--plate); overflow: hidden;
}
.im-stage:focus { outline: none; }
.im-stage:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
/* the instrument strip: what the next click does, then the engine's own status line */
.im-strip { display: flex; align-items: center; gap: .5rem; min-width: 0; padding: .375rem .375rem .375rem .5rem; border-bottom: 1px solid var(--rule); }
.im-mode {
  flex: none; display: inline-flex; align-items: center; gap: .375rem; min-height: 2rem; padding: 0 .625rem 0 .5rem;
  border: 1px solid var(--rule-2); border-radius: 999px; font: 600 .8125rem/1.1 var(--f-num); color: var(--ink-2); white-space: nowrap;
  transition: background-color .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease);
}
:lang(ja) .im-mode, :lang(zh-CN) .im-mode { font-family: var(--f-ui); }
.im-desk:not([data-mode="browse"]) .im-mode { border-color: var(--slab); background: var(--slab); color: var(--signal); }
.im-status { flex: 1 1 auto; min-width: 0; margin: 0; font: 500 .875rem/1.35 var(--f-ui); color: var(--ink); overflow-wrap: anywhere; }
.im-status:empty { visibility: hidden; }
.im-status[data-kind="loaded"] { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.im-strip:has(.im-status[data-kind="loaded"]) #fit { margin-inline-start: auto; }
.im-tool {
  flex: none; display: inline-flex; align-items: center; justify-content: center; gap: .375rem; min-height: var(--hit); min-width: var(--hit);
  padding: 0 .75rem; border: 1px solid var(--rule-2); border-radius: var(--r); background: var(--field); font: 600 .8125rem/1 var(--f-ui);
}
.im-tool:hover { border-color: var(--ink-3); }
.im-desk:not([data-image="ready"]) .im-tool { color: var(--ink-3); }

/* the mat: a registration surface a step darker than any plan (usually pale paper), so the plan's edge reads against it:
   warm grey in light, near black in dark. Its dot lattice is texture only; it carries no scale and the engine draws
   nothing from it. */
.im-mat {
  position: relative; min-height: 0; height: clamp(18rem, 58svh, 34rem);
  background-color: var(--mat);
  background-image: radial-gradient(circle, var(--mat-dot-2) 1.25px, transparent 1.75px), radial-gradient(circle, var(--mat-dot) 1px, transparent 1.5px);
  background-size: 6rem 6rem, 1.5rem 1.5rem; background-position: center;
  transition: box-shadow .2s var(--ease);
}
.im-mat canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.im-desk[data-image="ready"]:not([data-mode="browse"]) .im-mat canvas { cursor: crosshair; }
.im-desk:is([data-creating], [data-loading]) .im-mat canvas { cursor: progress; }
/* an armed mark rings the mat: the next click on it places something */
.im-desk[data-image="ready"]:not([data-mode="browse"]) .im-mat { box-shadow: inset 0 0 0 2px var(--signal); }
.im-busy {
  position: absolute; inset: 0 0 auto; height: 3px; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--signal), transparent) 0 0 / 40% 100% no-repeat;
  animation: im-scan 1.2s linear infinite;
}

/* the empty mat explains the task in the canvas's own mark colours; it never pretends to be a map */
.im-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 1rem; overflow: auto; color: var(--mat-ink); }
.im-frame {
  --c: var(--mat-dot-2);
  position: relative; display: grid; justify-items: center; gap: .625rem; width: min(100%, 28rem); padding: 1.5rem 1.25rem 1.25rem; text-align: center;
}
.im-frame::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(var(--c), var(--c)) left top / 1.25rem 2px no-repeat, linear-gradient(var(--c), var(--c)) left top / 2px 1.25rem no-repeat,
    linear-gradient(var(--c), var(--c)) right top / 1.25rem 2px no-repeat, linear-gradient(var(--c), var(--c)) right top / 2px 1.25rem no-repeat,
    linear-gradient(var(--c), var(--c)) left bottom / 1.25rem 2px no-repeat, linear-gradient(var(--c), var(--c)) left bottom / 2px 1.25rem no-repeat,
    linear-gradient(var(--c), var(--c)) right bottom / 1.25rem 2px no-repeat, linear-gradient(var(--c), var(--c)) right bottom / 2px 1.25rem no-repeat;
}
.im-desk[data-drop="over"] .im-frame { --c: var(--signal); }
.im-desk[data-drop="over"] .im-mat { box-shadow: inset 0 0 0 2px var(--signal); }
.im-schema { width: min(100%, 15rem); height: auto; overflow: visible; }
.im-s-area { fill: rgb(32 169 95 / .08); stroke: var(--k-area); stroke-width: 1.5; stroke-dasharray: 5 4; }
.im-s-scale { stroke: var(--k-scale); stroke-width: 3; stroke-linecap: round; }
.im-s-end { fill: var(--k-scale); stroke: var(--mat); stroke-width: 1.5; }
.im-s-o { fill: var(--k-origin); stroke: var(--mat); stroke-width: 1.5; }
.im-s-ox { fill: none; stroke: var(--k-origin); stroke-width: 1.5; }
.im-schema text { fill: var(--mat-ink); font: 600 12px var(--f-num); }
.im-empty-title { margin: .25rem 0 0; font: 600 1.25rem/1.25 var(--f-display); color: var(--mat-ink); overflow-wrap: anywhere; }
.im-desk[data-image="error"] .im-empty-title { color: var(--mat-warn); }
.im-empty-body { max-width: 24rem; margin: 0; font: 400 .875rem/1.5 var(--f-ui); color: var(--mat-ink-2); }
.im-pick {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: var(--hit); margin-top: .25rem; padding: 0 1.125rem;
  border-radius: 999px; background: var(--signal); color: var(--on-signal); font: 650 .9375rem/1.1 var(--f-ui); cursor: pointer;
}
.im-pick:hover { background: color-mix(in oklab, var(--signal) 86%, #fff); }
.im-desk[data-creating] .im-pick { opacity: .5; cursor: not-allowed; }
.im-drop { margin: 0; font: 500 .8125rem/1.4 var(--f-ui); color: var(--mat-ink-2); }
.im-desk[data-image="loading"] .im-schema { animation: im-blink 1.4s ease-in-out infinite; }

/* the legend: what each canvas mark means, beneath the map rather than over it */
.im-legend { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; min-width: 0; padding: .5rem .75rem; border-top: 1px solid var(--rule); font: 500 .8125rem/1.35 var(--f-ui); color: var(--ink-2); }
.im-k { display: inline-flex; align-items: center; gap: .4375rem; }
.im-k::before { content: ""; flex: none; }
.im-k[data-k="scale"]::before { width: 1.25rem; height: 3px; border-radius: 2px; background: var(--k-scale); }
.im-k[data-k="origin"]::before { width: .625rem; height: .625rem; border-radius: 50%; background: var(--k-origin); }
.im-k[data-k="area"]::before { width: .875rem; height: .625rem; border: 2px solid var(--k-area); background: rgb(32 169 95 / .1); }
.im-hint { margin-left: auto; color: var(--ink-3); }
@media (max-width: 29.99rem) {
  .im-tool > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .im-hint { margin-left: 0; flex-basis: 100%; }
}

/* ---- the ledger: hairline registers on one plate, not a stack of cards */
.im-ledger { container-type: inline-size; display: grid; min-width: 0; border: 1px solid var(--rule-2); border-radius: .5rem; background: var(--plate); overflow: hidden; }
.im-reg { position: relative; display: grid; gap: .625rem; min-width: 0; padding: .875rem 1rem 1rem; border-bottom: 1px solid var(--rule); }
.im-reg::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: transparent; transition: background-color .2s var(--ease); }
.im-reg[data-next]::before { background: var(--signal); }
.im-reg[data-active]::before { background: var(--ink); }
.im-reg-head { display: flex; align-items: center; gap: .625rem; min-width: 0; margin: 0; }
.im-reg-head h3, .im-disc-name { flex: 1 1 auto; min-width: 0; margin: 0; font: 650 1rem/1.25 var(--f-display); overflow-wrap: anywhere; }
.im-no {
  flex: none; display: grid; place-items: center; width: 1.75rem; height: 1.75rem; border: 1px solid var(--ink-3); border-radius: var(--r);
  font: 700 .75rem/1 var(--f-num); color: var(--ink-2); transition: background-color .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease);
}
.im-reg[data-done] .im-no { border-color: var(--ok); background: var(--ok); color: var(--field); }
.im-reg:is([data-next], [data-active]) .im-no { border-color: var(--slab); background: var(--slab); color: var(--signal); }
.im-state { flex: none; max-width: 50%; font: 600 .8125rem/1.25 var(--f-ui); color: var(--ink-3); text-align: end; overflow-wrap: anywhere; }
.im-reg[data-done] .im-state { color: var(--ok); }
.im-reg[data-active] .im-state { color: var(--ink); }
.im-reg-body { display: grid; gap: .625rem; min-width: 0; }

.im-field { display: grid; gap: .3125rem; min-width: 0; }
.im-field > span:first-child { font: 600 .8125rem/1.3 var(--f-ui); color: var(--ink-2); }
.im-field input {
  width: 100%; min-width: 0; min-height: var(--hit); padding: .5rem .75rem; border: 1px solid var(--rule-2); border-radius: var(--r);
  background: var(--field); color: var(--ink); font: 400 1rem/1.3 var(--f-ui);
}
.im-field input:hover:not(:disabled) { border-color: var(--ink-3); }
.im-field input:invalid { border-color: var(--alert); }
.im-field input:disabled { background: var(--plate-2); color: var(--ink-3); cursor: not-allowed; }
.im-unit { position: relative; display: block; }
.im-unit input { padding-right: 2.25rem; font-family: var(--f-num); font-variant-numeric: tabular-nums; }
.im-unit b { position: absolute; right: .75rem; top: 50%; transform: translateY(-50%); font: 600 .875rem/1 var(--f-num); color: var(--ink-3); pointer-events: none; }

.im-act {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: var(--hit); padding: .375rem .875rem;
  border: 1px solid var(--rule-2); border-radius: var(--r); background: var(--field); color: var(--ink); font: 600 .875rem/1.2 var(--f-ui); text-align: center;
  transition: border-color .15s var(--ease), background-color .15s var(--ease), color .15s var(--ease);
}
.im-act:hover:not(:disabled) { border-color: var(--ink-3); }
.im-act:is([aria-pressed="true"], .primary) { border-color: var(--slab); background: var(--slab); color: var(--on-slab); }
.im-act:is([aria-pressed="true"], .primary) .im-i { color: var(--signal); }
.im-act:disabled { color: var(--ink-3); cursor: not-allowed; }
.im-reg-body > .im-act { justify-self: start; }
.im-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); gap: .5rem; }

.im-file {
  position: relative; display: flex; align-items: center; gap: .625rem; min-height: 3.25rem; padding: .5rem .875rem;
  border: 1px dashed var(--ink-3); border-radius: var(--r); background: var(--field); font: 600 .9375rem/1.25 var(--f-ui); cursor: pointer;
}
.im-file input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.im-file:hover { border-color: var(--ink); }
.im-file:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }
.im-file:has(input:disabled) { color: var(--ink-3); }
.im-file input:disabled { cursor: not-allowed; }
.im-file .im-i { width: 1.25rem; height: 1.25rem; color: var(--ok); }
.im-desk[data-image="ready"] .im-file { border-style: solid; border-color: var(--rule-2); }
.im-meta { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .125rem .75rem; margin: 0; font: 500 .8125rem/1.4 var(--f-num); color: var(--ink-2); overflow-wrap: anywhere; }
.im-meta b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.im-note { margin: 0; font: 400 .8125rem/1.45 var(--f-ui); color: var(--ink-2); }
.im-note[data-tone="warn"] { padding-left: .625rem; border-left: 3px solid var(--warn); color: var(--ink); }

/* 04 folds: its whole head is the disclosure button */
.im-reg-opt > .im-reg-head { display: block; }
.im-disc {
  display: flex; align-items: center; gap: .625rem; width: calc(100% + 1rem); min-height: var(--hit); margin: -.375rem -.5rem;
  padding: .375rem .5rem; border: 0; border-radius: var(--r); background: transparent; color: var(--ink); text-align: start;
}
.im-disc:hover { background: var(--plate-2); }
.im-chev { color: var(--ink-3); transition: transform .2s var(--ease); }
.im-disc[aria-expanded="true"] .im-chev { transform: rotate(90deg); }

/* ---- creating is its own last act, on its own sheet (the slab in dark; in light a raised sheet, below), with its
   checklist and the engine's summary */
.im-save { display: grid; gap: .75rem; min-width: 0; padding: 1rem; background: var(--slab); color: var(--on-slab); }
.im-save :focus-visible { outline-color: var(--signal); }
.im-save-title { display: flex; align-items: center; gap: .5rem; margin: 0; font: 650 1.0625rem/1.25 var(--f-display); }
.im-save-title .im-i { color: var(--signal); }
.im-checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .375rem .75rem; margin: 0; padding: 0; list-style: none; font: 500 .8125rem/1.3 var(--f-ui); color: var(--on-slab-2); }
.im-checks li { display: flex; align-items: center; gap: .5rem; min-width: 0; overflow-wrap: anywhere; }
.im-checks li::before { content: ""; flex: none; width: .75rem; height: .75rem; border: 1.5px solid var(--on-slab-2); border-radius: 50%; }
.im-checks li[data-ok] { color: var(--on-slab); }
.im-checks li[data-ok]::before { border-color: var(--signal); background: var(--signal); box-shadow: inset 0 0 0 2px var(--slab); }
.im-summary { margin: 0; padding: .625rem .75rem; border-radius: var(--r); background: rgb(237 236 229 / .07); font: 400 .8125rem/1.5 var(--f-ui); color: var(--on-slab-2); overflow-wrap: anywhere; }
.im-create {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; width: 100%; min-height: 3rem; padding: .5rem 1rem;
  border: 1px solid var(--on-slab-2); border-radius: var(--r); background: transparent; color: var(--on-slab); font: 650 .9375rem/1.2 var(--f-ui);
  transition: background-color .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease);
}
.im-create:hover:not(:disabled) { border-color: var(--on-slab); }
.im-desk[data-ready] .im-create:not(:disabled) { border-color: var(--signal); background: var(--signal); color: var(--on-signal); }
.im-create:disabled { opacity: .5; cursor: not-allowed; }
.im-desk[data-creating] .im-create {
  opacity: 1; cursor: progress; animation: im-tape 1.2s linear infinite;
  background: repeating-linear-gradient(90deg, rgb(237 236 229 / .1) 0 .5rem, transparent .5rem 1rem) 0 0 / 200% 100%;
}
.im-save-note { margin: 0; font: 400 .8125rem/1.45 var(--f-ui); color: var(--on-slab-2); }
.im-save-note:empty { display: none; }
.im-save-note[data-tone="warn"] { padding-left: .625rem; border-left: 3px solid #ffc23d; color: var(--on-slab); }
.im-save-note[data-tone="ok"] { color: var(--on-slab); }
.im-result { display: grid; gap: .125rem; padding: .75rem .875rem; border: 1px solid var(--signal); border-radius: var(--r); animation: im-in .32s var(--ease) both; }
.im-result-k { margin: 0; font: 600 .8125rem/1.3 var(--f-ui); color: var(--signal); }
.im-result-name { margin: 0; font: 600 1.125rem/1.3 var(--f-display); overflow-wrap: anywhere; }
.im-result-n { margin: 0 0 .5rem; font: 500 .875rem/1.3 var(--f-num); font-variant-numeric: tabular-nums; color: var(--on-slab-2); }
.im-onward {
  display: inline-flex; align-items: center; justify-content: space-between; gap: .5rem; min-height: var(--hit); padding: 0 .75rem 0 .875rem;
  border-radius: var(--r); background: var(--on-slab); color: var(--slab); font: 650 .875rem/1.2 var(--f-ui); text-decoration: none;
}
.im-onward:hover { background: color-mix(in oklab, var(--on-slab) 85%, var(--signal)); }
/* in light the last act is a raised sheet, not a black block: inside it the slab tokens map to the page's sheet and ink;
   the signal stays the fill of what is ready, and what was signal-coloured text or line reads in the ok green */
:root:not([data-theme="dark"]) .im-save { --slab: var(--plate); --on-slab: var(--ink); --on-slab-2: var(--ink-3); box-shadow: inset 0 0 0 1px var(--rule-2), inset 0 3px 0 var(--ink); }
:root:not([data-theme="dark"]) .im-save :focus-visible { outline-color: var(--ink); }
:root:not([data-theme="dark"]) .im-save :is(.im-save-title .im-i, .im-result-k) { color: var(--ok); }
:root:not([data-theme="dark"]) .im-result { border-color: var(--ok); }
:root:not([data-theme="dark"]) .im-summary { background: var(--rule); }
:root:not([data-theme="dark"]) .im-desk[data-creating] .im-create { background: repeating-linear-gradient(90deg, var(--rule) 0 .5rem, transparent .5rem 1rem) 0 0 / 200% 100%; }
:root:not([data-theme="dark"]) .im-save-note[data-tone="warn"] { border-left-color: var(--warn); }

/* a wide ledger (one-column tablets): each register's name sits beside its controls, like a printed form */
@container (min-width: 40rem) {
  .im-reg { grid-template-columns: 14rem minmax(0, 1fr); column-gap: 1.5rem; align-items: start; }
  .im-reg > .im-reg-head { flex-wrap: wrap; }
  .im-reg > header.im-reg-head .im-state { flex-basis: 100%; max-width: none; padding-left: 2.375rem; text-align: start; }
  .im-save { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-flow: row dense; column-gap: 1.5rem; align-items: start; }
  .im-save > * { grid-column: 1; }
  .im-save > .im-save-title { grid-column: 1 / -1; }
  .im-save > :is(.im-create, .im-save-note, .im-result) { grid-column: 2; }
}

/* ---- the ledger dresses each mark register in its canvas colour, so the register and the mark it places read as one */
#imHScale::after, #imHOrigin::after, .im-disc-name::after { content: ""; display: inline-block; margin-inline-start: .5rem; vertical-align: middle; }
#imHScale::after { width: 1.125rem; height: 3px; border-radius: 2px; background: var(--k-scale); }
#imHOrigin::after { width: .5625rem; height: .5625rem; border-radius: 50%; background: var(--k-origin); }
.im-disc-name::after { width: .8125rem; height: .5625rem; border: 2px solid var(--k-area); background: rgb(32 169 95 / .1); }
/* a number is a few digits and a unit; a description is a sentence. Neither spans a whole wide column. */
.im-unit { max-width: 10rem; }
.im-field > input { max-width: 32rem; }
/* 02: the known distance and the button that marks it sit on one line when there is room */
#imRegScale .im-reg-body { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .625rem .5rem; }
#imRegScale .im-field { flex: 0 1 8rem; }
#imRegScale .im-act { flex: 0 1 auto; }
#imRegScale .im-note { flex: 1 0 100%; }
.im-k { flex: none; white-space: nowrap; }

/* ---- layout. One rule governs every size: the mat's box follows the viewport and the loaded image's proportions only,
   never text in the strip, legend or ledger. The engine re-fits its canvas on window resize and image load alone, so a mat
   resized for any other reason would show a stretched bitmap under clicks that land somewhere else. */
html { scrollbar-gutter: stable; }
.im-stage { container: im-stage / inline-size; }
.im-desk { padding-top: .75rem; }
.im-mat { --im-legend: calc(2.125rem + 1px); }
/* the legend keeps a known height: one line where the keys and the hint fit, otherwise the hint takes its own line */
@container im-stage (min-width: 52rem) {
  .im-legend { flex-wrap: nowrap; }
  .im-hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@container im-stage (max-width: 51.99rem) {
  .im-hint { flex-basis: 100%; margin-left: 0; }
  .im-mat { --im-legend: calc(3.5rem + 1px); }
}
@container im-stage (max-width: 20rem) {
  .im-strip { flex-wrap: wrap; }
  .im-status { order: 1; flex-basis: 100%; }
  .im-tool { margin-left: auto; }
}
/* a narrow strip reserves three status lines, so the map does not hop as the engine's prompts change length */
@media (max-width: 47.99rem) {
  .im-status { min-height: 3.9em; font-size: .8125rem; line-height: 1.3; }
}
@media (pointer: coarse) and (max-width: 47.99rem), (pointer: coarse) and (max-height: 32rem) {
  .im-drop { display: none; }
}

/* one column (phones, tablets upright). Empty, the mat is only as tall as its explanation, so 01 follows at once.
   Loaded, it takes the image's own proportions up to a share of the screen: no dead mat above the next action. */
@media (max-width: 55.99rem) and (min-height: 32.01rem), (max-width: 39.99rem) {
  .im-desk:not([data-image="ready"]) .im-mat { height: auto; min-height: 15rem; }
  .im-desk:not([data-image="ready"]) .im-empty { position: relative; inset: auto; overflow: visible; }
  .im-desk[data-image="ready"] .im-mat {
    height: clamp(13rem, calc((100vw - var(--pad-l) - var(--pad-r) - 2px - 2rem) / var(--im-aspect, 1.6) + 2rem), 42svh);
  }
  .im-frame { padding: 1.25rem 1rem 1rem; }
  .im-schema { width: min(100%, 12rem); }
}
/* …and with room to spare, the loaded bench holds under the header while the ledger passes beneath it,
   so every register's button is one tap from the map it marks. Typing on a touch keyboard releases it. */
@media (max-width: 55.99rem) and (min-height: 32.01rem) {
  .im-desk[data-image="ready"] .im-stage { position: sticky; top: var(--im-top); z-index: 6; box-shadow: 0 .875rem 1rem -1rem rgb(0 0 0 / .55); }
  html:has(.im-desk[data-image="ready"]) { scroll-padding-top: calc(var(--im-top) + var(--im-stage-h, 0px) + .75rem); }
}
@media (max-width: 55.99rem) and (min-height: 32.01rem) and (pointer: coarse) {
  .im-desk[data-image="ready"][data-im-editing] .im-stage { position: relative; box-shadow: none; }
  html:has(.im-desk[data-image="ready"][data-im-editing]) { scroll-padding-top: calc(var(--im-top) + .5rem); }
}

/* two columns: the bench fills the screen beneath the header and stays put; the ledger beside it scrolls with the page */
@media (min-width: 56rem) and (min-height: 32.01rem) {
  :root { --im-bar: calc(3.5rem + 1px); --im-ledger: 23rem; }
  .im-desk { grid-template-columns: minmax(0, 1fr) var(--im-ledger); padding-bottom: 2.5rem; }
  .im-stage { position: sticky; top: calc(var(--im-top) + .75rem); }
  /* viewport − header − desk gutters (.75rem above and below) − stage borders − strip − legend */
  .im-mat { height: max(18rem, calc(100svh - var(--im-bar) - 1.5rem - 2px - (3.5rem + 1px) - var(--im-legend))); }
  .im-ledger { align-self: start; }
}
@media (min-width: 64rem) and (min-height: 32.01rem) {
  .im-title .im-eyebrow { display: block; }
  .im-title h1 { font-size: 1.25rem; }
}
/* the settings unfold into the header from 64rem; the toggle and its popover are only for narrower screens */
@media (min-width: 64rem) {
  .im-prefs-toggle { display: none; }
  .im-prefs, .im-top[data-prefs="open"] .im-prefs {
    position: static; display: flex; flex-direction: row; align-items: center; gap: .375rem;
    min-width: 0; padding: 0 0 0 .5rem; border: 0; border-left: 1px solid var(--rule-2); border-radius: 0; background: none; box-shadow: none;
  }
  .im-top[data-prefs="open"] .im-prefs :is(.im-quiet, .im-lang select) { width: auto; justify-content: center; }
  .im-top[data-prefs="open"] .im-prefs .im-quiet .im-sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .im-lang select { font-size: .875rem; }
}
@media (min-width: 75rem) and (min-height: 32.01rem) {
  :root { --im-ledger: 25rem; }
  .im-desk { column-gap: 1rem; }
}
@media (min-width: 100rem) and (min-height: 32.01rem) {
  :root { --im-ledger: 27rem; }
  .im-reg { padding: 1rem 1.25rem 1.125rem; }
  .im-save { padding: 1.25rem; }
}

/* short landscape: the bench takes the whole height on the left, the ledger runs down the right, the legend gives way
   to the colour swatches on each register, and the strip keeps its three status lines */
@media (orientation: landscape) and (max-height: 32rem) and (min-width: 40rem) {
  :root { --im-bar: calc(3.25rem + 1px); }
  .im-top { flex-wrap: wrap; min-width: 0; padding-block: .25rem; }
  .im-title .im-eyebrow { display: none; }
  .im-title h1 { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .im-desk { grid-template-columns: minmax(0, 1fr) clamp(17rem, 34vw, 22rem); gap: .5rem; padding: .5rem var(--pad-r) 1.5rem var(--pad-l); }
  .im-stage { position: sticky; top: calc(var(--im-top) + .5rem); }
  .im-strip { padding-block: .25rem; }
  .im-status { min-height: 3.9em; font-size: .8125rem; line-height: 1.3; }
  .im-tool > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .im-legend { display: none; }
  /* viewport − header − desk gutters (.5rem above and below) − stage borders − strip (three lines) */
  .im-mat { height: max(11rem, calc(100svh - var(--im-bar) - 1rem - 2px - (3.675rem + 1px))); }
  .im-frame { gap: .5rem; padding: .75rem; }
  .im-schema { width: min(100%, 8.5rem); }
  .im-empty-title { font-size: 1.0625rem; }
  .im-ledger { align-self: start; }
  .im-reg { gap: .5rem; padding: .75rem .875rem .875rem; }
  .im-save { gap: .625rem; padding: .875rem; }
}
@media (orientation: landscape) and (max-height: 32rem) and (min-width: 40rem) and (max-width: 47.99rem) {
  .im-mark { display: none; }
  /* the dark armed chip still says a mark is live; the status beside it names which */
  .im-mode > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .im-mode { padding: 0 .5rem; }
}

/* Keep a useful ledger viewport when text or the software keyboard outgrows the sticky bench. */
.im-status[data-kind="loaded"] { min-height: 0; }
@media (max-width: 39.99rem) {
  .im-top {
    display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px 44px;
    gap: 8px; padding: 8px max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left));
  }
  .im-home { grid-column: 1; grid-row: 1; }
  .im-title { grid-column: 2; grid-row: 1; }
  .im-top > .im-lib { grid-column: 3; grid-row: 1; }
  .im-prefs-toggle { grid-column: 4; grid-row: 1; }
  .im-top > :is(.im-home, .im-lib, .im-prefs-toggle) { min-width: 44px; min-height: 44px; width: 44px; padding: 8px; }
  .im-top .im-i { width: 22px; height: 22px; }
  .im-mark, #imPrefsCode { display: none; }
  .im-draft { grid-column: 1 / -1; grid-row: 2; justify-self: start; width: auto; min-height: 0; padding: 4px 8px; }
  .im-draft > span { position: static; width: auto; height: auto; clip-path: none; white-space: normal; }
  .im-draft::before { width: 8px; height: 8px; flex: none; }
  .im-top[data-prefs="open"] .im-prefs { min-width: 0; width: min(16rem, calc(100vw - 16px)); max-height: 65dvh; overflow: auto; }
  .im-desk { padding-top: 12px; }
  .im-strip { gap: 8px; padding: 8px; }
  .im-strip .im-i { width: 22px; height: 22px; }
  .im-strip .im-tool { min-width: 44px; min-height: 44px; width: 44px; padding: 8px; }
  .im-mode { min-height: 44px; padding: 4px 8px; }
}
html[data-im-unpinned] .im-desk .im-stage { position: relative; top: auto; box-shadow: none; }
html[data-im-unpinned]:has(.im-desk[data-image="ready"]) { scroll-padding-top: calc(var(--im-top) + .5rem); }

@media (forced-colors: active) {
  .im-reg:is([data-next], [data-active])::before { background: Highlight; }
  .im-desk[data-image="ready"]:not([data-mode="browse"]) .im-mat { outline: 2px solid Highlight; outline-offset: -2px; }
}

/* ---- motion: each movement reports a real state change. Reduced motion (the lab's choice, else the system's) leaves a
   still equivalent; a hidden tab pauses everything. */
@keyframes im-blink { 50% { opacity: .35; } }
@keyframes im-scan { from { background-position: -67% 0; } to { background-position: 167% 0; } }
@keyframes im-tape { to { background-position: 1rem 0; } }
@keyframes im-in { from { opacity: 0; transform: translateY(.25rem); } }
:root:is([data-motion="reduced"], [data-lab-motion="reduced"]) *,
:root:is([data-motion="reduced"], [data-lab-motion="reduced"]) *::before,
:root:is([data-motion="reduced"], [data-lab-motion="reduced"]) *::after {
  animation: none !important; transition: none !important; scroll-behavior: auto !important;
}
:root:is([data-motion="reduced"], [data-lab-motion="reduced"]) .im-busy { background-size: 100% 100%; opacity: .45; }
:root:is([data-motion="reduced"], [data-lab-motion="reduced"]) .im-desk[data-image="loading"] .im-schema { opacity: .6; }
:root[data-im-hidden] *, :root[data-im-hidden] *::before, :root[data-im-hidden] *::after { animation-play-state: paused !important; }

/* The shared Lab room owns Home, not this page's preference controls. */
:root[data-lab-host] .im-home { display: none !important; }
