:root {
    --cg-blue: #2563eb;
    --cg-blue-dark: #1d4ed8;
    --cg-green: #16a34a;
    --cg-border: #e2e8f0;
    --cg-muted: #64748b;
    --cg-panel: #ffffff;
    --cg-bg: #f8fafc;
}

* {
    box-sizing: border-box;
}

button,
input,
select {
    font: inherit;
}

.editor-shell {
    border: 1px solid var(--cg-border);
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 12px 34px rgba(15, 23, 42, .06);
}

.upload-dropzone {
    display: flex;
    min-height: 430px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    margin: 14px;
    padding: 36px 20px;
    border: 2px dashed #93c5fd;
    border-radius: 15px;
    text-align: center;
    background:
        radial-gradient(circle at center, rgba(37, 99, 235, .07), transparent 22rem),
        #f8fbff;
    cursor: pointer;
    transition: .18s ease;
}

.upload-dropzone:hover,
.upload-dropzone.dragover {
    border-color: #2563eb;
    background-color: #eff6ff;
}

.upload-icon {
    display: grid;
    width: 74px;
    height: 74px;
    place-items: center;
    margin-bottom: 18px;
    border-radius: 22px;
    color: #2563eb;
    font-size: 34px;
    background: #dbeafe;
}

.upload-dropzone h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 900;
    letter-spacing: -.025em;
}

.upload-dropzone p {
    margin: 8px 0 18px;
    color: #64748b;
    font-size: 14px;
}

.upload-button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 18px;
    border-radius: 11px;
    color: #fff;
    font-size: 14px;
    font-weight: 900;
    background: #2563eb;
}

.upload-dropzone small {
    margin-top: 13px;
    color: #94a3b8;
    font-size: 11px;
}

.privacy-note {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 14px 14px;
    padding: 11px 13px;
    border-radius: 11px;
    color: #166534;
    background: #f0fdf4;
}

.privacy-note > i {
    font-size: 20px;
}

.privacy-note strong,
.privacy-note span {
    display: block;
}

.privacy-note strong {
    font-size: 12px;
}

.privacy-note span {
    margin-top: 1px;
    font-size: 11px;
    color: #15803d;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    min-height: calc(100vh - 175px);
    overflow: hidden;
    border: 1px solid var(--cg-border);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 12px 34px rgba(15, 23, 42, .06);
}

.preview-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-width: 0;
    min-height: 0;
    background: #0f172a;
}

.preview-toolbar {
    display: flex;
    min-height: 56px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
    color: #fff;
    background: #111827;
}

.file-summary {
    min-width: 0;
}

.file-summary strong,
.file-summary span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-summary strong {
    max-width: 600px;
    font-size: 12px;
}

.file-summary span {
    margin-top: 2px;
    color: #94a3b8;
    font-size: 10px;
}

.mini-button {
    display: inline-flex;
    min-height: 34px;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    border: 1px solid rgba(255, 255, 255, .15);
    border-radius: 8px;
    color: #e2e8f0;
    font-size: 11px;
    font-weight: 800;
    background: rgba(255, 255, 255, .05);
    cursor: pointer;
}

.canvas-area {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 460px;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 14px;
    background:
        linear-gradient(45deg, #182235 25%, transparent 25%),
        linear-gradient(-45deg, #182235 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #182235 75%),
        linear-gradient(-45deg, transparent 75%, #182235 75%),
        #111827;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    background-size: 16px 16px;
}

#editorImage {
    display: block;
    max-width: 100%;
}

.canvas-area .cropper-container {
    max-width: 100% !important;
    max-height: 100% !important;
}

.preview-footer {
    display: flex;
    min-height: 46px;
    align-items: center;
    gap: 26px;
    padding: 7px 12px;
    border-top: 1px solid rgba(255, 255, 255, .1);
    color: #cbd5e1;
    background: #111827;
}

.preview-footer div {
    display: flex;
    align-items: baseline;
    gap: 7px;
}

.preview-footer span {
    font-size: 10px;
    color: #94a3b8;
}

.preview-footer strong {
    font-size: 11px;
}

.controls-panel {
    min-height: 0;
    overflow-y: auto;
    padding: 13px;
    border-left: 1px solid var(--cg-border);
    background: #f8fafc;
    scrollbar-width: thin;
}

.control-section {
    margin-bottom: 10px;
    padding: 11px;
    border: 1px solid #e2e8f0;
    border-radius: 11px;
    background: #fff;
}

.section-heading,
.quality-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.section-heading {
    margin-bottom: 9px;
}

.section-heading > span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: #334155;
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .035em;
}

.section-heading > strong,
.quality-row strong {
    color: #2563eb;
    font-size: 11px;
}

.text-action {
    padding: 0;
    border: 0;
    color: #2563eb;
    font-size: 10px;
    font-weight: 800;
    background: transparent;
    cursor: pointer;
}

.ratio-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.ratio-grid button,
.transform-grid button {
    min-height: 34px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    color: #475569;
    font-size: 11px;
    font-weight: 800;
    background: #fff;
    cursor: pointer;
    transition: .15s ease;
}

.ratio-grid button:hover,
.transform-grid button:hover {
    border-color: #93c5fd;
    background: #eff6ff;
}

.ratio-grid button.active {
    color: #fff;
    border-color: #2563eb;
    background: #2563eb;
}

.transform-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.transform-grid button {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 2px;
    padding: 5px 2px;
    font-size: 10px;
}

.transform-grid button i {
    font-size: 14px;
}

.range-input {
    width: 100%;
    accent-color: #2563eb;
}

.output-section {
    margin-bottom: 10px;
}

.field-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
}

.field-grid label > span,
.filename-field > span,
.quality-row span {
    display: block;
    margin-bottom: 5px;
    color: #64748b;
    font-size: 10px;
    font-weight: 800;
}

.field-grid select,
.filename-field input {
    width: 100%;
    height: 35px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    outline: none;
    color: #334155;
    font-size: 11px;
    background: #fff;
}

.field-grid select {
    padding: 0 8px;
}

.field-grid select:focus,
.filename-field input:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .08);
}

.check-row {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 9px 0;
    color: #475569;
    font-size: 10px;
    font-weight: 700;
}

.check-row input {
    accent-color: #2563eb;
}

#qualityControl {
    padding-top: 8px;
    border-top: 1px solid #f1f5f9;
}

.quality-row {
    margin-bottom: 4px;
}

.filename-field {
    display: block;
    margin-top: 10px;
}

.filename-field > div {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
}

.filename-field input {
    padding: 0 9px;
    border-radius: 8px 0 0 8px;
}

.filename-field strong {
    display: flex;
    height: 35px;
    align-items: center;
    padding: 0 9px;
    border: 1px solid #e2e8f0;
    border-left: 0;
    border-radius: 0 8px 8px 0;
    color: #64748b;
    font-size: 10px;
    background: #f8fafc;
}

.stats-card {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding: 10px;
    border: 1px solid #dbeafe;
    border-radius: 11px;
    background: #eff6ff;
}

.stats-card > i {
    color: #60a5fa;
}

.stats-card div {
    min-width: 0;
}

.stats-card span,
.stats-card strong,
.stats-card small {
    display: block;
}

.stats-card span {
    color: #64748b;
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
}

.stats-card strong {
    margin-top: 2px;
    color: #1e3a8a;
    font-size: 11px;
}

.stats-card small {
    margin-top: 1px;
    color: #64748b;
    font-size: 9px;
}

.download-button {
    display: flex;
    width: 100%;
    min-height: 52px;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 8px 14px;
    border: 0;
    border-radius: 11px;
    color: #fff;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    box-shadow: 0 8px 20px rgba(37, 99, 235, .24);
    cursor: pointer;
}

.download-button > i {
    font-size: 20px;
}

.download-button span {
    text-align: left;
}

.download-button strong,
.download-button small {
    display: block;
}

.download-button strong {
    font-size: 13px;
}

.download-button small {
    margin-top: 1px;
    color: #dbeafe;
    font-size: 9px;
}

.download-button:disabled {
    cursor: wait;
    opacity: .65;
}

.local-processing {
    margin: 9px 2px 0;
    color: #64748b;
    font-size: 9px;
    line-height: 1.5;
    text-align: center;
}

.local-processing i {
    margin-right: 4px;
    color: #16a34a;
}

.working-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    background: rgba(15, 23, 42, .66);
    backdrop-filter: blur(2px);
}

.working-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 10px;
    color: #fff;
    font-size: 11px;
    background: rgba(15, 23, 42, .94);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, .25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: cgSpin .7s linear infinite;
}

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

.toast {
    position: fixed;
    top: 78px;
    right: 16px;
    z-index: 10000;
    max-width: min(360px, calc(100vw - 32px));
    padding: 11px 14px;
    border-radius: 10px;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    box-shadow: 0 14px 36px rgba(15, 23, 42, .22);
}

.toast.success {
    background: #15803d;
}

.toast.error {
    background: #b91c1c;
}

.toast.info {
    background: #1d4ed8;
}

.hidden {
    display: none !important;
}

/* Dark mode */
.dark .editor-shell,
.dark .workspace,
.dark .control-section {
    border-color: #1e293b;
    background: #0f172a;
}

.dark .upload-dropzone {
    border-color: #334155;
    color: #e2e8f0;
    background:
        radial-gradient(circle at center, rgba(37, 99, 235, .12), transparent 22rem),
        #0f172a;
}

.dark .upload-dropzone p,
.dark .upload-dropzone small {
    color: #94a3b8;
}

.dark .privacy-note {
    color: #86efac;
    background: #052e16;
}

.dark .privacy-note span {
    color: #4ade80;
}

.dark .controls-panel {
    border-color: #1e293b;
    background: #020617;
}

.dark .section-heading > span {
    color: #cbd5e1;
}

.dark .ratio-grid button,
.dark .transform-grid button,
.dark .field-grid select,
.dark .filename-field input {
    color: #cbd5e1;
    border-color: #334155;
    background: #0f172a;
}

.dark .ratio-grid button:hover,
.dark .transform-grid button:hover {
    border-color: #3b82f6;
    background: #172554;
}

.dark .ratio-grid button.active {
    color: #fff;
    border-color: #2563eb;
    background: #2563eb;
}

.dark .check-row,
.dark .field-grid label > span,
.dark .filename-field > span,
.dark .quality-row span {
    color: #94a3b8;
}

.dark #qualityControl {
    border-color: #1e293b;
}

.dark .filename-field strong {
    color: #94a3b8;
    border-color: #334155;
    background: #020617;
}

.dark .stats-card {
    border-color: #1e3a8a;
    background: #172554;
}

.dark .stats-card span,
.dark .stats-card small {
    color: #93c5fd;
}

.dark .stats-card strong {
    color: #dbeafe;
}

@media (max-width: 980px) {
    .workspace {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .preview-panel {
        min-height: 58vh;
    }

    .controls-panel {
        overflow: visible;
        border-top: 1px solid var(--cg-border);
        border-left: 0;
    }

    .canvas-area {
        min-height: 430px;
    }
}

@media (max-width: 640px) {
    .upload-dropzone {
        min-height: 360px;
        margin: 9px;
        padding: 24px 14px;
    }

    .upload-dropzone h2 {
        font-size: 20px;
    }

    .privacy-note {
        margin: 0 9px 9px;
    }

    .workspace {
        border-radius: 12px;
    }

    .preview-panel {
        min-height: 50vh;
    }

    .preview-toolbar {
        min-height: 50px;
    }

    .file-summary strong {
        max-width: 190px;
    }

    .mini-button {
        padding: 0 8px;
    }

    .mini-button {
        font-size: 0;
    }

    .mini-button i {
        font-size: 14px;
    }

    .canvas-area {
        min-height: 340px;
        padding: 7px;
    }

    .controls-panel {
        padding: 9px;
    }

    .control-section {
        padding: 10px;
    }

    .transform-grid button {
        min-height: 40px;
    }

    .stats-card {
        gap: 6px;
    }
}
