/* ============================================================ SQLTRAIN ===
   Design tokens. Dark is the default; [data-theme="light"] flips them.
   ======================================================================== */
:root {
  --bg:        #0d1117;
  --bg-2:      #131a23;
  --bg-3:      #19212c;
  --panel:     #141c26;
  --line:      #243040;
  --line-2:    #2f3d50;
  --txt:       #e6edf5;
  --txt-2:     #9fb0c3;
  --txt-3:     #6c7f94;
  --accent:    #35d6c0;
  --accent-2:  #14b8a6;
  --accent-dim:#0f3d3a;
  --blue:      #58a6ff;
  --amber:     #f0b429;
  --amber-dim: #3d2f0d;
  --green:     #3fb950;
  --green-dim: #12331b;
  --red:       #f85149;
  --red-dim:   #3d1a19;
  --purple:    #bc8cff;
  --shadow:    0 8px 30px rgba(0,0,0,.45);
  --radius:    12px;
  --radius-sm: 8px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --sb-w: 268px;
}
[data-theme="light"] {
  --bg:        #f6f8fa;
  --bg-2:      #ffffff;
  --bg-3:      #eef2f6;
  --panel:     #ffffff;
  --line:      #dde5ee;
  --line-2:    #c6d2e0;
  --txt:       #16202b;
  --txt-2:     #4a5b6e;
  --txt-3:     #78889a;
  --accent:    #0d9488;
  --accent-2:  #0f766e;
  --accent-dim:#d5f2ee;
  --blue:      #0969da;
  --amber:     #b45309;
  --amber-dim: #fdf1d8;
  --green:     #1a7f37;
  --green-dim: #dcf5e3;
  --red:       #cf222e;
  --red-dim:   #ffe9e7;
  --purple:    #8250df;
  --shadow:    0 6px 24px rgba(30,50,80,.10);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--txt);
  font-family: var(--sans); font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { line-height: 1.25; margin: 0 0 .5em; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.85rem; } h2 { font-size: 1.35rem; } h3 { font-size: 1.08rem; }
p { margin: 0 0 1em; }
code { font-family: var(--mono); font-size: .89em; }
::selection { background: var(--accent); color: #04211d; }

/* ------------------------------------------------------------- boot ---- */
#boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 999; }
.boot-card { text-align: center; width: min(360px, 84vw); }
.boot-logo { font-size: 2rem; font-weight: 800; letter-spacing: -.03em; margin-bottom: 1.2rem; }
.boot-logo span { color: var(--accent); }
.boot-bar { height: 4px; background: var(--bg-3); border-radius: 99px; overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 8%; background: var(--accent); border-radius: 99px; transition: width .35s ease; }
.boot-msg { margin-top: .9rem; color: var(--txt-3); font-size: .84rem; }

/* ------------------------------------------------------------ shell ---- */
#shell { display: flex; min-height: 100vh; }
#sidebar {
  width: var(--sb-w); flex: 0 0 var(--sb-w); background: var(--bg-2);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 40;
}
.sb-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 10px; }
.logo { font-size: 1.15rem; font-weight: 800; letter-spacing: -.03em; color: var(--txt); }
.logo:hover { text-decoration: none; }
.logo span { color: var(--accent); }

.sb-streak {
  margin: 4px 14px 14px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--amber-dim), transparent);
  border: 1px solid var(--line); font-size: .78rem; color: var(--txt-2);
}
.sb-streak b { color: var(--amber); font-size: 1.4rem; display: block; line-height: 1.1; font-weight: 750; }

.sb-nav, .sb-modules { display: flex; flex-direction: column; padding: 0 10px; gap: 1px; }
.sb-nav a, .sb-modules a {
  display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--txt-2); font-size: .87rem; font-weight: 500;
}
.sb-nav a:hover, .sb-modules a:hover { background: var(--bg-3); color: var(--txt); text-decoration: none; }
.sb-nav a.active, .sb-modules a.active { background: var(--accent-dim); color: var(--accent); }
.sb-nav .ic { width: 16px; text-align: center; opacity: .8; font-size: .8rem; }
.sb-section-label {
  padding: 18px 20px 7px; font-size: .68rem; text-transform: uppercase;
  letter-spacing: .1em; color: var(--txt-3); font-weight: 650;
}
.sb-modules a { justify-content: space-between; }
.sb-modules .mtitle { display: flex; align-items: center; gap: 9px; min-width: 0; }
.sb-modules .mnum {
  flex: 0 0 20px; height: 20px; border-radius: 6px; background: var(--bg-3);
  display: grid; place-items: center; font-size: .68rem; font-weight: 700; color: var(--txt-3);
  font-family: var(--mono);
}
.sb-modules a.active .mnum, .sb-modules a.done .mnum { background: var(--accent); color: #04211d; }
.sb-modules .mname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-modules .mpct { font-size: .68rem; color: var(--txt-3); font-family: var(--mono); flex: 0 0 auto; }
.sb-foot { margin-top: auto; padding: 14px 14px 18px; display: flex; gap: 6px; }
.ghost-btn {
  flex: 1; background: transparent; border: 1px solid var(--line); color: var(--txt-2);
  padding: 7px 8px; border-radius: var(--radius-sm); cursor: pointer; font-size: .75rem;
  font-family: inherit;
}
.ghost-btn:hover { background: var(--bg-3); color: var(--txt); border-color: var(--line-2); }

#scrim { display: none; }
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  padding: 0 26px; height: 56px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
#crumbs { font-size: .82rem; color: var(--txt-3); display: flex; align-items: center; gap: 7px; min-width: 0; }
#crumbs .sep { opacity: .45; }
#crumbs b { color: var(--txt-2); font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.xp-chip {
  font-family: var(--mono); font-size: .74rem; padding: 4px 10px; border-radius: 99px;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--txt-2); white-space: nowrap;
}
.xp-chip b { color: var(--accent); }
#view { padding: 30px 26px 90px; max-width: 1260px; width: 100%; }
.icon-btn { background: none; border: 0; color: var(--txt-2); font-size: 1.1rem; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--bg-3); color: var(--txt); }
.only-mobile { display: none; }

/* ----------------------------------------------------------- common ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.muted { color: var(--txt-2); }
.dim { color: var(--txt-3); }
.small { font-size: .82rem; }
.mono { font-family: var(--mono); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 18px; }

.btn {
  background: var(--accent); color: #04211d; border: 0; padding: 9px 16px; border-radius: var(--radius-sm);
  font-weight: 650; cursor: pointer; font-size: .86rem; font-family: inherit; white-space: nowrap;
  transition: filter .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.sec { background: var(--bg-3); color: var(--txt); border: 1px solid var(--line); }
.btn.sec:hover { border-color: var(--line-2); background: var(--bg-2); }
.btn.sm { padding: 6px 11px; font-size: .78rem; }
.btn.warn { background: var(--amber); color: #2a1f04; }

.pill {
  display: inline-flex; align-items: center; gap: 5px; font-size: .68rem; font-weight: 650;
  padding: 3px 9px; border-radius: 99px; background: var(--bg-3); color: var(--txt-2);
  text-transform: uppercase; letter-spacing: .05em;
}
.pill.beginner { background: var(--green-dim); color: var(--green); }
.pill.intermediate { background: var(--amber-dim); color: var(--amber); }
.pill.advanced { background: var(--red-dim); color: var(--red); }
.pill.expert { background: color-mix(in srgb, var(--purple) 18%, transparent); color: var(--purple); }
.pill.ok { background: var(--green-dim); color: var(--green); }

.diff { display: inline-flex; gap: 2px; vertical-align: middle; }
.diff i { width: 5px; height: 5px; border-radius: 99px; background: var(--line-2); display: block; }
.diff i.on { background: var(--amber); }

/* ------------------------------------------------------- dashboard ---- */
.hero {
  background: linear-gradient(140deg, var(--accent-dim), transparent 60%), var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 30px 32px; margin-bottom: 24px;
}
.hero h1 { font-size: 2rem; margin-bottom: .3em; }
.hero p { color: var(--txt-2); max-width: 62ch; margin-bottom: 1.2em; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 17px; }
.stat .k { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--txt-3); font-weight: 650; }
.stat .v { font-size: 1.7rem; font-weight: 720; letter-spacing: -.02em; margin-top: 3px; font-family: var(--mono); }
.stat .sub { font-size: .74rem; color: var(--txt-3); }

.mod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 14px; }
.mod-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 17px 19px; display: flex; flex-direction: column; gap: 9px; position: relative;
  transition: border-color .15s, transform .15s;
}
.mod-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.mod-card a.stretch { position: absolute; inset: 0; border-radius: var(--radius); }
.mod-card h3 { margin: 0; }
.mod-card .num { font-family: var(--mono); font-size: .72rem; color: var(--txt-3); font-weight: 700; }
.mod-card p { margin: 0; font-size: .85rem; color: var(--txt-2); }
.mod-card .foot { display: flex; align-items: center; gap: 10px; margin-top: auto; padding-top: 6px; }
.bar { flex: 1; height: 5px; background: var(--bg-3); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.bar.amber i { background: var(--amber); }
.locked { opacity: .55; }

/* ---------------------------------------------------------- lesson ---- */
/* Prose gets the larger share; the console only needs room for ~70 columns. */
.lesson-wrap { display: grid; grid-template-columns: minmax(0,1.15fr) minmax(0,.85fr); gap: 26px; align-items: start; }
.lesson-wrap.single { grid-template-columns: minmax(0,1fr); max-width: 820px; }
.teach { min-width: 0; }
.teach h2 { margin-top: 1.6em; }
.teach h2:first-child { margin-top: 0; }
.teach p { color: var(--txt); }
.teach ul, .teach ol { margin: 0 0 1em; padding-left: 1.3em; color: var(--txt); }
.teach li { margin-bottom: .35em; }
.teach code:not(pre code) {
  background: var(--bg-3); padding: 1.5px 5px; border-radius: 4px; color: var(--accent);
  border: 1px solid var(--line);
}
.callout { border-left: 3px solid var(--blue); background: var(--bg-2); padding: 12px 15px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin: 0 0 1.1em; font-size: .89rem; }
.callout.tip  { border-color: var(--green); }
.callout.warn { border-color: var(--red); }
.callout.note { border-color: var(--blue); }
.callout .lbl { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; font-weight: 700; display: block; margin-bottom: 3px; }
.callout.tip .lbl { color: var(--green); }
.callout.warn .lbl { color: var(--red); }
.callout.note .lbl { color: var(--blue); }
.callout p:last-child { margin-bottom: 0; }

.snippet { margin: 0 0 1.2em; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-2); }
.snippet pre { margin: 0; padding: 13px 15px; overflow-x: auto; font-family: var(--mono); font-size: .84rem; line-height: 1.55; }
.snippet .cap { padding: 7px 13px; border-top: 1px solid var(--line); font-size: .74rem; color: var(--txt-3); display: flex; align-items: center; gap: 8px; }
.snippet .cap .btn { margin-left: auto; }

.dtable-wrap { overflow-x: auto; margin: 0 0 1.2em; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table.dtable { border-collapse: collapse; width: 100%; font-size: .82rem; font-family: var(--mono); }
table.dtable th, table.dtable td { padding: 6px 11px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.dtable th { background: var(--bg-3); font-weight: 650; color: var(--txt-2); position: sticky; top: 0; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }
table.dtable tr:last-child td { border-bottom: 0; }
table.dtable tbody tr:hover { background: var(--bg-3); }
table.dtable td.null { color: var(--txt-3); font-style: italic; }
table.dtable td.num { text-align: right; }

.quiz { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 15px 17px; margin: 0 0 1.2em; background: var(--bg-2); }
.quiz .q { font-weight: 600; margin-bottom: 10px; }
.quiz .opt {
  display: block; width: 100%; text-align: left; padding: 8px 12px; margin-bottom: 6px;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--txt); cursor: pointer; font-size: .86rem; font-family: inherit;
}
.quiz .opt:hover { border-color: var(--accent); }
.quiz .opt.right { background: var(--green-dim); border-color: var(--green); color: var(--green); }
.quiz .opt.wrong { background: var(--red-dim); border-color: var(--red); color: var(--red); }
.quiz .explain { font-size: .84rem; color: var(--txt-2); margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }

/* ------------------------------------------------------ SQL console ---- */
.console { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 10px; }
.console-head { display: flex; align-items: center; gap: 8px; }
.console-head .title { font-size: .74rem; text-transform: uppercase; letter-spacing: .09em; color: var(--txt-3); font-weight: 700; }

.editor-box { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-2); overflow: hidden; }
.editor-box.focus { border-color: var(--accent); }
.ed { position: relative; min-height: 180px; }
.ed textarea, .ed pre {
  margin: 0; padding: 12px 14px; font-family: var(--mono); font-size: .845rem; line-height: 1.6;
  white-space: pre; overflow-wrap: normal; tab-size: 2; border: 0;
}
.ed pre { position: absolute; inset: 0; overflow: auto; pointer-events: none; color: var(--txt); }
.ed textarea {
  position: relative; width: 100%; height: 100%; min-height: 180px; display: block;
  background: transparent; color: transparent; caret-color: var(--accent); resize: vertical;
  outline: none; overflow: auto;
}
.ed textarea::placeholder { color: var(--txt-3); }
.tok-kw  { color: #ff7b95; font-weight: 600; }
.tok-fn  { color: var(--purple); }
.tok-str { color: #a5e075; }
.tok-num { color: #f0b429; }
.tok-com { color: var(--txt-3); font-style: italic; }
.tok-op  { color: var(--txt-2); }
[data-theme="light"] .tok-kw { color: #b3246b; }
[data-theme="light"] .tok-str { color: #1a7f37; }
[data-theme="light"] .tok-num { color: #9a6700; }

.ed-bar { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-top: 1px solid var(--line); background: var(--bg-3); }
.ed-bar .hint { font-size: .7rem; color: var(--txt-3); font-family: var(--mono); }

.result { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-2); }
.result-head { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-bottom: 1px solid var(--line); font-size: .74rem; color: var(--txt-3); font-family: var(--mono); background: var(--bg-3); }
/* Grows with the result up to a cap; drag the bottom edge for more room. */
.result-body { max-height: 440px; overflow: auto; resize: vertical; }
.result-body table.dtable th { top: 0; }
.result .err { padding: 13px 15px; color: var(--red); font-family: var(--mono); font-size: .82rem; white-space: pre-wrap; }
.result .empty { padding: 22px; text-align: center; color: var(--txt-3); font-size: .85rem; }

/* -------------------------------------------------------- exercise ---- */
.ex {
  border: 1px solid var(--line); border-left: 3px solid var(--amber); border-radius: var(--radius);
  background: var(--panel); padding: 18px 20px; margin-bottom: 16px;
}
.ex.solved { border-left-color: var(--green); }
.ex-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.ex-head .lbl { font-size: .7rem; text-transform: uppercase; letter-spacing: .09em; color: var(--amber); font-weight: 700; }
.ex.solved .ex-head .lbl { color: var(--green); }
.ex .prompt { font-size: .93rem; margin-bottom: 12px; }
.ex .prompt code { background: var(--bg-3); padding: 1.5px 5px; border-radius: 4px; color: var(--accent); }
.hintbox { font-size: .84rem; color: var(--txt-2); background: var(--bg-3); border-radius: var(--radius-sm); padding: 10px 13px; margin-top: 9px; border: 1px dashed var(--line-2); }
.verdict { margin-top: 10px; padding: 11px 14px; border-radius: var(--radius-sm); font-size: .86rem; }
.verdict.pass { background: var(--green-dim); color: var(--green); border: 1px solid color-mix(in srgb, var(--green) 35%, transparent); }
.verdict.fail { background: var(--red-dim); color: var(--red); border: 1px solid color-mix(in srgb, var(--red) 32%, transparent); }
.verdict b { display: block; margin-bottom: 2px; }
.verdict .why { color: var(--txt-2); font-size: .82rem; margin-top: 5px; }

.lesson-nav { display: flex; gap: 10px; margin-top: 34px; padding-top: 20px; border-top: 1px solid var(--line); }
.toc { display: flex; flex-direction: column; gap: 3px; }
.toc a { display: flex; gap: 10px; align-items: center; padding: 9px 13px; border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--txt); background: var(--panel); font-size: .89rem; }
.toc a:hover { border-color: var(--accent); text-decoration: none; }
.toc a .tick { width: 18px; height: 18px; border-radius: 99px; border: 1.5px solid var(--line-2); display: grid; place-items: center; font-size: .6rem; flex: 0 0 auto; }
.toc a.done .tick { background: var(--green); border-color: var(--green); color: #04211d; }
.toc a .mins { margin-left: auto; font-size: .72rem; color: var(--txt-3); font-family: var(--mono); }

/* --------------------------------------------------------- schema ----- */
.schema-grid { display: grid; grid-template-columns: 230px minmax(0,1fr); gap: 20px; align-items: start; }
.tbl-list { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 76px; }
.tbl-list button {
  text-align: left; background: transparent; border: 1px solid transparent; color: var(--txt-2);
  padding: 7px 11px; border-radius: var(--radius-sm); cursor: pointer; font-family: var(--mono);
  font-size: .8rem; display: flex; justify-content: space-between; gap: 8px;
}
.tbl-list button:hover { background: var(--bg-3); color: var(--txt); }
.tbl-list button.active { background: var(--accent-dim); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.tbl-list button span { color: var(--txt-3); font-size: .72rem; }
.col-badge { font-size: .64rem; padding: 1px 5px; border-radius: 4px; background: var(--bg-3); color: var(--txt-3); margin-left: 6px; border: 1px solid var(--line); }
.col-badge.pk { background: var(--amber-dim); color: var(--amber); }
.col-badge.fk { background: var(--accent-dim); color: var(--accent); }

/* -------------------------------------------------------- journal ----- */
.day { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin-bottom: 14px; overflow: hidden; }
.day-head { display: flex; align-items: center; gap: 12px; padding: 13px 18px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.day-head .date { font-weight: 650; }
.day-head .meta { margin-left: auto; font-size: .74rem; color: var(--txt-3); font-family: var(--mono); }
.day-body { padding: 14px 18px; }
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: flex; gap: 11px; padding: 5px 0; font-size: .86rem; align-items: baseline; }
.tl .t { font-family: var(--mono); font-size: .72rem; color: var(--txt-3); flex: 0 0 46px; }
.tl .dot { flex: 0 0 7px; height: 7px; border-radius: 99px; background: var(--accent); margin-top: 6px; }
.tl .dot.hw { background: var(--purple); }
.tl .dot.ex { background: var(--amber); }
.tl .dot.les { background: var(--blue); }

.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 11px); gap: 3px; overflow-x: auto; padding: 4px 0 10px; }
.heat i { width: 11px; height: 11px; border-radius: 2px; background: var(--bg-3); display: block; }
.heat i.l1 { background: color-mix(in srgb, var(--accent) 26%, var(--bg-3)); }
.heat i.l2 { background: color-mix(in srgb, var(--accent) 50%, var(--bg-3)); }
.heat i.l3 { background: color-mix(in srgb, var(--accent) 75%, var(--bg-3)); }
.heat i.l4 { background: var(--accent); }

.post-box {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 16px 18px; white-space: pre-wrap; font-size: .87rem; line-height: 1.65;
  max-height: 460px; overflow: auto;
}

/* ------------------------------------------------------- reference ---- */
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 14px; }
.ref-card h3 { font-size: .95rem; display: flex; align-items: center; gap: 8px; }
.ref-card pre { margin: 0; font-family: var(--mono); font-size: .78rem; background: var(--bg-2); padding: 11px 13px; border-radius: var(--radius-sm); overflow-x: auto; border: 1px solid var(--line); line-height: 1.55; }
.ref-card p { font-size: .82rem; color: var(--txt-2); margin: .6em 0 .4em; }

/* ------------------------------------------------- expanded console --- */
#modal-layer { display: none; }
#modal-layer.on {
  display: block; position: fixed; inset: 0; z-index: 120;
  background: var(--bg); padding: 16px 20px 20px;
}
body.no-scroll { overflow: hidden; }
/* Holds the console's place in the page while it is expanded. */
.console-placeholder { min-height: 4px; }

.console.expanded {
  position: static; height: 100%; display: flex; flex-direction: column; gap: 10px;
  max-width: 1500px; margin: 0 auto;
}
.console.expanded .console-head { flex: 0 0 auto; }
.console.expanded .editor-slot { flex: 0 0 auto; }
.console.expanded .ed textarea,
.console.expanded .ed pre { font-size: .95rem; line-height: 1.65; }
.console.expanded .result { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.console.expanded .result-body { flex: 1 1 auto; max-height: none; height: auto; resize: none; }
.console.expanded table.dtable { font-size: .86rem; }
.console.expanded table.dtable th, .console.expanded table.dtable td { padding: 7px 14px; }
.expand-btn { font-size: .72rem; white-space: nowrap; }

/* An expanded exercise: the whole card comes along so the question, hints and
   the pass/fail verdict stay visible next to the editor. */
.ex.expanded-host {
  height: 100%; overflow: auto; max-width: 1500px; margin: 0 auto;
  padding: 20px 24px 28px;
}
.ex.expanded-host .prompt { font-size: 1rem; max-width: 90ch; }
.ex.expanded-host .console.expanded { display: block; height: auto; max-width: none; }
.ex.expanded-host .console.expanded .result { display: block; }
.ex.expanded-host .console.expanded .result-body { max-height: 46vh; height: auto; resize: vertical; }

@media (max-width: 840px) {
  #modal-layer.on { padding: 10px; }
  .console.expanded .ed textarea, .console.expanded .ed pre { font-size: .88rem; }
}

/* --------------------------------------------------------- welcome ---- */
.welcome { display: flex; justify-content: center; padding: 10px 0 40px; }
.w-card {
  width: 100%; max-width: 720px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 26px 30px 22px; box-shadow: var(--shadow);
}
.w-dots { display: flex; gap: 7px; margin-bottom: 22px; }
.w-dot {
  flex: 1; height: 4px; border: 0; padding: 0; border-radius: 99px; cursor: pointer;
  background: var(--line-2); transition: background .2s;
}
.w-dot:hover { background: var(--txt-3); }
.w-dot.done { background: color-mix(in srgb, var(--accent) 55%, transparent); }
.w-dot.on { background: var(--accent); }
.w-ic { font-size: 2rem; line-height: 1; margin-bottom: 10px; }
.w-step h1 { margin: 0 0 .3em; font-size: 1.6rem; }
.w-lead { color: var(--txt-2); font-size: 1.05rem; margin: 0 0 1.2em; }
.w-content p { margin: 0 0 1em; }
.w-content ul { margin: 0 0 1.1em; padding-left: 20px; color: var(--txt-2); }
.w-content li { margin-bottom: 5px; }
.w-content .callout { margin-top: 4px; }
.w-flow { list-style: none; margin: 0 0 1.2em; padding: 0; counter-reset: wf; }
.w-flow li {
  counter-increment: wf; display: grid; grid-template-columns: 26px 1fr; gap: 4px 12px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.w-flow li::before {
  content: counter(wf); grid-row: span 2; align-self: start;
  width: 24px; height: 24px; border-radius: 99px; display: grid; place-items: center;
  background: var(--accent-dim); color: var(--accent); font-size: .78rem; font-weight: 700;
  font-family: var(--mono);
}
.w-flow li:last-child { border-bottom: 0; }
.w-flow b { font-size: .95rem; }
.w-flow span { color: var(--txt-2); font-size: .88rem; }
.w-name-row { margin: 0 0 1.1em; }
.w-name {
  width: 100%; font: inherit; font-size: 1rem; padding: 11px 14px;
  background: var(--bg-3); color: var(--txt); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.w-name:focus { outline: 0; border-color: var(--accent); }
.w-nav { display: flex; align-items: center; gap: 10px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.w-nav .btn:disabled { opacity: .35; cursor: default; }
.btn.big { font-size: .95rem; padding: 11px 20px; }

@media (max-width: 620px) {
  .w-card { padding: 20px 18px 18px; border-radius: 12px; }
  .w-step h1 { font-size: 1.32rem; }
  .w-lead { font-size: .96rem; }
  #skip { order: 10; }
}

/* ---------------------------------------------------------- drills ---- */
.drill {
  border: 1px solid var(--line); border-left: 3px solid var(--purple);
  border-radius: var(--radius); background: var(--panel); padding: 16px 18px 18px;
}
.drill.passed { border-left-color: var(--green); }
.drill-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.drill-head .lbl { font-size: .7rem; text-transform: uppercase; letter-spacing: .09em; color: var(--purple); font-weight: 700; }
.drill.passed .drill-head .lbl { color: var(--green); }
.drill-q .q { font-weight: 600; font-size: .96rem; margin-bottom: 12px; }
.drill-q .opts { display: flex; flex-direction: column; gap: 7px; }
.drill-q .opt {
  text-align: left; padding: 10px 13px; font: inherit; font-size: .88rem; cursor: pointer; color: var(--txt);
  background: var(--bg-3); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.drill-q .opt:hover:not(:disabled) { border-color: var(--accent); }
.drill-q .opt.right { background: var(--green-dim); border-color: var(--green); color: var(--green); }
.drill-q .opt.wrong { background: var(--red-dim); border-color: var(--red); color: var(--red); }
.type-row { display: flex; gap: 8px; align-items: center; }
.type-in {
  flex: 1; min-width: 0; font-family: var(--mono); font-size: .9rem; padding: 9px 12px;
  background: var(--bg-3); color: var(--txt); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.type-in:focus { outline: 0; border-color: var(--accent); }
.type-in.right { border-color: var(--green); color: var(--green); }
.type-in.wrong { border-color: var(--red); color: var(--red); }

/* -------------------------------------------------- mastery & locks --- */
.mastery {
  border: 1px dashed var(--line-2); border-radius: var(--radius); padding: 13px 16px;
  background: var(--bg-2); font-size: .86rem;
}
.mastery.done { border-style: solid; border-color: color-mix(in srgb, var(--green) 45%, transparent); }
.mastery .m-title { font-weight: 600; margin-bottom: 7px; }
.mastery.done .m-title { color: var(--green); }
.mastery ul { margin: 0; padding-left: 20px; color: var(--txt-2); }
.mastery li { margin-bottom: 3px; }
.mastery li.ok { color: var(--green); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--green) 45%, transparent); }
.mastery li::marker { content: '○  '; }
.mastery li.ok::marker { content: '✓  '; }

.toc a.locked { opacity: .55; }
.toc a.locked:hover { border-color: var(--line); transform: none; }
.sb-modules a.locked { opacity: .5; }
.sb-modules a.locked .mnum { background: transparent; }
.ghost-btn.wide { flex: 1 1 100%; margin-bottom: 6px; }
.ghost-btn.on { border-color: var(--accent); color: var(--accent); }

.locked-card { max-width: 660px; }
.locked-card .lock-ic { font-size: 1.7rem; margin-bottom: 6px; }
.lock-list { color: var(--txt-2); font-size: .88rem; margin: 10px 0 0; padding-left: 20px; }

/* -------------------------------------------------------- narrator ---- */
.narrator {
  position: sticky; top: 56px; z-index: 25; display: flex; align-items: center; gap: 8px;
  margin: 0 0 22px; padding: 8px 12px; border-radius: 99px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(10px); border: 1px solid var(--line);
}
.narrator[data-state="playing"] { border-color: var(--accent); }
.narrator.off { border-radius: var(--radius-sm); color: var(--txt-3); }
.n-play {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  background: var(--bg-3); color: var(--txt); border: 1px solid var(--line);
  padding: 6px 14px 6px 11px; border-radius: 99px; font: inherit; font-size: .82rem; font-weight: 550;
}
.n-play:hover { border-color: var(--accent); color: var(--accent); }
.narrator[data-state="playing"] .n-play { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.n-ic { font-size: .8rem; line-height: 1; }
.n-bar { width: 110px; height: 4px; border-radius: 99px; background: var(--bg-3); overflow: hidden; }
.n-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.n-count { font-family: var(--mono); font-size: .7rem; }
.n-hint { font-size: .76rem; }
.n-speed { font-family: var(--mono); font-size: .74rem; border: 1px solid var(--line); }

/* The paragraph currently being read. */
.speaking {
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  box-shadow: -10px 0 0 color-mix(in srgb, var(--accent) 13%, transparent),
               10px 0 0 color-mix(in srgb, var(--accent) 13%, transparent);
  border-radius: 3px;
}
/* Block-level highlights read better with a rail than a wash. */
.snippet.speaking, .callout.speaking, .quiz.speaking, .dtable-wrap.speaking {
  box-shadow: 0 0 0 2px var(--accent); background: none;
}
.teach p, .teach li, .teach h2, .teach h3 { cursor: default; }

.n-panel {
  position: absolute; right: 0; top: calc(100% + 8px); width: 330px; z-index: 40;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; font-size: .82rem;
}
.n-panel hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.n-row { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.n-row > span:first-child { width: 46px; color: var(--txt-2); flex: 0 0 auto; }
.n-row select, .n-row input[type="range"] { flex: 1; min-width: 0; }
.n-row select {
  background: var(--bg-3); color: var(--txt); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 5px 8px; font: inherit; font-size: .8rem;
}
.n-try { border: 1px solid var(--line); flex: 0 0 auto; font-size: .8rem; }
.n-try:hover { border-color: var(--accent); color: var(--accent); }
.n-upgrade-box {
  margin-top: 12px; padding: 11px 13px; border-radius: var(--radius-sm);
  background: var(--amber-dim); border: 1px solid color-mix(in srgb, var(--amber) 40%, transparent);
  font-size: .79rem; line-height: 1.55;
}
.n-upgrade-box b { color: var(--amber); }
.n-upgrade-box ol { margin: 7px 0; padding-left: 18px; }
.n-upgrade-box li { margin-bottom: 6px; }
.n-check { display: flex; gap: 9px; align-items: flex-start; margin-bottom: 9px; cursor: pointer; }
.n-check input { margin-top: 3px; flex: 0 0 auto; }
.n-check em { color: var(--txt-3); font-style: normal; }

@media (max-width: 840px) {
  .narrator { flex-wrap: wrap; border-radius: var(--radius); }
  .n-hint { display: none; }
  .n-panel { width: min(330px, calc(100vw - 40px)); }
}

/* ---------------------------------------------------------- toast ----- */
#toast-wrap { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 11px 16px; box-shadow: var(--shadow); font-size: .86rem;
  max-width: 340px; animation: slide .25s ease;
}
.toast.good { border-left-color: var(--green); }
.toast.bad { border-left-color: var(--red); }
.toast.xp { border-left-color: var(--amber); }
@keyframes slide { from { opacity: 0; transform: translateX(18px); } }

/* --------------------------------------------------------- mobile ----- */
@media (max-width: 1080px) { .lesson-wrap { grid-template-columns: minmax(0,1fr); } .console { position: static; } }
@media (max-width: 840px) {
  .only-mobile { display: inline-flex; }
  #sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow); }
  #sidebar.open { transform: none; }
  #scrim.on { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 35; }
  #view { padding: 20px 16px 80px; }
  #topbar { padding: 0 14px; }
  .hero { padding: 22px 20px; }
  .schema-grid { grid-template-columns: minmax(0,1fr); }
  .tbl-list { position: static; flex-direction: row; overflow-x: auto; padding-bottom: 6px; }
  .tbl-list button { white-space: nowrap; }
}

@media print {
  #sidebar, #topbar, .lesson-nav, .btn, #toast-wrap, .narrator { display: none !important; }
  body { background: #fff; color: #000; }
  #view { padding: 0; max-width: none; }
}
