:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --bar: #0f172a;
  --accent: #ff5a1f;
  --accent-2: #ff8a3d;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 1px rgba(15, 23, 42, 0.03);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.14);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
main { flex: 1; padding: 28px 16px 64px; }
a { color: inherit; }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.wide { max-width: 1160px; margin: 0 auto; }
.narrow { max-width: 460px; margin: 32px auto; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 28px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 16px 28px; }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--ink); color: #fff; border: 1px solid var(--ink); border-radius: 10px;
  padding: 10px 18px; min-height: 42px; font: inherit; font-weight: 600; font-size: 15px;
  text-decoration: none; cursor: pointer; transition: background .15s, transform .05s, box-shadow .15s;
}
.btn:hover { background: #1e293b; }
.btn:active { transform: translateY(1px); }
.btn-lg { min-height: 48px; padding: 12px 22px; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 14px; border-radius: 8px; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: #f8fafc; }
.btn-light { background: #fff; color: var(--ink); border-color: #fff; }
.btn-light:hover { background: #f1f5f9; }
.text-link { color: var(--ink-2); font-size: 14px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.stack { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; }
input[type="email"], input[type="text"], select {
  font: inherit; font-weight: 400; padding: 12px 14px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; min-height: 46px;
}
input:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgba(255, 90, 31, 0.25); }
.alert { background: #fff7ed; border: 1px solid #fed7aa; color: #7c2d12; padding: 10px 14px; border-radius: 10px; word-break: break-word; }
.banner { display: flex; align-items: center; gap: 10px; background: var(--green-bg); color: #14532d; padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; font-weight: 600; }

/* ---------- Top bar ---------- */
.topbar { background: var(--bar); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1160px; margin: 0 auto; padding: 0 16px; height: 60px; display: flex; align-items: center; justify-content: space-between; }
.brand img { height: 26px; width: auto; display: block; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; padding: 8px 10px; border-radius: 8px; min-height: 40px;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover { background: rgba(255, 255, 255, 0.1); }
.menu .avatar { width: 36px; height: 36px; min-height: 36px; padding: 0; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; justify-content: center; font-size: 15px; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 8px); background: #fff; color: var(--ink);
  border-radius: 12px; box-shadow: var(--shadow-lg); min-width: 220px; padding: 6px; z-index: 30;
  display: flex; flex-direction: column;
}
.menu-list a, .menu-list button {
  display: flex; align-items: center; justify-content: space-between; text-align: left; padding: 10px 12px; border-radius: 8px;
  text-decoration: none; background: none; border: 0; font: inherit; font-size: 15px; color: inherit; cursor: pointer; width: 100%;
}
.menu-list a:hover, .menu-list button:hover { background: #f1f5f9; }
.menu-list a.active { font-weight: 600; }
.menu-who { display: flex; flex-direction: column; padding: 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: 13px; color: var(--muted); word-break: break-all; }
.menu-who strong { color: var(--ink); font-size: 15px; }

/* ---------- Sign-in ---------- */
.auth { max-width: 940px; margin: 24px auto; display: grid; grid-template-columns: 1fr 1fr; background: var(--card); border-radius: 20px; overflow: hidden; box-shadow: var(--shadow-lg); min-height: 460px; }
.auth-art { background: #0f172a center / cover no-repeat; position: relative; }
.auth-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(160deg, rgba(15, 23, 42, 0.1), rgba(15, 23, 42, 0.55)); }
.auth-card { padding: 44px 40px; display: flex; flex-direction: column; justify-content: center; }
.auth-card h1 { font-size: 30px; margin: 0 0 8px; }
.icon-badge { width: 52px; height: 52px; border-radius: 14px; background: #fff1eb; color: var(--accent); display: grid; place-items: center; margin-bottom: 16px; }

/* ---------- Dashboard ---------- */
.hero {
  display: grid; grid-template-columns: 1fr 300px; gap: 28px; align-items: center;
  background: radial-gradient(circle at 85% 20%, rgba(255, 90, 31, 0.35), transparent 45%), linear-gradient(135deg, #0f172a, #1e293b);
  color: #fff; border-radius: 20px; padding: 36px; margin-bottom: 20px;
}
.hero h1 { font-size: 34px; margin: 0 0 12px; }
.hero-text p { margin: 0; color: #cbd5e1; font-size: 16px; max-width: 640px; }
.hero-side { background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.hero-label { font-size: 13px; color: #cbd5e1; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.hero-count { font-size: 18px; color: #cbd5e1; }
.hero-count strong { font-size: 40px; color: #fff; }
.hero-sub { font-size: 14px; color: #cbd5e1; }
.hero-done { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.hero .bar { background: rgba(255, 255, 255, 0.15); }
.how { color: var(--ink-2); font-size: 15px; margin: 0 0 22px; }

.bar { height: 8px; border-radius: 999px; background: #e2e8f0; overflow: hidden; width: 100%; }
.bar span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 22px; }
.module-card { background: var(--card); border-radius: var(--radius); overflow: hidden; text-decoration: none; display: flex; flex-direction: column; box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s; }
a.module-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.cover { position: relative; aspect-ratio: 16 / 9; background: #0f172a center / cover no-repeat; }
.module-card.locked .cover { filter: grayscale(0.6) brightness(0.55); }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.cover .pill { position: absolute; top: 12px; left: 12px; }
.cover .pill.status { left: auto; right: 12px; }
.pill-dark { background: rgba(15, 23, 42, 0.85); color: #fff; backdrop-filter: blur(4px); }
.pill-green { background: var(--green); color: #fff; }
.card-body { padding: 18px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title { font-size: 18px; margin: 0; }
.meta { display: flex; gap: 14px; color: var(--muted); font-size: 13px; }
.meta span { display: inline-flex; align-items: center; gap: 5px; }
.clamp { margin: 0; font-size: 14px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { margin-top: auto; padding-top: 10px; display: flex; justify-content: space-between; align-items: center; gap: 16px; min-height: 44px; }
.mini-progress { display: flex; align-items: center; gap: 10px; flex: 1; max-width: 180px; }
.mini-progress .bar { height: 6px; }
.module-card.locked { opacity: 0.85; }

/* ---------- Module / lesson ---------- */
.crumbs { margin-bottom: 12px; }
.crumbs a { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: 14px; padding: 6px 0; }
.crumbs a:hover { color: var(--ink); }
.module-head { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 20px 24px; margin-bottom: 18px; }
.module-head h2 { margin: 2px 0 0; font-size: 22px; }
.eyebrow { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.module-head-progress { display: flex; align-items: center; gap: 10px; width: 220px; flex: none; }

.lesson-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
.sidebar { padding: 18px 14px; position: sticky; top: 78px; max-height: calc(100vh - 96px); overflow: auto; }
.sidebar-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 0 8px 10px; }
.mobile-lessons { display: none; }
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { position: relative; }
.steps li:not(:last-child)::before { content: ""; position: absolute; left: 21px; top: 34px; bottom: -6px; width: 2px; background: var(--line); }
.steps li.done:not(:last-child)::before { background: var(--green); }
.steps a, .steps li > span { display: flex; gap: 12px; align-items: flex-start; padding: 8px; border-radius: 10px; text-decoration: none; }
.steps a:hover { background: #f8fafc; }
.steps li.current > a { background: #fff4ee; }
.dot { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid #cbd5e1; background: #fff; display: grid; place-items: center; color: #fff; position: relative; z-index: 1; }
.done .dot { background: var(--green); border-color: var(--green); }
.current .dot { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 90, 31, 0.2); }
.locked .dot { color: #94a3b8; }
.step-text { font-size: 14px; line-height: 1.4; padding-top: 3px; color: var(--ink-2); }
.current .step-text { color: var(--ink); font-weight: 600; }
.locked .step-text { color: #94a3b8; }

.lesson { padding: 32px 40px; }
.lesson-meta { margin-bottom: 4px; }
.lesson h1 { font-size: 30px; margin: 4px 0 14px; }
.lesson h2 { font-size: 22px; margin: 28px 0 10px; }
.lesson h3 { font-size: 18px; margin: 22px 0 8px; }
.lesson h4 { font-size: 16px; margin: 0 0 4px; }
.lesson .rich, .lesson ul, .lesson p { max-width: 740px; }
.rich p { margin: 0 0 14px; }
.lesson ul { padding-left: 22px; }
.lesson li { margin: 4px 0; }
.facts { display: grid; gap: 8px; margin: 16px 0; padding: 16px 18px; background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; max-width: 740px; }
.facts div { display: flex; gap: 8px; flex-wrap: wrap; }
.facts dt { font-weight: 600; }
.facts dd { margin: 0; color: var(--ink-2); }
.outcomes .ticks { list-style: none; padding: 0; }
.outcomes .ticks li { position: relative; padding-left: 30px; margin: 8px 0; }
.outcomes .ticks li::before { content: ""; position: absolute; left: 0; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--green-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' fill='none' stroke='%2316a34a' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E") center / 14px no-repeat; }
.cards { display: grid; gap: 12px; max-width: 740px; }
.card-item { border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; padding: 14px 16px; background: #fff; }
.card-item .rich p:last-child { margin-bottom: 0; }
.block { margin-bottom: 6px; }

.lesson-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.lesson-nav-right { display: flex; gap: 10px; flex-wrap: wrap; }
.ok-line { display: flex; align-items: center; gap: 8px; color: var(--green); font-weight: 600; }

/* ---------- Assessment ---------- */
.assess-facts { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 12px; }
.assess-facts span { background: #f1f5f9; border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.quiz { display: flex; flex-direction: column; gap: 16px; margin-top: 18px; }
.question { border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin: 0; min-width: 0; }
.question legend { display: flex; gap: 12px; font-weight: 600; font-size: 17px; padding: 0; margin-bottom: 12px; float: left; width: 100%; }
.question legend + * { clear: both; }
.qnum { flex: none; width: 28px; height: 28px; border-radius: 8px; background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 14px; }
.options { display: grid; gap: 8px; }
.option { position: relative; flex-direction: row; align-items: center; gap: 12px; font-weight: 400; font-size: 15px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; transition: border-color .12s, background .12s; }
.option:hover { border-color: #94a3b8; }
.option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.option-key { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid #cbd5e1; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: var(--muted); }
.option:has(input:checked) { border-color: var(--ink); background: #f8fafc; }
.option:has(input:checked) .option-key { background: var(--ink); border-color: var(--ink); color: #fff; }
.option:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.submit-bar { position: sticky; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 0 -40px -32px; padding: 14px 40px; background: #fff; border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 -6px 16px rgba(15, 23, 42, 0.06); }
#answered { font-weight: 600; color: var(--ink-2); }

.result { display: flex; align-items: center; gap: 24px; border-radius: 16px; padding: 24px; margin-top: 8px; }
.result h1 { margin: 0 0 6px; font-size: 26px; }
.result p { margin: 0; }
.result.pass { background: var(--green-bg); color: #14532d; }
.result.fail { background: var(--red-bg); color: #7f1d1d; }
.ring { --c: var(--green); flex: none; width: 104px; height: 104px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--c) calc(var(--pct) * 1%), rgba(255, 255, 255, 0.7) 0); }
.fail .ring { --c: var(--red); }
.ring span { width: 80px; height: 80px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-size: 24px; font-weight: 700; color: var(--ink); }

/* ---------- Admin ---------- */
.admin { padding: 28px; }
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.inline input { min-width: 260px; }
.inline-label { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; }
.add .muted { font-size: 13px; }
.table-wrap { overflow-x: auto; margin: 12px 0; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
button.link { background: none; border: 0; color: var(--red); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; padding: 26px; }
  .lesson-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-lessons { display: block; padding: 0; }
  .mobile-lessons summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; font-weight: 600; min-height: 52px; }
  .mobile-lessons summary::-webkit-details-marker { display: none; }
  .mobile-lessons summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin-left: 12px; transition: transform .15s; }
  .mobile-lessons[open] summary::after { transform: rotate(-135deg); }
  .mobile-lessons summary .muted { margin-left: auto; font-weight: 400; }
  .mobile-lessons .steps { padding: 0 10px 12px; }
}
@media (max-width: 640px) {
  main { padding: 16px 12px 48px; }
  .topbar-inner { height: 56px; }
  .brand img { height: 20px; }
  .hero { padding: 22px; border-radius: 16px; }
  .hero h1 { font-size: 26px; }
  .hero-text p { font-size: 15px; }
  .grid { grid-template-columns: 1fr; gap: 16px; }
  .module-head { flex-direction: column; align-items: stretch; gap: 12px; padding: 16px 18px; }
  .module-head h2 { font-size: 19px; }
  .module-head-progress { width: auto; }
  .lesson { padding: 22px 18px; }
  .lesson h1 { font-size: 24px; }
  .lesson h2 { font-size: 20px; }
  .lesson-nav { flex-direction: column-reverse; align-items: stretch; }
  .lesson-nav > *, .lesson-nav form, .lesson-nav .btn, .lesson-nav-right { width: 100%; }
  .lesson-nav-right { flex-direction: column-reverse; }
  .lesson-nav > span:empty { display: none; }
  .question { padding: 14px; }
  .question legend { font-size: 16px; }
  .submit-bar { flex-direction: column; align-items: stretch; margin: 0 -18px -22px; padding: 12px 18px; gap: 8px; }
  #answered { text-align: center; }
  .lesson-meta { display: none; }
  .hero-text p { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
  .result { flex-direction: column; text-align: center; }
  .auth { grid-template-columns: 1fr; margin: 0; min-height: 0; }
  .auth-art { height: 160px; background-position: center 20%; }
  .auth-card { padding: 28px 22px; }
  .pad, .admin { padding: 20px; }
  .narrow { margin: 12px auto; }
  .inline input { min-width: 0; width: 100%; }
}

.hint { margin-top: 18px; }
.dev-box { margin-top: 24px; padding: 14px; border: 1px dashed #f59e0b; border-radius: 10px; background: #fffbeb; }
.staff-chip { font-size: 13px; color: #cbd5e1; text-decoration: none; padding: 6px 10px; border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 999px; }
.foot a { color: inherit; }
.prose h2 { font-size: 18px; margin: 22px 0 8px; }
.prose ul { padding-left: 20px; }
