.image-selector {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

    .image-selector img,
    .ai-image-item,
    .ai-slot {
        width: 100%;
        aspect-ratio: 1 / 1;
        border-radius: 14px;
        object-fit: cover;
    }

.ai-image-item {
    position: relative;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.2);
}

    .ai-image-item:not(.ai-image-pending) {
        cursor: pointer;
    }

.ai-image-pending {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    cursor: default;
}

.ai-image-pending-inner {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-image-spinner {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    border: 3px solid rgba(152, 0, 255, 0.22);
    border-top-color: #9800ff;
    box-shadow: 0 0 14px rgba(152, 0, 255, 0.35);
    animation: ai-image-spin 0.8s linear infinite;
}

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

.ai-slot {
    border: 2px dashed rgba(255, 255, 255, 0.4);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-slot-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center;
    color: rgba(255, 255, 255, 0.85);
    font-size: 14px;
}

.ai-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding:
        calc(env(safe-area-inset-top, 0px) + 20px)
        16px
        calc(env(safe-area-inset-bottom, 0px) + 80px);
    box-sizing: border-box;
}

.job-request-toast {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translate(-50%, -10px);
    opacity: 0;
    z-index: 9999;
    padding: 10px 18px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.9);
    color: #f3e2fe;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
    pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s ease;
}

    .job-request-toast.show {
        opacity: 1;
        transform: translate(-50%, 0);
    }

.char-image-box {
    width: 100%;
    max-width: 260px;
    aspect-ratio: 1 / 1;
    margin: 16px auto;
    border-radius: 16px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
}

    .char-image-box img {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        object-fit: cover;
        border-radius: inherit;
    }

.action-bar {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

.apply-btn {
    background: linear-gradient(135deg, #6c5ce7, #8f7cff);
    color: #fff;
    padding: 10px 18px;
    border-radius: 14px;
    font-weight: 600;
}

    .apply-btn.is-disabled,
    .apply-btn:disabled {
        opacity: 0.45;
        pointer-events: none;
    }

.ai-modal textarea {
    width: 100%;
    min-height: 108px;
    resize: vertical;
    padding: 12px 14px;
    border-radius: 14px;
    background: #1b1928;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    line-height: 1.55;
    box-sizing: border-box;
}

.ai-modal textarea:focus {
    outline: none;
    border-color: rgba(177, 128, 255, 0.95);
    box-shadow: 0 0 0 3px rgba(123, 79, 255, 0.18);
}

.ai-modal textarea.is-invalid {
    border-color: rgba(255, 99, 132, 0.95);
    box-shadow: 0 0 0 3px rgba(255, 99, 132, 0.14);
}

.ai-modal textarea.is-valid {
    border-color: rgba(177, 128, 255, 0.95);
}

.page-title {
    text-align: center;
    margin: 12px 0 16px;
    font-size: 20px;
    font-weight: 600;
}

.style-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 0;
}

.style-btn {
    padding: 6px 12px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(0, 0, 0, 0.4);
    color: #ddd;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
}

    .style-btn:hover {
        background: var(--action-btn-solid-hover, #62407d);
    }

    .style-btn.active {
        background: linear-gradient(135deg, #7a5cff, #9b7cff);
        color: #fff;
        border-color: #bba8ff;
        box-shadow: 0 0 6px rgba(154, 120, 255, 0.7);
        transform: scale(1.05);
    }

.model-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.model-btn {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid #523369;
    background: #1a1024;
    color: #d9c6ff;
    cursor: pointer;
    font-size: 13px;
}

    .model-btn.active {
        background: #523369;
    }
.ai-modal {
    position: relative;
    z-index: 10000;
    width: min(100%, 560px);
    margin: 0 auto;
    padding: 18px;
    border-radius: 22px;
    background: linear-gradient(180deg, rgba(28, 18, 42, 0.98), rgba(18, 11, 29, 0.98));
    border: 1px solid rgba(178, 132, 255, 0.18);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.42);
    max-height: calc(100dvh - 100px);
    overflow-y: auto;
}

.ai-modal h3 {
    margin: 0 0 14px;
    font-size: 20px;
    font-weight: 700;
    color: #f6efff;
}

.ai-prompt-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 14px 0 8px;
}

.ai-prompt-guide {
    color: rgba(234, 225, 255, 0.72);
    font-size: 12px;
}

.ai-char-count {
    color: rgba(234, 225, 255, 0.78);
    font-size: 12px;
    font-weight: 600;
}

.ai-char-count.is-invalid {
    color: #ff5c7a;
}

.ai-char-count.is-valid {
    color: #cdb8ff;
}

.gemini-only {
    max-width: 120px;
    white-space: nowrap;
    transition:
        opacity 0.2s ease,
        transform 0.2s ease,
        max-width 0.2s ease,
        padding 0.2s ease,
        margin 0.2s ease,
        border-color 0.2s ease;
}

.gemini-only.is-hidden {
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    max-width: 0;
    padding-left: 0;
    padding-right: 0;
    margin: 0;
    border-color: transparent;
    overflow: hidden;
}

.ai-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

.ai-action-btn {
    min-width: 92px;
    padding: 11px 16px;
    border-radius: 14px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

.ai-action-btn:hover {
    transform: translateY(-1px);
}

.ai-action-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.ai-cancel-btn {
    background: var(--action-btn-solid, #523369);
    color: #efe7ff;
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: var(--action-btn-shadow, 0 10px 22px rgba(82, 51, 105, 0.34));
}

.ai-cancel-btn:hover {
    background: var(--action-btn-solid-hover, #62407d);
}

.ai-generate-btn {
    background: var(--action-btn-solid, #523369);
    color: #fff;
    box-shadow: var(--action-btn-shadow, 0 10px 22px rgba(82, 51, 105, 0.34));
}

.ai-generate-btn:hover:not(:disabled) {
    box-shadow: 0 14px 26px rgba(82, 51, 105, 0.42);
}

@media (max-width: 640px) {
    .ai-overlay {
        padding-left: 12px;
        padding-right: 12px;
    }

    .ai-modal {
        width: 100%;
        padding: 16px;
        border-radius: 18px;
    }

    .ai-modal-actions {
        gap: 8px;
    }

    .ai-action-btn {
        flex: 1;
    }
}