:root {
  --bg: #f5f6fb; --card: #fff; --text: #1d2133; --muted: #6b7088; --line: #e4e6ef;
  --primary: #4f46e5; --primary-d: #4338ca; --primary-l: #eef0ff;
  --ok: #059669; --ok-l: #e7f8f1; --warn: #b45309; --warn-l: #fff5e5; --bad: #dc2626; --bad-l: #fdecec;
  --radius: 14px; --shadow: 0 1px 2px rgba(20,24,60,.05), 0 6px 24px rgba(20,24,60,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 26px; margin: 0 0 6px; letter-spacing: -.01em; }
h2 { font-size: 19px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px; padding: 12px 28px;
  background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); font-size: 17px; }
.brand:hover { text-decoration: none; }
.logo { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; color: #fff;
  background: linear-gradient(135deg, #6366f1, #4338ca); font-weight: 800; }
.nav { display: flex; align-items: center; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a { padding: 7px 12px; border-radius: 9px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--primary-l); color: var(--primary); text-decoration: none; }
.nav a.active { background: var(--primary-l); color: var(--primary); }
.nav .who { margin-left: 10px; padding-left: 14px; border-left: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.menu-btn { display: none; margin-left: auto; border: 0; background: none; font-size: 22px; cursor: pointer; }

.container { max-width: 1180px; margin: 0 auto; padding: 28px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 18px; }
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid-2 { display: grid; gap: 18px; grid-template-columns: 2fr 1fr; }
.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .num { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.course-card { display: flex; flex-direction: column; gap: 8px; }
.course-card .code { font-size: 12px; font-weight: 700; color: var(--primary); letter-spacing: .06em; }
.course-card .desc { color: var(--muted); flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid transparent; background: var(--primary); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--primary-d); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--line); }
.btn.secondary:hover { background: #f7f7fb; }
.btn.danger { background: #fff; color: var(--bad); border-color: #f3c4c4; }
.btn.danger:hover { background: var(--bad-l); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-l); border-color: var(--primary); }
textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: 14px; }
.fields { display: grid; gap: 0 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 15px; margin: 6px 0; cursor: pointer; }
.check input { width: auto; }

.auth-wrap { display: grid; place-items: center; min-height: calc(100vh - 160px); }
.auth { width: 100%; max-width: 420px; }
.auth h1 { margin-bottom: 4px; }
.hero-note { margin-top: 14px; font-size: 13px; color: var(--muted); text-align: center; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f0f1f6; color: var(--muted); }
.badge.published, .badge.active, .badge.ok { background: var(--ok-l); color: var(--ok); }
.badge.draft, .badge.warn { background: var(--warn-l); color: var(--warn); }
.badge.archived, .badge.dropped, .badge.bad { background: var(--bad-l); color: var(--bad); }
.badge.role { background: var(--primary-l); color: var(--primary); }
.grade { display: inline-grid; place-items: center; min-width: 34px; height: 34px; border-radius: 10px; font-weight: 800; background: var(--primary-l); color: var(--primary); }
.grade.F { background: var(--bad-l); color: var(--bad); }

.progress { height: 8px; background: #eceef5; border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, #6366f1, #22c55e); border-radius: 99px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.num-dot { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: #f0f1f6; font-size: 13px; font-weight: 700; color: var(--muted); }
.num-dot.done { background: var(--ok-l); color: var(--ok); }

.lesson-body { white-space: pre-wrap; font-size: 16px; line-height: 1.7; }
.question { border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; background: #fff; }
.question .q-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-weight: 600; }
.opt-correct { color: var(--ok); font-weight: 600; }
.opt-wrong { color: var(--bad); }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: 6px 12px; border-radius: 10px; background: var(--warn-l); color: var(--warn); }
.answer-text { white-space: pre-wrap; background: #f8f9fc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 6px 0 10px; }
.q-builder { border: 1px dashed #c9cce0; border-radius: 12px; padding: 14px; margin-bottom: 12px; background: #fbfbfe; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }
.callout { background: var(--primary-l); border-radius: 12px; padding: 12px 14px; color: #2e2a7a; font-size: 14px; }
.callout code { font-size: 12px; word-break: break-all; }

.toast { position: fixed; right: 24px; bottom: 24px; max-width: 380px; padding: 12px 16px; border-radius: 12px; color: #fff;
  background: #1f2437; box-shadow: 0 10px 30px rgba(0,0,0,.2); z-index: 50; }
.toast.error { background: var(--bad); }
.toast.success { background: var(--ok); }

@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .container { padding: 18px; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .menu-btn { display: block; }
  .nav { display: none; width: 100%; flex-direction: column; align-items: stretch; }
  .nav.open { display: flex; }
  .nav .who { border-left: 0; margin: 6px 0 0; padding: 6px 12px; }
}
.lesson-body { margin: 14px 0 22px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.pts { width: 110px; }

/* --- Public demo + phone (390px) tweaks --- */
.card, .auth { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
.demo-banner {
  display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px 16px;
  padding: 10px 16px; background: #1e1b4b; color: #eef0ff;
  font-size: 13px; line-height: 1.45;
}
.demo-banner a { color: #c7d2fe; }
.demo-banner-text { flex: 1; min-width: 200px; }
.demo-logins { display: inline; }
.demo-reset-btn { margin-left: auto; flex-shrink: 0; }
.demo-reset-link { width: 100%; background: #312e81; border-radius: 10px; padding: 8px 12px; }
.demo-reset-link[hidden] { display: none; }
.demo-reset-note { color: #c7d2fe; margin-top: 4px; }

@media (max-width: 860px) {
  .btn, .btn.secondary { min-height: 44px; }
  input, select, textarea { font-size: 16px; } /* prevents iOS zoom on focus */
  .toast { left: 12px; right: 12px; bottom: 12px; max-width: none; }
  .page-head { align-items: stretch; }
  .demo-banner { padding: 10px 12px; }
  .demo-reset-btn { width: 100%; margin-left: 0; }
  .pts { width: 80px; }
}

@media (max-width: 430px) {
  h1 { font-size: 22px; }
  .container { padding: 14px 12px 28px; }
  .card { padding: 16px; }
  .topbar .brand span:last-child { font-size: 15px; }
}
