/* ===== Shared course engine styles ===== */
:root {
  --bg: #0f1117; --bg2: #161a23; --bg3: #1e2330; --line: #2a3142;
  --fg: #e6e9ef; --fg2: #a7b0c0; --fg3: #6b7489;
  --accent: #7c5cff; --accent2: #a48bff; --accent-bg: rgba(124,92,255,.14);
  --ok: #2ecc71; --ok-bg: rgba(46,204,113,.14);
  --bad: #ff5c7a; --bad-bg: rgba(255,92,122,.14);
  --warn: #ffb547; --warn-bg: rgba(255,181,71,.14);
  --info: #4cc3ff; --info-bg: rgba(76,195,255,.12);
  --hl1: #ffb547; --hl2: #4cc3ff; --hl3: #2ecc71; --hl4: #ff5c7a; --hl5: #c38bff;
  --radius: 14px; --shadow: 0 8px 30px rgba(0,0,0,.35);
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="light"] {
  --bg: #f6f7fb; --bg2: #ffffff; --bg3: #eef0f6; --line: #dde1ea;
  --fg: #171a21; --fg2: #4a5265; --fg3: #8a92a5;
  --accent-bg: rgba(124,92,255,.10);
  --shadow: 0 8px 30px rgba(20,30,60,.10);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 15px/1.6 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
code, pre, kbd { font-family: var(--mono); }
::selection { background: var(--accent); color: #fff; }

/* ----- layout ----- */
.app { display: grid; grid-template-columns: 270px 1fr; grid-template-rows: 56px 1fr; height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 0 18px; background: var(--bg2); border-bottom: 1px solid var(--line); z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--fg); }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 16px; }
.brand:hover { text-decoration: none; }
.topbar .spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; background: var(--bg3); border: 1px solid var(--line); font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill.click { cursor: pointer; }
.pill.click:hover { border-color: var(--accent); }
.pill.timer.running { background: var(--accent-bg); border-color: var(--accent); }
.daily { width: 90px; height: 6px; background: var(--line); border-radius: 9px; overflow: hidden; }
.daily > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--ok)); }
.iconbtn { border: 1px solid var(--line); background: var(--bg3); border-radius: 10px; width: 34px; height: 34px; cursor: pointer; display: grid; place-items: center; }
.iconbtn:hover { border-color: var(--accent); }

.sidebar { background: var(--bg2); border-right: 1px solid var(--line); overflow-y: auto; padding: 14px 10px 40px; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--fg3); margin: 16px 10px 6px; font-weight: 700; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--fg2); cursor: pointer; font-size: 14px; }
.nav-item:hover { background: var(--bg3); color: var(--fg); text-decoration: none; }
.nav-item.active { background: var(--accent-bg); color: var(--fg); font-weight: 600; }
.nav-item .ico { width: 22px; text-align: center; font-size: 16px; }
.nav-item .lbl { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ring { width: 22px; height: 22px; flex: none; }
.ring circle { fill: none; stroke-width: 3; }
.ring .bgc { stroke: var(--line); }
.ring .fgc { stroke: var(--ok); stroke-linecap: round; transition: stroke-dashoffset .4s; }

.main { overflow-y: auto; position: relative; }
.page { max-width: 1060px; margin: 0 auto; padding: 28px 28px 80px; }
.page.wide { max-width: none; padding: 0; height: 100%; }
.menu-btn { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: 56px; left: 0; bottom: 0; width: 280px; transform: translateX(-100%); transition: transform .2s; z-index: 20; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .menu-btn { display: grid; }
  .page { padding: 18px 16px 60px; }
  .hide-sm { display: none !important; }
}

/* ----- generic ui ----- */
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -.01em; }
h2 { font-size: 21px; margin: 26px 0 10px; }
h3 { font-size: 17px; margin: 20px 0 8px; }
.sub { color: var(--fg2); margin: 0 0 22px; }
.muted { color: var(--fg3); }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--bg3); padding: 9px 16px; border-radius: 11px; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--fg); }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #062; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 9px; }
.btn.big { padding: 14px 22px; font-size: 16px; border-radius: 14px; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; background: var(--bg3); border: 1px solid var(--line); color: var(--fg2); }
.tag.easy { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.tag.medium { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.tag.hard { color: var(--bad); background: var(--bad-bg); border-color: transparent; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.bar { height: 8px; background: var(--line); border-radius: 9px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 9px; transition: width .4s; }
input[type=text], input[type=number], input[type=email], input[type=password], select, textarea { background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* ----- home ----- */
.hero { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 26px; }
@media (max-width: 860px) { .hero { grid-template-columns: 1fr; } }
.hero .card.cta { background: linear-gradient(135deg, var(--accent-bg), transparent 70%), var(--bg2); border-color: var(--accent); }
.hero .big-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent2); font-weight: 700; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--bg3); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--fg3); }
.mod-card { cursor: pointer; transition: transform .12s, border-color .12s; display: flex; flex-direction: column; gap: 8px; }
.mod-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.mod-card .mico { font-size: 26px; }
.mod-card .mt { font-weight: 700; font-size: 16px; }
.mod-card .ms { color: var(--fg2); font-size: 13px; flex: 1; }
.quick { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 26px; }

/* ----- module page ----- */
.lesson-list { display: flex; flex-direction: column; gap: 8px; }
.lesson-row { display: flex; align-items: center; gap: 14px; padding: 13px 16px; border-radius: 12px; background: var(--bg2); border: 1px solid var(--line); cursor: pointer; }
.lesson-row:hover { border-color: var(--accent); }
.lesson-row .num { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--bg3); font-weight: 700; font-size: 13px; flex: none; }
.lesson-row.done .num { background: var(--ok); color: #052; }
.lesson-row .lt { flex: 1; font-weight: 600; }
.lesson-row .lm { color: var(--fg3); font-size: 13px; }

/* ----- lesson stepper ----- */
.lesson-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.lesson-head .crumb { color: var(--fg3); font-size: 13px; }
.dots { display: flex; gap: 5px; flex-wrap: wrap; margin: 6px 0 18px; }
.dots i { width: 22px; height: 6px; border-radius: 4px; background: var(--line); cursor: pointer; }
.dots i.done { background: var(--ok); }
.dots i.cur { background: var(--accent); }
.step { animation: slidein .25s ease; }
@keyframes slidein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.step-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 24px; gap: 10px; position: sticky; bottom: 0; padding: 14px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.kbd-hint { color: var(--fg3); font-size: 12px; }
kbd { background: var(--bg3); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: 11px; }
.step-type { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--accent2); margin-bottom: 8px; }

/* ----- markdown ----- */
.md { font-size: 16px; line-height: 1.7; }
.md p { margin: 0 0 14px; }
.md h1, .md h2, .md h3 { margin-top: 6px; }
.md ul, .md ol { padding-left: 22px; margin: 0 0 14px; }
.md li { margin: 4px 0; }
.md code { background: var(--bg3); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; font-size: .88em; }
.md pre { background: #0b0d12; color: #e6e9ef; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; overflow-x: auto; font-size: 13.5px; line-height: 1.55; }
.md pre code { background: none; border: 0; padding: 0; font-size: inherit; color: inherit; }
.md blockquote { margin: 0 0 14px; padding: 12px 16px; border-left: 4px solid var(--accent); background: var(--accent-bg); border-radius: 0 12px 12px 0; }
.md blockquote p:last-child { margin: 0; }
.md table { border-collapse: collapse; margin: 0 0 16px; font-size: 14px; width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; }
.md th { background: var(--bg3); }
.md strong { color: var(--fg); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.tldr { border: 1px solid var(--accent); background: var(--accent-bg); border-radius: 12px; padding: 10px 14px; margin-bottom: 16px; font-weight: 600; }
.tldr::before { content: "TL;DR  "; color: var(--accent2); font-weight: 800; letter-spacing: .05em; }

/* ----- quiz ----- */
.quiz-q { font-size: 18px; font-weight: 600; margin-bottom: 14px; }
.opts { display: flex; flex-direction: column; gap: 9px; }
.opt { text-align: left; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); cursor: pointer; display: flex; gap: 12px; align-items: flex-start; font-size: 15px; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt .k { width: 24px; height: 24px; border-radius: 7px; background: var(--bg3); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.opt.sel { border-color: var(--accent); background: var(--accent-bg); }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); animation: shake .3s; }
.opt:disabled { cursor: default; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.explain { margin-top: 14px; padding: 12px 16px; border-radius: 12px; background: var(--bg3); border-left: 4px solid var(--ok); }
.explain.bad { border-left-color: var(--bad); }

/* ----- flashcards ----- */
.fc-wrap { perspective: 1200px; max-width: 640px; margin: 0 auto; }
.fc { position: relative; min-height: 240px; cursor: pointer; transform-style: preserve-3d; transition: transform .45s; }
.fc.flip { transform: rotateY(180deg); }
.fc > div { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 18px; padding: 26px; display: flex; align-items: center; justify-content: center; text-align: center; background: var(--bg2); border: 1px solid var(--line); font-size: 18px; overflow: auto; }
.fc .back { transform: rotateY(180deg); border-color: var(--accent); }
.fc-actions { display: flex; justify-content: center; gap: 10px; margin-top: 18px; }

/* ----- toasts / confetti ----- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--bg2); border: 1px solid var(--accent); border-radius: 12px; padding: 10px 16px; box-shadow: var(--shadow); font-weight: 600; animation: toastin .3s ease; }
@keyframes toastin { from { opacity: 0; transform: translateY(10px) scale(.96); } }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 99; }

/* ----- focus overlay ----- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 24px; width: min(520px, 92vw); box-shadow: var(--shadow); }

/* ----- viz ----- */
.viz { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.viz svg { width: 100%; height: auto; display: block; overflow: visible; }
.viz-caption { color: var(--fg2); font-size: 14px; margin-top: 8px; }
.viz-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.viz-msg { min-height: 48px; margin-top: 10px; padding: 10px 14px; background: var(--bg3); border-radius: 10px; font-size: 14.5px; }
.viz-msg code { background: var(--bg); padding: 0 5px; border-radius: 5px; }
.viz-inputs { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; font-size: 13px; color: var(--fg2); }
.viz-inputs input[type=text] { font-family: var(--mono); font-size: 13px; min-width: 200px; }
.viz-vars { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.viz-vars span { font-family: var(--mono); font-size: 12.5px; background: var(--bg); border: 1px solid var(--line); padding: 2px 8px; border-radius: 7px; }
.viz-code { font-family: var(--mono); font-size: 12.5px; background: #0b0d12; color: #cfd6e4; border-radius: 10px; padding: 8px 0; margin-top: 10px; overflow-x: auto; }
.viz-code div { padding: 0 12px; white-space: pre; }
.viz-code div.on { background: rgba(124,92,255,.35); }
.v-cell { fill: var(--bg3); stroke: var(--line); stroke-width: 1.5; }
.v-text { fill: var(--fg); font-family: var(--mono); font-size: 15px; text-anchor: middle; dominant-baseline: central; }
.v-small { fill: var(--fg3); font-family: var(--mono); font-size: 11px; text-anchor: middle; dominant-baseline: central; }
.v-label { fill: var(--fg2); font-family: var(--sans); font-size: 12px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
.v-edge { stroke: var(--fg3); stroke-width: 2; fill: none; }
.v-node { fill: var(--bg3); stroke: var(--fg3); stroke-width: 2; }
.v-ptr { fill: var(--accent2); font-family: var(--mono); font-size: 12px; font-weight: 700; text-anchor: middle; }
.hl1 { fill: rgba(255,181,71,.35) !important; stroke: var(--hl1) !important; }
.hl2 { fill: rgba(76,195,255,.30) !important; stroke: var(--hl2) !important; }
.hl3 { fill: rgba(46,204,113,.32) !important; stroke: var(--hl3) !important; }
.hl4 { fill: rgba(255,92,122,.32) !important; stroke: var(--hl4) !important; }
.hl5 { fill: rgba(195,139,255,.32) !important; stroke: var(--hl5) !important; }
.dim { opacity: .35; }
.e-hl1 { stroke: var(--hl1) !important; stroke-width: 3.5 !important; }
.e-hl2 { stroke: var(--hl2) !important; stroke-width: 3.5 !important; }
.e-hl3 { stroke: var(--hl3) !important; stroke-width: 3.5 !important; }
.e-hl4 { stroke: var(--hl4) !important; stroke-width: 3.5 !important; }
.e-dim { opacity: .25; }
.v-anim { transition: all .3s ease; }

/* highlighted code blocks keep our pre styling */
.md pre.hl { background: #0b0d12; }
.md pre.hl .cm-keyword { color: #ff79c6; } .md pre.hl .cm-string { color: #f1fa8c; } .md pre.hl .cm-number { color: #bd93f9; }
.md pre.hl .cm-comment { color: #6272a4; } .md pre.hl .cm-type, .md pre.hl .cm-variable-3 { color: #8be9fd; font-style: italic; }
.md pre.hl .cm-def { color: #50fa7b; } .md pre.hl .cm-atom { color: #bd93f9; } .md pre.hl .cm-meta { color: #f8f8f2; } .md pre.hl .cm-operator { color: #ff79c6; }

/* ----- small-screen fixes ----- */
.app > *, .main, .page, .step, .md, .viz, .card { min-width: 0; }
.md pre, .viz-code { max-width: 100%; }
.md table { display: block; overflow-x: auto; }
@media (max-width: 600px) {
  .topbar { gap: 7px; padding: 0 10px; }
  .brand > span:last-child { display: none; }
  .pill { padding: 4px 8px; font-size: 12px; }
  .iconbtn { width: 32px; height: 32px; }
  .page { padding: 14px 12px 60px; }
  h1 { font-size: 23px; }
  .md { font-size: 15.5px; }
  .md pre { font-size: 12.5px; padding: 10px 12px; }
  .step-nav { padding: 10px 0; }
  .viz { padding: 10px; }
  .viz-inputs input[type=text] { min-width: 0; width: 100%; }
  .viz-inputs label { flex: 1 1 100%; }
  .opt { padding: 11px 12px; font-size: 14.5px; }
  .hero .card { padding: 16px; }
  .btn.big { padding: 12px 18px; font-size: 15px; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr) !important; }
  .topbar { min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .topbar::-webkit-scrollbar { display: none; }
  .kbd-hint { display: none; }
}

/* ----- account ----- */
.lh-acct { gap: 7px; max-width: 150px; overflow: hidden; }
.lh-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.lh-in { width: 100%; font-size: 16px; padding: 10px 12px; }
.lh-l { gap: 4px; font-size: 13px; font-weight: 600; color: var(--fg2); }
.lh-msg { color: var(--bad); font-size: 13.5px; min-height: 1em; }
.lh-tabs { margin-bottom: 14px; }
