body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #f0f0f0;
    font-family: 'Permanent Marker', cursive;
}

#photo-wall {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('https://www.transparenttextures.com/patterns/cork-board.png');
    /* Cork texture */
    background-color: #e8dcc5;
    z-index: 1;
}

.camera-container {
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 100;
    perspective: 1000px;
}

.camera-body {
    width: 300px;
    height: 260px;
    background: #2c2c2c;
    /* Dark grey body */
    border-radius: 30px;
    position: relative;
    box-shadow: 10px 10px 30px rgba(0, 0, 0, 0.5);
    background-image: linear-gradient(145deg, #333, #222);
    border: 2px solid #444;
    z-index: 20;
    /* Ensure body is above ejecting photo */
}

/* Rainbow stripe */
.camera-body::before {
    content: '';
    position: absolute;
    bottom: 40px;
    left: 0;
    width: 100%;
    height: 15px;
    background: linear-gradient(to right,
            #ff3b30 0%, #ff3b30 16.6%,
            #ff9500 16.6%, #ff9500 33.2%,
            #ffcc00 33.2%, #ffcc00 49.8%,
            #4cd964 49.8%, #4cd964 66.4%,
            #5ac8fa 66.4%, #5ac8fa 83%,
            #007aff 83%, #007aff 100%);
    opacity: 0.8;
}

.viewfinder {
    position: absolute;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 140px;
    height: 140px;
    background: #000;
    border-radius: 50%;
    border: 8px solid #dcdcdc;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
}

#webcam {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    /* Mirror effect */
}

.lens-ring {
    position: absolute;
    top: 28px;
    left: 50%;
    transform: translateX(-50%);
    width: 156px;
    height: 156px;
    border-radius: 50%;
    border: 2px solid #666;
    pointer-events: none;
}

.flash {
    position: absolute;
    top: 20px;
    right: 30px;
    width: 40px;
    height: 30px;
    background: #eee;
    border-radius: 4px;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
}

.flash::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 15px;
    background: #fff;
    border-radius: 2px;
    opacity: 0.5;
}

/* Camera flip toggle (mobile) */
.camera-toggle {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: #4cd964; /* green */
    color: #fff;
    font-size: 18px;
    line-height: 31px;
    text-align: center;
    cursor: pointer;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
    display: none; /* mobile only */
    z-index: 30;
}

.camera-toggle:active {
    transform: scale(0.95);
}

@media (max-width: 768px) {
    .camera-toggle {
        display: block;
    }
}

.shutter-button {
    position: absolute;
    bottom: 70px;
    right: 20px;
    width: 50px;
    height: 50px;
    line-height: 50px;
    text-align: center;
    font-size: 26px;
    font-weight: normal;
    color: white;
    background: #ff3b30;
    border-radius: 50%;
    border: 4px solid #fff;
    cursor: pointer;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s;
}

.shutter-button:active {
    transform: scale(0.95);
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.camera-label {
    position: absolute;
    bottom: 15px;
    left: 20px;
    color: #fff;
    font-size: 18px;
    letter-spacing: 1px;
    opacity: 0.8;
}

.photo-slot {
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 220px;
    height: 10px;
    background: #111;
    border-radius: 5px;
}

/* Photo Styles */
.photo {
    position: absolute;
    width: 200px;
    height: 240px;
    background: #fff;
    padding: 15px 15px 50px 15px;
    box-sizing: border-box;
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2);
    cursor: grab;
    transform-origin: center;
    /* Initial state for ejection */
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
}

.photo:active {
    cursor: grabbing;
}

.photo-image {
    width: 100%;
    height: 100%;
    background: #000;
    overflow: hidden;
    position: relative;
}

/* Vignette overlay */
.photo-image::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.6);
    pointer-events: none;
    z-index: 2;
}

/* Reverted to img styles, but without object-fit since we crop manually now */
.photo-image img {
    width: 100%;
    height: 100%;
    display: block;
    /* Default developed state */
    filter: contrast(1.2) brightness(1.1) saturate(0.9) sepia(0.2);
}

/* Animations */
@keyframes eject {
    0% {
        transform: translateX(-50%) translateY(0) scale(0.9);
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    100% {
        transform: translateX(-50%) translateY(-240px) scale(1);
    }
}

.photo.ejecting {
    animation: eject 1.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
    z-index: 10;
    /* Behind camera body (20) */
}

/* Developing Animation */
/* Initial State: White, Blurry, Faded */
.photo.developing .photo-image img {
    filter: brightness(2.5) blur(10px) grayscale(100%) opacity(0.5);
    transition: none;
    /* No transition initially */
}

/* Final State: Clear */
.photo.developed .photo-image img {
    filter: contrast(1.2) brightness(1.1) saturate(0.9) sepia(0.2);
    /* Slow transition for realistic developing effect */
    transition: filter 8s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Title and Save Button */
#app-title {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 3rem;
    color: #333;
    text-shadow: 2px 2px 0px rgba(255, 255, 255, 0.5);
    z-index: 200;
    cursor: text;
    margin: 0;
    padding: 10px;
    border: 2px dashed transparent;
    transition: border 0.3s;
}

#app-title:hover,
#app-title:focus {
    border-color: #666;
    outline: none;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
}

#save-btn {
    position: absolute;
    top: 30px;
    right: 30px;
    padding: 10px 20px;
    font-family: 'Permanent Marker', cursive;
    font-size: 1.2rem;
    background: #ffcc00;
    border: none;
    color: #333;
    cursor: pointer;
    z-index: 900;
    transform: rotate(3deg);
    box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

#save-btn:hover {
    transform: rotate(0deg) scale(1.05);
}

#save-btn:active {
    transform: scale(0.95);
}

/* Photo Caption */
.photo-caption {
    position: absolute;
    bottom: 15px;
    left: 0;
    width: 100%;
    text-align: center;
    font-family: 'Permanent Marker', cursive;
    font-size: 1rem;
    color: #333;
    cursor: text;
    z-index: 5;
    outline: none;
    border: 1px dashed transparent;
}

.photo-caption:hover,
.photo-caption:focus {
    border-color: rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.5);
}

/* Placeholder style for caption */
.photo-caption.placeholder {
    color: #aaa;
}

/* Delete Button */
.delete-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 24px;
    height: 24px;
    background: #ff3b30;
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 24px;
    font-family: sans-serif;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, transform 0.1s;
    box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.photo:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    transform: scale(1.1);
    background: #ff0000;
}

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

/* Loading Indicator */
#loading-indicator {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-content {
    text-align: center;
    color: white;
}

.loading-content p {
    font-family: 'Permanent Marker', cursive;
    font-size: 1.5rem;
    margin-top: 20px;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffcc00;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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

/* Mobile Responsive Styles */
@media (max-width: 768px) {

    body,
    html {
        overflow: auto;
        /* Enable scrolling on mobile */
    }

    #photo-wall {
        min-height: 100vh;
        height: auto;
        overflow: visible;
    }

    /* Smaller photos on mobile */
    .photo {
        width: 140px;
        height: 168px;
        padding: 10px 10px 35px 10px;
    }

    /* Smaller camera on mobile */
    .camera-container {
        bottom: 10px;
        left: 10px;
    }

    .camera-body {
        width: 200px;
        height: 173px;
        border-radius: 20px;
    }

    .viewfinder {
        top: 26px;
        width: 100px;
        height: 100px;
        border: 5px solid #dcdcdc;
    }

    .lens-ring {
        top: 24px;
        width: 110px;
        height: 110px;
    }

    .flash {
        top: 15px;
        right: 20px;
        width: 30px;
        height: 22px;
    }

    .shutter-button {
        bottom: 11px;
        right: 9px;
        width: 40px;
        height: 40px;
        border: 3px solid #fff;
    }

    .camera-label {
        bottom: 10px;
        left: 15px;
        font-size: 14px;
    }

    .camera-body::before {
        bottom: 27px;
        height: 12px;
    }

    .photo-slot {
        width: 150px;
        height: 8px;
    }

    /* Smaller title on mobile */
    #app-title {
        font-size: 2rem;
        top: 10px;
    }

    /* Smaller save button on mobile */
    #save-btn {
        top: 15px;
        right: 15px;
        padding: 8px 16px;
        font-size: 1rem;
    }

    /* Smaller caption font on mobile */
    .photo-caption {
        font-size: 0.85rem;
        bottom: 10px;
    }

    /* Smaller delete button on mobile */
    .delete-btn {
        width: 20px;
        height: 20px;
        line-height: 20px;
        font-size: 12px;
        top: -8px;
        right: -8px;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .photo {
        width: 120px;
        height: 144px;
        padding: 8px 8px 30px 8px;
    }

    .camera-body {
        width: 180px;
        height: 156px;
    }

    .viewfinder {
        width: 90px;
        height: 90px;
    }

    .lens-ring {
        width: 100px;
        height: 100px;
    }

    #app-title {
        font-size: 1.5rem;
    }

    .photo-caption {
        font-size: 0.75rem;
    }
}

/* Make camera draggable */
.camera-container {
    cursor: move;
}

.camera-container.dragging {
    cursor: grabbing;
}

/* Rearrange Button */
#rearrange-btn {
    position: absolute;
    top: 30px;
    right: 330px;
    padding: 10px 20px;
    font-family: 'Permanent Marker', cursive;
    font-size: 1.2rem;
    background: #5ac8fa;
    border: none;
    color: #fff;
    cursor: pointer;
    z-index: 200;
    transform: rotate(-2deg);
    box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
      transform: rotate(3deg);
}

#rearrange-btn:hover {
    transform: rotate(0deg) scale(1.05);
}

#rearrange-btn:active {
    transform: scale(0.95);
}

#reload-btn {
    position: absolute;
    top: 30px;
    right: 196px;
    padding: 10px 20px;
    font-family: 'Permanent Marker', cursive;
    font-size: 1.2rem;
    background: #ee5c4c;
    border: none;
    color: #fff;
    cursor: pointer;
    z-index: 200;
    transform: rotate(-2deg);
    box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

#reload-btn:hover {
    transform: rotate(0deg) scale(1.05);
}

#reload-btn:active {
    transform: scale(0.95);
}

/* Smooth transitions for layout changes */
.photo.animating {
    transition: left 0.8s ease-in-out, top 0.8s ease-in-out, transform 0.8s ease-in-out;
}

/* Mobile adjustments for rearrange button */
@media (max-width: 768px) {
    #rearrange-btn {
        top: 60px;
        right: 15px;
        padding: 8px 16px;
        font-size: 1rem;
    }
    #reload-btn {
        top: 105px;
        right: 15px;
        padding: 8px 16px;
        font-size: 1rem;
    }
}

/* Make title draggable */
#app-title {
    cursor: move;
    user-select: none;
}

#app-title.dragging {
    cursor: grabbing;
}

/* Make title draggable */
#app-title {
    cursor: move;
    user-select: none;
}

#app-title.dragging {
    cursor: grabbing;
}

/* Fix title dragging vs editing */
#app-title {
    cursor: move;
    /* user-select: none;  <-- Removed this to allow editing */
    position: absolute;
    left: 50%;
    /* transform: translateX(-50%); <-- This is initial state */
}

#app-title.dragging {
    cursor: grabbing;
    user-select: none;
    /* Only prevent selection while dragging */
}