/* =========================================
   1. 核心变量与基础设置
   ========================================= */
:root {
    /* --- 调色板 --- */
    --bg-base: #f8f9fa;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    
    --accent: #111827; /* 极致黑作为强调色 */
    --accent-hover: #000000;
    
    /* --- 玻璃质感 --- */
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-border: 1px solid rgba(255, 255, 255, 0.8);
    --glass-shadow: 0 4px 30px rgba(0, 0, 0, 0.04);
    --blur-amt: 24px;
    
    /* --- 空间与圆角 --- */
    --radius-s: 8px;
    --radius-m: 16px;
    --radius-l: 24px;
    --radius-xl: 32px;
    
    /* --- 动效 --- */
    --ease-elastic: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; outline: none; -webkit-tap-highlight-color: transparent; }

/* 核心修复：强制根元素和Body不许横向滚动 */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden; /* 关键：禁止横向溢出 */
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text-primary);
    background: var(--bg-base);
    height: 100vh;
    font-size: 14px;
}

/* --- 动态环境背景 --- */
.ambient-bg {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: -2;
    background: #ffffff;
    transition: background 1s ease;
}
.aurora {
    position: absolute;
    filter: blur(80px);
    opacity: 0.5;
    border-radius: 50%;
    animation: float 20s infinite ease-in-out;
    transition: background 1s ease;
}
.aurora-1 { width: 60vw; height: 60vw; top: -10%; left: -10%; background: #ffe4e6; animation-delay: 0s; }
.aurora-2 { width: 50vw; height: 50vw; bottom: -10%; right: -10%; background: #e0f2fe; animation-delay: -5s; }
.aurora-3 { width: 40vw; height: 40vw; top: 40%; left: 30%; background: #f3e8ff; animation-delay: -10s; }

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -50px) scale(1.1); }
    66% { transform: translate(-20px, 20px) scale(0.9); }
}

.noise-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1;
    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.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='1'/%3E%3C/svg%3E");
}

/* =========================================
   2. 主布局结构
   ========================================= */
.app-layout {
    display: flex;
    height: 100vh;
    padding: 16px;
    gap: 16px;
    width: 100%;
    max-width: 100%; /* 双重保险 */
}

/* --- 左侧边栏 --- */
.sidebar {
    width: 340px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--blur-amt));
    -webkit-backdrop-filter: blur(var(--blur-amt));
    border: var(--glass-border);
    border-radius: var(--radius-l);
    box-shadow: var(--glass-shadow);
    overflow: hidden;
    transition: transform 0.3s ease;
    z-index: 20;
    position: relative;
}

.brand-header {
    padding: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(0,0,0,0.03);
    flex-shrink: 0;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-mark {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, #111827, #374151);
    color: white;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.logo-text { font-family: 'Inter', sans-serif; font-weight: 700; font-size: 16px; letter-spacing: -0.5px; }

.lang-pill {
    background: rgba(0,0,0,0.04);
    border-radius: 20px;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
}
.lang-pill button { 
    background: none; border: none; padding: 2px 6px; 
    cursor: pointer; color: var(--text-tertiary); 
    transition: color 0.2s; font-family: inherit; font-size: inherit; font-weight: inherit;
}
.lang-pill button.active { color: var(--text-primary); }
.lang-pill .divider { color: rgba(0,0,0,0.1); margin: 0 2px; }

/* 滚动容器 + 渐隐遮罩 */
.scroll-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    padding-bottom: 180px;
    display: flex;
    flex-direction: column;
    gap: 32px;

    -webkit-mask-image: linear-gradient(to bottom, 
        black calc(100% - 190px), 
        transparent calc(100% - 150px),
        transparent 100%
    );
    mask-image: linear-gradient(to bottom, 
        black calc(100% - 190px), 
        transparent calc(100% - 150px),
        transparent 100%
    );
}
.scroll-container::-webkit-scrollbar { width: 0; }

/* =========================================
   3. 控件样式
   ========================================= */
.control-group { display: flex; flex-direction: column; gap: 16px; }
.group-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    font-weight: 600;
    display: flex; align-items: center; gap: 8px;
}
.group-title i { opacity: 0.7; }

.color-mixer {
    display: flex; align-items: center; justify-content: space-between;
    background: white; padding: 16px; border-radius: var(--radius-m);
    box-shadow: 0 2px 12px rgba(0,0,0,0.03); border: 1px solid rgba(0,0,0,0.04);
}
.color-node { display: flex; flex-direction: column; align-items: center; gap: 8px; position: relative; }
.color-surface {
    width: 48px; height: 48px; border-radius: 50%; border: 4px solid white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1), inset 0 0 0 1px rgba(0,0,0,0.05);
    cursor: pointer; transition: transform 0.3s var(--ease-elastic);
}
.color-node:hover .color-surface { transform: scale(1.1); }
.color-node input { position: absolute; opacity: 0; width: 100%; height: 100%; top:0; cursor: pointer; }
.color-label { font-size: 11px; color: var(--text-tertiary); font-weight: 500; }

.btn-swap {
    width: 36px; height: 36px; border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.08); background: #f9fafb; color: var(--text-secondary);
    cursor: pointer; transition: all 0.3s ease;
}
.btn-swap:hover { background: white; transform: rotate(180deg); color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,0.05); }

.btn-random {
    width: 100%; padding: 12px; border: 1px dashed rgba(0,0,0,0.15); border-radius: var(--radius-m);
    background: transparent; color: var(--text-secondary); font-weight: 500;
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: all 0.2s; position: relative; overflow: hidden;
}
.btn-random:hover { border-color: var(--accent); color: var(--accent); background: rgba(255,255,255,0.5); }
.btn-random:active { transform: scale(0.98); }
.shortcut-hint { font-size: 10px; background: rgba(0,0,0,0.05); padding: 2px 6px; border-radius: 4px; }

.group-header-row { display: flex; justify-content: space-between; align-items: center; }
.value-badge { font-family: 'JetBrains Mono', monospace; font-size: 12px; background: white; padding: 2px 6px; border-radius: 4px; border: 1px solid rgba(0,0,0,0.05); }

.angle-interface {
    background: white; padding: 20px; border-radius: var(--radius-m);
    box-shadow: 0 2px 12px rgba(0,0,0,0.03); border: 1px solid rgba(0,0,0,0.04);
    display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.angle-ring { width: 140px; height: 140px; border-radius: 50%; position: relative; cursor: grab; touch-action: none; }
.angle-ring:active { cursor: grabbing; }
.angle-track {
    position: absolute; inset: 0; border-radius: 50%;
    background: conic-gradient(from 0deg, #f3f4f6, #d1d5db, #f3f4f6);
    -webkit-mask: radial-gradient(transparent 58%, black 60%); mask: radial-gradient(transparent 58%, black 60%);
}
.angle-knob { position: absolute; top: 50%; left: 50%; width: 16px; height: 50%; transform-origin: top center; pointer-events: none; }
.angle-knob::after {
    content: ''; position: absolute; bottom: 8px; left: -8px; width: 16px; height: 16px;
    background: var(--accent); border-radius: 50%; box-shadow: 0 2px 6px rgba(0,0,0,0.2); border: 2px solid white;
}
.angle-center-dot { position: absolute; top: 50%; left: 50%; width: 6px; height: 6px; background: var(--text-tertiary); border-radius: 50%; transform: translate(-50%, -50%); }
.angle-presets { display: flex; gap: 8px; width: 100%; justify-content: center; }
.angle-presets button {
    width: 28px; height: 28px; border-radius: 6px; border: 1px solid rgba(0,0,0,0.08); background: #f9fafb;
    color: var(--text-secondary); cursor: pointer; font-size: 12px; transition: all 0.2s;
}
.angle-presets button:hover { background: var(--accent); color: white; border-color: var(--accent); }

.preset-scroll-view { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.preset-item {
    aspect-ratio: 1; border-radius: 10px; cursor: pointer; position: relative;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05); transition: transform 0.2s, box-shadow 0.2s; overflow: hidden;
}
.preset-item:hover { transform: translateY(-3px) scale(1.05); box-shadow: 0 8px 16px rgba(0,0,0,0.1); z-index: 10; }
.preset-item.active { box-shadow: 0 0 0 2px var(--accent), 0 4px 12px rgba(0,0,0,0.1); }
.preset-name {
    position: absolute; bottom: 0; left: 0; width: 100%;
    background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(4px);
    font-size: 10px; color: var(--text-primary); text-align: center;
    padding: 4px; font-weight: 600; transform: translateY(100%); transition: transform 0.3s ease;
}
.preset-item:hover .preset-name { transform: translateY(0); }

.upload-widget {
    border: 2px dashed rgba(0,0,0,0.1); border-radius: var(--radius-m); min-height: 80px;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    transition: all 0.2s; background: rgba(255,255,255,0.4); position: relative; overflow: hidden;
}
.upload-widget:hover { border-color: var(--accent); background: rgba(255,255,255,0.8); }
.upload-placeholder { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--text-secondary); pointer-events: none; }
.upload-preview {
    position: absolute; inset: 0; background-size: contain; background-repeat: no-repeat; background-position: center;
    display: none; background-color: #f3f4f6;
}
.upload-widget.has-image .upload-preview { display: block; }
.btn-remove-img {
    position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; background: rgba(0,0,0,0.6);
    color: white; border: none; border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 10px;
}
.slider-control { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.slider-control input { flex: 1; accent-color: var(--accent); cursor: pointer; }

/* =========================================
   4. 底部悬浮 Footer
   ========================================= */
.sidebar-footer {
    position: absolute;
    bottom: 16px; 
    left: 16px; 
    right: 16px;
    z-index: 20;
    
    background: radial-gradient(120% 100% at 50% 0%, rgba(255, 255, 255, 0.98) 0%, rgba(255, 255, 255, 0.88) 100%);
    backdrop-filter: blur(20px) saturate(120%);
    -webkit-backdrop-filter: blur(20px) saturate(120%);
    
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-top: 1px solid rgba(255, 255, 255, 1);
    
    box-shadow: 
        0 20px 40px -10px rgba(17, 24, 39, 0.08), 
        0 4px 12px -2px rgba(17, 24, 39, 0.05),
        inset 0 1px 0 0 rgba(255, 255, 255, 0.9);
    
    border-radius: 24px;
    padding: 20px;
    display: flex; 
    flex-direction: column; 
    gap: 16px;
    
    animation: slideUp 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
    overflow: hidden; 
}

/* 底部光效 */
.sidebar-footer::after {
    content: '';
    position: absolute;
    bottom: -20%; right: -20%;
    width: 60%; height: 60%;
    background: radial-gradient(circle, rgba(79, 70, 229, 0.08), transparent 70%);
    filter: blur(20px);
    pointer-events: none;
    z-index: 0;
}

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

.size-inputs { display: flex; align-items: center; justify-content: space-between; gap: 8px; z-index: 2; position: relative;}

/* 修复：添加 min-width: 0 防止 flex 子项在移动端撑开容器 */
.input-float { position: relative; flex: 1; min-width: 0; }

.input-float input {
    width: 100%; border: 1px solid rgba(0,0,0,0.1); border-radius: 8px;
    padding: 8px 12px 8px 60px;
    font-family: 'JetBrains Mono'; font-size: 12px;
    background: white; transition: border 0.2s;
}
.input-float input:focus { border-color: var(--accent); }
.input-float label {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    font-size: 10px; font-weight: 700; color: var(--text-tertiary);
    text-transform: uppercase; letter-spacing: 0.5px;
}
.x-divider { color: var(--text-tertiary); font-size: 12px; }
.export-actions { display: flex; gap: 10px; z-index: 2; position: relative;}
.format-select {
    padding: 0 12px; border: 1px solid rgba(0,0,0,0.1); border-radius: 10px;
    background: white; font-size: 12px; font-weight: 600; color: var(--text-primary); cursor: pointer;
}
.btn-primary {
    flex: 1; background: var(--accent); color: white; border: none; border-radius: 10px; height: 42px;
    font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: transform 0.2s, background 0.2s;
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(1px); }

/* =========================================
   5. 右侧工作区
   ========================================= */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 10;
}

.toolbar-container {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    margin-bottom: 16px;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--blur-amt));
    -webkit-backdrop-filter: blur(var(--blur-amt));
    border: var(--glass-border);
    border-radius: var(--radius-l);
    box-shadow: var(--glass-shadow);
    flex-shrink: 0;
}

.css-display {
    display: flex; align-items: center; gap: 12px;
    background: rgba(255,255,255,0.5); padding: 6px 6px 6px 16px;
    border-radius: 12px; border: 1px solid rgba(0,0,0,0.05);
    max-width: 60%;
}
.css-display .label { font-size: 11px; font-weight: 800; color: var(--text-primary); opacity: 0.5; }
.css-display .code-content {
    font-family: 'JetBrains Mono'; font-size: 12px; color: var(--text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.action-copy {
    background: white; border: none; border-radius: 8px; padding: 6px 12px;
    font-size: 11px; font-weight: 600; cursor: pointer; color: var(--text-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05); transition: background 0.2s; white-space: nowrap;
}
.action-copy:hover { background: #f3f4f6; }

.toolbar-actions { display: flex; gap: 12px; }
.tool-btn {
    width: 36px; height: 36px; border-radius: 10px; border: none;
    background: transparent; color: var(--text-secondary);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; font-size: 15px;
}
.tool-btn:hover { background: white; color: var(--text-primary); box-shadow: 0 2px 8px rgba(0,0,0,0.05); }

/* 画布 */
.canvas-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 20px;
}

.artboard-container {
    position: relative;
    display: flex; 
    align-items: center; 
    justify-content: center;
}

.artboard {
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border-radius: var(--radius-m);
    position: relative;
    z-index: 10;
    transition: width 0.4s var(--ease-smooth), height 0.4s var(--ease-smooth);
    overflow: hidden;
}

.artboard.grid-mode::before {
    content: ''; position: absolute; inset: 0; z-index: -1;
    background-image: linear-gradient(45deg, #e5e7eb 25%, transparent 25%), 
                      linear-gradient(-45deg, #e5e7eb 25%, transparent 25%), 
                      linear-gradient(45deg, transparent 75%, #e5e7eb 75%), 
                      linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.artboard-shadow {
    position: absolute;
    top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 100%; height: 100%; border-radius: var(--radius-m);
    box-shadow: 0 50px 100px -20px rgba(0,0,0,0.15), 0 30px 60px -30px rgba(0,0,0,0.2);
    z-index: 5;
    transition: width 0.4s var(--ease-smooth), height 0.4s var(--ease-smooth);
}

.preview-img {
    display: block;
    max-width: none; 
    object-fit: contain; 
    /* pointer-events: none;  Removed to allow interaction */
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    position: absolute; /* Added for positioning */
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.preview-img:active {
    cursor: grabbing;
}

/* Toast */
.toast-container { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); z-index: 100; pointer-events: none; }
.toast {
    background: rgba(17, 24, 39, 0.9); color: white; padding: 10px 20px; border-radius: 30px;
    font-size: 13px; font-weight: 500; box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    backdrop-filter: blur(10px); animation: fadeInUp 0.3s ease, fadeOut 0.3s ease 1.7s forwards;
    display: flex; align-items: center; gap: 8px;
}
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(-10px); } }

/* 响应式适配 */
@media (max-width: 1000px) {
    /* 核心修复：移动端允许页面整体滚动 */
    body {
        height: auto;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .app-layout { 
        flex-direction: column; 
        overflow: visible; 
        height: auto; 
        padding: 0; 
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }
    
    .sidebar-footer {
        position: fixed;
        bottom: 16px;
        left: 16px;
        /* 使用 calc 确保宽度自适应，避免溢出 */
        width: calc(100% - 32px);
        right: auto;
        z-index: 100;
        box-shadow: 0 10px 40px rgba(0,0,0,0.15);
        backdrop-filter: blur(20px) saturate(180%);
        -webkit-backdrop-filter: blur(20px) saturate(180%);
    }
    
    .sidebar { 
        width: 100%; 
        height: auto; 
        overflow: visible; 
        background: transparent;
        border: none;
        box-shadow: none;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
    
    .scroll-container { 
        /* 核心修复：减小底部留白，消除与预览区之间的大片空白 */
        padding: 20px; 
        overflow: visible;
        flex: none;
        -webkit-mask-image: none;
        mask-image: none;
    }

    .color-mixer {
        padding: 16px 12px;
    }
    
    .canvas-stage { 
        /* 核心修复：移除强制高度，避免内容较少时产生空白 */
        min-height: auto; 
        /* 核心修复：将防遮挡留白移到这里 (20px top, 180px bottom) */
        padding: 20px 20px 180px 20px; 
        order: 0; /* 保持自然顺序 (侧边栏在上，预览在下) */
        margin-bottom: 0;
    }
    
    .brand-header {
        padding: 16px 20px;
        background: rgba(255,255,255,0.6);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        margin: 0; 
        border-radius: 0 0 20px 20px;
        border-bottom: 1px solid rgba(255,255,255,0.5);
        position: sticky;
        top: 0;
        z-index: 50;
    }

    .toolbar-container { display: none; }
}