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

:root {
    color-scheme: dark;
    --bg: #08090d;
    --surface: #11131a;
    --surface-2: #171a23;
    --border: #292d38;
    --text: #f4f6fa;
    --muted: #969daa;
    --accent: #5ca8ff;
    --accent-hover: #4895ee;
    --danger: #ff4f68;
    --success: #32d583;
}

body {
    min-height: 100vh;
    background:
        radial-gradient(
            circle at top,
            #131e2a 0,
            #08090d 42%
        );
    color: var(--text);
    font-family:
        Inter,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    line-height: 1.5;
}

button,
select,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}


/* =========================
   HEADER
========================= */

.site-header {
    width: min(1200px, calc(100% - 32px));
    margin: 0 auto;
    padding: 22px 0;

    display: flex;
    align-items: center;
    gap: 20px;
}

.back-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-height: 42px;
    padding: 8px 15px;

    color: var(--text);
    text-decoration: none;

    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;

    transition:
        background 0.2s,
        border-color 0.2s,
        transform 0.2s;
}

.back-button:hover {
    background: var(--surface-2);
    border-color: #3b4050;
    transform: translateX(-2px);
}

.brand h1 {
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: 0.2px;
}

.brand span {
    display: block;
    margin-top: 2px;

    color: var(--muted);
    font-size: 0.8rem;
}


/* =========================
   MAIN
========================= */

main {
    width: min(1100px, calc(100% - 32px));
    margin: 0 auto;
    padding-bottom: 60px;
}


/* =========================
   HERO
========================= */

.hero {
    text-align: center;
    padding: 35px 15px 30px;
}

.hero-icon {
    width: 74px;
    height: 74px;

    margin: 0 auto 18px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 22px;

    background:
        linear-gradient(
            135deg,
            #182a3f,
            #141722
        );

    border: 1px solid #314051;

    font-size: 2.1rem;

    box-shadow:
        0 15px 40px rgba(0, 0, 0, 0.35);
}

.hero h2 {
    font-size: clamp(2rem, 5vw, 3rem);
    line-height: 1.1;
    margin-bottom: 12px;
}

.hero p {
    max-width: 650px;
    margin: 0 auto;

    color: var(--muted);
    font-size: 1rem;
}

.privacy-note {
    width: fit-content;
    max-width: 100%;

    margin: 18px auto 0;
    padding: 9px 14px;

    color: #b9c0cc;
    background: rgba(20, 23, 31, 0.8);

    border: 1px solid var(--border);
    border-radius: 999px;

    font-size: 0.82rem;
}


/* =========================
   CARDS
========================= */

.tool-card {
    margin-top: 20px;
    padding: 24px;

    background:
        linear-gradient(
            145deg,
            rgba(23, 26, 35, 0.96),
            rgba(13, 15, 21, 0.96)
        );

    border: 1px solid var(--border);
    border-radius: 18px;

    box-shadow:
        0 15px 45px rgba(0, 0, 0, 0.22);
}


/* =========================
   UPLOAD
========================= */

.upload-area {
    min-height: 250px;

    padding: 35px 20px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    text-align: center;

    border: 2px dashed #353a49;
    border-radius: 16px;

    transition:
        border-color 0.2s,
        background 0.2s;
}

.upload-area.dragover {
    border-color: var(--accent);
    background: rgba(124, 92, 255, 0.08);
}

.upload-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.upload-area h3 {
    font-size: 1.25rem;
    margin-bottom: 6px;
}

.upload-area p {
    color: var(--muted);
    margin-bottom: 18px;
}

.upload-area .drop-text {
    margin: 15px 0 0;
    font-size: 0.82rem;
}


/* =========================
   BUTTONS
========================= */

.primary-button,
.secondary-button,
.danger-button {
    border: 1px solid transparent;
    border-radius: 10px;

    min-height: 44px;
    padding: 9px 16px;

    font-weight: 700;

    transition:
        background 0.2s,
        border-color 0.2s,
        transform 0.2s,
        opacity 0.2s;
}

.primary-button {
    color: white;
    background: var(--accent);
}

.primary-button:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.secondary-button {
    color: var(--text);
    background: #191c25;
    border-color: var(--border);
}

.secondary-button:hover:not(:disabled) {
    background: #222632;
    border-color: #3b4050;
}

.danger-button {
    color: #ffb1bb;
    background: rgba(255, 79, 104, 0.08);
    border-color: rgba(255, 79, 104, 0.25);
}

.danger-button:hover:not(:disabled) {
    background: rgba(255, 79, 104, 0.15);
}

.large-button {
    width: 100%;
    min-height: 50px;
    margin-top: 8px;
    font-size: 1rem;
}


/* =========================
   SECTION HEADING
========================= */

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;

    margin-bottom: 20px;
}

.section-heading h3 {
    font-size: 1.15rem;
}

.section-heading p {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.82rem;
}


/* =========================
   SELECTED IMAGE LIST
========================= */

.image-list {
    display: grid;
    grid-template-columns:
        repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
}

.image-item {
    position: relative;

    overflow: hidden;

    background: #0d0f15;
    border: 1px solid var(--border);
    border-radius: 13px;
}

.image-item.active {
    border-color: var(--accent);
    box-shadow:
        0 0 0 1px var(--accent);
}

.image-item-preview {
    width: 100%;
    height: 150px;

    display: block;

    object-fit: contain;

    background:
        repeating-conic-gradient(
            #161922 0% 25%,
            #101219 0% 50%
        )
        50% / 20px 20px;
}

.image-item-info {
    padding: 11px 12px;
}

.image-item-name {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;

    font-size: 0.9rem;
    font-weight: 700;
}

.image-item-meta {
    margin-top: 4px;

    color: var(--muted);
    font-size: 0.75rem;
}

.image-item-actions {
    display: flex;
    gap: 7px;
    padding: 0 12px 12px;
}

.image-item-actions button {
    flex: 1;
    min-height: 36px;
    padding: 6px 8px;

    color: var(--text);
    background: #191c25;

    border: 1px solid var(--border);
    border-radius: 8px;

    font-size: 0.78rem;
    font-weight: 700;
}

.image-item-actions button:hover {
    background: #242936;
}


/* =========================
   EDITOR
========================= */

.editor-layout {
    display: grid;
    grid-template-columns:
        minmax(0, 1.4fr)
        minmax(280px, 0.8fr);

    gap: 24px;
}

.preview-panel {
    min-width: 0;
}

.canvas-wrapper {
    min-height: 420px;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 20px;

    overflow: hidden;

    background:
        repeating-conic-gradient(
            #171a22 0% 25%,
            #111319 0% 50%
        )
        50% / 24px 24px;

    border: 1px solid var(--border);
    border-radius: 14px;
}

#previewCanvas {
    display: block;

    max-width: 100%;
    max-height: 520px;

    width: auto;
    height: auto;

    object-fit: contain;

    box-shadow:
        0 12px 35px rgba(0, 0, 0, 0.35);
}

.controls-panel {
    padding: 18px;

    background: rgba(10, 12, 17, 0.7);

    border: 1px solid var(--border);
    border-radius: 14px;
}

.control-group {
    margin-bottom: 22px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-group h4 {
    margin-bottom: 10px;
    font-size: 0.9rem;
}


/* =========================
   CONTROL BUTTONS
========================= */

.button-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.button-grid .secondary-button:last-child {
    grid-column: 1 / -1;
}

.quick-buttons {
    display: grid;
    grid-template-columns:
        repeat(4, 1fr);
    gap: 7px;
}

.angle-button {
    min-height: 38px;

    color: var(--text);
    background: #191c25;

    border: 1px solid var(--border);
    border-radius: 8px;

    font-weight: 700;
    font-size: 0.82rem;
}

.angle-button:hover {
    background: #242936;
}

.angle-button.active {
    background: var(--accent);
    border-color: var(--accent);
}


/* =========================
   SELECT
========================= */

.select-control {
    width: 100%;
    min-height: 44px;

    padding: 8px 12px;

    color: var(--text);
    background: #191c25;

    border: 1px solid var(--border);
    border-radius: 10px;

    outline: none;
}

.select-control:focus {
    border-color: var(--accent);
}


/* =========================
   RANGE
========================= */

.range-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;

    margin-bottom: 10px;
}

.range-header h4 {
    margin: 0;
}

.range-header span {
    color: #badaff;
    font-size: 0.82rem;
    font-weight: 700;
}

input[type="range"] {
    width: 100%;
    height: 6px;

    accent-color: var(--accent);

    cursor: pointer;
}


/* =========================
   PROGRESS
========================= */

.progress-card {
    padding: 20px;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    gap: 15px;

    margin-bottom: 10px;

    font-size: 0.85rem;
    font-weight: 700;
}

#progressText {
    color: var(--muted);
}

.progress-track {
    width: 100%;
    height: 9px;

    overflow: hidden;

    background: #20232d;
    border-radius: 999px;
}

.progress-bar {
    width: 0;
    height: 100%;

    background: var(--accent);

    border-radius: inherit;

    transition: width 0.2s ease;
}


/* =========================
   RESULTS
========================= */

.selection-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;

    margin-bottom: 18px;
}

.results-grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fill, minmax(230px, 1fr));

    gap: 15px;
}

.result-card {
    position: relative;

    overflow: hidden;

    background: #0d0f15;
    border: 1px solid var(--border);
    border-radius: 13px;

    transition:
        border-color 0.2s,
        box-shadow 0.2s;
}

.result-card.selected {
    border-color: var(--accent);

    box-shadow:
        0 0 0 1px var(--accent);
}

.result-checkbox {
    position: absolute;
    top: 12px;
    left: 12px;

    z-index: 2;

    width: 20px;
    height: 20px;

    accent-color: var(--accent);
}

.result-image {
    width: 100%;
    height: 190px;

    display: block;

    object-fit: contain;

    background:
        repeating-conic-gradient(
            #171a22 0% 25%,
            #111319 0% 50%
        )
        50% / 20px 20px;
}

.result-info {
    padding: 12px;
}

.result-name {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;

    font-size: 0.88rem;
    font-weight: 700;
}

.result-meta {
    margin-top: 4px;

    color: var(--muted);
    font-size: 0.76rem;
}

.result-download {
    width: 100%;
    min-height: 38px;

    margin-top: 10px;

    color: var(--text);
    background: #191c25;

    border: 1px solid var(--border);
    border-radius: 8px;

    font-size: 0.8rem;
    font-weight: 700;
}

.result-download:hover {
    background: #252a36;
}


/* =========================
   DOWNLOAD ACTIONS
========================= */

.download-actions {
    display: grid;

    grid-template-columns:
        repeat(2, 1fr);

    gap: 10px;

    margin-top: 22px;
}


/* =========================
   FOOTER
========================= */

.site-footer {
    padding: 30px 16px 45px;

    text-align: center;

    color: var(--muted);

    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.site-footer p {
    color: var(--text);
    font-weight: 700;
}

.site-footer span {
    display: block;
    margin-top: 4px;
    font-size: 0.78rem;
}


/* =========================
   HIDDEN
========================= */

[hidden] {
    display: none !important;
}


/* =========================
   RESPONSIVE
========================= */

@media (max-width: 850px) {

    .editor-layout {
        grid-template-columns: 1fr;
    }

    .canvas-wrapper {
        min-height: 350px;
    }

    .controls-panel {
        padding: 16px;
    }
}


@media (max-width: 650px) {

    .site-header {
        width: min(100% - 22px, 1100px);
        padding: 16px 0;
    }

    main {
        width: min(100% - 22px, 1100px);
    }

    .hero {
        padding-top: 25px;
    }

    .hero h2 {
        font-size: 2rem;
    }

    .tool-card {
        padding: 16px;
        border-radius: 15px;
    }

    .section-heading {
        align-items: flex-start;
    }

    .image-list,
    .results-grid {
        grid-template-columns: 1fr;
    }

    .download-actions {
        grid-template-columns: 1fr;
    }

    .canvas-wrapper {
        min-height: 280px;
        padding: 12px;
    }

    #previewCanvas {
        max-height: 400px;
    }
}


@media (max-width: 450px) {

    .brand h1 {
        font-size: 1rem;
    }

    .back-button {
        min-height: 38px;
        padding: 7px 11px;
        font-size: 0.85rem;
    }

    .privacy-note {
        border-radius: 12px;
        font-size: 0.76rem;
    }

    .upload-area {
        min-height: 220px;
        padding: 25px 14px;
    }

    .button-grid {
        grid-template-columns: 1fr;
    }

    .button-grid .secondary-button:last-child {
        grid-column: auto;
    }

    .quick-buttons {
        grid-template-columns:
            repeat(2, 1fr);
    }

    .selection-controls {
        flex-direction: column;
    }

    .selection-controls button {
        width: 100%;
    }
}


@media (max-width: 380px) {

    .hero-icon {
        width: 64px;
        height: 64px;
        font-size: 1.8rem;
    }

    .hero h2 {
        font-size: 1.75rem;
    }

    .tool-card {
        padding: 13px;
    }

    .site-header {
        gap: 10px;
    }
}