:root {
    --purple-900: #41308f;
    --purple-700: #6e57c5;
    --purple-300: #b6a5f3;
    --gray-100: #f7f7fa;
    --gray-600: #4f4f5e;
    --white: #ffffff;
    --radius-lg: 0.75rem;
    --transition: 180ms ease;
    --label-width: 120px;
    --gap: 0.5rem;
    font-size: 16px; 
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body{
    background: linear-gradient(145deg, #41308f 0%, #6e57c5 100%);
    font-family: 'Montserrat', system-ui, sans-serif;
    font-weight: 600;
    font-style: normal;
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

/*---- ШАПКА ----*/
.site-header {
    background: rgba(65, 48, 143, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(182, 165, 243, 0.2);
    padding: 1rem 0;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(90%, 1200px);
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--white);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.logo img {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    object-fit: cover;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.nav-link:hover {
    color: white;
    background: rgba(182, 165, 243, 0.1);
    border-color: rgba(182, 165, 243, 0.3);
    transform: translateY(-1px);
}

.nav-link svg {
    width: 24px;
    height: 24px;
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.nav-link img {
    width: 24px;
    height: 24px;
    border-radius: 5px;
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.nav-link:hover svg,
.nav-link:hover img {
    opacity: 1;
}

/* Скрываем текст на средних экранах */
@media (max-width: 690px) {
    .nav-link span {
        display: none; /* Скрываем текст, оставляем только иконки */
    }
    
    .nav-links {
        gap: 0.8rem;
    }
    
    .nav-link {
        padding: 0.3rem 0.5rem;
    }
}

/* Адаптация для очень маленьких экранов */
@media (max-width: 480px) {
    .nav-links {
        gap: 0.4rem;
    }
    
    .nav-link {
        padding: 0.2rem 0.4rem;
        font-size: 0.7rem;
    }
    
    .nav-link span {
        display: none;
    }
    
    .nav-link svg,
    .nav-link img {
        width: 16px;
        height: 16px;
    }
    
    .logo img {
        width: 28px;
        height: 28px;
    }
    
    .logo {
        font-size: 1rem;
    }
}

.config,
.preview__img{
    background: linear-gradient(145deg,#ffffff 0%,#f5f6ff 100%);
}

.container {
    width: min(90%, 1200px);
    margin-inline: auto;
}

.generator__wrap {
    display: flex;
    gap: 3rem;
    padding-block: 4.5rem;
}

/*----- форма (левый столбец) -----*/
.config {
    flex: 1 1 370px;
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 2rem 2.5rem;
    box-shadow: 0 8px 16px rgb(0 0 0 / 0.08);
}

.config__title {
    margin: 0 0 1.5rem;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--purple-900);
}

/*---- поля БЕЗ тумблеров (Breed, Eyes, Mouth) ----*/
.field.no-switch {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.field.no-switch label {
    width: var(--label-width);
    flex-shrink: 0;
    margin: 0;
    font-size: 1rem;
}

.field.no-switch select {
    flex: 1;
    min-width: 0;
    padding: 0.45rem 0.75rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--purple-300);
    font: inherit;
    font-weight: 600;
    outline-color: var(--purple-700);
}

.field.no-switch .trait-arrows {
    flex-shrink: 0;
    margin-left: 0;
}

/*---- поля С тумблерами ----*/
.field:not(.no-switch) {
    display: grid;
    grid-template-columns: var(--label-width) 46px 1fr auto;
    align-items: center;
    column-gap: var(--gap);
    margin-bottom: 1.25rem;
}

.field:not(.no-switch) > label {
    justify-self: start;   
    text-align: left;      
    padding-left: 0;
    font-size: 1rem;
    margin: 0;
}

.field:not(.no-switch) select {
    grid-column: 3;
    width: 100%;
    min-width: 0;
    padding: 0.45rem 0.75rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--purple-300);
    font: inherit;
    font-weight: 600;
    outline-color: var(--purple-700);
}

.field:not(.no-switch) .trait-arrows {
    grid-column: 4;
    margin-left: 8px;
}

.field:not(.no-switch) .switch {
    grid-column: 2;
    grid-row: 1;
    transform: translateX(-16px);
}

/*---- общие стили для селектов ----*/
.field select,
.field select option {   
    font-weight: 600;   
}

/*---- тумблеры ----*/
.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    inset: 0;
    background-color: var(--gray-100);
    border-radius: 34px;
    cursor: pointer;
    transition: var(--transition);
}

.slider::before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    top: 3px;
    background-color: var(--purple-700);
    border-radius: 50%;
    transition: var(--transition);
    background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' fill='white' viewBox='0 0 16 16'><path d='M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z'/></svg>");
    background-size: 12px;
    background-repeat: no-repeat;
    background-position: center;
}

input:checked + .slider {
    background-color: var(--purple-300);
}

input:checked + .slider::before {
    transform: translateX(20px);
}

.switch input:not(:checked) + .slider::before {
    background: var(--gray-600);
    background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' fill='white' viewBox='0 0 16 16'><path d='M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z'/></svg>");
    background-size: 10px;
    background-repeat: no-repeat;
    background-position: center;
}

.switch input:not(:checked) + .slider {
    background: rgba(110, 87, 197, 0.25);
}

/*---- стрелочки для переключения трейтов ----*/
.trait-arrows {
    display: flex;
    gap: 4px;
}

.arrow-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--purple-300);
    background: white;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--purple-700);
}

.arrow-btn:hover {
    background: var(--purple-100, #f5f3ff);
    border-color: var(--purple-700);
    transform: scale(1.05);
}

.arrow-btn:active {
    transform: scale(0.95);
}

.arrow-btn svg {
    pointer-events: none;
}

/*---- состояния полей ----*/
.field.is-off select {
    display: none;
}

.field.is-off .trait-arrows {
    opacity: 0.3;
    pointer-events: none;
}

/*---- загрузка фона ----*/
.upload {
    display: inline-block;
    margin: 1rem 0 1.5rem;
    font-size: 0.9rem;
    color: var(--purple-700);
    cursor: pointer;
    text-decoration: underline;
}
.upload:hover {
    color: var(--purple-300);
}

/*---- кнопки действий ----*/
.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 0.5rem;
}

.actions:empty {
    display: none;
}

.btn {
    appearance: none;
    border: none;
    cursor: pointer;
    font: inherit;
    padding: 0.55rem 1.4rem;
    border-radius: var(--radius-lg);
    transition: var(--transition);
    background: var(--purple-700);
    color: var(--white);
}

.btn--secondary {
    background: var(--gray-100);
    color: var(--gray-600);
}

.btn--accent {
    background: var(--purple-300);
}

.btn:hover {
    filter: brightness(1.07);
}

/*---- превью (правый столбец) ----*/
.preview {
    flex: 0 1 520px; 
    max-width: 520px;
    width: 100%;
    margin-left: 6rem;
}

.preview__frame {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: 0 8px 16px rgb(0 0 0 / 0.08);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.preview__content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-bottom: 1rem;
}

.preview__stack {
    position: relative;
    width: 100%;
    max-width: 480px;
    aspect-ratio: 1/1;     
    background: var(--white);
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    background-image: none;
    background-color: var(--white);
}

.preview__stack.has-bg {
    background: var(--white);
    border-color: #d1d5db;
}

.layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    pointer-events: none;
    z-index: var(--z, 1);
    transition: opacity 0.15s ease;
    will-change: opacity;
    filter: none;
    backdrop-filter: none;
    box-shadow: none;
}

/* КНОПКИ В ПРЕВЬЮ - НА ДЕСКТОПЕ СНИЗУ */
.preview__buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    order: 1;
    margin-top: 1rem;
    margin-bottom: 0;
}

.preview__button {
    flex: 1;
    max-width: 140px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.preview__button--primary {
    background: var(--purple-700);
    color: var(--white);
}

.preview__button--primary:hover {
    background: var(--purple-300);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgb(0 0 0 / 0.15);
}

.preview__button--primary:active {
    transform: translateY(0);
}

.preview__button--secondary {
    background: var(--gray-100);
    color: var(--gray-600);
    border: 1px solid #e5e7eb;
}

.preview__button--secondary:hover {
    background: #f3f4f6;
    border-color: var(--purple-300);
    color: var(--purple-700);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgb(0 0 0 / 0.1);
}

.preview__button--secondary:active {
    transform: translateY(0);
}

.preview__download {
    display: none;
}

/*==== МОБИЛЬНАЯ АДАПТАЦИЯ ====*/
@media (max-width: 1008px) {
    .generator__wrap {
        flex-direction: column;
        gap: 1rem; /* вернул отступ между окнами */
        padding-block: 2rem;
    }
    
    /* ФОРМА СВЕРХУ */
    .config {
        order: -1;
        padding: 0.6rem 1rem 0; /* убрал нижний отступ полностью, уменьшил верхний */
    }
    
    /* ПРЕВЬЮ СНИЗУ */
    .preview {
        order: 1;
        margin-left: 0;
        flex: none;
        max-width: none;
    }
    
    .preview__frame {
        padding: 1rem;
        height: auto;
    }
    
    .preview__content {
        padding-bottom: 0;
    }
    
    .preview__stack {
        max-width: 100%;
        width: 100%;
        border-width: 1px;
    }
    
    /* КНОПКИ СНИЗУ ПРЕВЬЮ (ПОД КАРТИНКОЙ) */
    .preview__buttons {
        order: 1;
        gap: 0.75rem;
        margin-top: 1rem;
        margin-bottom: 0;
    }
    
    .preview__button {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
        max-width: none;
        flex: 1;
    }
    
    .config__title {
        margin: 0 0 0.6rem; /* уменьшил с 0.8rem */
        font-size: 1.1rem;
    }
    
    /* ИСПРАВЛЕННАЯ МОБИЛЬНАЯ СТРУКТУРА */
    .mobile-row {
        display: block !important;
        margin-bottom: 0.6rem; /* уменьшил с 0.8rem */
    }
    
    /* Поля БЕЗ тумблеров - выравнивание как у полей С тумблерами */
    .mobile-row .field.no-switch {
        display: grid !important;
        grid-template-columns: 85px 38px 1fr 60px;
        align-items: center;
        column-gap: 0.4rem;
        margin-bottom: 0.5rem; /* уменьшил с 0.6rem */
    }
    
    .mobile-row .field.no-switch label {
        font-size: 0.8rem !important;
        text-align: left !important;
        font-weight: 600;
        grid-column: 1;
    }
    
    .mobile-row .field.no-switch select {
        font-size: 0.7rem !important;
        padding: 0.3rem 0.4rem !important;
        border-radius: var(--radius-lg);
        grid-column: 3;
        width: 125px;
        justify-self: end;
        margin-right: 8px;
    }
    
    .mobile-row .field.no-switch .trait-arrows {
        grid-column: 4;
        justify-content: flex-start;
        margin-left: 0 !important;
        gap: 1px;
    }
    
    .mobile-row .arrow-btn {
        width: 22px;
        height: 22px;
        border-radius: 3px;
    }
    
    .mobile-row .arrow-btn svg {
        width: 9px;
        height: 9px;
    }
    
    /* Поля с тумблерами - та же структура */
    .field:not(.no-switch) {
        grid-template-columns: 85px 38px 1fr 60px;
        column-gap: 0.4rem;
        margin-bottom: 0.5rem; /* уменьшил с 0.6rem */
        align-items: center;
    }
    
    .field:not(.no-switch) > label {
        font-size: 0.8rem;
    }
    
    .field:not(.no-switch) select {
        font-size: 0.7rem;
        padding: 0.3rem 0.4rem;
        width: 125px;
        justify-self: end;
        margin-right: 8px;
    }
    
    .field:not(.no-switch) .switch {
        width: 34px;
        height: 18px;
        transform: translateX(-2px);
    }
    
    .field:not(.no-switch) .switch .slider::before {
        width: 14px;
        height: 14px;
        left: 2px;
        top: 2px;
        background-size: 8px;
    }
    
    .field:not(.no-switch) .switch input:checked + .slider::before {
        transform: translateX(16px);
    }
    
    .field:not(.no-switch) .trait-arrows {
        margin-left: 0;
        gap: 1px;
    }
    
    .field:not(.no-switch) .arrow-btn {
        width: 22px;
        height: 22px;
        border-radius: 3px;
    }
    
    .field:not(.no-switch) .arrow-btn svg {
        width: 9px;
        height: 9px;
    }
    
    .upload {
        margin: 0.5rem 0 0; /* увеличил отступ сверху до 0.5rem */
        font-size: 0.75rem;
    }
    
    .actions {
        display: none !important; /* принудительно скрываем пустой блок */
    }
    
    .btn {
        padding: 0.45rem 1rem;
        font-size: 0.8rem;
    }
    
    :root {
        --label-width: 85px;
        --gap: 0.4rem;
    }
}

/* Очень маленькие экраны */
@media (max-width: 480px) {
    .mobile-row .field.no-switch {
        grid-template-columns: 80px 36px 1fr 55px;
    }
    
    .mobile-row .field.no-switch label {
        font-size: 0.75rem !important;
    }
    
    .mobile-row .field.no-switch select {
        font-size: 0.65rem !important;
        width: 115px;
        margin-right: 6px;
    }
    
    .field:not(.no-switch) {
        grid-template-columns: 80px 36px 1fr 55px;
    }
    
    .field:not(.no-switch) > label {
        font-size: 0.75rem;
    }
    
    .field:not(.no-switch) select {
        font-size: 0.65rem;
        width: 115px;
        margin-right: 6px;
    }
    
    .preview__button {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }

    .config{
        max-height: 355px;
    }

}

/* Промежуточные разрешения - заполнение пустого пространства */
@media (min-width: 500px) and (max-width: 1008px) {
    .config {
        max-width: 600px;
        margin: 0 auto;
    }
    
    .field:not(.no-switch) select,
    .mobile-row .field.no-switch select {
        width: auto;
        min-width: 200px;
        max-width: 300px;
    }
}

/* ios safari: фикс большого зазора между формой и превью */
@supports (-webkit-touch-callout: none) {         /* таргетим webkit на iOS */
  @media (max-width: 1008px) {
    .generator__wrap{
      display: block !important;                  /* вместо flex-колонки с gap */
    }
    .config{
      margin-bottom: 0 !important;                /* на всякий случай */
      padding-bottom: 0 !important;
    }
    .upload{
      margin-bottom: 15px !important;                /* чтобы линк не добавлял отступ */
    }
    .preview{
      margin-top: 10px !important;                /* контролируемый зазор (поменяй при желании) */
    }
  }
}













