:root {
  --bg: #f8fafc;
  --surface: #fff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-light: #eff6ff;
  --green: #16a34a;
  --green-light: #f0fdf4;
  --red: #dc2626;
  --red-light: #fef2f2;
  --yellow: #ca8a04;
  --radius: 10px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }
.container { max-width: 960px; margin: 0 auto; padding: 0 20px; }

/* ── Header ── */
.header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.header .container, .header-inner { display: flex; align-items: center; height: 52px; gap: 16px; padding: 0 20px; }
.logo { font-weight: 700; font-size: 18px; color: var(--text); white-space: nowrap; }
.logo span { color: var(--primary); }
.header nav { display: flex; gap: 16px; font-size: 14px; margin-left: auto; }
.header nav a { color: var(--muted); }
.header nav a.active, .header nav span.active { color: var(--text); font-weight: 600; }
.header-title { font-size: 14px; font-weight: 600; color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-stats { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* ── User bar ── */
.user-bar { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.user-bar .user-name { font-size: 13px; color: var(--text); font-weight: 600; background: #eff6ff; padding: 4px 12px; border-radius: 12px; }
.user-bar a { font-size: 13px; color: var(--muted); text-decoration: none; }
.user-bar a:hover { color: var(--text); }

/* ── Hero (homepage) ── */
.hero { background: linear-gradient(135deg, #1e40af, #3b82f6); color: #fff; padding: 48px 0 40px; }
.hero h1 { font-size: 32px; margin-bottom: 8px; }
.hero p { opacity: .85; font-size: 16px; }

/* ── Stats bar (homepage) ── */
.stats-bar { display: flex; gap: 32px; padding: 24px 0; }
.stat { display: flex; flex-direction: column; }
.stat-num { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 13px; color: var(--muted); }

/* ── Test grid (homepage) ── */
.test-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; padding-bottom: 60px; }
.test-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: box-shadow .2s, border-color .2s; }
.test-card:hover { border-color: var(--primary); box-shadow: 0 4px 12px rgba(37,99,235,.1); }
.test-card.done { border-color: var(--green); }
.test-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.test-num { font-size: 13px; font-weight: 600; color: var(--muted); }
.test-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.test-meta { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.test-card-action { font-size: 13px; font-weight: 600; color: var(--primary); margin-top: auto; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 12px; }
.badge-new { background: var(--primary-light); color: var(--primary); }
.badge-progress { background: #fefce8; color: var(--yellow); }
.badge-done { background: var(--green-light); color: var(--green); }

/* ── Quiz layout ── */
.quiz-body { overflow: hidden; height: 100vh; display: flex; flex-direction: column; }
.quiz-body .header { flex-shrink: 0; }
.quiz-layout { flex: 1; display: flex; overflow: hidden; }

/* ── Sidebar ── */
.sidebar { width: 280px; min-width: 280px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-head { padding: 12px 16px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sidebar-list { flex: 1; overflow-y: auto; }

.sb-item { display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid #f1f5f9; font-size: 13px; transition: background .1s; }
.sb-item:hover { background: #f8fafc; }
.sb-item.sb-active { background: var(--primary-light); border-left: 3px solid var(--primary); }
.sb-num { width: 24px; height: 24px; border-radius: 50%; background: #f1f5f9; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--muted); flex-shrink: 0; }
.sb-active .sb-num { background: var(--primary); color: #fff; }
.sb-correct .sb-num { background: var(--green); color: #fff; }
.sb-wrong .sb-num { background: var(--red); color: #fff; }
.sb-selected .sb-num { background: var(--primary); color: #fff; opacity: .6; }
.sb-label { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-time { font-size: 11px; color: var(--primary); white-space: nowrap; cursor: pointer; padding: 2px 6px; border-radius: 4px; background: var(--primary-light); }
.sb-time:hover { background: #dbeafe; }

/* ── Main column ── */
.main-col { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ── Player bar ── */
.player-bar { background: #1e293b; padding: 12px 20px; flex-shrink: 0; }
.player-top { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.player-btn { width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--primary); color: #fff; font-size: 14px; cursor: pointer; flex-shrink: 0; }
.player-btn:hover { background: #1d4ed8; }
.player-track { flex: 1; height: 24px; background: #334155; border-radius: 4px; position: relative; cursor: pointer; overflow: hidden; }
.player-progress { height: 100%; background: rgba(59,130,246,.4); border-radius: 4px; transition: width .1s linear; pointer-events: none; }
.player-markers { position: absolute; inset: 0; pointer-events: none; }
.marker { position: absolute; top: 0; height: 100%; width: 2px; background: rgba(255,255,255,.5); pointer-events: auto; cursor: pointer; }
.marker span { position: absolute; top: -1px; left: 50%; transform: translateX(-50%); font-size: 9px; color: #fff; background: rgba(37,99,235,.8); padding: 1px 3px; border-radius: 2px; line-height: 1; white-space: nowrap; }
.marker.marker-current { background: #facc15; }
.marker.marker-current span { background: #ca8a04; }
.player-time { font-size: 12px; color: #94a3b8; white-space: nowrap; min-width: 90px; text-align: right; }
.player-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.player-ctrl { background: #334155; border: none; color: #cbd5e1; font-size: 12px; padding: 4px 10px; border-radius: 4px; cursor: pointer; }
.player-ctrl:hover { background: #475569; color: #fff; }
.player-ctrl-mark { background: #1e40af; color: #93c5fd; }
.player-ctrl-mark:hover { background: #2563eb; color: #fff; }
.player-speed { background: #334155; border: 1px solid #475569; color: #cbd5e1; font-size: 12px; padding: 3px 6px; border-radius: 4px; cursor: pointer; }

/* ── Question panel ── */
.question-panel { flex: 1; overflow-y: auto; padding: 28px 32px; }
.q-header { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.q-number { font-size: 13px; color: var(--muted); font-weight: 600; }
.q-listen { font-size: 12px; color: var(--primary); background: var(--primary-light); border: none; padding: 4px 12px; border-radius: 6px; cursor: pointer; }
.q-listen:hover { background: #dbeafe; }
.q-text { font-size: 17px; line-height: 1.7; margin-bottom: 20px; }
.q-image { max-width: 400px; width: 100%; border-radius: 8px; margin-bottom: 20px; border: 1px solid var(--border); }

/* ── Options ── */
.options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.option { display: flex; align-items: flex-start; gap: 12px; padding: 14px 18px; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; text-align: left; font-size: 15px; line-height: 1.5; transition: all .15s; width: 100%; }
.option:hover:not(.option-disabled) { border-color: var(--primary); background: var(--primary-light); }
.option-selected { border-color: var(--primary); background: var(--primary-light); }
.option-correct { border-color: var(--green); background: var(--green-light); }
.option-wrong { border-color: var(--red); background: var(--red-light); }
.option-disabled { cursor: default; }
.option-letter { width: 28px; height: 28px; border-radius: 50%; background: #f1f5f9; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex-shrink: 0; color: var(--muted); }
.option-selected .option-letter { background: var(--primary); color: #fff; }
.option-correct .option-letter { background: var(--green); color: #fff; }
.option-wrong .option-letter { background: var(--red); color: #fff; }
.option-text { flex: 1; }
.option-icon { font-weight: 700; font-size: 16px; flex-shrink: 0; }

/* ── Buttons ── */
.btn { padding: 10px 24px; border-radius: 8px; border: none; cursor: pointer; font-size: 14px; font-weight: 600; transition: all .15s; }
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-confirm { display: block; width: 100%; max-width: 200px; }

/* ── Feedback ── */
.q-feedback { padding: 12px 16px; border-radius: 8px; font-size: 14px; font-weight: 500; }
.feedback-ok { background: var(--green-light); color: var(--green); }
.feedback-fail { background: var(--red-light); color: var(--red); }

/* ── Bottom nav ── */
.bottom-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }

/* ── Result modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal { background: var(--surface); border-radius: 16px; padding: 40px; text-align: center; max-width: 420px; width: 90%; }
.modal h2 { font-size: 22px; margin-bottom: 16px; }
.result-score { font-size: 48px; font-weight: 800; color: var(--primary); }
.result-pct { font-size: 16px; color: var(--muted); margin-bottom: 16px; }
.result-level { font-size: 16px; font-weight: 700; padding: 8px 20px; border: 2px solid; border-radius: 24px; display: inline-block; margin-bottom: 24px; }
.result-actions { display: flex; flex-direction: column; gap: 10px; }

/* ── Footer ── */
.footer { padding: 32px 0; text-align: center; color: var(--muted); font-size: 13px; border-top: 1px solid var(--border); margin-top: 40px; }
.loading { text-align: center; padding: 40px; color: var(--muted); }

/* ── Mobile ── */
@media (max-width: 768px) {
  .hero h1 { font-size: 24px; }
  .test-grid { grid-template-columns: 1fr; }
  .stats-bar { gap: 20px; }
  .sidebar { display: none; }
  .question-panel { padding: 20px 16px; }
  .q-text { font-size: 15px; }
  .option { padding: 12px 14px; font-size: 14px; }
  .player-controls { gap: 4px; }
  .player-ctrl { padding: 4px 6px; font-size: 11px; }
}
