/* Global Styles */
:root {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --accent-color: #bb86fc;
    --accent-hover: #9965f4;
    --secondary-color: #03dac6;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
    --danger-color: #cf6679;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

/* Dynamic Background */
.background-globes {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.globe {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.6;
}

.globe-1 {
    width: 400px;
    height: 400px;
    background: #7a28ff;
    top: -100px;
    left: -100px;
    animation: float 10s infinite ease-in-out;
}

.globe-2 {
    width: 300px;
    height: 300px;
    background: #ff28a9;
    bottom: -50px;
    right: -50px;
    animation: float 12s infinite ease-in-out reverse;
}



@keyframes float {
    0% {
        transform: translate(0, 0);
    }

    50% {
        transform: translate(30px, 30px);
    }

    100% {
        transform: translate(0, 0);
    }
}

/* Glassmorphism Container */
.container {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--glass-shadow);
    width: 90%;
    max-width: 1400px;
    /* Increased width for v2 */
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    height: 90vh;
    overflow-y: hidden;
    /* Hide main scroll, scroll inside sections */
}

.header {
    text-align: center;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.header h1 {
    font-size: 2.5rem;
    margin: 0;
    background: linear-gradient(90deg, #bb86fc, #03dac6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.version-tag {
    font-size: 0.5em;
    vertical-align: super;
    background: rgba(187, 134, 252, 0.2);
    -webkit-text-fill-color: var(--accent-color);
    color: var(--accent-color);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 5px;
}

/* Main Layout */
.main-content {
    display: grid;
    grid-template-columns: 2fr 1fr;
    /* More space for controls */
    gap: 2rem;
    height: 100%;
    overflow: hidden;
}

/* Left Column: Controls */
.controls-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
    padding-right: 0.5rem;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

/* Hide scrollbar for Chrome, Safari and Opera */
.controls-section::-webkit-scrollbar {
    display: none;
}

.section-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--secondary-color);
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.5rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-weight: 500;
    color: #bdbdbd;
}

textarea,
input[type="text"] {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.75rem;
    color: #D4A574;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 1rem;
    transition: all 0.3s ease;
}

textarea:focus,
input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 10px rgba(187, 134, 252, 0.3);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* Output Display (for syntax highlighting) */
.output-display {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.75rem;
    color: #D4A574;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 1rem;
    min-height: 80px;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    user-select: text;
    cursor: text;
}

.output-display:empty::before {
    content: attr(data-placeholder);
    color: rgba(255, 255, 255, 0.3);
    font-style: italic;
}

/* Custom Fields */
.custom-field-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.custom-field-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: var(--accent-color);
}

.custom-field-row input[type="text"] {
    flex: 1;
}

.btn-delete {
    background: rgba(207, 102, 121, 0.2);
    color: var(--danger-color);
    border: 1px solid rgba(207, 102, 121, 0.5);
    padding: 0 1rem;
}

.btn-delete:hover {
    background: rgba(207, 102, 121, 0.4);
}


/* Tag Grid System */
.category-block {
    margin-bottom: 2rem;
}

.category-block h3 {
    font-size: 1.1rem;
    color: #fff;
    margin-bottom: 1rem;
}

.tags-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.5rem;
}

.tag-chip {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    padding: 0.35rem 0.6rem;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 32px;
}

.tag-chip:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.tag-chip.active {
    background: var(--accent-color);
    color: #121212;
    font-weight: 600;
    box-shadow: 0 0 15px rgba(187, 134, 252, 0.4);
    border-color: var(--accent-color);
}

.custom-tag-input {
    grid-column: 1 / -1;
    /* Span full width */
    margin-top: 0.5rem;
}

/* Right Column: Output */
.output-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
    padding-right: 1rem;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

/* Hide scrollbar for Chrome, Safari and Opera */
.output-section::-webkit-scrollbar {
    display: none;
}

.sticky-output {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.output-container {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex-grow: 1;
}

#final-prompt,
#final-negative {
    min-height: 250px;
    resize: vertical;
}

.output-container h2 {
    margin-top: 0;
    font-size: 1.25rem;
    color: var(--secondary-color);
    margin-bottom: 0.5rem;
}

.output-container h3 {
    margin-top: 0;
    font-size: 1rem;
    color: #ff5252;
    margin-bottom: 0.5rem;
}

.output-container textarea {
    background: transparent;
    border: none;
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    line-height: 1.5;
    flex-grow: 1;
    color: #81c784;
}

.negative-output-container textarea {
    color: #ff8a80;
}

/* Language Toggle */
.language-toggle {
    display: grid;
    grid-template-columns: 240px 1fr;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
}

.language-toggle label {
    margin: 0;
    color: var(--secondary-color);
    font-weight: 600;
}

.toggle-options {
    display: flex;
    gap: 1rem;
}

.toggle-options label {
    color: var(--text-color);
    font-weight: 400;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toggle-options input[type="radio"] {
    accent-color: var(--accent-color);
    width: auto;
    margin: 0;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 8px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-color), #7c4dff);
    color: white;
    /* Ensure text is readable */
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.divider {
    border: 0;
    height: 1px;
    background: var(--glass-border);
    margin: 2rem 0;
}

/* Responsive */
@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .container {
        height: auto;
        min-height: 90vh;
        overflow-y: visible;
    }

    .controls-section {
        overflow-y: visible;
    }
}

/* ==================== Preview Container ==================== */
.preview-container {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.2rem;
    margin-bottom: 1.5rem;
    backdrop-filter: blur(10px);
}

.preview-container h3 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#preview-wrapper {
    width: 100%;
    /* height: 320px; Removed fixed height */
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#preview-placeholder {
    /* position: absolute; Removed absolute */
    /* top: 0; */
    /* left: 0; */
    width: 100%;
    aspect-ratio: 1 / 1;
    /* Match image box ratio */
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    color: #666;
    text-align: center;
    padding: 2rem;
}

#preview-placeholder.active {
    display: flex;
}

#preview-placeholder i {
    font-size: 3rem;
    opacity: 0.3;
}

#preview-placeholder p {
    margin: 0;
    font-size: 0.95rem;
}

#preview-placeholder .preview-hint {
    font-size: 0.85rem;
    opacity: 0.6;
}

#preview-content {
    /* position: absolute; Removed absolute */
    /* top: 0; */
    /* left: 0; */
    width: 100%;
    /* height: 100%; */
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

#preview-content.active {
    display: flex;
}

#preview-image-box {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: white;
    text-align: center;
    padding: 2rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.preview-image-real {
    width: 100%;
    height: 100%;
    object-fit: contain;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 5;
    transition: opacity 0.3s ease;
}

#preview-image-box::before {
    content: attr(data-icon);
    position: absolute;
    font-size: 80px;
    opacity: 0.15;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.3s ease;
}

#preview-image-box .preview-text {
    position: relative;
    z-index: 1;
    font-weight: 500;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

#preview-label {
    margin-top: 0.8rem;
    font-size: 0.95rem;
    color: var(--primary-color);
    font-weight: 500;
    text-align: center;
}

.tags-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.tag-chip {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 0.6rem 0.4rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s, transform 0.15s;
    user-select: none;
    font-size: 0.85rem;
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
}

.tag-chip.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: #121212;
    font-weight: 600;
    box-shadow: 0 0 15px rgba(187, 134, 252, 0.4);
}

.tag-chip:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.custom-tag-input {
    width: 100%;
    box-sizing: border-box;
    margin-top: 0.5rem;
}

/* Mascot Styling */
#mascot-wrapper {
    position: fixed;
    bottom: -10px;
    right: -40px;
    z-index: 9999;
    pointer-events: none;
    /* Allows clicking through the empty space around the image */
    user-select: none;
}

#mascot-image {
    width: 320px;
    height: auto;
    filter: drop-shadow(2px 4px 12px rgba(0, 0, 0, 0.3));
    animation: mascotFloat 5s ease-in-out infinite;
    transition: transform 0.3s ease;
    pointer-events: auto;
    /* Re-enable pointer events for the image itself */
    cursor: pointer;
}

#mascot-image:hover {
    transform: scale(1.05) translateY(-5px);
    filter: drop-shadow(4px 8px 16px rgba(0, 0, 0, 0.4));
}

@keyframes mascotFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

@media (max-width: 768px) {
    #mascot-wrapper {
        right: -50px;
        bottom: -20px;
    }

    #mascot-image {
        width: 180px;
    }
}