:root {
    --bg: #f6f8fb;
    --bg-panel: #ffffff;
    --bg-panel-2: #f8fafc;
    --bg-input: #ffffff;
    --paper: #ffffff;
    --border: #e2e8f0;
    --border-light: #cbd5e1;
    --text: #172033;
    --text-dim: #64748b;
    --text-faint: #94a3b8;
    --ink: #2563eb;
    --ink-soft: rgba(37, 99, 235, 0.10);
    --ink-2: #3b82f6;
    --brass: #2563eb;
    --brass-soft: rgba(37, 99, 235, 0.08);
    --danger: #dc2626;
    --danger-soft: rgba(220, 38, 38, 0.08);
    --radius: 5px;
    --sans: 'Inter', -apple-system, sans-serif;
    --display: 'Fraunces', var(--sans);
}

::selection {
    background: var(--brass-soft);
    color: var(--text);
}

button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--brass);
    outline-offset: 2px;
}

.wrap {
    max-width: 1180px;
    margin: 0 auto;
    padding: 30px 24px 70px;
}


.brand-mark {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border: 1px solid var(--border-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-panel);
    color: var(--brass);
    font-family: 'Great Vibes', cursive;
    font-size: 24px;
}

header.top h1 {
    font-family: var(--display);
    font-weight: 600;
    font-size: 23px;
    margin: 0 0 4px;
    letter-spacing: 0.2px;
}

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

.top-inner {
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

section.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 22px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 10px;
}

.panel-head .ph-left {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.panel-head .ph-num {
    font-family: var(--display);
    font-weight: 600;
    color: var(--brass);
    font-size: 13px;
}

.panel-head h2 {
    font-family: var(--display);
    font-weight: 600;
    font-size: 16.5px;
    margin: 0;
}

.panel-head .ph-sub {
    font-size: 12.5px;
    color: var(--text-faint);
    margin-top: 2px;
}

/* ---- Tabs ---- */
.mode-tabs {
    display: flex;
    gap: 6px;
    padding: 14px 22px 0;
}

.mode-tab {
    background: none;
    border: 1px solid transparent;
    color: var(--text-faint);
    font-family: var(--sans);
    font-weight: 500;
    font-size: 13px;
    padding: 9px 16px;
    border-radius: var(--radius) var(--radius) 0 0;
    cursor: pointer;
    border-bottom: none;
    position: relative;
    top: 1px;
}

.mode-tab.active {
    color: var(--text);
    background: var(--bg-panel-2);
    border-color: var(--border);
    border-bottom-color: var(--bg-panel-2);
}

.mode-tab:hover:not(.active) {
    color: var(--text-dim);
}

.panel-body {
    padding: 22px;
}

.stage-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 22px;
}

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

.workspace {
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
}

.mode-view {
    display: none;
}

.mode-view.active {
    display: block;
}

/* draw / type canvases */
.canvas-surface {
    background: var(--paper);
    background-image:
        linear-gradient(rgba(55, 44, 30, 0.05) 1px, transparent 1px);
    background-size: 100% 32px;
    border: 1px solid var(--border-light);
    border-radius: 3px;
    width: 100%;
    display: block;
    touch-action: none;
    cursor: crosshair;
}

.canvas-toolbar {
    display: flex;
    align-items: center;
    gap: 18px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 9px;
}

.tool-label {
    font-size: 11.5px;
    color: var(--text-faint);
    font-weight: 500;
}

.swatches {
    display: flex;
    gap: 6px;
}

.swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    box-shadow: 0 0 0 1px var(--border-light);
}

.swatch.active {
    border-color: var(--brass);
}

input[type=color] {
    width: 26px;
    height: 26px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: none;
    cursor: pointer;
    box-shadow: 0 0 0 1px var(--border-light);
}

input[type=range] {
    accent-color: var(--brass);
    width: 110px;
}

.thin-btn {
    background: none;
    border: 1px solid var(--border-light);
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 500;
    padding: 7px 13px;
    border-radius: var(--radius);
    cursor: pointer;
}

.thin-btn:hover {
    border-color: var(--brass);
    color: var(--brass);
}

.thin-btn:disabled {
    opacity: .35;
    cursor: not-allowed;
}

/* type mode */
.type-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    padding: 11px 13px;
    border-radius: var(--radius);
    margin-bottom: 14px;
}

.font-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 14px;
}

.font-opt {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 8px;
    text-align: center;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 19px;
    line-height: 1.2;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.font-opt.active {
    border-color: var(--brass);
    background: var(--brass-soft);
    color: var(--text);
}

.font-opt span {
    font-family: inherit;
}

/* upload mode */
.dropzone {
    border: 1px dashed var(--border-light);
    border-radius: var(--radius);
    padding: 26px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s ease;
}

.dropzone:hover,
.dropzone.drag {
    border-color: var(--brass);
    background: var(--brass-soft);
}

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

.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: 4px;
}

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

.upload-compare {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 14px;
}

.compare-box {
    text-align: center;
}

.compare-box .cb-label {
    font-size: 11px;
    color: var(--text-faint);
    margin-bottom: 6px;
    font-weight: 500;
}

.compare-canvas-wrap {
    background:
        linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
        linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
    background-size: 14px 14px;
    background-position: 0 0, 0 7px, 7px -7px, -7px 0px;
    background-color: #f1f5f9;
    border: 1px solid var(--border-light);
    border-radius: 3px;
    overflow: hidden;
}

.compare-canvas-wrap canvas {
    width: 100%;
    display: block;
}

/* preview / output col */
.preview-col {
    display: flex;
    flex-direction: column;
}

.preview-title {
    font-size: 11.5px;
    color: var(--text-faint);
    font-weight: 500;
    margin-bottom: 10px;
    letter-spacing: 0.2px;
}

.stamp-preview {
    flex: 1;
    min-height: 200px;
    background:
        linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
        linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
    background-color: #f1f5f9;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.stamp-preview img {
    max-width: 100%;
    max-height: 220px;
}

.stamp-empty {
    color: var(--text-faint);
    font-size: 12.5px;
    text-align: center;
    max-width: 180px;
    line-height: 1.5;
}

.btn {
    width: 100%;
    padding: 12px 16px;
    background: var(--brass);
    color: #ffffff;
    border: none;
    border-radius: var(--radius);
    font-family: var(--sans);
    font-weight: 600;
    font-size: 13.5px;
    cursor: pointer;
    margin-top: 14px;
    transition: filter .12s ease;
}

.btn:hover:not(:disabled) {
    filter: brightness(1.08);
}

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

.btn.ink {
    background: var(--ink);
    color: #fff;
}

/* ---- Stage 2 : Apply to PDF ---- */
.stage2-locked {
    padding: 34px 22px;
    text-align: center;
    color: var(--text-faint);
    font-size: 13px;
}

.stage2-locked svg {
    color: var(--border-light);
    margin-bottom: 10px;
}

.pdf-grid {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 22px;
}

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

.thumb-strip {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 10px;
    margin-bottom: 16px;
}

.thumb {
    flex-shrink: 0;
    width: 78px;
    cursor: pointer;
    position: relative;
}

.thumb canvas {
    width: 100%;
    display: block;
    border: 2px solid var(--border-light);
    border-radius: 3px;
    background: #fff;
}

.thumb.selected canvas {
    border-color: var(--ink-2);
}

.thumb.reference canvas {
    border-color: var(--brass);
}

.thumb .t-num {
    font-size: 10.5px;
    color: var(--text-faint);
    text-align: center;
    margin-top: 5px;
}

.thumb .t-check {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 16px;
    height: 16px;
    background: rgba(15, 23, 42, 0.08);
    border: 1px solid var(--border-light);
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: var(--text-faint);
}

.thumb.selected .t-check {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
}

.stage-canvas-wrap {
    position: relative;
    display: inline-block;
    width: 100%;
    background: #fff;
    border: 1px solid var(--border-light);
    border-radius: 3px;
    overflow: hidden;
}

.stage-canvas-wrap canvas {
    width: 100%;
    display: block;
}

.stamp-overlay {
    position: absolute;
    cursor: move;
    touch-action: none;
    border: 1.5px dashed var(--brass);
}

.stamp-overlay img {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
}

.resize-handle {
    position: absolute;
    right: -7px;
    bottom: -7px;
    width: 15px;
    height: 15px;
    background: var(--brass);
    border-radius: 50%;
    cursor: nwse-resize;
    border: 2px solid var(--bg-panel-2);
}

.pdf-side {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.side-box {
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.side-box .sb-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.side-box .sb-desc {
    font-size: 11.5px;
    color: var(--text-faint);
    line-height: 1.5;
}

.page-count-badge {
    font-family: var(--sans);
    font-size: 12px;
    color: var(--brass);
    font-weight: 600;
}

.status-line {
    font-size: 12px;
    color: var(--text-faint);
    margin-top: 10px;
    min-height: 16px;
}

.error-box {
    margin-top: 12px;
    padding: 11px 12px;
    border: 1px solid rgba(180, 85, 63, 0.4);
    background: var(--danger-soft);
    border-radius: var(--radius);
    font-size: 12px;
    color: #dc2626;
    line-height: 1.5;
    display: none;
}

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

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

.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-size: 11px;
    color: var(--text-faint);
    flex-shrink: 0;
}

.file-chip .fclear {
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: pointer;
    font-size: 15px;
    padding: 2px 4px;
}

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

.privacy-note {
    display: flex;
    gap: 8px;
    font-size: 11.5px;
    color: var(--text-faint);
    line-height: 1.55;
    margin-top: 6px;
}

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

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

/* ================================
   WHITE THEME POLISH
   ================================ */

body {
    background: var(--bg);
    color: var(--text);
}

header.top {
    color: var(--text);
}

section.panel,
.workspace,
.side-box {
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04),
                0 8px 24px rgba(15, 23, 42, 0.035);
}

.brand-mark {
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.mode-tab.active {
    box-shadow: inset 0 1px 0 rgba(37, 99, 235, 0.08);
}

.type-input,
.font-opt,
.file-chip {
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.025);
}

.type-input:focus,
.font-opt:hover {
    border-color: var(--ink-2);
}

.dropzone {
    background: #fbfdff;
}

.dropzone:hover,
.dropzone.drag {
    background: var(--brass-soft);
}

.canvas-surface,
.stage-canvas-wrap,
.compare-canvas-wrap,
.stamp-preview {
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.btn {
    box-shadow: 0 2px 5px rgba(37, 99, 235, 0.18);
}

.btn:hover:not(:disabled) {
    filter: brightness(1.03);
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.20);
}

.thin-btn:hover {
    background: rgba(37, 99, 235, 0.04);
}

.file-chip {
    background: #f8fafc;
}

.privacy-note svg {
    color: var(--ink);
}

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