/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #FF6B6B;
    --primary-dark: #ee5a5a;
    --secondary: #4ECDC4;
    --accent: #FFE66D;
    --bg: #1a1a2e;
    --bg-light: #16213e;
    --bg-card: #0f3460;
    --text: #e8e8e8;
    --text-muted: #a0a0b0;
    --border: #2a2a4a;
    --shadow: rgba(0, 0, 0, 0.3);
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ===== App Container ===== */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* ===== Header ===== */
.app-header {
    text-align: center;
    padding: 30px 20px;
    background: linear-gradient(135deg, var(--bg-light), var(--bg-card));
    border-radius: var(--radius);
    margin-bottom: 20px;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.app-header::before {
    content: '😂🤣😜🤪😎🥳🤩😏';
    position: absolute;
    top: -10px;
    left: 0;
    right: 0;
    font-size: 20px;
    letter-spacing: 20px;
    opacity: 0.15;
    animation: scrollEmoji 20s linear infinite;
}

@keyframes scrollEmoji {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.app-header h1 {
    font-size: 2.2rem;
    background: linear-gradient(135deg, var(--primary), var(--accent), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
}

/* ===== Main Content Layout ===== */
.main-content {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 20px;
    align-items: start;
}

/* ===== Control Panel ===== */
.control-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    padding-right: 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) var(--bg-light);
}

.control-panel::-webkit-scrollbar {
    width: 6px;
}

.control-panel::-webkit-scrollbar-track {
    background: var(--bg-light);
    border-radius: 3px;
}

.control-panel::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 3px;
}

/* ===== Panel Section ===== */
.panel-section {
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    transition: border-color 0.3s;
}

.panel-section:hover {
    border-color: var(--primary);
}

.panel-section h2 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ===== Upload Area ===== */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg-card);
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary);
    background: rgba(255, 107, 107, 0.05);
    transform: scale(1.02);
}

.upload-area.dragover {
    animation: pulse 0.5s ease infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1.02); }
    50% { transform: scale(1.04); }
}

.upload-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 10px;
}

.upload-area p {
    color: var(--text-muted);
    margin: 4px 0;
}

.upload-hint {
    font-size: 0.85rem;
    opacity: 0.7;
}

.upload-area.has-image {
    padding: 10px;
}

.upload-area.has-image .upload-placeholder {
    display: none;
}

.upload-preview {
    max-width: 100%;
    max-height: 120px;
    border-radius: var(--radius-sm);
    display: none;
}

.upload-area.has-image .upload-preview {
    display: block;
    margin: 0 auto;
}

/* ===== Template Grid ===== */
.template-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--secondary) var(--bg);
}

.template-grid::-webkit-scrollbar {
    width: 4px;
}

.template-grid::-webkit-scrollbar-thumb {
    background: var(--secondary);
    border-radius: 2px;
}

.template-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 4px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.75rem;
    line-height: 1.3;
}

.template-item:hover {
    border-color: var(--secondary);
    background: rgba(78, 205, 196, 0.1);
    transform: translateY(-2px);
}

.template-item .template-emoji {
    font-size: 1.5rem;
    display: block;
    margin-bottom: 4px;
}

.template-item .template-name {
    color: var(--text-muted);
}

/* ===== Text Controls ===== */
.text-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.text-input-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.text-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    transition: border-color 0.3s;
    outline: none;
}

.text-input:focus {
    border-color: var(--primary);
}

.custom-text-row {
    display: flex;
    gap: 8px;
}

.custom-text-row .text-input {
    flex: 1;
}

/* ===== Style Controls ===== */
.style-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.control-row label {
    min-width: 70px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.control-row input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg);
    border-radius: 3px;
    outline: none;
}

.control-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

.control-row input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.range-value {
    min-width: 35px;
    text-align: right;
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: bold;
}

.control-row input[type="color"] {
    width: 40px;
    height: 30px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: transparent;
    padding: 2px;
}

.control-row input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.control-row input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

.font-select {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

.font-select:focus {
    border-color: var(--primary);
}

/* ===== Edit Controls ===== */
.edit-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
    outline: none;
}

.btn:hover {
    border-color: var(--primary);
    background: rgba(255, 107, 107, 0.1);
}

.btn-icon {
    font-size: 1.2rem;
    padding: 8px 12px;
    min-width: 42px;
    text-align: center;
}

.btn-add {
    background: var(--secondary);
    border-color: var(--secondary);
    color: #1a1a2e;
    font-weight: bold;
    white-space: nowrap;
}

.btn-add:hover {
    background: #3dbdb5;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    font-weight: bold;
    font-size: 1rem;
    padding: 12px 20px;
    width: 100%;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
}

.filter-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.filter-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.btn-filter {
    font-size: 0.8rem;
    padding: 6px 10px;
}

.btn-filter.active {
    background: var(--secondary);
    border-color: var(--secondary);
    color: #1a1a2e;
    font-weight: bold;
}

/* ===== Export Controls ===== */
.export-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.export-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.export-row label {
    min-width: 50px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.format-select {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

/* ===== Batch Controls ===== */
.batch-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.batch-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
    outline: none;
    line-height: 1.5;
}

.batch-textarea:focus {
    border-color: var(--primary);
}

.batch-progress {
    display: flex;
    align-items: center;
    gap: 10px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--secondary), var(--primary));
    border-radius: 4px;
    transition: width 0.3s;
    width: 0%;
}

#progressText {
    font-size: 0.85rem;
    color: var(--accent);
    min-width: 40px;
}

/* ===== Preview Panel ===== */
.preview-panel {
    position: sticky;
    top: 20px;
}

.preview-container {
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.preview-container h2 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--accent);
}

.canvas-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: repeating-conic-gradient(#2a2a4a 0% 25%, #1a1a2e 0% 50%) 50% / 20px 20px;
    border-radius: var(--radius);
    overflow: hidden;
    min-height: 400px;
}

#previewCanvas {
    max-width: 100%;
    max-height: 500px;
    display: block;
}

.canvas-placeholder {
    position: absolute;
    text-align: center;
    color: var(--text-muted);
}

.placeholder-emoji {
    font-size: 4rem;
    display: block;
    margin-bottom: 10px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.canvas-placeholder p {
    font-size: 1.1rem;
}

.canvas-info {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== Custom Text List ===== */
.custom-text-list {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.custom-text-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
}

.custom-text-item .item-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.custom-text-item .item-text {
    font-size: 0.85rem;
    cursor: grab;
}

.custom-text-item .item-text:active {
    cursor: grabbing;
}

.custom-text-item .item-position {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.custom-text-item .item-delete {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px;
    transition: transform 0.2s;
}

.custom-text-item .item-delete:hover {
    transform: scale(1.3);
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-card);
    border: 1px solid var(--primary);
    color: var(--text);
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    box-shadow: 0 4px 20px var(--shadow);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    color: var(--accent);
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--primary);
}

.modal-body {
    padding: 20px;
}

.batch-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.batch-result-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.batch-result-item img {
    width: 100%;
    display: block;
}

.batch-result-item .result-info {
    padding: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

.batch-result-item .result-download {
    display: block;
    text-align: center;
    padding: 6px;
    background: var(--bg-card);
    color: var(--secondary);
    text-decoration: none;
    font-size: 0.8rem;
    transition: background 0.2s;
}

.batch-result-item .result-download:hover {
    background: rgba(78, 205, 196, 0.1);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .control-panel {
        max-height: none;
    }

    .preview-panel {
        position: static;
    }

    .app-header h1 {
        font-size: 1.6rem;
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 10px;
    }

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

    .btn-group {
        gap: 4px;
    }
}
