@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&display=swap');

body {
    font-family: 'Inter', sans-serif;
    background-color: #f8fafc;
    background-image: radial-gradient(at 0% 0%, rgba(229, 231, 235, 0.5) 0px, transparent 50%), linear-gradient(to bottom right, #f9fafb, #f3f4f6);
    background-size: 100% 100%;
    background-attachment: fixed;
    overscroll-behavior: none;
}

html.dark body {
    background-color: #0f172a;
    background-image: radial-gradient(at 0% 0%, rgba(30, 41, 59, 0.5) 0px, transparent 50%), linear-gradient(to bottom right, #0f172a, #1e293b);
}

.custom-scroll::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}

.glass-panel {
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.8);
}

html.dark .glass-panel {
    background: rgba(30, 41, 59, 0.94);
    border-color: rgba(255, 255, 255, 0.08);
}

#mobileControls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 75dvh;
    z-index: 40;
    transform: translateY(calc(100% - 64px));
    transition: transform 0.5s cubic-bezier(0.19, 1, 0.22, 1);
    will-change: transform;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 24px 24px 0 0;
}

html.dark #mobileControls {
    border-top-color: rgba(255, 255, 255, 0.1);
}

@media (min-width: 768px) {
    #mobileControls {
        position: relative;
        height: 100%;
        transform: none !important;
        z-index: 20;
        border-radius: 0;
        border-top: none;
    }
}

#mobileControls.expanded {
    transform: translateY(0);
}

#mobileBackdrop {
    transition: opacity 0.4s ease;
}

#mobileBackdrop.hidden-backdrop {
    opacity: 0;
    pointer-events: none;
}

#floatingGenerateBtn {
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    background: linear-gradient(135deg, #1f2937 0%, #000000 100%);
    box-shadow: 0 8px 20px -4px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
    z-index: 50;
}

html.dark #floatingGenerateBtn {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    box-shadow: 0 8px 20px -4px rgba(255, 255, 255, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.1) inset;
}

#floatingGenerateBtn:active {
    transform: scale(0.9);
}

.drawer {
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    will-change: transform;
}

.drawer-open {
    transform: translateX(0);
}

.drawer-closed {
    transform: translateX(-100%);
}

.art-input {
    transition: all 0.3s;
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid #e5e7eb;
}

.art-input:focus {
    background: #fff;
    border-color: #9ca3af;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

html.dark .art-input {
    background: rgba(30, 41, 59, 0.6);
    border-color: #334155;
    color: #e2e8f0;
}

html.dark .art-input:focus {
    background: #1e293b;
    border-color: #64748b;
}

.switch-bg {
    position: absolute;
    height: calc(100% - 8px);
    width: calc(50% - 4px);
    top: 4px;
    left: 4px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 0;
    border: 1px solid rgba(0, 0, 0, 0.02);
}

html.dark .switch-bg {
    background: #334155;
    border-color: transparent;
}

#model-v4:checked~.switch-bg {
    transform: translateX(100%);
}

input[type="radio"]:checked+label {
    color: #111827;
}

html.dark input[type="radio"]:checked+label {
    color: #fff;
}

.view-toggle {
    background: rgba(243, 244, 246, 0.8);
    border: 1px solid rgba(229, 231, 235, 0.8);
    border-radius: 99px;
    padding: 3px;
    display: flex;
    position: relative;
    width: 140px;
}

html.dark .view-toggle {
    background: rgba(30, 41, 59, 0.8);
    border-color: rgba(51, 65, 85, 0.8);
}

.view-toggle button {
    position: relative;
    z-index: 2;
    flex: 1;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    transition: color 0.2s;
    padding: 4px 0;
}

.view-toggle button.active {
    color: #111827;
}

html.dark .view-toggle button {
    color: #94a3b8;
}

html.dark .view-toggle button.active {
    color: #fff;
}

.view-toggle-bg {
    position: absolute;
    top: 3px;
    bottom: 3px;
    left: 3px;
    width: calc(50% - 3px);
    background: white;
    border-radius: 99px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
}

html.dark .view-toggle-bg {
    background: #475569;
}

.view-toggle[data-state="history"] .view-toggle-bg {
    transform: translateX(100%);
}

.loader {
    width: 20px;
    height: 20px;
    border: 2px solid currentColor;
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    animation: rotation 0.8s linear infinite;
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.img-transition {
    transition-property: opacity, transform;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 500ms;
}

#adminControls {
    transition: all 0.3s;
    overflow: hidden;
}

#adminControls.hidden {
    max-height: 0;
    opacity: 0;
    margin: 0;
    padding: 0;
}

#adminControls:not(.hidden) {
    max-height: 200px;
    opacity: 1;
}

/* --- Inpaint Editor --- */
#inpaintModal {
    transition: opacity 0.3s, visibility 0.3s;
    background: #000;
}
#inpaintModal.modal-visible {
    opacity: 1;
    visibility: visible;
}
#inpaintModal.modal-hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}
.inpaint-canvas-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    overflow: hidden;
    background: #020617; /* 更深的背景突出画布 */
}
@media (max-width: 768px) {
    .inpaint-canvas-wrap {
        padding: 50px 40px 70px 40px; /* 顶部留出返回按钮, 两边留出侧边栏, 底部留出抽屉 */
    }
}
.inpaint-canvas-wrap canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: calc(100% - 40px);
    max-height: calc(100% - 40px);
    object-fit: contain;
    box-shadow: 0 0 120px rgba(0,0,0,0.9);
}
@media (max-width: 768px) {
    .inpaint-canvas-wrap canvas {
        max-width: calc(100% - 80px); /* 对应 padding 左右 40+40 */
        max-height: calc(100% - 120px); /* 对应 padding 顶 50 + 底 70 */
    }
}
#inpaintMaskCanvas {
    cursor: none;
    z-index: 2;
    opacity: 0.5;
}
#inpaintBaseCanvas {
    z-index: 1;
}
.inpaint-sidebar {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 20px;
    z-index: 100;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.inpaint-sidebar-left { left: 16px; }
.inpaint-sidebar-right { right: 16px; }

@media (max-width: 768px) {
    .inpaint-sidebar-left { left: 10px; }
    .inpaint-sidebar-right { right: 10px; }
    .inpaint-sidebar {
        padding: 4px;
        gap: 8px;
        border-radius: 16px;
        background: rgba(15, 23, 42, 0.7);
    }
    .inpaint-sidebar button {
        width: 46px !important;
        height: 46px !important;
        border-radius: 12px !important;
    }
}

.inpaint-sidebar button {
    width: 50px;
    height: 50px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.02);
    border: 1px solid rgba(255,255,255,0.03);
    color: rgba(255,255,255,0.3);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.inpaint-sidebar button:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}
.inpaint-sidebar button.tool-active {
    background: #2563eb;
    color: #fff;
    border-color: #3b82f6;
    box-shadow: 0 0 20px rgba(37, 99, 235, 0.4);
}

/* --- Inpaint Mobile Drawer --- */
#inpaintMobileDrawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border-top: 1px solid rgba(255,255,255,0.1);
    border-radius: 32px 32px 0 0;
    z-index: 150;
    transform: translateY(calc(100% - 70px));
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    padding: 0 24px 34px 24px;
}
#inpaintMobileDrawer.expanded {
    transform: translateY(0);
}
.drawer-handle {
    width: 40px;
    height: 4px;
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
    margin: 12px auto 20px auto;
}
.brush-size-slider {
    width: 140px;
    height: 4px;
    border-radius: 2px;
    accent-color: #3b82f6;
    background: rgba(255,255,255,0.05);
    appearance: none;
}
.brush-cursor {
    position: fixed;
    border: 1.5px solid #fff;
    box-shadow: 0 0 0 1.5px rgba(0,0,0,0.5);
    border-radius: 50%;
    pointer-events: none;
    z-index: 10000;
    display: none;
    mix-blend-mode: difference;
    transform: translate(0, 0);
    will-change: left, top, width, height;
}

/* --- Universal Modal & Lightbox Styles --- */
.custom-modal-backdrop {
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.custom-modal-content {
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-active {
    opacity: 1 !important;
    pointer-events: auto !important;
}
.modal-active .custom-modal-backdrop {
    opacity: 1 !important;
}
.modal-active .custom-modal-content {
    transform: scale(1) !important;
    opacity: 1 !important;
}
@media (min-width: 768px) {
    .modal-active #lightboxSidebar {
        transform: translate(0, 0) !important;
    }
}

/* Lightbox Sidebar Mobile bottom drawer behavior */
@media (max-width: 768px) {
    #lightboxSidebar {
        position: absolute !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 70dvh !important;
        z-index: 50 !important;
        border-radius: 2rem 2rem 0 0 !important;
        transform: translateY(calc(100% - 50px)) !important;
        transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1) !important;
    }
    #lightboxSidebar.expanded {
        transform: translateY(0) !important;
    }
}

/* --- Low Performance Mode (低性能模式) Override Rules --- */
html.low-perf body {
    background-image: none !important;
    background-color: #f8fafc !important;
}
html.low-perf.dark body {
    background-image: none !important;
    background-color: #0f172a !important;
}
html.low-perf * {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
    text-shadow: none !important;
    transition-duration: 0s !important;
    animation-duration: 0s !important;
    will-change: auto !important;
}
html.low-perf .glass-panel,
html.low-perf .custom-modal-content {
    background: rgba(255, 255, 255, 0.98) !important;
    border-color: rgba(0, 0, 0, 0.1) !important;
}
html.low-perf.dark .glass-panel,
html.low-perf.dark .custom-modal-content {
    background: rgba(30, 41, 59, 0.98) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}
html.low-perf #mobileControls,
html.low-perf #lightboxSidebar {
    transition: none !important;
}

/* --- 历史图库图片单张删除按钮样式 --- */
.delete-item-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border-radius: 9999px;
    transition: all 0.2s ease;
    z-index: 10;
    opacity: 1;
    cursor: pointer;
}

.delete-item-btn:hover {
    background-color: #ef4444 !important;
    transform: scale(1.08);
}

.delete-item-btn:active {
    transform: scale(0.95);
}

/* 桌面端默认隐藏，鼠标悬停时才显示 */
@media (min-width: 768px) {
    .delete-item-btn {
        opacity: 0;
        pointer-events: none;
    }
    .gallery-item:hover .delete-item-btn {
        opacity: 1;
        pointer-events: auto;
    }
}
