/**
 * Retro Instant Camera - Styles
 * 复古拍立得相机样式表
 */

/* ========================================
   CSS Variables / 变量定义
   ======================================== */
:root {
    /* 主题色 */
    --primary-color: #d93025;
    --primary-hover: #b52d20;
    --secondary-color: #222;
    
    /* 背景 */
    --bg-color: #d4d4d4;
    --bg-dot-color: #e0e0e0;
    
    /* 拍立得 */
    --polaroid-bg: #fdfdfd;
    --polaroid-shadow: rgba(0, 0, 0, 0.2);
    
    /* 动画时长 */
    --transition-fast: 0.1s;
    --transition-normal: 0.2s;
    --transition-slow: 0.5s;
    --develop-duration: 6s;
}

/* ========================================
   Base Styles / 基础样式
   ======================================== */
@import url('https://fonts.googleapis.com/css2?family=Permanent+Marker&display=swap');

*,
*::before,
*::after {
    box-sizing: border-box;
    outline: none;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    min-height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    flex-direction: row;
    font-family: sans-serif;
    user-select: none;
    touch-action: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 背景层 */
.background-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(var(--bg-dot-color) 15%, transparent 16%),
        radial-gradient(var(--bg-dot-color) 15%, transparent 16%);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    transition: opacity 0.3s ease;
}

.background-layer.has-image {
    background-image: none;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* ========================================
   Layout / 布局
   ======================================== */
.camera-zone {
    flex: 0 0 50%;
    max-width: 600px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    position: relative;
    z-index: 20;
    padding: 20px;
    padding-bottom: 80px;
}

.desk-zone {
    flex: 1;
    position: relative;
    height: 100vh;
}

/* ========================================
   Camera / 相机
   ======================================== */
.camera-wrapper {
    position: relative;
    width: 100%;
    max-width: 450px;
    aspect-ratio: 1 / 1;
}

.camera-img {
    width: 100%;
    height: auto;
    position: relative;
    z-index: 20;
    pointer-events: none;
    filter: drop-shadow(0 20px 30px rgba(0, 0, 0, 0.4));
}

/* ========================================
   Lens / 镜头
   ======================================== */
.lens-wrapper {
    position: absolute;
    top: 55%;
    left: 62%;
    transform: translate(-50%, -50%);
    width: 39%;
    height: 39%;
    border-radius: 50%;
    overflow: hidden;
    z-index: 25;
    background: #000;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
}

#camera-feed {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    opacity: 0.9;
    background: #000;
}

.lens-shine {
    position: absolute;
    top: 15%;
    left: 15%;
    width: 30%;
    height: 20%;
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(-45deg);
    filter: blur(3px);
    z-index: 26;
    pointer-events: none;
}

/* ========================================
   Shutter Button / 快门按钮
   ======================================== */
.shutter-btn {
    position: absolute;
    top: 55%;
    left: 23%;
    transform: translate(-50%, -50%);
    width: 19%;
    height: 19%;
    border-radius: 50%;
    z-index: 30;
    cursor: pointer;
    border: none;
    background: transparent;
    -webkit-tap-highlight-color: transparent;
    transition: transform var(--transition-fast);
}

.shutter-btn:hover {
    transform: translate(-50%, -50%) scale(1.05);
}

.shutter-btn:active,
.shutter-btn:disabled {
    transform: translate(-50%, -50%) scale(0.95);
}

.shutter-btn:disabled {
    cursor: not-allowed;
}

/* ========================================
   Ejection Slot / 出片口
   ======================================== */
.ejection-slot {
    position: absolute;
    z-index: 15;
    top: -40%;
    left: 50%;
    transform: translateX(-50%);
    width: 35%;
    height: 100%;
    pointer-events: none;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 20%;
}

/* ========================================
   Action Buttons / 操作按钮
   ======================================== */
.btn-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    gap: 10px;
}

.action-btn {
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 8px 16px;
    border-radius: 20px;
    font-family: 'Permanent Marker', cursive;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: all var(--transition-normal);
}

.action-btn:hover {
    background: var(--primary-color);
    color: white;
}

.action-btn:active {
    transform: scale(0.95);
}

.action-btn.secondary {
    border-color: var(--secondary-color);
    color: var(--secondary-color);
}

.action-btn.secondary:hover {
    background: var(--secondary-color);
    color: white;
}

/* ========================================
   Flash Effect / 闪光效果
   ======================================== */
.flash-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 10000;
    transition: opacity var(--transition-fast);
}

.flash-overlay.active {
    opacity: 1;
}

/* ========================================
   Polaroid Styles / 拍立得样式
   ======================================== */
.polaroid {
    width: 170px;
    background: var(--polaroid-bg);
    padding: 10px 10px 55px 10px;
    box-shadow: 0 4px 10px var(--polaroid-shadow);
    position: absolute;
    cursor: grab;
    pointer-events: auto;
    transform-origin: center center;
    touch-action: none;
    transition: opacity var(--transition-slow) ease-out, transform var(--transition-normal);
}

.polaroid:active {
    cursor: grabbing;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    z-index: 10000 !important;
}

.polaroid img {
    width: 100%;
    height: 170px;
    object-fit: cover;
    background: #222;
    border: 1px solid #e0e0e0;
    pointer-events: none;
    display: block;
    filter: blur(0) grayscale(0) brightness(1);
    will-change: filter;
}

/* 显影动画 */
.polaroid.developing-start img {
    filter: blur(15px) grayscale(0.5) brightness(0.9);
}

.polaroid.developing-slow img {
    transition: filter var(--develop-duration) ease-in-out;
    filter: blur(0) grayscale(0) brightness(1);
}

.polaroid.developing-fast img {
    transition: filter 3s ease-out !important;
    filter: blur(0) grayscale(0) brightness(1);
}

/* 拍立得标题 */
.polaroid .caption-main {
    position: absolute;
    bottom: 22px;
    left: 10px;
    width: 150px;
    text-align: center;
    color: #222;
    opacity: 0.9;
    cursor: text;
    font-family: 'Permanent Marker', cursive;
    font-size: 14px;
    line-height: 1.1;
    min-height: 18px;
}

.polaroid .caption-main:empty::before {
    content: 'Click to edit';
    opacity: 0.4;
}

.polaroid .caption-date {
    position: absolute;
    bottom: 8px;
    left: 10px;
    width: 150px;
    text-align: center;
    font-family: 'Permanent Marker', cursive;
    font-size: 10px;
    color: #555;
    pointer-events: none;
    user-select: none;
}

/* 弹出动画 */
.polaroid.ejecting {
    transform: translateY(100%);
    animation: riseOut 2s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

@keyframes riseOut {
    0% {
        transform: translateY(100%);
        opacity: 1;
    }
    100% {
        transform: translateY(-50px);
        opacity: 1;
    }
}

/* ========================================
   Polaroid Controls / 拍立得控制按钮
   ======================================== */
.polaroid-controls {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 5px;
    z-index: 50;
    opacity: 0;
    transition: opacity 0.3s ease-out, transform var(--transition-normal) ease-out;
    pointer-events: auto;
}

.polaroid:hover .polaroid-controls {
    opacity: 1;
    transform: translateX(-50%) translateY(-2px);
}

.polaroid-btn {
    background: rgba(217, 48, 37, 0.95);
    color: white;
    border: none;
    padding: 6px 10px;
    border-radius: 15px;
    font-family: 'Permanent Marker', cursive;
    font-size: 10px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all var(--transition-normal);
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.polaroid-btn:hover {
    transform: scale(1.05);
}

.polaroid-btn:active {
    transform: scale(0.95);
}

.polaroid-btn.delete-btn {
    background: rgba(217, 48, 37, 0.95);
}

.polaroid-btn.delete-btn:hover {
    background: rgba(185, 45, 32, 0.95);
}

.polaroid-btn.rotate-btn {
    background: rgba(156, 39, 176, 0.95);
}

.polaroid-btn.rotate-btn:hover {
    background: rgba(123, 31, 139, 0.95);
}

.polaroid-btn.zoom-in-btn {
    background: rgba(46, 179, 79, 0.95);
}

.polaroid-btn.zoom-in-btn:hover {
    background: rgba(34, 150, 68, 0.95);
}

.polaroid-btn.zoom-out-btn {
    background: rgba(33, 150, 243, 0.95);
}

.polaroid-btn.zoom-out-btn:hover {
    background: rgba(24, 120, 200, 0.95);
}

/* ========================================
   Error Message / 错误提示
   ======================================== */
.error-message {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(217, 48, 37, 0.95);
    color: white;
    padding: 15px 25px;
    border-radius: 20px;
    text-align: center;
    z-index: 200;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    font-family: 'Permanent Marker', cursive;
}

.error-message p {
    margin: 0 0 5px 0;
    font-size: 1rem;
}

.error-message small {
    opacity: 0.8;
    font-family: sans-serif;
}

.error-message[hidden] {
    display: none;
}

/* ========================================
   Footer / 页脚
   ======================================== */
.footer-text {
    position: fixed;
    bottom: 20px;
    left: 20px;
    font-family: 'Permanent Marker', cursive;
    font-size: 13px;
    color: #555;
    z-index: 100;
    max-width: 300px;
    line-height: 1.3;
}

/* ========================================
   Responsive / 响应式
   ======================================== */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }
    
    .camera-zone {
        flex: 0 0 auto;
        width: 100%;
        max-width: none;
        height: auto;
        padding-top: 60px;
        padding-bottom: 40px;
        justify-content: center;
    }
    
    .desk-zone {
        width: 100%;
        height: 100%;
    }
    
    .btn-container {
        top: 10px;
        right: 10px;
    }
    
    .action-btn {
        font-size: 12px;
        padding: 6px 12px;
    }
    
    .footer-text {
        font-size: 10px;
        max-width: 150px;
        bottom: 10px;
        left: 10px;
    }
    
    /* 移动端显示控制按钮 */
    .polaroid .polaroid-controls {
        opacity: 0;
        pointer-events: auto;
        transition: opacity 0.3s ease;
    }
    
    .polaroid.tapped .polaroid-controls,
    .polaroid:active .polaroid-controls {
        opacity: 1;
        transform: translateX(-50%) translateY(-2px);
    }
}

/* 手机横屏模式 */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        flex-direction: row;
    }
    
    .camera-zone {
        flex: 0 0 auto;
        width: auto;
        height: 100vh;
        padding: 10px;
        padding-bottom: 10px;
        justify-content: center;
    }
    
    .camera-wrapper {
        max-width: none;
        max-height: 90vh;
        width: auto;
        height: 90vh;
    }
    
    .desk-zone {
        flex: 1;
        height: 100vh;
    }
    
    .btn-container {
        top: 5px;
        right: 5px;
    }
    
    .action-btn {
        font-size: 10px;
        padding: 4px 8px;
    }
    
    .footer-text {
        display: none;
    }
}

@media (max-width: 480px) {
    .camera-wrapper {
        max-width: 320px;
    }
    
    .polaroid {
        width: 140px;
    }
    
    .polaroid img {
        height: 140px;
    }
    
    .polaroid .caption-main {
        width: 120px;
        font-size: 12px;
    }
    
    .polaroid .caption-date {
        width: 120px;
        font-size: 9px;
    }
}

/* ========================================
   Accessibility / 无障碍
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
    .polaroid {
        border: 2px solid #000;
    }
    
    .action-btn {
        border-width: 3px;
    }
}

/* ========================================
   Crop Modal / 裁切弹窗
   ======================================== */
.crop-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.crop-modal[hidden] {
    display: none;
}

.crop-container {
    background: #fff;
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.crop-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
}

.crop-header h3 {
    margin: 0;
    font-family: 'Permanent Marker', cursive;
    font-size: 18px;
    color: #333;
}

.crop-body {
    flex: 1;
    min-height: 300px;
    max-height: 60vh;
    overflow: hidden;
    background: #f5f5f5;
}

.crop-body img {
    display: block;
    max-width: 100%;
}

.crop-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.crop-btn {
    padding: 10px 20px;
    border-radius: 20px;
    font-family: 'Permanent Marker', cursive;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid;
}

.crop-btn.cancel-btn {
    background: #fff;
    border-color: #999;
    color: #666;
}

.crop-btn.cancel-btn:hover {
    background: #f5f5f5;
}

.crop-btn.confirm-btn {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

.crop-btn.confirm-btn:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

@media (max-width: 480px) {
    .crop-container {
        width: 95%;
        max-height: 95vh;
    }
    
    .crop-body {
        min-height: 200px;
        max-height: 50vh;
    }
    
    .crop-btn {
        padding: 8px 16px;
        font-size: 12px;
    }
}
