:root {
    --bg-color: #f4f7f8;
    --card-bg: #ffffff;
    --text-color: #141414;
    --text-muted: #676767;
    --border-color: #d1dcde;
    --btn-bg: #325f6b;
    --input-bg: #ffffff;
    --input-border: #b8c9cc;
    --link-color: #325f6b;
    --tag-bg: #f0f0f0;
    --hover-bg: rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-color: #141414;
        --card-bg: #1f1f1f;
        --text-color: #ffffff;
        --text-muted: #676767;
        --border-color: #323232;
        --btn-bg: #539fb3;
        --input-bg: #1f1f1f;
        --input-border: #323232;
        --link-color: #98c5d1;
        --tag-bg: #2a2a2a;
        --hover-bg: rgba(255, 255, 255, 0.06);
    }
}

:root[data-theme="dark"] {
    --bg-color: #141414;
    --card-bg: #1f1f1f;
    --text-color: #ffffff;
    --text-muted: #676767;
    --border-color: #323232;
    --btn-bg: #539fb3;
    --input-bg: #1f1f1f;
    --input-border: #323232;
    --link-color: #98c5d1;
    --tag-bg: #2a2a2a;
    --hover-bg: rgba(255, 255, 255, 0.06);
}

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

body {
    font-family: sans-serif;
    color: var(--text-color);
    background: var(--bg-color);
}

/* Common Header & Breadcrumb */
.header {
    margin-bottom: 0;
}

.site-title, .gallery-title {
    font-size: 16px;
    margin: 0;
    font-weight: bold;
    white-space: nowrap;
}

.site-title a, .gallery-title a {
    color: inherit;
    text-decoration: none;
}

.site-title a:hover, .gallery-title a:hover {
    text-decoration: underline;
}

.hover-underline {
    text-decoration: none;
}

.hover-underline:hover {
    text-decoration: underline;
}

.sep {
    color: var(--text-muted);
    font-weight: normal;
    margin: 0 4px;
}

/* Common Components: Filters, Selects, Checkboxes */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
}

.filter-label {
    font-size: 14px;
    font-weight: bold;
    color: var(--text-color);
}

.filter-select {
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    outline: none;
}

.setting-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.setting-checkbox input {
    margin: 0;
    width: auto;
}

.settings-link, .action-link {
    font-size: 14px;
    font-weight: normal;
    color: var(--text-muted);
    cursor: pointer;
    text-decoration: none;
}

.settings-link:hover, .action-link:hover {
    text-decoration: underline;
}

.artwork-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    align-items: center;
}

/* Make the admin-only deletion form align with the neighboring text links. */
.artwork-delete-form {
    display: inline;
    margin: 0;
}

.action-link-button {
    appearance: none;
    padding: 0;
    border: 0;
    background: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: normal;
    line-height: normal;
    color: inherit;
    cursor: pointer;
}

.artwork-dates {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-top: 10px;
    font-size: 14px;
    color: var(--text-muted);
}

.date-row {
    color: var(--text-muted);
}

.date-label {
    font-weight: normal;
    color: var(--text-muted);
}

/* Viewer action links use the primary text color while dates stay muted. */
#settings-toggle-rec,
.artwork-actions .action-link {
    color: var(--text-color);
}

.settings-container {
    margin-top: 16px;
}

.admin-public-form {
    margin-top: 10px;
}

.admin-form {
    display: grid;
    gap: 12px;
}

.admin-form .home-input {
    margin: 0;
}

.admin-form .btn-gallery {
    justify-self: start;
}

.admin-logout-form {
    margin-top: 16px;
}

.admin-error {
    margin-top: 12px;
    color: var(--text-color);
}

/* Badges & Blur */
.top-left-badges, .rec-top-left-badges {
    position: absolute;
    top: 6px;
    left: 6px;
    display: flex;
    gap: 4px;
    pointer-events: none;
}

.r18-badge, .ai-badge, .sensitive-badge, .rec-r18-badge, .rec-ai-badge, .rec-sensitive-badge {
    color: #fff;
    padding: 2px 6px;
    font-size: 12px;
    font-weight: bold;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
}

.r18-badge, .rec-r18-badge {
    background-color: #ff2d55;
}

.sensitive-badge, .rec-sensitive-badge {
    background-color: #ff9500;
}

.ai-badge, .rec-ai-badge {
    background-color: #007aff;
}

.blurred {
    filter: blur(20px);
    transition: filter 0.3s ease;
}

.grid-item:hover .blurred, .rec-item:hover .blurred {
    filter: blur(0px);
}

/* Homepage Styles */
.home-body {
    max-width: 480px;
    margin: 40px auto;
    padding: 0 16px;
    text-align: left;
}

.home-box {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    background: var(--card-bg);
}

.home-box h2 {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.home-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
    margin: 16px 0;
    border-radius: 6px;
    border: 1px solid var(--input-border);
    font-size: 16px;
    font-family: inherit;
    background: var(--input-bg);
    color: var(--text-color);
}

.btn-primary {
    padding: 10px 20px;
    background: var(--btn-bg);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
}

.btn-gallery {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-weight: bold;
    font-family: inherit;
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-gallery:hover {
    background: var(--hover-bg);
}

.homepage-footer-row {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    font-size: 14px;
    color: var(--text-muted);
}

.homepage-footer-box {
    margin-top: 24px;
    padding: 16px 24px;
}

.homepage-footer-box .homepage-footer-row {
    margin-top: 0;
}

.homepage-footer-row .settings-link {
    color: var(--text-color);
}

.footer-credit-content {
    margin-top: 16px;
    font-size: 12px;
}

.stats-details {
    display: grid;
    gap: 4px;
    font-size: 14px;
    color: var(--text-color);
    line-height: 1.25;
}

.stats-details strong {
    color: var(--text-color);
    font-weight: normal;
}

.credit-text, .footer-text {
    color: var(--text-muted);
}

.credit-text a, .footer-text a {
    color: inherit;
    text-decoration: none;
}

.credit-text a:hover, .footer-text a:hover {
    text-decoration: underline;
}

/* Gallery Styles */
.gallery-body {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 16px;
}

/* Fetching Page Styles */
.fetching-wrapper {
    max-width: 480px;
    margin: 40px auto;
    padding: 0 16px;
}

.fetching-content {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.fetching-thumb {
    width: 140px;
    height: 140px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--border-color);
    flex-shrink: 0;
}

.fetching-info {
    flex-grow: 1;
}

.fetching-artist-name {
    color: var(--text-muted);
    font-size: 14px;
    text-decoration: none;
}

.fetching-status-text {
    font-size: 14px;
    color: var(--text-muted);
}

.gallery-main {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    background: var(--card-bg);
}

.top-controls-wrapper {
    margin-bottom: 20px;
}

.top-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.search-and-toggle {
    display: flex;
    gap: 8px;
    align-items: center;
}

.filter-toggle-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: background 0.2s, color 0.2s;
}

.filter-toggle-btn:hover {
    background: rgba(128, 128, 128, 0.1);
}

.filter-toggle-btn.active {
    background: var(--text-color);
    color: var(--bg-color);
}

.filters-dropdown {
    margin-top: 16px;
}

.filters-dropdown .filters {
    justify-content: flex-end;
}

.grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
}

.grid-item {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    display: block;
}

.grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 24px 8px 8px;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    opacity: 0;
    transition: opacity 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.grid-item:hover .overlay {
    opacity: 1;
}

.overlay-title {
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.overlay-artist {
    color: rgba(255,255,255,0.7);
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.page-count, .rec-page-count {
    position: absolute;
    top: 6px;
    right: 6px;
    background-color: rgba(0, 0, 0, 0.65);
    color: #fff;
    padding: 2px 6px;
    font-size: 12px;
    font-weight: bold;
    border-radius: 4px;
    pointer-events: none;
}

.pagination-container {
    display: flex;
    justify-content: center;
    margin-top: 20px;
}

.pagination {
    display: flex;
    gap: 6px;
}

.page-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s;
}

.page-link:hover {
    background: var(--hover-bg);
}

.page-link.active {
    background: #ffffff;
    color: #141414;
    border-color: #ffffff;
    font-weight: bold;
}

.page-dots {
    color: var(--text-muted);
    font-size: 16px;
    font-weight: bold;
    padding: 0 4px;
    display: flex;
    align-items: center;
    height: 32px;
    letter-spacing: 1px;
}

.empty {
    text-align: center;
    color: var(--text-muted);
    padding: 60px 0;
    font-size: 15px;
}

.search-container { position: relative; }
.search-form { margin: 0; }
.search-input {
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    width: 220px;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-top: 4px;
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
    width: 220px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
}
.autocomplete-item {
    padding: 6px 8px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--link-color); color: #fff; }

/* Viewer Styles */
.viewer-body {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px 16px;
}

.artwork-card { 
    border: 1px solid var(--border-color); 
    border-radius: 16px; 
    padding: 20px; 
    background: var(--card-bg);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.artwork-content {
    display: flex;
    gap: 24px;
    align-items: flex-start;
    width: 100%;
}

.main-viewer {
    flex: 1;
    min-width: 0;
}

.divider {
    width: 1px;
    background-color: var(--border-color);
    align-self: stretch;
    margin: 16px 0;
    flex-shrink: 0;
}

.recommendations-sidebar {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.rec-title {
    font-size: 18px;
    font-weight: bold;
    margin: 0 0 12px 0;
    color: var(--text-color);
}

.media-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.media-item {
    width: 100%;
    height: auto;
    border-radius: 8px;
    display: block;
}

.info-section {
    margin-top: 16px;
}

.title {
    font-size: 20px;
    margin: 0 0 12px 0;
    word-break: break-word;
}

.title a {
    color: var(--text-color);
    text-decoration: none;
}

.title a:hover {
    text-decoration: underline;
}

.artist-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}

.avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
}

.artist-name {
    color: var(--text-color);
    font-size: 14px;
    text-decoration: none;
}

.tags, .tag-list, .badges-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.tag-item, .tag-badge {
    display: inline-flex;
    align-items: center;
    background: var(--tag-bg);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 12px;
    font-weight: bold;
    text-decoration: none;
    color: var(--text-color);
}

.tag-item:hover, .tag-badge:hover {
    opacity: 0.8;
}

.tag-orig {
    font-weight: bold;
}

.tag-trans, .tag-translated {
    color: var(--text-muted);
    font-weight: normal;
    margin-left: 4px;
}

.rec-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.rec-item {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

/* Loading Card (index.php) */
#loading-card {
    display: none;
    margin-top: 24px;
    padding: 16px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 100%;
}

.loading-content {
    display: flex;
    gap: 16px;
    align-items: center;
}

.loading-thumb {
    width: 60px;
    height: 60px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--border-color);
    flex-shrink: 0;
    display: none;
}

.loading-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.loading-title {
    font-size: 16px;
    font-weight: bold;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

.loading-artist {
    font-size: 14px;
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.loading-status {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.loading-cancel-btn {
    align-self: center;
    background: transparent;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    font-size: 14px;
    border-radius: 4px;
    cursor: pointer;
}

.loading-cancel-btn:hover {
    background: var(--hover-bg);
}

.rec-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.rec-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px 6px 6px;
    background: linear-gradient(transparent, rgba(0,0,0,0.75));
    opacity: 0;
    transition: opacity 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.rec-item:hover .rec-overlay {
    opacity: 1;
}

.rec-item-title {
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rec-item-artist {
    color: rgba(255,255,255,0.7);
    font-size: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gallery-context {
    margin-bottom: 24px;
}

.context-title {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: var(--text-color);
}

.action-sep {
    margin: 0 4px;
}

.context-stats {
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

.viewer-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 16px;
}

.header-nav-link {
    color: var(--text-color);
    font-size: 14px;
}

.rec-box {
    margin-top: 24px;
    padding: 20px;
}

.home-rec-title {
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 14px;
}

.rec-slideshow-container {
    display: flex;
    gap: 16px;
}

.slideshow-col {
    flex: 1;
    min-width: 0;
}

.slideshow-col .slideshow-wrapper {
    grid-template-columns: 1fr;
    position: relative;
    width: 100%;
    aspect-ratio: 1/1;
}

.credit-link {
    color: inherit;
}

/* Media Queries */
@media (max-width: 1200px) {
    .grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

@media (max-width: 900px) {
    .grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 820px) {
    .viewer-body {
        max-width: 500px;
        padding-bottom: 80px;
    }
    .artwork-content {
        flex-direction: column;
        gap: 16px;
    }
    .divider {
        width: 100%;
        height: 1px;
        margin: 8px 0;
    }
    .recommendations-sidebar {
        width: 100%;
    }
}

@media (max-width: 720px) {
    .gallery-body {
        padding-bottom: 80px;
    }
    .grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .top-controls {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 12px;
    }
    .search-and-toggle {
        justify-content: center;
        width: 100%;
    }
    .filters-dropdown .filters {
        justify-content: center;
    }
    .search-container {
        flex-basis: auto;
        display: flex;
        justify-content: center;
    }
    .viewer-header {
        justify-content: space-between;
    }
}

.settings-container .filters {
    justify-content: flex-start;
}

/* Helper & Layout Classes */
.d-none { display: none !important; }
.w-100 { width: 100% !important; }
.mb-0 { margin-bottom: 0 !important; }
.mt-4 { margin-top: 4px !important; }
.mt-8 { margin-top: 8px !important; }
.mb-8 { margin-bottom: 8px !important; }
.mb-10 { margin-bottom: 10px !important; }
.mt-12 { margin-top: 12px !important; }
.mb-12 { margin-bottom: 12px !important; }
.mb-14 { margin-bottom: 14px !important; }
.mt-16 { margin-top: 16px !important; }
.mb-16 { margin-bottom: 16px !important; }
.gap-8 { gap: 8px !important; }
.text-muted { color: var(--text-muted); }
.text-muted-fallback { color: var(--text-muted, #888); }
.text-decoration-none { text-decoration: none !important; }
.flex-column { flex-direction: column !important; }
.d-flex { display: flex !important; }
.justify-between { justify-content: space-between !important; }
.align-baseline { align-items: baseline !important; }

/* Specific Component Classes */
.error-code { font-size: 24px; font-weight: 700; margin: 0; line-height: 1; }
.error-message { margin-top: 12px; margin-bottom: 16px; color: var(--text-muted); font-size: 14px; }
.home-button-group { display: flex; gap: 8px; margin-bottom: 8px; }
.recent-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.fetching-container { display: flex; flex-direction: column; width: 100%; }
.error-actions { display: flex; gap: 8px; }
