:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #111827;
  --muted: #5b6475;
  --border: #d9dee8;
  --primary: #1f3a93;
  /* Blue behind white text (buttons, header, active states). */
  --primary-fill: #1f3a93;
  --primary-text: #ffffff;
  --high: #d92d20;
  --low: #f79009;
  --off: #8a94a6;
  --hl-on: #111827;
  --hl-on-text: #ffffff;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --primary-bg: #eef2ff;
  /* Off switches and field edges: 3:1 against white. */
  --switch-off: #808a9c;
  --field-border: #808a9c;
  --radius: 12px;
  color-scheme: light;
}
/* Dark: when the system is dark, unless Light was chosen in Settings,
   or whenever Dark was chosen. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141c;
    --surface: #182030;
    --text: #e7ebf3;
    --muted: #9aa4b6;
    --border: #2b3547;
    --primary: #6b89f3;
    /* Darker than the text blue, so white text on it reads (4.9:1). */
    --primary-fill: #4466e0;
    --primary-text: #ffffff;
    --hl-on: #e7ebf3;
    --hl-on-text: #0f141c;
    --ok: #47cd89;
    --ok-bg: #0e2a1d;
    --warn: #fdb022;
    --warn-bg: #2d2210;
    --primary-bg: #1b2547;
    --switch-off: #2b3547;
    --field-border: #2b3547;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141c;
  --surface: #182030;
  --text: #e7ebf3;
  --muted: #9aa4b6;
  --border: #2b3547;
  --primary: #6b89f3;
  /* Darker than the text blue, so white text on it reads (4.9:1). */
  --primary-fill: #4466e0;
  --primary-text: #ffffff;
  --hl-on: #e7ebf3;
  --hl-on-text: #0f141c;
  --ok: #47cd89;
  --ok-bg: #0e2a1d;
  --warn: #fdb022;
  --warn-bg: #2d2210;
  --primary-bg: #1b2547;
  --switch-off: #2b3547;
  --field-border: #2b3547;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* Where the keyboard is: a clear ring on anything focused by keyboard.
   Titles and panels that the app moves focus to don't need one. */
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: none; }
/* Example text in empty fields: the muted grey, not the browser's fainter
   default (3.5:1 on the dark theme; this is 6.5:1, and 6.0:1 on light). */
::placeholder { color: var(--muted); opacity: 1; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: var(--primary-fill); color: var(--primary-text);
}
.bar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; color: inherit; display: grid; place-items: center;
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active { background: rgb(255 255 255 / 0.15); }

main { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 24px); }
.screen { display: flex; flex-direction: column; gap: 12px; }

.hero { text-align: center; padding: 16px 0 8px; }
.hero img { border-radius: 18px; }
.tagline { font-size: 22px; font-weight: 600; margin: 12px 0 0; }
.trust { display: flex; align-items: center; justify-content: center; gap: 6px; text-align: center; color: var(--muted); font-size: 14px; }
.trust svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--ok); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.card p { margin: 0 0 6px; }
.card p:last-child { margin-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
/* The page takes keyboard focus (keys add and adjust boxes). */
.canvas-wrap:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.add-box { align-self: flex-start; }
.btn-link.small { min-height: 44px; }
h2 { margin: 0; font-size: 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 18px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary-fill); border-color: var(--primary-fill); color: var(--primary-text); }
.btn-block { width: 100%; }
.btn-small { min-height: 40px; font-size: 14px; align-self: flex-start; }
/* Disabled buttons lose their colour, not just some opacity: a half-clear
   blue on a dark sheet still looks like a button to press. */
.btn:disabled { background: var(--surface); border-color: var(--border); color: var(--muted); cursor: not-allowed; }
.btn:disabled:active { transform: none; }
.btn-link { border: 0; background: transparent; color: var(--primary); align-self: center; text-decoration: underline; }

.actions { display: flex; gap: 10px; position: sticky; bottom: 0; padding: 10px 0 calc(env(safe-area-inset-bottom) + 4px); background: var(--bg); }
.actions .btn { flex: 1; }

.seg-group { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg-group .seg:focus-visible { outline-offset: -4px; } /* inside: the group clips its edges */
.seg { flex: 1; min-height: 40px; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 14px; }
.seg + .seg { border-left: 1px solid var(--border); }
.seg.active { background: var(--primary-fill); color: var(--primary-text); }

.canvas-wrap {
  position: relative; overflow: hidden; touch-action: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  min-height: 120px;
}
.canvas-wrap canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; display: block; }

.viewer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.pager, .zoom { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.zoom { margin-left: auto; }
#zoomLevel { min-width: 44px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.mini-btn {
  min-width: 36px; height: 36px; padding: 0 8px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 18px; line-height: 1;
}
.mini-btn.mini-text { font-size: 14px; }
.mini-btn:disabled { opacity: 0.4; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 12px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px;
}
.chip::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--off); }
.chip.on::before { background: var(--high); }
.chip.on.low::before { background: var(--low); border-radius: 50%; } /* possible: round, not only orange */
.chip:not(.on) { color: var(--muted); text-decoration: line-through; }

.legend { font-size: 13px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 0; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.sw-high { background: var(--high); }
.sw-low { background: var(--low); border-radius: 50%; }
.sw-off { border: 2px dashed var(--off); }

.field-label { font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: -6px; }
textarea {
  width: 100%; padding: 12px; border-radius: var(--radius);
  border: 1px solid var(--field-border); background: var(--surface); color: var(--text);
  font: inherit; resize: vertical;
}
textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.text-preview {
  white-space: pre-wrap; word-break: break-word;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; min-height: 48px;
}
.text-preview mark {
  background: var(--hl-on); color: var(--hl-on-text);
  border-radius: 4px; padding: 0 2px; cursor: pointer;
  box-shadow: inset 0 -3px 0 var(--high);
}
.text-preview mark.low { box-shadow: none; text-decoration: underline dotted var(--low) 3px; text-underline-offset: 3px; }
.text-preview mark.off { background: transparent; color: inherit; outline: 2px dashed var(--off); box-shadow: none; }

details summary { cursor: pointer; font-weight: 600; }
#restoreBox > summary { padding: 11px 0; }
details[open] > *:not(summary) { margin-top: 10px; }
details textarea { display: block; }

/* Choose pages: small pictures, tap to choose. */
.pages-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pages-tools label { flex-basis: 100%; font-size: 14px; font-weight: 600; }
.pages-tools .text-input { flex: 1; min-width: 140px; }
.pages-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.page-pick {
  width: 100%; padding: 6px; border: 2px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer;
}
.page-pick canvas { width: 100%; height: auto; border-radius: 4px; }
.page-pick .thumb-blank { width: 100%; aspect-ratio: 1 / 1.414; border-radius: 4px; background: var(--bg); }
.page-pick[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-bg); font-weight: 600; }
.page-pick[aria-pressed="true"] .page-no::before { content: "✓ "; }
.pages-go { position: sticky; bottom: 0; padding: 10px 0; background: var(--bg); }

/* Help */
.help > p { margin: 0; }
.help-item > summary { padding: 11px 0; }
.help-title { display: inline; margin: 0; font-size: 16px; font-weight: 600; }
.help-item > div > :first-child { margin-top: 0; }
.help-item ol, .help-item ul { margin: 0 0 8px; padding-left: 22px; }
.help-item li { margin: 0 0 8px; line-height: 1.45; }
.help-item li:last-child { margin-bottom: 0; }
.help-item p { line-height: 1.45; }
.help-item .btn { margin-top: 10px; }
.oss-text { max-height: 60vh; overflow: auto; margin: 10px 0 0; padding: 10px; border-radius: 8px; background: var(--bg); font-size: 12px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.welcome-slide .btn-link { margin-top: 12px; font-size: 15px; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 88px);
  transform: translateX(-50%); max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 20px; font-size: 14px; z-index: 10;
}

/* ----- home action cards ----- */
.action-card {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 14px 16px; border-radius: 16px; text-align: left; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
.action-card:active { transform: scale(0.99); }
.action-card.primary { background: var(--primary-fill); border-color: var(--primary-fill); color: var(--primary-text); }
.action-icon {
  width: 44px; height: 44px; flex: none; border-radius: 12px; display: grid; place-items: center;
  background: var(--primary-bg); color: var(--primary);
}
.action-card.primary .action-icon { background: rgb(255 255 255 / 0.16); color: var(--primary-text); }
.action-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.action-text { display: flex; flex-direction: column; gap: 2px; }
.action-text strong { font-size: 16px; }
.action-text small { font-size: 13px; opacity: 0.8; }
.tip-card { background: transparent; }

/* Scanning line over the page while its text is being read */
.canvas-wrap.scanning::after {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 22%;
  background: linear-gradient(to bottom, transparent, rgb(91 124 240 / 0.28) 85%, rgb(91 124 240 / 0.9));
  animation: scan 1.8s ease-in-out infinite alternate; pointer-events: none;
}
@keyframes scan { from { transform: translateY(-100%); } to { transform: translateY(460%); } }
@media (prefers-reduced-motion: reduce) {
  .canvas-wrap.scanning::after, .progress.indeterminate #progressBar, .status-bar.busy .status-icon, .spinner { animation: none; }
}

/* ----- tools ----- */
.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 56px; padding: 6px 4px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 13px;
}
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool.active { background: var(--primary-fill); border-color: var(--primary-fill); color: var(--primary-text); }
.tool:disabled { opacity: 0.5; }

/* ----- tips, switches, steps, memory ----- */
.tip {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--primary-bg); border-radius: var(--radius); padding: 10px 12px;
}
.tip p { margin: 0; flex: 1 1 200px; font-size: 14px; }
.switch-row { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; min-height: 40px; }
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch { width: 40px; height: 24px; flex: none; border-radius: 12px; background: var(--switch-off); position: relative; transition: background 0.2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 2px rgb(0 0 0 / 0.3); }
.switch-row input:checked + .switch { background: var(--primary); }
.switch-row input:checked + .switch::after { transform: translateX(16px); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--primary); outline-offset: 2px; }
.step { display: flex; align-items: center; gap: 8px; font-size: 16px; margin-top: 4px; }
.step span {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary-fill); color: var(--primary-text); font-size: 13px;
}
.memory { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.memory p { margin: 0; flex: 1 1 180px; }
.update-bar { position: sticky; top: calc(env(safe-area-inset-top) + 60px); z-index: 4; margin-bottom: 12px; box-shadow: 0 4px 12px rgb(0 0 0 / 0.12); }

/* ----- presets ----- */
.preset-block { display: flex; flex-direction: column; gap: 6px; }
.preset-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.presets { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.presets::-webkit-scrollbar { display: none; }
.preset {
  flex: none; min-height: 38px; padding: 0 14px; border-radius: 19px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 14px; font-weight: 600;
}
.preset.active { background: var(--primary-fill); border-color: var(--primary-fill); color: var(--primary-text); }
.preset-note { margin: 0; }
.cat-list { display: flex; flex-direction: column; gap: 2px; padding: 6px 14px; }

/* ----- full-screen editor ----- */
body.editing main { padding: 0; max-width: none; }
.editor {
  height: calc(100dvh - var(--bar-h, 56px)); gap: 0;
  max-width: 900px; margin: 0 auto;
}
.editor-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px 6px; }
.keep-pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px; margin-left: auto;
  border-radius: 20px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 14px;
}
.keep-pill svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.keep-pill.active { background: var(--primary-fill); border-color: var(--primary-fill); color: var(--primary-text); }
.keep-pill.active svg path { fill: currentColor; stroke: none; }
.keep-only .preset-pill { opacity: 0.55; }
/* The preset was just picked automatically. */
.preset-pill.flash { animation: pill-flash 1.6s ease-out; }
/* Pills and chips look 40 px tall but take taps over 48 px (Android's
   size for touch): the extra 4 px above and below meet in the 8 px gaps
   between them, so no tap lands on the wrong one. */
.preset-pill, .keep-pill, .chip { position: relative; }
.preset-pill::after, .keep-pill::after, .chip::after { content: ""; position: absolute; inset: -5px -1px; } /* from inside the 1 px border */
@keyframes pill-flash {
  0%, 40% { background: var(--primary-bg); border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-bg); }
  100% { background: var(--surface); border-color: var(--border); box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) { .preset-pill.flash { animation: none; } }
.preset-pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px;
  border-radius: 20px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 14px;
}
.preset-pill svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.status-bar {
  display: flex; align-items: center; gap: 8px; margin: 0 12px; padding: 8px 12px;
  border: 0; border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; text-align: left;
}
.status-bar.ok { background: var(--ok-bg); }
.status-bar.warn { background: var(--warn-bg); }
.status-title { flex: 1; font-size: 14px; font-weight: 600; }
.status-pct { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.status-more { width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 2; }
.status-bar.busy .status-more { display: none; }
.status-icon { width: 18px; height: 18px; flex: none; border-radius: 50%; position: relative; }
.status-bar.busy .status-icon { border: 2.5px solid var(--primary-bg); border-top-color: var(--primary); animation: spin 0.9s linear infinite; }
.status-bar.ok .status-icon { background: var(--ok); }
.status-bar.ok .status-icon::after { content: ""; position: absolute; left: 6px; top: 3px; width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.status-bar.warn .status-icon { background: var(--warn); }
.status-bar.warn .status-icon::after { content: "!"; position: absolute; inset: 0; color: #fff; font-weight: 700; font-size: 13px; line-height: 18px; text-align: center; }
.status-text { margin: 0; font-size: 14px; color: var(--muted); }
.status-text:empty { display: none; }
.progress { height: 6px; border-radius: 3px; background: var(--primary-bg); overflow: hidden; position: relative; }
.progress.thin { height: 3px; margin: 4px 12px 0; border-radius: 2px; }
.progress[hidden] { display: none; }
#progressBar { height: 100%; width: 0; background: var(--primary); transition: width 0.3s ease; }
.progress.indeterminate #progressBar { width: 35%; position: absolute; animation: slide 1.2s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide { from { left: -35%; } to { left: 100%; } }

.stage { position: relative; flex: 1; min-height: 0; margin: 8px 12px; }
.stage .canvas-wrap { position: absolute; inset: 0; min-height: 0; }
.floating-zoom {
  position: absolute; right: 8px; bottom: 8px; margin: 0; padding: 2px; gap: 0;
  display: flex; align-items: center; border-radius: 22px;
  background: rgb(255 255 255 / 0.88); border: 1px solid var(--border);
  box-shadow: 0 1px 6px rgb(0 0 0 / 0.12); opacity: 0.7; transition: opacity 0.2s;
}
.floating-zoom:hover, .floating-zoom:focus-within, .floating-zoom.active, .floating-zoom.zoomed { opacity: 1; }
/* Adjusting the selected box without dragging: above the zoom and undo controls. */
.box-bar {
  position: absolute; left: 50%; bottom: 58px; transform: translateX(-50%); padding: 2px; gap: 0;
  display: flex; align-items: center; border-radius: 22px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: 0 1px 6px rgb(0 0 0 / 0.18);
}
.box-bar[hidden] { display: none; }
#imageScreen.adjusting #tapTip { display: none; }
.box-bar .box-mode { padding: 0 12px; font-size: 13px; font-weight: 600; color: var(--primary); }
.box-bar .box-mode[aria-pressed="true"] { background: var(--primary-bg); }
.zbtn.zfit { padding: 0 12px; font-size: 13px; font-weight: 600; color: var(--primary); white-space: nowrap; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .floating-zoom { background: rgb(24 32 48 / 0.88); } }
:root[data-theme="dark"] .floating-zoom { background: rgb(24 32 48 / 0.88); }
.zbtn {
  min-width: 40px; height: 40px; padding: 0 6px; border: 0; border-radius: 20px;
  background: transparent; color: var(--text); font: inherit; font-size: 18px; line-height: 1;
}
.zbtn:active { background: var(--primary-bg); }
.zbtn.zlevel { min-width: 46px; font-size: 12px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.floating-zoom #zoomLevel { min-width: 0; }
.history-btns { position: absolute; left: 8px; bottom: 8px; display: flex; gap: 8px; pointer-events: none; }
.history-btns > * { pointer-events: auto; }
.undo-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgb(0 0 0 / 0.18);
}
.undo-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.undo-btn:active { transform: scale(0.94); }
.notice {
  position: absolute; left: 8px; right: 8px; top: 8px; display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 10px 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--text);
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.15); font-size: 14px;
}
.notice p { margin: 0; flex: 1; }
/* 44px to tap, without making the bar taller. */
.notice-close { border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; padding: 0 4px; min-width: 44px; min-height: 44px; margin: -10px -8px -10px 0; }
.mode-hint {
  position: absolute; left: 50%; bottom: 56px; transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px);
  margin: 0; padding: 8px 12px; border-radius: 16px; background: rgb(17 24 39 / 0.86); color: #fff; font-size: 13px; text-align: center;
  pointer-events: none;
}
.floating-tip { position: absolute; left: 8px; right: 8px; bottom: 56px; box-shadow: 0 2px 10px rgb(0 0 0 / 0.15); }

.editor-bottom {
  display: flex; flex-direction: column; gap: 8px;
  padding: 0 12px calc(env(safe-area-inset-bottom) + 10px);
}
.editor .tools { grid-template-columns: repeat(5, 1fr); gap: 6px; }
.editor .tool { min-height: 52px; font-size: 12px; }

/* ----- slide-up panels ----- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  background: rgb(0 0 0 / 0.4); animation: fade 0.15s ease-out;
}
.sheet {
  width: 100%; max-width: 640px; max-height: 88dvh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px);
  background: var(--bg); border-radius: 18px 18px 0 0; box-shadow: 0 -4px 20px rgb(0 0 0 / 0.2);
  animation: rise 0.2s ease-out;
}
/* The sheet scrolls, so its parts keep their size: in a full sheet, flex
   would otherwise squash anything with overflow hidden (the Box colour
   buttons in Details) down to a line. */
.sheet > * { flex-shrink: 0; }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 4px; }
.sheet h2 { font-size: 18px; }
.sheet-sub { margin: 0; font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }
@keyframes rise { from { transform: translateY(40px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { animation: none; } }

.preset-list { display: flex; flex-direction: column; gap: 8px; }
.preset-row {
  display: flex; align-items: flex-start; gap: 12px; width: 100%; padding: 12px 14px; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit;
}
.preset-row.active { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.preset-row .radio { width: 20px; height: 20px; flex: none; margin-top: 1px; border-radius: 50%; border: 2px solid var(--off); }
.preset-row.active .radio { border-color: var(--primary); background: radial-gradient(var(--primary) 0 4.5px, transparent 5px); }
.preset-row-text { display: flex; flex-direction: column; gap: 2px; }
.preset-row-text small { color: var(--muted); font-size: 13px; }

.ready-busy { display: flex; align-items: center; gap: 10px; padding: 18px 4px; color: var(--muted); font-size: 14px; }
.ready-busy[hidden] { display: none; }
.spinner { width: 20px; height: 20px; flex: none; border-radius: 50%; border: 2.5px solid var(--primary-bg); border-top-color: var(--primary); animation: spin 0.9s linear infinite; }
#readyBody { display: flex; flex-direction: column; gap: 12px; }
#readyBody[hidden] { display: none; }
.thumbs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.thumbs img { height: 150px; width: auto; flex: none; border-radius: 8px; border: 1px solid var(--border); background: #fff; }
.ready-summary { margin: 0; font-size: 16px; font-weight: 600; }
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.checks li { display: flex; align-items: center; gap: 10px; font-size: 14px; flex-wrap: wrap; }
.checks li::before { content: ""; width: 20px; height: 20px; flex: none; border-radius: 50%; color: #fff; font-weight: 700; font-size: 12px; line-height: 20px; text-align: center; }
.checks li.ok::before { content: "\2713"; background: var(--ok); }
.checks li.bad::before { content: "!"; background: var(--warn); }
.checks li.info::before { content: "i"; background: var(--primary-bg); color: var(--primary); font-style: italic; }
.checks li span { flex: 1 1 180px; }
.check-action { border: 0; background: transparent; color: var(--primary); font: inherit; font-weight: 600; text-decoration: underline; padding: 4px 0; }
.ready-ack { padding: 8px 12px; border-radius: var(--radius); background: var(--warn-bg); }
#readyAckHint { min-height: 44px; padding: 0 8px; }
.ready-error { padding: 12px 14px; border-radius: var(--radius); background: var(--warn-bg); }
.ready-error[hidden] { display: none; }
.ready-error p { margin: 0; }
.ready-error .btn-link { margin-left: 12px; padding: 8px 0; }

/* ----- language choice ----- */
/* Language and Theme: "Automatic" on its own row, the two choices below. */
.lang-group { flex-wrap: wrap; }
.lang-group .seg:first-child { flex-basis: 100%; border-bottom: 1px solid var(--border); }
.lang-group .seg:nth-child(2) { border-left: 0; }
.legend > span { display: inline-flex; align-items: center; }

/* ----- text screen: one box, three views ----- */
.text-top { display: flex; align-items: center; }
.views .seg { min-height: 40px; }
.text-box textarea, .text-box .text-preview { min-height: 240px; max-height: 55dvh; overflow-y: auto; }
.text-box textarea { display: block; resize: none; }
.text-preview .w { border-radius: 4px; cursor: pointer; }
.text-preview .w:active { background: var(--primary-bg); }
.text-result { user-select: text; }
.view-hint { margin: -4px 0 0; }
.text-summary-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.text-summary { font-size: 14px; font-weight: 600; }

/* ----- first-run welcome ----- */
.welcome {
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column;
  background: var(--bg); padding: calc(env(safe-area-inset-top) + 12px) 0 calc(env(safe-area-inset-bottom) + 16px);
  animation: fade 0.2s ease-out;
}
.welcome-top { display: flex; align-items: center; justify-content: space-between; padding: 0 16px; }
.lang-mini { display: flex; gap: 6px; }
.lang-chip {
  min-height: 34px; padding: 0 12px; border-radius: 17px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px;
}
.lang-chip.active { background: var(--primary-fill); border-color: var(--primary-fill); color: var(--primary-text); }
.welcome-skip { border: 0; background: transparent; color: var(--primary); font: inherit; font-weight: 600; padding: 8px 4px; }
.welcome-viewport { flex: 1; overflow: hidden; touch-action: pan-y; }
.welcome-track { display: flex; height: 100%; transition: transform 0.3s ease; }
/* Each slide is one screen wide (the track moves a screen at a time); the
   text stays a 560 px column through the side padding, so on a wide screen
   the next slide doesn't peek in. */
.welcome-slide {
  flex: 0 0 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 0 max(28px, calc(50% - 252px)); text-align: center;
}
.welcome-slide h2 { font-size: 24px; line-height: 1.25; }
.welcome-slide p { margin: 0; font-size: 16px; color: var(--muted); }
.welcome-art {
  width: 120px; height: 120px; border-radius: 32px; display: grid; place-items: center;
  background: var(--primary-bg); color: var(--primary);
}
.welcome-art img { border-radius: 22px; }
.welcome-art svg { width: 56px; height: 56px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.welcome-ok { color: var(--ok) !important; font-weight: 600; }
.welcome-bottom { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 0 16px; max-width: 560px; width: 100%; margin: 0 auto; }
.welcome-dots { display: flex; gap: 8px; }
.welcome-dots span { width: 8px; height: 8px; border-radius: 4px; background: var(--border); transition: width 0.2s, background 0.2s; }
.welcome-dots span.on { width: 22px; background: var(--primary); }
@media (prefers-reduced-motion: reduce) { .welcome-track { transition: none; } .welcome { animation: none; } }

/* ----- watermark text field ----- */
.text-input {
  width: 100%; min-height: 44px; padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--field-border); background: var(--surface); color: var(--text); font: inherit;
}
.text-input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.notice #noticeAction { align-self: center; flex: none; }

/* ----- sharing log ----- */
/* Hide a word or phrase by typing it (Details): works without tapping. */
.hide-word { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.hide-word-row { display: flex; gap: 8px; }
.hide-word-row .text-input { flex: 1; min-width: 0; }
.hide-word-row .btn { align-self: stretch; min-height: 44px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; margin: 10px 0; }
.log-link { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; font: inherit; color: var(--text); cursor: pointer; }
.log-link svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.log-link > span { flex: 1; }
.log-link .chev { color: var(--muted); width: 18px; height: 18px; }
.log-list { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.log-entry { display: flex; gap: 12px; align-items: flex-start; }
.log-thumb { width: 64px; height: 64px; flex: none; object-fit: cover; object-position: top; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }
.log-thumb.text-thumb { display: grid; place-items: center; color: var(--muted); }
.log-thumb.text-thumb svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.log-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.log-body strong { font-size: 15px; }
.log-body .small { font-size: 13px; overflow-wrap: anywhere; }
.log-body .text-input { min-height: 38px; margin-top: 4px; font-size: 14px; }
.log-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 6px; }
.log-actions .btn-link { padding: 4px 0; font-size: 14px; color: var(--muted); }
.log-empty { text-align: center; padding: 24px 8px; }
#gdprText { width: 100%; margin-top: 10px; font-size: 14px; }
#gdprSheet .seg-group { margin-top: 6px; }

/* ----- scanning paper documents ----- */
.scan { height: calc(100dvh - var(--bar-h, 56px)); max-width: 900px; margin: 0 auto; gap: 0; }
.scan-stage { position: relative; flex: 1; min-height: 0; background: #0b0d12; overflow: hidden; }
.scan-stage video, .scan-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#scanReview { touch-action: none; }
.scan-private {
  position: absolute; left: 10px; top: 10px; display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 99px; background: rgb(0 0 0 / 0.55); color: #fff; font-size: 12px;
}
.scan-private svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.scan-torch {
  position: absolute; right: 10px; top: 10px; width: 44px; height: 44px; border-radius: 50%; border: 0;
  display: grid; place-items: center; background: rgb(0 0 0 / 0.55); color: #fff;
}
.scan-torch svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.scan-torch[aria-pressed="true"] { background: #fff; color: #111; }
.scan-torch[aria-pressed="true"] svg { fill: currentColor; }
.scan-hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px);
  margin: 0; padding: 8px 14px; border-radius: 12px; background: rgb(0 0 0 / 0.6); color: #fff; font-size: 14px; text-align: center;
}
.scan-hint:empty { display: none; }
.scan-bar { padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: 1px solid var(--border); }
.scan-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.scan-review-row { display: flex; gap: 8px; }
.scan-review-row .btn { flex: 1; padding-inline: 8px; }
.scan-thumbs { display: flex; gap: 6px; overflow-x: auto; min-width: 0; }
.scan-thumb { position: relative; flex: none; width: 40px; height: 52px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: #fff; overflow: hidden; }
.scan-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.scan-thumb span {
  position: absolute; right: 1px; top: 1px; width: 16px; height: 16px; border-radius: 50%;
  background: rgb(0 0 0 / 0.65); color: #fff; font-size: 12px; line-height: 16px; text-align: center;
}
.shutter {
  width: 64px; height: 64px; border-radius: 50%; border: 4px solid var(--primary); background: var(--surface);
  box-shadow: inset 0 0 0 4px var(--surface), inset 0 0 0 30px var(--primary);
}
.shutter:active { transform: scale(0.94); }
.shutter:disabled { opacity: 0.5; }
.scan-done { justify-self: end; }

/* ----- exported chats ----- */
.chat-info { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-info p { margin: 0; flex: 1 1 200px; }
.preview-more { display: block; margin-top: 10px; font-style: italic; }
.scan-intro {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 24px; text-align: center; color: #fff;
}
.scan-intro[hidden] { display: none; }
.scan-intro svg { width: 56px; height: 56px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; opacity: 0.85; }
.scan-intro p { margin: 0; max-width: 32ch; line-height: 1.45; }

/* ----- what is inside codes ----- */
.code-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.code-list li { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; overflow-wrap: anywhere; }
.code-list .small { font-size: 13px; margin-top: 2px; }
.code-list .btn-link { padding: 6px 0 0; font-size: 14px; }
.code-state { font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px; }
.code-state.on { background: var(--ok-bg); color: var(--ok); }
.code-state.off { background: var(--warn-bg); color: var(--warn); }
.log-code { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; }
.log-find-result { margin: 0; }

/* ----- plain-language instructions ----- */
.say-pill { margin-left: auto; }
.say-pill + .keep-pill { margin-left: 0; }
#sayIn { width: 100%; margin-top: 8px; font-size: 16px; }
.say-result { margin: 8px 0 0; }
.say-examples { margin: 10px 0 14px; }
.say-examples .chip { text-align: left; }

/* ----- everything found, one by one ----- */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.item-list-box { margin: 8px 0 12px; }
.item-list-box > summary { cursor: pointer; font-weight: 600; font-size: 15px; padding: 6px 0; }
.item-list { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; }
.item-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.item-list li:last-child { border-bottom: 0; }
.item-list .switch-row { flex: 1; min-width: 0; min-height: 44px; }
.item-text { display: flex; flex-direction: column; min-width: 0; }
.item-text strong { font-size: 14px; }
.item-value { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-list .btn-link { flex: none; font-size: 13px; min-height: 44px; padding: 0 4px; }

/* ----- text hidden under boxes in a PDF ----- */
.hidden-list { margin: 4px 0 10px; padding-left: 1.2em; overflow-wrap: anywhere; }
.hidden-list li { margin: 3px 0; }

/* ----- clearing the clipboard ----- */
.clip-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 15; /* under open panels */
  display: flex; align-items: center; gap: 10px; width: max-content; max-width: calc(100% - 24px);
  padding: 8px 8px 8px 14px; border-radius: 14px; background: var(--text); color: var(--bg);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.25); font-size: 14px;
}
.clip-bar .notice-close { color: var(--bg); }

/* ----- settings file ----- */
.settings-file { display: flex; flex-wrap: wrap; gap: 10px; }

/* ----- files dragged onto the window ----- */
.drop-zone {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px;
  background: rgb(31 58 147 / 0.18); backdrop-filter: blur(2px);
}
.drop-target {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  width: min(480px, 100%); padding: 40px 24px; border: 3px dashed var(--primary); border-radius: 18px;
  background: var(--surface); color: var(--text); font-size: 18px; font-weight: 600; text-align: center;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.2); pointer-events: none;
}
.drop-target svg { width: 48px; height: 48px; fill: none; stroke: var(--primary); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ----- wide windows: Details docked beside the page ----- */
:root { --dock-w: 380px; }
@media (min-width: 1100px) {
  body.docked .editor { max-width: none; margin: 0 var(--dock-w) 0 0; }
  body.docked .editor .tools { grid-template-columns: repeat(4, 1fr); }
  body.docked #detailsBtn { display: none; }
  /* Shown even while marked hidden for a moment (a slide-up Details closing). */
  body.docked #detailsSheet {
    display: block !important; position: fixed; top: var(--bar-h, 56px); right: 0; bottom: 0; left: auto;
    width: var(--dock-w); z-index: 4; background: var(--bg); border-left: 1px solid var(--border); animation: none;
  }
  body.docked #detailsSheet .sheet {
    max-width: none; max-height: none; height: 100%; border-radius: 0; box-shadow: none; animation: none;
    padding: 14px 18px 24px;
  }
  body.docked #detailsSheet .sheet-handle, body.docked #detailsSheet .sheet-close { display: none; }
}

/* ----- importing settings: what would change ----- */
.import-list { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 6px; }
.import-list li.weaker { color: var(--high); font-weight: 600; }
.import-warn { margin: 0; }

/* ----- Windows app only (body.desktop-app, set by desktop.js) ----- */
/* No share sheet in the Windows app: the safe copy is saved or dragged out. */
body.desktop-app #shareFinal { display: none; }
body.desktop-app #readyThumbs img[draggable="true"] { cursor: grab; }
.drag-hint { margin: 0; }
