/* =========================================================
   Logic for IT — décodé
   Palette : papier de labo bleuté, encre marine, LED ambre
   ========================================================= */
@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400&family=Bricolage+Grotesque:opsz,wght@12..96,500;12..96,700;12..96,800&family=JetBrains+Mono:wght@400;600;800&display=swap');

:root {
  --paper: #EEF1F6;
  --grid: #DDE3EC;
  --card: #FFFFFF;
  --ink: #172033;
  --ink-2: #3A4762;
  --ink-soft: #66738C;
  --line: #C9D1DE;
  --high: #FFB000;
  --high-glow: #FFD166;
  --high-bg: #FFF4D6;
  --low: #C3CBD8;
  --cobalt: #2647D9;
  --cobalt-bg: #E6EBFD;
  --ok: #17885A;
  --ok-bg: #E2F5EC;
  --bad: #CF3446;
  --bad-bg: #FCE8EA;
  --side: #121A2B;
  --side-2: #1C2740;

  --f-display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --f-body: 'Atkinson Hyperlegible', 'Segoe UI', system-ui, sans-serif;
  --f-mono: 'JetBrains Mono', 'Cascadia Mono', Consolas, monospace;

  --r: 14px;
  --shadow: 0 1px 0 rgba(23,32,51,.06), 0 8px 24px -12px rgba(23,32,51,.25);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 24px; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

body {
  margin: 0;
  font-family: var(--f-body);
  font-size: 1.075rem;
  line-height: 1.65;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  background-attachment: fixed;
}

a { color: var(--cobalt); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 2px; border-radius: 4px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: 100vh; }
.content { padding: 48px clamp(18px, 5vw, 72px) 120px; min-width: 0; }
.content > * { max-width: 800px; margin-left: auto; margin-right: auto; }
.content > .wide, .lesson > .wide { max-width: 1040px; }

/* ---------- sidebar ---------- */
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--side); color: #C9D2E3;
  padding: 22px 16px 40px;
  scrollbar-width: thin; scrollbar-color: #33415f transparent;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; margin: 0 6px 22px; }
.brand-name { font-family: var(--f-display); font-weight: 800; font-size: 1.2rem; line-height: 1.05; letter-spacing: -.01em; }
.brand-name small { display: block; font-family: var(--f-mono); font-weight: 400; font-size: .68rem; color: var(--high); letter-spacing: .08em; text-transform: uppercase; margin-top: 3px; }
.nav-page {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
  color: #DCE3F0; text-decoration: none; font-weight: 700; font-size: .95rem; line-height: 1.25;
}
.nav-page:hover { background: var(--side-2); }
.nav-page.current { background: var(--side-2); color: #fff; box-shadow: inset 3px 0 0 var(--high); }
.nav-page .leds { flex: none; }
.nav-page .np-bar { display: block; height: 3px; border-radius: 3px; background: #2b3856; margin-top: 5px; overflow: hidden; }
.nav-page .np-bar i { display: block; height: 100%; background: var(--high); width: 0; transition: width .4s; }
.nav-page .np-txt { flex: 1; min-width: 0; }
.nav-sections { list-style: none; margin: 4px 0 12px; padding: 0 0 0 18px; border-left: 1px solid #2b3856; margin-left: 22px; }
.nav-sections a {
  display: flex; justify-content: space-between; gap: 8px; padding: 4px 8px; border-radius: 6px;
  color: #9FACC4; text-decoration: none; font-size: .86rem; line-height: 1.3;
}
.nav-sections a:hover { color: #fff; background: var(--side-2); }
.nav-sections a.active { color: #fff; }
.nav-sections a.active::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--high); box-shadow: 0 0 8px var(--high); align-self: center; flex: none; margin-left: -18px; margin-right: 6px; }
.nav-sections .cnt { font-family: var(--f-mono); font-size: .72rem; color: #66738C; white-space: nowrap; }
.nav-sections .cnt.full { color: var(--high); }
.side-foot { margin: 26px 8px 0; font-size: .8rem; color: #66738C; }
.side-foot button { background: none; border: 1px solid #2b3856; color: #9FACC4; border-radius: 8px; padding: 6px 10px; cursor: pointer; font: inherit; }
.side-foot button:hover { color: #fff; border-color: #44547a; }

.topbar { display: none; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; inset: 0 auto 0 0; width: min(320px, 86vw); transform: translateX(-102%); transition: transform .25s; }
  body.menu-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(10,14,25,.45); }
  .topbar {
    display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 40;
    background: var(--side); color: #fff; padding: 10px 16px;
  }
  .topbar button { background: var(--side-2); color: #fff; border: 0; border-radius: 8px; padding: 8px 12px; font: inherit; font-weight: 700; cursor: pointer; }
  .topbar span { font-family: var(--f-display); font-weight: 700; }
  .content { padding-top: 28px; }
}

/* ---------- LEDs (bits) ---------- */
.leds { display: inline-flex; gap: 3px; vertical-align: middle; }
.led {
  display: inline-grid; place-items: center;
  width: 1.7em; height: 1.7em; border-radius: 7px;
  font-family: var(--f-mono); font-weight: 800; font-size: .95em; line-height: 1;
  background: var(--low); color: #56627A;
  border: 0; padding: 0; user-select: none;
  transition: background .15s, box-shadow .15s, color .15s;
}
.led.on { background: var(--high); color: #3d2a00; box-shadow: 0 0 0 1px #e59e00 inset, 0 0 14px -2px var(--high-glow); }
.led.mini { width: 11px; height: 11px; border-radius: 3px; font-size: 0; }
.led.mini.on { box-shadow: 0 0 8px var(--high); }
button.led { cursor: pointer; }
button.led:hover { filter: brightness(1.06); transform: translateY(-1px); }
.ledrow { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; }
.ledcell { display: inline-flex; flex-direction: column; align-items: center; gap: 4px; }
.ledcell .w { font-family: var(--f-mono); font-size: .7rem; color: var(--ink-soft); white-space: nowrap; }
.ledcell .led { width: 2.4em; height: 2.4em; font-size: 1.05em; border-radius: 10px; }
.ledrow .sep { width: 10px; }

/* inline bits inside text: <b class="bits">1011</b> */
.bits { font-family: var(--f-mono); font-weight: 600; letter-spacing: .04em; background: var(--high-bg); padding: 0 .3em; border-radius: 5px; color: #6b4a00; white-space: nowrap; }
code, .mono { font-family: var(--f-mono); font-size: .92em; }
code { background: #E3E8F1; padding: .05em .35em; border-radius: 5px; }
pre { font-family: var(--f-mono); font-size: .9rem; background: var(--side); color: #E6ECF7; padding: 16px 18px; border-radius: 12px; overflow-x: auto; line-height: 1.5; }
pre .c { color: #7f8db0; }
pre .k { color: var(--high); }
sub, sup { font-size: .7em; }

/* overline NOT */
.ov { display: inline-block; border-top: 1.6px solid currentColor; padding-top: 1px; line-height: 1.1; }
.expr { font-family: var(--f-mono); font-weight: 600; white-space: nowrap; }

/* ---------- typography ---------- */
h1, h2, h3, h4 { font-family: var(--f-display); line-height: 1.12; letter-spacing: -.015em; margin: 0; }
h1 { font-size: clamp(2.4rem, 5.5vw, 4.2rem); font-weight: 800; letter-spacing: -.03em; }
h2 { font-size: clamp(1.7rem, 3vw, 2.2rem); font-weight: 800; margin-top: .2em; }
h3 { font-size: 1.3rem; font-weight: 700; margin: 1.8em 0 .5em; }
h4 { font-size: 1.08rem; font-weight: 700; margin: 1.4em 0 .4em; }
p { margin: .7em 0; }
strong { font-weight: 700; }
.eyebrow { font-family: var(--f-mono); font-size: .76rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); display: flex; align-items: center; gap: 10px; }
.lead { font-size: 1.22rem; color: var(--ink-2); max-width: 60ch; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2.5em 0; }

/* ---------- chapter hero ---------- */
.chap-hero { padding: 24px 0 36px; border-bottom: 2px solid var(--ink); margin-bottom: 40px; }
.chap-hero .num { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.chap-hero .num .led { width: 2.2em; height: 2.2em; font-size: 1.2em; border-radius: 10px; }
.chap-hero .num span.lbl { font-family: var(--f-mono); font-size: .8rem; color: var(--ink-soft); letter-spacing: .1em; text-transform: uppercase; }
.chap-hero h1 { max-width: 16ch; }
.plan { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; margin-top: 22px; padding: 0; list-style: none; }
.plan a { display: block; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--ink); font-size: .93rem; line-height: 1.3; }
.plan a:hover { border-color: var(--ink); }
.plan a small { display: block; font-family: var(--f-mono); font-size: .7rem; color: var(--ink-soft); }

/* ---------- lesson section ---------- */
.lesson { padding: 34px 0 30px; border-bottom: 1px dashed var(--line); }
.lesson:last-of-type { border-bottom: 0; }
.lesson > * { max-width: 800px; margin-left: auto; margin-right: auto; }
.lesson .eyebrow { margin-bottom: 6px; }
.part-title { margin: 60px auto 10px; padding: 16px 20px; background: var(--ink); color: #fff; border-radius: var(--r); display: flex; align-items: center; gap: 14px; }
.part-title h2 { margin: 0; font-size: 1.5rem; color: #fff; }
.part-title .eyebrow { color: var(--high); }

/* callouts */
.tldr, .trap, .tip, .vocab, .method {
  border-radius: 12px; padding: 14px 18px; margin: 1.1em auto;
}
.tldr { background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--high); font-size: 1.1rem; }
.tldr::before { content: 'En une phrase'; display: block; font-family: var(--f-mono); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: #a87400; margin-bottom: 2px; }
.trap { background: var(--bad-bg); border: 1px solid #f2c3c9; }
.trap::before { content: '⚠ Piège classique'; display: block; font-weight: 700; color: var(--bad); margin-bottom: 2px; }
.tip { background: var(--ok-bg); border: 1px solid #bfe6d2; }
.tip::before { content: '💡 Astuce'; display: block; font-weight: 700; color: var(--ok); margin-bottom: 2px; }
.vocab { background: transparent; border: 1px dashed var(--ink-soft); font-size: .93rem; padding: 10px 14px; }
.vocab::before { content: 'EN → FR (le cours est en anglais)'; display: block; font-family: var(--f-mono); font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 4px; }
.vocab b { font-family: var(--f-mono); font-weight: 600; }
.tldr > :first-child, .trap > :first-child, .tip > :first-child { margin-top: 0; }
.tldr > :last-child, .trap > :last-child, .tip > :last-child, .vocab > :last-child { margin-bottom: 0; }

/* method steps: a real sequence → numbered */
.method { background: var(--card); border: 1px solid var(--line); padding: 16px 20px 10px; }
.method > h4:first-child { margin-top: 0; }
.method::before { content: 'Méthode'; display: inline-block; font-family: var(--f-mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; background: var(--ink); color: #fff; padding: 2px 8px; border-radius: 5px; margin-bottom: 8px; }
ol.steps { counter-reset: s; list-style: none; padding: 0; margin: .4em 0 .6em; }
ol.steps > li { counter-increment: s; position: relative; padding-left: 42px; margin: 0 0 .8em; }
ol.steps > li::before {
  content: counter(s); position: absolute; left: 0; top: 0;
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--high); color: #3d2a00; font-family: var(--f-mono); font-weight: 800; font-size: .85rem;
}

/* ---------- widget card ---------- */
.widget { background: var(--card); border: 1.5px solid var(--ink); border-radius: var(--r); margin: 1.6em auto; box-shadow: var(--shadow); overflow: hidden; }
.widget > .w-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: #F7F9FC; }
.widget > .w-head .tag { font-family: var(--f-mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; background: var(--cobalt); color: #fff; padding: 2px 8px; border-radius: 5px; }
.widget > .w-head h4 { margin: 0; font-size: 1rem; }
.widget > .w-body { padding: 18px; }
.widget .row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 8px 0; }
.widget .out { font-family: var(--f-mono); }
.big-out { font-family: var(--f-mono); font-size: 1.5rem; font-weight: 800; }
.readout { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-top: 14px; }
.readout div { background: var(--paper); border-radius: 10px; padding: 8px 12px; }
.readout small { display: block; font-family: var(--f-mono); font-size: .72rem; letter-spacing: .03em; color: var(--ink-soft); }
.readout b { font-family: var(--f-mono); font-size: 1.2rem; }

/* form controls */
input[type=text], input[type=number], select, textarea {
  font-family: var(--f-mono); font-size: 1rem; padding: 8px 11px; border-radius: 9px;
  border: 1.5px solid var(--line); background: #fff; color: var(--ink); min-width: 0;
}
input[type=text]:focus, input[type=number]:focus, select:focus { border-color: var(--cobalt); outline: none; box-shadow: 0 0 0 3px var(--cobalt-bg); }
input[type=range] { accent-color: var(--cobalt); }
label.inl { display: inline-flex; align-items: center; gap: 6px; font-size: .95rem; }
.btn {
  font: inherit; font-weight: 700; font-size: .95rem; cursor: pointer;
  padding: 8px 16px; border-radius: 9px; border: 1.5px solid var(--cobalt);
  background: var(--cobalt); color: #fff; transition: transform .08s, background .15s;
}
.btn:hover { background: #1d39b8; }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: #fff; color: var(--cobalt); }
.btn.ghost:hover { background: var(--cobalt-bg); }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.seg { display: inline-flex; border: 1.5px solid var(--cobalt); border-radius: 9px; overflow: hidden; }
.seg button { font: inherit; font-weight: 700; font-size: .88rem; border: 0; background: #fff; color: var(--cobalt); padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1.5px solid var(--cobalt); }
.seg button.on { background: var(--cobalt); color: #fff; }
.syntax { font-size: .82rem; color: var(--ink-soft); }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; margin: 1em auto; }
table { border-collapse: collapse; font-size: .95rem; }
table.tt, table.data { background: #fff; border: 1.5px solid var(--ink); border-radius: 10px; overflow: hidden; border-collapse: separate; border-spacing: 0; }
table.tt th, table.tt td, table.data th, table.data td { padding: 6px 12px; border-bottom: 1px solid var(--line); text-align: center; }
table.data td, table.data th { text-align: left; }
table.tt tr:last-child td, table.data tr:last-child td { border-bottom: 0; }
table.tt th, table.data th { background: var(--ink); color: #fff; font-family: var(--f-mono); font-weight: 600; font-size: .85rem; }
table.tt td { font-family: var(--f-mono); font-weight: 600; }
table.tt td.one { background: var(--high-bg); color: #8a5c00; }
table.tt td.sep, table.tt th.sep { border-left: 2px solid var(--ink); }
table.tt tr.hl td { background: var(--cobalt-bg); }
table.tt tr.hl td.one { background: #ffe39a; }
table.tt tr.click { cursor: pointer; }
table.tt tr.click:hover td { background: #f1f4fa; }
table.data td.mono, table.data td code { font-family: var(--f-mono); }
.cmp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }

/* ---------- quiz ---------- */
.quiz { margin: 1.6em auto; }
.quiz-title { font-family: var(--f-mono); font-size: .74rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.quiz-title::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.q { background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: 14px 16px; margin: 10px 0; transition: border-color .2s; }
.q.ok { border-color: var(--ok); }
.q .q-text { margin: 0 0 10px; font-weight: 700; }
.q .q-text .n { font-family: var(--f-mono); font-weight: 600; color: var(--ink-soft); margin-right: 6px; }
.q-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.q-choices button {
  font: inherit; font-size: .97rem; text-align: left; cursor: pointer;
  padding: 8px 14px; border-radius: 9px; border: 1.5px solid var(--line); background: #fff; color: var(--ink);
}
.q-choices button:hover:not(:disabled) { border-color: var(--cobalt); background: var(--cobalt-bg); }
.q-choices button.right { border-color: var(--ok); background: var(--ok-bg); color: #0d5c3b; font-weight: 700; }
.q-choices button.wrong { border-color: var(--bad); background: var(--bad-bg); color: #8f1c2a; text-decoration: line-through; }
.q-choices.vertical { flex-direction: column; }
.q-input { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.q-input input { flex: 1 1 180px; max-width: 360px; }
.q-input input.ok { border-color: var(--ok); background: var(--ok-bg); }
.q-input input.bad { border-color: var(--bad); background: var(--bad-bg); }
.q-feedback { margin-top: 10px; font-size: .97rem; display: none; }
.q-feedback.show { display: block; }
.q-feedback .verdict { font-weight: 700; }
.q-feedback .verdict.ok { color: var(--ok); }
.q-feedback .verdict.bad { color: var(--bad); }
.q-explain { display: none; margin-top: 10px; padding: 10px 14px; background: var(--paper); border-radius: 9px; font-size: .97rem; }
.q-explain.show { display: block; }
.q-explain > :first-child { margin-top: 0; } .q-explain > :last-child { margin-bottom: 0; }
.q .done-badge { float: right; font-family: var(--f-mono); font-size: .7rem; color: var(--ok); background: var(--ok-bg); border-radius: 5px; padding: 1px 6px; }
.q .reveal { font: inherit; font-size: .88rem; background: none; border: 0; color: var(--ink-soft); text-decoration: underline; cursor: pointer; padding: 0; margin-left: 4px; }
@keyframes shake { 0%,100% { transform: none } 25% { transform: translateX(-5px) } 75% { transform: translateX(5px) } }
.shake { animation: shake .25s; }

/* ---------- step-by-step player ---------- */
.stepper-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.stepper-controls .count { font-family: var(--f-mono); font-size: .85rem; color: var(--ink-soft); }
.stepper-msg { background: var(--cobalt-bg); border-radius: 9px; padding: 10px 14px; min-height: 2.6em; margin-top: 10px; }
.colcalc { font-family: var(--f-mono); font-size: 1.35rem; display: inline-grid; gap: 2px 0; padding: 10px 14px; background: var(--paper); border-radius: 10px; }
.colcalc .r { display: contents; }
.colcalc span { width: 1.55em; text-align: center; padding: 1px 0; border-radius: 5px; }
.colcalc .carry { font-size: .75em; color: var(--bad); height: 1.3em; }
.colcalc .res { border-top: 2px solid var(--ink); }
.colcalc .cur { background: #ffe39a; }
.colcalc .done { color: var(--ok); }
.colcalc .op { color: var(--ink-soft); }
.colcalc .struck { text-decoration: line-through; color: var(--ink-soft); }

/* division table */
.divtab { font-family: var(--f-mono); border-collapse: collapse; }
.divtab td { padding: 3px 10px; border-bottom: 1px solid var(--line); }
.divtab td.rem { font-weight: 800; color: #8a5c00; background: var(--high-bg); text-align: center; }
.divtab tr.new td { animation: pop .3s; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---------- circuits (svg) ---------- */
.circuit { width: 100%; height: auto; display: block; }
.circuit .wire { fill: none; stroke: #8995AB; stroke-width: 2.4; stroke-linejoin: round; }
.circuit .wire.on { stroke: var(--high); stroke-width: 3; filter: drop-shadow(0 0 3px rgba(255,176,0,.55)); }
.circuit .gate path, .circuit .gate rect, .circuit .gate circle.bub { fill: #fff; stroke: var(--ink); stroke-width: 2.2; }
.circuit .gate .xor-back { fill: none; }
.circuit .gate text { font-family: var(--f-mono); font-size: 13px; font-weight: 800; fill: var(--ink); text-anchor: middle; dominant-baseline: central; }
.circuit .gate .glabel { font-size: 11px; font-weight: 600; fill: var(--ink-soft); }
.circuit .gate .gname { font-size: 9px; font-weight: 600; fill: var(--ink-soft); }
.circuit .inp { cursor: pointer; }
.circuit .inp circle { fill: var(--low); stroke: var(--ink); stroke-width: 2; transition: fill .15s; }
.circuit .inp.on circle { fill: var(--high); }
.circuit .inp:hover circle { stroke: var(--cobalt); stroke-width: 3; }
.circuit .inp text, .circuit .outp text { font-family: var(--f-mono); font-weight: 800; font-size: 14px; text-anchor: middle; dominant-baseline: central; fill: var(--ink); pointer-events: none; }
.circuit .inp text.val { font-size: 11px; }
.circuit .outp circle { fill: #E3E7EE; stroke: var(--ink); stroke-width: 2; }
.circuit .outp.on circle { fill: var(--high); filter: drop-shadow(0 0 8px var(--high)); }
.circuit .lbl { font-family: var(--f-mono); font-size: 12px; fill: var(--ink-soft); }
.circuit .wv { font-family: var(--f-mono); font-size: 11px; font-weight: 800; fill: #8995AB; }
.circuit .wv.on { fill: #c98a00; }
.circuit .dot { fill: #8995AB; } .circuit .dot.on { fill: var(--high); }
.circuit-hint { font-size: .85rem; color: var(--ink-soft); margin: 4px 0 0; }

/* gate cards (playground) */
.gate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.gate-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fff; }
.gate-card h5 { font-family: var(--f-display); font-size: 1.05rem; margin: 0 0 4px; display: flex; justify-content: space-between; align-items: baseline; }
.gate-card h5 small { font-family: var(--f-mono); font-size: .75rem; color: var(--ink-soft); font-weight: 400; }
.gate-card p { font-size: .88rem; margin: 4px 0 8px; color: var(--ink-2); }
.gate-card table.tt { font-size: .82rem; }
.gate-card table.tt td, .gate-card table.tt th { padding: 3px 9px; }

/* ---------- karnaugh ---------- */
.kmap-wrap { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
table.kmap { border-collapse: separate; border-spacing: 4px; font-family: var(--f-mono); }
table.kmap th { font-size: .82rem; color: var(--ink-soft); font-weight: 600; padding: 2px 6px; }
table.kmap th.corner { position: relative; width: 56px; height: 44px; }
table.kmap th.corner span { position: absolute; font-size: .78rem; color: var(--ink); font-weight: 800; }
table.kmap th.corner .cv { right: 4px; top: 2px; } table.kmap th.corner .rv { left: 4px; bottom: 2px; }
table.kmap td {
  width: 52px; height: 52px; text-align: center; font-weight: 800; font-size: 1.2rem; border-radius: 10px;
  background: #F1F4F9; border: 1.5px solid var(--line); cursor: pointer; position: relative; user-select: none;
}
table.kmap td.v1 { background: var(--high-bg); color: #8a5c00; border-color: #f0cf7a; }
table.kmap td.vx { color: var(--cobalt); }
table.kmap td.dim { opacity: .3; }
table.kmap td .idx { position: absolute; left: 4px; top: 2px; font-size: .58rem; color: var(--ink-soft); font-weight: 400; }
table.kmap.ro td { cursor: default; }
.groups-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.groups-list li { display: flex; gap: 10px; align-items: center; padding: 6px 10px; border-radius: 9px; background: var(--paper); cursor: default; }
.groups-list .sw { width: 16px; height: 16px; border-radius: 5px; flex: none; }

/* ---------- waveforms ---------- */
.wave { width: 100%; height: auto; display: block; background: #0f1626; border-radius: 10px; }
.wave .grid { stroke: #24304a; stroke-width: 1; }
.wave .sig { fill: none; stroke-width: 2.4; stroke-linejoin: miter; }
.wave text { font-family: var(--f-mono); font-size: 13px; font-weight: 800; fill: #C9D2E3; dominant-baseline: central; }
.wave .edge { stroke: var(--high); stroke-width: 1; stroke-dasharray: 3 3; opacity: .5; }

/* 7-segment */
.seg7 svg { width: 120px; height: auto; }
.seg7 .s { fill: #2a3346; transition: fill .15s; }
.seg7 .s.on { fill: #FF4D3D; filter: drop-shadow(0 0 5px #ff4d3d); }
.seg7-panel { background: #0f1626; border-radius: 12px; padding: 14px; display: inline-flex; gap: 8px; }

/* timeline */
.timeline { list-style: none; padding: 0; margin: 1.2em 0; position: relative; }
.timeline::before { content: ''; position: absolute; left: 86px; top: 6px; bottom: 6px; width: 2px; background: var(--ink); }
.timeline li { display: grid; grid-template-columns: 76px 1fr; gap: 26px; margin-bottom: 14px; position: relative; }
.timeline li::before { content: ''; position: absolute; left: 81px; top: 8px; width: 12px; height: 12px; border-radius: 50%; background: var(--high); border: 2px solid var(--ink); }
.timeline .yr { font-family: var(--f-mono); font-weight: 800; text-align: right; }
.timeline .ev b { display: block; }
.timeline .ev span { color: var(--ink-2); font-size: .96rem; }

/* home */
.hero { padding: 30px 0 40px; }
.hero h1 { max-width: 14ch; }
.hero .byte-demo { margin: 30px 0 10px; padding: 22px; background: var(--side); border-radius: 18px; color: #fff; box-shadow: var(--shadow); }
.hero .byte-demo .ledcell .w { color: #8b97b1; }
.hero .byte-demo .readout div { background: var(--side-2); }
.hero .byte-demo .readout small { color: #8b97b1; }
.hero .byte-demo .readout b { color: #fff; }
.hero .byte-demo p { color: #C9D2E3; margin: 0 0 14px; }
.chap-cards { display: grid; gap: 14px; margin: 26px auto; }
.chap-card { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: start; text-decoration: none; color: var(--ink); background: var(--card); border: 1.5px solid var(--ink); border-radius: var(--r); padding: 18px 20px; box-shadow: var(--shadow); transition: transform .12s; }
.chap-card:hover { transform: translateY(-2px); }
.chap-card h3 { margin: 0 0 4px; font-size: 1.35rem; }
.chap-card p { margin: 0; color: var(--ink-2); font-size: .97rem; }
.chap-card .bar { height: 6px; background: var(--paper); border-radius: 6px; margin-top: 12px; overflow: hidden; }
.chap-card .bar i { display: block; height: 100%; width: 0; background: var(--high); transition: width .5s; }
.chap-card .bar-l { font-family: var(--f-mono); font-size: .75rem; color: var(--ink-soft); margin-top: 4px; }

/* training */
.trainer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.trainer-pick { text-align: left; font: inherit; cursor: pointer; padding: 12px 14px; border: 1.5px solid var(--line); background: #fff; border-radius: 12px; color: var(--ink); }
.trainer-pick:hover { border-color: var(--ink); }
.trainer-pick.on { border-color: var(--cobalt); background: var(--cobalt-bg); }
.trainer-pick b { display: block; }
.trainer-pick small { color: var(--ink-soft); font-family: var(--f-mono); font-size: .72rem; }
.score { font-family: var(--f-mono); font-weight: 800; }
.streak { color: #a87400; }
.exam-q { border-left: 4px solid var(--line); padding-left: 14px; }

/* misc */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }
.center { text-align: center; }
.muted { color: var(--ink-soft); }
.small { font-size: .88rem; }
.nowrap { white-space: nowrap; }
.pill { display: inline-block; font-family: var(--f-mono); font-size: .75rem; padding: 1px 8px; border-radius: 99px; background: var(--paper); border: 1px solid var(--line); }
.kbd { font-family: var(--f-mono); font-size: .85em; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: #fff; }
.page-nav { display: flex; justify-content: space-between; gap: 14px; margin-top: 60px; }
.page-nav a { flex: 1; padding: 16px 18px; border: 1.5px solid var(--ink); border-radius: 12px; background: var(--card); text-decoration: none; color: var(--ink); font-weight: 700; }
.page-nav a small { display: block; font-family: var(--f-mono); font-weight: 400; color: var(--ink-soft); font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; }
.page-nav a.next { text-align: right; }

@media print {
  .side, .topbar, .widget, .quiz, .page-nav { display: none !important; }
  .layout { display: block; }
  body { background: #fff; font-size: 11pt; }
  .content { padding: 0; }
}

/* compact LEDs (float decoder, long registers) */
.compact-leds .ledrow { gap: 3px; }
.compact-leds .ledcell .led { width: 1.55em; height: 1.75em; font-size: .82em; border-radius: 6px; }

/* small-screen safety */
.bits { white-space: normal; overflow-wrap: anywhere; }
.widget > .w-body { overflow-x: auto; }
.widget input[type=text], .q-input input { max-width: 100%; }
label.inl { flex-wrap: wrap; max-width: 100%; }
.seg { flex-wrap: wrap; }
.seg7-panel { flex-wrap: wrap; max-width: 100%; }
@media (max-width: 600px) {
  .content { padding-left: 14px; padding-right: 14px; }
  .widget > .w-body { padding: 14px 12px; }
  .ledcell .led { width: 2.05em; height: 2.05em; }
  .hero .byte-demo { padding: 16px 12px; }
  .colcalc { font-size: 1.1rem; }
  .expr { white-space: normal; }
}
.cmp-grid > *, .two-col > *, .kmap-wrap > * { min-width: 0; }
