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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #163d6e 0%, #071516 100%);
    min-height: 100vh;
    color: #333;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* background: rgba(0, 0, 0, 0.8); */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 2rem;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

/* Logo positioning above modal */
.logo-container {
    text-align: center;
    margin-bottom: 2rem;
}

.logo-link {
    text-decoration: none;
    cursor: pointer;
    transition: opacity 0.2s ease;
    display: inline-block;
}

.logo-link:hover {
    opacity: 0.8;
}

.itv-logo {
    height: 80px;
    width: auto;
    max-width: 300px;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    max-width: 90vw;
    max-height: 90vh;
    position: relative;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.cropper-modal-content {
    max-width: 80vw;
    max-height: 90vh;
    width: 900px;
}

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

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: #f0f0f0;
    color: #333;
}

/* Aspect Ratio Selection */
.aspect-ratio-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    margin-top: 2rem;
}

.aspect-ratio-option-btn {
    padding: 2rem 1.5rem;
    border: 3px solid #667eea;
    background: white;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.aspect-ratio-option-btn:hover {
    background: #667eea;
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
}

.aspect-ratio-option-btn:hover h3,
.aspect-ratio-option-btn:hover p {
    color: white;
}

.aspect-ratio-option-btn h3 {
    margin: 1rem 0 0.5rem;
    color: #333;
    font-size: 1.3rem;
    transition: color 0.3s ease;
}

.aspect-ratio-option-btn p {
    margin: 0;
    color: #666;
    font-size: 1rem;
    transition: color 0.3s ease;
}

.aspect-icon {
    width: 120px;
    height: 120px;
    margin: 0 auto;
    border: 3px solid #667eea;
    border-radius: 8px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    position: relative;
}

.aspect-16x9 {
    width: 160px;
    height: 90px;
}

.aspect-9x16 {
    width: 90px;
    height: 160px;
}

.aspect-4x3 {
    width: 144px;
    height: 108px;
}

/* Setup Modal */
.number-selector {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-top: 2rem;
}

.number-btn {
    padding: 1rem;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
}

.number-btn.hidden-for-pillar {
    display: none;
}

.number-btn.hidden-for-menu {
    display: none;
}

.number-btn:hover {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* Layout Selection */
.layout-selector {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2rem;
    margin-top: 2rem;
}

.layout-option {
    padding: 1.5rem;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
}

.layout-option:hover {
    border-color: #667eea;
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.2);
}

.layout-option.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.layout-option.disabled:hover {
    border-color: #e0e0e0;
}

.layout-preview {
    width: 120px;
    height: 68px;
    margin: 0 auto 1rem;
    border: 2px solid #ccc;
    border-radius: 4px;
    position: relative;
    background: #f8f9fa;
}

.columns-preview::after {
    content: '';
    position: absolute;
    top: 10%;
    bottom: 10%;
    left: 33.33%;
    width: 1px;
    background: #ccc;
}

.columns-preview::before {
    content: '';
    position: absolute;
    top: 10%;
    bottom: 10%;
    left: 66.66%;
    width: 1px;
    background: #ccc;
}

.grid-preview::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 10%;
    right: 10%;
    height: 1px;
    background: #ccc;
    transform: translateY(-50%);
}

.grid-preview::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 10%;
    bottom: 10%;
    width: 1px;
    background: #ccc;
    transform: translateX(-50%);
}

/* Portrait previews for Studio Pillar horizontal/diagonal layouts */
.horizontal-preview {
    width: 68px;
    height: 120px;
    margin: 0 auto 1rem;
    border: 2px solid #ccc;
    border-radius: 4px;
    position: relative;
    background: #f8f9fa;
}

.horizontal-preview::after {
    content: '';
    position: absolute;
    left: 10%;
    right: 10%;
    top: 50%;
    height: 1px;
    background: #ccc;
    transform: translateY(-50%);
}

.diagonal-preview {
    width: 68px;
    height: 120px;
    margin: 0 auto 1rem;
    border: 2px solid #ccc;
    border-radius: 4px;
    position: relative;
    background: #f8f9fa;
}

.diagonal-preview::before {
    content: '';
    position: absolute;
    left: 5%;
    right: 5%;
    top: 35%;
    height: 1px;
    background: #ccc;
    transform: rotate(-10deg);
    transform-origin: center;
}

.diagonal-preview::after {
    content: '';
    position: absolute;
    left: 5%;
    right: 5%;
    top: 65%;
    height: 1px;
    background: #ccc;
    transform: rotate(10deg);
    transform-origin: center;
}

.layout-option h3 {
    margin: 0 0 0.5rem 0;
    color: #333;
    font-size: 1.1rem;
}

.layout-option p {
    margin: 0;
    color: #666;
    font-size: 0.9rem;
}

/* Main App */
.main-app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

header {
    background: rgba(255, 255, 255, 0.95);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

header h1 {
    color: #333;
    font-size: 1.5rem;
}

.controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.grid-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #666;
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
}

.grid-toggle input[type="checkbox"] {
    margin: 0;
}

.separator-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #666;
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
}

.separator-toggle input[type="checkbox"] {
    margin: 0;
}

/* Buttons */
.btn {
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a6fd8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-secondary {
    background: #f8f9fa;
    color: #666;
    border: 1px solid #dee2e6;
}

.btn-secondary:hover {
    background: #e9ecef;
    color: #333;
}

/* Canvas Container */
main {
    flex: 1;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

.canvas-container {
    position: relative;
    background: white;
    border-radius: 0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    max-width: 90vw;
    max-height: 70vh;
    width: fit-content;
    margin: 0 auto;
}

#previewCanvas {
    display: block;
    max-width: 100%;
    max-height: 70vh;
    width: auto;
    height: auto;
}

.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    max-width: 100%;
    max-height: 70vh;
    width: auto;
    height: auto;
}

.grid-overlay.visible {
    opacity: 1;
}

.separator-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    max-width: 100%;
    max-height: 70vh;
    width: auto;
    height: auto;
}

.separator-overlay.visible {
    opacity: 1;
}

.slots-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
}

.slot {
    flex: 1;
    border: 2px dashed transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: rgba(102, 126, 234, 0.05);
}

.slot:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
}

.slot.has-image {
    background: transparent;
    border-color: transparent;
}

.slot.has-image:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
}

.slot-placeholder {
    color: #666;
    font-size: 0.9rem;
    text-align: center;
    pointer-events: none;
    opacity: 0.7;
}

/* Resolution Quality Indicator */
.resolution-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    color: white;
    z-index: 10;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

.resolution-indicator.good {
    background: #22c55e;
}

.resolution-indicator.low {
    background: #ef4444;
    animation: pulse-warning 2s ease-in-out infinite;
}

@keyframes pulse-warning {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.1);
    }
}

/* Status */
.status {
    text-align: center;
    color: white;
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem 2rem;
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

/* Upload Section */
.upload-section {
    text-align: center;
    padding: 3rem;
    border: 2px dashed #ccc;
    border-radius: 8px;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
}

.upload-section:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.05);
}

.upload-section.drag-over {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
}

/* Cropper Section */
.cropper-section {
    margin-bottom: 1rem;
    max-height: 400px;
    overflow: hidden;
}

/* Cropper Controls */
.cropper-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #eee;
}

.aspect-ratio-controls {
    display: flex;
    gap: 1rem;
}

.aspect-ratio-controls label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Responsive Design */
@media (max-width: 768px) {
    header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .grid-toggle {
        justify-content: center;
        padding: 0.5rem;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 6px;
    }

    .separator-toggle {
        justify-content: center;
        padding: 0.5rem;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 6px;
    }

    main {
        padding: 1rem;
    }

    .number-selector {
        grid-template-columns: repeat(2, 1fr);
    }

    .cropper-modal-content {
        width: 95vw;
        height: 90vh;
        max-width: none;
    }

    .cropper-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .action-buttons {
        justify-content: center;
    }

    .aspect-ratio-controls {
        justify-content: center;
    }
}

/* Enhanced Cropper.js Handles */
.cropper-point {
    width: 12px !important;
    height: 12px !important;
    background-color: #667eea !important;
    border: 2px solid #ffffff !important;
    border-radius: 50% !important;
    opacity: 1 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

.cropper-point:hover {
    background-color: #5a6fd8 !important;
    transform: scale(1.2) !important;
    transition: all 0.2s ease !important;
}

/* Corner handles - make them larger */
.cropper-point.point-nw,
.cropper-point.point-ne,
.cropper-point.point-sw,
.cropper-point.point-se {
    width: 16px !important;
    height: 16px !important;
    border-width: 3px !important;
}

/* Edge handles - make them rectangular for better visibility */
.cropper-point.point-n,
.cropper-point.point-s {
    width: 20px !important;
    height: 8px !important;
    border-radius: 4px !important;
}

.cropper-point.point-e,
.cropper-point.point-w {
    width: 8px !important;
    height: 20px !important;
    border-radius: 4px !important;
}

/* Cropper lines - make them more visible */
.cropper-line {
    background-color: rgba(102, 126, 234, 0.8) !important;
    opacity: 1 !important;
}

.cropper-line.line-n,
.cropper-line.line-s {
    height: 3px !important;
}

.cropper-line.line-e,
.cropper-line.line-w {
    width: 3px !important;
}

/* Crop box outline */
.cropper-crop-box {
    border: 2px solid #667eea !important;
}

/* Cropper view box - slightly darken the overlay */
.cropper-modal {
    background-color: rgba(0, 0, 0, 0.6) !important;
}

/* Copyright Footer */
.copyright-footer {
    text-align: center;
    padding: 20px;
    margin-top: 40px;
}

.copyright-footer p {
    margin: 0;
    font-size: 12px;
    color: white;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.copyright-footer .version {
    opacity: 0.5;
    font-size: 10px;
    margin-left: 8px;
}

/* Hide footer when modals are active */
.modal.active ~ .copyright-footer {
    display: none;
}

@media (max-width: 480px) {
    .number-selector {
        grid-template-columns: 1fr;
    }
    
    .action-buttons {
        flex-direction: column;
    }
}