* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Monaco', 'Courier New', monospace;
    background: #1a1a2e;
    color: #eee;
    padding: 20px;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

h1 {
    text-align: center;
    color: #00d4ff;
    margin-bottom: 10px;
    font-size: 2.5em;
    text-shadow: 0 0 10px #00d4ff;
}

h1 a {
    color: #00d4ff;
    text-decoration: none;
    transition: color 0.2s ease;
}

.subtitle {
    text-align: center;
    color: #888;
    margin-bottom: 30px;
}

.version {
    text-align:center;
    color:#00d4ff;
    font-family:'Monaco','Courier New',monospace;
    font-size:1em;
    text-shadow:0 0 6px #00d4ff;
    letter-spacing:1px;
}

.created-by {
    text-align: center;
    color: #555;
    margin-top: 40px;
    margin-bottom: 20px;
    font-size: 0.9em;
}

.created-by a {
    color: #00d4ff;
    text-decoration: none;
    transition: color 0.2s ease;
}

.created-by a:hover {
    color: #00ffff;
    text-decoration: underline;
}

.controls {
    background: #16213e;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

/* Dropzone Styles */
.dropzone {
    border: 3px dashed #00d4ff;
    border-radius: 8px;
    padding: 40px 20px;
    text-align: center;
    background: #0f3460;
    margin-left: 18px; /* Center horizontally */
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    width: 100%; /* Take full width of parent */
    max-width: 500px; /* Limit maximum width */
}

.dropzone:hover {
    background: #16213e;
    border-color: #00a8cc;
}

.dropzone.dragover {
    background: #00d4ff;
    border-color: #00a8cc;
    color: #1a1a2e;
}

.dropzone-icon {
    font-size: 3em;
    margin-bottom: 10px;
}

.dropzone-text {
    font-size: 1.2em;
    color: #00d4ff;
    margin-bottom: 10px;
}

.dropzone.dragover .dropzone-text {
    color: #1a1a2e;
}

.dropzone-subtext {
    font-size: 0.9em;
    color: #888;
}

.dropzone.dragover .dropzone-subtext {
    color: #333;
}

.dropzone.has-file {
    border-color: #4caf50;
    background: #1b5e20;
}

.dropzone.has-file .dropzone-text {
    color: #4caf50;
}

.dropzone-filename {
    font-size: 1.1em;
    color: #4caf50;
    margin-top: 10px;
    font-weight: bold;
    word-break: break-all;
}

.file-input-hidden {
    display: none;
}

/* URL Input Section */
.url-section {
    margin-bottom: 20px;
}

.url-input-group {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: end;
}

.quick-links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
    padding: 15px;
    background: #0f3460;
    border-radius: 4px;
}

.quick-link {
    padding: 5px 15px;
    background: #1a1a2e;
    border: 1px solid #00d4ff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    transition: all 0.2s;
}

.quick-link:hover {
    background: #00d4ff;
    color: #1a1a2e;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

label {
    color: #00d4ff;
    margin-bottom: 5px;
    font-size: 0.9em;
}

input[type="text"],
input[type="number"],
select {
    padding: 8px;
    background: #0f3460;
    border: 1px solid #00d4ff;
    border-radius: 4px;
    color: #eee;
    font-family: inherit;
}

#fitBgColor option {
    padding: 5px;
    font-weight: bold;
}

input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

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

button {
    background: #00d4ff;
    color: #1a1a2e;
    border: none;
    padding: 12px 30px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
    font-family: inherit;
    transition: all 0.3s;
}

button:hover:not(:disabled) {
    background: #00a8cc;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,212,255,0.3);
}

button:disabled {
    background: #555;
    cursor: not-allowed;
    opacity: 0.5;
}

.results {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    align-items: start;
}

.image-container {
    background: #16213e;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    margin-bottom: 24px; /* Add space below image containers */
}

.image-container h3 {
    color: #00d4ff;
    margin-top: 0; /* Ensure consistent top alignment */
    margin-bottom: 10px;
    text-align: center;
    height: 43px;
}

.image-dimensions {
    color: #888;
    font-size: 0.85em;
    text-align: center;
    margin-top: 5px;
    margin-bottom: 10px;
    height: 20px;
}

.image-wrapper {
    background: #0f3460;
    padding: 10px;
    border-radius: 4px;
    text-align: center;
    min-height: 360px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.3s ease;
}

.image-wrapper.dragover {
    background: #1a4d7a;
    border: 3px dashed #00d4ff;
    transform: scale(1.02);
}

.image-wrapper.placeholder::before {
    content: '?';
    font-size: 4em;
    color: #7e7b7b;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin-top: -20px;
}

.image-wrapper.placeholder::after {
    content: 'Waiting for conversion...';
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #555;
    font-size: 0.9em;
}

img {
    max-width: 100%;
    max-height: 100%;
    height: auto;
    border-radius: 4px;
    image-rendering: pixelated;
}

.download-btn {
    width: 100%;
    margin-top: 10px;
}

#status {
    margin-top: 20px;
    padding: 15px;
    border-radius: 4px;
    text-align: center;
    display: none;
}

#status.info {
    background: #0f3460;
    color: #00d4ff;
    display: block;
}

#status.success {
    background: #1b5e20;
    color: #4caf50;
    display: block;
}

#status.error {
    background: #5e1b1b;
    color: #f44336;
    display: block;
}

.loading {
    text-align: center;
    color: #00d4ff;
    display: none;
}

.loading.active {
    display: block;
}

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

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #333;
    border-top-color: #00d4ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 5px 10px 0 0;
}

.info-box {
    background: #0f3460;
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 20px;
    border-left: 4px solid #00d4ff;
}

.info-box h4 {
    color: #00d4ff;
    margin-bottom: 10px;
}

.info-box p {
    color: #aaa;
    font-size: 0.9em;
    line-height: 1.5;
}

.section-divider {
    text-align: center;
    color: #555;
    margin: 20px 0;
    position: relative;
}

.section-divider::before,
.section-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: #333;
}

.section-divider::before {
    left: 0;
}

.section-divider::after {
    right: 0;
}

/* Collapsible Section Styles */
.collapsible-header {
    cursor: pointer;
    user-select: none;
    transition: color 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.collapsible-header:hover {
    color: #00d4ff;
}

.collapsible-header .collapse-icon {
    font-size: 0.8em;
    transition: transform 0.3s ease;
}

.collapsible-header.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.collapsible-content {
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.4s ease, opacity 0.3s ease;
    opacity: 1;
}

.collapsible-content.collapsed {
    max-height: 0;
    opacity: 0;
}


/* Tab Styles */
.tabs-container {
    margin: 20px 0;
}

.tabs-header {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    border-bottom: 2px solid #333;
}

.tab-button {
    background: #0f3460;
    color: #888;
    border: none;
    padding: 12px 24px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9em;
    transition: all 0.3s ease;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.tab-button:hover {
    background: #16213e;
    color: #00d4ff;
}

.tab-button.active {
    background: #16213e;
    color: #00d4ff;
    border-bottom: 2px solid #00d4ff;
}

.tab-content {
    display: none;
}

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

/* Old Tab Styles */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #333;
}

.tab {
    padding: 12px 24px;
    background: transparent;
    color: #888;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
    transition: all 0.3s;
    margin-bottom: -2px;
}

.tab:hover {
    color: #00d4ff;
    background: transparent;
    transform: none;
    box-shadow: none;
}

.tab.active {
    color: #00d4ff;
    border-bottom-color: #00d4ff;
}

.tab-content {
    display: none;
}

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

/* Icon Button Styles */
.icon-btn {
    background: none;
    border: none;
    color: #00d4ff;
    font-size: 1.2em;
    cursor: pointer;
    padding: 0 10px 3px;
    margin-left: 10px;
    transition: transform 0.2s ease, opacity 0.2s ease;
    opacity: 0.8;
}

.icon-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.image-container h3 {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Overlay Styles */
.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.overlay.active {
    display: flex;
}

.overlay-content {
    background: #16213e;
    border-radius: 8px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 212, 255, 0.3);
    animation: overlaySlideIn 0.3s ease;
}

@keyframes overlaySlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.overlay-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #333;
}

.overlay-header h3 {
    margin: 0;
    color: #00d4ff;
}

.overlay-close {
    background: none;
    border: none;
    color: #888;
    font-size: 2em;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    transition: color 0.2s ease;
}

.overlay-close:hover {
    color: #ff4444;
}

.overlay-body {
    padding: 20px;
}


div.discord {
    background-color: white;
    margin: auto;
    padding: 4px;
    border-radius: 8px 0 0 0;
    text-align: center;
    position: fixed;
    bottom: -10px;
    right: 0;
    opacity: .8;
}

/* Convert Button Styles */
#convertBtn {
    transition: all 0.3s ease;
}

#convertBtn:hover:not(:disabled) {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

#convertBtn:active:not(:disabled) {
    transform: scale(1.05);
}

#convertBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
/* Loading Placeholder Styles */
.loading-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    background: #0f3460;
    border-radius: 8px;
    padding: 40px 20px;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(0, 212, 255, 0.2);
    border-top-color: #00d4ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

.loading-text {
    color: #00d4ff;
    font-size: 1.1em;
    text-align: center;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Responsive Styles for Small Screens */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    h1 {
        font-size: 1.8em;
    }

    .subtitle {
        font-size: 0.9em;
        margin-bottom: 15px;
    }

    .controls {
        padding: 10px;
    }

    /* Fix results grid to stack vertically on small screens using flexbox for ordering */
    .results {
        display: flex !important;
        flex-direction: column;
        gap: 10px;
    }

    /* Order the children: Original Image (0), Convert Button (1), Converted Image (2) */
    .results > .image-container:first-of-type {
        order: 0;
    }

    #convertBtnContainer {
        order: 1;
    }

    .results > .image-container:last-of-type {
        order: 2;
    }

    /* Hide converted image section until image is loaded on small screens */
    .results > .image-container:last-of-type {
        display: none;
    }

    .results > .image-container:last-of-type.visible {
        display: block;
    }

    /* Fix image container and canvas overflow */
    .image-container {
        padding: 10px;
        margin-bottom: 15px;
    }

    .image-wrapper {
        min-height: 150px;
        overflow: hidden;
    }

    /* Fix canvas container overflow and fit to screen */
    #canvasContainer {
        max-width: 100%;
        width: 100%;
        overflow: hidden;
        margin: 0 !important;
        display: flex !important;
        justify-content: center;
        align-items: center;
    }

    #backgroundCanvas,
    #originalImage,
    #cropCanvas {
        max-width: 100% !important;
        max-height: 50vh !important;
        width: auto !important;
        height: auto !important;
        object-fit: contain;
    }

    /* Ensure converted image also fits */
    #convertedImage {
        max-width: 100% !important;
        max-height: 50vh !important;
        object-fit: contain;
    }

    #convertedImageBorder {
        padding: 10px !important;
        display: flex;
        justify-content: center;
    }

    /* Fix tabs overflow - make them scrollable or wrap */
    .tabs-header {
        flex-wrap: wrap;
        gap: 5px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .tab-button {
        padding: 8px 12px;
        font-size: 0.75em;
        white-space: nowrap;
        flex: 1 1 auto;
        min-width: fit-content;
    }

    /* Convert button rotation for vertical layout - only show when visible via inline style */
    #convertBtnContainer[style*="display: flex"],
    #convertBtnContainer[style*="display:flex"] {
        position: relative !important;
        left: auto !important;
        top: auto !important;
        transform: none !important;
        display: flex !important;
        justify-content: center;
        align-items: center;
        width: 100%;
        margin: 10px 0;
    }

    #convertBtn {
        transform: rotate(90deg);
    }

    #convertBtn:hover:not(:disabled) {
        transform: rotate(90deg) scale(1.1);
    }

    /* Fix dropzone sizing */
    .dropzone {
        margin-left: 0;
        padding: 20px 10px;
        max-width: 100%;
    }

    .dropzone-icon {
        font-size: 2em;
    }

    .dropzone-text {
        font-size: 1em;
    }

    .dropzone-subtext {
        font-size: 0.8em;
    }

    /* Form adjustments */
    .form-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* Fix dropdown/select styling for small screens */
    select {
        width: 100%;
        max-width: 100%;
        min-height: 48px;
        font-size: 18px !important; /* Larger font, prevents iOS zoom */
        padding: 12px 10px;
        box-sizing: border-box;
        line-height: 1.4;
        border-radius: 6px;
    }

    /* Style options for browsers that support it (desktop/some Android) */
    select option {
        font-size: 18px;
        padding: 14px 10px;
        line-height: 1.6;
        background-color: #0f3460;
        color: #eee;
    }

    /* Increase size attribute for multi-line visibility on supported browsers */
    select[multiple],
    select[size] {
        height: auto;
        min-height: 150px;
    }

    .form-group {
        width: 100%;
        max-width: 100%;
    }

    label {
        font-size: 0.85em;
    }

    /* Overlay adjustments */
    .overlay-content {
        width: 95%;
        max-height: 85vh;
    }
}

/* Even smaller screens */
@media (max-width: 480px) {
    h1 {
        font-size: 1.5em;
    }

    .tab-button {
        padding: 6px 8px;
        font-size: 0.7em;
    }

    .image-container h3 {
        font-size: 0.9em;
        height: auto;
        flex-wrap: wrap;
    }

    .icon-btn {
        font-size: 1em;
        padding: 0 5px;
        margin-left: 5px;
    }

    /* Ensure dropdowns fit on very small screens but remain readable */
    select {
        font-size: 16px !important; /* Keep 16px minimum to prevent iOS zoom */
        padding: 10px 8px;
        min-height: 44px;
    }

    select option {
        font-size: 16px;
        padding: 12px 8px;
    }

    .controls {
        padding: 8px;
    }

    .tab-content {
        padding: 0 5px;
    }
}
