/*
VOICE   calm, precise tool — like a good office scanner: nothing decorative in the way of the page
IDEA    the paper itself is the hero; the app is the scanner bed around it
PICTURE every document shown as a real sheet (white, soft shadow); detected edges in electric blue
COLOUR  neutral grey bed, white paper, one electric-blue accent, a yellow scan beam for delight
TYPE    system UI with Japanese fallbacks (Hiragino / Noto Sans JP / Yu Gothic) — works offline
LAYOUT  mobile-first: header · content · thumb-reach dock; editor stage + side panel on desktop
*/
:root {
  --bg: #eef0f3; --surface: #ffffff; --surface-2: #f6f7f9; --ink: #13161b; --muted: #545c68; --line: #d7dce3;
  --accent: #1f4fff; --accent-ink: #ffffff; --accent-soft: #e5ebff; --danger: #c62828; --danger-soft: #fdecec;
  --beam: #ffd23f; --shadow: 0 1px 2px rgb(16 24 40 / .08), 0 6px 18px rgb(16 24 40 / .08);
  --radius: 14px; --tap: 44px;
  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013; --surface: #171a1f; --surface-2: #1d2127; --ink: #eef0f3; --muted: #a7afba; --line: #2b3038;
    --accent: #8aa4ff; --accent-ink: #0a0f2c; --accent-soft: #1d2647; --danger: #ff8a80; --danger-soft: #3a1d1d;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .35);
  }
}

* { box-sizing: border-box; min-width: 0; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); overflow-x: clip; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 50; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 10px; }
.skip:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* Icons */
.ic { width: 22px; height: 22px; flex: none; }
.ic.sm { width: 16px; height: 16px; }
.ic.xs { width: 16px; height: 16px; vertical-align: -3px; margin-inline-end: 4px; }
.ic.big { width: 44px; height: 44px; color: var(--muted); }

/* Views */
.view { min-height: 100dvh; display: flex; flex-direction: column; }
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; min-height: 60px;
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.bar h1 { font-size: 20px; line-height: 1.2; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar h1:focus { outline: none; }
.bar-right { display: flex; gap: 2px; }
.brand { display: flex; align-items: center; gap: 10px; flex: 1; }
.logo { width: 34px; height: 34px; color: var(--accent); }
main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 8px max(16px, env(safe-area-inset-left)) calc(110px + env(safe-area-inset-bottom)); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: color-mix(in srgb, var(--ink) 30%, var(--line)); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: var(--surface); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); background: var(--surface); }
.btn.big { min-height: 56px; padding: 0 28px; font-size: 18px; border-radius: 16px; }
.btn.wide { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled, .icon-btn:disabled, .mini:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn { width: var(--tap); height: var(--tap); display: inline-grid; place-items: center; border-radius: 12px; border: 0; background: transparent; cursor: pointer; color: inherit; flex: none; }
.icon-btn:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.mini { width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.mini .ic { width: 18px; height: 18px; }
.mini.danger { color: var(--danger); }
.pill { min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid currentColor; background: transparent; font-weight: 600; cursor: pointer; }
.pill[aria-pressed="true"] { background: var(--beam); color: #111; border-color: var(--beam); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }

/* Dock (thumb zone actions) */
.dock { position: fixed; inset: auto 0 0 0; z-index: 6; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap;
  padding: 12px max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: linear-gradient(to top, var(--bg) 70%, transparent); }
.dock .btn { flex: 1 1 0; max-width: 220px; }
.dock .btn.big { flex: 1.6 1 0; }
@media (max-width: 600px) {
  .dock.four .btn { flex-direction: column; gap: 2px; min-height: 58px; padding: 6px 4px; font-size: 13px; border-radius: 14px; }
  .dock.four .btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
}
@media (max-width: 420px) { .dock .btn { padding: 0 12px; } .dock { gap: 8px; } }

/* Library */
.lib-tools { display: flex; gap: 10px; margin: 4px 0 16px; }
.lib-tools .select-wrap { flex: 0 1 170px; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 12px; min-height: var(--tap); border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.search input { flex: 1; border: 0; background: transparent; font-size: 16px; min-height: 42px; outline: none; }
.search:focus-within { outline: 3px solid var(--accent); outline-offset: 1px; }
.select-wrap select, .field select, .field input, .field textarea { min-height: var(--tap); border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 0 12px; font-size: 16px; width: 100%; }
.field textarea { padding: 10px 12px; line-height: 1.6; resize: vertical; }
.doc-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px 14px; }
.doc-card { position: relative; }
.doc-open { width: 100%; display: flex; flex-direction: column; gap: 6px; padding: 0; border: 0; background: none; text-align: start; cursor: pointer; border-radius: 12px; }
.paper { display: grid; place-items: center; aspect-ratio: 3 / 4; background: #fff; border-radius: 6px; box-shadow: var(--shadow); overflow: hidden; }
.paper img { width: 100%; height: 100%; object-fit: contain; }
.doc-open:hover .paper { transform: translateY(-2px); }
.doc-title { font-weight: 650; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; padding-inline-end: 36px; }
.doc-meta { font-size: 13px; color: var(--muted); }
.doc-more { position: absolute; right: -6px; bottom: 18px; }
.empty { text-align: center; max-width: 460px; margin: 4vh auto 0; }
.empty h2 { font-size: 26px; line-height: 1.15; margin: 8px 0; text-wrap: balance; }
.empty-art { width: min(300px, 80%); height: auto; color: var(--ink); }
.empty-art .beam { animation: beam 2.6s ease-in-out infinite; }
@keyframes beam { 0%, 100% { transform: translateY(-58px); } 50% { transform: translateY(58px); } }
.feature-list { list-style: none; padding: 0; margin: 20px auto 0; text-align: start; display: grid; gap: 10px; max-width: 360px; }
.feature-list li { display: flex; gap: 10px; align-items: center; }
.feature-list .ic { color: var(--accent); }
.empty-small { color: var(--muted); padding: 24px 0; }
.notice { padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); }
.notice.err { background: var(--danger-soft); color: var(--danger); }

/* Document view */
.title-btn-wrap { display: flex; }
.title-btn { border: 0; background: none; font: inherit; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 6px 4px; cursor: pointer; border-radius: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-btn .ic { color: var(--muted); }
.hint { margin: 0 0 12px; font-size: 14px; }
.page-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 18px 14px; }
.page-card { display: flex; flex-direction: column; gap: 6px; touch-action: manipulation; }
.page-card.dragging { opacity: .6; transform: scale(1.04); }
.page-open { position: relative; padding: 0; border: 0; background: none; cursor: pointer; border-radius: 8px; }
.badge { position: absolute; left: 6px; bottom: 6px; min-width: 26px; height: 26px; padding: 0 6px; display: grid; place-items: center; border-radius: 8px; background: rgb(19 22 27 / .82); color: #fff; font-size: 13px; font-weight: 700; }
.badge.ocr { left: auto; right: 6px; background: var(--accent); color: var(--accent-ink); }
.badge.ocr .ic { margin: 0; }
.page-tools { display: flex; justify-content: center; gap: 6px; }
.page-add { width: 100%; aspect-ratio: 3 / 4; display: grid; place-content: center; justify-items: center; gap: 8px; border: 2px dashed var(--line); border-radius: 8px; background: transparent; cursor: pointer; color: var(--muted); font-weight: 600; }
.page-add:hover { border-color: var(--accent); color: var(--accent); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid color-mix(in srgb, var(--accent) 25%, transparent); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Editor */
.view.edit { height: 100dvh; min-height: 0; }
.ed-title { text-align: center; font-size: 17px !important; }
.ed-body { flex: 1; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.stage { position: relative; display: grid; place-items: center; padding: 12px; min-height: 0; overflow: hidden;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--ink) 6%, var(--bg)), var(--bg)); }
.stage.loading::after { content: ""; position: absolute; top: 14px; right: 14px; width: 22px; height: 22px; border-radius: 50%; border: 3px solid color-mix(in srgb, var(--accent) 25%, transparent); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.fit { position: relative; max-width: 100%; max-height: 100%; box-shadow: var(--shadow); background: #fff; }
.fit > canvas.preview, .fit > img { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-select: none; }
.ed-side { background: var(--surface); border-top: 1px solid var(--line); display: flex; flex-direction: column; max-height: 50dvh; min-height: 0; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.tabs [role="tab"] { min-height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: none; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs [role="tab"][aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.panel { overflow: auto; padding: 14px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
@media (min-width: 900px) {
  .ed-body { grid-template-rows: none; grid-template-columns: minmax(0, 1fr) 380px; }
  .ed-side { max-height: none; border-top: 0; border-left: 1px solid var(--line); }
}
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin: 8px 0; }
.tool { min-height: 68px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-size: 13px; font-weight: 600; text-align: center; padding: 6px; }
.tool:hover { border-color: var(--accent); }

/* Crop */
.crop-wrap { touch-action: none; }
.crop-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.crop-shade { fill: rgb(0 0 0 / .45); }
.crop-poly { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.handle { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; border: 0; background: transparent; cursor: grab; touch-action: none; padding: 0; }
.handle::after { content: ""; position: absolute; inset: 11px; border-radius: 50%; background: #fff; border: 4px solid var(--accent); box-shadow: 0 1px 4px rgb(0 0 0 / .4); }
.handle.active::after, .handle:focus-visible::after { inset: 7px; background: var(--beam); }
.handle:focus-visible { outline-offset: 0; border-radius: 50%; }
.loupe { position: absolute; top: 12px; left: 12px; width: 132px; height: 132px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 4px 16px rgb(0 0 0 / .4); pointer-events: none; }
.loupe.right { left: auto; right: 12px; }

/* Markup */
.mark-layer { position: absolute; inset: 0; touch-action: none; }
.mark-layer[data-tool="redact"], .mark-layer[data-tool="highlight"] { cursor: crosshair; }
.mark { position: absolute; padding: 0; border: 0; background: none; cursor: move; }
.mark.redact { background: #000; }
.mark.highlight { background: rgb(255 226 0 / .45); mix-blend-mode: multiply; }
.mark.signature img { width: 100%; height: 100%; object-fit: contain; mix-blend-mode: multiply; pointer-events: none; }
.mark.sel { outline: 2px dashed var(--accent); outline-offset: 2px; }
.rz { position: absolute; right: -14px; bottom: -14px; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; cursor: nwse-resize; }

/* Forms */
.field { display: grid; gap: 6px; margin: 0 0 14px; border: 0; padding: 0; }
.field > span, .field legend { font-weight: 600; font-size: 15px; }
fieldset.field legend { margin-bottom: 6px; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.inline { border: 0; padding: 0; margin: 0; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 15px; font-weight: 600; }
.chip input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.switch { display: flex; align-items: center; gap: 12px; min-height: var(--tap); cursor: pointer; font-weight: 600; }
.switch input { appearance: none; -webkit-appearance: none; width: 48px; height: 28px; border-radius: 999px; background: var(--line); position: relative; flex: none; cursor: pointer; margin: 0; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(20px); }
.range { display: grid; gap: 4px; margin: 10px 0; font-weight: 600; }
.range output { color: var(--muted); font-variant-numeric: tabular-nums; margin-inline-start: 6px; }
.range input { width: 100%; min-height: 32px; accent-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 12px; }
.err-text { color: var(--danger); font-weight: 600; min-height: 1em; margin: 4px 0; }
.err-text:empty { display: none; }
details.langs { margin-bottom: 12px; }
details.langs summary { cursor: pointer; font-weight: 600; min-height: var(--tap); display: flex; align-items: center; }
details.langs .chips { margin: 6px 0 8px; }
.ocr-text { font-size: 16px; }
.tt { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 10px; }
.tt h2, .tt h3 { font-size: 16px; margin: 4px 0; display: flex; align-items: center; }
.out-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-top: 8px; }
.out-box p { margin: 0 0 8px; white-space: normal; }
.codes { padding-inline-start: 18px; } .codes code, .codes a { overflow-wrap: anywhere; }

/* Dialogs */
dialog { border: 0; padding: 0; color: var(--ink); background: var(--surface); border-radius: 20px; box-shadow: 0 20px 60px rgb(0 0 0 / .35); width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: rgb(10 12 16 / .55); }
.dlg-body { padding: 22px 20px 18px; overflow: auto; max-height: calc(100dvh - 24px); }
.dlg-body.wide { width: 100%; }
.dlg-title { font-size: 21px; margin: 0 0 12px; line-height: 1.25; }
.dlg-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }
@media (max-width: 600px) {
  dialog.sheet { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 20px 20px 0 0; max-height: 92dvh; }
  dialog.sheet .dlg-body { padding-bottom: max(18px, env(safe-area-inset-bottom)); max-height: 92dvh; }
  .dlg-actions .btn { flex: 1 1 auto; }
}
.storage { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 4px; }
.storage h3 { font-size: 16px; margin: 10px 0 4px; }
.storage .btn { margin: 4px 8px 4px 0; }
.sig-pad { width: 100%; aspect-ratio: 900 / 360; background: #fff; border: 2px dashed var(--line); border-radius: 12px; touch-action: none; cursor: crosshair; }
.sig-list { list-style: none; padding: 0; display: grid; gap: 8px; }
.sig-list li { display: flex; gap: 8px; align-items: center; }
.sig-pick { flex: 1; height: 72px; background: #fff; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; padding: 6px; }
.sig-pick img { height: 100%; margin: 0 auto; object-fit: contain; }

/* Busy + toast */
.busy { width: min(360px, calc(100vw - 32px)); }
.busy-card { padding: 24px; display: grid; justify-items: center; gap: 12px; text-align: center; }
.busy-card p { margin: 0; font-weight: 600; outline: none; }
.busy-card progress { width: 100%; height: 8px; accent-color: var(--accent); }
.toast { position: fixed; inset: auto 16px calc(96px + env(safe-area-inset-bottom)) 16px; margin: 0 auto; max-width: 520px; width: auto; height: auto; border: 0;
  display: none; align-items: center; gap: 12px; padding: 12px 14px 12px 16px; border-radius: 14px; background: #1b1f26; color: #fff; box-shadow: 0 10px 30px rgb(0 0 0 / .3); z-index: 40; overflow: visible; }
.toast.show { display: flex; animation: rise .2s ease-out; }
.toast.err { background: #8e1c1c; }
.toast span { flex: 1; }
.toast-act { min-height: 40px; padding: 0 12px; border-radius: 10px; border: 0; background: rgb(255 255 255 / .16); color: #fff; font-weight: 700; cursor: pointer; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
.drop-hint { position: fixed; inset: 0; z-index: 30; display: none; place-items: center; background: color-mix(in srgb, var(--accent) 18%, transparent); border: 4px dashed var(--accent); font-size: 22px; font-weight: 700; pointer-events: none; }
body.dropping .drop-hint { display: grid; }

/* Camera */
.view.cam { position: fixed; inset: 0; z-index: 20; background: #000; color: #fff; min-height: 0; }
.cam-stage { position: absolute; inset: 0; }
.cam-stage video { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; }
.cam-overlay { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: hidden; pointer-events: none; }
.cam-overlay polygon { fill: rgb(31 79 255 / .18); stroke: #fff; stroke-width: 3; stroke-linejoin: round; opacity: 0; transition: opacity .15s; }
.cam-overlay.found polygon { opacity: 1; stroke: #8aa4ff; filter: drop-shadow(0 0 6px rgb(31 79 255 / .8)); }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cam-flash.go { animation: flash .35s ease-out; }
@keyframes flash { 0% { opacity: .8; } 100% { opacity: 0; } }
.cam-top { position: absolute; inset: 0 0 auto 0; display: flex; align-items: center; gap: 8px; padding: max(10px, env(safe-area-inset-top)) 12px 10px; background: linear-gradient(rgb(0 0 0 / .55), transparent); }
.cam-hint-wrap { flex: 1; text-align: center; min-width: 0; }
.cam-hint { margin: 0; font-weight: 600; text-shadow: 0 1px 3px rgb(0 0 0 / .8); }
.cam-res { margin: 2px 0 0; font-size: 13px; opacity: .85; text-shadow: 0 1px 3px rgb(0 0 0 / .8); }
.pill.hd[aria-pressed="true"] { background: #fff; color: #111; border-color: #fff; }
.cam-top-right { display: flex; align-items: center; gap: 6px; }
.icon-btn.on-dark { color: #fff; background: rgb(0 0 0 / .35); }
.icon-btn.on-dark[aria-pressed="true"] { background: var(--beam); color: #111; }
.btn.on-dark { background: rgb(255 255 255 / .12); color: #fff; border-color: rgb(255 255 255 / .4); }
.cam-bottom { position: absolute; inset: auto 0 0 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 18px 20px max(22px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgb(0 0 0 / .65)); }
.cam-side { justify-self: start; cursor: pointer; }
.cam-side:focus-within .icon-btn { outline: 3px solid #fff; }
.cam-side.done { justify-self: end; display: flex; flex-direction: column; align-items: center; gap: 4px; border: 0; background: none; color: #fff; font-weight: 700; min-width: 64px; }
.stack { position: relative; width: 52px; height: 64px; border-radius: 6px; background: rgb(255 255 255 / .15); border: 2px solid #fff; overflow: hidden; display: grid; place-items: center; }
.stack img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.stack b { position: relative; background: var(--accent); color: #fff; min-width: 26px; height: 26px; border-radius: 13px; display: grid; place-items: center; font-size: 14px; padding: 0 6px; }
.stack.working b { background: var(--beam); color: #111; }
.done-label { font-size: 14px; }
.shutter { width: 78px; height: 78px; border-radius: 50%; border: 4px solid #fff; background: transparent; padding: 5px; cursor: pointer; }
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform .1s; }
.shutter:active span { transform: scale(.88); }
.shutter:focus-visible { outline: 3px solid var(--beam); outline-offset: 4px; }
.cam-error { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; padding: 32px; text-align: center; background: #111; }
.cam-error p { max-width: 420px; font-size: 17px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (forced-colors: active) {
  .chip input:checked + span, .btn.primary, .tabs [role="tab"][aria-selected="true"] { forced-color-adjust: none; background: Highlight; color: HighlightText; }
  .handle::after { background: Canvas; border-color: Highlight; }
  .crop-poly { stroke: Highlight; }
}

/* OCR review: tappable line boxes over the page and the line corrector */
.ocr-layer { position: absolute; inset: 0; }
.ocr-box { position: absolute; padding: 0; border: 1px solid rgb(31 79 255 / .35); background: rgb(31 79 255 / .06); border-radius: 3px; cursor: pointer; }
.ocr-box:hover { background: rgb(31 79 255 / .16); }
.ocr-box.low { border: 2px solid #e8590c; background: rgb(255 146 43 / .22); }
.ocr-box.cur { outline: 3px solid var(--accent); outline-offset: 2px; background: rgb(31 79 255 / .2); }
.fix { border: 2px solid var(--accent); border-radius: 14px; padding: 12px; margin: 10px 0; background: var(--surface-2); }
.fix h2 { font-size: 16px; margin: 0 0 8px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.fix-crop { width: 100%; height: auto; display: block; background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; object-fit: contain; }
.fix input { font-size: 20px; }
.engine-note { display: flex; align-items: center; margin: 4px 0 8px; }
.models { list-style: none; padding: 0; margin: 6px 0; display: grid; gap: 8px; }
.models li { display: flex; align-items: center; gap: 10px; justify-content: space-between; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.models .m-name { font-weight: 600; }
.models .m-meta { font-size: 13px; color: var(--muted); }
.credits { font-size: 14px; }
.credits li { margin: 4px 0; }
@media (forced-colors: active) { .ocr-box.low { border-color: Highlight; } }

/* Crop mode: the page gets the screen; tools shrink to one row */
.tool-row { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.tool-row::-webkit-scrollbar { display: none; }
.tool-sm { flex: 1 0 auto; min-width: 64px; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 6px 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tool-sm:hover { border-color: var(--accent); }
.view.edit.crop-mode .ed-side { max-height: none; }
.view.edit.crop-mode .panel { padding-top: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.view.edit.crop-mode .stage { padding: 18px; }
.crop-img { width: 100%; height: 100%; display: block; }
.handle { width: 48px; height: 48px; margin: -24px 0 0 -24px; }
.handle::after { inset: 12px; }
.handle.edge::after { inset: 18px 8px; border-radius: 6px; border-width: 3px; }
.handle.edge[data-vertical="true"]::after { inset: 8px 18px; }
.handle.active::after, .handle:focus-visible::after { inset: 8px; }
.handle.edge.active::after, .handle.edge:focus-visible::after { inset: 14px 4px; }
.handle.edge[data-vertical="true"].active::after, .handle.edge[data-vertical="true"]:focus-visible::after { inset: 4px 14px; }
@media (max-width: 899px) { .ed-side { max-height: 44dvh; } }
.btn.pulse { animation: pulse 1.2s ease-in-out 3; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 35%, transparent); } }

/* ------------------------------ live translate ------------------------------ */
.live-stage { position: absolute; inset: 0; overflow: hidden; }
.live-stage video, .live-still { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; }
.live-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.live-top { z-index: 2; }
.live-langs { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; min-width: 0; }
.live-sel select { appearance: none; -webkit-appearance: none; max-width: 38vw; min-height: 44px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid rgb(255 255 255 / .5); background: rgb(0 0 0 / .5); color: #fff; font: 600 16px/1.2 system-ui, sans-serif; text-overflow: ellipsis; }
.live-sel select:focus-visible { outline: 3px solid var(--beam); outline-offset: 2px; }
.live-sel option { color: #111; background: #fff; }
.live-arrow { font-weight: 700; text-shadow: 0 1px 3px rgb(0 0 0 / .8); }
.live-hint { position: absolute; z-index: 2; left: 50%; bottom: calc(max(22px, env(safe-area-inset-bottom)) + 108px); transform: translateX(-50%); margin: 0;
  max-width: calc(100vw - 32px); padding: 6px 14px; border-radius: 999px; background: rgb(0 0 0 / .55); font-weight: 600; text-align: center; }
.live-hint:empty { display: none; }
.live-bottom { position: absolute; z-index: 2; inset: auto 0 0 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 18px 16px max(22px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgb(0 0 0 / .65)); }
.live-list-btn { justify-self: start; min-height: 52px; min-width: 52px; padding: 8px 14px; gap: 8px; }
.live-list-btn b { min-width: 1.6em; padding: 0 6px; border-radius: 999px; background: #fff; color: #111; font-size: 14px; }
.live-pause { display: grid; place-items: center; }
.live-pause span { display: grid; place-items: center; background: #fff; color: #111; }
.live-pause .ic { width: 30px; height: 30px; }
.live-sheet { position: absolute; z-index: 3; inset: auto 0 0 0; max-height: 62vh; overflow: auto; padding: 8px 16px max(16px, env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0; background: var(--surface); color: var(--ink); box-shadow: 0 -8px 30px rgb(0 0 0 / .35); }
.live-sheet-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 6px 0; background: inherit; }
.live-sheet-head .h3 { margin: 0; }
.live-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.live-item { padding: 12px; border: 1px solid var(--line, #ddd); border-radius: 12px; }
.live-tr { margin: 0 0 4px; font-size: 19px; font-weight: 650; line-height: 1.35; }
.live-src { margin: 0 0 8px; color: var(--muted, #555); font-size: 15px; }

/* editor: translation language pickers */
.tr-langs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px; margin-bottom: 10px; }
.tr-langs select { width: 100%; }
.tiny-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
