/* Global Settings */
:root {
    --primary-color: #6200ea;
    --primary-light: #b388ff;
    --secondary-color: #00bfa5;
    --bg-color: #f3f4f6;
    --panel-bg: #ffffff;
    --border-color: #e5e7eb;
    --text-color: #1f2937;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    padding: 20px;
    min-height: 100vh;
    display: flex; flex-direction: column; align-items: center; /* Changed for better vertical flow */
}

/* Main App Container - Desktop Layout (Left Preview, Right Controls) */
.app-container {
    display: grid;
    grid-template-columns: 1fr 460px; /* Fixed width for controls on desktop */
    gap: 35px;
    max-width: 1200px;
    width: 100%;
    background: var(--panel-bg);
    padding: 40px;
    border-radius: 28px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.08);
    align-items: start; /* Aligns items to top */
}

/* ================= Left Preview Section ================= */
.preview-section {
    text-align: center; display: flex; flex-direction: column; align-items: center;
    position: sticky; top: 40px; /* Keeps preview visible on large screens while scrolling controls */
}
h1 { margin-bottom: 25px; font-size: 28px; font-weight: 800; color: #111; }

.stage-container {
    width: 100%; max-width: 480px; aspect-ratio: 1 / 1;
    border-radius: 24px; overflow: visible;
    background-color: #fff;
    box-shadow: inset 0 0 0 2px var(--border-color);
    margin-bottom: 35px; position: relative;
}
.stage-container svg { width: 100%; height: 100%; display: block; }

.main-actions { width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 12px; }
.btn-large { width: 100%; padding: 16px; font-size: 18px; }

.download-group-custom {
    display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 25px;
    background: #f9fafb; padding: 10px 15px; border-radius: 16px; border: 1px solid var(--border-color);
    width: 100%; max-width: 480px;
}
.download-group-custom label { font-weight: bold; color: #666; white-space: nowrap;}
#download-size {
    width: 80px; padding: 10px; border-radius: 10px; border: 2px solid var(--border-color);
    font-size: 16px; text-align: center; font-weight: bold; color: var(--primary-color);
}
.tip-text { font-size: 12px; color: #999; margin-top: 8px;}

.btn-primary, .btn-secondary {
    border: none; border-radius: 50px; cursor: pointer; font-weight: 700; transition: all 0.2s; color: white; flex-grow: 1; padding: 12px;
}
.btn-primary { background: linear-gradient(135deg, var(--primary-color), #7c4dff); box-shadow: 0 8px 20px -6px rgba(98, 0, 234, 0.5); }
.btn-secondary { background: var(--bg-color); color: var(--text-color); box-shadow: none; border: 2px solid var(--border-color); }
.btn-primary:hover { transform: translateY(-3px); box-shadow: 0 12px 25px -8px rgba(98, 0, 234, 0.6); }
.btn-secondary:hover { background: #e0e0e0; }
.btn-primary:active, .btn-secondary:active { transform: translateY(1px); }

/* ================= Right Controls Section ================= */
.controls-section {
    display: flex; flex-direction: column;
    border: 1px solid var(--border-color); border-radius: 20px; overflow: hidden;
    background: #fcfcfc;
    height: 720px; /* Fixed height for desktop to allow internal scrolling */
}
.tab-headers {
    display: flex; overflow-x: auto; background: white; border-bottom: 1px solid var(--border-color); scrollbar-width: none;
    padding: 5px 5px 0; flex-shrink: 0;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}
.tab-headers::-webkit-scrollbar { display: none; }
.tab-btn {
    padding: 15px 20px; background: none; border: none; font-size: 15px; font-weight: 600; color: #888;
    cursor: pointer; white-space: nowrap; transition: all 0.2s; border-bottom: 4px solid transparent; border-radius: 8px 8px 0 0;
}
.tab-btn.active { color: var(--primary-color); border-bottom-color: var(--primary-color); background: #fcfcfc;}

.tab-contents { flex-grow: 1; overflow-y: auto; padding: 25px; -webkit-overflow-scrolling: touch; }
.tab-pane { display: none; animation: fadeIn 0.3s ease; }
.tab-pane.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.control-group h3 { font-size: 13px; color: #555; margin-bottom: 15px; margin-top: 30px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; display: flex; align-items: center; gap: 8px;}
.control-group h3::before { content: ''; display: block; width: 4px; height: 14px; background: var(--primary-color); border-radius: 2px;}
.control-group h3:first-child { margin-top: 0; }

/* Grids & Color Palettes */
.options-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 12px; }
.option-btn {
    aspect-ratio: 1 / 1; border: 2px solid var(--border-color); border-radius: 16px; background: white;
    cursor: pointer; display: flex; justify-content: center; align-items: center; transition: all 0.2s; padding: 6px;
}
.option-btn svg { width: 100%; height: 100%; fill: #ccc; stroke: #ccc; overflow: visible; filter: grayscale(100%) opacity(0.7); transition: all 0.2s; }
.option-btn:hover { border-color: var(--primary-light); background: #f5f0ff; }
.option-btn:hover svg { filter: grayscale(0%) opacity(1); }
.option-btn.selected { border-color: var(--primary-color); background-color: #ede7f6; box-shadow: 0 0 0 3px rgba(98, 0, 234, 0.15); }
.option-btn.selected svg { fill: var(--primary-color) !important; stroke: var(--primary-color) !important; filter: none; }

.colors-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.color-btn {
    width: 42px; height: 42px; border-radius: 50%; border: 3px solid white;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1); cursor: pointer; transition: transform 0.2s;
}
.color-btn:hover { transform: scale(1.15); z-index: 2;}
.color-btn.selected { box-shadow: 0 0 0 3px var(--primary-color), 0 6px 12px rgba(98, 0, 234, 0.2); border-color: white; transform: scale(1.1);}

/* Modern Range Sliders */
input[type=range] {
    -webkit-appearance: none; width: 100%; height: 8px; background: #e0e0e0; border-radius: 5px; outline: none; margin: 10px 0;
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%; height: 8px; cursor: pointer;
    background: linear-gradient(90deg, var(--primary-color) var(--range-progress, 50%), #e0e0e0 var(--range-progress, 50%));
    border-radius: 5px;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none; border: 3px solid white; height: 20px; width: 20px; border-radius: 50%; background: var(--primary-color); cursor: pointer; margin-top: -6px; box-shadow: 0 2px 5px rgba(0,0,0,0.2); transition: transform 0.1s;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type=range]::-moz-range-track { background: #e0e0e0; height: 8px; border-radius: 5px; }
input[type=range]::-moz-range-thumb {
    border: 3px solid white; height: 20px; width: 20px; border-radius: 50%; background: var(--primary-color); cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
input[type=range]::-moz-range-progress { background-color: var(--primary-color); height: 8px; border-radius: 5px; }

.range-control {
    display: flex; align-items: center; gap: 15px; background: white;
    padding: 15px 20px; border-radius: 16px; border: 2px solid var(--border-color);
    margin-bottom: 15px; box-shadow: 0 4px 10px rgba(0,0,0,0.03);
}
.range-control label { font-size: 14px; font-weight: 700; color: #555; min-width: 50px;}
.range-output { font-family: monospace; font-weight: 800; color: var(--primary-color); min-width: 35px; text-align: right; font-size: 15px;}

.transform-group {
    display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px;
    background: #f8f9fa; padding: 15px; border-radius: 20px; border: 1px solid var(--border-color);
}
.transform-control-compact { display: flex; flex-direction: column; align-items: center; gap: 0px; }
.transform-control-compact label { font-size: 11px; font-weight: 700; color: #888; margin-bottom: 5px; white-space: nowrap;}

/* SEO Content & Footer */
.seo-content-container { max-width: 1000px; margin: 40px auto; padding: 40px; background-color: #ffffff; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); color: #4a5568; line-height: 1.7; }
.seo-content-container h2 { font-size: 2rem; color: #2d3748; margin-top: 40px; margin-bottom: 20px; font-weight: 700; }
.seo-content-container h2:first-child { margin-top: 0; }
.seo-content-container h3 { font-size: 1.4rem; color: #4a5568; margin-top: 30px; margin-bottom: 15px; font-weight: 600; }
.seo-content-container p { margin-bottom: 20px; font-size: 1.05rem; }
.seo-content-container ul { margin-bottom: 25px; padding-left: 25px; }
.seo-content-container li { margin-bottom: 10px; }
.seo-content-container strong { color: #2d3748; font-weight: 600; }
footer { text-align: center; padding: 30px 20px; margin-top: 20px; color: #718096; font-size: 0.9rem; border-top: 1px solid #e2e8f0; width: 100%; max-width: 1200px;}

/* =========================================
   【核心】Mobile Responsiveness
   ========================================= */
@media (max-width: 900px) {
    body {
        padding: 10px; /* Reduce body padding on mobile */
    }
    .app-container {
        grid-template-columns: 1fr; /* Stack vertically */
        gap: 30px;
        padding: 20px; /* Reduce container padding */
    }

    .preview-section {
        position: static; /* Remove sticky on mobile so it scrolls away */
    }

    .stage-container {
        margin-bottom: 25px;
        /* Ensure it doesn't get too small, but fits screen */
        width: 100%; 
        max-width: 400px; 
    }

    .controls-section {
        height: auto; /* Let height grow naturally */
        max-height: 70vh; /* But cap it at 70% viewport height so it doesn't dominate */
        border-radius: 16px;
    }
    
    .tab-contents {
        padding: 20px; /* Slightly less padding in tabs */
    }
    
    .main-actions, .download-group-custom {
         max-width: 400px; /* Match stage container width */
    }

    .seo-content-container {
        margin: 30px 0;
        padding: 25px;
        border-radius: 16px;
    }
    .seo-content-container h2 { font-size: 1.6rem; }
}

/* Small Phone Adjustments */
@media (max-width: 480px) {
    h1 { font-size: 24px; }
    .app-container { padding: 15px; }
    .tab-btn { padding: 12px 15px; font-size: 14px; }
    
    /* Make controls very compact on small screens */
    .options-grid { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); }
    .transform-group { padding: 10px; gap: 8px;}
    
    .download-group-custom { flex-wrap: wrap; justify-content: center;}
    .download-group-custom button { width: 100%; flex-grow: 1;}
}