/* ===== 全局变量与基础样式 ===== */
:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --max-width: 1200px;
    --nav-height: 60px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; cursor: pointer; }
.hidden { display: none !important; }
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 20px; }
.page-container { padding-top: 30px; padding-bottom: 60px; }

/* ===== 加载动画 ===== */
.loading { position: fixed; inset: 0; background: rgba(255,255,255,0.8); display: flex; align-items: center; justify-content: center; z-index: 9999; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 登录页 ===== */
.login-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 20px; }
.login-card { background: white; border-radius: 20px; padding: 50px 40px; text-align: center; box-shadow: 0 25px 60px rgba(0,0,0,0.3); max-width: 420px; width: 100%; }
.login-icon { font-size: 64px; margin-bottom: 10px; }
.login-card h1 { font-size: 28px; color: var(--text); margin-bottom: 8px; }
.login-subtitle { color: var(--text-secondary); margin-bottom: 30px; font-size: 15px; }
.input-group { display: flex; gap: 10px; }
.input-group input { flex: 1; padding: 14px 18px; border: 2px solid var(--border); border-radius: var(--radius); font-size: 16px; outline: none; transition: border-color 0.3s; }
.input-group input:focus { border-color: var(--primary); }
.btn-primary { padding: 14px 28px; background: var(--primary); color: white; border: none; border-radius: var(--radius); font-size: 16px; font-weight: 600; cursor: pointer; transition: background 0.3s, transform 0.1s; white-space: nowrap; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(0.97); }
/* ===== 验证失效浮层 ===== */
.session-expired-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(5px); display: flex; align-items: center; justify-content: center; z-index: 10000; animation: fadeIn 0.3s ease; }
.session-expired-card { background: white; border-radius: 20px; padding: 44px 38px; text-align: center; box-shadow: 0 25px 60px rgba(0,0,0,0.3); max-width: 380px; width: calc(100% - 40px); }
.expired-icon { font-size: 52px; margin-bottom: 12px; }
.session-expired-card h2 { font-size: 22px; font-weight: 700; margin-bottom: 10px; color: var(--text); }
.session-expired-card p { font-size: 14px; color: var(--text-secondary); line-height: 1.7; margin-bottom: 18px; }
.expired-timer { font-size: 14px; color: var(--text-muted); margin-bottom: 18px; }
.expired-timer span { font-size: 22px; font-weight: 700; color: var(--primary); }

/* ===== 登录错误文字 ===== */
.error-text { color: #ef4444; font-size: 14px; margin-top: 12px; min-height: 20px; transition: color 0.2s; }
.error-text.error-warn     { color: #d97706; }           /* 还剩2次：黄色警告 */
.error-text.error-critical { color: #ef4444; font-weight: 600; } /* 最后1次：红色强调 */
.error-text.error-lockout  { color: #7c3aed; }           /* 锁定倒计时：紫色 */

/* 输入框/按钮禁用状态 */
.input-group input:disabled  { opacity: 0.5; cursor: not-allowed; background: var(--bg); }
.btn-primary:disabled        { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ===== 导航栏 ===== */
.navbar { position: sticky; top: 0; background: rgba(255,255,255,0.95); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); z-index: 100; height: var(--nav-height); }
.nav-content { max-width: var(--max-width); margin: 0 auto; padding: 0 20px; height: 100%; display: flex; align-items: center; gap: 20px; }
.nav-brand { font-size: 20px; font-weight: 700; color: var(--text); white-space: nowrap; }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.nav-search { width: 300px; display: flex; align-items: center; background: var(--bg); border-radius: 25px; padding: 0 4px 0 16px; border: 1px solid var(--border); transition: border-color 0.3s; }
.nav-search:focus-within { border-color: var(--primary); }
.nav-search input { border: none; background: none; outline: none; padding: 10px 0; font-size: 14px; width: 100%; color: var(--text); }
.btn-search { background: none; border: none; font-size: 18px; cursor: pointer; padding: 8px 10px; }
.btn-logout { background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 14px; font-size: 13px; color: var(--text-secondary); cursor: pointer; transition: all 0.2s; white-space: nowrap; flex-shrink: 0; }
.btn-logout:hover { border-color: #ef4444; color: #ef4444; background: #fff5f5; }
.nav-menu-btn { display: none; background: none; border: none; font-size: 24px; cursor: pointer; padding: 5px; }

/* 移动端菜单 */
.mobile-menu { position: absolute; top: var(--nav-height); left: 0; right: 0; background: white; border-bottom: 1px solid var(--border); box-shadow: var(--shadow-lg); }
.mobile-menu a { display: block; padding: 15px 20px; color: var(--text); font-size: 16px; border-bottom: 1px solid var(--border); }
.mobile-menu a:hover { background: var(--bg); }
.mobile-search { padding: 12px 16px; }
.mobile-search input { width: 100%; padding: 10px 16px; border: 1px solid var(--border); border-radius: 25px; font-size: 14px; outline: none; }

/* ===== Hero区域 ===== */
.hero { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 60px 20px; text-align: center; margin-bottom: 40px; }
.hero h1 { font-size: 36px; margin-bottom: 12px; font-weight: 800; }
.hero p { font-size: 18px; opacity: 0.9; margin-bottom: 25px; }
.hero-stats { display: flex; justify-content: center; gap: 40px; flex-wrap: wrap; }
.hero-stats .stat { text-align: center; }
.hero-stats .stat-num { font-size: 28px; font-weight: 700; display: block; }
.hero-stats .stat-label { font-size: 14px; opacity: 0.8; }

/* ===== 板块标题 ===== */
.section { margin-bottom: 45px; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.section-header h2 { font-size: 22px; font-weight: 700; }
.view-all { font-size: 14px; color: var(--primary); font-weight: 500; }
.page-header { margin-bottom: 30px; }
.page-header h1 { font-size: 26px; font-weight: 700; }

/* 页头顶行：返回键 + 标题 */
.page-header-top { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.page-header-top h1 { font-size: 26px; font-weight: 700; margin: 0; }
.page-header .btn-back { margin-bottom: 0; flex-shrink: 0; } /* 覆盖 story-detail 中的底部间距 */

/* 故事列表控制栏：类型 Tab + 排序 */
.stories-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.type-tabs { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 25px; padding: 3px; }
.type-tab { padding: 6px 16px; border: none; border-radius: 20px; background: none; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--text-secondary); transition: all 0.2s; white-space: nowrap; }
.type-tab.active { background: var(--primary); color: white; box-shadow: 0 1px 4px rgba(99,102,241,0.4); }
.type-tab:not(.active):hover { color: var(--primary); background: var(--primary-light); }

/* ===== 分类卡片 ===== */
.category-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.category-grid.full { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.category-card { background: var(--bg-card); border-radius: var(--radius); padding: 24px; border: 1px solid var(--border); cursor: pointer; transition: all 0.3s; display: flex; align-items: flex-start; gap: 16px; }
.category-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--primary-light); }
.category-icon { font-size: 36px; flex-shrink: 0; width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; background: var(--primary-light); border-radius: var(--radius-sm); }
.category-info h3 { font-size: 17px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.category-info p { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.category-info .count { font-size: 12px; color: var(--primary); font-weight: 500; margin-top: 6px; }

/* ===== 故事卡片 ===== */
.story-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
.story-card { background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; cursor: pointer; transition: all 0.3s; }
.story-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.story-card-body { padding: 20px; }
.story-card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 10px; }
.story-card h3 { font-size: 17px; font-weight: 600; color: var(--text); line-height: 1.4; flex: 1; }
.story-badges { display: flex; gap: 6px; flex-shrink: 0; margin-left: 10px; flex-wrap: wrap; justify-content: flex-end; }
.story-type-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; white-space: nowrap; }
.story-type-badge.short { background: #fef3c7; color: #d97706; }
.story-type-badge.novel { background: #ede9fe; color: #7c3aed; }
.story-status { font-size: 11px; padding: 2px 8px; border-radius: 10px; white-space: nowrap; font-weight: 500; }
.story-status.ongoing { background: #dbeafe; color: #2563eb; }
.story-status.finished { background: #dcfce7; color: #16a34a; }
.story-meta { display: flex; gap: 14px; font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; flex-wrap: wrap; }
.story-summary { font-size: 14px; color: var(--text-secondary); line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.story-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-muted); }
.story-category-tag { background: var(--primary-light); color: var(--primary); padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }

/* ===== 故事详情页 ===== */
.story-detail-header { margin-bottom: 24px; }
.story-detail-header h1 { font-size: 28px; font-weight: 700; margin-bottom: 12px; }
.story-detail-meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--text-secondary); font-size: 14px; margin-bottom: 16px; align-items: center; }
.story-detail-meta .story-status, .story-detail-meta .story-type-badge { font-size: 12px; }
.story-detail-summary { font-size: 15px; color: var(--text-secondary); line-height: 1.8; padding: 20px; background: var(--bg); border-radius: var(--radius); border-left: 4px solid var(--primary); }

/* 短篇全文阅读区 */
.short-story-divider { height: 1px; background: linear-gradient(to right, var(--primary-light), transparent); margin: 28px 0; }
.short-story-content { max-width: 700px; margin: 0 auto 60px; font-size: 18px; line-height: 2; color: var(--text); }
.short-story-content p { text-indent: 2em; margin-bottom: 14px; }

@media (max-width: 768px) {
    .short-story-content { font-size: 16px; line-height: 1.95; }
}
@media (max-width: 480px) {
    .short-story-content { font-size: 15px; }
}
.chapter-list-header { display: flex; align-items: center; justify-content: space-between; margin: 30px 0 16px; }
.chapter-list-header h2 { font-size: 20px; font-weight: 600; }
.chapter-list { background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.chapter-item { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.2s; }
.chapter-item:last-child { border-bottom: none; }
.chapter-item:hover { background: var(--primary-light); }
.chapter-item .ch-number { color: var(--text-muted); font-size: 14px; margin-right: 12px; min-width: 50px; }
.chapter-item .ch-title { font-size: 15px; color: var(--text); flex: 1; }
.chapter-item .ch-words { font-size: 13px; color: var(--text-muted); }
.btn-back { background: none; border: 1px solid var(--border); padding: 8px 16px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; color: var(--text-secondary); transition: all 0.2s; margin-bottom: 20px; }
.btn-back:hover { border-color: var(--primary); color: var(--primary); }

/* ===== 阅读器 ===== */
.reader-header { position: sticky; top: 0; background: rgba(255,255,255,0.95); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; z-index: 50; }
.reader-header .btn-back { margin-bottom: 0; padding: 6px 14px; font-size: 13px; }
.reader-chapter-title { font-size: 15px; font-weight: 600; color: var(--text); text-align: center; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 15px; }
.btn-icon { background: none; border: none; font-size: 20px; cursor: pointer; padding: 5px; }
.reader-settings { background: var(--bg-card); border-bottom: 1px solid var(--border); padding: 16px 20px; display: flex; align-items: center; justify-content: center; gap: 40px; flex-wrap: wrap; }
.settings-item { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--text-secondary); }
.font-size-ctrl { display: flex; align-items: center; gap: 10px; }
.font-size-ctrl button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg); cursor: pointer; font-size: 14px; font-weight: 600; transition: all 0.2s; }
.font-size-ctrl button:hover { border-color: var(--primary); color: var(--primary); }
.font-size-ctrl span { min-width: 24px; text-align: center; font-weight: 600; }
.theme-btns { display: flex; gap: 8px; }
.theme-btn { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; transition: all 0.2s; }
.theme-btn.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.theme-btn.light { background: #ffffff; }
.theme-btn.sepia { background: #f5e6d0; }
.theme-btn.dark { background: #1a1a2e; }
.reader-body { max-width: 750px; margin: 0 auto; padding: 40px 24px 60px; font-size: 18px; line-height: 2; color: var(--text); }
.reader-body p { text-indent: 2em; margin-bottom: 16px; }
.reader-nav { max-width: 750px; margin: 0 auto; padding: 20px 24px 60px; display: flex; justify-content: space-between; gap: 12px; }
.reader-nav button { padding: 12px 24px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-card); cursor: pointer; font-size: 14px; color: var(--text); transition: all 0.2s; flex: 1; max-width: 200px; }
.reader-nav button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.reader-nav button:disabled { opacity: 0.4; cursor: not-allowed; }
.reader-nav .btn-catalog { background: var(--primary); color: white; border-color: var(--primary); }
.reader-nav .btn-catalog:hover { background: var(--primary-hover); }

/* 阅读器主题 */
.reader-theme-sepia .reader-body { background: #fdf6e3; color: #5c4b37; }
.reader-theme-sepia .reader-header { background: rgba(253,246,227,0.95); }
.reader-theme-dark .reader-body { background: #1a1a2e; color: #c8c8d8; }
.reader-theme-dark .reader-header { background: rgba(26,26,46,0.95); border-color: #2d2d44; }
.reader-theme-dark .reader-nav button { background: #252540; border-color: #2d2d44; color: #c8c8d8; }

/* ===== 排序栏 ===== */
.sort-bar { display: flex; gap: 8px; }
.sort-btn { padding: 8px 18px; border: 1px solid var(--border); border-radius: 25px; background: var(--bg-card); cursor: pointer; font-size: 13px; color: var(--text-secondary); transition: all 0.2s; }
.sort-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ===== 分页 ===== */
.pagination { display: flex; justify-content: center; gap: 8px; margin-top: 30px; flex-wrap: wrap; }
.page-btn { width: 40px; height: 40px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-card); cursor: pointer; font-size: 14px; color: var(--text); transition: all 0.2s; display: flex; align-items: center; justify-content: center; }
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== 空状态 ===== */
.empty-state { text-align: center; padding: 80px 20px; color: var(--text-muted); }
.empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state p { font-size: 16px; }

/* ===== 页脚 ===== */
.footer { text-align: center; padding: 30px 20px; color: var(--text-muted); font-size: 14px; border-top: 1px solid var(--border); margin-top: 40px; }

/* ===== 响应式 - 平板 ===== */
@media (max-width: 768px) {
    .nav-right { display: none; }
    .nav-menu-btn { display: block; }
    .hero { padding: 40px 20px; }
    .hero h1 { font-size: 26px; }
    .hero p { font-size: 15px; }
    .hero-stats { gap: 24px; }
    .hero-stats .stat-num { font-size: 22px; }
    .category-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
    .story-grid { grid-template-columns: 1fr; }
    .page-header h1, .page-header-top h1 { font-size: 22px; }
    .story-detail-header h1 { font-size: 22px; }
    .stories-controls { flex-direction: column; align-items: flex-start; }
    .reader-body { padding: 30px 18px 50px; font-size: 17px; }
    .reader-settings { gap: 20px; }
}

/* ===== 响应式 - 手机 ===== */
@media (max-width: 480px) {
    :root { --nav-height: 54px; }
    .login-card { padding: 40px 24px; }
    .login-icon { font-size: 48px; }
    .login-card h1 { font-size: 24px; }
    .input-group { flex-direction: column; }
    .hero { padding: 30px 16px; margin-bottom: 24px; }
    .hero h1 { font-size: 22px; }
    .hero-stats { gap: 16px; }
    .hero-stats .stat-num { font-size: 20px; }
    .section-header h2 { font-size: 18px; }
    .category-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .category-card { padding: 16px; flex-direction: column; align-items: center; text-align: center; gap: 10px; }
    .category-icon { width: 44px; height: 44px; font-size: 28px; }
    .category-info p { display: none; }
    .story-card-body { padding: 16px; }
    .page-header-top h1 { font-size: 20px; }
    .type-tab { padding: 5px 12px; font-size: 12px; }
    .reader-body { padding: 24px 16px 40px; font-size: 16px; line-height: 1.9; }
    .reader-nav button { padding: 10px 16px; font-size: 13px; }
    .chapter-item { padding: 12px 16px; }
    .container { padding: 0 16px; }
    .page-container { padding-top: 20px; padding-bottom: 40px; }
}

/* ===== 滚动条美化 ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== 动画 ===== */
.view { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
