/* =====================================================
   [1] 基础变量与重置 (Variables & Reset)
   ===================================================== */
:root {
    --primary-color: #bd1f1f;
    --primary-dark: #a11717;
    --accent-color: #ff4757;
    --bg-background: #f6f6f6;
    --bg-card: #ffffff;
    --text-main: #333333;
    --text-light: #777777;
    --border-color: #eeeeee;
    --transition-speed: 0.3s;
    --card-radius: 15px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-background);
    color: var(--text-main);
    line-height: 1.6;
    /* 禁止用户选中文字，防止 PDF 抓取干扰 */
    -webkit-user-select: none;
    user-select: none;
}

a {
    text-decoration: none;
    color: inherit;
}

/* =====================================================
   [2] 页面公共组件 (Topbar & Footer)
   ===================================================== */
.topbar {
    background-color: var(--primary-color);
    color: #ffffff;
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.topbar .logo {
    font-size: 1.5rem;
    font-weight: bold;
}

.topbar nav a {
    margin-left: 20px;
    font-weight: 600;
    color: #ffffff;
    transition: opacity var(--transition-speed);
}

.topbar nav a:hover {
    opacity: 0.8;
}

.footer {
    text-align: center;
    padding: 40px 20px;
    background-color: #f3f3f3;
    color: var(--text-light);
    font-size: 0.9rem;
    margin-top: 50px;
}

/* =====================================================
   [3] 顶部横幅 (Hero Banner)
   ===================================================== */
.hero-banner {
    height: 45vh;
    width: 100%;
    /* 渐变遮罩 + 背景图 */
    background-image: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), 
                      url('https://images.unsplash.com/photo-1543353071-873f17a7a088?auto=format&fit=crop&w=1600&q=80');
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #ffffff;
    text-align: center;
}

.hero-banner h1 {
    font-size: 3rem;
    margin: 0 0 10px 0;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    text-transform: capitalize;
}

.hero-banner p {
    font-size: 1.2rem;
    margin: 0;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
}

/* =====================================================
   [4] 分类导航条 (Scroll Nav)
   ===================================================== */
.section-nav {
    background-color: #ffffff;
    padding: 15px 10px;
    display: flex;
    justify-content: center;
    gap: 12px;
    overflow-x: auto; /* 支持横向滚动 */
    white-space: nowrap;
    border-bottom: 1px solid var(--border-color);
}

/* 隐藏滚动条但保留功能 */
.section-nav::-webkit-scrollbar {
    display: none;
}

.nav-chip {
    padding: 8px 22px;
    border-radius: 30px;
    border: 1px solid #dddddd;
    font-weight: 600;
    color: #444444;
    transition: all var(--transition-speed);
}

.nav-chip:hover {
    background-color: var(--accent-color);
    color: #ffffff;
    border-color: var(--accent-color);
}

/* =====================================================
   [5] 菜谱列表布局 (Grid & Card Logic)
   ===================================================== */
.main-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
}

.recipe-section {
    padding: 40px 0;
    border-bottom: 1px solid #f5f5f5;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.section-header h2 {
    color: var(--primary-color);
    font-size: 1.8rem;
    margin: 0;
    padding-left: 15px;
    border-left: 5px solid var(--primary-color);
}

.view-all {
    color: var(--accent-color);
    font-weight: bold;
    font-size: 0.95rem;
}

.recipe-grid {
    display: flex;
    flex-wrap: wrap; /* 允许换行 */
    gap: 20px;      /* 卡片间距 */
}

.recipe-card {
    /* 核心：三格基准，自动拉伸充满 */
    flex-grow: 1;
    flex-shrink: 1;
    flex-basis: calc(33.333% - 20px);
    
    min-width: 280px;
    max-width: 100%;
    background-color: var(--bg-card);
    border-radius: var(--card-radius);
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}

.recipe-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.12);
}

.recipe-card .img-box {
    width: 100%;
    height: 220px;
    background-color: #eeeeee;
}

.recipe-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.recipe-card .info {
    padding: 20px;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.recipe-card h4 {
    margin: 0;
    font-size: 1.15rem;
    color: #222222;
    line-height: 1.4;
}

.back-link {
    display: inline-block;
    margin-bottom: 20px;
    color: var(--accent-color);
    font-weight: 600;
}


@media print {
    .topbar, .footer, .pdf-btn, .section-nav, .view-all, .back-link {
        display: none !important;
    }
    .recipe-container {
        box-shadow: none !important;
        margin: 0 !important;
        width: 100% !important;
    }
}

@media (max-width: 768px) {
    .recipe-card {
        /* 手机端占满全行 */
        flex-basis: 100%;
    }
    .hero-banner h1 {
        font-size: 2.2rem;
    }
    .section-nav {
        justify-content: flex-start;
        padding-left: 15px;
    }
}

/* =====================================================
   广告位布局样式
   ===================================================== */

/* 1. 整体包装层，使用 Flex 布局 */
.main-wrapper {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    max-width: 1200px; /* 根据屏幕宽度调整 */
    margin: 0 auto;
    gap: 20px;
}

/* 2. 侧边广告通用样式 */
.side-ad {
    flex: 0 0 300px; /* 固定 300px 宽度 */
    position: sticky;
    top: 20px;       /* 随页面滚动时悬浮在顶部 */
    margin-top: 50px;
    z-index: 10;
}

/* 3. 底部固定横幅 */
.bottom-ad-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    border-top: 1px solid #ddd;
    padding: 10px 0;
    text-align: center;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
}

/* 4. 响应式：屏幕太小时隐藏侧边广告，防止挤压内容 */
@media (max-width: 1400px) {
    .side-ad {
        display: none;
    }
    .main-wrapper {
        display: block; /* 恢复单列显示 */
    }
    .main-container {
        max-width: 1000px;
        margin: 0 auto;
    }
}

/* 调整底部间距，防止广告遮挡 Footer 内容 */
footer {
    padding-bottom: 100px !important;
}

/* =====================================================
   [8] 搜索页面专有样式 (Search Results Styles)
   ===================================================== */

/* 搜索容器 */
.search-section {
    padding-top: 40px;
}

.search-section h1 {
    color: var(--primary-color);
    margin-bottom: 10px;
}

.subtitle {
    color: var(--text-light);
    margin-bottom: 30px;
}

/* 搜索框增强 */
.search-box {
    display: flex;
    gap: 10px;
    max-width: 600px;
}

.search-box input {
    flex: 1;
    padding: 12px 20px;
    border: 2px solid var(--border-color);
    border-radius: 30px;
    font-size: 1rem;
    outline: none;
    transition: border-color var(--transition-speed);
}

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

.search-box button {
    padding: 12px 30px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 30px;
    font-weight: bold;
    cursor: pointer;
    transition: background var(--transition-speed);
}

.search-box button:hover {
    background-color: var(--primary-dark);
}

/* 搜索结果卡片 */
.results-container {
    margin-top: 30px;
}

.recipe-card-search {
    background-color: var(--bg-card);
    border-radius: var(--card-radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    transition: transform var(--transition-speed);
}

.recipe-card-search:hover {
    transform: translateX(5px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.1);
}

.card-inner {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.search-result-img {
    width: 200px;
    height: 140px;
    object-fit: cover;
    border-radius: 10px;
    flex-shrink: 0;
}

.card-info {
    flex: 1;
}

.card-info h3 {
    margin: 0 0 10px 0;
    color: var(--primary-color);
}

.ingredients-list {
    font-size: 0.9rem;
    color: var(--text-main);
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.description-text {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-bottom: 15px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.view-details-btn {
    display: inline-block;
    color: var(--primary-color);
    font-weight: bold;
    font-size: 0.9rem;
    text-decoration: underline;
}

/* 高亮样式 */
mark {
    background-color: rgba(189, 31, 31, 0.1);
    color: var(--primary-color);
    padding: 0 2px;
    border-radius: 2px;
}

/* 状态提示 */
.search-placeholder, .no-results, .error {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
    background: #fff;
    border-radius: var(--card-radius);
}

/* 移动端搜索结果适配 */
@media (max-width: 600px) {
    .card-inner {
        flex-direction: column;
    }
    
    .search-result-img {
        width: 100%;
        height: 180px;
    }

    .search-box {
        flex-direction: column;
    }
    
    .search-box input, .search-box button {
        width: 100%;
    }
}

/* =====================================================
   [9] AI 生成页专有样式 (Generation Page Styles)
   ===================================================== */

/* 头部文案 */
.gen-header {
    text-align: center;
    padding: 30px 0;
}

.gen-header h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 10px;
}

/* 标签选择器 (Chips) */
.tag-selector {
    margin: 20px 0;
}

.tag-label {
    display: block;
    font-weight: bold;
    margin-bottom: 12px;
    color: var(--text-main);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.chip {
    padding: 8px 18px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.chip:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.chip.selected {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

/* 生成表单布局 */
.gen-form {
    background: white;
    padding: 30px;
    border-radius: var(--card-radius);
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
}

.input-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
}

.input-group label {
    font-weight: 600;
    margin-bottom: 8px;
    color: #444;
}

.input-group input {
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
}

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

.form-row {
    display: flex;
    gap: 20px;
}

.form-row .input-group {
    flex: 1;
}

/* 文件上传自定义 */
.file-custom {
    position: relative;
}

.file-custom input[type="file"] {
    width: 100%;
    padding: 8px;
    background: #f9f9f9;
    border: 1px dashed #ccc;
    cursor: pointer;
}

/* 提交按钮与加载器 */
.submit-btn {
    width: 100%;
    padding: 15px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.3s;
}

.submit-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.loader {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* =====================================================
   [10] AI 生成结果卡片 (AI Result Card)
   ===================================================== */
.result-area {
    margin: 40px 0;
}

.generated-recipe-card {
    background: white;
    border-radius: var(--card-radius);
    border: 2px solid var(--primary-color);
    overflow: hidden;
    animation: fadeIn 0.6s ease-out;
}

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

.recipe-header-gen {
    background: #fff5f5;
    padding: 30px;
    text-align: center;
    border-bottom: 1px solid #ffebeb;
}

.badge {
    background: var(--primary-color);
    color: white;
    padding: 4px 12px;
    border-radius: 40px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.recipe-tags-row {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    gap: 15px;
}

.recipe-content-gen {
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.recipe-content-gen h3 {
    color: var(--primary-color);
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.recipe-footer-gen {
    padding: 20px;
    background: #f9f9f9;
    text-align: center;
}

/* SEO 内容区块 */
.seo-content {
    margin-top: 60px;
    border-top: 2px solid #eee;
    padding-top: 40px;
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 30px;
}

.feat {
    background: #fff;
    padding: 20px;
    border-radius: 10px;
    border: 1px solid #eee;
}

.link-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
}

.link-cloud a {
    font-size: 0.9rem;
    color: #666;
    background: #eee;
    padding: 5px 12px;
    border-radius: 4px;
}

.link-cloud a:hover {
    background: var(--primary-color);
    color: white;
}

/* =====================================================
   [11] 菜谱详情页专有样式 (Recipe Detail Page)
   ===================================================== */

/* 详情页专用容器 */
.recipe-container {
    background: #ffffff;
    padding: 40px;
    border-radius: var(--card-radius);
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    margin-bottom: 40px;
}

/* 标题 */
.recipe-title {
    font-size: 2.5rem;
    color: var(--text-dark);
    margin-bottom: 20px;
    line-height: 1.2;
}

/* 元数据（标签、时间、难度） */
.recipe-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 25px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 15px;
}

.recipe-meta .tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.recipe-meta .tag {
    background: #f0f0f0;
    color: #666;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    text-transform: capitalize;
}

.recipe-meta .info {
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    gap: 20px;
}

/* 详情页大图 */
.recipe-banner {
    width: 100%;
    max-height: 500px;
    object-fit: cover;
    border-radius: 12px;
    margin-bottom: 40px;
}

/* 详情页章节通用 */
.recipe-container h2 {
    font-size: 1.8rem;
    color: var(--primary-color);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
}

.recipe-container h2::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #eee;
    margin-left: 15px;
}

/* 食材列表样式 */
.ingredients ul {
    list-style: none;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.ingredients li {
    padding: 10px 0;
    border-bottom: 1px dashed #eee;
    display: flex;
    justify-content: space-between;
}

.ingredients li span {
    color: var(--text-light);
    font-size: 0.9rem;
}

/* 烹饪步骤样式 */
.steps ol {
    padding-left: 25px;
}

.steps li {
    margin-bottom: 20px;
    padding-left: 10px;
    line-height: 1.8;
}

.steps li::marker {
    color: var(--primary-color);
    font-weight: bold;
    font-size: 1.2rem;
}

/* PDF 导出时的修正 */
.pdf-mode .recipe-container {
    box-shadow: none;
    padding: 0;
}

.pdf-mode .recipe-title {
    font-size: 2rem;
}

/* 按钮样式补充 */
.pdf-btn {
    background: white;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
    padding: 10px 20px;
    border-radius: 30px;
    cursor: pointer;
    font-weight: bold;
    margin: 5px;
    transition: all 0.3s;
}

.pdf-btn:hover {
    background: var(--primary-color);
    color: white;
}

/* 详情页中心主体宽度微调 */
.central-content {
    flex: 1;
    min-width: 0; /* 防止内容撑破 flex */
    max-width: 900px;
}

/* =====================================================
   打印控制
   ===================================================== */
@media print {
    .no-print {
        display: none !important;
    }
}

/* 移动端适配 */
@media (max-width: 768px) {
    .recipe-container {
        padding: 20px;
    }
    .recipe-title {
        font-size: 1.8rem;
    }
    .ingredients ul {
        grid-template-columns: 1fr;
    }
}