:root {
    /* Color system */
    --bg: #f4f6f9;
    --bg-panel: #ffffff;
    --bg-panel-2: #fafbfc;
    --bg-input: #f7f9fb;

    --grid-line: rgba(30, 41, 59, 0.05);

    --border: #e4e8ee;
    --border-light: #cbd5e1;

    --text: #1a2233;
    --text-dim: #5b6779;
    --text-faint: #94a0b2;

    --accent: #2f42e0;
    --accent-hover: #2536c4;
    --accent-dim: rgba(47, 66, 224, 0.10);
    --accent-ring: rgba(47, 66, 224, 0.16);

    --accent-2: #159a82;
    --accent-2-dim: rgba(21, 154, 130, 0.09);
    --accent-2-ring: rgba(21, 154, 130, 0.18);

    --accent-3: #d69e2e;
    --danger: #dc3d2e;
    --danger-dim: rgba(220, 61, 46, 0.08);

    --key-color: #2563eb;

    /* Spacing scale */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 22px;
    --sp-6: 28px;

    /* Radius & shadow */
    --radius-sm: 5px;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.10);

    --ease: cubic-bezier(0.4, 0, 0.2, 1);

    --mono: 'JetBrains Mono', ui-monospace, monospace;
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --display: 'Space Grotesk', var(--sans);
}

* {
    box-sizing: border-box;
}

body {
    background: #ffffff;
    color: var(--text);
    font-family: var(--sans);
    -webkit-font-smoothing: antialiased;
}

::selection {
    background: var(--accent-ring);
    color: var(--text);
}

/* Focus visibility */

button:focus-visible,
input:focus-visible,
label:focus-within {
    outline: 2px solid var(--accent-2);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Main wrapper */

.wrap {
    max-width: 1240px;
    margin: 0 auto;
    padding: 32px 24px 72px;
    color: var(--text);
}

/* Header */

header.top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    padding-bottom: 24px;
    margin-bottom: 28px;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-family: var(--mono);
    font-size: 13px;
    flex-shrink: 0;
    background: var(--bg-panel);
    box-shadow: var(--shadow-sm);
}

.brand h1 {
    font-family: var(--display);
    font-size: 20px;
    font-weight: 600;
    margin: 0;
    letter-spacing: 0.1px;
    color: var(--text);
}

.brand p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-dim);
    max-width: 480px;
    line-height: 1.55;
}

.top-note {
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--text-faint);
    text-align: right;
    line-height: 1.8;
    white-space: nowrap;
    padding-top: 8px;
}

.top-note .dot {
    color: var(--accent-2);
}

/* Main grid */

main.grid {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 24px;
    align-items: start;
}

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

    .top-note {
        display: none;
    }
}

/* Panels */

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

/* Control panel */

.control-panel {
    padding: 24px;
}

.step {
    margin-bottom: 28px;
}

.step:last-of-type {
    margin-bottom: 20px;
}

.step-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 12px;
}

.step-num {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    border: 1px solid var(--accent-ring);
    background: var(--accent-dim);
    width: 21px;
    height: 21px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.step-title {
    font-family: var(--display);
    font-weight: 600;
    font-size: 14.5px;
    color: var(--text);
    letter-spacing: 0.1px;
}

.step-sub {
    font-size: 12px;
    color: var(--text-faint);
    margin: 0 0 14px 31px;
    line-height: 1.55;
}

/* Dropzone */

.dropzone {
    border: 1.5px dashed var(--border-light);
    border-radius: var(--radius);
    padding: 26px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
    background: var(--bg-input);
}

.dropzone:hover,
.dropzone.drag {
    border-color: var(--accent-2);
    background: var(--accent-2-dim);
    box-shadow: 0 0 0 4px var(--accent-2-ring);
}

.dropzone svg {
    color: var(--text-faint);
    margin-bottom: 10px;
}

.dropzone .dz-title {
    font-size: 13.5px;
    color: var(--text);
    font-weight: 500;
}

.dropzone .dz-sub {
    font-size: 11.5px;
    color: var(--text-faint);
    margin-top: 5px;
    font-family: var(--mono);
}

input[type="file"] {
    display: none;
}

/* File chip */

.file-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 13px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    font-size: 12.5px;
}

.file-chip .fname {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
    font-weight: 500;
}

.file-chip .fmeta {
    font-family: var(--mono);
    color: var(--text-faint);
    font-size: 11px;
    flex-shrink: 0;
}

.file-chip .fclear {
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 4px;
    transition: color 0.12s var(--ease), background-color 0.12s var(--ease);
}

.file-chip .fclear:hover {
    color: var(--danger);
    background: var(--danger-dim);
}

/* Mode cards */

.mode-list {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.mode-card {
    /* display: flex; */
    width: 100%;
    gap: 11px;
    align-items: flex-start;
    padding: 12px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    background: var(--bg-input);
    transition: border-color 0.12s var(--ease), background-color 0.12s var(--ease), box-shadow 0.12s var(--ease);
}

.mode-card > div {
    flex: 1 1 auto;
    min-width: 0;
}

.mode-card:hover {
    border-color: var(--border-light);
}

.mode-card.active {
    border-color: var(--accent-2);
    background: var(--accent-2-dim);
    box-shadow: 0 0 0 3px var(--accent-2-ring);
}

.mode-card input {
    margin-top: 3px;
    accent-color: var(--accent-2);
    flex-shrink: 0;
}

.mode-card .m-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.mode-card .m-desc {
    font-size: 11.5px;
    color: var(--text-faint);
    margin-top: 3px;
    line-height: 1.5;
}

/* Range */

.range-row {
    display: flex;
    gap: 8px;
}

.radio-inline {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12.5px;
    color: var(--text-dim);
    cursor: pointer;
}

.radio-inline input {
    accent-color: var(--accent-2);
}

.range-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--mono);
    font-size: 12.5px;
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    margin-top: 10px;
    box-sizing: border-box;
    transition: border-color 0.12s var(--ease), box-shadow 0.12s var(--ease);
}

.range-input:focus {
    border-color: var(--accent-2);
    box-shadow: 0 0 0 3px var(--accent-2-ring);
}

.range-input:disabled {
    opacity: 0.4;
}

.range-input::placeholder {
    color: var(--text-faint);
}

/* Buttons */

.btn {
    width: 100%;
    padding: 13px 16px;
    background: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: var(--radius);
    font-family: var(--sans);
    font-weight: 600;
    font-size: 13.5px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background-color 0.12s var(--ease), box-shadow 0.12s var(--ease), transform 0.08s var(--ease);
}

.btn:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 4px 12px var(--accent-ring);
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    box-shadow: none;
}

.btn.secondary {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text);
    box-shadow: none;
}

.btn.secondary:hover:not(:disabled) {
    border-color: var(--accent-2);
    color: var(--accent-2);
    background: var(--accent-2-dim);
}

/* Progress */

.progress-track {
    margin-top: 14px;
    height: 5px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
    display: none;
}

.progress-track.show {
    display: block;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-2);
    border-radius: 3px;
    transition: width 0.15s var(--ease);
}

.progress-label {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 8px;
    display: none;
}

.progress-label.show {
    display: block;
}

/* Error */

.error-box {
    margin-top: 14px;
    padding: 12px 13px;
    border: 1px solid rgba(220, 61, 46, 0.25);
    background: var(--danger-dim);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--danger);
    line-height: 1.55;
    display: none;
}

.error-box.show {
    display: block;
}

/* Privacy */

.privacy-note {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
    font-size: 11.5px;
    color: var(--text-faint);
    line-height: 1.6;
    display: flex;
    gap: 8px;
}

.privacy-note svg {
    flex-shrink: 0;
    margin-top: 1px;
    color: var(--accent-2);
}

/* Output panel */

.output-panel {
    min-height: 560px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.output-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    padding: 6px 10px;
    background: var(--bg-panel-2);
}

.tabs {
    display: flex;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-faint);
    font-family: var(--mono);
    font-size: 12.5px;
    padding: 13px 16px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.12s var(--ease), border-color 0.12s var(--ease);
}

.tab-btn:hover:not(:disabled) {
    color: var(--text-dim);
}

.tab-btn.active {
    color: var(--text);
    border-bottom-color: var(--accent);
    font-weight: 500;
}

.tab-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.output-actions {
    display: flex;
    gap: 8px;
    padding-right: 6px;
}

/* Action buttons */

.icon-btn {
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    color: var(--text-dim);
    font-family: var(--sans);
    font-size: 11.5px;
    font-weight: 500;
    padding: 7px 13px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: border-color 0.12s var(--ease), color 0.12s var(--ease), background-color 0.12s var(--ease);
}

.icon-btn:hover:not(:disabled) {
    border-color: var(--accent-2);
    color: var(--accent-2);
    background: var(--accent-2-dim);
}

.icon-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.icon-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.icon-btn.primary:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #ffffff;
}

/* Output body */

.output-body {
    flex: 1;
    position: relative;
    padding: 20px;
    overflow: auto;
}

/* Empty state */

.empty-state {
    height: 100%;
    min-height: 460px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-faint);
    gap: 12px;
}

.empty-state svg {
    color: var(--border-light);
}

.empty-state .e-title {
    font-family: var(--display);
    font-size: 14.5px;
    color: var(--text-dim);
    font-weight: 600;
}

.empty-state .e-sub {
    font-size: 12px;
    max-width: 280px;
    line-height: 1.55;
}

/* Views */

.view {
    display: none;
}

.view.active {
    display: block;
}

/* Preview */

.preview-canvas-wrap {
    position: relative;
    display: inline-block;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #ffffff;
    box-shadow: var(--shadow-sm);
    line-height: 0;
    overflow: hidden;
}

.preview-shell {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}

.preview-legend {
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--text-faint);
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 190px;
    padding-top: 2px;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
    flex-shrink: 0;
}

.legend-title {
    color: var(--text-dim);
    font-family: var(--sans);
    font-size: 12.5px;
    font-weight: 600;
    margin-bottom: 3px;
}

.item-dot {
    position: absolute;
    width: 5px;
    height: 5px;
    background: var(--accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 2px var(--accent-dim);
    cursor: pointer;
    transition: background-color 0.1s var(--ease), box-shadow 0.1s var(--ease);
}

.item-dot:hover {
    background: var(--accent-2);
    box-shadow: 0 0 0 3px var(--accent-2-ring);
    z-index: 5;
}

.item-tooltip {
    position: absolute;
    background: #ffffff;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text);
    max-width: 240px;
    line-height: 1.6;
    pointer-events: none;
    z-index: 10;
    box-shadow: var(--shadow-lg);
}

.item-tooltip .t-text {
    color: var(--accent-2);
    word-break: break-word;
    font-weight: 600;
}

.item-tooltip .t-row {
    color: var(--text-faint);
}

.item-tooltip .t-row b {
    color: var(--key-color);
    font-weight: 500;
}

.preview-note {
    margin-top: 16px;
    font-size: 11.5px;
    color: var(--text-faint);
    font-family: var(--mono);
}

/* JSON view */

.json-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.stat-strip {
    display: flex;
    gap: 18px;
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--text-faint);
}

.stat-strip b {
    color: var(--text-dim);
    font-weight: 600;
}

pre.json-pre {
    margin: 0;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 18px 20px;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.65;

    width: 800px;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;

    overflow-x: auto;
    overflow-y: auto;

    max-height: 560px;
    white-space: pre;
}

.jk {
    color: var(--key-color);
}

.js {
    color: var(--accent-2);
}

.jn {
    color: var(--accent-3);
}

.jb {
    color: #8b5cf6;
}

.jp {
    color: var(--text-faint);
}

/* Footer */

footer.credit {
    margin-top: 32px;
    text-align: center;
    font-size: 11.5px;
    color: var(--text-faint);
    font-family: var(--mono);
}

/* PDF-to-JSON default hidden */

#pdf-to-json {
    display: none;
}