/* =========================================
   Design System & Variables
   ========================================= */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --success-color: #10b981;
    
    --poster-width: 1080px;
    --poster-height: 1350px; /* 4:5 Aspect Ratio */
    
    /* Using fluid sizes for poster to scale via CSS transform instead of responsive units inside poster */
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* =========================================
   Layout
   ========================================= */
.app-header {
    text-align: center;
    padding: 1rem;
    background: var(--card-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 10;
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
}

.app-header p {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.workspace {
    display: flex;
    flex-direction: column;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    gap: 1.5rem;
}

@media (min-width: 1024px) {
    .workspace {
        flex-direction: row;
        align-items: flex-start;
        padding: 2rem;
    }
    
    .preview-section {
        flex: 1;
        position: sticky;
        top: 100px;
    }
    
    .controls-section {
        width: 450px;
        flex-shrink: 0;
    }
}

/* =========================================
   Poster Preview Area container
   ========================================= */
.preview-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    width: 100%;
}

/* We render the poster at high resolution (1080x1350) and scale it down using CSS transform to fit screen */
.poster-container {
    width: var(--poster-width);
    height: var(--poster-height);
    position: relative;
    overflow: hidden;
    background-color: #000;
    transform-origin: top center;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    border-radius: 4px; /* Optional slight rounding for preview */
}

/* Scale handling for preview */
/* For mobile screens (assume max width 400px), we scale factor = ScreenWidth / 1080 */
/* It will be calculated in JS but we set a default max-width block wrapper here */


/* =========================================
   Poster Internals (1080x1350 scale)
   ========================================= */
.poster-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    z-index: 1;
}

.poster-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 60px 40px;
}

/* Logos Header */
.poster-logos {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 0 40px;
    align-items: flex-start;
}

.logo-left, .logo-right {
    height: 90px;
    object-fit: contain;
    max-width: 250px;
    filter: drop-shadow(0px 4px 6px rgba(0,0,0,0.3));
}

/* Main Congratulations Title */
.poster-title-container {
    margin-top: 50px;
    margin-bottom: 50px;
    text-align: center;
    width: 100%;
    z-index: 10;
}

.ribbon-wrapper {
    position: relative;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    filter: drop-shadow(0 15px 15px rgba(0,0,0,0.5)); 
    margin: 40px 0;
}

.ribbon {
    position: relative;
    padding: 20px 60px;
    border-radius: 50% 50% 10% 10% / 60px 60px 10px 10px; /* Nice Arch */
    z-index: 2;
    border: 3px solid rgba(255,255,255,0.4);
    display: inline-block;
    min-width: 600px;
    box-shadow: inset 0 -5px 15px rgba(0,0,0,0.2);
    background: linear-gradient(90deg, #d4af37 0%, #fbd63c 100%);
}

.ribbon-tail-left, .ribbon-tail-right {
    position: absolute;
    top: 50%;
    transform: translateY(-20px);
    height: 0;
    width: 0;
    z-index: 1;
    filter: brightness(0.65);
}

.ribbon-tail-left {
    left: -70px;
    border-top: 50px solid #d4af37;
    border-bottom: 50px solid #d4af37;
    border-right: 50px solid #d4af37;
    border-left: 50px solid transparent;
}

.ribbon-tail-right {
    right: -70px;
    border-top: 50px solid #d4af37;
    border-bottom: 50px solid #d4af37;
    border-left: 50px solid #d4af37;
    border-right: 50px solid transparent;
}

.congratulations-text {
    font-family: 'Playfair Display', serif;
    font-size: 80px;
    font-weight: 800;
    line-height: 1.1;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 4px 8px rgba(0,0,0,0.4);
    max-width: 100%;
    overflow-wrap: break-word;
    word-break: break-word;
    padding: 0 10px;
    margin: 0;
}

/* Avatar Area */
.poster-avatar-area {
    position: relative;
    margin-bottom: 80px;
}

.avatar-frame {
    width: 500px;
    height: 500px;
    border-radius: 50%;
    padding: 15px; /* Border thickness */
    background: linear-gradient(135deg, #fbd63c 0%, #d4af37 50%, #fbd63c 100%);
    box-shadow: 0 15px 35px rgba(0,0,0,0.5), inset 0 0 20px rgba(0,0,0,0.5);
    touch-action: none;
    overscroll-behavior: contain;
}

.avatar-viewport {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
    position: relative;
    background-color: #2c2c2c;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    overscroll-behavior: contain;
}

.avatar-image {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1);
    transform-origin: center center;
    min-width: 100%;
    min-height: 100%;
    cursor: grab;
    object-fit: cover;
    touch-action: none;
    -webkit-user-drag: none;
    user-select: none;
    -webkit-user-select: none;
}

.avatar-image:active {
    cursor: grabbing;
}

.avatar-image.placeholder {
    opacity: 0; /* hidden initial */
}

.avatar-placeholder-icon {
    font-size: 150px;
    color: rgba(255,255,255,0.2);
    position: absolute;
    pointer-events: none;
}

/* Rank Badge */
.rank-badge-container {
    position: absolute;
    bottom: -10px;
    right: -10px;
    width: 180px;
    height: 180px;
    background: radial-gradient(circle, #fff 0%, #e0e0e0 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.6);
    border: 6px solid #d4af37;
    z-index: 5;
}

.rank-badge {
    width: 120px;
    height: 120px;
    object-fit: contain;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3));
}

/* Details Section */
.poster-details {
    text-align: center;
    width: 100%;
    padding: 0 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: rgba(0,0,0,0.2);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: 30px;
    padding: 40px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
}

.person-name {
    font-family: 'Montserrat', sans-serif;
    font-size: 90px;
    font-weight: 800;
    line-height: 1.1;
    text-transform: uppercase;
    text-shadow: 0 4px 8px rgba(0,0,0,0.6);
}

.achievement-title {
    font-family: 'Inter', sans-serif;
    font-size: 55px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.6);
    padding-bottom: 20px;
    margin-top: -20px;
}


/* =========================================
   Controls / Editor Panel
   ========================================= */
.controls-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border: 1px solid var(--border-color);
}

.controls-card h2 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    font-weight: 600;
    border-bottom: 2px solid var(--bg-color);
    padding-bottom: 0.5rem;
}

.control-group {
    margin-bottom: 1.5rem;
}

.control-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.sub-label {
    font-size: 0.75rem !important;
    font-weight: 500 !important;
    color: var(--text-muted) !important;
}

/* Interactive Galleries */
.scrollable-gallery {
    display: flex;
    overflow-x: auto;
    gap: 0.75rem;
    padding-bottom: 0.75rem;
}

/* Custom Scrollbar for Galleries */
.scrollable-gallery::-webkit-scrollbar {
    height: 8px;
}
.scrollable-gallery::-webkit-scrollbar-track {
    background: var(--bg-color);
    border-radius: 4px;
}
.scrollable-gallery::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
.scrollable-gallery::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.gallery-item {
    height: 70px;
    min-width: 50px;
    border-radius: 8px;
    object-fit: cover;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    background-color: var(--bg-color);
}

.gallery-item.active {
    border-color: var(--primary-color);
    transform: scale(1.05);
    box-shadow: 0 4px 6px rgba(99, 102, 241, 0.3);
}

/* Upload Actions */
.hidden-input {
    display: none;
}

.photo-upload-actions {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.photo-adjustment {
    background: var(--bg-color);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 1rem;
}

.help-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 0.5rem;
}

.zoom-control {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text-muted);
}

.zoom-control input[type=range] {
    flex: 1;
    accent-color: var(--primary-color);
}

/* Text Inputs */
.input-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.input-col {
    flex: 1;
}

.form-control {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.color-picker {
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    background: none;
    margin-top: 1.125rem; /* align with input field below label */
}

.color-picker::-webkit-color-swatch-wrapper {
    padding: 2px;
}
.color-picker::-webkit-color-swatch {
    border-radius: 4px;
    border: none;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    width: 100%;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}
.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(99, 102, 241, 0.2);
}

.btn-large {
    padding: 1rem 1.5rem;
    font-size: 1rem;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: var(--bg-color);
    border-color: #d1d5db;
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover {
    background-color: #059669;
    box-shadow: 0 4px 6px rgba(16, 185, 129, 0.2);
}

/* =========================================
   Modal Output
   ========================================= */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.8);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--card-bg);
    margin: 5vh auto;
    width: 90%;
    max-width: 500px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.close-modal {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

.close-modal:hover {
    color: var(--text-main);
}

.modal-body {
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    background-color: #e5e5e5;
}

#generated-image {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.modal-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* =========================================
   Utility
   ========================================= */
.preview-actions {
    width: 100%;
    max-width: 400px;
    margin-top: 1rem;
}

html.is-dragging-avatar,
body.is-dragging-avatar {
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
}

body.is-dragging-avatar {
    position: fixed;
    left: 0;
    right: 0;
    width: 100%;
}






