body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #1a1a1a;
    color: #e0e0e0;
    font-size: 16px;
}

#header {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    border-bottom: 1px solid #333;
    gap: 20px;
    background-color: #2a2a2a;
    box-sizing: border-box;
}

#search-form {
    display: flex;
    flex: 1;
    gap: 10px;
    box-sizing: border-box;
}

#search-form input {
    flex: 1;
    padding: 8px;
    border: 1px solid #444;
    border-radius: 4px;
    background-color: #333;
    color: #e0e0e0;
    box-sizing: border-box;
    min-width: 0;
    height: 44px;
}

#search-form button {
    height: 44px;
    box-sizing: border-box;
}

#random-btn {
    background-color: #2a2a2a;
    border: 1px solid #444;
    padding: 8px;
    font-size: 20px;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    cursor: pointer;
    box-sizing: border-box;
}

#random-btn:hover {
    background-color: #3a3a3a;
    border-color: #555;
    text-decoration: none;
}

#user-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

#login-form {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-wrap: wrap;
    margin: 0px;
}

a {
    color: #4a9eff;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
    color: #6bb3ff;
}

button {
    cursor: pointer;
    font-family: inherit;
}

button.btn-primary {
    padding: 8px 16px;
    background-color: #0d6efd;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    min-height: 44px;
}

button.btn-primary:hover {
    background-color: #0b5ed7;
}

button.btn-danger {
    background-color: #dc3545;
    color: white;
}

button.btn-danger:hover {
    background-color: #c82333;
}

button.btn-secondary {
    background-color: #6c757d;
    color: white;
    cursor: not-allowed;
    opacity: 0.65;
}

button.btn-secondary:hover {
    background-color: #5a6268;
}

.search-results {
    display: flex;
    flex-wrap: wrap;
    padding: 20px;
    gap: 20px;
}

.search-results>div {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.search-results img {
    max-width: 45vw;
    max-height: 45vh;
    margin: 0;
    object-fit: contain;
    border: 1px solid #444;
    border-radius: 4px;
    background-color: #2a2a2a;
}

.main-image {
    max-width: 80vw;
    max-height: 80vh;
    object-fit: contain;
    border: 1px solid #444;
    border-radius: 4px;
    margin: 20px 0;
    background-color: #2a2a2a;
}

.similar-image {
    max-width: 30vw;
    max-height: 30vh;
    object-fit: contain;
    border: 1px solid #444;
    border-radius: 4px;
    background-color: #2a2a2a;
}

.similar-container {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 20px 0;
}

.similar-container>div {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.image-metadata {
    text-align: center;
    font-size: 0.9em;
    color: #999;
    margin: 0;
}

.image-controls {
    display: flex;
    flex-direction: row;
    gap: 5px;
    margin-top: 5px;
    align-items: center;
    position: relative;
}

.inline-details {
    display: block;
    width: 100%;
}

.inline-details summary {
    display: block;
    cursor: pointer;
    user-select: none;
    padding: 4px 10px;
    background-color: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 0.9em;
    color: #4a9eff;
    transition: background-color 0.2s;
    text-align: center;
}

.inline-details summary:hover {
    background-color: #3a3a3a;
    border-color: #555;
}

.inline-details[open] summary {
    background-color: #3a3a3a;
}

.details-content {
    position: absolute;
    top: 100%;
    left: 0;
    background-color: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 15px;
    margin-top: 5px;
    min-width: 300px;
    max-width: 400px;
    z-index: 100;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.details-content input[type="text"] {
    box-sizing: border-box;
}

.content-wrapper {
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

th,
td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #333;
}

th {
    background-color: #2a2a2a;
    font-weight: 600;
}

form {
    margin: 10px 0;
}

h1,
h2 {
    margin: 20px 0 10px 0;
    color: #f0f0f0;
}

textarea {
    width: 100%;
    min-height: 80px;
    padding: 8px;
    border: 1px solid #444;
    border-radius: 4px;
    font-family: inherit;
    margin: 10px 0;
    background-color: #333;
    color: #e0e0e0;
}

input[type="text"],
input[type="password"],
input[type="file"],
input[type="search"] {
    padding: 8px;
    border: 1px solid #444;
    border-radius: 4px;
    background-color: #333;
    color: #e0e0e0;
    font-size: 16px;
    margin-right: 10px;
}

/* Style the search input clear button for dark theme */
input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
    height: 16px;
    width: 16px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23e0e0e0"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>');
    background-size: 16px 16px;
    cursor: pointer;
}

input[type="search"]::-webkit-search-cancel-button:hover {
    opacity: 0.7;
}

input[type="file"]::file-selector-button {
    background-color: #0d6efd;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 10px;
}

input[type="file"]::file-selector-button:hover {
    background-color: #0b5ed7;
}

pre {
    background-color: #2a2a2a;
    color: #e0e0e0;
}

.mod-description-input {
    width: 300px;
    margin-right: 10px;
}

.welcome-image {
    max-width: 400px;
    width: 100%;
    height: auto;
    object-fit: contain;
    border: 1px solid #444;
    border-radius: 4px;
    margin: 20px 0 10px 0;
    background-color: #2a2a2a;
}

.welcome-quote {
    font-style: italic;
    text-align: center;
    margin: 10px 0;
    color: #e0e0e0;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    * {
        box-sizing: border-box;
    }

    body {
        font-size: 18px;
        overflow-x: hidden;
    }

    #header {
        flex-direction: column;
        padding: 15px;
        gap: 0px;
        align-items: stretch;
        width: 100%;
        max-width: 100vw;
    }

    #header>a {
        text-align: center;
        padding: 8px;
    }

    #search-form {
        width: 100%;
        flex-direction: row;
        gap: 8px;
        margin: 5px 0px;
    }

    #search-form input {
        flex: 1;
        min-width: 0;
        padding: 12px;
        font-size: 16px;
        height: 50px;
    }

    #search-form button {
        flex-shrink: 0;
        width: auto;
        padding: 12px 20px;
        height: 50px;
    }

    #random-btn {
        padding: 10px;
        width: 50px;
        height: 50px;
        font-size: 22px;
    }

    #user-controls {
        flex-direction: column;
        width: 100%;
        gap: 10px;
        align-items: stretch;
    }

    #user-controls>a,
    #user-controls>form {
        width: 100%;
    }

    #login-form {
        flex-direction: column;
        width: 100%;
        gap: 0;
        align-items: stretch;
        transition: gap 0.3s ease;
    }

    /* Add gap when form has focus or username has content */
    #login-form:focus-within,
    #login-form:has(input[type="text"]:not(:placeholder-shown)) {
        gap: 8px;
    }

    #login-form input[type="text"],
    #login-form input[type="password"] {
        width: 100%;
        margin-bottom: 0;
    }

    #login-form label {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        width: auto;
        flex-shrink: 0;
        white-space: nowrap;
        margin-bottom: 0;
        margin-top: 8px;
        transition: margin-top 0.3s ease;
    }

    /* Remove label top margin when password/button are shown */
    #login-form:focus-within label,
    #login-form:has(input[type="text"]:not(:placeholder-shown)) label {
        margin-top: 0;
    }

    #login-form label input[type="checkbox"] {
        width: auto;
        min-height: auto;
        margin: 0;
    }

    /* Hide password field and button when username is empty and unfocused */
    #login-form input[type="password"],
    #login-form button {
        max-height: 0;
        min-height: 0;
        opacity: 0;
        overflow: hidden;
        margin: 0 !important;
        padding: 0 !important;
        border: 0;
        transition: max-height 0.3s ease, opacity 0.3s ease, margin 0.3s ease, padding 0.3s ease, border 0.3s ease, min-height 0.3s ease;
    }

    /* Show password and button when username has content OR when form has focus */
    #login-form:focus-within input[type="password"],
    #login-form:focus-within button,
    #login-form input[type="text"]:not(:placeholder-shown)~input[type="password"],
    #login-form input[type="text"]:not(:placeholder-shown)~button {
        max-height: 200px;
        min-height: 44px;
        opacity: 1;
        margin-bottom: 0 !important;
        padding: 12px !important;
        border: 1px solid #444;
        transition: max-height 0.3s ease, opacity 0.3s ease, margin 0.3s ease, padding 0.3s ease, border 0.3s ease, min-height 0.3s ease;
    }

    /* Button needs no border */
    #login-form:focus-within button,
    #login-form input[type="text"]:not(:placeholder-shown)~button {
        border: none;
    }

    button.btn-primary {
        width: 100%;
        padding: 12px 16px;
        font-size: 16px;
        min-height: 44px;
    }

    .search-results {
        flex-direction: column;
        align-items: center;
        padding: 15px;
        gap: 20px;
    }

    .search-results>div {
        width: 100%;
    }

    .search-results img {
        max-width: 90vw;
        max-height: 60vh;
    }

    .main-image {
        max-width: 95vw;
        max-height: 70vh;
    }

    .similar-container {
        flex-direction: column;
        align-items: center;
        gap: 20px;
    }

    .similar-container>div {
        width: 100%;
    }

    .similar-image {
        max-width: 90vw;
        max-height: 50vh;
    }

    .image-metadata {
        font-size: 1em;
    }

    .details-content {
        position: static;
        min-width: auto;
        max-width: 100%;
        width: 100%;
    }

    .content-wrapper {
        padding: 15px;
    }

    h1 {
        font-size: 1.75em;
    }

    h2 {
        font-size: 1.5em;
    }

    table {
        font-size: 14px;
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    th,
    td {
        padding: 8px 6px;
    }

    textarea {
        font-size: 16px;
        padding: 12px;
    }

    input[type="text"],
    input[type="password"],
    input[type="file"],
    input[type="search"] {
        padding: 12px;
        font-size: 16px;
        min-height: 44px;
        margin-bottom: 10px;
        width: 100%;
        box-sizing: border-box;
    }

    .mod-description-input {
        width: 100%;
        margin-right: 0;
        margin-bottom: 10px;
    }

    form {
        width: 100%;
    }

    a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    .welcome-image {
        max-width: 90vw;
    }
}

/* Extra small devices (phones in portrait) */
@media (max-width: 480px) {
    body {
        font-size: 16px;
    }

    #header {
        padding: 12px;
        gap: 12px;
    }

    .content-wrapper {
        padding: 12px;
    }

    h1 {
        font-size: 1.5em;
    }

    h2 {
        font-size: 1.3em;
    }

    table {
        font-size: 12px;
    }

    th,
    td {
        padding: 6px 4px;
    }
}

/* X Compose Styles */
#x-compose-root * {
    box-sizing: border-box;
}

/* Add to X button */
.add-to-x-btn {
    background-color: black;
    color: white;
    border: 1px solid #536471;
    border-radius: 9999px;
    padding: 6px 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: auto;
    font-size: 14px;
}

.add-to-x-btn:hover {
    background-color: #1a1a1a;
}

.add-to-x-btn img {
    background: transparent !important;
    filter: brightness(0) invert(1);
    border: none;
}

/* Image grid layouts */
.x-grid {
    display: grid;
    gap: 2px;
    width: 100%;
    aspect-ratio: 16/9;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid #cfd9de;
}

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

.x-grid-2 {
    grid-template-columns: 1fr 1fr;
}

.x-grid-3 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.x-grid-3 .x-tile:nth-child(1) {
    grid-row: 1 / 3;
}

.x-grid-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.x-tile {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #333;
}

.x-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Overlay buttons (remove, reorder) */
.x-overlay-btn {
    position: absolute;
    height: 28px;
    width: 28px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    font-size: 16px;
    transition: background 0.2s;
}

.x-overlay-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}

.x-remove {
    top: 8px;
    right: 8px;
}

.x-move-left {
    bottom: 8px;
    left: 8px;
}

.x-move-right {
    bottom: 8px;
    right: 8px;
}

/* Composer dialog inputs */
#x-compose-root textarea {
    width: 100%;
    height: 80px;
    margin-bottom: 10px;
    padding: 10px;
    border: 1px solid #333;
    border-radius: 8px;
    resize: none;
    background: #000;
    color: #e7e9ea;
    font-family: inherit;
    min-height: 80px;
}

#x-compose-root input[type="text"] {
    width: 100%;
    margin-bottom: 16px;
    padding: 10px;
    border: 1px solid #333;
    border-radius: 8px;
    background: #000;
    color: #e7e9ea;
    font-size: 16px;
}

/* Compose modal overlay */
.x-compose-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Compose modal dialog */
.x-compose-dialog {
    background: #000;
    color: #e7e9ea;
    width: 90%;
    max-width: 600px;
    border-radius: 16px;
    padding: 20px;
    border: 1px solid #333;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

/* Compose modal header */
.x-compose-header {
    margin-bottom: 16px;
}

.x-compose-header h2 {
    margin: 0;
    font-size: 20px;
    color: #e7e9ea;
}

/* Close button */
.x-compose-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #e7e9ea;
    padding: 0;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
}

/* Floating bubble indicator */
.x-compose-bubble {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #1d9bf0;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 9999px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    font-weight: bold;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Compose buttons */
.x-compose-btn-clear {
    background: transparent;
    border: 1px solid #536471;
    color: #e7e9ea;
    padding: 8px 16px;
    border-radius: 9999px;
    cursor: pointer;
    transition: background 0.2s;
}

.x-compose-btn-clear:hover {
    background: rgba(239, 243, 244, 0.1);
}

.x-compose-btn-post {
    background: #1d9bf0;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 9999px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.x-compose-btn-post:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Helper text */
.x-compose-help {
    margin-bottom: 16px;
    font-size: 13px;
    color: #71767b;
}

.x-compose-help p {
    margin: 0 0 8px 0;
}

/* Character counter */
.x-compose-counter {
    color: #71767b;
}

.x-compose-counter.over-limit {
    color: #f4212e;
}

/* Mode selector */
.x-mode-selector {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    padding: 10px;
    background: rgba(239, 243, 244, 0.05);
    border-radius: 8px;
    border: 1px solid #333;
}

.x-mode-selector label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
    color: #e7e9ea;
}

.x-mode-selector input[type="radio"] {
    margin: 0;
    width: 18px;
    height: 18px;
    accent-color: #1d9bf0;
    cursor: pointer;
}

/* X Compose Mobile Styles */
@media (max-width: 768px) {

    /* Full screen modal on mobile */
    .x-compose-dialog {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        padding: 16px;
        border: none;
    }

    .x-compose-overlay {
        align-items: stretch;
        justify-content: stretch;
    }
}