:root {
    --bg-dark: #0a0c10;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-edge: rgba(255, 255, 255, 0.2);
    --primary: #4f46e5;
    --primary-hover: #6366f1;
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --accent: #ff4400;
    --radius: 12px;
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.8);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    padding: 1rem 2rem;
    text-align: center;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0%, transparent 100%);
    z-index: 10;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    background: linear-gradient(to right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

header p {
    font-size: 0.8rem;
    color: var(--text-dim);
}

main {
    flex: 1;
    overflow: hidden;
}

.editor-container {
    display: flex;
    height: 100%;
}

/* Canvas Wrapper */
.canvas-wrapper {
    flex: 1;
    background: radial-gradient(circle at center, #1e293b 0%, #0a0c10 100%);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: default;
}

.canvas-wrapper.active {
    background: radial-gradient(circle at center, #312e81 0%, #0a0c10 100%);
}

canvas {
    max-width: 95%;
    max-height: 95%;
    box-shadow: var(--shadow);
    border-radius: 4px;
    /* 照片通常边缘锋利，给一点点圆角示意即可 */
}

#bg-canvas {
    z-index: 1;
}

#overlay-canvas {
    position: absolute;
    z-index: 2;
    pointer-events: auto;
}

/* Empty State */
.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 5;
    transition: opacity 0.3s ease;
}

.canvas-wrapper.has-content .empty-state {
    opacity: 0;
    pointer-events: none;
}

.empty-state-content .icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 1rem;
    filter: drop-shadow(0 0 20px var(--primary));
    animation: pulse 2s infinite;
}

.empty-state-content p {
    font-size: 1.2rem;
    font-weight: 600;
}

.empty-state-content small {
    color: var(--text-dim);
}

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

    50% {
        transform: scale(1.05);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        opacity: 0.8;
    }
}

/* Sidebar Controls */
.sidebar-controls {
    width: 360px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    z-index: 20;
    overflow-y: auto;
}

.sidebar-section {
    padding: 1.5rem;
    border-bottom: 1px solid var(--glass-border);
}

.section-title {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    margin-bottom: 1rem;
}

/* Upload Cards */
.upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.upload-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px dashed var(--glass-border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--primary);
}

.card-icon {
    font-size: 1.5rem;
    display: block;
    margin-bottom: 0.5rem;
}

.upload-card p {
    font-size: 0.75rem;
    font-weight: 500;
}

/* Control Grid */
.control-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-item.full {
    grid-column: span 2;
}

.control-grid.secondary {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.flex-center {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.val-badge {
    background: var(--primary);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    min-width: 38px;
    text-align: center;
}

/* Layer Switcher */
.layer-switcher {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    padding: 2px;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
}

.layer-btn {
    flex: 1;
    padding: 0.5rem;
    font-size: 0.75rem;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.layer-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.4);
}

/* Component Blocks */
.component-block {
    margin-top: 1.5rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.component-header {
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.03);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.component-header label.main-label {
    color: var(--text-main);
    font-size: 0.85rem;
    font-weight: 600;
}

.component-content {
    padding: 1rem;
}

select,
input[type="text"],
input[type="number"] {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.5rem;
    color: var(--text-main);
    font-size: 0.85rem;
    width: 100%;
    outline: none;
    transition: border-color 0.2s;
}

select:focus,
input[type="text"]:focus,
input[type="number"]:focus {
    border-color: var(--primary);
}

input[type="color"] {
    width: 100%;
    height: 38px;
    background: none;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    cursor: pointer;
}

/* Range Input Customization */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--text-main);
    border: 2px solid var(--primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

/* Switch styling */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border-radius: 24px;
}

.switch .slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

/* Export Button */
.sidebar-footer {
    padding: 1.5rem;
    margin-top: auto;
}

.export-button {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary) 0%, #6d28d9 100%);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}

.export-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.6);
}

.export-button:active {
    transform: translateY(0);
}

/* Responsive Media Queries */
@media (max-width: 1024px) {
    .sidebar-controls {
        width: 300px;
    }
}

@media (max-width: 768px) {
    body {
        overflow: auto;
    }

    #app {
        height: auto;
    }

    .editor-container {
        flex-direction: column;
    }

    .canvas-wrapper {
        min-height: 50vh;
        width: 100%;
    }

    .sidebar-controls {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--glass-border);
        overflow-y: visible;
    }

    .sidebar-controls {
        backdrop-filter: none;
        /* 移动端背景可适当简化以提升流畅度 */
        background: #0f172a;
    }

    /* 针对移动端增大触控热区 */
    input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }

    select,
    input[type="text"],
    input[type="number"],
    .upload-card {
        min-height: 44px;
    }
}

/* --- Modal Styles --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    width: 95%;
    max-width: 500px;
    padding: 2.5rem;
    text-align: center;
    position: relative;
    transform: translateY(20px);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal.active .modal-content {
    transform: translateY(0);
}

.close-modal {
    position: absolute;
    top: 1rem;
    right: 1.2rem;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.8rem;
    cursor: pointer;
    transition: color 0.2s;
}

.close-modal:hover {
    color: var(--text-main);
}

.modal h3 {
    margin-bottom: 0.5rem;
    font-size: 1.8rem;
    background: linear-gradient(135deg, #fff 0%, #aaa 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.modal-desc {
    color: var(--text-dim);
    font-size: 1rem;
    margin-bottom: 2rem;
}

.donation-tabs {
    display: flex;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.3rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
}

.tab-btn {
    flex: 1;
    padding: 0.8rem;
    border: none;
    background: none;
    color: var(--text-dim);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 9px;
    transition: all 0.3s;
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.qr-container {
    width: 350px;
    height: 350px;
    margin: 0 auto;
    background: white;
    padding: 12px;
    border-radius: 16px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

#qr-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: none;
}

#qr-image.loaded {
    display: block;
}

.qr-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 0.8rem;
}

.donate-note {
    margin-top: 1.5rem;
    font-size: 0.8rem;
    color: var(--text-dim);
    font-style: italic;
}

.donate-btn {
    margin-top: 1rem;
    width: 100%;
    justify-content: center;
    font-weight: bold;
    background: rgba(255, 120, 0, 0.1);
    color: #ff9800;
    border: 1px solid rgba(255, 152, 0, 0.2);
}

.donate-btn:hover {
    background: rgba(255, 120, 0, 0.2);
    border-color: rgba(255, 152, 0, 0.4);
    transform: translateY(-2px);
}