:root{
  color-scheme: light;
  --navy-950:#071c30;
  --navy-900:#0d2b46;
  --navy-700:#1a4a73;
  --blue-500:#2f7fe0;
  --blue-100:#e4f0fd;
  --gold-500:#c08e2e;
  --gold-100:#f7ecd5;
  --green-600:#28925c;
  --green-100:#e2f5eb;
  --red-600:#c94a3f;
  --red-100:#fbe8e6;
  --bg:#f2f5f9;
  --surface:#ffffff;
  --surface-2:#eaf0f6;
  --border:#d6dfe8;
  --text:#152233;
  --muted:#5c6b7a;
  --rail-bg:#0d2b46;
  --rail-text:#cfe0f2;
  --font-display:'Fraunces', 'Iowan Old Style', Georgia, serif;
  --font-body:'Public Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    color-scheme: dark;
    --bg:#0a1722; --surface:#10202f; --surface-2:#13293c; --border:#22394c;
    --text:#e7edf3; --muted:#93a7b9; --blue-100:#12283d; --gold-100:#2a2312;
    --green-100:#12291f; --red-100:#2c1815; --rail-bg:#071722; --rail-text:#bcd2e6;
  }
}
:root[data-theme="dark"]{
  color-scheme: dark;
  --bg:#0a1722; --surface:#10202f; --surface-2:#13293c; --border:#22394c;
  --text:#e7edf3; --muted:#93a7b9; --blue-100:#12283d; --gold-100:#2a2312;
  --green-100:#12291f; --red-100:#2c1815; --rail-bg:#071722; --rail-text:#bcd2e6;
}

*{box-sizing:border-box;}
html,body{ background:var(--bg); }
body{ color:var(--text); font-family:var(--font-body); line-height:1.5; margin:0; }
h1,h2,h3,.display{ font-family:var(--font-display); text-wrap:balance; }
code,.mono,.stat,td.num,th.num{ font-family:var(--font-mono); }
button{ font-family:inherit; }
a{ color:var(--blue-500); }
img{ max-width:100%; }
::selection{ background:var(--blue-100); }

.app{ display:flex; min-height:100vh; max-width:1280px; margin:0 auto; }

/* ---------- Rail ---------- */
.rail{
  width:296px; flex:none; background:var(--rail-bg); color:var(--rail-text);
  padding:28px 20px 28px 24px; display:flex; flex-direction:column; gap:22px;
  position:sticky; top:0; align-self:flex-start; height:100vh; height:100dvh; overflow-y:auto;
}
.brand{ display:flex; align-items:center; gap:10px; padding-bottom:14px; border-bottom:1px solid rgba(255,255,255,.12); }
.brand-mark{
  width:34px;height:34px;border-radius:8px;
  background:linear-gradient(155deg,var(--blue-500),#5aa6f2);
  display:flex;align-items:center;justify-content:center;
  color:#fff; font-family:var(--font-display); font-weight:700; font-size:17px; flex:none; overflow:hidden;
}
.brand-mark img{ width:100%; height:100%; object-fit:contain; padding:4px; }
.brand-text .k1{ font-size:10.5px; letter-spacing:.09em; text-transform:uppercase; color:rgba(255,255,255,.55); }
.brand-text .k2{ font-family:var(--font-display); font-size:16px; font-weight:600; color:#fff; }
.rail-back{ display:flex; align-items:center; gap:6px; font-size:12.5px; color:rgba(255,255,255,.65); text-decoration:none; margin-top:-8px; }
.rail-back svg{ width:14px; height:14px; }
.rail-back:hover{ color:#fff; }

.rail-progress{ padding:2px 2px 4px; }
.rail-progress .pct{ font-family:var(--font-mono); font-size:22px; color:#fff; font-weight:600; }
.rail-progress .lbl{ font-size:12px; color:rgba(255,255,255,.6); margin-top:2px;}
.barbg{ height:6px; border-radius:99px; background:rgba(255,255,255,.14); margin-top:10px; overflow:hidden; }
.barfill{ height:100%; border-radius:99px; background:linear-gradient(90deg,var(--blue-500),var(--gold-500)); transition:width .5s ease; }

.stepper{ list-style:none; margin:0; padding:0; display:flex; flex-direction:column; position:relative; }
.step{ position:relative; display:flex; gap:12px; padding:11px 8px; border-radius:10px; cursor:pointer; align-items:flex-start; }
.step:hover{ background:rgba(255,255,255,.06); }
.step.is-current{ background:rgba(47,127,224,.22); }
.step.is-locked{ cursor:not-allowed; opacity:.55; }
.step-line{ position:absolute; left:23px; top:38px; bottom:-6px; width:2px; background:rgba(255,255,255,.14); }
.step:last-child .step-line{ display:none; }
.step.is-passed .step-line{ background:var(--green-600); }
.node{
  width:30px;height:30px;border-radius:50%; flex:none; display:flex;align-items:center;justify-content:center;
  background:rgba(255,255,255,.10); border:1.5px solid rgba(255,255,255,.25);
  font-family:var(--font-mono); font-size:12.5px; font-weight:600; color:#fff; z-index:1;
}
.step.is-passed .node{ background:var(--green-600); border-color:var(--green-600); }
.step.is-current .node{ border-color:var(--gold-500); box-shadow:0 0 0 3px rgba(192,142,46,.25); }
.node svg{ width:14px;height:14px; }
.step-meta .t{ font-size:13.5px; font-weight:600; color:#fff; margin-top:3px; }
.step-meta .s{ font-size:11.5px; color:rgba(255,255,255,.55); margin-top:1px; }
.step-meta .score{ font-family:var(--font-mono); font-size:11px; margin-top:3px; color:var(--gold-500); }
.cert-node{ margin-top:2px; }
.rail-foot{ margin-top:auto; font-size:11px; color:rgba(255,255,255,.45); line-height:1.5; padding-top:10px; border-top:1px solid rgba(255,255,255,.1); }
.rail-mobile{ display:none; }

/* ---------- Main ---------- */
.main{ flex:1; min-width:0; padding:36px 44px 80px; }
.topline{ display:flex; justify-content:space-between; align-items:baseline; gap:16px; flex-wrap:wrap; margin-bottom:26px; }
.eyebrow{ font-size:11.5px; letter-spacing:.09em; text-transform:uppercase; color:var(--blue-500); font-weight:600; }
.course-title{ font-size:15px; color:var(--muted); }

.mod-head{ display:flex; gap:16px; align-items:flex-start; margin-bottom:22px; }
.mod-icon{ width:52px;height:52px;border-radius:14px; flex:none; background:var(--blue-100); color:var(--blue-500); display:flex;align-items:center;justify-content:center; }
.mod-icon svg{ width:26px;height:26px; }
.mod-num{ font-family:var(--font-mono); color:var(--muted); font-size:12.5px; letter-spacing:.04em; }
.mod-title{ font-size:29px; font-weight:600; margin:2px 0 4px; }
.mod-sub{ color:var(--muted); font-size:15px; max-width:62ch; }

.section-label{ font-size:12px; letter-spacing:.08em; text-transform:uppercase; color:var(--muted); font-weight:600; margin:34px 0 14px; display:flex; align-items:center; gap:8px; }
.section-label::after{ content:""; flex:1; height:1px; background:var(--border); }

.cards{ display:grid; grid-template-columns:repeat(auto-fit,minmax(230px,1fr)); gap:14px; }
.card{ background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:16px 18px; display:flex; flex-direction:column; gap:6px; }
.card .ct{ font-weight:600; font-size:14.5px; }
.card .cb{ font-size:13.6px; color:var(--muted); }
.card .cb b{ color:var(--text); font-weight:600; }

.tablewrap{ overflow-x:auto; border:1px solid var(--border); border-radius:12px; }
table{ width:100%; border-collapse:collapse; font-size:13.6px; min-width:480px; }
caption{ text-align:left; padding:12px 16px 0; font-size:12.5px; color:var(--muted); caption-side:top; }
thead th{ text-align:left; padding:11px 16px; background:var(--surface-2); font-size:11.5px; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); font-weight:600; border-bottom:1px solid var(--border); }
tbody td{ padding:11px 16px; border-bottom:1px solid var(--border); vertical-align:top; }
tbody tr:last-child td{ border-bottom:none; }
tbody tr:nth-child(odd){ background:color-mix(in srgb, var(--surface-2) 35%, transparent); }
td.tag{ font-family:var(--font-mono); font-weight:600; color:var(--navy-700); }

/* ---------- Matching exercise ---------- */
.match-wrap{ background:var(--surface); border:1px solid var(--border); border-radius:14px; padding:20px 22px; }
.match-instructions{ font-size:13.5px; color:var(--muted); margin-bottom:14px; }
.match-grid{ display:grid; grid-template-columns:1fr 1fr; gap:22px; }
@media (max-width:640px){ .match-grid{ grid-template-columns:1fr; } }
.match-col-label{ font-size:11px; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); margin-bottom:8px; font-weight:600; }
.match-item{ display:block; width:100%; text-align:left; padding:11px 14px; margin-bottom:8px; border:1.5px solid var(--border); border-radius:10px; background:var(--surface); font-size:13.8px; cursor:pointer; color:var(--text); transition:border-color .15s, background .15s; }
.match-item.term{ font-family:var(--font-mono); font-weight:600; }
.match-item:hover:not(:disabled){ border-color:var(--blue-500); }
.match-item.selected{ border-color:var(--blue-500); background:var(--blue-100); }
.match-item.solved{ border-color:var(--green-600); background:var(--green-100); cursor:default; opacity:.85; }
.match-item.wrong{ border-color:var(--red-600); background:var(--red-100); animation:shake .32s; }
.match-item:disabled{ cursor:default; }
@keyframes shake{ 0%,100%{transform:translateX(0);} 25%{transform:translateX(-4px);} 75%{transform:translateX(4px);} }
.match-status{ margin-top:12px; font-size:13px; color:var(--muted); display:flex; justify-content:space-between; align-items:center; gap:10px; flex-wrap:wrap; }
.match-status.done{ color:var(--green-600); font-weight:600; }
.btn-ghost{ border:1.5px solid var(--border); background:transparent; color:var(--text); padding:7px 13px; border-radius:8px; font-size:12.8px; cursor:pointer; }
.btn-ghost:hover{ border-color:var(--blue-500); color:var(--blue-500); }

/* ---------- Quiz ---------- */
.quiz-box{ background:var(--surface); border:1px solid var(--border); border-radius:14px; padding:22px 24px 24px; }
.quiz-meta{ display:flex; justify-content:space-between; align-items:center; margin-bottom:6px; flex-wrap:wrap; gap:8px;}
.quiz-meta .req{ font-size:12px; color:var(--muted); }
.quiz-meta .req b{ color:var(--gold-500); font-family:var(--font-mono); }
.qitem{ padding:20px 0; border-top:1px solid var(--border); }
.qitem:first-of-type{ border-top:none; padding-top:8px; }
.qtext{ font-weight:600; font-size:15px; margin-bottom:12px; }
.qtext .qn{ color:var(--muted); font-family:var(--font-mono); font-weight:600; margin-right:6px; }
.choices{ display:flex; flex-direction:column; gap:8px; }
.choice{ display:flex; align-items:center; gap:10px; text-align:left; border:1.5px solid var(--border); border-radius:10px; padding:11px 14px; background:var(--surface); cursor:pointer; font-size:13.9px; width:100%; }
.choice:hover:not(:disabled){ border-color:var(--blue-500); }
.choice .bullet{ width:19px;height:19px;border-radius:50%; border:1.5px solid var(--border); flex:none; display:flex; align-items:center; justify-content:center; font-size:10px; color:transparent; }
.choice.picked{ border-color:var(--blue-500); background:var(--blue-100); }
.choice.picked .bullet{ border-color:var(--blue-500); background:var(--blue-500); color:#fff; }
.choice.correct{ border-color:var(--green-600); background:var(--green-100); }
.choice.correct .bullet{ border-color:var(--green-600); background:var(--green-600); color:#fff; }
.choice.incorrect{ border-color:var(--red-600); background:var(--red-100); }
.choice.incorrect .bullet{ border-color:var(--red-600); background:var(--red-600); color:#fff; }
.choice:disabled{ cursor:default; }
.qexplain{ margin-top:10px; font-size:12.8px; color:var(--muted); background:var(--surface-2); border-left:3px solid var(--blue-500); padding:9px 12px; border-radius:0 8px 8px 0; display:none; }
.qexplain.show{ display:block; }

.quiz-actions{ display:flex; justify-content:flex-end; gap:10px; margin-top:8px; }
.btn{ border:none; background:var(--blue-500); color:#fff; padding:11px 20px; border-radius:9px; font-size:13.8px; font-weight:600; cursor:pointer; }
.btn:hover{ background:var(--navy-700); }
.btn:disabled{ opacity:.45; cursor:not-allowed; }
.btn.secondary{ background:transparent; color:var(--text); border:1.5px solid var(--border); }
.btn.secondary:hover{ border-color:var(--blue-500); color:var(--blue-500); background:transparent; }

.result-banner{ margin-top:18px; border-radius:12px; padding:16px 18px; display:none; align-items:center; gap:14px; }
.result-banner.show{ display:flex; }
.result-banner.pass{ background:var(--green-100); border:1px solid var(--green-600); }
.result-banner.fail{ background:var(--red-100); border:1px solid var(--red-600); }
.result-score{ font-family:var(--font-mono); font-size:24px; font-weight:600; flex:none; }
.result-banner.pass .result-score{ color:var(--green-600); }
.result-banner.fail .result-score{ color:var(--red-600); }
.result-text b{ display:block; font-size:14px; margin-bottom:2px; }
.result-text span{ font-size:12.8px; color:var(--muted); }

.nav-foot{ display:flex; justify-content:space-between; align-items:center; margin-top:36px; padding-top:20px; border-top:1px solid var(--border); flex-wrap:wrap; gap:12px; }
.nav-foot .hint{ font-size:12.5px; color:var(--muted); }

/* ---------- Certificate ---------- */
.cert-card{ background:linear-gradient(160deg, var(--navy-900), var(--navy-700)); color:#fff; border-radius:18px; padding:44px 40px; text-align:center; position:relative; overflow:hidden; }
.cert-card::before{ content:""; position:absolute; inset:0; background:radial-gradient(circle at 85% 0%, rgba(192,142,46,.25), transparent 55%); }
.cert-badge{ width:64px;height:64px; margin:0 auto 16px; border-radius:50%; background:rgba(192,142,46,.18); border:1.5px solid var(--gold-500); display:flex; align-items:center; justify-content:center; position:relative;}
.cert-badge svg{ width:30px;height:30px; color:var(--gold-500); }
.cert-card h2{ font-size:26px; margin:0 0 6px; position:relative; }
.cert-card p{ color:rgba(255,255,255,.7); font-size:14px; max-width:52ch; margin:0 auto 26px; position:relative; }
.cert-grid{ display:grid; grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); gap:12px; position:relative; text-align:left; }
.cert-item{ background:rgba(255,255,255,.06); border:1px solid rgba(255,255,255,.12); border-radius:10px; padding:12px 14px; }
.cert-item .t{ font-size:12.5px; color:rgba(255,255,255,.65); }
.cert-item .v{ font-family:var(--font-mono); font-size:19px; font-weight:600; margin-top:2px; color:var(--gold-500); }

@media (max-width:900px){
  .rail{ display:none; }
  .rail-mobile{ display:block; position:sticky; top:0; z-index:5; background:var(--rail-bg); color:var(--rail-text); padding:14px 16px calc(14px + env(safe-area-inset-top,0px)) 16px; padding-top:calc(14px + env(safe-area-inset-top,0px)); }
  .rail-mobile .brand{ border:none; padding:0 0 10px; }
  .rail-mobile .rail-back{ margin-bottom:8px; }
  .rail-mobile .stepper{ flex-direction:row; overflow-x:auto; gap:6px; padding-bottom:2px; }
  .rail-mobile .step{ flex-direction:column; align-items:center; text-align:center; width:72px; flex:none; padding:8px 4px; }
  .rail-mobile .step-line{ display:none; }
  .rail-mobile .step-meta{ width:100%; }
  .rail-mobile .step-meta .s, .rail-mobile .step-meta .score{ display:none; }
  .rail-mobile .step-meta .t{ font-size:10px; line-height:1.2; white-space:normal; overflow-wrap:break-word; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
  .main{ padding:22px 18px 60px; }
  .mod-title{ font-size:23px; }
}

/* ================= HUB / LANDING ================= */
.hub-header{ display:flex; align-items:center; gap:14px; padding:26px 44px; border-bottom:1px solid var(--border); }
.hub-header .brand-mark{ width:44px; height:44px; border-radius:10px; }
.hub-header .hk1{ font-size:11px; letter-spacing:.09em; text-transform:uppercase; color:var(--muted); }
.hub-header .hk2{ font-family:var(--font-display); font-size:19px; font-weight:600; }
.hub-wrap{ max-width:1100px; margin:0 auto; padding:0 44px 80px; }
.hub-hero{ padding:48px 0 8px; max-width:70ch; }
.hub-hero .eyebrow{ margin-bottom:10px; }
.hub-hero h1{ font-size:38px; font-weight:600; margin:0 0 12px; }
.hub-hero p{ color:var(--muted); font-size:16px; }
.level-section{ margin-top:44px; }
.level-title{ display:flex; align-items:baseline; gap:12px; margin-bottom:18px; }
.level-title h2{ font-size:21px; font-weight:600; margin:0; }
.level-title .count{ font-size:12.5px; color:var(--muted); font-family:var(--font-mono); }
.course-grid{ display:grid; grid-template-columns:repeat(auto-fit,minmax(260px,1fr)); gap:16px; }
.course-card{ background:var(--surface); border:1px solid var(--border); border-radius:14px; padding:22px 22px 20px; display:flex; flex-direction:column; gap:10px; text-decoration:none; color:var(--text); transition:border-color .15s, transform .15s; }
.course-card:hover{ border-color:var(--blue-500); transform:translateY(-2px); }
.course-card .cc-icon{ width:42px; height:42px; border-radius:11px; background:var(--blue-100); color:var(--blue-500); display:flex; align-items:center; justify-content:center; }
.course-card .cc-icon svg{ width:22px; height:22px; }
.course-card .cc-title{ font-weight:600; font-size:16px; margin-top:4px; }
.course-card .cc-desc{ font-size:13.3px; color:var(--muted); flex:1; }
.course-card .cc-meta{ font-size:11.5px; color:var(--gold-500); font-family:var(--font-mono); display:flex; align-items:center; gap:6px; }
.hub-footer{ font-size:12.5px; color:var(--muted); padding-top:30px; margin-top:20px; border-top:1px solid var(--border); }
@media (max-width:640px){
  .hub-header, .hub-wrap{ padding-left:18px; padding-right:18px; }
  .hub-hero h1{ font-size:28px; }
}
