/* 移动版样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-y: contain; /* 减少下拉时顶部空白弹性回弹 */
}

html, body {
    height: 100%;
    touch-action: pan-x pan-y;
}

.container {
    max-width: 100%;
    min-height: 100vh;
    min-height: 100svh; /* 现代浏览器更稳的视口高度，避免地址栏伸缩导致跳动 */
    display: flex;
    flex-direction: column;
}

/* 头部样式 */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 20px;
    padding-top: calc(15px + env(safe-area-inset-top));
    display: flex;
    gap: 8px;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    will-change: transform;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
}

.header-nav {
    display: flex;
    gap: 15px;
}

.nav-link {
    color: white;
    text-decoration: none;
    font-size: 14px;
    padding: 5px 10px;
    border-radius: 15px;
    background: rgba(255,255,255,0.2);
    transition: background 0.3s;
}

.nav-link:hover {
    background: rgba(255,255,255,0.3);
}

.header-back {
    display: flex;
    align-items: center;
}

.back-btn {
    color: white;
    text-decoration: none;
    font-size: 16px;
    padding: 5px;
}

/* 分类导航样式 */
.category-nav {
    background: white;
    border-bottom: 1px solid #e0e0e0;
    padding: 15px 20px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.category-list {
    display: flex;
    gap: 5px;
    min-width: max-content;
    padding-bottom: 15px;
}

.category-item {
    padding: 8px 16px;
    border-radius: 20px;
    background: #f5f5f5;
    color: #666;
    text-decoration: none;
    font-size: 14px;
    white-space: nowrap;
    transition: all 0.3s;
    border: 2px solid transparent;
}

.category-item:hover {
    background: #e3f2fd;
    color: #1976d2;
}

.category-item.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
}

.header form {
    flex: 1 1 260px;
    max-width: 520px;
    min-width: 120px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap; /* 保证输入与按钮同一行 */
}

.header form input[type="text"],
.header form input[type="search"] {
    width: auto; /* 与flex搭配，避免把按钮挤到下一行 */
    padding: 8px 12px;
    border: 1px solid rgba(255,255,255,0.6);
    border-radius: 16px;
    background: rgba(255,255,255,0.2);
    color: #fff;
}

.header form input[type="text"],
.header form input[type="search"] {
    flex: 1 1 auto; /* 输入框自适应占满剩余 */
    min-width: 0;   /* 允许在极小宽度下收缩而不换行 */
}

.header form button,
.header form .nav-link {
    flex: 0 0 auto;    /* 固定宽度，不被压缩 */
    white-space: nowrap; /* 按钮文字不换行 */
}

.header form input::placeholder {
    color: rgba(255,255,255,0.85);
}

/* 主内容区 */
.main {
    flex: 1;
    padding: 20px;
    -webkit-overflow-scrolling: touch; /* iOS 惯性滚动 */
}

/* 修正 iOS Safari 聚焦输入框时自动放大：确保字体至少16px */
input, textarea, select {
    font-size: 16px;
}

.header input[type="text"],
.header input[type="search"],
.header form input {
    font-size: 16px;
}

/* 文章列表样式 */
.article-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.article-item {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 15px rgba(0,0,0,0.08);
    transition: transform 0.2s, box-shadow 0.2s;
}

.article-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 25px rgba(0,0,0,0.12);
}

.article-cover {
    width: 100%;
    height: 200px;
    overflow: hidden;
}

.article-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.article-content {
    padding: 15px;
}

.article-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 10px;
    line-height: 1.4;
}

.article-title a {
    color: #333;
    text-decoration: none;
}

.article-title a:hover {
    color: #667eea;
}

.article-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 12px;
    color: #666;
}

.article-meta span {
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 10px;
}

.category {
    background: #e3f2fd !important;
    color: #1976d2 !important;
}

.article-excerpt {
    color: #666;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 15px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.article-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
    border-top: 1px solid #f0f0f0;
}

.price-tag {
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
    color: white;
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: 600;
}

.free-tag {
    background: linear-gradient(135deg, #51cf66, #40c057);
    color: white;
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: 600;
}

.purchase-count {
    font-size: 12px;
    color: #666;
}

/* 文章详情页样式 */
.article-detail {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 15px rgba(0,0,0,0.08);
}

.article-header {
    padding: 20px;
    border-bottom: 1px solid #f0f0f0;
}

.article-detail .article-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 15px;
    line-height: 1.3;
}

.article-detail .article-cover {
    height: 250px;
    margin-top: 15px;
}

.article-detail .article-content {
    padding: 20px;
}

.content {
    font-size: 16px;
    line-height: 1.8;
    color: #333;
}

/* 富文本内容样式 */
.rich-content {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.rich-content h1,
.rich-content h2,
.rich-content h3,
.rich-content h4,
.rich-content h5,
.rich-content h6 {
    margin: 1.5em 0 0.5em 0;
    font-weight: 600;
    line-height: 1.3;
}

.rich-content h1 { font-size: 1.8em; color: #2c3e50; }
.rich-content h2 { font-size: 1.6em; color: #34495e; }
.rich-content h3 { font-size: 1.4em; color: #34495e; }
.rich-content h4 { font-size: 1.2em; color: #34495e; }
.rich-content h5 { font-size: 1.1em; color: #34495e; }
.rich-content h6 { font-size: 1em; color: #34495e; }

.rich-content p {
    margin: 1em 0;
    line-height: 1.8;
}

.rich-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin: 1em 0;
}

.rich-content video {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1em 0;
}

.rich-content blockquote {
    border-left: 4px solid #667eea;
    background: #f8f9fa;
    padding: 1em 1.5em;
    margin: 1.5em 0;
    border-radius: 0 8px 8px 0;
    font-style: italic;
    color: #555;
}

.rich-content ul,
.rich-content ol {
    margin: 1em 0;
    padding-left: 2em;
}

.rich-content li {
    margin: 0.5em 0;
    line-height: 1.6;
}

.rich-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.rich-content th,
.rich-content td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #e3e6f0;
}

.rich-content th {
    background: #f8f9fa;
    font-weight: 600;
    color: #2c3e50;
}

.rich-content tr:hover {
    background: #f8f9fa;
}

.rich-content code {
    background: #f1f3f4;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
    font-size: 0.9em;
    color: #e74c3c;
}

.rich-content pre {
    background: #2c3e50;
    color: #ecf0f1;
    padding: 1.5em;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1.5em 0;
    font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
    font-size: 0.9em;
    line-height: 1.4;
}

.rich-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.rich-content a {
    color: #667eea;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.3s;
}

.rich-content a:hover {
    border-bottom-color: #667eea;
}

.rich-content strong,
.rich-content b {
    font-weight: 600;
    color: #2c3e50;
}

.rich-content em,
.rich-content i {
    font-style: italic;
    color: #34495e;
}

.rich-content hr {
    border: none;
    height: 2px;
    background: linear-gradient(to right, transparent, #e3e6f0, transparent);
    margin: 2em 0;
}

.rich-content .mce-content-body {
    font-size: inherit;
    font-family: inherit;
    line-height: inherit;
}

/* 响应式调整 */
@media (max-width: 768px) {
    .rich-content {
        font-size: 15px;
    }
    
    .rich-content h1 { font-size: 1.6em; }
    .rich-content h2 { font-size: 1.4em; }
    .rich-content h3 { font-size: 1.3em; }
    
    .rich-content table {
        font-size: 14px;
    }
    
    .rich-content th,
    .rich-content td {
        padding: 8px 10px;
    }
    
    .rich-content pre {
        font-size: 0.8em;
        padding: 1em;
    }
}

.content-preview {
    text-align: center;
    padding: 40px 20px;
}

.content-locked {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 30px 20px;
    margin-top: 20px;
}

.lock-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.content-locked p {
    color: #666;
    font-size: 14px;
}

/* 购买区域样式 */
.purchase-section {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 25px;
    margin: 20px -20px -20px -20px;
    text-align: center;
}

.price-info {
    margin-bottom: 20px;
}

.price {
    font-size: 28px;
    font-weight: 700;
    display: block;
    margin-bottom: 5px;
}

.purchase-section .purchase-count {
    color: rgba(255,255,255,0.8);
    font-size: 14px;
}

.purchase-btn {
    background: white;
    color: #667eea;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: transform 0.2s;
}

.purchase-btn:hover {
    transform: translateY(-2px);
}

.purchase-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* 分页样式 */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 30px;
    padding: 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 15px rgba(0,0,0,0.08);
}

.page-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 14px;
    transition: transform 0.2s;
}

.page-btn:hover {
    transform: translateY(-2px);
}

.page-info {
    font-size: 14px;
    color: #666;
}

/* 底部样式 */
.footer {
    background: #333;
    color: white;
    text-align: center;
    padding: 20px;
    margin-top: 40px;
}

.footer p {
    font-size: 12px;
    opacity: 0.8;
}

/* 底部Tab栏 */
.with-tabbar {
    padding-bottom: 80px; /* 预留底部空间，避免内容被遮挡 */
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
}

.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 60px;
    background: rgba(255,255,255,0.98);
    border-top: 1px solid #e0e0e0;
    box-shadow: 0 -6px 20px rgba(0,0,0,0.06);
    backdrop-filter: saturate(180%) blur(8px);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom);
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: transform;
}

.tabbar a.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: #666;
    font-size: 12px;
    width: 20%;
}

.tabbar .tab-icon {
    font-size: 22px;
    line-height: 1;
    margin-bottom: 2px;
}

.tabbar a.tab-item.active {
    color: #667eea;
}

/* iOS 专用优化（Safari 特征检测） */
@supports (-webkit-touch-callout: none) {
    body {
        overscroll-behavior-y: none; /* 降低顶部回弹 */
    }
    .header, .tabbar {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        will-change: transform;
    }
}

/* 表单样式 */
.form-container {
    background: white;
    border-radius: 12px;
    padding: 30px 20px;
    box-shadow: 0 2px 15px rgba(0,0,0,0.08);
    margin-bottom: 20px;
}

.form-title {
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 30px;
    color: #333;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
}

.form-input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
}

.form-input:focus {
    outline: none;
    border-color: #667eea;
}

.form-btn {
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
}

.form-btn:hover {
    transform: translateY(-2px);
}

.form-links {
    text-align: center;
    margin-top: 20px;
}

.form-links a {
    color: #667eea;
    text-decoration: none;
    font-size: 14px;
}

.error-message {
    background: #ffebee;
    color: #c62828;
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
}

.success-message {
    background: #e8f5e8;
    color: #2e7d32;
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 480px) {
    .header { flex-wrap: wrap; }
    .header h1 { font-size: 18px; }
    .header-nav { order: 2; }
    .header form { order: 3; flex: 1 0 100%; max-width: 100%; margin-top: 6px; }
    .nav-link { font-size: 12px; padding: 4px 8px; }
    .header {
        padding: 12px 15px;
    }
    
    .header h1 {
        font-size: 16px;
    }
    
    .main {
        padding: 10px;
    }
    
    .article-content {
        padding: 12px;
    }
    
    .article-detail .article-content {
        padding: 15px;
    }
    
    .form-container {
        padding: 20px 15px;
    }
}

@media (max-width: 360px) {
    .header h1 { font-size: 15px; }
    .nav-link { font-size: 11px; padding: 4px 6px; }
}

/* 推荐系统专用样式 */
.rec-badge {
    background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
}

.lottery-type {
    background: #e0e7ff;
    color: #4f46e5;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.draw-time {
    color: #f59e0b;
    font-size: 12px;
    font-weight: 500;
}

.rec-status {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
}

.rec-status.status-pending {
    background: #dbeafe;
    color: #1e40af;
}

.rec-status.status-correct {
    background: #d1fae5;
    color: #065f46;
}

.rec-status.status-incorrect {
    background: #fee2e2;
    color: #991b1b;
}