/* ===== Reset & Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --primary: #4f46e5;
  --primary-light: #6366f1;
  --primary-dark: #4338ca;
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --text-lighter: #94a3b8;
  --border: #e2e8f0;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
  --header-h: 56px;
  --max-w: 600px;
}
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input, textarea, select { font-family: inherit; font-size: inherit; outline: none; }

/* ===== Layout ===== */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #fff; height: var(--header-h);
  display: flex; align-items: center; padding: 0 16px;
  box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}
.app-header .back-btn { font-size: 22px; padding: 4px 8px; margin-left: -8px; }
.app-header h1 { font-size: 18px; font-weight: 600; flex: 1; text-align: center; }
.app-header .right-btn { font-size: 14px; padding: 4px 8px; }

.app-container { max-width: var(--max-w); margin: 0 auto; padding: 16px; }

/* ===== Category Grid (Homepage) ===== */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 16px;
  padding: 16px;
}
@media (min-width: 480px) {
  .category-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
@media (min-width: 768px) {
  .category-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 20px; }
}
@media (min-width: 1024px) {
  .category-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 24px; }
}

.category-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.category-card:active { transform: scale(0.95); }
.category-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.category-card .icon {
  width: 56px; height: 56px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
}
.category-card .name { font-size: 14px; font-weight: 600; color: var(--text); }
.category-card .count { font-size: 11px; color: var(--text-lighter); }

/* ===== Lesson List ===== */
.lesson-list { display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.lesson-item {
  background: var(--card-bg); border-radius: var(--radius-sm);
  padding: 14px 16px; display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow); cursor: pointer; transition: all 0.15s;
}
.lesson-item:active { transform: scale(0.98); }
.lesson-item .num {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff;
}
.lesson-item .info { flex: 1; min-width: 0; }
.lesson-item .info .title { font-size: 15px; font-weight: 500; }
.lesson-item .info .meta { font-size: 12px; color: var(--text-lighter); margin-top: 2px; }
.lesson-item .tag {
  font-size: 11px; padding: 2px 8px; border-radius: 20px; flex-shrink: 0;
}
.tag-free { background: #dcfce7; color: #16a34a; }
.tag-member { background: #fef3c7; color: #d97706; }
.lesson-item .arrow { color: var(--text-lighter); font-size: 18px; }
.lesson-item .fav-btn { flex-shrink: 0; font-size: 18px; cursor: pointer; padding: 4px; filter: grayscale(0.2); transition: transform .12s; }
.lesson-item .fav-btn:active { transform: scale(1.25); }
.lesson-item .fav-btn.on { filter: none; }

/* ===== Player ===== */
.player-wrapper { width: 100%; height: 100vh; overflow: hidden; }
.player-wrapper iframe { width: 100%; height: 100%; border: none; }

/* ===== Auth Pages ===== */
.auth-page {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 24px;
}
.auth-card {
  background: #fff; border-radius: 20px; padding: 32px 24px;
  width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.auth-card .logo { text-align: center; margin-bottom: 24px; }
.auth-card .logo .icon { font-size: 48px; }
.auth-card .logo h2 { font-size: 20px; margin-top: 8px; color: var(--text); }
.auth-card .logo p { font-size: 13px; color: var(--text-light); margin-top: 4px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form .input-group { display: flex; flex-direction: column; gap: 6px; }
.auth-form label { font-size: 13px; color: var(--text-light); font-weight: 500; }
.auth-form input {
  padding: 12px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 15px; transition: border-color 0.2s;
}
.auth-form input:focus { border-color: var(--primary); }
.auth-form .btn-primary {
  background: var(--primary); color: #fff; padding: 13px; border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 600; margin-top: 8px; transition: background 0.2s;
}
.auth-form .btn-primary:active { background: var(--primary-dark); }
.auth-form .btn-primary:disabled { opacity: 0.6; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-light); }
.auth-footer a { color: var(--primary); font-weight: 500; }

/* ===== Buttons ===== */
.btn { padding: 10px 20px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; transition: all 0.2s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-outline { border: 1.5px solid var(--border); color: var(--text); background: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-sm { padding: 6px 14px; font-size: 13px; }

/* ===== Profile ===== */
.profile-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #fff; padding: 32px 20px; text-align: center;
}
.profile-header .avatar {
  width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 12px;
  background: rgba(255,255,255,0.2); display: flex; align-items: center; justify-content: center;
  font-size: 32px; border: 3px solid rgba(255,255,255,0.3);
}
.profile-header .name { font-size: 20px; font-weight: 600; }
.profile-header .badge { display: inline-block; margin-top: 8px; font-size: 12px; padding: 3px 12px; border-radius: 20px; background: rgba(255,255,255,0.2); }
.profile-menu { background: #fff; margin: 12px; border-radius: var(--radius); overflow: hidden; }
.profile-menu-item {
  display: flex; align-items: center; gap: 12px; padding: 16px;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.profile-menu-item:last-child { border-bottom: none; }
.profile-menu-item:active { background: var(--bg); }
.profile-menu-item .icon { font-size: 20px; width: 24px; text-align: center; }
.profile-menu-item .label { flex: 1; font-size: 15px; }
.profile-menu-item .value { font-size: 13px; color: var(--text-lighter); }
.profile-menu-item .arrow { color: var(--text-lighter); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-overlay.show { opacity: 1; pointer-events: auto; }
.modal-box {
  background: #fff; border-radius: 20px; padding: 28px 24px;
  width: 100%; max-width: 360px; max-height: 90vh; overflow-y: auto;
  transform: scale(0.9); transition: transform 0.2s;
}
.modal-overlay.show .modal-box { transform: scale(1); }
.modal-box h3 { font-size: 18px; text-align: center; margin-bottom: 16px; }
.modal-box .input {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 15px; margin-bottom: 12px;
}
.modal-box .btn-row { display: flex; gap: 10px; margin-top: 8px; }
.modal-box .btn-row .btn { flex: 1; text-align: center; }
.act-contact-box { margin-top: 6px; border: 1px dashed var(--primary, #3b82f6); border-radius: var(--radius-sm); background: rgba(59,130,246,0.06); padding: 12px 14px; }
.act-contact-title { font-size: 13px; font-weight: 600; color: var(--primary, #3b82f6); margin-bottom: 6px; }
.act-contact-body { font-size: 13px; color: var(--text); line-height: 1.5; word-break: break-all; }

/* ===== Form Group (shared across pages) ===== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; color: var(--text-light); margin-bottom: 5px; font-weight: 500; }
.form-group input, .form-group textarea, .form-group select {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; transition: border-color 0.2s; background: #fff; color: var(--text);
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus { border-color: var(--primary); }
.form-group textarea { min-height: 120px; resize: vertical; }

/* ===== Toast ===== */
.toast {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.8); color: #fff; padding: 12px 24px;
  border-radius: 8px; font-size: 14px; z-index: 2000;
  opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* ===== Splash Ad ===== */
.splash-ad {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: #000; z-index: 9999; display: flex; flex-direction: column;
}
.splash-ad img { width: 100%; flex: 1; object-fit: cover; }
.splash-ad .skip-bar {
  display: flex; justify-content: flex-end; padding: 12px;
  background: rgba(0,0,0,0.6); color: #fff;
}
.splash-ad .skip-btn {
  background: rgba(255,255,255,0.2); color: #fff; padding: 6px 16px;
  border-radius: 20px; font-size: 13px;
}

/* ===== Popup Ad ===== */
.popup-ad-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6); z-index: 2000;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.popup-ad-box { position: relative; max-width: 340px; width: 100%; }
.popup-ad-box img { width: 100%; border-radius: 16px; }
.popup-ad-box .close-btn {
  position: absolute; top: -36px; right: 0; width: 32px; height: 32px;
  background: rgba(255,255,255,0.3); border-radius: 50%; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}

/* ===== Empty State ===== */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-lighter); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .text { font-size: 14px; }

/* ===== Loading ===== */
.loading { text-align: center; padding: 40px; color: var(--text-lighter); font-size: 14px; }
.loading::after { content: ''; display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin-left: 8px; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Article Reader ===== */
.article-reader { background: #fff; min-height: 100vh; padding: 20px; max-width: var(--max-w); margin: 0 auto; }
.article-reader h1 { font-size: 22px; margin-bottom: 12px; }
.article-reader .article-meta { font-size: 13px; color: var(--text-lighter); margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.article-reader .article-content { font-size: 16px; line-height: 1.8; }
.article-reader .article-content img { border-radius: 8px; margin: 12px 0; }

/* ===== Member Banner ===== */
.member-banner {
  background: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
  color: #fff; margin: 12px; border-radius: var(--radius); padding: 16px;
  display: flex; align-items: center; gap: 12px; cursor: pointer;
}
.member-banner .icon { font-size: 28px; }
.member-banner .text { flex: 1; }
.member-banner .text .title { font-size: 16px; font-weight: 600; }
.member-banner .text .desc { font-size: 12px; opacity: 0.9; margin-top: 2px; }

/* ===== Form Divider ===== */
.form-divider { height: 1px; background: var(--border); margin: 18px 0; }

/* ===== Radio Group ===== */
.radio-group { display: flex; flex-wrap: wrap; gap: 12px; padding: 8px 0; }
.radio-group label { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; color: var(--text); }
.radio-group input[type=radio] { width: 16px; height: 16px; accent-color: var(--primary); }

/* ===== Cover Picker ===== */
.cover-picker .cover-preview {
  width: 100%; height: 120px; border-radius: var(--radius-sm);
  border: 1px dashed var(--border); background: var(--bg) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-lighter); font-size: 13px;
}
.cover-picker .cover-preview:not(.has-img)::after { content: '封面预览'; }
.cover-picker .cover-preview.has-img { border-style: solid; }
.cover-presets { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin: 8px 0; }
.cover-preset {
  aspect-ratio: 3/2; border-radius: 6px; cursor: pointer;
  background-size: cover; background-position: center;
  border: 2px solid transparent; transition: all 0.15s;
}
.cover-preset:hover { transform: scale(1.05); border-color: var(--primary); }
.cover-inputs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.cover-inputs input[type=text] { flex: 1; min-width: 160px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; }
.upload-btn {
  padding: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; background: #fff; cursor: pointer; color: var(--text);
}
.upload-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ===== Icon Picker ===== */
.icon-picker { overflow: hidden; }
.icon-presets { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 8px; }
.icon-preset {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 22px; border-radius: 8px; cursor: pointer; background: var(--bg);
  border: 2px solid transparent; transition: all 0.15s; line-height: 1;
}
.icon-preset:hover { transform: scale(1.1); border-color: var(--primary); background: #fff; }

/* ===== Rich Text Editor ===== */
.rich-editor { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.re-toolbar {
  display: flex; flex-wrap: wrap; gap: 4px; padding: 8px;
  background: #f8fafc; border-bottom: 1px solid var(--border); align-items: center;
}
.re-toolbar button {
  min-width: 32px; height: 32px; padding: 0 6px; border-radius: 6px;
  background: #fff; border: 1px solid var(--border); font-size: 14px;
  display: flex; align-items: center; justify-content: center; color: var(--text);
}
.re-toolbar button:hover { border-color: var(--primary); color: var(--primary); }
.re-toolbar input[type=color] { width: 32px; height: 32px; border: 1px solid var(--border); border-radius: 6px; padding: 2px; background: #fff; cursor: pointer; }
.re-toolbar .re-sep { width: 1px; height: 22px; background: var(--border); margin: 0 2px; }
.re-upload { display: flex; align-items: center; justify-content: center; min-width: 32px; height: 32px; padding: 0 6px; border-radius: 6px; background: #fff; border: 1px solid var(--border); cursor: pointer; font-size: 14px; }
.re-upload:hover { border-color: var(--primary); }
.re-content { min-height: 220px; padding: 14px; font-size: 15px; line-height: 1.7; outline: none; overflow-y: auto; max-height: 50vh; }
.re-content:empty::before { content: '在此输入图文内容…'; color: var(--text-lighter); }
.re-content img { max-width: 100%; border-radius: 8px; margin: 8px 0; }

/* ===== Lesson Cover Thumbnail ===== */
.lesson-item .lesson-cover {
  width: 56px; height: 56px; border-radius: 10px; flex-shrink: 0;
  background-size: cover; background-position: center; background-color: var(--primary);
  position: relative; overflow: hidden;
}
.lesson-item .lesson-cover .num {
  position: absolute; top: 4px; left: 4px; width: 20px; height: 20px;
  border-radius: 6px; font-size: 11px; box-shadow: none; background: rgba(0,0,0,0.35);
}
.lesson-item .dl-btn {
  font-size: 18px; color: var(--text-light); padding: 6px 8px; flex-shrink: 0;
  cursor: pointer; border-radius: 8px;
}
.lesson-item .dl-btn:hover { background: var(--bg); color: var(--primary); }

/* ===== Admin content cover column ===== */
.cover-thumb { width: 56px; height: 38px; border-radius: 6px; background-size: cover; background-position: center; background-color: var(--bg); }
.table-cover-cell { width: 64px; }

/* ===== Player download button ===== */
.player-bar .dl-btn {
  font-size: 18px; color: #fff; padding: 4px 8px; cursor: pointer; opacity: 0.9;
}
.player-bar .dl-btn:hover { opacity: 1; }

/* ===== 宽屏增强（仅桌面 ≥1024px 生效，手机端不受影响） ===== */
@media (min-width: 1024px) {
  :root { --max-w: 1100px; }
  /* 顶栏全宽渐变保持，内容限宽居中 */
  .app-header { padding: 0 max(16px, calc((100% - 1100px) / 2)); }
  .app-container { padding: 20px 16px; }
}
