@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600&family=Quicksand:wght@500;600;700&display=swap');

:root {
    /* Theme: Soft Dream (Updated) */
    --bg-base: #f0f4f8;
    --orb-1: #ff9a9e;
    --orb-2: #a18cd1;
    --orb-3: #fbc2eb;
    
    --glass-bg: rgba(255, 255, 255, 0.65);
    --glass-border: rgba(255, 255, 255, 0.8);
    --glass-blur: blur(24px);
    --glass-shadow: 0 20px 60px rgba(100, 110, 140, 0.08);
    
    --primary: #ff9a9e;
    --accent: #a18cd1;
    --text-main: #445;
    --text-sub: #889;
    
    --radius-card: 24px;
    --radius-md: 16px;
    
    --font-main: 'Quicksand', sans-serif;
    --font-display: 'Fredoka', sans-serif;
}

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

body {
    font-family: var(--font-main);
    color: var(--text-main);
    height: 100vh;
    width: 100vw;
    background: var(--bg-base);
    position: relative;
    /* Allow scrolling on small screens, hide on large if content fits */
    overflow-x: hidden;
    overflow-y: auto; 
}

/* --- Background & Particles --- */
.lively-bg { position: fixed; inset: 0; z-index: -2; background: linear-gradient(135deg, #eef2f3 0%, #dfe9f3 100%); overflow: hidden; pointer-events: none; }
.flow-orb { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.6; animation: orbFloat 12s ease-in-out infinite alternate; will-change: transform; }
.orb-1 { width: 60vw; height: 60vw; background: var(--orb-1); top: -20%; left: -10%; }
.orb-2 { width: 50vw; height: 50vw; background: var(--orb-2); bottom: -10%; right: -10%; animation-delay: -4s; }
.orb-3 { width: 40vw; height: 40vw; background: var(--orb-3); top: 30%; left: 30%; animation: orbFloat 18s infinite; opacity: 0.4; }
.noise-layer { position: absolute; inset: 0; opacity: 0.03; pointer-events: none; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E"); }
@keyframes orbFloat { 0% { transform: translate(0,0) rotate(0deg); } 100% { transform: translate(40px, -40px) rotate(10deg); } }

/* Particles System */
.particles-container { position: fixed; inset: 0; pointer-events: none; z-index: -1; overflow: hidden; }
.particle { position: absolute; font-size: 24px; opacity: 0; animation: floatUp 10s linear infinite; }
.p1 { left: 10%; animation-delay: 0s; }
.p2 { left: 30%; animation-delay: 2s; font-size: 32px; }
.p3 { left: 70%; animation-delay: 5s; }
.p4 { left: 90%; animation-delay: 7s; font-size: 28px; }

@keyframes floatUp {
    0% { transform: translateY(100vh) rotate(0deg); opacity: 0; }
    10% { opacity: 0.6; }
    90% { opacity: 0.6; }
    100% { transform: translateY(-10vh) rotate(360deg); opacity: 0; }
}

/* --- Layout Grid --- */
.studio-grid {
    width: 100%; 
    height: 100vh; /* Fill viewport */
    padding: 2vh 2vw;
    display: grid;
    grid-template-columns: 360px 1fr 340px;
    gap: 20px;
    max-width: 1920px; margin: 0 auto;
}

.glass-panel {
    background: var(--glass-bg); 
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 2px solid var(--glass-border); 
    border-radius: var(--radius-card);
    box-shadow: var(--glass-shadow);
    display: flex; flex-direction: column; overflow: hidden;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* --- Left Panel --- */
.panel-left { z-index: 10; }
.panel-header { padding: 20px; text-align: center; border-bottom: 1px dashed rgba(0,0,0,0.05); }
.brand-pill {
    display: inline-flex; align-items: center; gap: 10px; background: #fff; padding: 10px 24px;
    border-radius: 50px; box-shadow: 0 4px 15px rgba(0,0,0,0.03); cursor: default;
}
.brand-pill .icon { font-size: 1.4rem; }
.brand-pill .name { font-family: var(--font-display); font-weight: 600; font-size: 1.2rem; color: var(--text-main); letter-spacing: 0.5px; }

.scroll-zone { flex: 1; overflow-y: auto; padding: 20px; scrollbar-width: none; }
.scroll-zone::-webkit-scrollbar { display: none; }

.module-group { margin-bottom: 24px; background: rgba(255,255,255,0.3); padding: 16px; border-radius: 20px; }
.module-title { font-size: 0.85rem; font-weight: 800; color: var(--text-sub); margin-bottom: 12px; text-transform: uppercase; letter-spacing: 1px; opacity: 0.8; }

.upload-stack { display: flex; flex-direction: column; gap: 16px; }

/* Upload Boxes (Missing in previous CSS) */
.squircle-upload {
    position: relative; width: 100%; aspect-ratio: 1/1;
    background: #fff; border: 2px dashed #ddd; border-radius: 20px;
    cursor: pointer; transition: all 0.3s ease; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
}
.squircle-upload:hover { border-color: var(--accent); box-shadow: 0 8px 20px rgba(161, 140, 209, 0.15); transform: translateY(-2px); }
.squircle-upload.has-file { border-style: solid; border-color: #fff; }

.state-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 10px; }
.state-empty .icon-bg { font-size: 2rem; filter: grayscale(1); transition: filter 0.3s; }
.squircle-upload:hover .state-empty .icon-bg { filter: grayscale(0); transform: scale(1.1); }
.text-group .main-text { display: block; font-weight: 700; font-size: 0.95rem; color: var(--text-main); }
.text-group .sub-text { display: block; font-size: 0.75rem; color: var(--text-sub); margin-top: 2px; }

.squircle-upload img { 
    position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; 
    opacity: 0; transition: opacity 0.3s; pointer-events: none; 
}
.squircle-upload.has-file img { opacity: 1; }
.squircle-upload.has-file .state-empty { opacity: 0; }

/* Prompt Input */
.prompt-capsule { display: flex; flex-direction: column; gap: 10px; }
.capsule-select, .capsule-text {
    width: 100%; border: none; background: #fff; padding: 12px 16px;
    border-radius: 12px; font-family: inherit; font-size: 0.9rem; color: var(--text-main);
    box-shadow: 0 2px 8px rgba(0,0,0,0.02); transition: all 0.2s; resize: none;
}
.capsule-text { min-height: 80px; line-height: 1.5; }
.capsule-select:focus, .capsule-text:focus { outline: none; box-shadow: 0 0 0 3px rgba(161, 140, 209, 0.2); }

.panel-footer { padding: 20px; background: rgba(255,255,255,0.3); }
.btn-fluid {
    width: 100%; padding: 16px; border: none; border-radius: 50px;
    background: linear-gradient(135deg, var(--orb-1) 0%, var(--orb-2) 100%);
    color: #fff; font-weight: 700; font-size: 1.1rem; cursor: pointer;
    box-shadow: 0 10px 25px rgba(255, 154, 158, 0.4); transition: transform 0.2s;
    position: relative; overflow: hidden;
}
.btn-fluid:hover { transform: scale(1.02); box-shadow: 0 15px 30px rgba(255, 154, 158, 0.5); }
.btn-fluid:active { transform: scale(0.98); }

/* --- Center Panel (Viewport) --- */
.panel-center {
    padding: 10px;
    background: rgba(255, 255, 255, 0.4); /* More transparent */
    border: 1px solid rgba(255,255,255,0.6);
}

.viewport-frame {
    width: 100%; height: 100%;
    background: #fff; border-radius: 20px;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.02);
    display: flex; flex-direction: column;
    overflow: hidden;
}

.frame-top {
    padding: 12px 20px; display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid #f0f0f0; background: #fafafa;
}
.traffic-dots { display: flex; gap: 6px; }
.traffic-dots span { width: 10px; height: 10px; border-radius: 50%; background: #ddd; }
.traffic-dots span:nth-child(1) { background: #ff6b6b; }
.traffic-dots span:nth-child(2) { background: #feca57; }
.traffic-dots span:nth-child(3) { background: #1dd1a1; }
.frame-tag { font-size: 0.75rem; font-weight: 700; color: #bbb; letter-spacing: 1px; }

.canvas-wrapper {
    flex: 1; position: relative; display: flex; align-items: center; justify-content: center;
    background: 
        linear-gradient(45deg, #f8f9fa 25%, transparent 25%), 
        linear-gradient(-45deg, #f8f9fa 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #f8f9fa 75%), 
        linear-gradient(-45deg, transparent 75%, #f8f9fa 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    overflow: hidden;
}

.alive-empty { text-align: center; opacity: 0.5; animation: breathe 3s infinite ease-in-out; }
.float-character { font-size: 4rem; margin-bottom: 10px; display: block; }
.alive-empty h3 { margin-bottom: 5px; color: var(--text-main); }
.alive-empty p { font-size: 0.9rem; color: var(--text-sub); }
@keyframes breathe { 0%, 100% { transform: scale(0.95); opacity: 0.5; } 50% { transform: scale(1); opacity: 0.8; } }

#resultImage {
    max-width: 100%; max-height: 100%; object-fit: contain;
    display: none; box-shadow: 0 10px 40px rgba(0,0,0,0.1);
}

/* --- Four Image Grid --- */
.image-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
    height: 100%;
    padding: 12px;
}

.grid-item {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    transition: all 0.3s ease;
    cursor: pointer;
}

.grid-item:hover {
    transform: scale(1.02);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.grid-item.selected {
    box-shadow: 0 0 0 4px var(--accent), 0 8px 25px rgba(161, 140, 209, 0.3);
    transform: scale(1.02);
}

.grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.grid-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.5) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding: 12px;
}

.grid-item:hover .grid-overlay,
.grid-item.selected .grid-overlay {
    opacity: 1;
}

/* Selection Checkbox */
.select-checkbox {
    position: relative;
    cursor: pointer;
}

.select-checkbox input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.select-checkbox .checkmark {
    width: 28px;
    height: 28px;
    background: rgba(255,255,255,0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: transparent;
    transition: all 0.2s ease;
    border: 2px solid rgba(255,255,255,0.5);
}

.select-checkbox input:checked + .checkmark {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.select-checkbox:hover .checkmark {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Zoom Button */
.zoom-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.9);
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.zoom-btn:hover {
    transform: scale(1.1);
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Selection Hint */
.selection-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background: linear-gradient(135deg, rgba(161, 140, 209, 0.1) 0%, rgba(255, 154, 158, 0.1) 100%);
    border-radius: 0 0 20px 20px;
    margin-top: -10px;
}

.hint-icon {
    font-size: 1.2rem;
}

.hint-text {
    font-size: 0.85rem;
    color: var(--text-main);
}

.hint-text strong {
    color: var(--accent);
    font-weight: 700;
}

/* --- Lightbox Modal --- */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.lightbox-overlay.active {
    opacity: 1;
    visibility: visible;
}

.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    animation: lightboxZoom 0.3s ease;
}

@keyframes lightboxZoom {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.lightbox-content img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.lightbox-close {
    position: absolute;
    top: -40px;
    right: 0;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-close:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.1);
}

.lightbox-actions {
    position: absolute;
    bottom: -60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
}

.lightbox-select-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 25px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    white-space: nowrap;
}

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

/* --- History Button & Modal --- */
.history-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    padding: 10px 16px;
    border: none;
    border-radius: 20px;
    background: rgba(255,255,255,0.9);
    color: #333;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.history-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.history-count {
    background: #667eea;
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
}

.history-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.history-overlay.active {
    opacity: 1;
    visibility: visible;
}

.history-modal {
    background: #fff;
    border-radius: 20px;
    width: 90vw;
    max-width: 900px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.history-header h3 {
    margin: 0;
    font-size: 18px;
}

.history-close {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: #f0f0f0;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s ease;
}

.history-close:hover {
    background: #e0e0e0;
}

.history-content {
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.history-item {
    border: 1px solid #eee;
    border-radius: 12px;
    padding: 15px;
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 14px;
    color: #666;
}

.history-item-images {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.history-item-images img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.history-item-images img:hover {
    transform: scale(1.05);
}

.history-restore-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-restore-btn:hover {
    transform: translateY(-1px);
}

/* --- Right Panel (Chat & Tips) --- */
.panel-right { gap: 20px; padding: 20px; }

.sub-module { 
    background: rgba(255,255,255,0.5); border-radius: 20px; 
    padding: 16px; display: flex; flex-direction: column; 
}

.module-header { 
    display: flex; justify-content: space-between; align-items: center; 
    margin-bottom: 12px; font-size: 0.9rem; font-weight: 700; color: var(--text-main); 
}

/* Chat */
.chat-module { flex: 1; min-height: 0; } /* Allow shrinking */
.chat-flow { 
    flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; 
    background: rgba(255,255,255,0.4); border-radius: 12px; margin-bottom: 10px;
    scrollbar-width: thin;
}
.bubble {
    max-width: 90%; padding: 10px 14px; border-radius: 14px; font-size: 0.85rem; line-height: 1.4;
    position: relative; word-wrap: break-word;
}
.bubble.ai { align-self: flex-start; background: #fff; border-bottom-left-radius: 2px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 2px; }

.chat-dock { display: flex; gap: 8px; }
#chatInput { 
    flex: 1; border: none; padding: 10px 14px; border-radius: 50px; font-size: 0.85rem; 
    box-shadow: 0 2px 8px rgba(0,0,0,0.05); 
}
.btn-send {
    width: 36px; height: 36px; border: none; border-radius: 50%; background: var(--text-main); color: #fff;
    cursor: pointer; display: flex; align-items: center; justify-content: center; transition: transform 0.2s;
}
.btn-send:hover { transform: scale(1.1); }

/* Tips */
.tips-module { height: 35%; min-height: 200px; }
.tips-scroll { overflow-y: auto; padding-right: 4px; display: flex; flex-direction: column; gap: 10px; height: 100%; }
.tips-scroll::-webkit-scrollbar { width: 4px; }
.tips-scroll::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 10px; }

.tip-card { padding: 12px; border-radius: 12px; border: 1px solid rgba(0,0,0,0.05); transition: transform 0.2s; }
.tip-card:hover { transform: translateX(4px); }

.tip-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 0.85rem; color: var(--text-main); }
.tip-card p { font-size: 0.75rem; color: var(--text-sub); line-height: 1.4; }

.color-1 { background: #fff5f5; border-color: #ffec99; }
.color-2 { background: #ebfbee; border-color: #b2f2bb; }
.color-3 { background: #e7f5ff; border-color: #a5d8ff; }
.color-4 { background: #fff0f6; border-color: #ffdeeb; }

/* --- Loading Overlay --- */
.loading-overlay {
    position: fixed; inset: 0; z-index: 999;
    background: rgba(255,255,255,0.8); backdrop-filter: blur(10px);
    display: none; flex-direction: column; align-items: center; justify-content: center;
    gap: 20px;
}
.liquid-loader { display: flex; gap: 10px; }
.drop {
    width: 20px; height: 20px; border-radius: 50%; background: var(--primary);
    animation: bounce 1.5s infinite ease-in-out;
}
.drop:nth-child(2) { animation-delay: 0.2s; background: var(--accent); }
.drop:nth-child(3) { animation-delay: 0.4s; background: var(--orb-3); }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-20px); } }

.loading-text { font-family: var(--font-display); font-weight: 600; color: var(--text-main); animation: pulse 2s infinite; }

/* --- Admin Mode Override (Existing) --- */
.studio-grid.admin-mode {
    grid-template-columns: 300px 1fr;
    height: auto; min-height: 100vh;
}

/* --- Responsive Design --- */
@media (max-width: 1200px) {
    .studio-grid {
        grid-template-columns: 320px 1fr;
        grid-template-rows: 1fr auto;
        height: auto; /* Allow scrolling */
        overflow-y: visible;
    }
    .panel-right {
        grid-column: span 2;
        flex-direction: row;
        height: 400px;
    }
    .tips-module, .chat-module { height: 100%; }
}

@media (max-width: 850px) {
    .studio-grid {
        grid-template-columns: 1fr;
        display: flex; flex-direction: column;
        padding: 10px;
    }
    
    body { overflow-y: auto; height: auto; }
    
    .panel-left, .panel-center, .panel-right {
        width: 100%;
        height: auto;
        min-height: auto;
    }

    .panel-center { height: 60vh; min-height: 400px; order: -1; } /* Show preview first on mobile? No, usually controls first, but preview is key. Let's keep standard order or put preview top. */
    .panel-center { order: 0; }
    
    .panel-right { flex-direction: column; height: auto; }
    .chat-module { height: 300px; }
    .tips-module { height: auto; }
}