/* Pagelia — design tokens, then base, layout, components. Mobile first; 760px is the editor breakpoint. */

/* ---------- Tokens ---------- */

:root {
    /* Brand */
    --brand: #0b7a68;          /* Pagelia jade: primary actions, mark tile */
    --brand-deep: #08604f;     /* hover / pressed */
    --brand-text: #0a7363;     /* brand used as text on canvas, surface and wash (≥5:1) */
    --brand-wash: #e3f3ee;     /* selected and hover tints */
    --leaf: #8fe3c9;           /* the fold in the mark; never text on light */
    --tittle: #0b7a68;         /* the leaf over the i in the wordmark */
    --on-brand: #ffffff;
    --check-mark: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27%3E%3Cpath d=%27M3.5 8.5l3 3 6-7%27 fill=%27none%27 stroke=%27%23ffffff%27 stroke-width=%272.2%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27/%3E%3C/svg%3E");

    /* Neutrals: cool and untinted, so the jade is the only colour on the page */
    --canvas: #f4f5f7;
    --surface: #ffffff;
    --surface-hover: #eef0f3;
    --document-ground: #e8ebef;
    --hairline: #dce0e6;
    --field-border: #808a97;   /* ≥3:1 on surface */
    --text: #0e1621;
    --text-muted: #4f5a69;

    /* Status: success is a true green, never the brand jade */
    --success: #13733a;
    --success-ground: #e8f6ec;
    --error: #b42318;
    --error-ground: #fef3f2;

    /* Shape, rhythm, motion */
    --radius-thumb: 4px;
    --radius-control: 12px;
    --radius-inset: 14px;
    --radius-panel: 20px;
    --grid: 8px;
    --tap: 44px;
    --shadow-control: 0 1px 2px rgba(14, 22, 33, .12);
    --shadow-card: 0 1px 2px rgba(14, 22, 33, .04), 0 4px 16px rgba(14, 22, 33, .06);
    --shadow-page: 0 1px 2px rgba(14, 22, 33, .06), 0 12px 32px rgba(14, 22, 33, .12);
    --shadow-float: 0 8px 28px rgba(14, 22, 33, .18);
    --ease: cubic-bezier(.16, 1, .3, 1);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --brand: #34c7a5;
        --brand-deep: #5fd8bb;
        --brand-text: #45cfae;
        --brand-wash: #13302b;
        --leaf: #8fe3c9;
        --tittle: #8fe3c9;
        --on-brand: #04211b;
        --check-mark: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27%3E%3Cpath d=%27M3.5 8.5l3 3 6-7%27 fill=%27none%27 stroke=%27%2304211b%27 stroke-width=%272.2%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27/%3E%3C/svg%3E");
        --canvas: #0a0c10;
        --surface: #161a21;
        --surface-hover: #1f252e;
        --document-ground: #12161c;
        --hairline: #323a45;
        --field-border: #6b7584;
        --text: #eef1f5;
        --text-muted: #a3adba;
        --success: #4ade80;
        --success-ground: #0f2618;
        --error: #f97066;
        --error-ground: #2a1513;
        --shadow-control: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow-card: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
        --shadow-page: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45);
        --shadow-float: 0 8px 28px rgba(0, 0, 0, .5);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --brand: #34c7a5;
    --brand-deep: #5fd8bb;
    --brand-text: #45cfae;
    --brand-wash: #13302b;
    --leaf: #8fe3c9;
    --tittle: #8fe3c9;
    --on-brand: #04211b;
    --check-mark: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27%3E%3Cpath d=%27M3.5 8.5l3 3 6-7%27 fill=%27none%27 stroke=%27%2304211b%27 stroke-width=%272.2%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27/%3E%3C/svg%3E");
    --canvas: #0a0c10;
    --surface: #161a21;
    --surface-hover: #1f252e;
    --document-ground: #12161c;
    --hairline: #323a45;
    --field-border: #6b7584;
    --text: #eef1f5;
    --text-muted: #a3adba;
    --success: #4ade80;
    --success-ground: #0f2618;
    --error: #f97066;
    --error-ground: #2a1513;
    --shadow-control: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-page: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45);
    --shadow-float: 0 8px 28px rgba(0, 0, 0, .5);
    color-scheme: dark;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--canvas);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
}

body { accent-color: var(--brand); caret-color: var(--brand); }
::selection { background: var(--brand); color: var(--on-brand); }

h1, h2, p { margin-top: 0; }
h1 { font-size: 1.75rem; line-height: 1.2; letter-spacing: -.03em; font-weight: 650; text-wrap: balance; }
p { text-wrap: pretty; }

a { color: var(--brand-text); text-underline-offset: .18em; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; color: var(--text); -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; }

/* One checkbox for the whole app: visible in both themes, jade when checked. */
input[type="checkbox"] { appearance: none; flex-shrink: 0; display: inline-block; width: 20px; height: 20px; margin: 0; border: 1.5px solid var(--field-border); border-radius: 6px; background: var(--surface); cursor: pointer; }
input[type="checkbox"]:hover:not(:disabled) { border-color: var(--brand); }
input[type="checkbox"]:checked { border-color: var(--brand); background: var(--brand) var(--check-mark) center / 14px no-repeat; }
input[type="checkbox"]:disabled { cursor: not-allowed; background-color: var(--surface-hover); }
button, a, input, select, textarea, summary { border-radius: var(--radius-control); }

:focus-visible { outline: none; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible, [tabindex]:focus-visible:not(h1) {
    outline: 2px solid var(--brand);
    outline-offset: 3px;
}

input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 1; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.icon { width: 20px; height: 20px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Brand ---------- */

.brand { display: inline-flex; align-items: center; color: var(--text); text-decoration: none; border-radius: var(--radius-control); }
.brand-logo { display: inline-flex; align-items: center; gap: 10px; }
.brand-mark { width: 32px; height: 32px; flex-shrink: 0; }
.brand-word { height: 25px; width: auto; color: var(--text); }

/* ---------- Shell ---------- */

.workshop { min-height: 100dvh; display: flex; flex-direction: column; }

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--hairline);
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    backdrop-filter: saturate(180%) blur(16px);
}

.privacy {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    margin: 0;
    padding: 6px 12px 6px 10px;
    border-radius: 999px;
    background: var(--brand-wash);
    color: var(--text);
    font-size: .75rem;
    font-weight: 550;
    line-height: 1.3;
}
.privacy .icon { width: 16px; height: 16px; color: var(--brand-text); }

.app-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px 16px;
    flex-wrap: wrap;
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--hairline);
    color: var(--text-muted);
    font-size: .75rem;
}
.footer-brand { display: inline-flex; align-items: center; gap: 8px; }
.footer-brand .brand-mark { width: 18px; height: 18px; }
.pulse { display: inline-flex; align-items: center; gap: 8px; }
.pulse::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--success); }
.is-busy .pulse::before { background: var(--brand); }

.load-error { margin: 0; border-radius: 0; }
.load-error a { color: inherit; font-weight: 600; margin-left: 8px; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Welcome ---------- */

.welcome { flex: 1; display: grid; align-content: center; width: 100%; padding: 32px 16px 48px; }
.welcome .document-pane { max-width: 680px; width: 100%; margin: auto; background: none; border: none; overflow: visible; }

.welcome-copy { text-align: center; margin-bottom: 32px; }
.welcome-copy h1 { font-size: clamp(2rem, 7vw, 3.25rem); letter-spacing: -.035em; font-weight: 700; margin-bottom: 14px; }
.welcome-copy p { color: var(--text-muted); margin-bottom: 0; line-height: 1.7; font-size: 1.0625rem; }

/* Drop targets: the welcome upload zone and the images picker share one look and one active state. */
.upload-zone, .file-pick-face { border: 1.5px dashed var(--field-border); background: var(--surface); box-shadow: var(--shadow-card); cursor: pointer; text-align: center; }
.upload-zone:hover, .document-pane.is-drag .upload-zone, .document-pane:has(#pdf-input:focus-visible) .upload-zone,
.file-pick-face:hover, .file-pick.is-drag .file-pick-face, .file-pick:has(input:focus-visible) .file-pick-face {
    border-color: var(--brand);
    background: color-mix(in srgb, var(--brand-wash) 55%, var(--surface));
    box-shadow: 0 0 0 4px var(--brand-wash);
}
.document-pane:has(#pdf-input:focus-visible) .upload-zone, .file-pick:has(input:focus-visible) .file-pick-face { outline: 2px solid var(--brand); outline-offset: 3px; }

.upload-zone { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 40px 20px; border-radius: var(--radius-panel); }
.upload-zone strong { font-size: 1.125rem; font-weight: 600; letter-spacing: -.01em; }
.upload-icon { width: 60px; height: 60px; fill: none; stroke: var(--brand-text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 4px; }
.upload-zone:hover .primary-button { background: var(--brand-deep); }
.upload-hint { font-size: .8125rem; color: var(--text-muted); }

.welcome-tasks { margin-top: 36px; }
.section-label { margin: 0; font-size: .8125rem; font-weight: 600; letter-spacing: .01em; color: var(--text-muted); }
.welcome-error { max-width: 680px; margin: 0 auto 24px; }

.promises { list-style: none; margin: 40px 0 0; padding: 24px 0 0; border-top: 1px solid var(--hairline); display: grid; gap: 18px; }
.promises li { display: flex; gap: 12px; align-items: flex-start; }
.promises .icon { width: 22px; height: 22px; color: var(--brand-text); margin-top: 1px; }
.promises span { display: grid; gap: 2px; font-size: .8125rem; color: var(--text-muted); line-height: 1.5; }
.promises strong { color: var(--text); font-size: .875rem; font-weight: 600; }

/* ---------- Editor ---------- */

.editor { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 16px 16px 32px; max-width: 1440px; width: 100%; margin: 0 auto; align-content: start; }

.document-pane { min-width: 0; border: 1px solid var(--hairline); border-radius: var(--radius-panel); background: var(--document-ground); overflow: hidden; }
.document-pane.is-drag { outline: 2px solid var(--brand); outline-offset: 2px; }

.document-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--surface); padding: 10px 12px; border: 1px solid var(--hairline); border-radius: var(--radius-inset); grid-column: 1 / -1; }
.document-title { display: flex; align-items: center; gap: 12px; flex: 1 1 0; min-width: 0; }
.document-title .icon { width: 28px; height: 28px; color: var(--brand-text); }
.document-title > div { min-width: 0; display: grid; gap: 2px; }
.document-title strong { font-size: .875rem; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.document-title span { color: var(--text-muted); font-size: .75rem; font-variant-numeric: tabular-nums; }
.document-switch { max-width: 100px; min-height: var(--tap); background: var(--surface); border: 1px solid var(--field-border); padding: 8px; font-size: .8125rem; }

.icon-button { width: var(--tap); height: var(--tap); min-width: var(--tap); flex-shrink: 0; border: 0; background: transparent; display: inline-grid; place-items: center; color: var(--text-muted); }
.icon-button:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }

/* The page leads. Tasks follow on a phone; a result puts the download first. */
.editor .document-pane { order: 2; }
.editor .task-panel { order: 3; }
.editor.is-result .task-panel, .editor.is-selecting .task-panel { order: 2; }
.editor.is-result .document-pane, .editor.is-selecting .document-pane { order: 3; }
.editor.is-choosing .panel-copy { margin-bottom: 4px; }
.editor.is-selecting { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

/* ---------- Task panel ---------- */

.task-panel { min-width: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.task-panel h1 { margin: 0; font-size: 1.5rem; }
.task-heading { display: flex; align-items: center; gap: 8px; margin-left: -8px; }
.task-heading h1 { flex: 1; }
.panel-copy { color: var(--text-muted); font-size: .875rem; margin: 0; line-height: 1.6; }

.task-options { display: grid; margin-top: 8px; }
.task-option { display: flex; width: 100%; gap: 20px; align-items: center; justify-content: space-between; border: 0; border-bottom: 1px solid var(--hairline); border-radius: 0; padding: 12px 8px; min-height: 56px; background: transparent; text-align: left; }
.task-option > span { display: grid; gap: 3px; }
.task-option strong { font-size: .9375rem; font-weight: 600; }
.task-option small { font-size: .8125rem; line-height: 1.45; color: var(--text-muted); overflow-wrap: anywhere; }
.task-option .icon { width: 16px; height: 16px; color: var(--text-muted); }
.task-option:hover:not(:disabled) { background: var(--surface); border-radius: var(--radius-control); border-bottom-color: transparent; }
.task-option:hover:not(:disabled) .icon { color: var(--brand-text); transform: translateX(2px); }
.compact { padding-block: 14px; }

.more-tools, .advanced { font-size: .875rem; }
summary { cursor: pointer; color: var(--text-muted); min-height: var(--tap); display: flex; align-items: center; gap: 10px; padding: 8px 0; list-style: none; font-weight: 550; }
summary::-webkit-details-marker { display: none; }
summary::before { content: ""; width: 7px; height: 7px; margin-left: 2px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); }
details[open] > summary::before { transform: rotate(45deg) translate(-1px, -1px); }
summary:hover { color: var(--text); }
.advanced > :not(summary) { margin-top: 12px; }

.selection-guide { color: var(--text-muted); font-size: .875rem; margin: 0; }
.selection-tools { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.selection-tools .text-button { flex-shrink: 0; padding: 8px; }
.selection-count { font-size: .8125rem; margin: 0; color: var(--text-muted); overflow-wrap: anywhere; }

.inspect { font-family: var(--mono); font-size: .8125rem; padding: 16px; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius-inset); white-space: pre-wrap; overflow-wrap: anywhere; }
.attachment-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: .8125rem; }

/* ---------- Buttons ---------- */

.primary-button, .secondary-button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    padding: 12px 20px;
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    font-size: .9375rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}
.primary-button { background: var(--brand); color: var(--on-brand); width: 100%; box-shadow: var(--shadow-control); }
.primary-button.is-inline { width: auto; padding-inline: 30px; }
.primary-button:hover:not(:disabled) { background: var(--brand-deep); }
.primary-button:active:not(:disabled) { transform: translateY(1px); }
.secondary-button { background: var(--surface); color: var(--text); border-color: var(--hairline); }
.secondary-button:hover:not(:disabled) { border-color: var(--field-border); background: var(--surface-hover); }

.text-button { background: none; border: 0; color: var(--brand-text); padding: 10px 0; min-height: var(--tap); font-size: inherit; font-weight: 550; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.text-button:hover:not(:disabled) { text-decoration-thickness: 2px; }
.text-button.danger { color: var(--error); }
.ghost { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); background: none; border: 0; padding: 8px; color: var(--brand-text); font-size: .875rem; }

/* Disabled controls read as unavailable without fading into the background. */
.primary-button:disabled { background: var(--surface-hover); color: var(--text-muted); border-color: var(--hairline); box-shadow: none; }
.secondary-button:disabled, .text-button:disabled, .ghost:disabled, .icon-button:disabled, .back-button:disabled, .task-option:disabled, .file-choice:disabled { color: var(--text-muted); }
.text-button:disabled { text-decoration: none; }
.back-button { display: inline-flex; align-items: center; align-self: start; gap: 6px; margin: 0 0 8px -6px; padding: 6px; min-height: var(--tap); border: 0; background: none; color: var(--text-muted); font-size: .8125rem; }
.back-button .icon { width: 16px; height: 16px; }

.confirm-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; min-height: var(--tap); }
.document-toolbar .confirm-inline { flex: 1 0 100%; }
.confirm-inline p { margin: 0; font-size: .875rem; }
.confirm-inline:focus { outline: 2px solid var(--brand); outline-offset: 3px; }

/* Primary task action stays reachable on a phone. */
.task-action { position: fixed; z-index: 10; bottom: max(12px, env(safe-area-inset-bottom)); left: 16px; width: calc(100% - 32px); box-shadow: var(--shadow-float); }
.editor:has(.task-action) { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.editor:has(.task-action)::after { content: ""; position: fixed; bottom: 0; left: 0; right: 0; height: calc(76px + env(safe-area-inset-bottom)); z-index: 9; background: var(--surface); border-top: 1px solid var(--hairline); pointer-events: none; }

/* ---------- Forms ---------- */

fieldset.form { border: 0; margin: 0; padding: 0; min-width: 0; }
.form { display: grid; gap: 16px; }
.form .primary-button { margin-top: 8px; }

.field { display: grid; gap: 8px; font-size: .875rem; }
.field > span { color: var(--text-muted); font-size: .8125rem; }
.field input, .field select, .field textarea { width: 100%; min-height: 48px; font-size: 1rem; padding: 10px 12px; background: var(--surface); border: 1px solid var(--field-border); border-radius: var(--radius-control); color: var(--text); }
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--text-muted); }
.field textarea { min-height: 100px; resize: vertical; }
.field-check { display: flex; align-items: center; gap: 10px; font-size: .8125rem; min-height: var(--tap); }

.file-pick { display: grid; gap: 8px; }
.file-pick-face { display: grid; place-items: center; padding: 24px; min-height: 120px; border-radius: var(--radius-inset); font-size: .875rem; }

.photo-strip { display: flex; gap: var(--grid); overflow-x: auto; }
.photo-chip { width: 56px; height: 56px; object-fit: cover; border: 1px solid var(--hairline); border-radius: var(--radius-thumb); background: var(--canvas); }

/* ---------- Notes and results ---------- */

.note { font-size: .875rem; line-height: 1.6; margin: 0; }
.note.is-error { padding: 12px 16px; background: var(--error-ground); color: var(--error); border-radius: var(--radius-control); }
.note.is-ok { color: var(--success); }

.result-symbol { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--success-ground); color: var(--success); margin-bottom: 8px; }
.result-symbol svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.result-file { display: grid; gap: 8px; padding: 20px; background: var(--surface); border-radius: var(--radius-inset); margin: 8px 0; }
.result-file strong { font-size: .875rem; font-weight: 500; overflow-wrap: anywhere; }
.result-file span { font-size: .8125rem; color: var(--text-muted); }
.result-download { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border: 0; border-bottom: 1px solid var(--hairline); border-radius: 0; background: none; text-align: left; font-size: .8125rem; overflow-wrap: anywhere; }
.result-download span { color: var(--brand-text); font-weight: 550; flex-shrink: 0; }

.local-note { border-top: 1px solid var(--hairline); padding-top: 20px; display: flex; align-items: flex-start; gap: 8px; color: var(--text-muted); font-size: .75rem; line-height: 1.6; margin: 16px 0 0; }
.local-note .icon { width: 15px; height: 15px; margin-top: 2px; }

/* ---------- Merge list ---------- */

.merge-files { padding: 8px 16px 16px; background: var(--surface); border-bottom: 1px solid var(--hairline); display: grid; gap: 8px; }
.merge-file { display: flex; align-items: center; min-width: 0; }
.file-choice { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 10px 4px; }
.file-choice > span { display: inline-grid; place-items: center; min-width: 24px; height: 24px; border-radius: 50%; background: var(--surface-hover); color: var(--text-muted); font-size: .75rem; font-variant-numeric: tabular-nums; }
.file-choice strong { font-size: .8125rem; font-weight: 500; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.file-choice small { display: none; color: var(--text-muted); white-space: nowrap; font-size: .75rem; }
.file-choice[aria-pressed="true"] strong { color: var(--brand-text); font-weight: 600; }
.file-choice[aria-pressed="true"] > span { background: var(--brand); color: var(--on-brand); }

/* ---------- Preview ---------- */

.preview { position: relative; display: grid; grid-template-rows: minmax(0, 1fr) auto auto; gap: 4px; height: min(48dvh, 520px); min-height: 280px; padding: 16px 12px 8px; }
.preview.is-loading { place-items: center; }
.preview-skeleton { width: min(72%, 480px); height: min(78%, 640px); background: var(--surface); border-radius: var(--radius-thumb); box-shadow: var(--shadow-page); }
.preview-placeholder { min-height: 180px; display: grid; place-content: center; text-align: center; padding: 24px; color: var(--text-muted); }

.preview-scroll {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    border-radius: var(--radius-thumb);
    scrollbar-color: var(--field-border) transparent;
    scrollbar-width: thin;
    scrollbar-gutter: stable;
}
.preview-sheet { --look-zoom: 1; display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 8px; min-width: 100%; }

/* PDF pages are paper: they stay white in dark mode. */
.preview-leaf { position: relative; width: calc(var(--leaf-w, 100%) * var(--look-zoom, 1)); max-width: 720px; min-height: 100px; background: #fff; box-shadow: var(--shadow-page); }
.preview-leaf.is-marked { outline: 2px solid var(--brand); outline-offset: 2px; }
.preview-leaf canvas { display: block; width: 100%; height: auto; }

.preview-text { position: absolute; inset: 0; overflow: hidden; line-height: 1; -webkit-text-size-adjust: none; }
.preview-text span { position: absolute; color: transparent; white-space: pre; cursor: text; transform-origin: 0 0; }
.preview-text span.is-hit { background: var(--brand); color: var(--on-brand); }

.preview-meta { margin: 0; padding: 10px 0 4px; text-align: center; color: var(--text-muted); font-size: .75rem; font-variant-numeric: tabular-nums; }
.preview-hits { font-family: var(--mono); font-size: .75rem; font-variant-numeric: tabular-nums; color: var(--brand-text); }

.preview-strip { display: none; position: relative; overflow-x: auto; overflow-y: hidden; padding: 4px 0; scrollbar-color: var(--field-border) transparent; scrollbar-width: thin; }
.preview-rail { position: relative; height: 90px; }
.preview-thumb { position: absolute; top: 0; width: 56px; padding: 0; border: 1px solid var(--hairline); border-radius: var(--radius-thumb); overflow: hidden; background: var(--surface); color: var(--text-muted); font-size: .75rem; font-variant-numeric: tabular-nums; }
.preview-thumb canvas { display: block; width: 100%; height: 64px; object-fit: contain; background: #fff; }
.preview-thumb span { display: block; padding: 2px 0; text-align: center; }
.preview-thumb[aria-current="true"] { border-color: var(--brand); box-shadow: inset 0 -3px 0 var(--brand); color: var(--text); }
.preview-thumb.is-marked { border-color: var(--brand); }
.preview-thumb.is-dropped { opacity: .35; }

.preview-lock { margin: auto; max-width: 28ch; padding: 24px; text-align: center; color: var(--text-muted); font-size: .875rem; }

.look-field, .look-find { display: flex; align-items: center; gap: var(--grid); min-width: 0; }
.look-field span, .look-find span:first-child { font-size: .8125rem; color: var(--text-muted); }
.look-field input, .look-find input { min-height: 36px; padding: 8px 10px; border: 1px solid var(--hairline); background: var(--canvas); color: var(--text); }
.look-field input { width: 6.5rem; }
.look-find { flex: 1 1 10rem; }
.look-find input { flex: 1; min-width: 0; width: 100%; }

/* Page selection: tiles with a labeled checkbox. */
.page-select { position: absolute; z-index: 2; top: 12px; right: 12px; display: flex; align-items: center; gap: 8px; background: var(--surface); color: var(--text); padding: 10px 14px; min-height: var(--tap); border: 1px solid var(--field-border); border-radius: var(--radius-control); cursor: pointer; font-size: .8125rem; }
.page-select:has(input:checked) { color: var(--brand-text); border-color: var(--brand); }
.is-busy .page-select { pointer-events: none; opacity: .6; }

.preview.is-selecting { height: 60dvh; }
.preview.is-selecting .preview-sheet { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 16px; }
.preview.is-selecting .preview-leaf { width: 100%; min-height: 190px; padding-bottom: 52px; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius-inset); overflow: hidden; box-shadow: var(--shadow-card); }
.preview.is-selecting .preview-leaf:hover { border-color: var(--field-border); }
.preview.is-selecting .preview-leaf.is-marked { border-color: var(--brand); outline: 1px solid var(--brand); outline-offset: 0; }
.preview.is-selecting .preview-text { pointer-events: none; }
.preview.is-selecting .preview-meta { display: none; }
.preview.is-selecting .page-select { inset: 0; align-items: end; justify-content: center; padding: 15px 8px; background: transparent; border: 0; border-radius: 0; font-weight: 550; }
.preview.is-selecting .page-select:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 3px; }
.preview.is-selecting .page-select:has(input:checked) { background: linear-gradient(transparent calc(100% - 52px), var(--brand-wash) 0); }

/* ---------- Status pages (404, engine QA) ---------- */

.status-page { flex: 1; display: grid; align-content: center; justify-items: center; gap: 4px; max-width: 520px; width: 100%; margin: 0 auto; padding: 48px 16px; text-align: center; }
.status-page p { color: var(--text-muted); }
.status-page .primary-button { margin-top: 12px; }
.status-page .status-code { margin: 0; font-size: .8125rem; font-weight: 600; letter-spacing: .12em; color: var(--brand-text); }

/* ---------- Boot and fatal states ---------- */

.boot { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 16px; text-align: center; padding: 24px; }
.boot-mark { width: 56px; height: 56px; }
.boot-line { color: var(--text-muted); font-size: .875rem; margin: 0; max-width: 32ch; }
.boot-pulse { position: relative; width: 120px; height: 2px; overflow: hidden; border-radius: 2px; background: var(--hairline); }
.boot-pulse::after { content: ""; position: absolute; inset: 0; width: 40%; border-radius: inherit; background: var(--brand); }
.noscript { max-width: 40ch; margin: 24px auto; padding: 0 16px; text-align: center; color: var(--text-muted); }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; width: 100%; z-index: 100; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); background: var(--error-ground); color: var(--error); box-shadow: var(--shadow-float); }
#blazor-error-ui .reload { color: inherit; font-weight: 600; margin-left: 8px; }
#blazor-error-ui .dismiss { cursor: pointer; margin-left: 24px; }

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: no-preference) {
    .primary-button, .secondary-button, .task-option, .upload-zone, .file-pick-face, .icon-button, .field input, .field select { transition: background-color 160ms ease-out, border-color 160ms ease-out, box-shadow 160ms ease-out, color 160ms ease-out, transform 160ms var(--ease); }
    .task-option .icon, summary::before { transition: transform 200ms var(--ease), color 160ms ease-out; }
    .boot-pulse::after { animation: boot-slide 1.2s var(--ease) infinite; }
    .result-symbol { animation: pop-in 420ms var(--ease) both; }
}

@keyframes boot-slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
@keyframes pop-in { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Breakpoints ---------- */

@media (min-width: 560px) {
    .promises { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
    .promises li { flex-direction: column; gap: 10px; }
    .welcome-tasks .task-options { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; }
}

@media (min-width: 760px) {
    .app-header { padding: 14px 32px; min-height: 68px; }
    .brand-mark { width: 34px; height: 34px; }
    .brand-word { height: 27px; }
    .privacy { font-size: .8125rem; }
    .app-footer { padding-inline: 32px; }

    .editor { grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); gap: 24px; padding: 24px 32px 32px; align-items: start; }
    .editor .document-pane, .editor.is-result .document-pane { order: 0; grid-column: 1; grid-row: 2; }
    .editor .task-panel, .editor.is-result .task-panel { order: 0; grid-column: 2; grid-row: 2; }
    .task-panel { position: sticky; top: 92px; }
    .task-action { position: static; width: 100%; box-shadow: none; }
    .editor:has(.task-action) { padding-bottom: 32px; }
    .editor:has(.task-action)::after { display: none; }

    .preview { height: min(76dvh, 880px); padding: 28px 24px 12px; }
    .preview-strip { display: block; }
    .preview.is-selecting .preview-strip { display: none; }
    .preview.is-selecting .preview-sheet { grid-template-columns: repeat(auto-fill, minmax(160px, 200px)); justify-content: center; gap: 20px; }
    .preview-placeholder { min-height: 420px; }

    .document-switch { max-width: 180px; }
    .file-choice small { display: block; }
}

@media (max-width: 420px) {
    .privacy { padding: 6px 10px 6px 8px; font-size: .6875rem; }
    .brand-word { height: 22px; }
    .brand-mark { width: 28px; height: 28px; }
}

@media (max-width: 359px) {
    .brand-word { display: none; }
    .editor, .welcome { padding-inline: 12px; }
    .preview.is-selecting .preview-sheet { gap: 12px; }
}
