:root {
    --primary-hue: 160;
    --primary: hsl(var(--primary-hue), 80%, 50%);
    --primary-dark: hsl(var(--primary-hue), 80%, 40%);
    --secondary: hsl(200, 80%, 60%);
    --bg-dark: hsl(220, 40%, 8%);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.7);
    --danger: hsl(0, 80%, 60%);
    --success: hsl(140, 70%, 50%);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
    padding: 2rem 1rem;
}

/* Background Animations */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    filter: blur(100px);
}

.blob {
    position: absolute;
    border-radius: 50%;
    opacity: 0.5;
    animation: move 25s infinite alternate ease-in-out;
}

.blob-1 {
    width: 500px;
    height: 500px;
    background: linear-gradient(135deg, var(--primary), hsl(200, 80%, 50%));
    top: -100px;
    left: -100px;
}

.blob-2 {
    width: 400px;
    height: 400px;
    background: linear-gradient(135deg, hsl(280, 80%, 60%), hsl(320, 80%, 50%));
    bottom: -100px;
    right: -100px;
    animation-delay: -8s;
}

.blob-3 {
    width: 350px;
    height: 350px;
    background: linear-gradient(135deg, hsl(40, 90%, 55%), hsl(20, 90%, 55%));
    top: 50%;
    left: 50%;
    animation-delay: -15s;
}

@keyframes move {
    0% {
        transform: translate(0, 0) scale(1) rotate(0deg);
    }

    50% {
        transform: translate(30px, -30px) scale(1.1) rotate(5deg);
    }

    100% {
        transform: translate(-20px, 40px) scale(0.95) rotate(-5deg);
    }
}

/* App Container */
.app-container {
    background: var(--glass-bg);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid var(--glass-border);
    border-radius: 28px;
    padding: 2.5rem;
    width: 100%;
    max-width: 650px;
    box-shadow:
        0 25px 50px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    text-align: center;
}

header h1 {
    font-size: 2.2rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #fff 30%, var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

header p {
    color: var(--text-muted);
    font-size: 1rem;
    margin-bottom: 2rem;
}

/* Drop Zone */
.drop-zone {
    border: 2px dashed var(--glass-border);
    border-radius: 20px;
    padding: 3rem 2rem;
    transition: all 0.3s ease;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.02);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.06);
    transform: scale(1.01);
}

.drop-zone.has-file {
    border-style: solid;
    border-color: var(--success);
    background: rgba(70, 200, 100, 0.1);
}

.icon-container {
    color: var(--primary);
    margin-bottom: 1rem;
}

.drop-zone h3 {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

.drop-zone p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.drop-zone span {
    color: var(--primary);
    font-weight: 600;
    text-decoration: underline;
}

/* Format Selection */
.format-selection {
    margin-top: 2rem;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    border: 1px solid var(--glass-border);
}

.format-selection h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.format-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.8rem;
}

.format-options.three-col {
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

#formatGrid {
    grid-template-columns: repeat(4, 1fr);
}

.format-option {
    position: relative;
    cursor: pointer;
    padding: 1.2rem 0.8rem;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 2px solid transparent;
    transition: all 0.3s ease;
    text-align: center;
}

.format-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.format-option:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
}

.format-option.active {
    border-color: var(--primary);
    background: rgba(70, 200, 150, 0.15);
}

.format-option.ocr-option.active {
    border-color: #f59e0b;
    background: rgba(245, 158, 11, 0.15);
}

.format-icon {
    font-size: 1.8rem;
    margin-bottom: 0.4rem;
}

.format-name {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.2rem;
}

.format-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.ocr-note {
    margin-top: 0.8rem;
    padding: 0.8rem 1rem;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 10px;
    font-size: 0.85rem;
    color: #f59e0b;
    text-align: left;
}

.ocr-note.success {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
    color: #10b981;
    margin-top: 0;
}

/* Sub Options */
.sub-options {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.option-group {
    flex: 1;
    min-width: 150px;
    text-align: left;
}

.option-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.option-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.option-group select:hover {
    border-color: var(--primary);
}

.option-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(70, 200, 150, 0.2);
}

/* File Info Card */
.file-info-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
    padding: 1rem 1.25rem;
    background: rgba(70, 200, 100, 0.1);
    border: 1px solid rgba(70, 200, 100, 0.3);
    border-radius: 14px;
    text-align: left;
}

.file-info-card .file-icon {
    font-size: 2.5rem;
}

.file-details {
    flex: 1;
    overflow: hidden;
}

.file-details .file-name {
    font-weight: 600;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.file-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
}

.file-remove:hover {
    color: var(--danger);
    background: rgba(255, 100, 100, 0.15);
}

/* Progress Section */
.progress-section {
    margin-top: 1.5rem;
}

.progress-bar {
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 10px;
    transition: width 0.3s ease;
}

.progress-text {
    margin-top: 0.75rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Actions */
.actions {
    margin-top: 2rem;
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn {
    border: none;
    padding: 1rem 2.5rem;
    border-radius: 14px;
    font-family: inherit;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: 0 10px 25px rgba(70, 200, 150, 0.35);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 15px 30px rgba(70, 200, 150, 0.45);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(0.8);
    transform: none;
    box-shadow: none;
}

/* Preview Section */
.preview-section {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    border: 1px solid var(--glass-border);
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.preview-header h3 {
    font-size: 1rem;
    color: var(--text-main);
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.preview-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.preview-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary);
}

.preview-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.preview-page-info {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.preview-page-info input {
    width: 56px;
    padding: 0.3rem 0.5rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-main);
    text-align: center;
    font-family: inherit;
    font-size: 0.85rem;
}

.preview-page-info input:focus {
    outline: none;
    border-color: var(--primary);
}

.preview-zoom {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-left: 0.5rem;
    padding-left: 0.5rem;
    border-left: 1px solid var(--glass-border);
}

#zoomLabel {
    min-width: 48px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.preview-canvas-wrap {
    position: relative;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 12px;
    padding: 0.75rem;
    overflow: auto;
    max-height: 60vh;
    text-align: center;
}

.preview-canvas-wrap canvas {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.preview-status {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    min-height: 1.2em;
}

/* Generated output preview */
.output-preview {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(16, 185, 129, 0.35);
    border-radius: 16px;
    text-align: left;
}

.output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.output-header h3 {
    font-size: 1.05rem;
}

.output-header p {
    margin-top: 0.25rem;
    color: var(--text-muted);
    font-size: 0.82rem;
    word-break: break-word;
}

.btn-secondary {
    flex-shrink: 0;
    padding: 0.65rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    font-size: 0.85rem;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.18);
}

.output-content {
    min-height: 80px;
    max-height: 520px;
    overflow: auto;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.25);
}

.output-code {
    margin: 0;
    padding: 1rem;
    color: #d1fae5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font: 0.85rem/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.output-frame {
    display: block;
    width: 100%;
    height: 450px;
    border: 0;
    background: #fff;
}

.output-table-wrap {
    overflow: auto;
}

.output-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text-main);
    font-size: 0.82rem;
}

.output-table th,
.output-table td {
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--glass-border);
    text-align: left;
    vertical-align: top;
    white-space: pre-wrap;
}

.output-table th {
    position: sticky;
    top: 0;
    background: rgba(16, 185, 129, 0.22);
    font-weight: 600;
}

.output-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
    padding: 0.75rem;
}

.output-image-grid figure {
    margin: 0;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 8px;
}

.output-image-grid img {
    display: block;
    width: 100%;
    height: 190px;
    object-fit: contain;
    background: #fff;
    border-radius: 4px;
}

.output-image-grid figcaption {
    padding-top: 0.45rem;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-align: center;
}

/* Loader */
.loader {
    width: 22px;
    height: 22px;
    border: 3px solid transparent;
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: none;
}

.btn-primary.loading .btn-text {
    display: none;
}

.btn-primary.loading .loader {
    display: block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive */
@media (max-width: 600px) {
    .app-container {
        padding: 1.5rem;
        border-radius: 20px;
    }

    header h1 {
        font-size: 1.6rem;
    }

    .format-options,
    #formatGrid {
        grid-template-columns: repeat(2, 1fr);
    }

    .sub-options {
        flex-direction: column;
    }

    .option-group {
        min-width: 100%;
    }

    .preview-canvas-wrap {
        max-height: 50vh;
    }

    .output-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .output-header .btn-secondary {
        width: 100%;
        justify-content: center;
    }

    .output-frame {
        height: 360px;
    }
}