:root {
  --primary: #1a8a3f;
  --primary-light: #23b553;
  --primary-dark: #126830;
  --primary-bg: #e8f5ee;
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin:0; padding:0; box-sizing:border-box; }
body {
  font-family:-apple-system,BlinkMacSystemFont,"PingFang SC","Helvetica Neue",sans-serif;
  background:var(--bg); color:var(--text); min-height:100vh; -webkit-font-smoothing:antialiased;
}

/* ===== Header ===== */
.app-header {
  background:linear-gradient(135deg,var(--primary)0%,var(--primary-light)100%);
  color:#fff; padding:14px 22px; padding-top:12px;
  position:sticky; top:0; z-index:100; display:flex; align-items:center; gap:12px;
  box-shadow:0 1px 6px rgba(26,138,63,0.15);
}
.app-header h1 { font-size:16px; font-weight:600; flex:1; }
.app-header .back-btn { width:30px; height:30px; display:flex; align-items:center; justify-content:center; background:rgba(255,255,255,0.2); border:none; border-radius:6px; color:#fff; font-size:18px; cursor:pointer; }
.app-header .user-badge { width:30px; height:30px; border-radius:50%; background:rgba(255,255,255,0.25); display:flex; align-items:center; justify-content:center; font-size:13px; font-weight:600; cursor:pointer; overflow:hidden; }
.app-header h1 { font-size:18px; font-weight:600; flex:1; }
.app-header .back-btn {
  width:32px; height:32px; display:flex; align-items:center; justify-content:center;
  background:rgba(255,255,255,0.2); border:none; border-radius:8px; color:#fff; font-size:18px; cursor:pointer;
}
.app-header .user-badge {
  width:32px; height:32px; border-radius:50%; background:rgba(255,255,255,0.25);
  display:flex; align-items:center; justify-content:center; font-size:14px; font-weight:600; cursor:pointer; overflow:hidden;
}
.app-header .user-badge img { width:100%; height:100%; object-fit:cover; }

/* ===== Login Page ===== */
.login-page {
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  min-height:100vh; padding:24px;
  background:linear-gradient(135deg,#e8f5ee 0%,#f0fdf4 100%);
}
.login-logo {
  width:72px; height:72px; border-radius:20px;
  background:linear-gradient(135deg,var(--primary),var(--primary-light));
  display:flex; align-items:center; justify-content:center; font-size:32px; margin-bottom:8px; color:#fff;
}
.login-title { font-size:24px; font-weight:700; margin-bottom:4px; }
.login-subtitle { font-size:14px; color:var(--text-secondary); margin-bottom:32px; }
.login-form { width:100%; max-width:360px; }
.form-group { margin-bottom:16px; }
.form-group label { display:block; font-size:14px; font-weight:500; margin-bottom:6px; color:var(--text); }
.form-group input, .form-group select {
  width:100%; padding:14px 16px; border:2px solid var(--border); border-radius:var(--radius);
  font-size:16px; background:var(--card); transition:border-color 0.2s; -webkit-appearance:none;
}
.form-group input:focus { outline:none; border-color:var(--primary); }
.login-tab {
  flex:1; padding:12px; border:none; font-size:15px; font-weight:600;
  cursor:pointer; transition:all 0.2s; background:#fff; color:var(--text-secondary);
}
.login-tab.active { background:var(--primary); color:#fff; }
.login-error {
  background:#fef2f2; color:var(--danger); padding:10px; border-radius:8px;
  font-size:13px; margin-bottom:12px; display:none;
}
.photo-upload { display:flex; align-items:center; gap:12px; }
.photo-preview {
  width:64px; height:64px; border-radius:50%; border:2px dashed var(--border);
  overflow:hidden; display:flex; align-items:center; justify-content:center;
  flex-shrink:0; background:#f9fafb; cursor:pointer;
}
.photo-preview img { width:100%; height:100%; object-fit:cover; }
.photo-preview .placeholder { color:#ccc; font-size:24px; }
.photo-hint { font-size:12px; color:var(--text-secondary); flex:1; }

/* ===== Buttons ===== */
.btn {
  width:100%; padding:14px; border:none; border-radius:var(--radius);
  font-size:16px; font-weight:600; cursor:pointer; transition:all 0.2s;
}
.btn-primary { background:var(--primary); color:#fff; }
.btn-primary:active { transform:scale(0.98); background:var(--primary-dark); }
.btn-primary:disabled { opacity:0.5; cursor:not-allowed; }
.btn-outline { background:transparent; color:var(--primary); border:2px solid var(--primary); }
.btn-danger { background:var(--danger); color:#fff; }
.btn-sm { padding:8px 16px; font-size:14px; width:auto; }

/* ===== Dashboard / Progress ===== */
.progress-card {
  background:linear-gradient(135deg,var(--primary)0%,var(--primary-light)100%);
  border-radius:var(--radius); padding:20px; color:#fff;
  margin-bottom:16px; box-shadow:0 4px 15px rgba(26,138,63,0.2);
}
.progress-card .greeting { font-size:16px; opacity:0.9; }
.progress-card .name { font-size:22px; font-weight:700; margin:4px 0 16px; }
.progress-bar-bg { height:8px; background:rgba(255,255,255,0.25); border-radius:4px; overflow:hidden; margin-bottom:8px; }
.progress-bar-fill { height:100%; background:#fff; border-radius:4px; transition:width 0.5s; }
.progress-stats { display:flex; justify-content:space-between; font-size:13px; opacity:0.9; }
.progress-stats .highlight { font-weight:700; font-size:15px; }
.exam-badge {
  display:inline-flex; align-items:center; gap:6px;
  margin-top:12px; padding:8px 16px; border-radius:20px;
  background:#fff; color:var(--primary); font-size:14px; font-weight:600; cursor:pointer; transition:all 0.2s;
}
.exam-badge:active { transform:scale(0.96); }
.exam-badge.disabled { opacity:0.5; cursor:not-allowed; background:rgba(255,255,255,0.2); color:#fff; }

/* ===== Section Title ===== */
.section-title { font-size:16px; font-weight:600; margin:20px 0 12px; display:flex; align-items:center; gap:8px; }
.section-title .badge { font-size:12px; font-weight:500; padding:2px 8px; border-radius:10px; background:var(--primary-bg); color:var(--primary); }

/* ===== Content List ===== */
.content-grid { display:flex; flex-direction:column; gap:12px; }
.content-card {
  background:var(--card); border-radius:var(--radius); padding:16px;
  box-shadow:var(--shadow); cursor:pointer; display:flex; gap:14px; transition:all 0.15s;
}
.content-card:active { transform:scale(0.98); }
.content-icon { width:48px; height:48px; border-radius:12px; flex-shrink:0; display:flex; align-items:center; justify-content:center; font-size:22px; }
.content-icon.video { background:#e0f2fe; color:#0284c7; }
.content-icon.ppt { background:#fef3c7; color:#d97706; }
.content-info { flex:1; min-width:0; }
.content-title { font-size:15px; font-weight:600; margin-bottom:4px; }
.content-meta { font-size:12px; color:var(--text-secondary); display:flex; gap:12px; }
.content-progress { margin-top:8px; display:flex; align-items:center; gap:8px; }
.content-progress .mini-bar { flex:1; height:4px; background:#f0f0f0; border-radius:2px; overflow:hidden; }
.content-progress .mini-bar div { height:100%; background:var(--primary); border-radius:2px; transition:width 0.3s; }
.content-progress .pct { font-size:12px; color:var(--text-secondary); min-width:32px; text-align:right; }
.status-dot { width:8px; height:8px; border-radius:50%; flex-shrink:0; margin-top:4px; }
.status-dot.done { background:var(--success); }
.status-dot.pending { background:var(--border); }

/* ===== Player ===== */
.study-timer { display:flex; align-items:center; justify-content:space-between; background:var(--primary-bg); padding:12px 16px; border-radius:var(--radius); margin-bottom:12px; }
.study-timer .timer { font-size:20px; font-weight:700; color:var(--primary); }
.study-timer .timer-label { font-size:13px; color:var(--text-secondary); }
.study-timer .status { font-size:13px; color:var(--primary); }
.video-wrapper { position:relative; width:100%; border-radius:var(--radius); overflow:hidden; background:#000; margin-bottom:16px; }
.video-wrapper video { width:100%; display:block; max-height:50vh; }
.ppt-viewer { background:var(--card); border-radius:var(--radius); overflow:hidden; margin-bottom:16px; box-shadow:var(--shadow); }
.ppt-slide { width:100%; min-height:300px; display:flex; align-items:center; justify-content:center; background:#fff; padding:20px; }
.ppt-slide img { max-width:100%; max-height:70vh; object-fit:contain; }
.ppt-slide .no-image { width:100%; height:300px; display:flex; flex-direction:column; align-items:center; justify-content:center; color:#ccc; font-size:48px; }
.ppt-controls { display:flex; align-items:center; justify-content:center; gap:16px; padding:12px; background:#f9fafb; border-top:1px solid var(--border); }
.ppt-controls button { width:40px; height:40px; border-radius:50%; border:1px solid var(--border); background:var(--card); cursor:pointer; display:flex; align-items:center; justify-content:center; font-size:16px; }
.ppt-controls .page-num { font-size:14px; color:var(--text-secondary); }
.player-info { background:var(--card); border-radius:var(--radius); padding:16px; box-shadow:var(--shadow); }
.player-info h2 { font-size:18px; margin-bottom:8px; }
.player-info .desc { font-size:14px; color:var(--text-secondary); line-height:1.6; }

/* ===== Exam ===== */
.exam-header { background:var(--card); border-radius:var(--radius); padding:16px; margin-bottom:16px; box-shadow:var(--shadow); display:flex; justify-content:space-between; align-items:center; }
.exam-timer { font-size:20px; font-weight:700; color:var(--primary); }
.exam-progress { font-size:14px; color:var(--text-secondary); }
.question-card { background:var(--card); border-radius:var(--radius); padding:20px; margin-bottom:16px; box-shadow:var(--shadow); }
.question-num { font-size:13px; color:var(--primary); font-weight:600; margin-bottom:8px; }
.question-text { font-size:17px; font-weight:500; line-height:1.6; margin-bottom:20px; }
.options { display:flex; flex-direction:column; gap:10px; }
.option {
  display:flex; align-items:flex-start; gap:12px; padding:14px 16px;
  border:2px solid var(--border); border-radius:var(--radius); cursor:pointer; transition:all 0.15s; font-size:15px; line-height:1.5;
}
.option:active { transform:scale(0.98); }
.option.selected { border-color:var(--primary); background:var(--primary-bg); }
.option.correct { border-color:var(--success); background:#f0fdf4; }
.option.wrong { border-color:var(--danger); background:#fef2f2; }
.option .letter {
  width:24px; height:24px; border-radius:50%; flex-shrink:0; display:flex; align-items:center; justify-content:center;
  font-size:13px; font-weight:600; background:#f3f4f6; color:var(--text-secondary);
}
.option.selected .letter { background:var(--primary); color:#fff; }
.option.correct .letter { background:var(--success); color:#fff; }
.option.wrong .letter { background:var(--danger); color:#fff; }
.exam-nav { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:20px; }
.question-dots { display:flex; flex-wrap:wrap; gap:6px; justify-content:center; margin-bottom:16px; }
.question-dot {
  width:28px; height:28px; border-radius:50%; display:flex; align-items:center; justify-content:center;
  font-size:11px; font-weight:600; cursor:pointer; border:1px solid var(--border); background:#fff; color:var(--text-secondary);
}
.question-dot.current { border-color:var(--primary); background:var(--primary); color:#fff; }
.question-dot.answered { background:var(--primary-bg); border-color:var(--primary); color:var(--primary); }

/* ===== Result & Certificate ===== */
.result-card { background:var(--card); border-radius:var(--radius); padding:32px 24px; text-align:center; box-shadow:var(--shadow); margin-bottom:16px; }
.result-icon { font-size:64px; margin-bottom:12px; }
.result-score { font-size:48px; font-weight:800; color:var(--primary); margin-bottom:4px; }
.result-label { font-size:16px; color:var(--text-secondary); margin-bottom:16px; }
.result-status { display:inline-flex; align-items:center; gap:6px; padding:8px 20px; border-radius:20px; font-size:15px; font-weight:600; }
.result-status.pass { background:#f0fdf4; color:var(--success); }
.result-status.fail { background:#fef2f2; color:var(--danger); }
.result-stats { display:flex; justify-content:center; gap:24px; margin-top:20px; }
.result-stat { text-align:center; }
.result-stat .num { font-size:20px; font-weight:700; }
.result-stat .num.green { color:var(--success); }
.result-stat .num.red { color:var(--danger); }
.result-stat .label { font-size:12px; color:var(--text-secondary); margin-top:4px; }

/* ===== Certificate ===== */
.certificate-page { padding:20px 12px 12px; display:flex; flex-direction:column; align-items:center; background:#f8f6f0; }
.cert-card { width:100%; max-width:360px; background:#fffdf7; border:3px double #c4a35a; border-radius:4px; padding:32px 20px 28px; position:relative; box-shadow:0 8px 32px rgba(0,0,0,0.08); }
.cert-card::before { content:''; position:absolute; inset:6px; border:1px solid #d4c48a; border-radius:2px; pointer-events:none; }
.cert-title { text-align:center; font-size:28px; font-weight:700; letter-spacing:8px; color:#8b1a1a; padding-bottom:16px; border-bottom:2px solid #c4a35a; margin-bottom:24px; font-family:"STKaiti","KaiTi",serif; }
.cert-body { text-align:center; line-height:2.2; font-size:15px; color:#333; padding:0 8px; }
.cert-body .highlight { font-size:18px; font-weight:700; color:#8b1a1a; }
.cert-body .highlight.name { font-size:22px; }
.cert-body .label { color:#666; font-size:14px; }
.cert-profile { display:flex; align-items:center; gap:16px; margin:0 auto 18px; max-width:288px; text-align:left; }
.cert-photo { width:92px; height:118px; flex-shrink:0; border:1px solid #d4c48a; background:#fff; display:flex; align-items:center; justify-content:center; overflow:hidden; }
.cert-photo img { width:100%; height:100%; object-fit:cover; display:block; }
.cert-photo-placeholder { width:100%; height:100%; display:flex; align-items:center; justify-content:center; background:#f5efe0; color:#9b7b34; font-size:32px; font-family:"STKaiti","KaiTi",serif; }
.cert-info { flex:1; min-width:0; border-top:1px solid #eadfbf; }
.cert-info-row { display:grid; grid-template-columns:44px 1fr; align-items:center; min-height:34px; border-bottom:1px solid #eadfbf; font-size:15px; color:#555; }
.cert-info-row span { color:#777; }
.cert-info-row strong { color:#8b1a1a; font-size:17px; font-weight:700; word-break:break-all; }
.cert-statement { margin-top:8px; text-align:left; text-indent:2em; line-height:2; font-size:16px; }
.cert-score { margin-top:10px; text-align:center; line-height:1.8; }
.cert-seal-area { display:flex; flex-direction:column; align-items:center; margin-top:20px; padding-top:16px; }
.cert-seal-area svg { width:100px; height:100px; }
.cert-school { text-align:center; font-size:14px; color:#555; font-family:"STKaiti","KaiTi",serif; margin-top:4px; }
.cert-date { text-align:center; font-size:13px; color:#888; margin-top:4px; }
.cert-footer-text { text-align:center; font-size:14px; color:#8b1a1a; font-family:"STKaiti","KaiTi",serif; margin-top:8px; letter-spacing:2px; }
#page-certificate.page { padding-bottom:0; }

/* ===== Toast ===== */
.toast {
  position:fixed; bottom:100px; left:50%; transform:translateX(-50%);
  background:rgba(0,0,0,0.8); color:#fff; padding:10px 20px; border-radius:8px;
  font-size:14px; z-index:999; display:none; animation:toastIn 0.3s;
}
@keyframes toastIn { from{opacity:0;transform:translateX(-50%) translateY(10px)} to{opacity:1;transform:translateX(-50%) translateY(0)} }

/* ===== Loading ===== */
.loading-dots { display:flex; align-items:center; justify-content:center; gap:8px; padding:40px; }
.loading-dots span { width:8px; height:8px; border-radius:50%; background:var(--primary); animation:bounce 0.6s infinite alternate; }
.loading-dots span:nth-child(2) { animation-delay:0.15s; }
.loading-dots span:nth-child(3) { animation-delay:0.3s; }
@keyframes bounce { from{transform:translateY(0);opacity:0.3} to{transform:translateY(-8px);opacity:1} }

/* ===== Pass Banner ===== */
.pass-banner { background:linear-gradient(135deg,#fbbf24,#f59e0b); border-radius:var(--radius); padding:14px 16px; margin-bottom:12px; color:#92400e; font-size:15px; font-weight:600; box-shadow:0 2px 10px rgba(245,158,11,0.2); display:none; }

/* ===== Responsive ===== */
@media (min-width:480px) { .content-grid { display:grid; grid-template-columns:1fr 1fr; } }

/* ===== User Modal ===== */
.user-modal {
  display:none; position:fixed; inset:0; background:rgba(0,0,0,0.5); z-index:200;
  align-items:center; justify-content:center; padding:24px;
}
.user-modal.active { display:flex; }
.user-modal-box { background:#fff; border-radius:var(--radius); padding:24px; max-width:320px; width:100%; }
