h1:focus,
h1:focus-visible {
    outline:none;
}

body {
    background-color: #0b0f19;
    color: #f1f5f9;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    margin: 0;
    padding: 0;
}

.app-header {
    background: #1e293b;
    border-bottom: 1px solid #334155;
    padding: 1rem 2rem;
}

.brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: #ffffff;
    text-decoration: none;
}

.brand-accent {
    color: #38bdf8;
}

.catalog-container, .editor-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2.5rem 1rem;
}

.catalog-header, .editor-header {
    max-width: 600px;
    text-align: center;
    margin: 0 auto 2.5rem auto;
}

.catalog-header h1, .editor-header h1 {
    margin: 0 0 0.5rem 0;
    font-size: 2.25rem;
    font-weight: 700;
}

.catalog-header p, .editor-header p {
    color: #94a3b8;
    margin: 0;
    font-size: 1.1rem;
}

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.5rem;
}

.template-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.template-card:hover {
    transform: translateY(-4px);
    border-color: #38bdf8;
    box-shadow: 0 10px 25px -5px rgba(56, 189, 248, 0.15);
}

.card-preview {
    width: 100%;
    aspect-ratio: 1 / 1; /* Жестко держим квадратную форму карточки */
    background: #0f172a; /* Темный фон на случай загрузки */
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid #334155;
    overflow: hidden;
    position: relative;
}

/* Авто-ресайз и кадрирование любой картинки/заглушки под размеры карточки */
.card-preview img.preview-image {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Грамотный пропорциональный ресайз с обрезкой хвостов */
    object-position: center; /* Центрирование содержимого */
    display: block;
    transition: transform 0.3s ease;
}

/* Легкий зум картинки при наведении на карточку */
.template-card:hover .card-preview img.preview-image {
    transform: scale(1.05);
}

.preview-placeholder {
    color: #475569;
    font-size: 0.875rem;
    font-weight: 600;
}

.card-info {
    padding: 1rem;
}

.card-info h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
    color: #f8fafc;
}

.card-info p {
    margin: 0;
    font-size: 0.875rem;
    color: #94a3b8;
    line-height: 1.4;
}

.btn-back {
    display: inline-block;
    color: #38bdf8;
    text-decoration: none;
    margin-bottom: 1.5rem;
    font-weight: 500;
    transition: opacity 0.2s ease;
}

.btn-back:hover {
    opacity: 0.8;
}

.dropzone-box {
    position: relative;
    max-width: 600px;
    margin: 0 auto 2rem auto;
    background: #1e293b;
    border: 2px dashed #334155;
    border-radius: 16px;
    padding: 3rem 2rem;
    text-align: center;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.dropzone-box:hover:not(.disabled) {
    border-color: #38bdf8;
    background-color: #1a2436;
}

.dropzone-box.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.dropzone-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.dropzone-box.disabled .dropzone-input {
    cursor: not-allowed;
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.dropzone-content h3 {
    margin: 0 0 0.25rem 0;
    font-size: 1.25rem;
}

.dropzone-content p {
    margin: 0;
    color: #94a3b8;
    font-size: 0.875rem;
}

.alert {
    max-width: 600px;
    margin: 0 auto 1.5rem auto;
    padding: 1rem 1.25rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    font-weight: 500;
}

.alert-info {
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.3);
    color: #38bdf8;
}

.alert-danger {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(56, 189, 248, 0.3);
    border-top-color: #38bdf8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.result-card {
    max-width: 600px;
    margin: 0 auto;
    background: #1e293b;
    border: 1px solid #10b981;
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
}

.result-card h3 {
    color: #10b981;
    margin: 0 0 1.25rem 0;
}

.btn-download {
    display: block;
    width: 100%;
    box-sizing: border-box;
    background: #10b981;
    color: #ffffff;
    font-weight: 600;
    text-decoration: none;
    padding: 0.875rem;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.btn-download:hover {
    background: #059669;
}

/* Модификация изображения */
.cropper-wrapper {
    max-width: 600px;
    margin: 0 auto;
    background: #1e293b;
    border-radius: 12px;
    padding: 1rem;
    border: 1px solid #334155;
}

.cropper-wrapper p {
    color: #94a3b8;
    font-size: 1.1rem;
    text-align: center;
    margin: 0 0 1.5rem;
}

.cropper-container {
    max-height: 400px;
    overflow: hidden;
    background: #0f172a;
    border-radius: 8px;
}

.cropper-container img {
    max-width: 100%;
    display: block;
}

.cropper-toolbar {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.btn-tool {
    background: #334155;
    color: #f8fafc;
    border: none;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.2s;
}

.btn-tool:hover {
    background: #475569;
}

.cropper-actions {
    margin-top: 1rem;
    text-align: center;
}

.btn-confirm {
    background: #38bdf8;
    color: #0f172a;
    font-weight: 600;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 8px;
    cursor: pointer;
    width: 100%;
    transition: opacity 0.2s;
}

.btn-confirm:hover {
    opacity: 0.9;
}

/* Позиционирование на превью шаблона */
.positioner-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
    border: 1px solid #334155;
    background: #0f172a;
    overflow: hidden;
    user-select: none;
}

.template-bg-image {
    display: block;
    width: 100%;
    max-height: 60vh;
    pointer-events: none;
}

.positioner-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 1rem;
}

.btn-primary, .btn-secondary {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.btn-primary {
    background: #38bdf8;
    color: #0f172a;
}

.btn-primary:hover {
    background: #0284c7;
    color: #ffffff;
}

.btn-secondary {
    background: #334155;
    color: #f8fafc;
}

.btn-secondary:hover {
    background: #475569;
}

.positioner-wrapper {
    max-width: 650px;
    margin: 0 auto;
    background: #1e293b;
    padding: 1.25rem;
    border-radius: 12px;
    border: 1px solid #334155;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.positioner-wrapper p {
    color: #94a3b8;
    font-size: 1.1rem;
    text-align: center;
    margin: 0 0 1.5rem;
}

.positioner-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    max-width: 100%;
    border: 1px solid #475569;
    border-radius: 8px;
    background: #0f172a;
    overflow: hidden;
    user-select: none;
}

.template-bg-image {
    display: block;
    max-width: 100%;
    max-height: 60vh;
    height: auto;
    object-fit: contain;
    pointer-events: none;
}

.draggable-overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 120px;
    height: 120px;
    border: 2px dashed #38bdf8;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
    touch-action: none;
    cursor: move;
    box-sizing: border-box;
}

.overlay-img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none;
}

.draggable-overlay::after {
    content: '';
    position: absolute;
    right: -5px;
    bottom: -5px;
    width: 10px;
    height: 10px;
    background: #38bdf8;
    border: 2px solid #0f172a;
    border-radius: 2px;
    cursor: nwse-resize;
}

.positioner-actions {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-top: 1.25rem;
    gap: 1rem;
}

.template-badge {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    background: #1e293b;
    border: 1px solid #334155;
    padding: 1rem 1.25rem;
    border-radius: 16px;
    box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.25);
    width: 100%;
    box-sizing: border-box;
}

.template-badge-preview {
    width: 100px;
    height: 100px;
    min-width: 100px;
    border-radius: 12px;
    overflow: hidden;
    background: #0f172a;
    border: 1px solid #475569;
}

.template-badge-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.template-badge-info {
    text-align: left;
    min-width: 0;
}

.badge-label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #38bdf8;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.template-badge-info h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    color: #f8fafc;
    line-height: 1.2;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.template-badge-info p {
    margin: 0;
    color: #94a3b8;
    font-size: 0.9rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
    word-break: break-word;
}