/* ===== CSS Variables ===== */
:root {
    --xmas-red: #c41e3a;
    --xmas-red-light: #ff4757;
    --xmas-green: #228b22;
    --xmas-green-light: #2ed573;
    --xmas-gold: #ffd700;
    --xmas-gold-light: #ffed4e;
    --xmas-blue: #1e90ff;
    --xmas-white: #fffafa;
    --xmas-dark: #1a0a0a;
    --xmas-dark-2: #2d1a1a;

    --glow-red: 0 0 20px rgba(196, 30, 58, 0.8), 0 0 40px rgba(196, 30, 58, 0.4);
    --glow-green: 0 0 20px rgba(34, 139, 34, 0.8), 0 0 40px rgba(34, 139, 34, 0.4);
    --glow-gold: 0 0 20px rgba(255, 215, 0, 0.8), 0 0 40px rgba(255, 215, 0, 0.4);

    --font-display: 'Mountains of Christmas', cursive;
    --font-body: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;

    --safe-area-top: env(safe-area-inset-top);
    --safe-area-bottom: env(safe-area-inset-bottom);
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--xmas-dark);
}

body {
    font-family: var(--font-body);
    background: linear-gradient(180deg, var(--xmas-dark) 0%, var(--xmas-dark-2) 50%, #0f1a0f 100%);
    color: var(--xmas-white);
    position: relative;
    min-height: 100%;
    min-height: -webkit-fill-available;
}

/* iOS PWA Safe Area Background Fix */
html {
    background: var(--xmas-dark);
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    body::after {
        content: '';
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: env(safe-area-inset-bottom);
        background: linear-gradient(180deg, #0f1a0f 0%, var(--xmas-dark) 100%);
        z-index: 9999;
    }
}

/* ===== Snowflakes ===== */
#snowflakes-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    overflow: hidden;
}

.snowflake {
    position: absolute;
    top: -20px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 1rem;
    animation: snowfall linear infinite;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
}

@keyframes snowfall {
    0% {
        transform: translateY(0) rotate(0deg) translateX(0);
        opacity: 1;
    }
    50% {
        transform: translateY(50vh) rotate(180deg) translateX(20px);
    }
    100% {
        transform: translateY(100vh) rotate(360deg) translateX(-20px);
        opacity: 0.3;
    }
}

/* ===== Christmas Lights ===== */
.christmas-lights {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-around;
    padding: 10px 5px;
    padding-top: calc(10px + var(--safe-area-top));
    z-index: 100;
    background: linear-gradient(180deg, rgba(0,0,0,0.5) 0%, transparent 100%);
}

.light {
    width: 12px;
    height: 18px;
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    position: relative;
    animation: twinkle 1.5s ease-in-out infinite;
}

.light::before {
    content: '';
    position: absolute;
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 6px;
    background: #333;
    border-radius: 2px 2px 0 0;
}

.light.red {
    background: var(--xmas-red);
    box-shadow: var(--glow-red);
    animation-delay: 0s;
}

.light.gold {
    background: var(--xmas-gold);
    box-shadow: var(--glow-gold);
    animation-delay: 0.3s;
}

.light.green {
    background: var(--xmas-green);
    box-shadow: var(--glow-green);
    animation-delay: 0.6s;
}

.light.blue {
    background: var(--xmas-blue);
    box-shadow: 0 0 20px rgba(30, 144, 255, 0.8), 0 0 40px rgba(30, 144, 255, 0.4);
    animation-delay: 0.9s;
}

@keyframes twinkle {
    0%, 100% {
        opacity: 1;
        filter: brightness(1.2);
    }
    50% {
        opacity: 0.4;
        filter: brightness(0.6);
    }
}

/* ===== App Container ===== */
#app {
    height: 100%;
    width: 100%;
    position: relative;
    padding-top: calc(40px + var(--safe-area-top));
    padding-bottom: var(--safe-area-bottom);
    background: linear-gradient(180deg, var(--xmas-dark) 0%, var(--xmas-dark-2) 50%, #0f1a0f 100%);
}

/* ===== Views ===== */
.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    padding-top: calc(50px + var(--safe-area-top));
    padding-bottom: var(--safe-area-bottom);
    background: linear-gradient(180deg, var(--xmas-dark) 0%, var(--xmas-dark-2) 50%, #0f1a0f 100%);
}

.view.active {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

/* ===== Camera View ===== */
#camera-view {
    padding: 15px;
    padding-top: calc(50px + var(--safe-area-top));
}

.app-header {
    text-align: center;
    margin-bottom: 15px;
    position: relative;
}

/* ===== Language Switch Button ===== */
.lang-switch-btn {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 20px;
    border: 1.5px solid var(--xmas-gold);
    background: rgba(255, 215, 0, 0.1);
    color: var(--xmas-gold);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    z-index: 10;
}

.lang-switch-btn:hover {
    background: rgba(255, 215, 0, 0.2);
    transform: scale(1.02);
}

.lang-switch-btn:active {
    transform: scale(0.95);
    background: rgba(255, 215, 0, 0.3);
}

.lang-switch-btn i {
    font-size: 1rem;
}

.lang-switch-btn .lang-text {
    font-family: var(--font-body);
}

.title {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    color: var(--xmas-white);
    text-shadow:
        0 0 10px var(--xmas-red),
        0 0 20px var(--xmas-red),
        0 0 30px var(--xmas-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.title .icon {
    animation: bounce 2s ease-in-out infinite;
}

.title .icon:last-child {
    animation-delay: 0.5s;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.subtitle {
    font-size: 0.9rem;
    color: var(--xmas-gold);
    margin-top: 5px;
    opacity: 0.9;
}

/* ===== Camera Container ===== */
.camera-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

.camera-frame {
    position: relative;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 3/4;
    border-radius: 20px;
    overflow: hidden;
    background: #000;
    box-shadow:
        0 0 0 3px var(--xmas-gold),
        0 0 30px rgba(255, 215, 0, 0.3),
        inset 0 0 60px rgba(0, 0, 0, 0.5);
}

.frame-corner {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 3px solid var(--xmas-gold);
    z-index: 10;
}

.frame-corner.top-left {
    top: 15px;
    left: 15px;
    border-right: none;
    border-bottom: none;
    border-radius: 5px 0 0 0;
}

.frame-corner.top-right {
    top: 15px;
    right: 15px;
    border-left: none;
    border-bottom: none;
    border-radius: 0 5px 0 0;
}

.frame-corner.bottom-left {
    bottom: 15px;
    left: 15px;
    border-right: none;
    border-top: none;
    border-radius: 0 0 0 5px;
}

.frame-corner.bottom-right {
    bottom: 15px;
    right: 15px;
    border-left: none;
    border-top: none;
    border-radius: 0 0 5px 0;
}

#camera-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.scan-line {
    position: absolute;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--xmas-gold), transparent);
    opacity: 0.5;
    animation: scan 3s linear infinite;
}

@keyframes scan {
    0% { top: 0; }
    100% { top: 100%; }
}

/* ===== Controls ===== */
.controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
    padding: 20px;
}

.control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 2px solid var(--xmas-gold);
    background: rgba(255, 215, 0, 0.1);
    color: var(--xmas-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.control-btn:active {
    transform: scale(0.9);
    background: rgba(255, 215, 0, 0.3);
}

.control-btn svg {
    width: 24px;
    height: 24px;
}

.control-btn i {
    font-size: 1.3rem;
}

.capture-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    position: relative;
}

.capture-ring {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 4px solid var(--xmas-white);
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--xmas-red) 0%, var(--xmas-red-light) 100%);
    box-shadow:
        0 0 20px var(--xmas-red),
        inset 0 0 20px rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% {
        box-shadow:
            0 0 20px var(--xmas-red),
            inset 0 0 20px rgba(255, 255, 255, 0.2);
    }
    50% {
        box-shadow:
            0 0 40px var(--xmas-red),
            0 0 60px rgba(196, 30, 58, 0.5),
            inset 0 0 20px rgba(255, 255, 255, 0.3);
    }
}

.capture-btn:active .capture-ring {
    transform: scale(0.9);
}

.capture-inner {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.capture-icon {
    font-size: 1.8rem;
    color: white;
}

/* ===== Processing View ===== */
#processing-view {
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, var(--xmas-dark-2) 0%, var(--xmas-dark) 100%);
}

.processing-content {
    text-align: center;
    padding: 20px;
}

.magic-circle {
    width: 150px;
    height: 150px;
    margin: 0 auto 30px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ring {
    position: absolute;
    border-radius: 50%;
    border: 3px solid transparent;
}

.ring-1 {
    width: 100%;
    height: 100%;
    border-top-color: var(--xmas-red);
    border-right-color: var(--xmas-red);
    animation: spin 2s linear infinite;
}

.ring-2 {
    width: 80%;
    height: 80%;
    border-bottom-color: var(--xmas-green);
    border-left-color: var(--xmas-green);
    animation: spin 1.5s linear infinite reverse;
}

.ring-3 {
    width: 60%;
    height: 60%;
    border-top-color: var(--xmas-gold);
    border-right-color: var(--xmas-gold);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.magic-icon {
    font-size: 3rem;
    animation: float 2s ease-in-out infinite;
    z-index: 10;
    color: var(--xmas-red);
}

@keyframes float {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-10px) scale(1.1); }
}

.processing-title {
    font-family: var(--font-display);
    font-size: 1.8rem;
    color: var(--xmas-gold);
    text-shadow: 0 0 20px var(--xmas-gold);
    margin-bottom: 10px;
}

.processing-subtitle {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9rem;
    margin-bottom: 30px;
}

.progress-bar {
    width: 80%;
    max-width: 300px;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    margin: 0 auto 30px;
    overflow: hidden;
}

.progress-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--xmas-red), var(--xmas-gold), var(--xmas-green));
    background-size: 200% 100%;
    border-radius: 4px;
    animation: progress-animate 3s ease-in-out infinite;
    transition: width 0.3s ease;
}

@keyframes progress-animate {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.magic-particles {
    display: flex;
    justify-content: center;
    gap: 20px;
    font-size: 1.5rem;
}

.magic-particles i {
    animation: sparkle 1.5s ease-in-out infinite;
}

.magic-particles i:nth-child(1) { animation-delay: 0s; color: var(--xmas-gold); }
.magic-particles i:nth-child(2) { animation-delay: 0.2s; color: var(--xmas-gold-light); }
.magic-particles i:nth-child(3) { animation-delay: 0.4s; color: var(--xmas-white); }
.magic-particles i:nth-child(4) { animation-delay: 0.6s; color: var(--xmas-blue); }
.magic-particles i:nth-child(5) { animation-delay: 0.8s; color: var(--xmas-green); }
.magic-particles i:nth-child(6) { animation-delay: 1s; color: var(--xmas-gold); }

@keyframes sparkle {
    0%, 100% {
        transform: scale(1) rotate(0deg);
        opacity: 0.5;
    }
    50% {
        transform: scale(1.3) rotate(15deg);
        opacity: 1;
    }
}

/* ===== Result View ===== */
#result-view {
    padding: 15px;
}

.result-header {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px 0;
}

.back-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: none;
    color: var(--xmas-gold);
    font-size: 1rem;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 20px;
    transition: all 0.3s ease;
}

.back-btn:active {
    background: rgba(255, 215, 0, 0.2);
}

.back-btn svg {
    width: 20px;
    height: 20px;
}

.back-btn i {
    font-size: 1rem;
}

.result-title {
    flex: 1;
    text-align: center;
    font-family: var(--font-display);
    font-size: 1.3rem;
    color: var(--xmas-gold);
    text-shadow: 0 0 10px var(--xmas-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.result-title i {
    color: var(--xmas-green);
}

.result-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

.result-frame {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    border-radius: 15px;
    overflow: hidden;
    box-shadow:
        0 0 0 4px var(--xmas-gold),
        0 0 40px rgba(255, 215, 0, 0.4),
        0 20px 60px rgba(0, 0, 0, 0.5);
    animation: result-appear 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes result-appear {
    from {
        opacity: 0;
        transform: scale(0.8) rotateY(-10deg);
    }
    to {
        opacity: 1;
        transform: scale(1) rotateY(0);
    }
}

#result-image {
    display: block;
    max-width: 100%;
    max-height: 55vh;
    object-fit: contain;
}

.result-decoration {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.deco-item {
    position: absolute;
    font-size: 1.5rem;
    animation: deco-float 3s ease-in-out infinite;
}

.deco-item.top-left { top: 10px; left: 10px; color: var(--xmas-red); }
.deco-item.top-right { top: 10px; right: 10px; animation-delay: 0.5s; color: var(--xmas-gold); }
.deco-item.bottom-left { bottom: 10px; left: 10px; animation-delay: 1s; color: var(--xmas-red); }
.deco-item.bottom-right { bottom: 10px; right: 10px; animation-delay: 1.5s; color: var(--xmas-gold); }

@keyframes deco-float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-5px) rotate(10deg); }
}

/* ===== Result Actions ===== */
.result-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px 10px;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 24px;
    border-radius: 30px;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

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

.action-btn.primary {
    background: linear-gradient(135deg, var(--xmas-red) 0%, var(--xmas-red-light) 100%);
    color: white;
    box-shadow: 0 4px 20px rgba(196, 30, 58, 0.4);
}

.action-btn.secondary {
    background: linear-gradient(135deg, var(--xmas-green) 0%, var(--xmas-green-light) 100%);
    color: white;
    box-shadow: 0 4px 20px rgba(34, 139, 34, 0.4);
}

.action-btn.outline {
    background: transparent;
    color: var(--xmas-gold);
    border: 2px solid var(--xmas-gold);
}

.btn-icon {
    font-size: 1.1rem;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: calc(100px + var(--safe-area-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(200, 30, 30, 0.95);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast.success {
    background: rgba(34, 139, 34, 0.95);
}

.toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.toast-icon {
    font-size: 1.1rem;
}

/* ===== Animations ===== */
@keyframes fade-in-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Responsive ===== */
@media (min-height: 800px) {
    .camera-frame {
        max-width: 350px;
    }

    #result-image {
        max-height: 60vh;
    }
}

@media (max-height: 600px) {
    .app-header {
        margin-bottom: 10px;
    }

    .title {
        font-size: 1.5rem;
    }

    .subtitle {
        display: none;
    }

    .camera-frame {
        max-width: 280px;
    }

    .controls {
        padding: 10px;
    }
}
