:root {
    --sidebar-width: 500px;
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.18);
    --shadow-color: rgba(31, 38, 135, 0.15);
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    background-attachment: fixed;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* Animated background pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    animation: subtleMove 20s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes subtleMove {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(30px, 30px); }
}

.main-container {
    display: flex;
    height: 100vh;
    padding: 20px;
    gap: 20px;
    position: relative;
    z-index: 1;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2rem;
    box-shadow: 0 8px 32px var(--shadow-color);
    transition: all 0.3s ease;
}

.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.preview-toolbar {
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: 20px 20px 0 0;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    box-shadow: 0 8px 32px var(--shadow-color);
}

.preview-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    overflow: hidden;
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-top: none;
    border-radius: 0 0 20px 20px;
    box-shadow: 0 8px 32px var(--shadow-color);
    position: relative;
}

#previewCanvas {
    display: block;
    max-width: min(calc(100vw - var(--sidebar-width) - 180px), 600px);
    max-height: calc(100vh - 300px);
    width: auto;
    height: auto;
    object-fit: contain;
}

.preview-frame {
    background: linear-gradient(145deg, #2c3e50, #34495e);
    border-radius: 20px;
    padding: 1.5rem;
    box-shadow: 
        0 30px 80px rgba(0,0,0,0.35),
        0 10px 30px rgba(0,0,0,0.2),
        inset 0 1px 0 rgba(255,255,255,0.15),
        inset 0 -2px 8px rgba(0,0,0,0.2);
    position: relative;
    transition: all 0.3s ease;
    max-width: calc(100vw - var(--sidebar-width) - 120px);
    max-height: calc(100vh - 200px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Portrait 0° - chin at bottom (default) */
.preview-frame.orientation-0 {
    padding: 1.5rem 1.5rem 4.5rem 1.5rem;
}

/* Landscape 90° - chin on right */
.preview-frame.orientation-90 {
    padding: 1.5rem 4.5rem 1.5rem 1.5rem;
}

/* Portrait 180° - chin at top */
.preview-frame.orientation-180 {
    padding: 4.5rem 1.5rem 1.5rem 1.5rem;
}

/* Landscape 270° - chin on left */
.preview-frame.orientation-270 {
    padding: 1.5rem 1.5rem 1.5rem 4.5rem;
}

.preview-frame.light-mode {
    background: linear-gradient(145deg, #f0eeeb, #faf9f7);
    box-shadow: 
        0 30px 80px rgba(0,0,0,0.15),
        0 10px 30px rgba(0,0,0,0.1),
        inset 0 1px 0 rgba(255,255,255,0.9),
        inset 0 -2px 8px rgba(0,0,0,0.05);
}

.preview-frame:hover {
    transform: translateY(-5px);
}

.preview-frame::before {
    content: '';
    position: absolute;
    background: rgba(0,0,0,0.35);
    border-radius: 5.5px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.6);
    z-index: 10;
    transition: all 0.15s ease-out;
}

.preview-frame::after {
    content: '';
    position: absolute;
    background: rgba(0,0,0,0.35);
    border-radius: 5.5px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.6);
    z-index: 10;
    transition: all 0.15s ease-out;
}

/* Portrait 0° - buttons at bottom, horizontal */
.preview-frame.orientation-0::before {
    bottom: 0.65rem;
    left: 12%;
    width: 36.5%;
    height: 11px;
}

.preview-frame.orientation-0::after {
    bottom: 0.65rem;
    right: 12%;
    width: 36.5%;
    height: 11px;
}

/* Landscape 90° - buttons on right, vertical */
.preview-frame.orientation-90::before {
    right: 0.65rem;
    top: 12%;
    width: 11px;
    height: 36.5%;
}

.preview-frame.orientation-90::after {
    right: 0.65rem;
    bottom: 12%;
    width: 11px;
    height: 36.5%;
}

/* Portrait 180° - buttons at top, horizontal */
.preview-frame.orientation-180::before {
    top: 0.65rem;
    left: 12%;
    width: 36.5%;
    height: 11px;
}

.preview-frame.orientation-180::after {
    top: 0.65rem;
    right: 12%;
    width: 36.5%;
    height: 11px;
}

/* Landscape 270° - buttons on left, vertical */
.preview-frame.orientation-270::before {
    left: 0.65rem;
    top: 12%;
    width: 11px;
    height: 36.5%;
}

.preview-frame.orientation-270::after {
    left: 0.65rem;
    bottom: 12%;
    width: 11px;
    height: 36.5%;
}

.preview-frame.light-mode::before,
.preview-frame.light-mode::after {
    background: rgba(0,0,0,0.15);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.25);
}

.device-color-toggle {
    position: absolute;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.device-color-toggle:hover {
    background: rgba(255, 255, 255, 0.5);
    border-color: rgba(102, 126, 234, 0.6);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.2);
}

.device-color-toggle svg {
    width: 24px;
    height: 24px;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}

.preview-screen {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 0;
    max-height: calc(100vh - 300px);
    border: 2px solid rgba(0,0,0,0.35);
    transition: border-color 0.3s ease;
}

.preview-frame.light-mode .preview-screen {
    border-color: rgba(0,0,0,0.15);
}

#previewCanvas {
    display: block;
}

.drop-zone {
    border: 3px dashed rgba(102, 126, 234, 0.5);
    border-radius: 16px;
    padding: 2.5rem 1.5rem;
    text-align: center;
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(10px);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.drop-zone:hover, .drop-zone.drag-over {
    background: rgba(255, 255, 255, 0.5);
    border-color: rgba(102, 126, 234, 0.8);
    transform: scale(1.02);
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.2);
}

.drop-zone i {
    font-size: 3.5rem;
    color: #2d3748;
    margin-bottom: 0.75rem;
    display: block;
}

.drop-zone div {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 0.25rem;
}

.drop-zone small {
    color: #718096;
    font-size: 0.9rem;
}

.file-input {
    display: none;
}

.section-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #4a5568;
    margin-top: 2rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid rgba(113, 128, 150, 0.2);
}

.section-title:first-child {
    margin-top: 0;
}

.orientation-buttons {
    display: flex;
    gap: 0.75rem;
}

.orientation-btn {
    padding: 0.75rem;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex: 1;
}

.orientation-btn:hover {
    border-color: rgba(102, 126, 234, 0.6);
    background: rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.orientation-btn.active {
    border-color: rgba(102, 126, 234, 0.8);
    background: rgba(102, 126, 234, 0.15);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.orientation-btn svg {
    display: block;
    margin: 0 auto;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.chapter-list {
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

.chapter-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.9rem;
    transition: all 0.2s;
    color: #2d3748;
}

.chapter-item:last-child {
    border-bottom: none;
}

.chapter-item:hover {
    background: rgba(102, 126, 234, 0.25);
}

.chapter-item.active {
    background: rgba(102, 126, 234, 0.3);
    color: #667eea;
    font-weight: 600;
}

.file-list {
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 1rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

.file-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.file-list-header span {
    font-size: 0.9rem;
    color: #2d3748;
    font-weight: 600;
}

.file-list-items {
    max-height: 180px;
    overflow-y: auto;
}

.file-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.9rem;
    transition: all 0.2s;
    color: #2d3748;
}

.file-item:last-child {
    border-bottom: none;
}

.file-item:hover {
    background: rgba(102, 126, 234, 0.25);
}

.file-item.active {
    background: rgba(102, 126, 234, 0.3);
    color: #667eea;
    font-weight: 600;
}

.file-item .file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-item .file-remove {
    margin-left: 0.5rem;
    color: #718096;
    cursor: pointer;
    transition: all 0.2s;
}

.file-item .file-remove:hover {
    color: #f5576c;
    transform: scale(1.2);
}

.empty-state {
    text-align: center;
    color: #718096;
    padding: 4rem 1rem;
}

.empty-state i {
    font-size: 5rem;
    margin-bottom: 1.5rem;
    color: #718096;
    opacity: 0.6;
}

.empty-state p {
    font-size: 1.1rem;
    font-weight: 500;
    color: #718096;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
    z-index: 1000;
    border-radius: 24px;
}

.loading-overlay.hidden {
    display: none;
}

.range-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.range-group input[type="range"] {
    flex: 1;
}

.range-group input[type="number"] {
    width: 75px;
}

.range-group .unit {
    color: #718096;
    font-size: 0.875rem;
    min-width: 30px;
    font-weight: 600;
}

.btn-group-sm .btn {
    font-size: 0.9rem;
}

.progress-container {
    margin-top: 1.5rem;
}

h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 2rem;
    color: #2d3748;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

h1 i {
    color: #2d3748;
}

label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 0.5rem;
}

.form-select, .form-control {
    font-size: 0.9rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    color: #2d3748;
    border-radius: 10px;
    padding: 0.6rem 0.9rem;
    transition: all 0.3s;
}

.form-select {
    padding-right: 2.5rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%232d3748' d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 12px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

.form-select:focus, .form-control:focus {
    border-color: rgba(102, 126, 234, 0.6);
    background-color: rgba(255, 255, 255, 0.4);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%23667eea' d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 12px;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    outline: none;
}

.form-control::placeholder {
    color: rgba(45, 55, 72, 0.5);
}

.form-range {
    height: 8px;
    border-radius: 4px;
    background: rgba(113, 128, 150, 0.4);
}

.form-range::-webkit-slider-runnable-track {
    background: rgba(113, 128, 150, 0.4);
    border-radius: 4px;
    height: 8px;
}

.form-range::-moz-range-track {
    background: rgba(113, 128, 150, 0.4);
    border-radius: 4px;
    height: 8px;
}

.form-range::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.form-range::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.form-check-input {
    width: 1.2em;
    height: 1.2em;
    border: 2px solid rgba(102, 126, 234, 0.4);
    background: rgba(255, 255, 255, 0.3);
    cursor: pointer;
}

.form-check-input:checked {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: rgba(102, 126, 234, 0.8);
}

.form-check-label {
    color: #2d3748;
    font-weight: 500;
    cursor: pointer;
}

.btn {
    border-radius: 12px;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    padding: 0.65rem 1.25rem;
    font-size: 0.95rem;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-success {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(56, 239, 125, 0.3);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(56, 239, 125, 0.4);
}

.btn-outline-secondary, .btn-outline-danger {
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(10px);
    color: #2d3748;
    border: 2px solid rgba(255, 255, 255, 0.4);
}

.btn-outline-danger {
    color: #f5576c;
    border-color: rgba(245, 87, 108, 0.4);
}

.btn-outline-secondary:hover {
    background: rgba(255, 255, 255, 0.5);
    border-color: rgba(102, 126, 234, 0.6);
    color: #2d3748;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.btn-outline-danger:hover {
    background: rgba(255, 255, 255, 0.5);
    border-color: rgba(245, 87, 108, 0.8);
    color: #f5576c;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 87, 108, 0.2);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.progress {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    overflow: hidden;
    height: 10px;
}

.progress-bar {
    background: var(--primary-gradient);
    transition: width 0.3s ease;
}

/* Scrollbar styling */
.sidebar::-webkit-scrollbar,
.chapter-list::-webkit-scrollbar,
.file-list-items::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track,
.chapter-list::-webkit-scrollbar-track,
.file-list-items::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb,
.chapter-list::-webkit-scrollbar-thumb,
.file-list-items::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.4);
    border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.chapter-list::-webkit-scrollbar-thumb:hover,
.file-list-items::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.6);
}

/* Improved spacing */
.mb-2 {
    margin-bottom: 1rem !important;
}

.mb-3 {
    margin-bottom: 1.5rem !important;
}

.mt-1 {
    margin-top: 0.5rem !important;
}

.mt-3 {
    margin-top: 1.5rem !important;
}

/* Text styling */
.text-muted {
    color: rgba(45, 55, 72, 0.6) !important;
}

.text-primary {
    color: #667eea !important;
}

.small {
    font-size: 0.875rem;
}

.fw-bold {
    font-weight: 700;
}

/* Sidebar footer */
.sidebar-footer {
    margin-top: 2rem;
    padding-top: 1.5rem;
}

.footer-divider {
    height: 1px;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(113, 128, 150, 0.3) 20%, 
        rgba(113, 128, 150, 0.3) 80%, 
        transparent 100%);
    margin-bottom: 1rem;
}

.footer-text {
    text-align: center;
    font-size: 0.8rem;
    color: #718096;
    opacity: 0.7;
}

.footer-text a {
    color: #667eea;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s;
}

.footer-text a:hover {
    color: #764ba2;
    text-decoration: underline;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    :root {
        --sidebar-width: 400px;
    }
    
    .main-container {
        padding: 15px;
    }
}

/* Loading spinner customization */
.spinner-border {
    width: 3rem;
    height: 3rem;
    border-width: 0.3em;
    border-color: rgba(255, 255, 255, 0.3);
    border-right-color: white;
}

.loading-overlay span {
    font-size: 1.1rem;
    font-weight: 600;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Safari-specific fixes */
@supports (-webkit-backdrop-filter: none) or (backdrop-filter: none) {
    .sidebar,
    .preview-toolbar,
    .preview-area {
        -webkit-backdrop-filter: blur(20px) saturate(180%);
    }
}

/* Smooth fade-in animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sidebar,
.preview-toolbar,
.preview-area {
    animation: fadeIn 0.6s ease-out;
}

/* Hover glow effect for interactive elements */
.btn:not(:disabled):hover,
.orientation-btn:hover,
.chapter-item:hover,
.file-item:hover {
    position: relative;
}

.btn-primary:hover::before,
.btn-success:hover::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: inherit;
    background: inherit;
    filter: blur(8px);
    opacity: 0.5;
    z-index: -1;
}
