/* Base Styles */
:root {
    --primary-color: #ff80bf;
    --secondary-color: #9580ff;
    --background-color: #ffeeff;
    --text-color: #333;
    --button-color: #ff69b4;
    --button-hover: #ff5aad;
    --white: #ffffff;
    --black: #000000;
    --gray: #f0f0f0;
    --shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    --border-radius: 12px;
    
    /* Template Colors - Updated as per request */
    --basic-color: #ffffff; /* Text color for basic black template */
    --basic-bg: #000000;    /* Background color for basic black template */
    --pastel1-color: #4a90e2; /* Sky blue */
    --pastel1-bg: #e6f2ff;
    --pastel2-color: #ffb700; /* Yellow */
    --pastel2-bg: #fff9e6;
}

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

body {
    font-family: 'Sunflower', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Typography */
h1, h2, h3 {
    margin-bottom: 20px;
}

.main-title {
    font-family: 'Do Hyeon', sans-serif;
    font-size: 2.5rem;
    text-align: center;
    color: var(--primary-color);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    margin: 20px 0;
}

h2 {
    font-family: 'Sunflower', sans-serif;
    font-weight: 700;
    font-size: 1.8rem;
    color: var(--secondary-color);
    text-align: center;
}

p {
    margin-bottom: 15px;
}

.instructions {
    text-align: center;
    font-size: 1.2rem;
    margin-bottom: 20px;
}

/* Layout */
header, footer {
    text-align: center;
    padding: 20px 0;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

footer a:hover {
    color: var(--button-hover);
    text-decoration: underline;
}

main {
    min-height: 80vh;
}

section.step {
    display: none;
    padding: 20px;
    background-color: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 30px;
}

section.active {
    display: block;
}

.navigation {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 30px;
}

/* Buttons */
button {
    font-family: 'Sunflower', sans-serif;
    font-weight: 500;
    padding: 10px 20px;
    cursor: pointer;
    border: none;
    border-radius: 30px;
    transition: all 0.3s ease;
}

.next-btn, .primary-btn {
    background-color: var(--button-color);
    color: var(--white);
}

.next-btn:hover, .primary-btn:hover {
    background-color: var(--button-hover);
    transform: translateY(-2px);
}

.back-btn, .secondary-btn {
    background-color: var(--gray);
    color: var(--text-color);
}

.back-btn:hover, .secondary-btn:hover {
    background-color: #e0e0e0;
    transform: translateY(-2px);
}

button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
    transform: none;
}

.control-btn {
    background-color: var(--secondary-color);
    color: var(--white);
    margin: 0 5px;
}

.control-btn:hover {
    background-color: #8470ee;
}

/* Template Selection */
.frame-selection-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 60px;
    margin: 30px 0;
}

.layout-or {
    font-size: 36px;
    font-weight: 900;
    margin: 0 20px;
    display: flex;
    align-items: center;
}

.template-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    padding: 0;
    transition: all 0.3s ease;
    background-color: transparent;
}

.template-option:hover .frame-preview {
    transform: scale(1.03);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.template-option.selected .frame-preview {
    box-shadow: 0 0 0 3px var(--primary-color), 0 5px 15px rgba(0, 0, 0, 0.3);
}

.frame-preview {
    background-color: black;
    padding: 10px;
    position: relative;
    border: 5px solid black;
    margin-bottom: 0;
    transition: all 0.3s ease;
}

.frame-preview.vertical {
    width: 180px;
    height: 400px;
    display: grid;
    grid-template-rows: repeat(4, 1fr);
    grid-gap: 10px;
    border-width: 3px; /* Thinner border for cleaner look */
}

.frame-preview.grid {
    width: 300px;
    height: 210px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    grid-gap: 10px;
    border-width: 3px; /* Thinner border for cleaner look */
}

.photo-slot {
    background-color: white;
}

/* Camera Section */
.camera-container {
    position: relative;
    width: 100%;
    max-width: 640px;
    height: 60vh;
    margin: 0 auto 20px;
    overflow: hidden;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    background-color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.camera-controls {
    display: flex;
    justify-content: center;
    margin: 15px 0;
}

.photo-status {
    text-align: center;
    font-size: 1.2rem;
    margin: 10px 0;
}

.photo-strip {
    display: flex;
    overflow-x: auto;
    margin: 15px 0;
    padding: 10px;
    background-color: var(--gray);
    border-radius: var(--border-radius);
    scrollbar-width: thin;
}

.photo-thumbnail {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
    margin-right: 10px;
    border-radius: 5px;
    object-fit: cover;
    transition: transform 0.3s ease;
    cursor: pointer;
}

.photo-thumbnail:hover {
    transform: scale(1.05);
}

/* Smartphone overlay */
.smartphone-overlay {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 30px;
    overflow: hidden;
    border: 10px solid #222;
    box-shadow: 0 0 0 2px #444;
}

/* 카메라 권한 안내 텍스트 */
#camera-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1;
    text-align: center;
    padding: 20px;
    font-size: 1.2rem;
}

/* 모바일 세로 모드에서 카메라 가로 표시 */
@media screen and (max-width: 768px) and (orientation: portrait) {
    .camera-container {
        height: 50vh; /* 세로 모드에서 높이 조정 */
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
        /* 최소 높이 지정으로 너무 작아지지 않도록 */
        min-height: 300px;
    }
    
    #camera-feed {
        position: absolute;
        width: 100%; 
        height: 100%;
        object-fit: cover;
        z-index: 2;
    }
    
    /* 세로 모드에서 비디오 회전 스타일 */
    #camera-feed.camera-portrait-mode {
        transform: rotate(-90deg);
        transform-origin: center;
        width: 150vh; /* 더 넓게 설정하여 꽉 차게 함 */
        height: auto;
        max-width: none;
        position: absolute;
        z-index: 5;
    }
    
    .smartphone-overlay {
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
        width: 100%;
        height: 100%;
        position: relative;
    }
}

.smartphone-notch {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 150px;
    height: 25px;
    background-color: #222;
    border-bottom-left-radius: 15px;
    border-bottom-right-radius: 15px;
    z-index: 10;
}

#countdown-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 5;
}

#countdown-overlay.active {
    pointer-events: auto;
}

#countdown {
    font-size: 5rem;
    color: white;
    background-color: rgba(0, 0, 0, 0.5);
    width: 100px;
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    margin-bottom: 20px;
}

.capture-now-btn {
    background-color: var(--primary-color);
    color: white;
    padding: 10px 20px;
    border-radius: 30px;
    border: none;
    font-family: 'Sunflower', sans-serif;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s;
    opacity: 0;
    margin-top: 20px;
}

#countdown-overlay.active .capture-now-btn {
    opacity: 1;
    pointer-events: auto;
}

.capture-now-btn:hover {
    background-color: var(--button-hover);
    transform: scale(1.05);
}

#flash-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: white;
    opacity: 0;
    pointer-events: none;
}

/* Photo Selection */
.selection-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin: 20px 0;
}

@media screen and (max-width: 768px) {
    .selection-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.selection-photo {
    position: relative;
    padding-bottom: 100%; /* Square aspect ratio */
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    box-shadow: var(--shadow);
}

.selection-photo img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover; /* 항상 프레임에 꽉 차게 표시 */
}

.selection-photo.selected::after {
    content: attr(data-order);
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: var(--primary-color);
    border: 2px solid white;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 16px;
}

.selection-photo.selected {
    box-shadow: 0 0 0 3px var(--primary-color);
}

/* Final Composition */
.composition-preview {
    width: 100%;
    max-width: 400px;
    margin: 0 auto 30px;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

#composition-container {
    width: 100%;
    padding-bottom: 280%; /* Aspect ratio for photostrip */
    position: relative;
    background-color: white;
}

#composition-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.custom-text-container {
    text-align: center;
    margin: 20px auto;
    max-width: 400px;
}

.custom-text-container label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.custom-text-container input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    margin-bottom: 10px;
    font-family: 'Sunflower', sans-serif;
}

/* Color Picker Styles */
.color-picker-container {
    text-align: center;
    margin: 20px auto;
    max-width: 400px;
}

.color-picker-container label {
    display: block;
    margin-bottom: 10px;
    font-weight: 500;
    font-size: 1.1rem;
}

/* Color palette grid */
.color-palette {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

@media screen and (max-width: 480px) {
    .color-palette {
        grid-template-columns: repeat(5, 1fr);
    }
}

.color-option {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    margin: 0 auto;
}

.color-option:hover {
    transform: scale(1.15);
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);
}

.color-option.selected {
    transform: scale(1.15);
    box-shadow: 0 0 0 3px var(--primary-color);
}

/* Hide but keep the original color input as fallback */
.color-picker-container input[type="color"] {
    width: 0;
    height: 0;
    padding: 0;
    border: none;
    position: absolute;
    opacity: 0;
}

/* Theme Selection Styles */
.theme-container {
    text-align: center;
    margin: 20px auto;
    max-width: 400px;
}

.theme-container label {
    display: block;
    margin-bottom: 10px;
    font-weight: 500;
    font-size: 1.1rem;
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

@media screen and (max-width: 480px) {
    .theme-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.theme-option {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    padding: 5px;
    border-radius: 10px;
}

.theme-option:hover {
    transform: scale(1.05);
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);
}

.theme-option.selected {
    transform: scale(1.05);
    box-shadow: 0 0 0 3px var(--primary-color);
}

.theme-preview {
    height: 60px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 5px;
    position: relative;
    overflow: hidden;
}

.theme-icon {
    font-size: 24px;
    position: relative;
    z-index: 2;
}

.theme-name {
    font-size: 0.9rem;
    font-weight: 500;
}

.image-adjustments {
    margin: 20px auto;
    max-width: 400px;
}

.adjustment-control {
    margin-bottom: 15px;
}

.adjustment-control label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.adjustment-control input[type="range"] {
    width: 100%;
    margin-bottom: 5px;
}

#brightness-value {
    font-size: 0.9rem;
    color: var(--secondary-color);
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 1000;
    color: white;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 15px;
}

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

@keyframes flash {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

/* Responsive Design */
@media screen and (max-width: 768px) {
    .main-title {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    .template-grid {
        grid-template-columns: 1fr;
    }

    /* Frame selection mobile adjustments */
    .frame-selection-container {
        gap: 30px;
        flex-direction: column;
    }
    
    .layout-or {
        margin: 0;
        font-size: 28px;
    }
    
    .frame-preview.vertical {
        width: 140px;
        height: 310px;
    }
    
    .frame-preview.grid {
        width: 220px;
        height: 160px;
    }

    /* Camera container mobile adjustments */
    .camera-container {
        height: auto;
        max-height: 70vh;
    }

    .camera-controls {
        flex-wrap: wrap;
        gap: 10px;
        justify-content: center;
    }

    .control-btn {
        margin: 5px;
        padding: 10px 15px;
        font-size: 0.95rem;
    }
    
    /* Navigation buttons mobile adjustments */
    .navigation {
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .navigation button {
        flex: 1;
        min-width: 0;
        padding: 10px;
        font-size: 0.95rem;
    }
    
    /* Custom text input mobile adjustments */
    .custom-text-container input {
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: 12px;
    }
}

/* Extra small devices (phones) */
@media screen and (max-width: 480px) {
    .frame-preview.vertical {
        width: 120px;
        height: 280px;
    }
    
    .frame-preview.grid {
        width: 200px;
        height: 140px;
    }
    
    .camera-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .control-btn, .primary-btn {
        width: 100%;
        margin: 5px 0;
    }
}
