:root {
    --discord-bg: #36393f;
    --discord-secondary: #2f3136;
    --discord-text: #dcddde;
    --discord-input: #40444b;
    --discord-accent: #5865f2;
    --discord-hover: #4752c4;
    --discord-border: #202225;
    --discord-danger: #ed4245;
    --discord-success: #43b581;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'gg sans', 'Noto Sans', sans-serif;
}

body {
    background: var(--discord-bg);
    color: var(--discord-text);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
}

.container {
    height: 100vh;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 3fr 7fr;
    gap: 20px;
    padding: 20px;
}

.input-section, .preview-section {
    background: var(--discord-secondary);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--discord-border);
    height: calc(100vh - 40px);
    overflow-y: auto;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: var(--discord-input);
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 10px;
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.expanded {
    max-height: 1000px !important;
}

.collapsible-content.expanded {
    max-height: 1000px;
    transition: max-height 0.3s ease-in;
}

.form-group {
    margin-bottom: 16px;
    position: relative;
}

label {
    display: block;
    margin-bottom: 8px;
    color: var(--discord-text);
    font-weight: 500;
}

input, textarea, select {
    width: 100%;
    padding: 10px;
    background: var(--discord-input);
    border: 1px solid var(--discord-border);
    border-radius: 8px;
    color: var(--discord-text);
    font-size: 14px;
    transition: all 0.3s;
}

textarea {
    width: 100%;
    padding: 10px;
    background: var(--discord-input);
    border: 1px solid var(--discord-border);
    border-radius: 8px;
    color: var(--discord-text);
    font-size: 14px;
    transition: all 0.3s;
    line-height: 1.6;
    z-index: 1;
    position: relative;
    resize: vertical;
    min-height: 100px;
    max-height: 500px;
}

.highlight-wrapper {
    margin-bottom: 16px;
}

.parameters {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin: 20px 0;
}

.char-prompt {
    background: var(--discord-input);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 10px;
    transition: all 0.2s;
}

.char-prompt:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.prompt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.prompt-controls {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 10px 16px;
    background: var(--discord-accent);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    transition: all 0.2s;
}

.btn:hover:not(:disabled) {
    background: var(--discord-hover);
    transform: translateY(-1px);
}

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

.btn-secondary {
    background: var(--discord-secondary);
    border: 1px solid var(--discord-border);
}

.btn-remove {
    background: var(--discord-danger);
    padding: 6px 12px;
}

.btn-coords {
    background: var(--discord-accent);
    padding: 6px 12px;
    transition: all 0.2s;
}

.btn-coords.coords-active {
    background: var(--discord-success);
}

.btn-coords:hover {
    transform: translateY(-2px);
}

#imagePreview {
    width: 100%;
    min-height: 400px;
    border: 2px dashed var(--discord-border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--discord-input);
    margin-bottom: 20px;
}

#generatedImage {
    max-width: 100%;
    max-height: 600px;
    border-radius: 8px;
    cursor: pointer;
}

.preview-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
}

.history-section {
    background: var(--discord-input);
    padding: 15px;
    border-radius: 8px;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.history-controls {
    display: flex;
    gap: 10px;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.history-item {
    position: relative;
    cursor: pointer;
    border-radius: 4px;
    overflow: hidden;
    aspect-ratio: 1;
}

.history-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s;
}

.history-item:hover img {
    transform: scale(1.05);
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkbox-group input[type="checkbox"] {
    width: auto;
}

.checkbox-group label {
    margin-bottom: 0;
}

.coords-popup {
    position: fixed;
    background: var(--discord-secondary);
    border: 1px solid var(--discord-border);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    width: 250px;
    z-index: 1000;
    animation: popup-appear 0.2s ease-out;
    overflow: hidden;
}

@keyframes popup-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.coords-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: var(--discord-input);
    border-bottom: 1px solid var(--discord-border);
}

.coords-popup-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.coords-close-btn {
    background: none;
    border: none;
    color: var(--discord-text);
    font-size: 20px;
    cursor: pointer;
    padding: 0 5px;
}

.coords-close-btn:hover {
    color: white;
}

.coords-popup .coords-toggle {
    padding: 12px 15px;
    border-bottom: 1px solid var(--discord-border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.coords-popup .position-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    padding: 15px;
    max-width: 100%;
}

.coords-popup .grid-cell {
    width: 100%;
    aspect-ratio: 1;
    background: var(--discord-input);
    border: 1px solid var(--discord-border);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.coords-popup .grid-cell:hover {
    background: var(--discord-hover);
    transform: scale(1.1);
}

.coords-popup .grid-cell.selected {
    background: var(--discord-accent);
    border-color: white;
    transform: scale(1.1);
}

.coords-popup .use-coords-checkbox {
    width: auto !important;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spin {
    animation: spin 1s linear infinite;
}

.download-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    color: white;
    transition: opacity 0.5s ease;
}

.download-overlay.fade-out {
    opacity: 0;
}

.download-content {
    background: var(--discord-secondary);
    border-radius: 8px;
    padding: 20px;
    width: 400px;
    max-width: 90%;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.progress-container {
    width: 100%;
    height: 10px;
    background: var(--discord-input);
    border-radius: 5px;
    margin: 15px 0;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--discord-accent);
    width: 0%;
    transition: width 0.3s ease;
}

.download-spinner {
    display: inline-block;
    position: relative;
    width: 50px;
    height: 50px;
    margin: 10px auto;
}

.spinner-dot {
    position: absolute;
    width: 6px;
    height: 6px;
    background-color: var(--discord-accent);
    border-radius: 50%;
    animation: spinner-animation 1.2s linear infinite;
}

.spinner-dot:nth-child(1) {
    top: 22px;
    left: 0;
    animation-delay: 0s;
}

.spinner-dot:nth-child(2) {
    top: 13px;
    left: 6px;
    animation-delay: -0.15s;
}

.spinner-dot:nth-child(3) {
    top: 6px;
    left: 22px;
    animation-delay: -0.3s;
}

.spinner-dot:nth-child(4) {
    top: 13px;
    right: 6px;
    animation-delay: -0.45s;
}

.spinner-dot:nth-child(5) {
    top: 22px;
    right: 0;
    animation-delay: -0.6s;
}

.spinner-dot:nth-child(6) {
    bottom: 13px;
    right: 6px;
    animation-delay: -0.75s;
}

.spinner-dot:nth-child(7) {
    bottom: 6px;
    left: 22px;
    animation-delay: -0.9s;
}

.spinner-dot:nth-child(8) {
    bottom: 13px;
    left: 6px;
    animation-delay: -1.05s;
}

@keyframes spinner-animation {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.3;
    }
}

.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    padding-top: 50px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.9);
}

.modal-content {
    margin: auto;
    display: block;
    max-width: 95%;
    max-height: 95%;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
}

.close-modal:hover,
.close-modal:focus {
    color: #bbb;
    text-decoration: none;
}

@media only screen and (max-width: 700px){
    .modal-content {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
        height: auto;
        overflow: visible;
    }

    body {
        height: auto;
        overflow: visible;
    }

    .input-section, .preview-section {
        height: auto;
        overflow-y: visible;
    }

    .parameters {
        grid-template-columns: 1fr;
    }

    #imagePreview {
        min-height: 300px;
    }

    #generatedImage {
        max-width: 100%;
        height: auto;
    }

    .preview-controls {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        background: var(--discord-secondary);
        padding: 10px;
        border-radius: 20px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.2);
        z-index: 1000;
    }

    .history-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }
}