/* =========================================================
   Maker Notebook — site styles
   Hand-made "kids' engineering notebook" look:
   graph paper, sticker cards, ink outlines, hard shadows.
   ========================================================= */

:root {
  --paper: #fbf5e6;
  --paper-2: #f3ead2;
  --grid: rgba(52, 84, 140, 0.11);
  --grid-strong: rgba(52, 84, 140, 0.2);
  --ink: #1f2a44;
  --ink-soft: #4a5572;
  --tomato: #e8553b;
  --tomato-soft: #fbd9d1;
  --mustard: #f2b632;
  --mustard-soft: #fcebc0;
  --pcb: #1f6b4f;
  --pcb-dark: #17543e;
  --copper: #d08a3c;
  --copper-lit: #ffcc66;
  --sky: #5b8fd6;
  --sky-soft: #d9e6f8;
  --mint: #4fb38a;
  --mint-soft: #d4efe2;
  --white: #fffdf7;

  --font-head: "Mali", "Sarabun", system-ui, sans-serif;
  --font-body: "Sarabun", system-ui, sans-serif;
  --font-code: "JetBrains Mono", ui-monospace, Consolas, monospace;

  --line: 2.5px;
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 2px 2px 0 var(--ink);
  --radius: 14px 18px 13px 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  overflow-x: hidden;
}

img, svg { max-width: 100%; }

a { color: inherit; }

h1, h2, h3, h4 {
  font-family: var(--font-head);
  line-height: 1.25;
  margin: 0 0 0.5em;
}
h1 { font-size: clamp(30px, 5vw, 52px); font-weight: 700; }
h2 { font-size: clamp(24px, 3.4vw, 34px); font-weight: 700; }
h3 { font-size: 21px; font-weight: 600; }

p { margin: 0 0 1em; }

/* ---------- language & level switching ---------- */
html[data-lang="th"] .en,
html[data-lang="en"] .th { display: none !important; }
html:not([data-level="secondary"]) .for-secondary { display: none !important; }

/* ---------- layout ---------- */
.wrap { width: min(1120px, 100% - 32px); margin-inline: auto; }
.section { padding: 48px 0; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--paper);
  border-bottom: var(--line) solid var(--ink);
}
.topbar .wrap {
  display: flex; align-items: center; gap: 12px;
  min-height: 64px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none;
  font-family: var(--font-head); font-weight: 700; font-size: 20px;
  line-height: 1.2;
}
.brand img { width: 34px; height: 50px; }
.brand small { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); line-height: 1.5; margin-top: 1px; }
.topnav { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.topnav a {
  font-family: var(--font-head); font-weight: 600; text-decoration: none;
  padding: 4px 10px; border-radius: 10px;
}
.topnav a:hover, .topnav a[aria-current="page"] { background: var(--mustard-soft); }

.toggle {
  display: inline-flex;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  background: var(--white);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.toggle button {
  font: 600 14px var(--font-head);
  border: 0; background: transparent; color: var(--ink);
  padding: 5px 12px; cursor: pointer;
}
.toggle button[aria-pressed="true"] { background: var(--ink); color: var(--white); }

@media (max-width: 640px) {
  .topnav a.navlink { display: none; }
  .brand { font-size: 17px; white-space: nowrap; gap: 8px; }
  .brand img { width: 28px; height: 42px; }
}

/* ---------- sticker card ---------- */
.card {
  position: relative;
  background: var(--white);
  border: var(--line) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card.tape::before {
  /* a strip of masking tape holding the card */
  content: "";
  position: absolute; top: -13px; left: 50%;
  width: 92px; height: 24px;
  transform: translateX(-50%) rotate(-3deg);
  background: rgba(242, 182, 50, 0.55);
  border-left: 2px dashed rgba(255, 255, 255, 0.6);
  border-right: 2px dashed rgba(255, 255, 255, 0.6);
}
.card.tape.tape-left::before { left: 18%; transform: translateX(-50%) rotate(4deg); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 700 17px var(--font-head);
  color: var(--ink); text-decoration: none;
  background: var(--mustard);
  border: var(--line) solid var(--ink);
  border-radius: 12px 14px 12px 15px;
  box-shadow: var(--shadow);
  padding: 10px 20px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
  min-height: 44px;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn.red { background: var(--tomato); color: var(--white); }
.btn.green { background: var(--mint); }
.btn.white { background: var(--white); }
.btn.small { font-size: 15px; padding: 6px 12px; min-height: 38px; box-shadow: var(--shadow-sm); }
.btn.small:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }

/* marker highlight */
.mark {
  background: linear-gradient(transparent 58%, var(--mustard) 58%, var(--mustard) 90%, transparent 90%);
  padding: 0 4px;
}
.mark.red { background: linear-gradient(transparent 58%, var(--tomato-soft) 58%, var(--tomato-soft) 90%, transparent 90%); }

/* chip / tag */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font: 600 13px var(--font-head);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 1px 10px;
  background: var(--white);
}
.chip.chip-green { background: var(--mint-soft); }
.chip.chip-blue { background: var(--sky-soft); }
.chip.soon { background: var(--paper-2); color: var(--ink-soft); border-style: dashed; }

/* rubber stamp */
.stamp {
  display: inline-block;
  font: 700 22px var(--font-head);
  color: var(--tomato);
  border: 3px double var(--tomato);
  border-radius: 8px;
  padding: 2px 14px;
  transform: rotate(-8deg);
  opacity: 0.92;
  letter-spacing: 1px;
}
.stamp.pop { animation: stamp-in 0.35s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes stamp-in {
  from { transform: rotate(-8deg) scale(2.2); opacity: 0; }
  to { transform: rotate(-8deg) scale(1); opacity: 0.92; }
}

/* ---------- mascot speech ---------- */
.ping-says {
  display: flex; align-items: flex-start; gap: 12px;
}
.ping-says img { width: 46px; flex: none; }
.bubble {
  position: relative;
  background: var(--white);
  border: var(--line) solid var(--ink);
  border-radius: 16px 18px 16px 6px;
  padding: 10px 14px;
  font-family: var(--font-head);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}
.bubble.good { background: var(--mint-soft); }
.bubble.warn { background: var(--mustard-soft); }
.bubble.bad { background: var(--tomato-soft); }

/* ---------- footer ---------- */
.footer {
  border-top: var(--line) solid var(--ink);
  background: var(--paper-2);
  padding: 28px 0 36px;
  font-size: 14px;
  color: var(--ink-soft);
}
.footer a { color: var(--ink); }

/* =========================================================
   HOME
   ========================================================= */
.hero { padding: 40px 0 24px; }
.hero-grid {
  display: grid; grid-template-columns: 1.3fr 1fr; gap: 32px; align-items: center;
}
.hero h1 .scribble { position: relative; white-space: nowrap; }
.hero h1 .scribble svg {
  position: absolute; left: -4%; bottom: -12px; width: 108%; height: 18px; overflow: visible;
}
.hero .lead { font-size: 19px; max-width: 34em; }
.hero-art { position: relative; display: flex; justify-content: center; }
.hero-art .mascot-big {
  width: min(230px, 60vw); cursor: pointer;
  filter: drop-shadow(5px 6px 0 rgba(31, 42, 68, 0.18));
  transition: transform 0.2s;
}
.hero-art .mascot-big:hover { transform: rotate(-4deg); }
.hero-art .note {
  position: absolute; font: 600 15px var(--font-head); color: var(--ink-soft);
}
.hero-art .note.n1 { left: 0; top: 20%; transform: rotate(-6deg); }
.hero-art .note.n2 { right: 0; bottom: 18%; transform: rotate(5deg); }
.hero-art .note svg { display: block; }

@media (max-width: 820px) {
  .hero-grid { grid-template-columns: 1fr; }
  .hero-art { order: -1; }
  .hero-art .mascot-big { width: min(170px, 42vw); }
  .hero-art .note { display: none; }
}

.boards { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
@media (max-width: 820px) { .boards { grid-template-columns: 1fr; } }

.board-card { display: flex; flex-direction: column; gap: 14px; padding: 0; overflow: hidden; }
.board-card .art {
  height: 220px; display: grid; place-items: center;
  border-bottom: var(--line) solid var(--ink);
  border-radius: 12px 16px 0 0;
  position: relative; overflow: hidden;
}
.board-card.arduino .art {
  background-color: var(--pcb);
  background-image: radial-gradient(rgba(255,255,255,0.12) 1.2px, transparent 1.4px);
  background-size: 14px 14px;
}
.board-card.microbit .art {
  background-color: #2b3a67;
  background-image: radial-gradient(rgba(255, 90, 80, 0.35) 2.2px, transparent 2.6px);
  background-size: 18px 18px;
}
.board-card .body { padding: 0 22px 22px; display: flex; flex-direction: column; gap: 10px; }
.board-card .meta { display: flex; gap: 8px; flex-wrap: wrap; }
.led-progress { display: flex; gap: 6px; align-items: center; }
.led-progress i {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--ink); background: #e4dccb;
}
.led-progress i.on { background: var(--mustard); box-shadow: 0 0 0 3px rgba(242, 182, 50, 0.35); }
.led-progress span { font: 600 14px var(--font-head); margin-left: 6px; color: var(--ink-soft); }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; counter-reset: step; }
@media (max-width: 820px) { .steps { grid-template-columns: 1fr; } }
.steps .card { padding-top: 30px; }
.steps .num {
  position: absolute; top: -20px; left: 18px;
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  font: 700 22px var(--font-head);
  background: var(--tomato); color: var(--white);
  border: var(--line) solid var(--ink);
}
.steps .card:nth-child(2) .num { background: var(--mustard); color: var(--ink); }
.steps .card:nth-child(3) .num { background: var(--mint); color: var(--ink); }

/* teacher card */
.teacher {
  display: grid; grid-template-columns: 270px 1fr; gap: 44px; align-items: center;
  padding: 36px 40px;
}
.polaroid {
  position: relative; margin: 0;
  background: #fff;
  padding: 12px 12px 46px;
  border: 2px solid var(--ink);
  box-shadow: var(--shadow);
  transform: rotate(-3deg);
}
.polaroid::before {
  content: ""; position: absolute; top: -14px; left: 50%;
  width: 96px; height: 26px; transform: translateX(-50%) rotate(4deg);
  background: rgba(242, 182, 50, 0.6);
  border-left: 2px dashed rgba(255, 255, 255, 0.6);
  border-right: 2px dashed rgba(255, 255, 255, 0.6);
}
.polaroid img { display: block; width: 100%; height: auto; border: 1.5px solid rgba(31, 42, 68, 0.2); }
.polaroid figcaption {
  position: absolute; left: 0; right: 0; bottom: 10px;
  text-align: center; font: 600 19px var(--font-head);
}
.teacher-txt h2 { margin: 12px 0 2px; font-size: clamp(28px, 4vw, 40px); }
.teacher-txt .role { font: 600 18px var(--font-head); color: var(--ink-soft); margin-bottom: 20px; }
.made-by { font: 600 15px var(--font-head); color: var(--ink); margin-bottom: 6px !important; }
@media (max-width: 760px) {
  .teacher { grid-template-columns: 1fr; gap: 28px; padding: 30px 20px; text-align: center; }
  .polaroid { width: min(250px, 80%); margin: 0 auto; }
  .teacher-txt .ping-says { text-align: left; }
}

/* =========================================================
   LESSON MAP (PCB)
   ========================================================= */
.track-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding: 32px 0 20px;
}
.pcb {
  position: relative;
  border: var(--line) solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 44px 34px 40px 46px;
  background-color: var(--pcb);
  background-image: radial-gradient(rgba(255,255,255,0.09) 1.2px, transparent 1.5px);
  background-size: 16px 16px;
  margin-bottom: 48px;
}
.pcb.mb {
  background-color: #2b3a67;
  background-image: radial-gradient(rgba(255,255,255,0.1) 1.2px, transparent 1.5px);
}
.pcb .silk {
  position: absolute; color: rgba(255,255,255,0.75);
  font: 600 12px var(--font-code); letter-spacing: 1.5px;
}
.pcb .silk.tl { top: 12px; left: 46px; }
.pcb .silk.br { bottom: 12px; right: 30px; }
.pcb .hole {
  position: absolute; width: 16px; height: 16px; border-radius: 50%;
  background: var(--paper); border: 3px solid #c9a35a;
}
.pcb .hole.h1 { top: 12px; left: 12px; }
.pcb .hole.h2 { top: 12px; right: 12px; }
.pcb .hole.h3 { bottom: 12px; left: 12px; }
.pcb .hole.h4 { bottom: 12px; right: 12px; }

.map-grid {
  position: relative; z-index: 1;
  display: grid; gap: 30px 36px;
}
.traces {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 0; overflow: visible;
}
.traces path { fill: none; stroke: var(--copper); stroke-width: 6; stroke-linejoin: round; stroke-linecap: round; opacity: 0.85; }
.traces path.lit { stroke: var(--copper-lit); filter: drop-shadow(0 0 4px rgba(255, 204, 102, 0.9)); opacity: 1; }

.lesson-card {
  position: relative;
  display: flex; align-items: center; gap: 14px;
  margin-left: 18px;
  min-height: 104px;
  padding: 14px 16px 14px 34px;
  background: var(--white);
  border: var(--line) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none; color: var(--ink);
  transition: transform 0.12s, box-shadow 0.12s;
}
a.lesson-card:hover { transform: translate(-2px, -2px) rotate(-0.6deg); box-shadow: 6px 6px 0 var(--ink); }
.lesson-card.soon { background: #ece6d6; box-shadow: var(--shadow-sm); }
.lesson-card.soon .thumb, .lesson-card.soon .txt { opacity: 0.6; }
.lesson-card .pad {
  position: absolute; left: -20px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  font: 700 15px var(--font-code);
  background: #e9c47a; color: var(--ink);
  border: var(--line) solid var(--ink);
}
.lesson-card.done .pad { background: var(--copper-lit); box-shadow: 0 0 0 4px rgba(255, 204, 102, 0.45), 0 0 16px rgba(255, 204, 102, 0.9); }
.lesson-card.current .pad { background: var(--tomato); color: var(--white); animation: pulse 1.6s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232, 85, 59, 0.55); }
  50% { box-shadow: 0 0 0 8px rgba(232, 85, 59, 0); }
}
.lesson-card .thumb {
  flex: none; width: 72px; height: 64px;
  position: relative; overflow: hidden;
  display: grid; place-items: center;
}
.lesson-card .thumb > * { position: absolute; left: 50%; top: 50%; transform-origin: center; }
.lesson-card .thumb > svg { transform: translate(-50%, -50%); }
@media (max-width: 560px) {
  .pcb { padding: 40px 14px 36px 28px; }
  .lesson-card { padding: 12px 12px 12px 30px; gap: 10px; min-height: 92px; }
  .lesson-card .thumb { width: 54px; height: 54px; }
  .lesson-card .thumb > svg { width: 48px; height: 48px; }
}
.lesson-card .txt { flex: 1; min-width: 0; }
.lesson-card .txt b { display: block; font: 700 17px var(--font-head); line-height: 1.3; }
.lesson-card .txt span { display: block; font-size: 14px; color: var(--ink-soft); line-height: 1.4; }
.lesson-card .state {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  border: var(--line) solid var(--ink);
  background: var(--white);
}
.lesson-card.done .state { background: var(--mint); }
.lesson-card.current .state { background: var(--tomato); }
.lesson-card .state svg { width: 16px; height: 16px; }
.lesson-card .soon-tag {
  position: absolute; right: 12px; top: -12px;
}

/* =========================================================
   LESSON PAGE
   ========================================================= */
.crumbs { font: 500 14px var(--font-head); color: var(--ink-soft); padding-top: 22px; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

.lesson-head {
  display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center;
  padding: 14px 0 26px;
}
.lesson-head .bignum {
  width: 84px; height: 84px; border-radius: 50%;
  display: grid; place-items: center;
  font: 700 34px var(--font-code);
  background: #e9c47a;
  border: 3px solid var(--ink);
  box-shadow: var(--shadow);
}
.lesson-head.mb .bignum { background: var(--sky-soft); }
.lesson-head h1 { margin: 0; font-size: clamp(28px, 4.4vw, 44px); }
.lesson-head .sub { color: var(--ink-soft); font-size: 18px; margin: 0; }
.level-box { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font: 600 13px var(--font-head); }
@media (max-width: 760px) {
  .lesson-head { grid-template-columns: auto 1fr; }
  .lesson-head .bignum { width: 64px; height: 64px; font-size: 26px; }
  .level-box { grid-column: 1 / -1; align-items: flex-start; }
}

.lesson-nav {
  position: sticky; top: 66px; z-index: 40;
  display: flex; gap: 8px; overflow-x: auto;
  padding: 10px 0; margin-bottom: 8px;
  background: var(--paper);
  scrollbar-width: thin;
}
.lesson-nav a {
  flex: none;
  font: 600 14px var(--font-head); text-decoration: none;
  border: 2px solid var(--ink); border-radius: 10px;
  padding: 3px 12px; background: var(--white);
}
.lesson-nav a:hover { background: var(--mustard-soft); }

.block { margin: 34px 0 46px; scroll-margin-top: 130px; }
.block-title { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.block-title .tab {
  flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  font: 700 18px var(--font-head);
  border: var(--line) solid var(--ink);
  background: var(--mustard);
}
.block-title h2 { margin: 0; font-size: clamp(22px, 3vw, 28px); }

.goals { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.goals li { display: flex; gap: 10px; align-items: flex-start; }
.goals li::before {
  content: ""; flex: none; margin-top: 6px;
  width: 16px; height: 16px; border: 2.5px solid var(--ink); border-radius: 4px;
  background: var(--mustard-soft);
  transform: rotate(-4deg);
}

.parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
.part {
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.part .pic { height: 78px; position: relative; overflow: hidden; display: grid; place-items: center; }
.part .pic > * { position: absolute; left: 50%; top: 50%; transform-origin: center; }
.part b { display: block; font: 600 15px var(--font-head); margin-top: 6px; }
.part small { color: var(--ink-soft); }

/* side note for secondary level */
.deep {
  border: 2px dashed var(--sky);
  background: var(--sky-soft);
  border-radius: 12px;
  padding: 14px 18px;
  margin-top: 18px;
}
.deep .chip { background: var(--white); margin-bottom: 6px; }

/* code */
.code-card { padding: 0; overflow: hidden; }
.code-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-bottom: var(--line) solid var(--ink);
  background: var(--paper-2);
  font: 600 14px var(--font-head);
}
.code-bar .dots { display: flex; gap: 5px; margin-right: 4px; }
.code-bar .dots i { width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--ink); }
.code-bar .dots i:nth-child(1) { background: var(--tomato); }
.code-bar .dots i:nth-child(2) { background: var(--mustard); }
.code-bar .dots i:nth-child(3) { background: var(--mint); }
.code-bar .btn { margin-left: auto; }
pre.code {
  margin: 0; padding: 18px 20px;
  overflow-x: auto;
  font: 500 15px/1.7 var(--font-code);
  background: #1f2a44; color: #f4efe2;
  tab-size: 2;
}
pre.code .k { color: #ffb86b; }
pre.code .f { color: #8fd3ff; }
pre.code .n { color: #ffd479; }
pre.code .s { color: #b6e3a3; }
pre.code .c { color: #9aa6c4; font-style: italic; }

.explain { display: grid; gap: 12px; margin-top: 18px; }
.explain .row { display: grid; grid-template-columns: minmax(0, 260px) 1fr; gap: 14px; align-items: start; }
.explain code {
  font: 500 14px var(--font-code);
  background: var(--white); border: 2px solid var(--ink); border-radius: 8px;
  padding: 4px 8px; display: inline-block; white-space: pre-wrap; word-break: break-word;
}
@media (max-width: 640px) { .explain .row { grid-template-columns: 1fr; gap: 4px; } }

/* quiz */
.quiz { display: grid; gap: 22px; }
.q-title { font: 600 18px var(--font-head); margin-bottom: 10px; }
.choices { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.choice {
  text-align: left;
  font: 500 16px var(--font-body);
  color: var(--ink);
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  min-height: 46px;
}
.choice:hover { background: var(--mustard-soft); }
.choice.right { background: var(--mint-soft); border-color: var(--pcb); }
.choice.wrong { background: var(--tomato-soft); animation: shake 0.35s; }
@keyframes shake {
  25% { transform: translateX(-5px); } 75% { transform: translateX(5px); }
}
.q-feedback { min-height: 1.6em; margin: 8px 0 0; font: 600 15px var(--font-head); }
.q-feedback.ok { color: var(--pcb); }
.q-feedback.no { color: var(--tomato); }
.quiz-score { font: 700 18px var(--font-head); }

.finish {
  display: flex; flex-wrap: wrap; align-items: center; gap: 18px;
  padding: 24px; margin: 30px 0 60px;
}
.finish .stamp-slot { min-width: 120px; }

/* worksheet: only when printing */
.print-only { display: none; }

@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 13pt; }
  .no-print, .topbar, .lesson-nav, .footer, .lab, .finish, .quiz, .crumbs .no-print { display: none !important; }
  .print-only { display: block !important; }
  .card { box-shadow: none; }
  .block { margin: 14px 0; page-break-inside: avoid; }
  .ws-head { display: flex; gap: 24px; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 14px; }
  .ws-head span { flex: 1; border-bottom: 1px dotted #000; }
  .ws-q { margin-bottom: 14px; page-break-inside: avoid; }
  .ws-q ol { list-style: none; padding-left: 6mm; margin: 4px 0 0; }
  .ws-q li::before { content: "○  "; }
  .ws-draw { border: 2px dashed #000; height: 70mm; border-radius: 6px; padding: 6px; }
  pre.code { background: #fff; color: #000; border: 1px solid #000; }
  pre.code * { color: #000 !important; }
}

/* =========================================================
   ARDUINO WIRING LAB
   ========================================================= */
.lab { padding: 0; overflow: hidden; scroll-margin-top: 130px; }
.lab-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-bottom: var(--line) solid var(--ink);
  background: var(--paper-2);
}
.lab-toolbar .sep { width: 2px; align-self: stretch; background: rgba(31,42,68,0.2); margin: 0 4px; }
.swatches { display: flex; gap: 5px; align-items: center; font: 600 13px var(--font-head); }
.swatch {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--ink); cursor: pointer; padding: 0;
}
.swatch[aria-pressed="true"] { outline: 3px solid var(--ink); outline-offset: 2px; }
.swatch.auto {
  background: conic-gradient(#e8553b 0 25%, #222 0 50%, #f2b632 0 75%, #3f8fd6 0);
}
.lab-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; }
@media (max-width: 980px) { .lab-body { grid-template-columns: minmax(0, 1fr); } }
.stage-wrap {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(rgba(31,42,68,0.05) 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(90deg, rgba(31,42,68,0.05) 1px, transparent 1px) 0 0 / 20px 20px,
    #fffaf0;
}
.stage { position: relative; transform-origin: 0 0; }
.stage > .abs { position: absolute; }
.stage svg.overlay { position: absolute; left: 0; top: 0; overflow: visible; touch-action: none; }
.stage svg.overlay .wire { fill: none; stroke-linecap: round; cursor: pointer; }
.stage svg.overlay .wire-hit { fill: none; stroke: transparent; stroke-width: 12; cursor: pointer; pointer-events: stroke; }
.stage svg.overlay .wire-hit:hover + .wire, .stage svg.overlay .wire.hover { filter: drop-shadow(0 0 3px rgba(232,85,59,0.9)); }
.stage .tip {
  position: absolute; z-index: 5; pointer-events: none;
  font: 600 11px var(--font-head);
  background: var(--ink); color: var(--white);
  padding: 1px 7px; border-radius: 6px;
  white-space: nowrap; transform: translate(-50%, -150%);
}
.lab-side {
  border-left: var(--line) solid var(--ink);
  padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
  background: var(--white);
}
@media (max-width: 980px) { .lab-side { border-left: 0; border-top: var(--line) solid var(--ink); } }
.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; line-height: 1.45; }
.checklist li i {
  flex: none; width: 22px; height: 22px; margin-top: 1px;
  border: 2.5px solid var(--ink); border-radius: 6px; background: var(--white);
  display: grid; place-items: center;
}
.checklist li.ok i { background: var(--mint); }
.checklist li.ok i::after { content: ""; width: 10px; height: 6px; border-left: 3px solid var(--ink); border-bottom: 3px solid var(--ink); transform: rotate(-45deg) translate(1px, -1px); }
.checklist li.ok span { text-decoration: line-through; text-decoration-thickness: 2px; color: var(--ink-soft); }
/* sliders in the lab side panel (distance, light...) */
.lab-controls { display: grid; gap: 10px; border-top: 2px dashed rgba(31,42,68,0.2); padding-top: 12px; }
.lab-controls .ctrl { display: grid; gap: 4px; font: 600 14px var(--font-head); }
.lab-controls input[type="range"] { width: 100%; accent-color: var(--tomato); }
.stage .dark-tint { background: #0b1020; pointer-events: none; transition: opacity 0.2s; }

/* micro:bit lab (Blockly) */
.mb-lab { padding: 0; overflow: hidden; scroll-margin-top: 130px; }
.toggle button[aria-selected="true"] { background: var(--ink); color: var(--white); }
.mb-lab-body { display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
@media (max-width: 980px) { .mb-lab-body { grid-template-columns: minmax(0, 1fr); } }
.mb-code { position: relative; min-width: 0; min-height: 540px; border-right: var(--line) solid var(--ink); background: #fffaf0; }
@media (max-width: 980px) { .mb-code { min-height: 430px; border-right: 0; border-bottom: var(--line) solid var(--ink); } }
/* the block area always fills the full height of the lab */
.blockly-host { position: absolute; inset: 0; }
.text-host { position: absolute; inset: 0; display: flex; flex-direction: column; background: #1f2a44; }
.text-host .CodeMirror, .text-host textarea {
  flex: 1; min-height: 0; height: auto; width: 100%; display: block;
  font: 500 15px/1.6 var(--font-code); background: #1f2a44; color: #f4efe2; border: 0;
}
.text-host .CodeMirror-gutters { background: #18213a; border-right: 2px solid #2c3a5e; }
.text-host .CodeMirror-linenumber { color: #6f7ea6; }
.text-host .CodeMirror-cursor { border-left: 2px solid var(--mustard); }
.text-host .cm-keyword, .text-host .cm-def { color: #ffb86b; }
.text-host .cm-number { color: #ffd479; }
.text-host .cm-string { color: #b6e3a3; }
.text-host .cm-comment { color: #9aa6c4; font-style: italic; }
.text-host .cm-variable, .text-host .cm-property, .text-host .cm-variable-2 { color: #8fd3ff; }
.text-note {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 8px 12px; font: 600 14px var(--font-head);
  background: var(--mustard-soft); border-bottom: 2px solid var(--ink);
}
.mb-side { padding: 16px; display: flex; flex-direction: column; gap: 14px; background: var(--white); min-width: 0; }
.mb-boards { display: grid; gap: 10px; justify-items: center; background: #eef2fa; border-radius: 12px; padding: 10px; }
.mb-boards.two { grid-template-columns: 1fr 1fr; }
.mb-one { width: 100%; text-align: center; }
.mb-name { font: 700 13px var(--font-head); margin-bottom: 4px; }
.mb-rot { transition: transform 0.25s; }
.mb-boards.compass { position: relative; overflow: hidden; padding-top: 26px; }
.mb-boards .north { position: absolute; top: 4px; left: 50%; transform: translateX(-50%); font: 700 14px var(--font-head); color: var(--tomato); }
.mb-rot svg { width: 100%; max-width: 300px; height: auto; touch-action: manipulation; }
.mb-rot.shake { animation: mbshake 0.45s; }
@keyframes mbshake { 20% { transform: translateX(-8px) rotate(-6deg); } 40% { transform: translateX(8px) rotate(6deg); } 60% { transform: translateX(-6px) rotate(-4deg); } 80% { transform: translateX(6px) rotate(3deg); } }
.mb-boards .btn-hit { cursor: pointer; }
.mb-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.mb-controls .ctrl { flex: 1 1 100%; display: grid; gap: 4px; font: 600 14px var(--font-head); }
.mb-controls input[type="range"] { width: 100%; accent-color: var(--tomato); }
.lab-tip { font-size: 14px; margin: 10px 4px 0; }
.blkchip {
  display: inline-block; font: 600 14px var(--font-head); color: #fff;
  background: #3f7fc4; border: 2px solid var(--ink); border-radius: 10px; padding: 3px 10px;
}
.back-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.back-cards .part b { margin: 0 0 4px; }
.back-cards .part small { display: block; line-height: 1.45; }
.part .pic > .mbart { transform: translate(-50%, -50%); }
.mbart svg { width: 96px; height: auto; display: block; }
.ws-grid { border-collapse: collapse; }
.ws-grid td { border: 2px solid #000; width: 14mm; height: 14mm; }
.tour-inner > svg { position: absolute; left: 0; top: 0; width: 300px; height: 236px; }

/* lesson 01 board tour */
.tour { padding: 0; overflow: hidden; }
.tour-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; }
@media (max-width: 980px) { .tour-body { grid-template-columns: minmax(0, 1fr); } }
.tour-stage { padding: 18px; background: #fffaf0; display: flex; justify-content: center; }
.tour-inner { position: relative; transform-origin: 0 0; }
.tour-inner wokwi-arduino-uno { position: absolute; left: 0; top: 0; }
.spot {
  position: absolute; padding: 0; cursor: pointer;
  background: rgba(242, 182, 50, 0.12);
  border: 1.2px dashed rgba(242, 182, 50, 0.9); border-radius: 4px;
}
.spot span {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 12px; height: 12px; border-radius: 50%;
  display: grid; place-items: center;
  font: 700 7px var(--font-code); color: var(--ink);
  background: var(--mustard); border: 1px solid var(--ink);
}
.spot:hover, .spot.picked { background: rgba(242, 182, 50, 0.4); border-style: solid; }
.tour.game .spot { background: transparent; border-color: transparent; }
.tour.game .spot span { display: none; }
.tour.game .spot:hover { background: rgba(255, 255, 255, 0.18); border-color: rgba(255,255,255,0.6); }
.spot.right { background: rgba(79, 179, 138, 0.6) !important; border-color: var(--pcb) !important; }
.spot.wrong { background: rgba(232, 85, 59, 0.5) !important; animation: shake 0.35s; }
.tour-side { border-left: var(--line) solid var(--ink); padding: 16px; display: flex; flex-direction: column; gap: 14px; background: var(--white); }
@media (max-width: 980px) { .tour-side { border-left: 0; border-top: var(--line) solid var(--ink); } }
.tour-info { min-height: 130px; }
.tour-info h3 { font-size: 20px; margin-bottom: 6px; }

.lesson-pager { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: -30px 0 60px; }

/* code box inside the lab */
.lab-code { border-top: var(--line) solid var(--ink); }
.lab-code .code-bar { flex-wrap: wrap; border-bottom: 0; }
.lab-code .code-bar .btn { margin-left: auto; }
.lab-code .code-bar .btn + .btn { margin-left: 0; }
.edit-note { font: 600 13px var(--font-head); color: var(--tomato); }
.lab-code textarea {
  width: 100%; min-height: 260px; display: block; resize: vertical;
  font: 500 15px/1.6 var(--font-code); background: #1f2a44; color: #f4efe2;
  border: 0; padding: 14px; tab-size: 2;
}
.lab-code .CodeMirror {
  height: auto; min-height: 250px;
  font: 500 15px/1.65 var(--font-code);
  background: #1f2a44; color: #f4efe2;
}
.lab-code .CodeMirror-scroll { min-height: 250px; }
.lab-code .CodeMirror-gutters { background: #18213a; border-right: 2px solid #2c3a5e; }
.lab-code .CodeMirror-linenumber { color: #6f7ea6; }
.lab-code .CodeMirror-cursor { border-left: 2px solid var(--mustard); }
.lab-code .CodeMirror-selected, .lab-code .CodeMirror-focused .CodeMirror-selected { background: rgba(91, 143, 214, 0.35); }
.lab-code .cm-keyword, .lab-code .cm-type, .lab-code .cm-variable-3 { color: #ffb86b; }
.lab-code .cm-number { color: #ffd479; }
.lab-code .cm-string { color: #b6e3a3; }
.lab-code .cm-comment { color: #9aa6c4; font-style: italic; }
.lab-code .cm-meta { color: #f29bd0; }
.lab-code .cm-variable, .lab-code .cm-def { color: #8fd3ff; }
.lab-code .cm-operator, .lab-code .cm-punctuation { color: #f4efe2; }
.lab-code .CodeMirror-matchingbracket { color: #fff !important; background: rgba(242, 182, 50, 0.35); }
.lab-code .cm-run-line { background: rgba(242, 182, 50, 0.28); box-shadow: inset 4px 0 0 var(--mustard); }
.lab-code .cm-err-line { background: rgba(232, 85, 59, 0.35); box-shadow: inset 4px 0 0 var(--tomato); }
.serial { border-top: 2px solid #2c3a5e; background: #111829; }
.serial-title { font: 600 12px var(--font-code); color: #8fd3ff; padding: 6px 14px 0; letter-spacing: 1px; }
.serial pre { margin: 0; padding: 6px 14px 12px; max-height: 140px; overflow: auto; font: 500 14px/1.5 var(--font-code); color: #b6e3a3; }

.lab-hint { font-size: 13px; color: var(--ink-soft); padding: 8px 12px; border-top: 2px dashed rgba(31,42,68,0.2); }

/* =========================================================
   MICRO:BIT PLAYGROUND
   ========================================================= */
.mb-play { padding: 0; overflow: hidden; }
.mb-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 900px) { .mb-body { grid-template-columns: minmax(0, 1fr); } }
.mb-blocks { padding: 18px; border-right: var(--line) solid var(--ink); display: flex; flex-direction: column; gap: 18px; background: #fffaf0; }
@media (max-width: 900px) { .mb-blocks { border-right: 0; border-bottom: var(--line) solid var(--ink); } }
.mb-board { padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 12px; background: #eef2fa; }
.mb-board svg { width: min(420px, 100%); height: auto; touch-action: manipulation; }
.mb-board .btn-hit { cursor: pointer; }
.mb-board .btn-hit:hover circle.cap { fill: #4a4f5c; }

/* hand-made code blocks */
.blk-event {
  position: relative;
  background: var(--mustard);
  border: var(--line) solid var(--ink);
  border-radius: 18px 18px 10px 10px;
  padding: 10px 12px 12px;
  box-shadow: var(--shadow-sm);
}
.blk-event.btn-a { background: #7cc6a5; }
.blk-event.btn-b { background: #8fb4e8; }
.blk-event > .label { font: 700 16px var(--font-head); display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.blk-cmd {
  position: relative;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-left: 14px;
  background: var(--tomato); color: var(--white);
  border: var(--line) solid var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
  font: 600 15px var(--font-head);
}
.blk-cmd::before {
  /* little notch, like a puzzle piece */
  content: ""; position: absolute; top: -9px; left: 18px;
  width: 22px; height: 8px;
  background: inherit;
  border: var(--line) solid var(--ink); border-bottom: 0;
  border-radius: 6px 6px 0 0;
}
.blk-cmd input[type="text"] {
  font: 600 16px var(--font-code);
  text-transform: uppercase;
  border: 2px solid var(--ink); border-radius: 999px;
  padding: 3px 12px; width: 11em; max-width: 100%;
  color: var(--ink); background: var(--white);
}
.icon-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.icon-pick button {
  width: 40px; height: 40px; padding: 4px;
  border: 2px solid var(--ink); border-radius: 8px;
  background: #2a2e38; cursor: pointer;
}
.icon-pick button[aria-pressed="true"] { outline: 3px solid var(--white); outline-offset: 1px; box-shadow: 0 0 0 5px var(--ink); }
.icon-pick button svg { width: 100%; height: 100%; display: block; }

.code-tabs { display: flex; gap: 6px; }
.code-tabs button {
  font: 600 14px var(--font-head);
  border: 2px solid var(--ink); border-radius: 8px 8px 0 0; border-bottom: 0;
  background: var(--paper-2); padding: 4px 12px; cursor: pointer; color: var(--ink);
}
.code-tabs button[aria-selected="true"] { background: #1f2a44; color: var(--white); }
.warn-text { font: 600 14px var(--font-head); color: var(--tomato); min-height: 1.4em; margin: 0; }

/* utility */
.center { text-align: center; }
.muted { color: var(--ink-soft); }
.row-gap { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
