/* ===== Reset & Variables ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #0f0f14;
    --bg-card: #1a1a24;
    --bg-input: #14141e;
    --bg-hover: #242436;
    --border: #2a2a3e;
    --text: #e8e8f0;
    --text-muted: #8888a0;
    --accent: #a78bfa;
    --accent-hover: #c4b5fd;
    --accent-glow: rgba(167, 139, 250, 0.25);
    --green: #34d399;
    --red: #f87171;
    --orange: #fbbf24;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --transition: 0.2s ease;

    --cat-emotion: #f472b6;
    --cat-scene: #60a5fa;
    --cat-texture: #a78bfa;
    --cat-color: #fbbf24;
    --cat-scent: #34d399;
    --cat-style: #fb923c;
    --cat-nature: #4ade80;
    --cat-story: #e879f9;
}

html { font-size: 14px; }

body {
    font-family: "Microsoft YaHei", "PingFang SC", -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px 200px;
}

/* ===== Header ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.header-left { display: flex; align-items: baseline; gap: 12px; }

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #e879f9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle { font-size: 0.85rem; color: var(--text-muted); }

.btn-settings {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.btn-settings:hover { color: var(--accent); border-color: var(--accent); }

/* ===== Mode Tabs ===== */
.mode-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
}
.tab:hover { color: var(--text); border-color: var(--text-muted); }
.tab.active {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}

/* ===== Input Area ===== */
.input-panel.hidden { display: none; }

.input-group {
    display: flex;
    gap: 10px;
}

#keywordInput {
    flex: 1;
    padding: 14px 18px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
    outline: none;
    transition: var(--transition);
}
#keywordInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
#keywordInput::placeholder { color: var(--text-muted); }

.btn-primary {
    padding: 14px 28px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border: none;
    border-radius: var(--radius);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-text, .btn-loading { display: inline-flex; align-items: center; gap: 6px; }

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Upload Zone ===== */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 12px;
    position: relative;
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--accent);
    background: rgba(167, 139, 250, 0.05);
}

.upload-placeholder { color: var(--text-muted); }
.upload-placeholder p { margin-top: 12px; font-size: 1rem; }
.upload-hint { font-size: 0.8rem; opacity: 0.6; display: block; margin-top: 6px; }

.image-preview {
    max-width: 100%;
    max-height: 260px;
    border-radius: var(--radius-sm);
    object-fit: contain;
}
.image-preview.hidden { display: none; }

#imagePanel .btn-primary { width: 100%; }

/* ===== Error Bar ===== */
.error-bar {
    background: rgba(248, 113, 113, 0.12);
    border: 1px solid var(--red);
    color: var(--red);
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.error-bar.hidden { display: none; }
.btn-close-error {
    background: none; border: none; color: var(--red);
    font-size: 1.3rem; cursor: pointer; padding: 0 4px;
}

/* ===== Results Area ===== */
.results-area { margin-top: 28px; }
.results-area.hidden { display: none; }

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.results-header h2 { font-size: 1.2rem; font-weight: 600; }

.results-actions { display: flex; gap: 8px; }

.btn-outline {
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    transition: var(--transition);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 5px 12px; }

/* ===== Category Cards ===== */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

@media (max-width: 700px) {
    .categories-grid { grid-template-columns: 1fr; }
}

.category-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    transition: var(--transition);
}
.category-card:hover { border-color: var(--bg-hover); }

.category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.category-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.95rem;
}

.category-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.category-actions { display: flex; gap: 6px; }

.btn-cat-action {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: var(--transition);
}
.btn-cat-action:hover { color: var(--accent); background: var(--accent-glow); }

.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    user-select: none;
}
.tag:hover { border-color: var(--text-muted); }
.tag.selected {
    border-color: var(--accent);
    background: var(--accent-glow);
    color: var(--accent-hover);
}

/* Per-category accent on selected tags */
.category-card[data-cat="情感/情绪"] .tag.selected { border-color: var(--cat-emotion); color: var(--cat-emotion); background: rgba(244, 114, 182, 0.15); }
.category-card[data-cat="场景/空间"] .tag.selected { border-color: var(--cat-scene); color: var(--cat-scene); background: rgba(96, 165, 250, 0.15); }
.category-card[data-cat="材质/质感"] .tag.selected { border-color: var(--cat-texture); color: var(--cat-texture); background: rgba(167, 139, 250, 0.15); }
.category-card[data-cat="色彩/光影"] .tag.selected { border-color: var(--cat-color); color: var(--cat-color); background: rgba(251, 191, 36, 0.15); }
.category-card[data-cat="气味/香调"] .tag.selected { border-color: var(--cat-scent); color: var(--cat-scent); background: rgba(52, 211, 153, 0.15); }
.category-card[data-cat="风格/时代"] .tag.selected { border-color: var(--cat-style); color: var(--cat-style); background: rgba(251, 146, 60, 0.15); }
.category-card[data-cat="自然/元素"] .tag.selected { border-color: var(--cat-nature); color: var(--cat-nature); background: rgba(74, 222, 128, 0.15); }
.category-card[data-cat="人物/故事"] .tag.selected { border-color: var(--cat-story); color: var(--cat-story); background: rgba(232, 121, 249, 0.15); }

/* Category dot colors */
.category-card[data-cat="情感/情绪"] .category-dot { background: var(--cat-emotion); }
.category-card[data-cat="场景/空间"] .category-dot { background: var(--cat-scene); }
.category-card[data-cat="材质/质感"] .category-dot { background: var(--cat-texture); }
.category-card[data-cat="色彩/光影"] .category-dot { background: var(--cat-color); }
.category-card[data-cat="气味/香调"] .category-dot { background: var(--cat-scent); }
.category-card[data-cat="风格/时代"] .category-dot { background: var(--cat-style); }
.category-card[data-cat="自然/元素"] .category-dot { background: var(--cat-nature); }
.category-card[data-cat="人物/故事"] .category-dot { background: var(--cat-story); }

/* ===== Prompt Builder ===== */
.prompt-builder {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 16px 24px;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.5);
    z-index: 100;
}
.prompt-builder.hidden { display: none; }

.prompt-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
}
.prompt-header h3 { font-size: 0.95rem; font-weight: 500; }

.selected-count {
    color: var(--accent);
    font-weight: 700;
    font-size: 1.1rem;
}

.template-switcher { display: flex; gap: 6px; }

.template-btn {
    padding: 5px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
}
.template-btn:hover { border-color: var(--text-muted); color: var(--text); }
.template-btn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

.prompt-content {
    position: relative;
    max-width: 1100px;
    margin: 0 auto;
}

#promptOutput {
    width: 100%;
    min-height: 80px;
    max-height: 140px;
    padding: 12px 60px 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    font-family: inherit;
}

.btn-copy {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
}
.btn-copy:hover { border-color: var(--accent); color: var(--accent); }
.btn-copy.copied { border-color: var(--green); color: var(--green); }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 440px;
    max-width: 90vw;
    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.1rem; }

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}
.btn-close:hover { color: var(--text); }

.modal-body { padding: 20px; }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.form-select, .form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
}
.form-select:focus, .form-input:focus {
    border-color: var(--accent);
}
.form-select option { background: var(--bg-card); }
.form-select optgroup { color: var(--accent); font-style: normal; font-weight: 700; padding: 6px 0; }
.form-select optgroup option { color: var(--text); font-weight: 400; padding-left: 8px; }

.modal-body .btn-primary { width: 100%; margin-top: 8px; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Animation ===== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.category-card {
    animation: fadeInUp 0.4s ease forwards;
    opacity: 0;
}
.category-card:nth-child(1) { animation-delay: 0.05s; }
.category-card:nth-child(2) { animation-delay: 0.10s; }
.category-card:nth-child(3) { animation-delay: 0.15s; }
.category-card:nth-child(4) { animation-delay: 0.20s; }
.category-card:nth-child(5) { animation-delay: 0.25s; }
.category-card:nth-child(6) { animation-delay: 0.30s; }
.category-card:nth-child(7) { animation-delay: 0.35s; }
.category-card:nth-child(8) { animation-delay: 0.40s; }
