:root {
    color-scheme: light;
    --ink: #172033;
    --muted: #687386;
    --line: #dfe4ec;
    --soft: #f5f7fa;
    --white: #fff;
    --blue: #2f66e8;
    --blue-dark: #1f4fc7;
    --blue-soft: #edf3ff;
    --green: #16805d;
    --amber: #a96b08;
    --red: #b93838;
    --shadow: 0 16px 45px rgba(23, 32, 51, .08);
    font-family: Inter, "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
}

.ocr-ui-loading body {
    overflow: hidden;
}

.ocr-ui-loading body > * {
    visibility: hidden;
}

.ocr-ui-loading body::before {
    position: fixed;
    z-index: 9999;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    color: var(--ink);
    background:
        radial-gradient(circle at 92% 2%, rgba(47, 102, 232, .08), transparent 28rem),
        #f7f8fb;
    content: "Densen OCR";
    visibility: visible;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: .04em;
}

.ocr-ui-loading body::after {
    position: fixed;
    z-index: 10000;
    top: calc(50% + 38px);
    left: 50%;
    width: 28px;
    height: 28px;
    margin-left: -14px;
    border: 3px solid rgba(47, 102, 232, .18);
    border-top-color: var(--blue);
    border-radius: 50%;
    content: "";
    visibility: visible;
    animation: spin .8s linear infinite;
}

body {
    color: var(--ink);
    background:
        radial-gradient(circle at 92% 2%, rgba(47, 102, 232, .08), transparent 28rem),
        #f7f8fb;
}

.topbar {
    position: sticky;
    z-index: 50;
    top: 0;
    display: flex;
    min-height: 68px;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 10px max(24px, calc((100% - 1950px) / 2));
    border-bottom: 1px solid rgba(223, 228, 236, .85);
    background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(16px);
}

.brand {
    display: inline-flex;
    align-items: center;
}

.brand img {
    display: block;
    width: auto;
    height: 36px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.language-button {
    min-width: 48px;
    min-height: 38px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--ink);
    background: var(--white);
}

.privacy-pill {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid #cde8dd;
    border-radius: 999px;
    color: #12684d;
    background: #f1fbf7;
    font-size: 13px;
    font-weight: 600;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 3px rgba(22, 128, 93, .12);
}

body > header {
    padding: 58px max(24px, calc((100% - 1950px) / 2)) 42px;
    color: var(--ink);
    background: transparent;
}

body > header .eyebrow {
    margin: 0 0 12px;
    color: var(--blue);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .16em;
}

body > header h1 {
    max-width: 760px;
    margin: 0 0 14px;
    font-size: clamp(32px, 5vw, 52px);
    line-height: 1.12;
    letter-spacing: -.03em;
}

body > header > p:not(.eyebrow) {
    max-width: 760px;
    margin: 0;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.75;
}

main {
    max-width: 1950px;
    margin: 0 auto;
    padding: 0 24px 48px;
}

.workflow-steps {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    margin: 0 0 20px;
    padding: 0;
    list-style: none;
}

.workflow-steps li {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #8c96a7;
    font-size: 13px;
    font-weight: 700;
}

.workflow-steps li:not(:last-child)::after {
    position: absolute;
    z-index: -1;
    top: 50%;
    right: 14px;
    left: 42px;
    height: 1px;
    background: var(--line);
    content: "";
}

.workflow-steps b {
    display: inline-grid;
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 50%;
    color: #8c96a7;
    background: #f7f8fb;
}

.workflow-steps .active {
    color: var(--blue);
}

.workflow-steps .active b {
    border-color: var(--blue);
    color: var(--white);
    background: var(--blue);
    box-shadow: 0 0 0 4px rgba(47, 102, 232, .1);
}

.workflow-steps .complete {
    color: var(--green);
}

.workflow-steps .complete b {
    border-color: var(--green);
    color: var(--white);
    background: var(--green);
}

.toolbar {
    display: grid;
    grid-template-columns: minmax(250px, 1fr) minmax(210px, auto) auto minmax(180px, auto) auto;
    gap: 12px;
    align-items: stretch;
    margin-bottom: 18px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--white);
    box-shadow: var(--shadow);
}

.source-picker {
    min-width: 0;
}

.dropzone {
    display: flex;
    min-height: 82px;
    flex-direction: column;
    justify-content: center;
    padding: 14px 18px;
    border: 1px dashed #aeb9c9;
    border-radius: 12px;
    background: var(--soft);
    transition: border-color 220ms ease, background-color 220ms ease, transform 220ms ease;
}

.dropzone:hover,
.dropzone.drag {
    border-color: var(--blue);
    background: var(--blue-soft);
    transform: translateY(-1px);
}

.dropzone strong {
    color: var(--ink);
    font-size: 15px;
}

.dropzone span {
    margin-top: 5px;
    color: var(--muted);
    line-height: 1.5;
}

.options {
    min-height: 46px;
    align-self: stretch;
    border-color: var(--line);
    border-radius: 10px;
    color: var(--muted);
    background: var(--white);
}

.options select,
.pdf-option select {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 7px 32px 7px 10px;
    color: var(--ink);
    background: var(--white);
}

.recognition-mode {
    position: relative;
    display: grid;
    align-content: center;
    gap: 5px;
    min-width: 190px;
}

.recognition-mode > span {
    color: var(--ink);
    font-weight: 700;
}

.recognition-mode small {
    display: none;
    position: absolute;
    z-index: 20;
    top: calc(100% + 7px);
    right: 0;
    width: 280px;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--muted);
    background: var(--white);
    box-shadow: 0 8px 24px rgba(23, 32, 51, .12);
    line-height: 1.45;
}

.recognition-mode:focus-within small,
.recognition-mode:hover small {
    display: block;
}

button {
    min-height: 42px;
    border-radius: 10px;
    background: var(--blue);
    transition: border-color 200ms ease, background-color 200ms ease, transform 200ms ease;
}

button:hover:not(:disabled) {
    background: var(--blue-dark);
    transform: translateY(-1px);
}

button:focus-visible,
select:focus-visible,
label:focus-visible,
summary:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(47, 102, 232, .25);
    outline-offset: 2px;
}

#run {
    min-width: 122px;
    align-self: stretch;
}

#status {
    grid-column: 1 / -1;
    min-height: 42px;
    padding: 11px 13px;
    border: 1px solid #d7e3ff;
    border-radius: 10px;
    color: #254d9d;
    background: var(--blue-soft);
    line-height: 1.45;
}

#status[data-loading="true"]::before {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 8px;
    border: 2px solid rgba(47, 102, 232, .25);
    border-top-color: var(--blue);
    border-radius: 50%;
    vertical-align: -2px;
    content: "";
    animation: spin .8s linear infinite;
}

#stats {
    margin: 0 0 18px;
    padding: 0 4px;
    color: var(--muted);
}

.card {
    border-color: var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.pdf-controls {
    margin-bottom: 18px;
    padding: 18px;
}

.pdf-meta {
    color: var(--ink);
}

.pdf-diagnostics {
    border-color: #f0cccc;
    background: #fff8f8;
}

.grid {
    grid-template-columns: minmax(0, 1.55fr) minmax(340px, 1fr);
    gap: 18px;
}

.preview-header,
.result-header {
    min-height: 58px;
    padding: 10px 12px 10px 20px;
    border-bottom-color: var(--line);
}

.preview-header h2,
.result-header h2 {
    color: var(--ink);
    font-size: 16px;
}

.preview-actions button,
.result-actions button,
.pdf-result-tabs button,
.pdf-page-nav button {
    border-color: var(--line);
    color: var(--blue);
    background: var(--white);
}

.preview-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.preview-actions button.active {
    border-color: var(--blue);
    color: var(--white);
    background: var(--blue);
}

.preview-actions button:hover:not(:disabled),
.result-actions button:hover:not(:disabled),
.pdf-result-tabs button:hover:not(:disabled),
.pdf-page-nav button:hover:not(:disabled) {
    border-color: var(--blue);
    color: var(--blue-dark);
    background: var(--blue-soft);
}

.preview {
    min-height: 470px;
    background:
        linear-gradient(45deg, #f2f4f8 25%, transparent 25%),
        linear-gradient(-45deg, #f2f4f8 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f2f4f8 75%),
        linear-gradient(-45deg, transparent 75%, #f2f4f8 75%),
        #fafbfc;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    background-size: 16px 16px;
}

canvas {
    box-shadow: 0 4px 20px rgba(23, 32, 51, .1);
}

.selection-layer {
    position: absolute;
    z-index: 3;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    touch-action: none;
}

.selection-layer.active {
    cursor: crosshair;
    pointer-events: auto;
}

.selection-rectangle {
    position: absolute;
    border: 2px solid var(--blue);
    border-radius: 3px;
    background: rgba(47, 102, 232, .16);
    box-shadow:
        0 0 0 9999px rgba(23, 32, 51, .28),
        0 0 0 1px rgba(255, 255, 255, .9) inset;
    pointer-events: none;
}

#overlay polygon {
    stroke: var(--red);
}

#overlay text {
    fill: var(--red);
}

#overlay .active {
    fill: rgba(47, 102, 232, .14);
    stroke: var(--blue);
}

#results {
    max-height: 600px;
}

.recognized-table-section + .recognized-table-section {
    border-top: 1px solid var(--line);
}

.recognized-table-section h3 {
    position: sticky;
    z-index: 2;
    top: 0;
    margin: 0;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    background: var(--soft);
    font-size: 12px;
}

.recognized-table-scroll {
    overflow-x: auto;
}

.recognized-table {
    width: 100%;
    min-width: max-content;
    border-collapse: collapse;
    background: var(--white);
}

.recognized-table td {
    min-width: 110px;
    max-width: 320px;
    padding: 10px 12px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    color: var(--ink);
    font-size: 13px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.recognized-table tr:last-child td {
    border-bottom: 0;
}

.recognized-table td:last-child {
    border-right: 0;
}

.line:hover,
.line.active {
    background: var(--blue-soft);
}

.pdf-result-tabs,
.page-heading {
    border-bottom-color: var(--line);
    background: var(--soft);
}

.pdf-result-tabs button.active {
    border-color: var(--blue);
    color: var(--blue-dark);
    background: var(--blue-soft);
}

.empty {
    padding: 64px 24px;
    color: var(--muted);
    line-height: 1.6;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 900px) {
    .toolbar {
        grid-template-columns: 1fr 1fr;
    }

    .source-picker,
    #status {
        grid-column: 1 / -1;
    }

    .grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .topbar {
        min-height: 60px;
        padding: 9px max(14px, env(safe-area-inset-right)) 9px max(14px, env(safe-area-inset-left));
    }

    .brand img {
        height: 31px;
    }

    .privacy-pill {
        display: none;
    }

    body > header {
        padding: 36px max(16px, env(safe-area-inset-left)) 28px;
    }

    body > header h1 {
        font-size: 34px;
    }

    main {
        margin-top: 0;
        padding-right: max(14px, env(safe-area-inset-right));
        padding-left: max(14px, env(safe-area-inset-left));
    }

    .toolbar {
        display: flex;
        padding: 14px;
        border-radius: 16px;
    }

    .mobile-source-actions {
        display: flex;
    }

    .source-button {
        border-color: var(--line);
        color: var(--blue);
        border-radius: 10px;
    }

    #run {
        border-radius: 12px;
        background: var(--blue);
    }

    .card {
        border-radius: 16px;
    }

    .workflow-steps li {
        font-size: 0;
    }

    .workflow-steps li b {
        font-size: 13px;
    }

    .workflow-steps li:not(:last-child)::after {
        right: 10px;
        left: 36px;
    }

    .preview {
        min-height: 280px;
    }
}

@media (max-width: 430px) {
    body > header h1 {
        font-size: 30px;
    }

    .topbar-actions {
        gap: 6px;
    }

    .language-button {
        min-width: 44px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
