:root {
    --primary: #4F46E5;
    --secondary: #F97316;
    --radius: 16px;
    --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    --bg: #F6F3EE;
    --surface: #FFFFFF;
    --text: #1C1917;
    --muted: #57534E;
    --line: rgba(28, 25, 23, 0.08);
    --shadow: 0 10px 30px rgba(28, 25, 23, 0.08);
}

html[data-theme="dark"] {
    --bg: #0E1116;
    --surface: #171C24;
    --text: #F5F3EF;
    --muted: #C4BDB3;
    --line: rgba(245, 243, 239, 0.08);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    max-width: 100%;
    overflow-x: hidden;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
}

img { max-width: 100%; height: auto; }

a { color: var(--primary); }

.skip-link {
    position: absolute;
    left: -999px;
    top: 0;
    background: var(--primary);
    color: #fff;
    padding: 0.5rem 1rem;
    z-index: 1000;
}
.skip-link:focus { left: 0.75rem; top: 0.75rem; }

.brand {
    display: inline-flex;
    align-items: center;
    color: inherit;
    text-decoration: none;
    flex-shrink: 0;
}
.brand img {
    display: block;
    height: 48px;
    width: auto;
    max-width: min(280px, 58vw);
    object-fit: contain;
    object-position: left center;
}
.site-header .container {
    min-height: 72px;
}
.hero-logo {
    display: block;
    height: 72px;
    width: auto;
    max-width: 320px;
    object-fit: contain;
    margin: 0 auto 1rem;
}

.site-header, .site-footer {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.site-footer { border-top: 1px solid var(--line); border-bottom: 0; color: var(--muted); }

.btn {
    border-radius: 12px;
    font-weight: 600;
}
.btn-primary,
.btn-primary:hover,
.btn-primary:focus {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}
.btn-outline-primary:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.btn-ghost {
    background: transparent;
    border: 1px solid var(--line);
    color: inherit;
}
.btn-lg { min-height: 48px; padding: 0.75rem 1.15rem; }
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.form-check-input:focus-visible,
.btn-icon:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent);
    outline-offset: 2px;
}

.form-control, .form-select {
    border-radius: 12px;
    min-height: 46px;
    background: var(--surface);
    color: var(--text);
    border-color: var(--line);
}

.hero { padding: 4rem 0 3rem; }
.hero-card, .surface-card, .info-card, .auth-card, .stat-card, .campaign-card, .empty-state {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.hero-card {
    max-width: 760px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem;
    text-align: center;
}
.hero-copy { color: var(--muted); max-width: 42rem; margin: 0 auto 1.5rem; }
.section-title { margin-bottom: 1.25rem; }

.campaign-card {
    display: block;
    padding: 0.9rem;
    text-decoration: none;
    color: inherit;
    height: 100%;
}
.campaign-card h3 { font-size: 1.05rem; margin: 0.75rem 0 0.25rem; }
.campaign-card span { color: var(--primary); font-weight: 600; font-size: 0.92rem; }
.campaign-thumb {
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 14px;
    background: #E8E4DC;
}
.campaign-thumb img { width: 100%; height: 100%; object-fit: cover; }

.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-wrap { width: 100%; max-width: 480px; }
.auth-card { padding: 2rem; }
.auth-card-wide { max-width: none; }
.auth-wrap:has(.auth-card-wide) { max-width: 640px; }

.campaign-page {
    padding-bottom: 2rem;
    overflow-x: hidden;
}
.campaign-layout {
    display: grid;
    gap: 1.5rem;
    min-width: 0;
}
.editor-column,
.info-column {
    min-width: 0;
    max-width: 100%;
}
@media (min-width: 992px) {
    .campaign-layout {
        grid-template-columns: minmax(0, 1.4fr) 320px;
        align-items: start;
    }
}
.campaign-heading h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem; color: var(--secondary); font-weight: 700; margin-bottom: 0.25rem; }
.campaign-desc { color: var(--muted); }

.editor-app {
    max-width: 560px;
    width: 100%;
    margin: 0 auto;
    min-width: 0;
}
.editor-stage {
    position: relative;
    width: 100%;
    max-width: min(520px, 100%);
    margin: 0 auto 1rem;
    aspect-ratio: 1 / 1;
    background: #111;
    border-radius: 18px;
    overflow: hidden;
    touch-action: none;
    box-shadow: var(--shadow);
}
.editor-stage canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}
.editor-stage canvas:active { cursor: grabbing; }
.drop-overlay,
.editor-loading {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: grid;
    place-items: center;
    background: rgba(12, 14, 18, 0.72);
    color: #fff;
    font-weight: 700;
    gap: 0.75rem;
}
.editor-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.privacy-note {
    font-size: 0.88rem;
    color: var(--muted);
    text-align: center;
    margin-bottom: 1rem;
    padding: 0 0.25rem;
    overflow-wrap: anywhere;
}
.editor-controls {
    display: grid;
    gap: 0.85rem;
    min-width: 0;
    width: 100%;
}
.photo-input-sr {
    position: absolute;
    left: 0;
    top: 0;
    width: 0;
    height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}
.canvas-add-photo {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: grid;
    place-items: center;
    margin: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.18);
    color: #fff;
    font-weight: 700;
    font-size: clamp(1rem, 4.2vw, 1.35rem);
    cursor: pointer;
    touch-action: manipulation;
    text-align: center;
    padding: 1rem;
    text-decoration: underline;
    text-underline-offset: 0.2em;
}
.canvas-add-photo[hidden] { display: none !important; }

.model-picker {
    max-width: 560px;
    width: 100%;
    margin: 0 auto 1.25rem;
}
.model-picker-head {
    text-align: center;
    margin-bottom: 0.85rem;
}
.model-picker-head h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.2rem;
}
.model-picker-head p {
    color: var(--muted);
    margin: 0;
    font-size: 0.92rem;
}
.model-empty {
    text-align: center;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--line);
    border-radius: 16px;
    padding: 1rem;
}
.model-carousel {
    position: relative;
    display: block;
}
.model-carousel-viewport {
    display: flex;
    align-items: stretch;
    gap: 0.65rem;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
    padding: 8px 44px 10px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.model-carousel-viewport::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}
.model-card {
    flex: 0 0 auto;
    width: min(148px, calc((100% - 0.65rem) / 2));
    min-width: 108px;
    max-width: 150px;
    display: flex;
    flex-direction: column;
    scroll-snap-align: start;
    border: 2px solid var(--line);
    background: var(--surface);
    border-radius: 16px;
    padding: 0.4rem;
    text-align: left;
    color: inherit;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.model-card:hover,
.model-card:focus-visible {
    border-color: color-mix(in srgb, var(--primary) 55%, #fff);
}
.model-card.is-selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 28%, transparent);
}
.model-card-thumb {
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    background:
        linear-gradient(45deg, #ece8e1 25%, transparent 25%) 0 0 / 16px 16px,
        linear-gradient(-45deg, #ece8e1 25%, transparent 25%) 0 8px / 16px 16px,
        linear-gradient(45deg, transparent 75%, #ece8e1 75%) 8px -8px / 16px 16px,
        linear-gradient(-45deg, transparent 75%, #ece8e1 75%) 8px 0 / 16px 16px,
        #f7f4ef;
}
.model-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.model-card-name {
    display: block;
    margin-top: 0.4rem;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.model-card-badge {
    display: block;
    margin-top: 0.15rem;
    min-height: 1em;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--primary);
    visibility: hidden;
}
.model-card.is-selected .model-card-badge { visibility: visible; }
.model-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: inherit;
    display: grid;
    place-items: center;
    padding: 0;
    box-shadow: var(--shadow);
}
.model-nav-prev { left: 0; }
.model-nav-next { right: 0; }
.model-nav:disabled {
    opacity: 0.28;
    cursor: default;
}
@media (min-width: 576px) {
    .model-card { width: min(140px, calc((100% - 1.3rem) / 3)); }
}
@media (min-width: 768px) {
    .model-card { width: min(132px, calc((100% - 1.95rem) / 4)); }
}
@media (max-width: 575.98px) {
    .model-card {
        width: calc((100% - 0.65rem) / 2);
        min-width: 0;
        max-width: none;
    }
}
.bg-picker { margin: 0.15rem 0 0.35rem; }
.bg-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.5rem;
}
.bg-tile {
    position: relative;
    aspect-ratio: 1;
    width: 100%;
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 0;
    overflow: hidden;
    cursor: pointer;
    background-size: cover;
    background-position: center;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.bg-tile:hover,
.bg-tile:focus-visible {
    border-color: color-mix(in srgb, var(--primary) 55%, #fff);
}
.bg-tile[aria-selected="true"] {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 35%, transparent);
}
.bg-tile-custom {
    display: grid;
    place-items: center;
    background: conic-gradient(from 180deg, #ef4444, #f59e0b, #22c55e, #3b82f6, #a855f7, #ef4444);
}
.bg-tile-custom input[type="color"] {
    width: 62%;
    height: 62%;
    border: 0;
    padding: 0;
    background: none;
    cursor: pointer;
}
.bg-tile-custom input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.bg-tile-custom input[type="color"]::-webkit-color-swatch {
    border: 2px solid #fff;
    border-radius: 999px;
}
.zoom-row, .rotate-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    width: 100%;
    overflow: visible;
}
.zoom-row input[type="range"],
.blur-control input[type="range"] {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    height: 32px;
    margin: 0;
    accent-color: var(--primary);
}
.btn-icon {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: inherit;
    font-size: 1.35rem;
}
.blur-control {
    display: grid;
    gap: 0.45rem;
    min-width: 0;
    width: 100%;
    padding: 0.85rem 0.95rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    overflow: visible;
}
.blur-control-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-width: 0;
}
.blur-toggle {
    flex: 0 0 auto;
    width: 2.6em;
    height: 1.4em;
    margin: 0;
    accent-color: var(--primary);
    cursor: pointer;
}
.blur-control-label {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    font-weight: 600;
    line-height: 1.3;
}
.blur-control input[type="range"]:disabled {
    opacity: 0.38;
}
.share-actions { display: grid; gap: 0.55rem; }
.info-card { padding: 1.35rem; }
.info-card ol { padding-left: 1.1rem; }

.toast-copy {
    position: fixed;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: 0.65rem 1rem;
    border-radius: 999px;
    z-index: 1080;
}

.error-page h1 { font-size: 4rem; }
.page-title { font-size: 1.7rem; font-weight: 700; }

html[data-theme="dark"] .table {
    --bs-table-bg: var(--surface);
    --bs-table-color: var(--text);
    --bs-table-border-color: var(--line);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
    --bs-table-hover-bg: rgba(255, 255, 255, 0.05);
    color: var(--text);
    background-color: transparent;
}
html[data-theme="dark"] .table > :not(caption) > * > * {
    background-color: var(--surface);
    color: var(--text);
    border-bottom-color: var(--line);
}
html[data-theme="dark"] .table thead th {
    background-color: color-mix(in srgb, var(--surface) 86%, #000);
    color: var(--muted);
}
html[data-theme="dark"] code {
    color: #E7B8C8;
}
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
    background-color: var(--bg);
    color: var(--text);
    border-color: var(--line);
}
html[data-theme="dark"] .form-control::placeholder {
    color: var(--muted);
}
html[data-theme="dark"] .pagination .page-link {
    background: var(--surface);
    color: var(--text);
    border-color: var(--line);
}
html[data-theme="dark"] .pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
html[data-theme="dark"] .modal-content { background: var(--surface); color: var(--text); }
html[data-theme="dark"] .btn-close { filter: invert(1); }

.lead-preparing { font-weight: 700; color: var(--primary); }
.narrow-content { max-width: 720px; }
.narrow-content h1 { margin-bottom: 0.75rem; }
.narrow-content h2 { margin-top: 1.6rem; font-size: 1.2rem; }
.site-footer a { color: inherit; }
.footer-credit {
    margin-top: 0.35rem;
    font-size: 0.82rem;
}
.footer-credit a {
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}
.footer-credit a:hover,
.footer-credit a:focus-visible {
    text-decoration: underline;
}

@media (max-width: 767.98px) {
    .site-header .container {
        min-height: 58px;
        padding-top: 0.55rem;
        padding-bottom: 0.55rem;
        gap: 0.5rem;
    }
    .brand img {
        height: 34px;
        max-width: min(170px, 48vw);
    }
    .campaign-page .container {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
        padding-top: 1rem;
    }
    .campaign-heading h1 {
        font-size: 1.35rem;
        overflow-wrap: anywhere;
    }
    .editor-stage { border-radius: 14px; }
    .btn-icon {
        width: 42px;
        height: 42px;
    }
    .bg-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .info-card { padding: 1.1rem; }
    .modal-dialog { margin: 0.6rem; }
}

@media (max-width: 419.98px) {
    .bg-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .model-carousel-viewport { padding-left: 38px; padding-right: 38px; }
}
