:root {
    --bg-color: #f0f2f5;
    --grid-color: #cbd5e1;
    --accent-color: #ff4757;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 255, 255, 0.8);
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    background-image: 
        linear-gradient(var(--grid-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
    background-size: 50px 50px;
    font-family: 'Inter', sans-serif;
    height: 100vh;
    width: 100vw;
    overflow: hidden; 
    user-select: none;
}

.toolbar {
    position: fixed;
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(15px);
    padding: 15px 40px;
    border-radius: 60px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 30px rgba(0,0,0,0.08);
    z-index: 10000;
    transition: transform 0.3s, opacity 0.3s;
    width: max-content;
}

.icon-btn {
    background: none;
    border: none;
    color: #444;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: 0.2s;
}
.icon-btn:hover { color: #000; transform: scale(1.1); }
.icon-btn span { font-size: 16px; font-weight: 500; }

.divider { width: 1px; height: 24px; background: #bbb; }

/* 自定义下拉菜单样式 */
.custom-select-container {
    position: relative;
    width: auto;
    font-family: 'Inter', sans-serif;
    user-select: none;
}
.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    cursor: pointer;
    transition: 0.2s;
    border-radius: 50%;
}
.custom-select-trigger:hover { transform: scale(1.1); }

.custom-options {
    position: absolute;
    top: 140%;
    left: 50%;
    transform: translateX(-50%) scaleY(0);
    transform-origin: top;
    width: 160px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    border: 1px solid #fff;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    padding: 12px;
    opacity: 0;
    visibility: hidden;
    transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 11000;
    max-height: 300px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.custom-options.open {
    transform: translateX(-50%) scaleY(1);
    opacity: 1;
    visibility: visible;
}
.custom-option {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    overflow: hidden;
    border: 2px solid transparent;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.custom-option:hover { transform: scale(1.15); z-index: 10; }
.custom-option.selected { border-color: var(--accent-color); transform: scale(1.1); }

/* 滚动条样式 */
.custom-options::-webkit-scrollbar { width: 4px; }
.custom-options::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

.style-preview {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
    overflow: hidden;
    margin: 0;
    background: #fff;
    flex-shrink: 0;
    transition: transform 0.2s;
}
.style-preview:hover { transform: scale(1.1); }

input[type="text"] {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: #333;
    font-family: 'Caveat', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'SimHei', 'Heiti SC', 'WenQuanYi Micro Hei', sans-serif;
    font-weight: 400;
    font-size: 28px;
    width: 240px;
    text-align: center;
    outline: none;
    transition: border-color 0.3s, color 0.2s;
}
input[type="text"]:focus { border-bottom-color: var(--accent-color); }

/* 颜色选择器样式 */
input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    width: 28px;
    height: 28px;
    padding: 0;
    background: none;
    cursor: pointer;
    border-radius: 50%;
    overflow: hidden;
    transition: transform 0.2s;
}
input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}
input[type="color"]::-webkit-color-swatch {
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}
input[type="color"]:hover {
    transform: scale(1.1);
}

#workspace {
    position: relative;
    width: 100%;
    height: 100%;
    transform-origin: center center;
    transition: transform 0.2s ease-out;
}

.camera-container {
    position: absolute;
    top: 220px;
    left: calc(50% - 250px);
    z-index: 100;
    filter: drop-shadow(0 30px 50px rgba(0,0,0,0.2));
    pointer-events: auto; 
    cursor: grab;
}
.camera-container:active {
    cursor: grabbing;
}
.camera-container svg { pointer-events: auto; }

/* 照片 */
.polaroid-item {
    position: absolute;
    width: 330px;
    height: 495px;
    top: 410px; 
    left: 50%;
    margin-left: -165px; 
    transform-origin: center top;
    cursor: grab;
    transition: box-shadow 0.3s;
    will-change: transform, top;
    z-index: 500; 
}

.polaroid-item:active {
    cursor: grabbing;
    box-shadow: 0 40px 80px rgba(0,0,0,0.3) !important;
}

/* 吐片动画 */
/* .polaroid-item.ejecting {
    animation: natural-eject 1.4s ease-out forwards;
} */

/* @keyframes natural-eject {
    0% { 
        top: 420px; 
        transform: scale(0.85) rotate(0deg);
        opacity: 0;
    }
    20% {
        opacity: 1;
        top: 450px; 
        transform: scale(0.9) rotate(0deg);
    }
    60% {
        top: 620px; 
        transform: scale(1) rotate(0deg); 
    }
    100% { 
        top: 640px; 
        transform: scale(1) rotate(var(--random-rotate)); 
    }
} */

.dev-overlay {
    transition: opacity 8s ease-in-out;
    opacity: 1;
}
.polaroid-item.developed .dev-overlay { opacity: 0; }

.delete-btn {
    position: absolute;
    top: -15px;
    right: -15px;
    width: 30px;
    height: 30px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    opacity: 0;
    transition: 0.2s;
    pointer-events: auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    z-index: 10;
}
.delete-btn:hover { transform: scale(1.1); }
.polaroid-item:hover .delete-btn { opacity: 1; }

body.capturing .toolbar,
body.capturing .delete-btn,
body.capturing .tip,
    body.capturing .footer-copyright,
    body.capturing .controls-wrapper {
        display: none !important;
    }

.flash {
    position: fixed;
    inset: 0;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 20000;
}

@keyframes flash-animation {
    0% { opacity: 0; }
    20% { opacity: 0.8; }
    100% { opacity: 0; }
}

.flash.fire {
    animation: flash-animation 0.3s ease-out forwards;
}

@keyframes pulse {
    0% { filter: drop-shadow(0 0 0 rgba(255, 71, 87, 0)); }
    50% { filter: drop-shadow(0 0 12px rgba(255, 71, 87, 0.6)); }
    100% { filter: drop-shadow(0 0 0 rgba(255, 71, 87, 0)); }
}
.shutter-ready { animation: pulse 2s infinite; cursor: pointer; }

/* 缩略图栏样式 */
.thumbnail-bar {
    position: fixed;
    top: 140px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    z-index: 11000;
    max-width: 80vw;
    overflow-x: auto;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    scrollbar-width: none;
}
.thumbnail-bar.visible {
    opacity: 1;
    pointer-events: auto;
}
.thumbnail-bar::-webkit-scrollbar { display: none; }

.thumb-wrapper {
    position: relative;
    width: 50px;
    height: 50px;
    flex-shrink: 0;
    cursor: pointer;
    transition: transform 0.2s;
}
.thumb-wrapper:hover { transform: scale(1.1); }

.thumb-item {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    object-fit: cover;
    border: 2px solid transparent;
    transition: border-color 0.2s;
    display: block;
    background: #ddd;
}

.thumb-wrapper.selected .thumb-item {
    border-color: var(--accent-color);
}

.check-indicator {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    background: var(--accent-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 10px;
    opacity: 0;
    transform: scale(0);
    transition: 0.2s;
    border: 2px solid #fff;
}
.thumb-wrapper.selected .check-indicator {
    opacity: 1;
    transform: scale(1);
}

.thumb-delete-btn {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 18px;
    height: 18px;
    background: #ff4757;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 10px;
    opacity: 0;
    transform: scale(0);
    transition: 0.2s;
    border: 2px solid #fff;
    cursor: pointer;
    z-index: 10;
}

.thumb-wrapper:hover .thumb-delete-btn {
    opacity: 1;
    transform: scale(1);
}

.tip {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    color: #94a3b8;
    font-size: 15px;
    pointer-events: none;
    text-align: center;
}

/* Camera Modal Styles */
.camera-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content {
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    max-width: 90vw;
    width: 640px;
}

.modal-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #333;
    font-weight: 600;
    font-size: 18px;
}

.close-modal-btn {
    background: none;
    border: none;
    font-size: 28px;
    color: #666;
    cursor: pointer;
    padding: 0 10px;
    transition: color 0.2s;
}
.close-modal-btn:hover { color: #000; }

.video-wrapper {
    width: 100%;
    aspect-ratio: 4/3;
    max-height: 55vh;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    margin: 0 auto;
}

#webcam-feed {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

/* Aspect Ratio Selector */
.ratio-selector {
    display: flex;
    gap: 10px;
    margin-bottom: -10px;
}

.ratio-btn {
    background: #f0f2f5;
    border: 1px solid #ccc;
    border-radius: 16px;
    padding: 6px 16px;
    font-size: 14px;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
}

.ratio-btn:hover {
    background: #e0e0e0;
    color: #333;
}

.ratio-btn.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.capture-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    border: 4px solid #ddd;
    background: transparent;
    padding: 4px;
    cursor: pointer;
    transition: transform 0.1s;
}
.capture-btn:active { transform: scale(0.95); }

.capture-inner {
    width: 100%;
    height: 100%;
    background: #ff4757;
    border-radius: 50%;
    transition: background 0.2s;
}
.capture-btn:hover .capture-inner { background: #ff6b81; }

/* Footer Copyright Styles */
.footer-copyright {
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    color: #94a3b8;
    font-size: 12px;
    z-index: 100;
    text-align: center;
    font-family: 'Inter', sans-serif;
    opacity: 0.8;
    transition: opacity 0.3s;
}

.footer-copyright:hover {
    opacity: 1;
}

.footer-copyright a {
    color: #94a3b8;
    text-decoration: none;
    transition: color 0.2s;
}

.footer-copyright a:hover {
    color: var(--accent-color);
    text-decoration: underline;
}

/* Controls Wrapper */
.controls-wrapper {
    position: fixed;
    bottom: 30px;
    right: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    z-index: 10000;
    pointer-events: none; /* Let clicks pass through around the items */
}

.controls-wrapper > * {
    pointer-events: auto; /* Re-enable clicks */
}

/* Joystick Controls */
.joystick-container {
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 8px 30px rgba(0,0,0,0.08);
    touch-action: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s;
    position: relative;
}

/* Zoom Controls */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--glass-bg);
    backdrop-filter: blur(15px);
    padding: 8px 16px;
    border-radius: 50px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 30px rgba(0,0,0,0.08);
    min-width: 136px; /* Ensure consistent width for alignment */
    justify-content: center;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: #555;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    font-size: 14px;
}

.zoom-btn:hover {
    background: rgba(0,0,0,0.05);
    color: #000;
    transform: scale(1.1);
}

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

.zoom-level {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: #444;
    min-width: 45px;
    text-align: center;
    user-select: none;
}

.joystick-arrow {
    position: absolute;
    color: rgba(0, 0, 0, 0.3);
    font-size: 10px;
    pointer-events: none;
}

.joystick-arrow.up { top: 4px; left: 50%; transform: translateX(-50%); }
.joystick-arrow.down { bottom: 4px; left: 50%; transform: translateX(-50%); }
.joystick-arrow.left { left: 4px; top: 50%; transform: translateY(-50%); }
.joystick-arrow.right { right: 4px; top: 50%; transform: translateY(-50%); }

.joystick-knob {
    width: 40px;
    height: 40px;
    background: rgba(255, 71, 87, 0.9); /* Accent color */
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    position: absolute; 
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none; /* Let container handle events */
    transition: transform 0.1s;
}

@media (max-width: 768px) {
    .toolbar {
        top: 15px;
        width: 90%;
        max-width: 90%;
        padding: 10px;
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
        border-radius: 20px;
    }

    /* 调整相机位置，避免与底部重叠 */
    .camera-container {
        top: 80px;
    }

    .toolbar .divider {
        display: none;
    }
    
    .icon-btn span {
        display: none;
    }
    
    .icon-btn {
        font-size: 20px;
    }

    input[type="text"] {
        width: 100px;
        font-size: 16px;
    }
    
    .thumbnail-bar {
        top: auto;
        bottom: 90px;
        max-width: 95vw;
        padding: 8px;
        background: rgba(255, 255, 255, 0.8);
    }
    
    .controls-wrapper {
        bottom: 15px;
        right: 15px;
        scale: 0.85;
        transform-origin: bottom right;
        gap: 10px;
    }
    
    .tip {
        bottom: 50px;
        width: 90%;
        font-size: 12px;
    }
    
    .modal-content {
        width: 95vw;
        padding: 15px;
    }
}
