:root {
    --ink: #182127;
    --paper: #f8f3e8;
    --panel: #fffcf4;
    --accent: #dc4d38;
    --accent-dark: #a52f1e;
    --soft: #ddc59a;
    --shadow: 0 18px 40px rgba(24, 33, 39, 0.15);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--ink);
    background: radial-gradient(circle at 15% 20%, #ffd9c6 0, #ffd9c6 20%, transparent 38%),
        radial-gradient(circle at 90% 12%, #f3ddb2 0, #f3ddb2 16%, transparent 30%),
        linear-gradient(135deg, #f4eee0, #f7f0df 50%, #fce9df);
    overflow-x: hidden;
}

body.modal-open {
    overflow: hidden;
}

.bg-shape {
    position: fixed;
    border-radius: 50%;
    filter: blur(1px);
    opacity: 0.5;
    pointer-events: none;
    z-index: 0;
}

.shape-a {
    width: 360px;
    height: 360px;
    background: #f8a47d;
    top: -130px;
    right: -80px;
}

.shape-b {
    width: 280px;
    height: 280px;
    background: #f1c96a;
    bottom: -120px;
    left: -80px;
}

.app-shell {
    width: 100%;
    min-height: 100dvh;
    margin: 0;
    padding: 14px;
    position: relative;
    z-index: 1;
}

.screen {
    display: none;
    animation: fade-up 260ms ease;
    width: 100%;
    min-height: calc(100dvh - 28px);
}

.screen.show {
    display: flex;
}

.screen.scrollable {
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 24px 0 40px;
}

.step-screen {
    width: 100%;
}

.align-items-center {
    align-items: center;
}

.justify-content-center {
    justify-content: center;
}

.panel {
    background: var(--panel);
    border: 2px solid rgba(24, 33, 39, 0.08);
    border-radius: 22px;
    box-shadow: var(--shadow);
    padding: 26px;
    width: min(960px, 100%);
    position: relative;
    z-index: 2;
}

.panel.wide {
    padding: 28px;
    width: min(1120px, 100%);
}

h1,
h2,
h3 {
    margin: 0 0 10px;
}

p {
    margin: 8px 0 14px;
}

.terms-check {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin: 14px 0;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.field-grid.single {
    grid-template-columns: 1fr;
}

.builder-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 4px 0 18px;
    border-bottom: 1px solid rgba(24, 33, 39, 0.08);
    margin-bottom: 18px;
}

.builder-logo {
    width: 56px;
    height: 56px;
    object-fit: contain;
    border-radius: 14px;
    background: #fff;
    border: 1px solid rgba(24, 33, 39, 0.08);
    padding: 6px;
    flex-shrink: 0;
}

.builder-logo-fallback {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, #dc4d38, #9b2c2c);
    flex-shrink: 0;
}

.builder-title {
    margin: 0 0 4px;
    font-size: 22px;
}

.builder-subtitle {
    margin: 0;
    font-size: 13px;
    color: rgba(24, 33, 39, 0.65);
}

label {
    display: grid;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
}

input,
select {
    width: 100%;
    border: 1px solid rgba(24, 33, 39, 0.2);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 14px;
    background: #fff;
    outline: none;
    transition: border-color 160ms, box-shadow 160ms;
}

input.is-invalid,
select.is-invalid {
    border-color: rgba(185, 28, 28, 0.85);
    box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.12);
}

.field-error {
    min-height: 16px;
    font-size: 12px;
    color: #b91c1c;
    font-weight: 600;
    margin-top: -2px;
}

input:focus,
select:focus {
    border-color: rgba(220, 77, 56, 0.8);
    box-shadow: 0 0 0 3px rgba(220, 77, 56, 0.18);
}

.row {
    display: flex;
    gap: 12px;
    align-items: center;
    margin: 14px 0;
}

.upload-row {
    justify-content: space-between;
    flex-wrap: wrap;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

.btn {
    border: 0;
    background: var(--accent);
    color: #fff;
    padding: 10px 16px;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 160ms ease, background 160ms ease;
}

.btn:hover {
    transform: translateY(-1px);
    background: var(--accent-dark);
}

.btn:disabled {
    background: #d3b6ae;
    cursor: not-allowed;
    transform: none;
}

.btn.secondary {
    background: #415a67;
}

.btn.secondary:hover {
    background: #31434d;
}

.btn.danger {
    background: #842f24;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-top: 8px;
}

.template-card {
    border: 2px solid transparent;
    border-radius: 16px;
    overflow: hidden;
    background: #fff;
    cursor: pointer;
    padding: 0;
}

.template-card.active {
    border-color: var(--accent);
}

.template-thumb {
    aspect-ratio: 1/1;
}

.template-meta {
    padding: 10px;
    font-size: 13px;
    font-weight: 700;
}

.crop-preview-wrap {
    display: grid;
    place-items: center;
    margin-top: 8px;
}

#cropPreview {
    width: min(320px, 85vw);
    height: auto;
    border-radius: 16px;
    background: #f3e8d3;
    border: 1px solid rgba(24, 33, 39, 0.2);
}

.poster-canvas {
    width: min(520px, 100%);
    max-height: none;
    height: auto;
    border-radius: 18px;
    border: 1px solid rgba(24, 33, 39, 0.2);
    display: block;
    margin: 0 auto;
}

.status {
    min-height: 22px;
    font-size: 14px;
    font-weight: 600;
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    place-items: center;
    background: rgba(10, 12, 15, 0.65);
    z-index: 20;
    padding: 18px;
}

.modal.open {
    display: grid;
}

.modal-content {
    width: min(540px, 94vw);
    background: #fff;
    border-radius: 18px;
    padding: 18px;
    max-height: 90vh;
    overflow-y: auto;
}

#cropCanvas {
    width: 100%;
    height: auto;
    border-radius: 12px;
    background: #efefef;
    margin-bottom: 8px;
    cursor: grab;
}

@keyframes fade-up {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 860px) {
    .field-grid,
    .template-grid {
        grid-template-columns: 1fr;
    }

    .app-shell {
        padding: 10px;
    }

    .screen {
        min-height: calc(100dvh - 20px);
    }

    .panel,
    .panel.wide {
        border-radius: 16px;
        padding: 16px;
    }

    .actions {
        width: 100%;
    }

    .actions .btn {
        flex: 1 1 100%;
    }

    .row {
        flex-direction: column;
        align-items: stretch;
    }

    .upload-row {
        gap: 10px;
    }
}
