/* OCR Lite — Copyright (c) 2026 Bernhard Straub · SPDX-License-Identifier: MIT */
:root {
  --bg: #eef0f3;
  --card: #ffffff;
  --fg: #16181d;
  --muted: #6b7280;
  --faint: #9aa1ad;
  --line: rgba(15, 23, 42, 0.09);
  --hover: rgba(15, 23, 42, 0.06);
  --press: rgba(15, 23, 42, 0.1);
  --accent: #3b6cf6;
  --accent-soft: rgba(59, 108, 246, 0.12);
  --accent-fg: #ffffff;
  --ok: #16a34a;
  --warn: #ea580c;
  --amber: #b45309;
  --bad: #dc2626;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 6px 24px rgba(15, 23, 42, 0.06);
  --stage: #e5e8ed;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --card: #1b1e24;
    --fg: #e8eaee;
    --muted: #9aa1ad;
    --faint: #6b7280;
    --line: rgba(255, 255, 255, 0.08);
    --hover: rgba(255, 255, 255, 0.06);
    --press: rgba(255, 255, 255, 0.1);
    --accent: #5b8cff;
    --accent-soft: rgba(91, 140, 255, 0.16);
    --ok: #4ade80;
    --warn: #fb923c;
    --amber: #fbbf24;
    --bad: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.25);
    --stage: #0d0f12;
  }
}
:root[data-theme="dark"] {
  --bg: #111317; --card: #1b1e24; --fg: #e8eaee; --muted: #9aa1ad; --faint: #6b7280; --line: rgba(255,255,255,.08);
  --hover: rgba(255,255,255,.06); --press: rgba(255,255,255,.1); --accent: #5b8cff; --accent-soft: rgba(91,140,255,.16);
  --ok: #4ade80; --warn: #fb923c; --amber: #fbbf24; --bad: #f87171; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.25); --stage: #0d0f12;
}

* { box-sizing: border-box; }
/* `hidden` must win over every component display rule (.empty / .menu.pop set display: flex — they stayed visible) */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
/* hidden until ui/i18n.js has put the texts of the page's language in */
html:not(.i18n) body { visibility: hidden; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  /* iOS Safari needs the prefix (and no long-press menu): else a press on the image selects the page */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
i[data-icon] { display: inline-flex; width: 16px; height: 16px; }
i[data-icon] svg { width: 100%; height: 100%; }
.grow { flex: 1; }
.meta { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ── buttons ───────────────────────────────────────── */
/* manipulation: no double-tap zoom on iOS — quick presses on one button zoomed the page and the next press hit another */
button { font: inherit; color: inherit; cursor: default; touch-action: manipulation; }
/* min-height, not height: a label that wraps (a narrow screen held upright) makes the button taller, never spills out */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 30px; padding: 3px 12px; text-align: center;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg);
  font-weight: 500; transition: background 0.12s;
}
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:active:not(:disabled) { background: var(--press); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-fg); box-shadow: 0 1px 2px rgba(59, 108, 246, 0.35); }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn.stop { background: var(--warn); border-color: transparent; color: #fff; }
.btn.small { min-height: 26px; padding: 2px 10px; font-size: 12px; }
.btn.toggle.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.ib {
  display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 30px; padding: 0 7px;
  border: 0; border-radius: 7px; background: transparent; color: var(--fg); font-size: 14px;
}
.ib:hover:not(:disabled) { background: var(--hover); }
.ib:active:not(:disabled) { background: var(--press); }
.ib.on { background: var(--accent-soft); color: var(--accent); }
button:disabled { opacity: 0.35; }
.seg { display: inline-flex; align-items: center; gap: 1px; padding: 2px; border-radius: 9px; background: var(--hover); }
.seg .div { width: 1px; height: 16px; background: var(--line); margin: 0 3px; }

/* ── title bar ───────────────────────────────────────────────────────── */
.titlebar {
  /* wraps instead of overflowing: a header wider than the viewport makes iPadOS Safari shrink the page to fit */
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 14px; flex-wrap: wrap;
}
/* iPad / phones: keep the bar clear of the status bar and rounded corners (0 unless the page reaches under them) */
.titlebar { padding-top: env(safe-area-inset-top, 0px); padding-right: max(14px, env(safe-area-inset-right, 0px)); }
.titlebar { padding-left: max(14px, env(safe-area-inset-left, 0px)); }
/* iPadOS 26 blurs the page under the status bar (scroll-edge effect; pushing the page down 20 px confirmed it) unless a fixed element ≥ 90 % of the viewport wide and > 10 px tall sits at the top edge — then the
   status bar takes that element's colour, solid (WebKit's rule as described in coder/xum PR #7022). This band qualifies
   and paints nothing: its background is clipped to its (absent) text; taps pass through. */
.edgeband { position: fixed; top: 0; left: 0; right: 0; height: 12px; z-index: 2147483647; pointer-events: none;
  background: var(--bg); -webkit-background-clip: text; background-clip: text; }
.select { flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; margin-right: 6px; }
.logo { width: 20px; height: 20px; border-radius: 6px; background: linear-gradient(160deg, #3f6ce0, #1a3283); position: relative; }
.logo::after { content: ""; position: absolute; inset: 4px 5px; border-radius: 2px; background: #f7f3e8; }
.select select {
  height: 30px; padding: 0 28px 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--fg);
  font: inherit; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 13px, calc(100% - 10px) 13px; background-size: 5px 5px; background-repeat: no-repeat;
}

/* ── cards ─────────────────────────────────────────── */
main { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; padding: 0 12px; min-height: 0; }
/* a phone on its side (little height): one compact title bar row (the name only as the logo), slimmer card heads,
   the status line without the engine details (Settings and About show them) */
@media (orientation: landscape) and (max-height: 500px) {
  .titlebar { gap: 6px; min-height: 44px; }
  .brandname { display: none; }
  .select select { max-width: 150px; }
  .cardhead { min-height: 38px; padding: 4px 8px 4px 12px; gap: 6px; }
  .statusbar { height: 26px; }
  .statusbar #backendInfo { display: none; }
  main { gap: 8px; }
}
/* a phone on its side: the notch / Dynamic Island sits left or right */
main { padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); }
/* one column only for a narrow screen held upright; a phone on its side (812 px with Display Zoom) keeps image and
   text side by side, like the iPad in both orientations */
@media (max-width: 820px) and (orientation: portrait) {
  /* the status line may take two lines; the engine details are in Settings and About */
  .statusbar { height: auto; min-height: 34px; }
  .statusbar #backendInfo { display: none; }
}
body.stacked main { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.cardhead { display: flex; align-items: center; gap: 8px; min-height: 46px; padding: 8px 10px 8px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.label { font-weight: 600; font-size: 13px; margin-right: 4px; }

/* image */
.imgwrap { flex: 1; min-height: 0; position: relative; overflow: auto; display: flex; padding: 18px; background: var(--stage);
  background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 16px 16px; }
#stage { position: relative; margin: auto; line-height: 0; cursor: grab; touch-action: none; }
#stage.cropping { cursor: crosshair; }
/* the image's size is set by app.js (fit × zoom); the pane scrolls when it is larger; touch gestures are app.js's own */
.imgwrap { touch-action: none; }
#img { display: block; border-radius: 4px; box-shadow: 0 2px 14px rgba(0, 0, 0, 0.18); -webkit-user-drag: none; pointer-events: none; }
#stage.zoomed #img { border-radius: 0; box-shadow: none; }
#rect { position: absolute; border: 1.5px solid var(--accent); border-radius: 2px; box-shadow: 0 0 0 9999px rgba(10, 14, 22, 0.45); pointer-events: none; }
.empty { margin: auto; text-align: center; color: var(--muted); font-size: 15px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty .sub { font-size: 12px; color: var(--faint); }
/* the five steps (the empty pane, cloned into the How to dialog): number · the control as it looks · what to do */
.howsteps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; text-align: left; }
.empty .howsteps { padding: 16px 18px; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); max-width: 440px; }
.howsteps li { display: grid; grid-template-columns: 26px 72px minmax(0, 1fr); align-items: center; gap: 10px; }
.howsteps .hn { width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; }
.howsteps .hic { display: flex; gap: 4px; justify-content: center; }
.chip { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 28px; padding: 0 8px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--fg); font-size: 12px; font-weight: 500; }
.chip.ok { background: #16a34a; color: #fff; border-color: transparent; }
.chip.ok svg { stroke-width: 2.6; }
.chip.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.howsteps .ht { display: flex; flex-direction: column; gap: 1px; }
.howsteps .ht b { color: var(--fg); font-size: 14px; font-weight: 600; }
.howsteps .ht span { color: var(--muted); font-size: 12px; line-height: 1.35; }
.helpbody .howsteps { margin: 6px 0 10px; }
.tips { margin: 0 0 6px; padding-left: 20px; }
.tips li { margin-bottom: 4px; }
.empty a { color: var(--accent); text-decoration: none; }
.imgwrap.dragover { outline: 2px dashed var(--accent); outline-offset: -10px; }

/* text */
#editor { flex: 1; min-height: 0; overflow: auto; padding: 22px 28px; outline: none; -webkit-user-select: text; user-select: text; cursor: text; }
#editor:empty::before { content: attr(data-placeholder); color: var(--faint); font-family: -apple-system, system-ui, sans-serif; font-size: 14px; }
#editor[contenteditable="false"] { cursor: default; }
/* a finger's swipe scrolls the text straight away, and stops at its ends instead of pulling the page */
#editor, #src { touch-action: pan-x pan-y; overscroll-behavior: contain; }
/* Fit (app.js fitText): no wrapping — every line as written; the font size is set so the widest line fits */
#editor.fit .l, #editor.fit table.t td { white-space: pre; overflow-wrap: normal; }
#src { flex: 1; min-height: 0; resize: none; border: 0; outline: none; padding: 18px 22px; background: var(--card); color: var(--fg);
  font: 13px/1.6 ui-monospace, "SF Mono", Menlo, monospace; tab-size: 8; -webkit-user-select: text; user-select: text; }
.fmt { font-family: "Iowan Old Style", Georgia, serif; font-size: 15px; min-width: 30px; }
.fmt del, .fmt ins, .fmt u { color: inherit; }
.fmt ins { text-decoration: none; background: rgba(52, 199, 89, 0.22); border-radius: 2px; padding: 0 2px; }
.fmt sup, .fmt sub { font-size: 0.65em; }
.menuwrap { position: relative; }
.menu { position: absolute; right: 0; top: 34px; z-index: 5; min-width: 210px; padding: 5px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.menu button { display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--fg); }
.menu button:hover { background: var(--accent); color: var(--accent-fg); }

/* status */
.statusbar { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 20px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.dot.busy { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.dot.ok { background: var(--ok); }
.dot.err { background: var(--warn); }
#status.err { color: var(--warn); }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ── settings ──────────────────────────────────────── */
dialog { background: var(--card); color: var(--fg); border: 0; border-radius: 16px; padding: 0; width: min(980px, 94vw); box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35); }
/* no backdrop-filter: the only blur in the UI, and a suspect for the iPad's soft top band */
dialog::backdrop { background: rgba(10, 14, 22, 0.45); }
dialog form { padding: 18px 22px 20px; }
.dlghead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
dialog h2 { margin: 0; font-size: 17px; }
.group { padding: 12px 0; border-top: 1px solid var(--line); }
.group h3 { margin: 0 0 8px; font-size: 13px; display: flex; gap: 8px; align-items: baseline; }
.hint { color: var(--muted); margin: 4px 0 8px; font-size: 12px; }
.fields { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; }
.field { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 8px; color: var(--muted); }
.field.wide { display: flex; }
.field.wide input { flex: 1; }
input[type="text"], input[type="number"] {
  height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); font: inherit; -webkit-user-select: text; user-select: text;
}
input[type="number"] { width: 96px; }
input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.switch { display: inline-flex; align-items: center; gap: 8px; }
.switch input { display: none; }
.switch span { width: 34px; height: 20px; border-radius: 99px; background: var(--press); position: relative; transition: background 0.15s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: left 0.15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { left: 16px; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
#presetTable { border-collapse: collapse; width: max-content; min-width: 100%; }
#presetTable th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; padding: 8px 6px; background: var(--hover); white-space: nowrap; }
#presetTable td { padding: 4px 6px; border-top: 1px solid var(--line); }
#presetTable input { height: 28px; }
#presetTable input[type="number"] { width: 9ch; min-width: 0; text-align: right; padding: 0 6px; }
#presetTable th:not(:first-child) { text-align: right; }
#presetTable input[readonly] { background: transparent; border-color: transparent; }
#presetTable tr.shipped td:first-child input { font-weight: 600; }
/* up to 900 px wide (a phone either way up, a tablet held upright) the 9 columns do not fit: each preset is a card —
   its name across the top, the values as label · value pairs side by side, Duplicate / Delete at the bottom right */
@media (max-width: 900px) {
  #presetWrap { overflow-x: visible; border: 0; }
  #presetTable, #presetTable tbody { display: block; width: 100%; }
  #presetTable tr:first-child { display: none; }
  #presetTable tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 4px 14px; padding: 10px 12px;
    margin-bottom: 8px; border: 1px solid var(--line); border-radius: 10px; }
  #presetTable td { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 0; border: 0; }
  #presetTable td::before { content: attr(data-label); color: var(--muted); font-size: 12px; }
  #presetTable td.f-name, #presetTable td.act { grid-column: 1 / -1; }
  #presetTable td.f-name::before, #presetTable td.act::before { content: none; }
  #presetTable td.f-name input { width: 100% !important; }
  #presetTable input[type="number"] { width: 7ch; }
  #presetTable td.act { justify-content: flex-end; }
  /* an editable (own) preset: its fields look like fields */
  #presetTable tr:not(.shipped) { border-color: var(--accent); }
}
.err { color: var(--warn); min-height: 1.2em; margin: 6px 0 0; }
.dlgfoot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.prelines { white-space: pre-line; }
#crashCheck.err { color: var(--warn); }

/* auto-crop popover */
.menu.pop { left: 0; right: auto; min-width: 340px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.menu.pop .seg .ib { padding: 0 10px; font-size: 12px; }
.menu.pop .switch { color: var(--fg); }
.poprow { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#rect.auto { border-style: dashed; }
/* the model storage (Settings): one entry for the model — name · version, the small print, its state */
#modelProgress { width: 100%; }
.modelentry { padding: 10px 12px; margin: 6px 0 8px; border: 1px solid var(--line); border-radius: 10px; }
.modelentry .mname { font-weight: 600; font-size: 14px; }
.modelentry .hint { margin: 2px 0 0; }
.modelentry .mstate { margin-top: 4px; color: var(--accent); font-weight: 500; }
.modelentry .mstate:empty { display: none; }
/* expert mode (app.js): the presets and the technical details only then; the bar keeps its places (Read stays last) */
body:not(.expert) .expert-only { display: none !important; }

/* ── the read's scan overlay (scan.js) over the page image ───────────── */
.scan { position: absolute; inset: 0; pointer-events: none; border-radius: 4px; overflow: hidden; }
.scan-grid { position: absolute; inset: 0; width: 100%; height: 100%; transition: opacity 0.8s ease; }
.scan-line { position: absolute; left: 0; right: 0; top: 0; height: 2px; will-change: transform;
  background: var(--accent); box-shadow: 0 0 10px 2px var(--accent), 0 0 26px 6px var(--accent-soft); transition: opacity 0.6s ease; }
/* the faint trail above the line */
.scan-line::before { content: ""; position: absolute; left: 0; right: 0; bottom: 2px; height: 56px;
  background: linear-gradient(to top, var(--accent-soft), transparent); }
.scan-outline { position: absolute; inset: 0; border-radius: 4px; opacity: 0; }
.scan.prompt .scan-grid, .scan.prompt .scan-line { opacity: 0; }
.scan.prompt .scan-outline { animation: scanPulse 1.8s ease-in-out infinite; }
@keyframes scanPulse {
  0%, 100% { opacity: 0.35; box-shadow: inset 0 0 0 2px var(--accent); }
  50% { opacity: 1; box-shadow: inset 0 0 0 2px var(--accent), inset 0 0 22px var(--accent-soft); }
}
.scan-bar { display: none; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--accent-soft); }
.scan-bar span { display: block; height: 100%; width: 0; background: var(--accent); }
.scan.still .scan-bar { display: block; }
.scan.still .scan-grid, .scan.still .scan-line, .scan.still .scan-outline { display: none; }

/* ── browser build: "new version" banner (web/pwa.js) ──────────────── */
.updbar { position: fixed; left: 50%; bottom: 46px; transform: translateX(-50%); z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 14px; border-radius: 12px; background: var(--card); color: var(--fg); box-shadow: var(--shadow); border: 1px solid var(--line); }
/* the tips (tip.js): a manual popover — the top layer, above an open dialog; placed by tip.js */
#tip { position: fixed; inset: auto; margin: 0; max-width: min(340px, calc(100vw - 8px)); padding: 5px 9px; border: 1px solid var(--line);
  border-radius: 7px; background: var(--card); color: var(--fg); box-shadow: var(--shadow); font-size: 12px; line-height: 1.4;
  pointer-events: none; white-space: normal; overflow-wrap: anywhere; }
/* a status message with a link (e.g. Set up OCR Lite) */
#status a { color: var(--accent); }

/* about */
button.brand { border: 0; background: transparent; color: inherit; padding: 4px 6px; border-radius: 8px; font: inherit; font-weight: 600; font-size: 14px; }
button.brand:hover { background: var(--hover); }
dialog.about { width: min(540px, 92vw); }
dialog.about h2 { display: flex; align-items: center; gap: 10px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 8px 0 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; -webkit-user-select: text; user-select: text; overflow-wrap: anywhere; }
dialog.about { max-height: 90vh; }
dialog.about form { max-height: 90vh; overflow-y: auto; }
/* the licences scroll in their own box (the list of training sources is long); the facts above stay in view */
.lic { border-top: 1px solid var(--line); padding-top: 10px; font-size: 12px; -webkit-user-select: text; user-select: text;
  max-height: 46vh; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding-right: 6px; }
.lic ul.srcs { margin: 4px 0 6px; }
.lic ul.srcs li { margin-bottom: 4px; }
.lic h3 { margin: 0 0 6px; font-size: 13px; }
.lic dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.lic dt { color: var(--muted); }
.lic dd { margin: 0; overflow-wrap: anywhere; }
.lic ul { margin: 0; padding-left: 16px; }
.lic a { color: var(--accent); }
@media (max-width: 520px) { .lic dl { grid-template-columns: 1fr; gap: 2px; } .lic dd { margin-bottom: 6px; } }
/* zoom readout */
.zoomval { min-width: 46px; text-align: center; font-size: 12px; }

/* help: one scrolling body like the About box */
dialog.help { width: min(600px, 92vw); }
.helpbody { border-top: 1px solid var(--line); padding-top: 4px; font-size: 13px; -webkit-user-select: text; user-select: text; }
.helpbody h3 { margin: 12px 0 4px; font-size: 13px; }
.helpbody p { margin: 0 0 6px; }
.helpbody ol { margin: 0 0 6px; padding-left: 20px; }
.helpbody li { margin-bottom: 3px; }

/* the first-run setup (setup.js) */
dialog.setup { width: min(560px, 94vw); max-height: 90vh; }
dialog.setup h2 { display: flex; align-items: center; gap: 10px; }
dialog.setup form { padding: 0; }
dialog .sheet { padding: 18px 22px 20px; max-height: 90vh; overflow-y: auto; }
.setup section > p { margin: 0 0 8px; }
.setup section { font-size: 13px; }
.steps { display: flex; gap: 6px; list-style: none; margin: 0 0 6px; padding: 0; flex-wrap: wrap; }
.steps li { font-size: 11px; padding: 2px 10px; border-radius: 99px; background: var(--hover); color: var(--faint); }
.steps li.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.steps li.done { color: var(--muted); }
.steps li.done::before { content: "✓ "; }
.setup .dlgfoot { flex-wrap: wrap; align-items: center; margin-top: 12px; }
.setup .dlgfoot.start { justify-content: flex-start; margin: 4px 0 8px; }
.setup input[type="password"] { height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); font: inherit; -webkit-user-select: text; user-select: text; min-width: 0; }
.setup a { color: var(--accent); }
.suhint { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); margin: 6px 0; }
.suhint p { margin: 2px 0 0; color: var(--muted); }
.suother summary { cursor: default; color: var(--muted); font-size: 12px; margin: 4px 0; }
/* an install sheet (setup.js installSheet): title, numbered steps with the menu items' icons inline, the vendor's help */
.instsheet { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); margin: 6px 0; }
.instsheet .insttitle { display: block; font-size: 14px; margin-bottom: 4px; }
.instsheet p { margin: 4px 0; }
.inststeps { margin: 4px 0 6px; padding-left: 22px; }
.inststeps li { margin-bottom: 4px; }
.instsheet i.inl { width: 15px; height: 15px; vertical-align: -3px; margin: 0 2px; }
.instsheet .instbtn { margin: 4px 0 8px; }
/* Chrome's install chip in the address bar, drawn as it looks (light blue pill) — the same in both themes */
.instchip { display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px 1px 6px; border-radius: 99px; background: #d3e3fd;
  color: #041e49; font-size: 12px; font-weight: 500; vertical-align: 1px; white-space: nowrap; }
.instchip i.inl { margin: 0; }
.instmore summary { cursor: default; color: var(--muted); margin: 4px 0; }
.insthelp { font-size: 12px; }
.suthen { margin: 10px 0 4px; font-weight: 500; }
.suother .instsheet { border-style: dashed; }
#suProgress { width: 100%; }
.hint.ok { color: var(--ok); }
/* the device check's verdict (setup.js gpu step): green ok · amber slow · red rejected */
.suverdict { font-weight: 600; padding: 8px 12px; border-radius: 10px; background: var(--hover); border-left: 4px solid var(--line); }
.suverdict.ok { border-left-color: var(--ok); color: var(--ok); }
.suverdict.slow { border-left-color: var(--amber); color: var(--amber); }
.suverdict.bad { border-left-color: var(--bad); color: var(--bad); }
.sudetected, #suGpuProblems { margin: 0 0 6px; padding-left: 20px; overflow-wrap: anywhere; }
#suGpuProblems { color: var(--bad); }
#suGpuProblems:empty, .sudetected:empty { display: none; }
label.btn.disabled { opacity: 0.35; pointer-events: none; }
/* a touch screen without a mouse: no keyboard / mouse hints */
@media (hover: none) and (pointer: coarse) { .kbd { display: none; } }
/* a disabled Read lets the tap through to the page, which says why (app.js explainRead) */
#readBtn:disabled { pointer-events: none; }
/* the control Read waits for, pointed at */
@keyframes attn { 0%, 100% { box-shadow: var(--shadow); } 50% { box-shadow: 0 0 0 3px var(--accent); } }
.attn { animation: attn 0.6s ease-in-out 2; }
/* image above text would leave each too little room: there one card at a time, chosen by the tabs in its head; the
   image steps of the title bar only with the image (app.js setTab) */
/* the tabs (tab mode, body.stacked — app.js): upright one bar at the bottom, above the status line — the same place
   whatever the cards above it do; on a phone's side in the title bar after the logo */
.tabbar { display: none; }
body.stacked .tabbar { display: flex; gap: 4px; margin: 8px 12px 0; padding: 3px; border-radius: 10px; background: var(--hover); }
body.stacked .tabbar button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; height: 40px; border: 0;
  border-radius: 8px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 14px; }
body.stacked .tabbar button.on { background: var(--card); color: var(--accent); box-shadow: var(--shadow); }
body.stacked .titlebar .tabbar { margin: 0; flex-shrink: 0; }
body.stacked .titlebar .tabbar button { flex: none; height: 30px; padding: 0 12px; font-size: 13px; }
body.stacked[data-tab="text"] #imgCard, body.stacked[data-tab="image"] #textCard { display: none; }
/* a phone upright: the text tools in two lines, the title bar of the Text tab in one */
@media (max-width: 480px) and (orientation: portrait) {
  .cardhead { gap: 6px; padding-left: 10px; }
  #presetSel { max-width: 132px; }
}
/* ── the bar: the image's tools in three rows by task (index.html) ─────────────────────────────────────────────────
   On its side (and on a desktop) two lines: Crop · Adjust, then logo · Read row · Help · Settings · preset · Read.
   Upright four: logo · Help · Settings, Crop, Adjust, Read row · preset · Read. The rows keep their height whatever their controls do: the
   image below never moves */
.titlebar { row-gap: 6px; padding-top: max(6px, env(safe-area-inset-top, 0px)); padding-bottom: 6px; }
.titlebar .row { display: flex; align-items: center; gap: 6px; min-height: 34px; min-width: 0; }
.titlebar .brand { margin-right: 0; }
#cropRow { order: 0; }
#adjustRow { order: 1; flex: 1 1 0; }
.rowbreak { order: 2; flex-basis: 100%; height: 0; }
.titlebar .brand, .titlebar > .tabbar { order: 3; }
.appgap { display: none; }
#readRow { order: 4; flex: 1 1 0; }
#appRow { order: 5; gap: 2px; }
/* How to: labelled and tinted — the way in for a first visit; a phone on its side keeps only its icon */
#howBtn { background: var(--accent-soft); color: var(--accent); border-color: transparent; margin-right: 4px; }
#presetBox { order: 6; }
#readBtn { order: 7; }
/* Apply / Cancel: the usual green ✓ and red ✕, filled while a rectangle waits — the same in both themes (white on
   the solid colour) */
#cropAct { gap: 4px; }
/* Auto's mode: the ▾ right beside it, slim; Auto as wide as its longest mode (the row never moves); the menu drops
   below (over the image while open, never moving it) */
#sideBtn, #scaleMenuBtn { min-width: 20px; padding: 0 3px; font-size: 14px; }
#textCropBtn { min-width: 58px; }
#sideMenu { min-width: 130px; }
#sideMenu .menuhead { display: block; padding: 6px 10px 8px; font-weight: 600; white-space: nowrap; }
#sideMenu button:disabled { opacity: 0.4; background: transparent; color: var(--fg); }
#sideMenu button.on::before { content: "✓ "; }
#sideMenu button:not(.on) { padding-left: 24px; }
#scaleMenu { left: 0; right: auto; min-width: 250px; }
#scaleMenu .menuhead { display: block; padding: 6px 10px 8px; font-weight: 600; white-space: nowrap; }
#scaleMenu button { white-space: nowrap; }
#scaleMenu button.on::before { content: "✓ "; }
#scaleMenu button:not(.on) { padding-left: 24px; }
#cropApplyBtn:not(:disabled) { background: #16a34a; color: #fff; }
#cropCancelBtn:not(:disabled) { background: #dc2626; color: #fff; }
#cropApplyBtn:not(:disabled):hover { background: #15803d; }
#cropCancelBtn:not(:disabled):hover { background: #b91c1c; }
#cropAct svg { stroke-width: 2.6; }
.croplabel { color: var(--muted); font-size: 12px; padding: 0 2px 0 4px; }
/* the Scale: label · slider · Auto in one segment; the slider gives way first */
#scaleSeg { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
/* after a read: the wand offers the step by the lines */
#scaleAutoBtn.suggest { color: #fff; background: var(--accent); }
/* what the Scale gives and the model input's size: one line each, never pushing the image smaller */
#scaleInfo, #bakeInfo { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; font-size: 12px; }
/* a fixed width ("×2.71"): nothing moves when the text changes */
#scaleInfo { flex: 0 0 auto; width: 48px; font-variant-numeric: tabular-nums; }
#bakeInfo { flex: 1 1 0; }
/* a phone on its side: a free strip above the first line — iOS pulls Control Center down from the top edge (on the
   right, where the Scale's slider sits) and a drag there moved the slider */
@media (orientation: landscape) and (max-height: 500px) {
  .titlebar { padding-top: max(14px, env(safe-area-inset-top, 0px)); }
  .howlabel { display: none; }
  #howBtn { padding: 2px 8px; }
}
/* upright: the app row on top, then Crop, Adjust, the Read row with Read at its end */
@media (orientation: portrait) {
  .titlebar .brand { order: 0; }
  .appgap { display: block; order: 0; }
  #appRow { order: 0; }
  #cropRow { order: 1; flex-basis: 100%; justify-content: space-between; }
  #adjustRow { order: 2; flex-basis: 100%; }
  .rowbreak { display: none; }
  #readRow { order: 3; }
  #presetBox { order: 4; }
  #readBtn { order: 5; }
}
/* a phone: the zoom by pinch and double tap only; Open as its icon (the crop row fits 375 px) */
@media (max-width: 480px) and (orientation: portrait), (orientation: landscape) and (max-height: 500px) {
  #zoomSeg { display: none; }
  .openlabel { display: none; }
  #openBtn { padding: 0 8px; }
}
@media (max-width: 480px) and (orientation: portrait) {
  .titlebar { gap: 6px; padding-left: max(10px, env(safe-area-inset-left, 0px)); padding-right: max(10px, env(safe-area-inset-right, 0px)); }
  .titlebar .seg { gap: 0; }
  .titlebar .row { gap: 4px; }
  .titlebar .ib { min-width: 28px; padding: 0 5px; }
  #cropSeg .btn.small { padding: 2px 8px; }
  /* the crop's size goes; the model input's stays */
  #bakeInfo .from { display: none; }
}
/* the Text tab: the Read row stays (Read again) and the wand with it (its offer comes after a read, when the Text tab
   shows); the crop row, contrast · pencil and zoom go */
body.stacked[data-tab="text"] #cropRow, body.stacked[data-tab="text"] #adjSeg, body.stacked[data-tab="text"] #zoomSeg { display: none; }
/* tab mode upright: Adjust and Read share one line — contrast · pencil, the wand, its scale, the preset (expert mode,
   narrow), Read; the image's size goes to the scale's tooltip */
@media (orientation: portrait) {
  body.stacked #adjustRow { flex: 0 0 auto; flex-basis: auto; }
  /* the Text tab: the crop row goes — a break keeps the wand on Read's line, not beside the logo */
  body.stacked[data-tab="text"] .rowbreak { display: block; order: 1; }
}
/* a phone on its side, the Text tab: the wand joins the Read line (the first line, crop · adjust, goes) */
@media (orientation: landscape) and (max-height: 500px) {
  body.stacked[data-tab="text"] #adjustRow { order: 4; flex: 0 0 auto; }
}
@media (max-width: 480px) and (orientation: portrait) {
  body.stacked #bakeInfo { display: none; }
  body.stacked #scaleInfo { width: 40px; }
  body.stacked #presetSel { max-width: 92px; }
}
/* the crop rectangle's handles: corners and edge middles — where a finger adjusts it (elsewhere a finger pans); the
   held one filled and larger, so a grab is plain to see */
#rect .hd { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border: 2px solid var(--accent); background: #fff; border-radius: 3px; box-sizing: border-box; }
#rect .lt { left: 0; top: 0; } #rect .rt { left: 100%; top: 0; } #rect .lb { left: 0; top: 100%; } #rect .rb { left: 100%; top: 100%; }
#rect .t { left: 50%; top: 0; } #rect .b { left: 50%; top: 100%; } #rect .l { left: 0; top: 50%; } #rect .r { left: 100%; top: 50%; }
#rect .hd.held { background: var(--accent); transform: scale(1.6); }
/* tab mode: the text with less side padding — Fit gets the width */
body.stacked #editor { padding: 16px 12px; }
body.stacked #src { padding: 14px 12px; }
/* a computer, a tablet on its side (not a phone): ONE flow — logo · Crop · Adjust · Read row, then the end cluster
   (How to · Help · Settings · preset · Read) pushed to the right end by one flexible margin. Whole groups wrap, none
   stretches or breaks inside; the sizes that change with the image (the Scale's slider, its info, the model input) keep
   fixed widths, so nothing hops. The phone layouts (above) place the cluster's parts one by one */
#barEnd { display: contents; }
@media (orientation: landscape) and (min-height: 501px) {
  .titlebar { column-gap: 12px; }
  .titlebar .brand, #cropRow, #adjustRow, #readRow, #appRow, #presetBox, #readBtn { order: 0; }
  .rowbreak, .appgap { display: none; }
  .titlebar .brand, #cropRow, #adjustRow, #readRow, #appRow { flex: 0 0 auto; }
  #bakeInfo { flex: 0 0 auto; width: 176px; }
  /* the zoom first, the size line after it: its fixed width's free end then sits before the flexible margin, not as a
     hole inside the line */
  #zoomSeg { order: -1; }
  #barEnd { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; margin-left: auto; }
}
