/*
  Styles for the course exercise pages.

  You are free to use this source as you see fit. MITM AB 2026
*/
:root {
  --ink: #1d1d1f;
  --muted: #5f6368;
  --line: #e2e4e9;
  --bg: #ffffff;
  --panel: #f6f7f9;
  --blue: #1a8fd6;
  --blue-soft: #e8f4fc;
  --magenta: #c8236a;
  --green: #2a9d47;
  --green-soft: #e9f7ed;
  --red: #d93025;
  --red-soft: #fdecea;
  --orange: #e8870e;
  --orange-soft: #fff4e5;
  --purple: #7a3db8;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px; }

/* header */
.top { padding: 40px 0 8px; }
.course { color: var(--muted); font-size: 14px; letter-spacing: .02em; margin: 0; }
h1 { font-size: clamp(26px, 4vw, 34px); line-height: 1.2; margin: 6px 0 10px; }
.lead { color: var(--muted); max-width: 64ch; margin: 0 0 8px; }

.bar {
  position: sticky; top: 0; z-index: 10;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.bar .wrap { display: flex; align-items: center; gap: 14px; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
.progress { flex: 0 0 140px; height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
#progressbar { height: 100%; width: 0; background: var(--green); transition: width .4s; }
#progresscount { font-size: 14px; color: var(--muted); min-width: 92px; }
#exnav { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.navchip {
  width: 30px; height: 30px; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--line);
  color: var(--ink); text-decoration: none; font-size: 13px;
}
.navchip:hover { border-color: var(--blue); color: var(--blue); }
.navchip.done { background: var(--green); border-color: var(--green); color: #fff; }
.linkbtn { background: none; border: 0; color: var(--muted); font-size: 13px; cursor: pointer; text-decoration: underline; }

/* exercise cards */
#exercises { padding: 24px 0 60px; display: grid; gap: 28px; }
.ex {
  border: 1px solid var(--line); border-radius: 14px;
  padding: 22px 22px 18px; background: #fff;
}
.ex.is-done { border-color: #bfe3c8; }
.ex > header { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 8px; }
.exnum {
  flex: 0 0 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 600;
  background: var(--blue-soft); color: var(--blue);
}
.ex.is-done .exnum { background: var(--green); color: #fff; }
.exhead { flex: 1; min-width: 0; }
.exhead h2 { font-size: 20px; margin: 2px 0 4px; line-height: 1.3; }
.meta { display: flex; gap: 6px; flex-wrap: wrap; }
.lec, .kind {
  font-size: 12px; padding: 2px 8px; border-radius: 99px;
  background: var(--panel); color: var(--muted); border: 1px solid var(--line);
}
.kind { color: var(--magenta); border-color: #f0c9d8; background: #fdf2f6; }
.done-badge { display: none; font-size: 13px; color: var(--green); font-weight: 600; white-space: nowrap; }
.ex.is-done .done-badge { display: inline; }

.intro { overflow-x: auto; }
.intro .katex-display, .solution .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.rules { padding-left: 22px; margin: 6px 0; }
.rules li { margin: 2px 0; }

.part { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 14px; }
.part h3 { font-size: 16px; margin: 0 0 6px; color: var(--purple); }
/* optional parts: not needed to count the exercise as solved */
.part.optional { background: var(--panel); border: 1px dashed var(--line); border-radius: 10px; padding: 12px 14px; }
.opt-badge {
  display: inline-block; vertical-align: 2px; margin-left: 8px;
  font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px;
  color: var(--muted); background: #fff; border: 1px solid var(--line);
}
.opt-note { color: var(--muted); font-size: 14px; margin: 0 0 8px; }
.prompt p { margin: 4px 0 10px; }

.scroll { overflow-x: auto; padding-bottom: 4px; }

/* inputs */
input.num {
  width: 4.2em; padding: 6px 6px; text-align: center;
  font: inherit; font-variant-numeric: tabular-nums;
  border: 1px solid #c9ccd3; border-radius: 6px; background: #fff;
}
input.num:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
input.num.right { border-color: var(--green); background: var(--green-soft); }
input.num.wrong { border-color: var(--red); background: var(--red-soft); }

/* matrix entry grid */
.mgrid { border-collapse: separate; border-spacing: 4px 6px; margin: 4px 0; }
.mgrid th { font-weight: normal; color: var(--muted); padding: 0 2px; }
.mgrid th.rowlab { font-size: 12px; text-align: right; padding-right: 6px; white-space: nowrap; }
.mgrid td { padding: 0 2px; }
/* brackets and the augmentation bar are thin columns of their own (no borders on the input cells) */
.mgrid td.brk, .mgrid td.vbar, .mgrid th.gap { width: 2px; min-width: 2px; padding: 0; }
.mgrid td.brk, .mgrid td.vbar { background: var(--ink); }

/* options */
.opts { display: grid; gap: 8px; margin: 6px 0; }
.opt {
  display: flex; gap: 10px; align-items: center;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; cursor: pointer; overflow-x: auto;
}
.opt:hover { border-color: #b7c4d4; }
.opt input { flex: 0 0 auto; }
.opt.right { border-color: var(--green); background: var(--green-soft); }
.opt.wrong { border-color: var(--red); background: var(--red-soft); }

/* classification */
.classify { display: grid; gap: 10px; }
.citem {
  display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 12px;
}
.citem.right { border-color: var(--green); background: var(--green-soft); }
.citem.wrong { border-color: var(--red); background: var(--red-soft); }
.clabel { color: var(--muted); }
.cmath { overflow-x: auto; }
.cmath .katex-display { margin: 6px 0; }
@media (max-width: 640px) {
  .citem { grid-template-columns: 22px minmax(0, 1fr); }
  .citem .seg { grid-column: 1 / -1; }
}

.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: inline-block; padding: 6px 12px; border-radius: 99px;
  border: 1px solid #c9ccd3; font-size: 14px; background: #fff; white-space: nowrap;
}
.seg input:checked + span { background: var(--blue); border-color: var(--blue); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }

/* chips for leading variables */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.chip {
  min-width: 52px; padding: 6px 12px; border-radius: 99px; cursor: pointer;
  border: 1px solid #c9ccd3; background: #fff; font: inherit;
}
.chip[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: #fff; }
.chip.wrong { box-shadow: 0 0 0 2px var(--red); }

/* fields */
.fields { display: flex; gap: 10px 22px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.field { display: inline-flex; gap: 8px; align-items: center; }
/* a coordinate tuple "( _ , _ , _ )" stays on one line */
.field.tuple { gap: 6px; white-space: nowrap; }
.ptable { border-collapse: separate; border-spacing: 4px 6px; }
.ptable th { font-weight: normal; text-align: right; padding-right: 4px; white-space: nowrap; }
.ptable td.op { color: var(--muted); }

/* buttons and feedback */
.actions { margin: 10px 0 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  font: inherit; font-size: 14px; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid #c9ccd3; background: #fff; color: var(--ink);
}
.btn:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #127bbb; color: #fff; }
.btn.ghost { background: var(--panel); }
.btn.small { font-size: 13px; padding: 3px 10px; margin-left: 4px; }

.fb:empty { display: none; }
.fb { margin-top: 8px; padding: 10px 14px; border-radius: var(--radius); border-left: 4px solid; overflow-x: auto; }
.fb.ok { background: var(--green-soft); border-color: var(--green); }
.fb.bad { background: var(--red-soft); border-color: var(--red); }
.fb.hint { background: var(--orange-soft); border-color: var(--orange); }
.fb ul { margin: 6px 0 0; padding-left: 20px; }

.tools { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.hints .hint { margin-top: 8px; padding: 10px 14px; border-radius: var(--radius); background: var(--orange-soft); border-left: 4px solid var(--orange); overflow-x: auto; }
.solution { margin-top: 12px; padding: 14px 16px; border-radius: var(--radius); background: var(--panel); overflow-x: auto; }
.solution h3 { margin: 0 0 6px; font-size: 16px; }
.solution h4 { margin: 10px 0 4px; font-size: 15px; color: var(--purple); }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* workbench */
.wb-current {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border-radius: var(--radius); padding: 4px 16px; margin: 6px 0 10px;
}
.wb-mat { overflow-x: auto; font-size: 1.15em; min-width: 0; }
.wb-status { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); background: #fff; }
.badge.on { border-color: var(--green); color: var(--green); background: var(--green-soft); }
.badge.warn { border-color: var(--red); color: var(--red); background: var(--red-soft); }
.wb-ops { display: grid; gap: 8px; }
.wb-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.wb-row select { font: inherit; font-size: 14px; padding: 6px 8px; border-radius: 6px; border: 1px solid #c9ccd3; background: #fff; }
.formula { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.formula input.fac { width: 4.6em; }
.steps { margin-top: 10px; }
.steps summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 2px; padding: 6px 0; overflow-x: auto; }
.cstep { display: inline-flex; align-items: center; gap: 2px; }
.sim { display: inline-flex; flex-direction: column; align-items: center; margin: 0 4px; font-size: 13px; color: var(--green); }
.sim .tilde { font-size: 22px; line-height: 1; color: var(--ink); }
.oplab { white-space: nowrap; }
.wb-answer { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.wb-answer h4 { margin: 0 0 2px; font-size: 15px; }
.wb-answer .seg { margin: 6px 0 8px; }

/* graph */
.graph { margin-top: 10px; max-width: 420px; }
.graph svg { width: 100%; height: auto; display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.graph .g { stroke: #eceef2; stroke-width: 1; }
.graph .ax { stroke: #8a8f98; stroke-width: 1.2; }
.graph .curve { fill: none; stroke: var(--blue); stroke-width: 2.4; }
.graph .pt { fill: var(--magenta); }
.graph .pt.hit { fill: var(--green); }
.graph text { font-size: 11px; fill: var(--muted); }

footer { color: var(--muted); font-size: 13px; padding: 20px 0 40px; border-top: 1px solid var(--line); }

/* coordinate plane widget */
.plane { max-width: 440px; margin-top: 6px; }
.plane svg { width: 100%; height: auto; display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); cursor: crosshair; }
.plane .g { stroke: #eceef2; stroke-width: 1; }
.plane .ax { stroke: #8a8f98; stroke-width: 1.2; }
.plane .tick { font-size: 10px; fill: var(--muted); }
.plane .hit { fill: transparent; }
.plane .given-pt { fill: var(--ink); }
.plane { position: relative; }
.plane .plab { position: absolute; transform: translateY(-100%); pointer-events: none; font-size: 15px; line-height: 1; white-space: nowrap; color: var(--ink); }
.plane .plab.mlab { color: var(--blue); font-weight: 600; }
.plane .plab.mlab.act { color: var(--magenta); }
.plane .gline { stroke: var(--purple); stroke-width: 2; }
.plane line.given { stroke: var(--purple); stroke-width: 2.2; }
.plane .ah-given { fill: var(--purple); }
.plane line.mine { stroke: var(--blue); stroke-width: 2.4; }
.plane .ah-mine { fill: var(--blue); }
.plane .tail { fill: var(--blue); }
.plane .mpt { fill: var(--blue); }
.plane .mpt.act { fill: var(--magenta); }
.plane .mlab { font-size: 12px; fill: var(--blue); font-weight: 600; }
.readout { min-height: 1.4em; margin-top: 4px; }

/* site banner with the course name, and the back link to the index */
.site-head { background: #13314a; color: #fff; }
.site-head-inner { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding-top: 18px; padding-bottom: 18px; }
.brand { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-size: clamp(24px, 3.6vw, 32px); font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; }
.brand-sub { font-size: 14px; opacity: .8; margin-top: 2px; }
a.brand { color: inherit; text-decoration: none; }
/* the current section, shown under the course name on section pages */
.brand-section {
  margin-top: 6px; font-size: 15px; color: #9fd3f5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-section b { color: #fff; font-weight: 600; }
.backlink {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 8px 16px; border-radius: 99px; font-weight: 600; font-size: 15px;
  background: #fff; color: #13314a; text-decoration: none; border: 2px solid #fff;
}
.backlink:hover { background: transparent; color: #fff; }
.section-label { color: var(--blue); font-weight: 600; font-size: 15px; margin: 0; letter-spacing: .02em; }
.top { padding-top: 28px; }

/* section list on the index */
.sections .meta-right { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; min-width: 120px; }
.sections .count { font-size: 14px; color: var(--muted); white-space: nowrap; }
.sections .count.all { color: var(--green); font-weight: 600; }
.sections .mini { width: 110px; height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.sections .mini span { display: block; height: 100%; background: var(--green); }
@media (max-width: 560px) {
  .sections a { flex-wrap: wrap; }
  .sections .meta-right { margin-left: 0; align-items: flex-start; width: 100%; }
}

/* keep the banner (course name + back link) on screen; the progress bar sticks just below it.
   --head-h is set by engine.js to the banner's current height. */
.site-head { position: sticky; top: 0; z-index: 20; }
.bar { top: var(--head-h, 0px); }
html { scroll-padding-top: calc(var(--head-h, 0px) + 72px); }
@media (max-width: 640px) {
  .site-head-inner { padding-top: 10px; padding-bottom: 10px; gap: 12px; }
  .brand-name { font-size: 20px; }
  .brand-sub { display: none; }
  .brand-section { margin-top: 2px; font-size: 13px; }
  .backlink { padding: 6px 12px; font-size: 14px; }
}

/* narrow screens: one compact line with a horizontally scrolling row of exercise numbers */
#progresscount b { font-weight: inherit; }
.foot-reset { display: none; }
@media (max-width: 640px) {
  .bar .wrap { flex-wrap: nowrap; gap: 10px; padding-top: 6px; padding-bottom: 6px; }
  .bar .progress { display: none; }
  #progresscount { min-width: 0; white-space: nowrap; font-size: 13px; }
  #progresscount .solved-word { display: none; }
  #exnav {
    flex-wrap: nowrap; overflow-x: auto; gap: 5px; padding: 2px 0; min-width: 0;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(to right, #000 85%, transparent);
    -webkit-mask-image: linear-gradient(to right, #000 85%, transparent);
  }
  #exnav::-webkit-scrollbar { display: none; }
  .navchip { flex: 0 0 auto; width: 28px; height: 28px; font-size: 12px; }
  #resetprogress { display: none; }
  .foot-reset { display: inline; }
  html { scroll-padding-top: calc(var(--head-h, 0px) + 52px); }
}

/* grid items default to min-width: auto, which lets a wide formula widen the whole card;
   allow cards to shrink so wide content scrolls inside them instead */
#exercises > .ex { min-width: 0; }
.ex .part, .ex .intro, .ex .solution, .ex .hints { min-width: 0; max-width: 100%; }

/* restore the 16px side gutters that the shorthand paddings above reset to 0 */
.top { padding-left: 16px; padding-right: 16px; }
#exercises { padding-left: 16px; padding-right: 16px; }
footer.wrap { padding-left: 16px; padding-right: 16px; }

/* inline formulas are never split over two lines, and punctuation after a formula stays with it */
.katex { white-space: nowrap; }
.nobr { white-space: nowrap; }
/* on narrow screens a long one-line computation scrolls sideways within its paragraph instead of
   breaking or running out of the card */
.solution p, .solution li, .fb, .prompt p, .hint, .opt > span, .intro p { overflow-x: auto; overflow-y: hidden; }

/* progress panel on the index pages (assets/progress.js) */
.progress-panel { margin: 8px 0 60px; padding: 20px 22px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.progress-panel h2 { margin: 0 0 8px; font-size: 20px; }
.progress-panel h3 { margin: 0 0 6px; font-size: 16px; }
.progress-panel ul { margin: 4px 0 10px; padding-left: 20px; }
.pp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-top: 14px; }
.pp-box { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px; min-width: 0; }
.pp-box textarea { width: 100%; margin-top: 8px; font: 12px/1.4 ui-monospace, Menlo, monospace; border: 1px solid #c9ccd3; border-radius: 6px; padding: 8px; resize: vertical; word-break: break-all; }
label.btn { display: inline-block; }
