html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: Arial, sans-serif;
    background: #eef2f7;
    overflow-x: hidden;
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: border-box;
}

/* Header Banner Styles */
.page-header {
    background: #2f56a6;
    color: white;
    padding: 12px 0;
    text-align: center;
    width: 100%;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 0.5px;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 8px auto;
    padding: 20px 15px 0 15px;
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.left-panel {
    flex: 1;
    display: flex;
    justify-content: center;
    min-width: 0; /* Allow flex item to shrink below content size */
}

#posterCanvas {
    width: 100%;
    max-width: 480px;
    height: auto !important;
    aspect-ratio: 1 / 1;
    border-radius: 15px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.15);
    background: white;
    display: block;
    object-fit: contain;
}

canvas {
    width: 100%;
    max-width: 480px;
    height: auto;
    aspect-ratio: 1 / 1;
    border-radius: 15px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.15);
    background: white;
    display: block;
    object-fit: contain;
}

.right-panel {
    width: 350px;
    flex-shrink: 0;
}

.card {
    background: #2f56a6;
    padding: 25px;
    border-radius: 14px;
    margin-bottom: 25px;
    color: white;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}

.card h3 {
    margin-top: 0;
    margin-bottom: 15px;
}

/* Upload card specific styling */
.upload-card {
    padding: 20px;
}

.upload-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.upload-text {
    flex: 1;
}

.upload-text h3 {
    margin-top: 0;
    margin-bottom: 8px;
    font-size: 18px;
    font-weight: bold;
}

.upload-text p {
    margin: 0;
    font-size: 14px;
    line-height: 1.4;
    opacity: 0.95;
}

.upload-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    background: white;
    border: 1px solid #000000;
    border-radius: 50%;
    cursor: pointer;
    transition: 0.2s;
    flex-shrink: 0;
}

.upload-icon-btn:hover {
    background: #f0f0f0;
    transform: scale(1.05);
}

.upload-icon-btn svg {
    display: block;
}

.card input {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
}

#nameInput {
    width: 90%; /* Reduced width instead of 100% */
    padding-right: 20px; /* Extra padding on right side */
}

#charCount {
    display: block;
    margin-top: 8px;
    font-size: 12px;
    text-align: right;
    opacity: 0.8;
}

.download-btn {
    width: 100%;
    padding: 16px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 40px;
    background: linear-gradient(135deg, #2f56a6, #1c3f85);
    color: white;
    cursor: pointer;
    transition: 0.3s;
    box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 25px rgba(0,0,0,0.3);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: bold;
    color: #000;
}

.modal-close {
    font-size: 28px;
    font-weight: bold;
    color: #999;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #000;
}

.modal-body {
    padding: 40px 24px;
}

.upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 40px;
    border: 2px dashed #2f56a6;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    background-color: #f8f9fa;
}

.upload-area:hover {
    border-color: #1c3f85;
    background-color: #f0f2f5;
}

.upload-icon-large {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100px;
    height: 100px;
    background: #e3f2fd;
    border: 1px solid #90caf9;
    border-radius: 50%;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(47, 86, 166, 0.1);
}

.upload-icon-large svg {
    display: block;
}

.upload-area p {
    margin: 0;
    font-size: 16px;
    color: #424242;
    font-weight: 500;
    letter-spacing: 0.3px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid #e0e0e0;
}

.btn-cancel,
.btn-confirm {
    padding: 10px 24px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.btn-cancel {
    background: white;
    border: 1px solid #d0d0d0;
    color: #000;
}

.btn-cancel:hover {
    background: #f5f5f5;
    border-color: #999;
}

.btn-confirm {
    background: #2f56a6;
    color: white;
}

.btn-confirm:hover {
    background: #1c3f85;
}

/* Edit Image Modal Styles */
.edit-modal-content {
    max-width: 600px;
    background: #ffffff;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.edit-modal-body {
    padding: 24px;
    background: #fafafa;
}

.image-preview-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    margin: 0 auto 24px;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 250px;
    max-height: 300px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#imagePreviewCanvas {
    max-width: 100%;
    max-height: 280px;
    display: block;
    image-rendering: auto;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: smooth;
}

.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    background-image: 
        linear-gradient(to right, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0.5) 33.33%, transparent 33.33%, transparent 66.66%, rgba(255,255,255,0.5) 66.66%, rgba(255,255,255,0.5) 100%),
        linear-gradient(to bottom, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0.5) 33.33%, transparent 33.33%, transparent 66.66%, rgba(255,255,255,0.5) 66.66%, rgba(255,255,255,0.5) 100%);
    background-size: 3px 100%, 100% 3px;
}

.image-controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 500px;
}

.zoom-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: white;
    border-radius: 8px;
    font-size: 24px;
    font-weight: normal;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: #333;
    user-select: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.zoom-btn:hover {
    background: #f5f5f5;
    box-shadow: 0 3px 6px rgba(0,0,0,0.15);
}

.zoom-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.zoom-slider-wrapper {
    flex: 1;
    position: relative;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
}

.zoom-slider {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    margin: 0;
    padding: 0;
    background: transparent;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    z-index: 2;
}

.zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #2f56a6;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.2s;
}

.zoom-slider::-webkit-slider-thumb:hover {
    background: #1c3f85;
    transform: scale(1.15);
}

.zoom-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #2f56a6;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.2s;
}

.zoom-slider::-moz-range-thumb:hover {
    background: #1c3f85;
    transform: scale(1.15);
}

.zoom-slider-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: #2f56a6;
    border-radius: 4px;
    pointer-events: none;
    z-index: 1;
}

.rotation-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 500px;
}

.rotate-btn {
    width: 48px;
    height: 48px;
    border: 1px solid #d0d0d0;
    background: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: #333;
    user-select: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.rotate-btn:hover {
    background: #f0f0f0;
    border-color: #2f56a6;
    transform: scale(1.05);
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

.rotate-btn:active {
    transform: scale(0.95);
    background: #e0e0e0;
}

.rotate-btn svg {
    display: block;
}

.rotation-slider-wrapper {
    flex: 1;
    position: relative;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
}

.rotation-slider {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    margin: 0;
    padding: 0;
    background: transparent;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    z-index: 2;
}

.rotation-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #2f56a6;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.2s;
}

.rotation-slider::-webkit-slider-thumb:hover {
    background: #1c3f85;
    transform: scale(1.15);
}

.rotation-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #2f56a6;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.2s;
}

.rotation-slider::-moz-range-thumb:hover {
    background: #1c3f85;
    transform: scale(1.15);
}

.rotation-slider-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: #2f56a6;
    border-radius: 4px;
    pointer-events: none;
    z-index: 1;
}

.edit-modal-close {
    font-size: 28px;
    font-weight: bold;
    color: #999;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.edit-modal-close:hover {
    color: #000;
}

/* Footer Styles */
.page-footer {
    background: linear-gradient(to bottom, #f5f5f5, #fafafa);
    border-top: 1px solid #d0d0d0;
    padding: 7px 10px;
    margin-top: 10px;
    flex-shrink: 0;
    width: 100%;
}

.footer-content {
    max-width: 1300px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    padding-left: 0;
}

.footer-logo {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.upnext-logo {
    display: flex;
    gap: 2px;
    align-items: center;
}

.logo-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    font-size: 20px;
    font-weight: bold;
    color: #FFFFFF;
    font-family: Arial, sans-serif;
    border-radius: 4px;
}

.logo-subtext {
    font-size: 9px;
    color: #4361EE;
    font-weight: 500;
    letter-spacing: 0.5px;
    margin-left: 2px;
    margin-top: 2px;
}

.footer-copyright {
    font-size: 13px;
    color: #666;
    font-weight: 400;
    line-height: 1.5;
}

/* Responsive */
@media (max-width: 1000px) {
    .container {
        flex-direction: column;
        align-items: center;
    }

    .right-panel {
        width: 100%;
        max-width: 400px;
    }
    
    .footer-content {
        flex-direction: column;
        text-align: center;
        align-items: center;
    }
    
    .footer-logo {
        align-items: center;
    }
}

/* Mobile: Android & iOS phones – canvas fully visible, never cut */
@media (max-width: 768px) {
    html {
        overflow-x: hidden;
        width: 100%;
    }

    body {
        max-height: none;
        min-height: 100vh;
        overflow-x: hidden;
        overflow-y: auto;
        width: 100%;
        max-width: 100vw;
    }

    .container {
        width: 100%;
        max-width: 100vw;
        padding: 12px 12px 0;
        margin: 0 auto;
        min-height: 0;
        overflow-x: hidden;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
    }

    .left-panel {
        width: 100%;
        max-width: 100vw;
        min-width: 0;
        padding: 0 12px;
        overflow: visible;
        flex-shrink: 0;
        display: flex;
        justify-content: center;
        align-items: flex-start;
    }

    /* Canvas: size by vmin so it never gets cut on any side (fits in viewport) */
    #posterCanvas,
    .left-panel canvas {
        width: auto !important;
        max-width: min(85vmin, calc(100vw - 24px)) !important;
        height: auto !important;
        max-height: min(85vmin, calc(100vh - 200px)) !important;
        aspect-ratio: 1 / 1;
        display: block;
        object-fit: contain;
        margin-top: 55%;
    }

    .right-panel {
        max-width: 100%;
        padding: 0 4px;
    }

    .card {
        padding: 18px;
        margin-bottom: 16px;
    }

    .upload-content {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .upload-icon-btn {
        align-self: center;
    }

    .page-header {
        padding: 10px 12px;
    }

    .header-content {
        font-size: 14px;
        padding: 0 8px;
    }

    .page-footer {
        padding: 10px 12px;
    }

    .footer-copyright {
        font-size: 11px;
    }
}

/* All mobile breakpoints: keep canvas within vmin so it never cuts */
@media (max-width: 768px) and (min-width: 415px) {
    #posterCanvas,
    .left-panel canvas {
        max-width: min(85vmin, calc(100vw - 24px)) !important;
        max-height: min(85vmin, calc(100vh - 200px)) !important;
        margin-top: 55%;
    }

    .container {
        padding: 16px 10px 0;
    }
}

@media (max-width: 414px) and (min-width: 361px) {
    #posterCanvas,
    .left-panel canvas {
        max-width: min(85vmin, calc(100vw - 24px)) !important;
        max-height: min(85vmin, calc(100vh - 200px)) !important;
        margin-top: 25%;
    }

    .container {
        padding: 12px 12px 0;
    }
}

@media (max-width: 360px) and (min-width: 321px) {
    #posterCanvas,
    .left-panel canvas {
        max-width: min(85vmin, calc(100vw - 20px)) !important;
        max-height: min(85vmin, calc(100vh - 180px)) !important;
        margin-top: 55%;
    }

    .container {
        padding: 10px 10px 0;
    }
}

@media (max-width: 320px) {
    #posterCanvas,
    .left-panel canvas {
        max-width: min(85vmin, calc(100vw - 16px)) !important;
        max-height: min(85vmin, calc(100vh - 160px)) !important;
        margin-top: 55%;
    }

    .container {
        padding: 8px 8px 0;
    }

    .card {
        padding: 14px;
        margin-bottom: 12px;
    }

    .header-content {
        font-size: 13px;
    }
}

@media (max-width: 400px) and (min-width: 385px) {
    #posterCanvas,
    .left-panel canvas {
        max-width: min(85vmin, calc(100vw - 24px)) !important;
        max-height: min(85vmin, calc(100vh - 200px)) !important;
        margin-top: 25%;
    }
}

@media (max-width: 420px) and (min-width: 408px) {
    #posterCanvas,
    .left-panel canvas {
        max-width: min(85vmin, calc(100vw - 24px)) !important;
        max-height: min(85vmin, calc(100vh - 200px)) !important;
        margin-top: 25%;
    }
}

/* Mobile phones – stack layout, scroll if needed, canvas never cut */
@media (max-width: 768px) {
    html,
    body {
        height: auto;
        min-height: 100vh;
        max-height: none;
        overflow-x: hidden;
        overflow-y: auto;
        width: 100%;
        max-width: 100vw;
    }

    .container {
        flex-direction: column;
        align-items: center;
        width: 100%;
        max-width: 100vw;
        padding: 12px 12px 16px;
        margin: 0 auto;
        min-height: 0;
        overflow: visible;
        -webkit-overflow-scrolling: touch;
    }

    .left-panel {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        padding: 0;
        margin: 0;
        overflow: visible;
        flex-shrink: 0;
        display: flex;
        justify-content: center;
        align-items: flex-start;
    }

    #posterCanvas,
    .left-panel canvas {
        width: 100% !important;
        max-width: 480px;
        height: auto !important;
        aspect-ratio: 1 / 1;
        display: block;
        object-fit: contain;
        margin: 16px auto 0;
    }

    .right-panel {
        width: 100%;
        max-width: 480px;
        padding: 12px 0 0;
    }

    .card {
        padding: 18px;
        margin-bottom: 16px;
    }

    .upload-content {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .upload-icon-btn {
        align-self: center;
    }

    .page-header {
        padding: 10px 12px;
    }

    .header-content {
        font-size: 14px;
        padding: 0 8px;
    }

    .page-footer {
        padding: 10px 12px;
    }
}

/* Short screens – reduce top margin & width slightly */
@media (max-width: 768px) and (max-height: 600px) {
    #posterCanvas,
    .left-panel canvas {
        margin-top: 8px;
        max-width: min(420px, 100vw - 24px);
    }
}

/* Very narrow screens – slightly tighter padding and margin */
@media (max-width: 360px) {
    .container {
        padding: 8px 8px 12px;
    }

    #posterCanvas,
    .left-panel canvas {
        margin-top: 8px;
    }

    .card {
        padding: 14px;
        margin-bottom: 12px;
    }

    .header-content {
        font-size: 13px;
    }
}