:root {
    --theme-color: #1d2b4c;
    --primary-gradient: linear-gradient(135deg, #0f1626 0%, #1d2b4c 100%);
    --generating-gradient: linear-gradient(135deg, #162519 0%, #1d3d2b 100%);
    --purple-glow: rgba(120, 100, 255, 0.3);
    --purple-glow-intense: rgba(120, 100, 255, 0.5);
    --translucent-surface: rgba(255, 255, 255, 0.1);
    --border-color: rgba(255, 255, 255, 0.2);
    --primary-text: rgba(255, 255, 255, 0.85);
    --secondary-text: rgba(255, 255, 255, 0.6);
    --icon-color: rgba(255, 255, 255, 0.8);
    --details-bg: rgba(15, 20, 35, 0.85);
    --details-content-bg: rgba(0, 0, 0, 0.2);
    --transition-speed: 0.3s;
    --error-color: rgba(255, 100, 100, 0.8);
    --success-color: rgba(100, 255, 100, 0.8);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transition: all var(--transition-speed) ease;
}

body {
    font-family: "Helvetica Neue", sans-serif;
    background: var(--primary-gradient);
    color: var(--primary-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-weight: 300;
    position: relative;
    overflow-x: hidden;
}

/* Ambient background shapes */
body::before,
body::after {
    content: "";
    position: fixed;
    width: 60vw;
    height: 60vw;
    border-radius: 50%;
    background: radial-gradient(circle, var(--purple-glow) 0%, transparent 70%);
    filter: blur(40px);
    z-index: -1;
    animation: float 15s infinite alternate ease-in-out;
}

body::before {
    top: -20vh;
    left: -20vw;
}

body::after {
    bottom: -20vh;
    right: -20vw;
    animation-delay: -7s;
}

@keyframes float {
    0% {
        transform: translateY(0) rotate(0deg);
    }
    100% {
        transform: translateY(30px) rotate(5deg);
    }
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    50% {
        transform: scale(1.05);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 0.8;
    }
}

.container {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex-grow: 1;
    z-index: 1;
    position: relative;
}

header {
    text-align: center;
    padding: 1.5rem 0;
}

h1 {
    font-weight: 200;
    letter-spacing: 2px;
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

footer {
    text-align: center;
    padding: 1rem 0;
    margin-top: auto;
}

.form-area {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: var(--translucent-surface);
    backdrop-filter: blur(5px);
    padding: 1.5rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.parameter {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
}

.parameter label {
    font-size: 0.8rem;
    opacity: 0.8;
    letter-spacing: 0.5px;
    display: inline-block;
    margin-bottom: 0.25rem;
}

.parameters-heading {
    font-size: 0.9rem;
    font-weight: 300;
    margin: 0.75rem 0 0.5rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--primary-text);
}

.input-wrapper,
.textarea-wrapper,
.select-wrapper {
    position: relative;
}

.tooltip {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    background: var(--details-bg);
    padding: 0.5rem;
    border-radius: 5px;
    font-size: 0.75rem;
    color: var(--secondary-text);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 10;
    max-width: 250px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

.input-wrapper:hover .tooltip,
.textarea-wrapper:hover .tooltip,
.select-wrapper:hover .tooltip {
    opacity: 1;
    visibility: visible;
}

textarea,
select,
input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.9rem;
    background: rgba(0, 0, 0, 0.2);
    color: var(--primary-text);
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}

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

textarea:focus,
select:focus,
input:focus {
    outline: none;
    border-color: var(--purple-glow-intense);
    box-shadow: 0 0 10px var(--purple-glow);
}

textarea::placeholder,
input::placeholder {
    color: var(--secondary-text);
    opacity: 0.7;
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='rgba(255, 255, 255, 0.8)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1em;
    cursor: pointer;
}

button {
    padding: 0.75rem 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--translucent-surface);
    color: var(--primary-text);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 300;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all var(--transition-speed) cubic-bezier(0.175, 0.885, 0.32, 1.275);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

button:focus-visible {
    outline: 2px solid var(--purple-glow-intense);
    outline-offset: 2px;
}

button svg {
    width: 18px;
    height: 18px;
    stroke: var(--icon-color);
}

button:hover {
    background: var(--translucent-surface);
    transform: scale(1.05);
    box-shadow: 0 0 15px var(--purple-glow);
}

#generate {
    margin-top: 0.5rem;
    align-self: center;
}

.parameter-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.result-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    margin-top: 1rem;
}

.loading {
    display: none;
    font-size: 0.85rem;
    font-weight: 300;
    letter-spacing: 1px;
    color: var(--secondary-text);
    position: relative;
    padding-left: 24px;
}

.loading::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid var(--purple-glow);
    border-right: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.image-container {
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    max-width: 80vw;
    max-height: 80vh;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 1rem;
    transition: transform 0.5s cubic-bezier(0.19, 1, 0.22, 1);
}

.image-container:hover {
    transform: scale(1.02);
}

img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.image-controls {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.hidden {
    display: none;
}

.status-text {
    font-size: 0.85rem;
    font-weight: 300;
    letter-spacing: 1px;
    color: var(--secondary-text);
}

.section-header {
    font-size: 1rem;
    font-weight: 300;
    margin: 0.5rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.image-info {
    background: var(--details-content-bg);
    padding: 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-top: 0.5rem;
    max-height: 150px;
    overflow-y: auto;
    width: 100%;
}

.image-info pre {
    white-space: pre-wrap;
    font-family: monospace;
    color: var(--secondary-text);
}

.generating .form-area {
    background: var(--generating-gradient);
}

.tab-buttons {
    display: flex;
    margin-bottom: 1rem;
}

.tab-button {
    background: transparent;
    border: none;
    padding: 0.5rem 1rem;
    color: var(--secondary-text);
    border-bottom: 2px solid transparent;
    border-radius: 0;
    font-size: 0.85rem;
}

.tab-button.active {
    color: var(--primary-text);
    border-bottom-color: var(--purple-glow-intense);
}

.tab-button:hover {
    background: transparent;
    transform: none;
    box-shadow: none;
    color: var(--primary-text);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.parameters-updated {
    animation: highlightForm 1s ease;
}

@keyframes highlightForm {
    0% {
        box-shadow: 0 0 0 0 rgba(120, 100, 255, 0.5);
    }
    50% {
        box-shadow: 0 0 20px 10px rgba(120, 100, 255, 0.5);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(120, 100, 255, 0.5);
    }
}

/* Responsive improvements */
@media (max-width: 600px) {
    .container {
        padding: 1rem 0.5rem;
    }

    .form-area {
        padding: 1rem;
    }

    .parameter-group {
        grid-template-columns: 1fr;
    }

    button {
        padding: 0.5rem 1rem;
    }

    img {
        max-height: 50vh;
    }
}

/* Accessibility focus states */
:focus-visible {
    outline: 2px solid var(--purple-glow-intense);
    outline-offset: 2px;
}

/* Error feedback */
.error-message {
    color: var(--error-color);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* Success feedback */
.success-message {
    color: var(--success-color);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

.label-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.clear-button {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 5px;
    height: auto;
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--secondary-text);
    margin: 0;
}

.clear-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: var(--primary-text);
    transform: scale(1.02);
    box-shadow: 0 0 8px var(--purple-glow);
}

.button-container-below {
    display: flex;
    /* justify-content: flex-end; */
    justify-content: space-between;
    margin-top: 0.5rem;
}

.paste-button {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 5px;
    height: auto;
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--secondary-text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.paste-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: var(--primary-text);
    transform: scale(1.02);
    box-shadow: 0 0 8px var(--purple-glow);
}

.paste-icon {
    opacity: 0.8;
}

.paste-button:hover .paste-icon {
    opacity: 1;
}

/* Resolution controller */
.resolution-controller {
    margin: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.aspect-rectangle-container {
    display: flex;
    justify-content: center;
    padding: 1rem 0;
}

.aspect-rectangle {
    position: relative;
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    transition: width 0.2s, height 0.2s;
}

.canvas-container {
    position: relative;
    display: flex;
    justify-content: center;
    margin: 1rem 0;
    overflow: hidden;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.2);
}

#resolution-canvas {
    max-width: 100%;
    height: auto;
    cursor: crosshair;
    touch-action: none; /* Prevent browser handling of touch events */
}

.dimension-display {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.6);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--primary-text);
    pointer-events: none;
}

.drag-handle {
    position: absolute;
    bottom: -8px;
    right: -8px;
    width: 16px;
    height: 16px;
    background: var(--purple-glow-intense);
    border-radius: 50%;
    cursor: nwse-resize;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
}

.drag-handle:hover,
.drag-handle:active {
    transform: scale(1.2);
    box-shadow: 0 0 10px var(--purple-glow);
}

.aspect-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.aspect-guides,
.size-presets {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.guide,
.preset {
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--secondary-text);
}

.guide:hover,
.preset:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--primary-text);
}

.guide.active,
.preset.active {
    background: var(--purple-glow);
    color: var(--primary-text);
    border-color: var(--purple-glow-intense);
}

.flip-orientation {
    padding: 0.25rem;
    height: 24px;
    width: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.flip-orientation svg {
    width: 14px;
    height: 14px;
    stroke: var(--secondary-text);
}

.flip-orientation:hover {
    background: rgba(255, 255, 255, 0.1);
}

.flip-orientation:hover svg {
    stroke: var(--primary-text);
}

/* Media queries for responsive design */
@media (max-width: 600px) {
    .aspect-rectangle {
        width: 100px;
        height: 100px;
    }

    .guide,
    .preset {
        padding: 0.2rem 0.4rem;
        font-size: 0.65rem;
    }
}
