:root {
  --brand: #6d5efc;
  --brand-soft: color-mix(in srgb, var(--brand) 12%, transparent);
  --bg: #f6f5fb;
  --card: #ffffff;
  --text: #1d1b2c;
  --muted: #6b6880;
  --line: #e7e5f0;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --fire: #f97316;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 16, 60, .05), 0 6px 24px rgba(20, 16, 60, .06);
}
:root[data-theme="dark"] {
  --bg: #121120; --card: #1c1a2e; --text: #eceaf6; --muted: #a29fb8; --line: #2d2a44;
  --ok-soft: #12321f; --bad-soft: #3a1717;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: 'Heebo', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.3rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.ltr { direction: ltr; unicode-bidi: embed; }

/* layout */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--text); font-size: 1.1rem; }
.logo-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 1.1rem; }
.nav { display: flex; gap: 4px; margin-inline-start: 16px; }
.nav a { padding: 8px 12px; border-radius: 10px; color: var(--muted); font-weight: 500; }
.nav a.active, .nav a:hover { background: var(--brand-soft); color: var(--brand); }
.spacer { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-weight: 700; font-size: .9rem; white-space: nowrap; }
.chip.fire { color: var(--fire); }
.chip.xp { color: var(--brand); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; border: 0; }
.menu { position: relative; }
.menu-pop { position: absolute; inset-inline-end: 0; top: 46px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); min-width: 200px; padding: 6px; display: none; }
.menu-pop.open { display: block; }
.menu-pop button, .menu-pop a { display: block; width: 100%; text-align: start; padding: 10px 12px; background: none; border: 0; border-radius: 8px; color: var(--text); }
.menu-pop button:hover, .menu-pop a:hover { background: var(--brand-soft); }
main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
@media (max-width: 640px) { .grid-4 { grid-template-columns: 1fr 1fr; gap: 10px; } .stat .num { font-size: 1.5rem; } }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 16px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 12px; border: 1px solid transparent; background: var(--brand); color: #fff; font-weight: 700; transition: transform .08s, filter .15s; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.danger { background: var(--bad); }
.btn.ok { background: var(--ok); }
.btn.sm { padding: 6px 12px; font-size: .875rem; border-radius: 10px; }
.btn.block { width: 100%; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { background: var(--brand-soft); color: var(--brand); }

/* forms */
label { display: block; font-weight: 500; margin-bottom: 6px; font-size: .925rem; }
.field { margin-bottom: 14px; }
.input, textarea.input, select.input { width: 100%; padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.input { min-height: 100px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.error-box { background: var(--bad-soft); color: var(--bad); padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; }

/* login */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login-side { background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 55%, #ff7ab6)); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: center; position: relative; overflow: hidden; }
.login-side h1 { font-size: 2.4rem; }
.login-side .feat { display: flex; gap: 12px; align-items: center; margin-top: 14px; font-size: 1.05rem; }
.login-side .feat span { width: 38px; height: 38px; border-radius: 12px; background: rgba(255,255,255,.18); display: grid; place-items: center; }
.login-form { display: grid; place-items: center; padding: 32px 16px; }
.login-form .card { width: 100%; max-width: 400px; padding: 32px; }
@media (max-width: 820px) { .login-wrap { grid-template-columns: 1fr; } .login-side { padding: 32px 20px; } .login-side h1 { font-size: 1.8rem; } .login-side .feats { display: none; } }

/* dashboard */
.hero { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; margin-bottom: 24px; }
@media (max-width: 900px) { .hero { grid-template-columns: 1fr; } }
.continue-card { background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 60%, #000)); color: #fff; border: 0; }
.continue-card .muted { color: rgba(255,255,255,.8); }
.continue-card .btn { background: #fff; color: var(--brand); }
.stat { text-align: center; }
.stat .num { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.streak-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-top: 12px; max-width: 280px; }
.streak-cal div { aspect-ratio: 1; border-radius: 6px; background: var(--line); }
.streak-cal div.on { background: var(--fire); }
.streak-cal div.today { outline: 2px solid var(--brand); outline-offset: 1px; }

.course-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; transition: transform .15s; cursor: pointer; }
.course-card:hover { transform: translateY(-3px); }
.course-cover { height: 120px; display: flex; align-items: flex-end; padding: 16px; color: #fff; font-size: 2.4rem; position: relative; }
.course-body { padding: 18px; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--brand); border-radius: 99px; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.progress.ok > div { background: var(--ok); }
.ring { --p: 0; width: 64px; height: 64px; border-radius: 50%; background: conic-gradient(var(--brand) calc(var(--p) * 1%), var(--line) 0); display: grid; place-items: center; flex: none; }
.ring span { width: 50px; height: 50px; border-radius: 50%; background: var(--card); display: grid; place-items: center; font-weight: 800; font-size: .9rem; }

.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.badge { text-align: center; padding: 14px 8px; border-radius: 14px; border: 1px dashed var(--line); }
.badge .ic { font-size: 2rem; filter: grayscale(1); opacity: .35; }
.badge.earned { border-style: solid; background: var(--brand-soft); border-color: transparent; }
.badge.earned .ic { filter: none; opacity: 1; }
.badge .t { font-weight: 700; font-size: .9rem; margin-top: 4px; }
.badge .d { font-size: .78rem; color: var(--muted); }

/* course page */
.module { margin-bottom: 14px; padding: 0; overflow: hidden; }
.module-head { padding: 16px 20px; display: flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; }
.module-head .arrow { transition: transform .2s; color: var(--muted); }
.module.collapsed .arrow { transform: rotate(90deg); }
.module.collapsed .lesson-list { display: none; }
.lesson-list { border-top: 1px solid var(--line); }
.lesson-item { display: flex; align-items: center; gap: 12px; padding: 13px 20px; color: var(--text); border-bottom: 1px solid var(--line); }
.lesson-item:last-child { border-bottom: 0; }
.lesson-item:hover { background: var(--brand-soft); }
.lesson-item.locked { opacity: .5; pointer-events: none; }
.lesson-item.current { background: var(--brand-soft); }
.status-dot { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: .8rem; flex: none; color: var(--muted); }
.status-dot.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.tag { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); font-weight: 700; white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.gray { background: var(--line); color: var(--muted); }

/* lesson page */
.lesson-layout { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
@media (max-width: 1000px) { .lesson-layout { grid-template-columns: 1fr; } .lesson-side { order: 2; } }
.player { position: relative; aspect-ratio: 16/9; background: #000; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.player iframe, .player video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player .empty { position: absolute; inset: 0; display: grid; place-items: center; color: #aaa; }
.lesson-side { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; padding: 0; }
.lesson-side .lesson-item { padding: 10px 14px; font-size: .925rem; }
.side-mod { padding: 10px 14px; font-weight: 700; font-size: .85rem; color: var(--muted); background: var(--bg); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; color: var(--muted); font-weight: 700; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.desc { white-space: pre-wrap; }

/* quiz */
.q { margin-bottom: 20px; }
.q-title { font-weight: 700; margin-bottom: 10px; }
.opt { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; margin-bottom: 8px; cursor: pointer; transition: border-color .15s, background .15s; }
.opt:hover { border-color: color-mix(in srgb, var(--brand) 50%, var(--line)); }
.opt.sel { border-color: var(--brand); background: var(--brand-soft); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt input { display: none; }
.opt .letter { width: 26px; height: 26px; border-radius: 8px; background: var(--line); display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex: none; }
.opt.sel .letter { background: var(--brand); color: #fff; }
.explain { padding: 10px 14px; border-radius: 10px; background: var(--bg); font-size: .925rem; margin-top: 4px; }
.score-big { font-size: 3rem; font-weight: 800; }

.comment { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.comment .avatar { width: 32px; height: 32px; font-size: .85rem; flex: none; }
.comment .who { font-weight: 700; font-size: .9rem; }

/* admin */
.admin-layout { display: grid; grid-template-columns: 220px 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .admin-layout { grid-template-columns: 1fr; } }
.admin-nav { padding: 8px; position: sticky; top: 76px; }
@media (max-width: 860px) { .admin-nav { position: static; display: flex; overflow-x: auto; } }
.admin-nav a { display: block; padding: 10px 14px; border-radius: 10px; color: var(--text); font-weight: 500; white-space: nowrap; }
.admin-nav a.active, .admin-nav a:hover { background: var(--brand-soft); color: var(--brand); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 12px 10px; border-bottom: 1px solid var(--line); font-size: .925rem; vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: .825rem; }
.admin-mod { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; }
.admin-mod-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--bg); border-radius: 12px 12px 0 0; }
.admin-lesson { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.drag { cursor: grab; color: var(--muted); }
.creds { background: var(--brand-soft); border-radius: 12px; padding: 16px; font-size: 1.05rem; }
.creds b { font-family: ui-monospace, monospace; }
.qedit { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.qedit .optrow { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }

/* modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(15, 12, 40, .5); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .15s; }
.modal { background: var(--card); border-radius: 20px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: pop .2s cubic-bezier(.2,.8,.2,1); }
.modal.wide { max-width: 820px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.95); opacity: 0; } }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px); background: var(--text); color: var(--card); padding: 12px 22px; border-radius: 12px; font-weight: 500; z-index: 60; transition: transform .25s cubic-bezier(.2,.8,.2,1), opacity .25s; pointer-events: none; opacity: 0; max-width: calc(100vw - 32px); }
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.xp-pop { position: fixed; top: 80px; left: 50%; transform: translateX(-50%); background: var(--brand); color: #fff; padding: 12px 24px; border-radius: 99px; font-weight: 800; font-size: 1.2rem; z-index: 70; animation: xp 1.8s forwards; }
@keyframes xp { 0% { opacity: 0; transform: translate(-50%, 20px) scale(.8); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.05); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -30px); } }
.confetti { position: fixed; top: -10px; width: 10px; height: 14px; z-index: 80; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

.center-screen { min-height: 70vh; display: grid; place-items: center; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty-state .big { font-size: 3rem; }

/* certificate */
.cert { background: #fff; color: #1d1b2c; max-width: 900px; margin: 0 auto; aspect-ratio: 1.414; padding: 6%; border: 14px solid var(--brand); outline: 2px solid var(--brand); outline-offset: -26px; text-align: center; display: flex; flex-direction: column; justify-content: center; gap: 12px; }
.cert h1 { font-size: 2.6rem; color: var(--brand); }
.cert .name { font-size: 2.2rem; font-weight: 800; border-bottom: 2px solid #ddd; display: inline-block; padding: 0 30px 6px; margin: 0 auto; }
@media print { .topbar, .no-print { display: none !important; } main { padding: 0; } body { background: #fff; } .cert { border-width: 10px; } }

@media (max-width: 640px) {
  .nav { display: none; }
  .hide-sm { display: none !important; }
  h1 { font-size: 1.45rem; }
  .card { padding: 16px; }
}
.mobile-nav { display: none; }
@media (max-width: 640px) {
  .mobile-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); z-index: 30; justify-content: space-around; padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); }
  .mobile-nav a { display: flex; flex-direction: column; align-items: center; font-size: .75rem; color: var(--muted); padding: 4px 10px; }
  .mobile-nav a.active { color: var(--brand); }
  .mobile-nav a span { font-size: 1.3rem; }
  main { padding-bottom: 90px; }
}
