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

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f0f0f0;
}

.container {
    width: 100%;
    height: 100%;
    max-width: 500px; /* Limit width for larger screens */
    margin: 0 auto;
    position: relative;
    background-image: url('../images/p1/bg.png');
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center top;
    overflow: hidden;
}

/* Logo Area */
.logo {
    position: absolute;
    top: 5%; /* Moved down from 2% */
    left: 0;
    width: 100%;
    z-index: 10;
    text-align: center;
    animation: fadeInDown 1s ease-out forwards;
}

.logo img {
    width: 75%;
    height: auto;
}

/* Title Area */
.title {
    position: absolute;
    top: 18%; /* Adjusted slightly for new logo position */
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    z-index: 20;
    animation: titleEnter 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards, float-title 4s ease-in-out infinite 1s;
}

.title img {
    width: 100%;
    height: auto;
}

/* Floating Camera - Now positioned at bottom right as requested */
.camera-icon {
    position: absolute;
    bottom: -2%;
    right: -5%;
    width: 45%; /* Slightly larger */
    z-index: 25;
    transform-origin: bottom right;
    animation: float-foreground 5s ease-in-out infinite;
}

.camera-icon img {
    width: 100%;
    height: auto;
    display: block;
}

/* People */
.people {
    position: absolute;
    bottom: 8%;
    left: -5%;
    width: 70%;
    z-index: 15;
    display: flex;
    justify-content: flex-start;
    animation: slideInLeft 1s ease-out forwards, breathe 4s ease-in-out infinite 1s;
}

.people img {
    width: 100%;
    height: auto;
    object-fit: contain;
}

/* Button */
.btn-enter {
    position: absolute;
    bottom: 5%;
    left: 50%;
    transform: translateX(-50%);
    width: 40%;
    z-index: 30;
    cursor: pointer;
    animation: pulse 2s infinite, btn-entrance 0.5s ease-out 1s backwards;
}

.btn-enter img {
    width: 100%;
    height: auto;
    display: block;
}

/* Animations */
@keyframes titleEnter {
    from {
        opacity: 0;
        transform: translateX(-50%) scale(0.5);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes float-title {
    0%, 100% {
        transform: translateX(-50%) translateY(0);
    }
    50% {
        transform: translateX(-50%) translateY(-10px);
    }
}

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

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes breathe {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
}

@keyframes pulse {
    0% {
        transform: translateX(-50%) scale(1);
    }
    50% {
        transform: translateX(-50%) scale(1.05);
    }
    100% {
        transform: translateX(-50%) scale(1);
    }
}

@keyframes btn-entrance {
    from {
        opacity: 0;
        transform: translateX(-50%) scale(0);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }
}

/* Responsive adjustments for very tall screens (iPhone X+) */
@media (min-aspect-ratio: 9/16) {
    .container {
        background-size: cover;
    }
}

/* --- P2: Intro / Rules --- */
.page-p2 {
    background-image: url('../images/p2/p2_bg.png'); /* 假设背景图已包含手绘风格背景 */
    display: block; /* Changed from flex to block for absolute positioning control */
    position: relative;
}

/* 蓝色半透明面板 */
.rules-container {
    position: absolute;
    top: 10%; /* Moved up significantly from 42% */
    left: 50%;
    transform: translate(-50%, -50%);
    width: 85%;
    background: linear-gradient(to bottom, #1d65b2, rgba(255, 255, 255, 0)); 
    border-radius: 0;
    padding: 30px 25px 60px 25px;
    box-shadow: none;
    animation: fadeInUpStatic 0.8s ease-out forwards;
    color: #fff;
    z-index: 5; /* Ensure it's behind the camera */
    margin-left: -42%;
}

/* 文本样式重置 */
.rules-text-block {
    font-size: 15px;
    line-height: 1.8;
    text-align: justify;
    text-indent: 2em;
    color: #fff;
    text-shadow: none; /* Removed shadow if user wants flat look, or keep subtle? Removing for strict adherence */
}

.rules-text-block p {
    margin-bottom: 15px;
}

/* P2 Bottom Area for Camera and Button */
.p2-bottom-area {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: auto;
    z-index: 20;
    pointer-events: none; /* Allow clicks to pass through transparent areas if needed, but button needs events */
}

.p2-camera {
    position: absolute;
    bottom: 0;
    right: -10%; /* Shift right slightly */
    width: 60%;
    z-index: 10;
}

.p2-camera img {
    width: 100%;
    height: auto;
    display: block;
}

.p2-btn-start {
    position: absolute;
    bottom: 80px; /* Moved up from 12% to overlap camera more */
    left: 50%;
    transform: translateX(-50%);
    width: 40%;
    z-index: 30;
    cursor: pointer;
    pointer-events: auto;
    animation: pulse 2s infinite;
}

.p2-btn-start img {
    width: 100%;
    height: auto;
    display: block;
}

/* Animation for static position */
@keyframes fadeInUpStatic {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- P3: Scene Selection --- */
.page-p3 {
    background-image: url('../images/p3/p3_bg.png');
    position: relative;
    /* overflow-y: auto; Removed, internal scrolling now */
}

.scene-title {
    text-align: center;
    color: #fff;
    font-size: 22px;
    position: absolute;
    top: 10%;
    width: 100%;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    font-weight: bold;
    z-index: 10;
}

.scene-selection-wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -55%);
    width: 90%;
  
    background: rgba(30, 80, 160, 0.6); /* Semi-transparent blue */
    border: 2px solid #fff; /* White stroke */
    border-radius: 20px; /* Rounded rectangle */
    overflow-y: auto; /* Scroll inside the box */
    padding: 15px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.scene-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    padding-bottom: 20px;
}

/* P3: Scene Selection Item Styling */
.scene-item {
    background: transparent; /* Changed from white to transparent */
    border-radius: 10px;
   
    /* box-shadow: 0 2px 5px rgba(0,0,0,0.1); Removed shadow from container */
    cursor: pointer;
    transition: transform 0.2s;
    border: none; /* Handled by internal border or removed */
    position: relative; /* For absolute positioning of label */
    margin-bottom: 10px;
}

.scene-item.active {
    /* border-color: #FF7E5F;  Removed border highlight style */
    transform: scale(0.98);
}

.scene-item.active img {
    border: 3px solid #FF7E5F; /* Highlight image instead */
}

.scene-item:active {
    transform: scale(0.95);
}

.scene-item img {
    width: 100%;
    height: 100px; /* Adjust height as needed */
    object-fit: cover;
    display: block;
    border-radius: 5px; /* Slight radius for image */
    box-sizing: border-box;
    border: 3px solid transparent; /* Reserve space for border */
}

.scene-name {
    position: absolute;
    bottom: -8px; /* Overlap the bottom of the image */
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    color: #000;
    font-size: 12px;
    font-weight: bold;
    padding: 4px 12px;
    border-radius: 15px; /* Pill shape */
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    white-space: nowrap;
    z-index: 5;
    min-width: 80%; /* Ensure it's not too narrow */
    text-align: center;
}

.p3-btn-start {
    position: absolute;
    bottom: 3%;
    left: 50%;
    transform: translateX(-50%);
    width: 40%;
    z-index: 30;
    cursor: pointer;
    animation: pulse 2s infinite;
}

.p3-btn-start img {
    width: 100%;
    height: auto;
    display: block;
}

/* --- P4: Upload --- */
.page-p4 {
    background-image: url('../images/p4/p4_bg.png');
    position: relative;
}

.upload-panel {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 85%;
    background: rgba(30, 80, 160, 0.7); /* Blue translucent box */
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.3); /* White outer glow */
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Upload Area */
.upload-area {
    width: 100%;
    height: 200px;
    position: relative;
    margin-bottom: 20px;
    cursor: pointer;
    overflow: hidden;
    border-radius: 10px;
}

.upload-bg-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

.upload-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.2); /* Slight dim for contrast */
}

.upload-icon-img {
    width: 80px;
    height: 80px;
    margin-bottom: 10px;
    object-fit: contain;
}

.upload-text {
    font-size: 16px;
    color: #fff;
    font-weight: bold;
}

.user-photo-preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain; /* Contain to show full photo */
    z-index: 3;
    background: #000; /* Black bg for aspect ratio gaps */
}

/* Instructions */
.upload-instructions {
    width: 100%;
    color: #fff;
    font-size: 13px;
    line-height: 1.6;
    text-align: left;
}

.upload-instructions p {
    margin-bottom: 5px;
}

/* Bottom Buttons */
.p4-btn-group {
    position: absolute;
    bottom: 8%;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 20px;
    z-index: 30;
}

.p4-btn {
    width: 40%;
    cursor: pointer;
    transition: transform 0.1s;
}

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

.p4-btn img {
    width: 100%;
    height: auto;
    display: block;
}

/* Modal Styles */
.custom-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
}

.modal-content img {
    max-width: 100%;
    max-height: 80vh;
    border-radius: 5px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.close-modal {
    position: absolute;
    top: -40px;
    right: 0;
    color: white;
    font-size: 30px;
    cursor: pointer;
    font-weight: bold;
}

/* Loading Modal */
.loading-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s;
}

.loading-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    width: 80%;
    max-width: 300px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    animation: zoomIn 0.3s ease-out;
}

.loading-spinner {
    margin-bottom: 20px;
}

.spinner-icon {
    font-size: 40px;
    animation: spin 2s infinite linear;
    display: inline-block;
}

.loading-text {
    color: #333;
    font-size: 16px;
    line-height: 1.5;
    font-weight: bold;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --- P5: Editor / Preview --- */
.page-p5 {
    background-image: url('../images/p5/p5_bg.png');
    position: relative;
}

.editor-panel {
    position: absolute;
    top: 48%; /* Adjusted to fit layout */
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    height: 80%; /* Takes up most of the screen */
    background: rgba(30, 80, 160, 0.8); /* Blue panel */
    border-radius: 15px;
    padding: 15px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
}

.editor-preview {
    width: 100%;
    height: 50%; /* Top half for preview */
    background: #fff;
    border-radius: 10px;
    margin-bottom: 15px;
    position: relative;
    overflow: hidden; /* Restore overflow hidden as requested */
    border: 2px solid #fff;
}

.editor-bg-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 10px;
    z-index: 0;
}

.editor-scene-bg {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
}

.editor-person {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    max-height: 90%; /* Adjust as needed */
    width: auto;
    z-index: 5;
}

.editor-grid-wrapper {
    flex: 1;
    overflow-y: auto; /* Scrollable grid */
    padding-right: 5px; /* Space for scrollbar */
}

.editor-scene-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 3 columns */
    gap: 10px;
}

.editor-scene-item {
    cursor: pointer;
    position: relative;
    transition: transform 0.1s;
}

.editor-scene-item:active {
    transform: scale(0.95);
}

.editor-scene-item img {
    width: 100%;
    height: 60px; /* Smaller thumbnails */
    object-fit: cover;
    border-radius: 5px;
    display: block;
    margin-bottom: 5px; /* Space for caption */
}

.editor-scene-name {
    background: #fff;
    color: #000;
    font-size: 10px;
    padding: 2px 5px;
    border-radius: 10px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

/* Bottom Buttons P5 */
.p5-btn-group {
    position: absolute;
    bottom: 5%;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 20px;
    z-index: 30;
}

.p5-btn {
    width: 40%;
    cursor: pointer;
    transition: transform 0.1s;
}

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

.p5-btn img {
    width: 100%;
    height: auto;
    display: block;
}

/* P5 Control Frame */
.control-frame {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 2px dotted red;
    box-sizing: border-box;
    pointer-events: none; /* Let touches pass through to image for moving */
}

.btn-close {
    position: absolute;
    top: -15px;
    left: -15px;
    width: 30px;
    height: 30px;
    background: red;
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 28px;
    font-weight: bold;
    font-size: 20px;
    cursor: pointer;
    pointer-events: auto; /* Enable clicking */
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.btn-resize {
    position: absolute;
    bottom: -15px;
    right: -15px;
    width: 30px;
    height: 30px;
    background: #007bff; /* Blue */
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: nwse-resize;
    pointer-events: auto; /* Enable dragging */
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.btn-resize svg {
    width: 20px;
    height: 20px;
    stroke: white;
}
.page-p6 {
    background-image: url('../images/p6/p6_bg.png');
}

.result-card {
    position: absolute;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    background: #fff;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    animation: zoomIn 0.5s ease-out forwards;
}

.result-img {
    width: 100%;
    height: auto;
    border-radius: 5px;
    display: block;
}

.save-tip {
    text-align: center;
    color: #fff;
    font-size: 14px;
    margin-top: 20px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    position: absolute;
    top: 65%; /* Below result card */
    width: 100%;
}

.action-bar {
    position: absolute;
    bottom: 8%;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 20px;
}

.btn-secondary {
    background: #fff;
    color: #333;
    padding: 10px 30px;
    border-radius: 25px;
    font-size: 14px;
    border: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    cursor: pointer;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(45deg, #FF7E5F, #FEB47B);
    color: white;
    padding: 10px 30px;
    border-radius: 25px;
    font-size: 14px;
    border: none;
    box-shadow: 0 5px 10px rgba(255, 126, 95, 0.3);
    cursor: pointer;
    text-decoration: none;
}

/* --- P7: Share/End --- */
.page-p7 {
    /* Fallback if p7_bg doesn't exist, reuse p1 or a color */
    background-color: #eef2f3; 
}

.end-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px;
}

.end-logo {
    width: 80%;
    margin-bottom: 40px;
    animation: fadeInDown 1s ease-out;
}

.end-icon {
    width: 40%;
    margin-bottom: 40px;
    animation: pulse 3s infinite;
}

.end-text {
    font-size: 20px;
    color: #333;
    font-weight: bold;
    text-align: center;
    margin-bottom: 30px;
}

/* Animations Helper */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes zoomIn {
    from { opacity: 0; transform: translateX(-50%) scale(0.8); }
    to { opacity: 1; transform: translateX(-50%) scale(1); }
}
