:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-hover: #252836;
    --border: #2e3144;
    --text: #e4e4e7;
    --text-muted: #8b8d9e;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --equal: #4ade80;
    --equal-bg: rgba(74, 222, 128, 0.12);
    --replace: #fb923c;
    --replace-bg: rgba(251, 146, 60, 0.12);
    --delete: #f87171;
    --delete-bg: rgba(248, 113, 113, 0.12);
    --insert: #60a5fa;
    --insert-bg: rgba(96, 165, 250, 0.12);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

header {
    text-align: center;
    padding: 2rem 1rem 1rem;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    margin-top: 0.5rem;
    font-size: 0.95rem;
}

main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
}

/* Upload Section */
.upload-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    width: 100%;
    max-width: 800px;
}

.upload-box {
    background: var(--bg-card);
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
}

.upload-box:hover,
.upload-box.dragover {
    border-color: var(--primary);
    background: var(--bg-hover);
}

.upload-box.has-file {
    border-color: var(--equal);
    border-style: solid;
}

.upload-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.upload-label {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.upload-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.file-name {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--equal);
    word-break: break-all;
    min-height: 1.2em;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-primary {
    background: var(--primary);
    color: white;
    padding: 0.75rem 2.5rem;
    font-size: 1rem;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

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

.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    background: var(--bg-hover);
    color: var(--text-muted);
}

.btn-small.active {
    background: var(--primary);
    color: white;
}

.btn-small:hover {
    color: var(--text);
}

.btn-icon {
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-hover);
    color: var(--text);
    font-size: 0.85rem;
}

.btn-icon:hover {
    background: var(--primary);
    color: white;
}

/* Loading */
.loading {
    text-align: center;
    padding: 2rem;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

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

.hidden {
    display: none !important;
}

/* Stats Bar */
.stats-bar {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.stat {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 0.75rem 1.25rem;
    text-align: center;
    min-width: 100px;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-equal { color: var(--equal); }
.stat-replace { color: var(--replace); }
.stat-delete { color: var(--delete); }
.stat-insert { color: var(--insert); }

/* Controls */
.controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--bg-card);
    border-radius: 8px;
}

.checkbox-control {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    font-size: 0.85rem;
    user-select: none;
}

.checkbox-control input {
    display: none;
}

.check-box {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 2px solid var(--border);
    position: relative;
    transition: all 0.2s;
}

.check-box.equal { border-color: var(--equal); }
.check-box.replace { border-color: var(--replace); }
.check-box.delete { border-color: var(--delete); }
.check-box.insert { border-color: var(--insert); }

.checkbox-control input:checked + .check-box.equal { background: var(--equal); }
.checkbox-control input:checked + .check-box.replace { background: var(--replace); }
.checkbox-control input:checked + .check-box.delete { background: var(--delete); }
.checkbox-control input:checked + .check-box.insert { background: var(--insert); }

.checkbox-control input:checked + .check-box::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 5px;
    width: 4px;
    height: 8px;
    border: solid var(--bg);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.hint-text {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
}

.view-toggle {
    display: flex;
    gap: 2px;
    background: var(--bg);
    border-radius: 8px;
    padding: 2px;
    margin-left: 0.5rem;
}

/* Viewer */
.viewer-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    height: calc(100vh - 220px);
    min-height: 500px;
}

.viewer-panel,
.diff-panel {
    background: var(--bg-card);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-title {
    font-weight: 600;
    font-size: 0.9rem;
}

.page-indicator {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 4px;
}

.scroll-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: #2a2a2a;
    scroll-behavior: auto;
}

.pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem;
    gap: 0.5rem;
}

.page-wrapper {
    position: relative;
    max-width: 100%;
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    border-radius: 2px;
    flex-shrink: 0;
}

.page-wrapper canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Overlay zones for double-click navigation */
.overlay-zone {
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.15s, box-shadow 0.15s;
    z-index: 2;
}

.overlay-zone:hover {
    background: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.overlay-zone.overlay-equal:hover {
    box-shadow: inset 0 0 0 2px var(--equal);
    background: rgba(74, 222, 128, 0.06);
}
.overlay-zone.overlay-replace:hover {
    box-shadow: inset 0 0 0 2px var(--replace);
    background: rgba(251, 146, 60, 0.08);
}
.overlay-zone.overlay-delete:hover {
    box-shadow: inset 0 0 0 2px var(--delete);
    background: rgba(248, 113, 113, 0.08);
}
.overlay-zone.overlay-insert:hover {
    box-shadow: inset 0 0 0 2px var(--insert);
    background: rgba(96, 165, 250, 0.08);
}

/* Flash animation on double-click match */
.overlay-zone.flash {
    animation: zone-flash 1.2s ease-out;
}

@keyframes zone-flash {
    0% {
        background: rgba(99, 102, 241, 0.5);
        box-shadow: inset 0 0 0 3px var(--primary), 0 0 20px rgba(99, 102, 241, 0.6);
    }
    40% {
        background: rgba(99, 102, 241, 0.3);
        box-shadow: inset 0 0 0 3px var(--primary), 0 0 12px rgba(99, 102, 241, 0.4);
    }
    100% {
        background: transparent;
        box-shadow: none;
    }
}

/* Text Diff */
.diff-content {
    flex: 1;
    overflow: auto;
    padding: 1rem;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
}

.diff-line {
    padding: 2px 8px;
    border-radius: 3px;
    margin-bottom: 1px;
    white-space: pre-wrap;
    word-break: break-word;
}

.diff-line.equal { background: var(--equal-bg); border-left: 3px solid var(--equal); }
.diff-line.replace { background: var(--replace-bg); border-left: 3px solid var(--replace); }
.diff-line.delete { background: var(--delete-bg); border-left: 3px solid var(--delete); }
.diff-line.insert { background: var(--insert-bg); border-left: 3px solid var(--insert); }

/* Word-level diff highlights */
.word-equal {
    color: var(--text);
}

.word-replace {
    background: var(--replace);
    color: var(--bg);
    border-radius: 2px;
    padding: 0 2px;
    font-weight: 600;
}

.word-delete {
    background: var(--delete);
    color: var(--bg);
    border-radius: 2px;
    padding: 0 2px;
    text-decoration: line-through;
    font-weight: 600;
}

.word-insert {
    background: var(--insert);
    color: var(--bg);
    border-radius: 2px;
    padding: 0 2px;
    font-weight: 600;
}

/* Responsive */
@media (max-width: 768px) {
    .upload-grid {
        grid-template-columns: 1fr;
    }
    .viewer-container {
        grid-template-columns: 1fr;
    }
    .stats-bar {
        gap: 0.5rem;
    }
    .stat {
        min-width: 80px;
        padding: 0.5rem;
    }
}
