/* Embedded Bytes: one stylesheet for every page. Tokens match the SVG style guide in Plans/Plan.md. */

:root {
  color-scheme: light;

  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --ink: #1E293B;
  --muted: #64748B;
  --line: #CBD5E1;
  --highlight-amber: #FEF3C7;

  /* Accent tokens. The brand (home) accent is ink; topics override these three. */
  --accent: #1E293B;
  --accent-strong: #1E293B;
  --accent-soft: #E2E8F0;

  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-heading: 'IBM Plex Sans Condensed', 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Mono', Consolas, Menlo, monospace;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;

  --radius: 12px;
  --radius-sm: 8px;
  --page-width: 1120px;
  --text-width: 68ch;
  --gutter: 16px;
}

/* ---------- Topic themes ----------
   Set data-topic on <body> (insight pages) or on a .card (home grid).
   accent: fills and borders · accent-strong: text and buttons (>= 4.5:1 on white) · accent-soft: tints.
   Topic keys and colours (live and reserved) live in _source/content/registry.mjs. */

/* eb:topics (generated by scripts/site-gen.mjs from _source/content/registry.mjs) */
[data-topic="mcu"] {
  --accent: #2563EB;
  --accent-strong: #1D4ED8;
  --accent-soft: #DBEAFE;
}

[data-topic="c"] {
  --accent: #65A30D;
  --accent-strong: #4D7C0F;
  --accent-soft: #ECFCCB;
}

[data-topic="cpp"] {
  --accent: #EA580C;
  --accent-strong: #C2410C;
  --accent-soft: #FFEDD5;
}

[data-topic="python"] {
  --accent: #4F46E5;
  --accent-strong: #4338CA;
  --accent-soft: #E0E7FF;
}

[data-topic="digital"] {
  --accent: #DB2777;
  --accent-strong: #BE185D;
  --accent-soft: #FCE7F3;
}
/* /eb:topics */

/* ---------- Fonts ---------- */

/* IBM Plex Sans, self-hosted (Latin subset, SIL OFL 1.1: see assets/fonts/OFL.txt). */
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Sans';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/ibm-plex-sans-latin-400-italic.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/ibm-plex-sans-latin-600-normal.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/ibm-plex-sans-latin-700-normal.woff2') format('woff2');
}

/* IBM Plex Sans Condensed for headings and the wordmark (SIL OFL 1.1: see assets/fonts/OFL-condensed.txt). */
@font-face {
  font-family: 'IBM Plex Sans Condensed';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/ibm-plex-sans-condensed-latin-600-normal.woff2') format('woff2');
}

@font-face {
  font-family: 'IBM Plex Sans Condensed';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/ibm-plex-sans-condensed-latin-700-normal.woff2') format('woff2');
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1.125rem;
  line-height: 1.65;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

h1,
h2,
h3 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 var(--space-4);
}

h1 {
  font-size: clamp(2.1rem, 1.5rem + 2.6vw, 3.2rem);
  letter-spacing: -0.01em;
}

h2 {
  font-size: clamp(1.5rem, 1.3rem + 0.9vw, 1.85rem);
}

h3 {
  font-size: 1.2rem;
}

p {
  margin: 0 0 var(--space-4);
}

a {
  color: var(--accent-strong);
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--accent);
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--accent-soft);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

pre {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  margin: 0 0 var(--space-5);
  overflow-x: auto;
}

pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

.container {
  width: min(100% - 2 * var(--gutter), var(--page-width));
  margin-inline: auto;
}

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -100px;
  background: var(--surface);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  z-index: 10;
}

.skip-link:focus {
  top: var(--space-2);
}

/* ---------- Header and footer ---------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-block: var(--space-3);
}

/* Logo: inline mascot (follows the topic accent) + live wordmark text. */
.logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
}

.logo-mark {
  flex: none;
  width: 40px;
  height: 40px;
}

.wordmark {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.45rem;
  letter-spacing: -0.01em;
  line-height: 1;
  color: var(--ink);
}

.wordmark b {
  font-weight: 700;
  color: var(--accent-strong);
}

.site-nav a {
  font-weight: 600;
  text-decoration: none;
  color: var(--ink);
}

.site-nav a:hover {
  color: var(--accent-strong);
}

.site-footer {
  margin-top: var(--space-8);
  padding-block: var(--space-6);
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer .container {
  display: grid;
  gap: var(--space-2);
}

.site-footer p {
  margin: 0;
}

.credit {
  color: var(--ink);
  font-weight: 600;
}

.byline {
  color: var(--muted);
  font-weight: 400;
}

.author {
  color: var(--ink);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.25em;
}

.disclaimer {
  font-size: 0.85rem;
}

/* ---------- Home: hero and cards ---------- */

.hero {
  display: grid;
  gap: var(--space-6);
  align-items: center;
  padding-block: var(--space-6) var(--space-7);
}

.hero h1 {
  font-size: clamp(2.4rem, 1.6rem + 3.4vw, 3.8rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
}

.hero p {
  color: var(--muted);
  font-size: 1.2rem;
  max-width: 34ch;
}

.button {
  display: inline-block;
  background: var(--accent-strong);
  color: #FFFFFF;
  font-weight: 700;
  text-decoration: none;
  padding: var(--space-3) var(--space-5);
  border-radius: 999px;
}

.button:hover {
  background: var(--ink);
  color: #FFFFFF;
}

@media (min-width: 900px) {
  .hero {
    grid-template-columns: 1fr 1.25fr;
  }
}

.section-intro {
  color: var(--muted);
  max-width: var(--text-width);
}

.card-grid {
  list-style: none;
  margin: var(--space-5) 0 0;
  padding: 0;
  display: grid;
  gap: var(--space-5);
  grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  border-top: 4px solid var(--accent);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card:hover,
.card:focus-within {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgb(30 41 59 / 0.08);
}

/* Covers may be SVG or PNG; a fixed 5:3 box keeps them aligned. */
.card img {
  width: 100%;
  aspect-ratio: 5 / 3;
  object-fit: cover;
  border-bottom: 1px solid var(--line);
}

.card-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: var(--space-4) var(--space-5) var(--space-5);
}

.card h3 {
  margin-bottom: var(--space-2);
}

.card h3 a {
  color: var(--ink);
  text-decoration: none;
}

/* The heading link covers the whole card. */
.card h3 a::after {
  content: "";
  position: absolute;
  inset: 0;
}

.card p {
  color: var(--muted);
  font-size: 1rem;
}

.card .meta {
  margin-top: auto;
}

/* ---------- Meta: topic tag and read time ---------- */

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  align-items: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.meta span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.meta img {
  width: 18px;
  height: 18px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 600;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
}

/* Inline topic icon (tight viewBox, sized to the text, stroke follows the topic). */
.tag-icon {
  flex: none;
  width: auto;
  height: 1.05em;
  color: var(--accent-strong);
  overflow: visible;
}

/* ---------- Article ---------- */

.article {
  padding-block: var(--space-6);
}

.article > * {
  max-width: var(--text-width);
  margin-inline: auto;
}

.article .meta {
  margin-bottom: var(--space-4);
}

.tldr {
  font-size: 1.25rem;
  color: var(--ink);
  border-left: 4px solid var(--accent);
  padding-left: var(--space-4);
}

.article h2 {
  margin-top: var(--space-7);
}

.article figure {
  max-width: 760px;
  margin: var(--space-6) auto;
}

.article figure img {
  width: 100%;
  border-radius: var(--radius);
}

figcaption {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  margin-top: var(--space-2);
}

.table-wrap {
  overflow-x: auto;
  margin-block: var(--space-5);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
}

th,
td {
  text-align: left;
  vertical-align: top;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
}

thead th {
  background: var(--bg);
}

tbody th {
  font-weight: 600;
  white-space: nowrap;
}

tbody tr:last-child > * {
  border-bottom: 0;
}

.takeaway {
  background: var(--highlight-amber);
  border-radius: var(--radius);
  padding: var(--space-5);
  margin-block: var(--space-7);
}

.takeaway h2 {
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 var(--space-2);
}

.takeaway p {
  margin: 0;
  font-weight: 600;
}

/* ---------- Prev / next ---------- */

.pager {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
}

.pager a {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  text-decoration: none;
  font-weight: 700;
  color: var(--ink);
}

.pager a:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.pager .label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.pager .label img {
  width: 16px;
  height: 16px;
}

.pager .next {
  text-align: right;
  align-items: flex-end;
}

/* ---------- Topic tiles (home) ---------- */

.tiles {
  display: grid;
  gap: var(--space-4);
  margin-top: var(--space-5);
}

/* One row per topic: icon block, text, and a strip with one segment per entry. */
.tile {
  position: relative;
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: var(--space-3) var(--space-5);
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5) var(--space-4) var(--space-4);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.tile:hover,
.tile:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.tile-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.tile-icon img,
.tile-icon .tag-icon {
  width: 28px;
  height: 28px;
}

.tile-icon .tag-icon {
  width: auto;
  height: 28px;
}

.tile h3 {
  margin: 0 0 var(--space-1);
}

.tile h3 a {
  color: var(--ink);
  text-decoration: none;
}

.tile h3 a:hover {
  color: var(--accent-strong);
}

/* The heading link covers the whole tile. */
.tile h3 a::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
}

.tile p {
  margin: 0;
  color: var(--muted);
}

.tile-size {
  grid-column: 1 / -1;
  display: grid;
  gap: var(--space-2);
  min-width: 0;
}

/* One segment per entry: --n is the entry count (set by site-gen); the strip never outgrows its column. */
.tile .bar {
  display: flex;
  gap: 3px;
  width: min(100%, calc(var(--n, 1) * 17px - 3px));
}

.tile .bar i {
  flex: 1 1 0;
  max-width: 14px;
  height: 10px;
  border-radius: 2px;
  background: var(--accent);
}

.tile .count {
  font-size: 0.9rem;
}

@media (min-width: 760px) {
  .tile {
    grid-template-columns: 64px 1fr 15rem;
  }

  .tile-size {
    grid-column: auto;
    justify-items: end;
    text-align: right;
  }

  .tile .bar {
    justify-content: flex-end;
  }
}

/* ---------- Topic landing page ---------- */

.topic-hero {
  display: grid;
  gap: var(--space-6);
  align-items: center;
  padding-block: var(--space-7) var(--space-5);
}

@media (min-width: 900px) {
  .topic-hero {
    grid-template-columns: 1.1fr 1fr;
  }
}

/* Grid items default to min-width: auto, so a long code line would widen the column past the page. */
.topic-hero > * {
  min-width: 0;
}

.topic-hero .kicker {
  margin: 0 0 var(--space-2);
  color: var(--accent-strong);
  font-weight: 700;
}

.topic-hero p {
  color: var(--muted);
  max-width: 46ch;
}

.topic-visual {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
}

.topic-visual .eb-mascot {
  flex: none;
  width: 112px;
  height: 112px;
}

.topic-visual .cb {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.topic-cover {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* ---------- Mascot callouts ---------- */

.callout {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: var(--space-3);
  align-items: start;
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-block: var(--space-5);
}

.callout.watch {
  background: var(--highlight-amber);
}

.callout .eb-mascot {
  width: 64px;
  height: 64px;
}

.callout .label {
  display: block;
  margin-bottom: var(--space-1);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.callout p {
  margin: 0;
}

/* ---------- Code blocks (K3 dark editor) ----------
   Source pages hold plain code; the build highlights it (.tk-*) and wraps lines (.ln). */

.cb {
  margin: 0 0 var(--space-5);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #1E293B;
  color: #E2E8F0;
  font-size: 0.9rem;
}

.cb-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #0F172A;
  color: #CBD5E1;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1;
}

.cb-head i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #475569;
}

.cb-file {
  font-family: var(--font-mono);
}

.cb-lang {
  margin-left: auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: #334155;
  color: #E2E8F0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.cb pre {
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #E2E8F0;
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
}

.cb code {
  counter-reset: ln;
}

.cb .ln {
  display: block;
  min-height: 1.6em;
}

/* Line numbers come from CSS, so they are never copied with the code. */
.cb .ln::before {
  counter-increment: ln;
  content: counter(ln);
  display: inline-block;
  width: 2ch;
  margin-right: 1.6ch;
  text-align: right;
  color: #64748B;
  user-select: none;
}

.tk-kw { color: #93C5FD; font-weight: 700; }
.tk-ty { color: #5EEAD4; }
.tk-st { color: #FCD34D; }
.tk-nu { color: #FDA4AF; }
.tk-pp { color: #C4B5FD; }
.tk-cm { color: #94A3B8; font-style: italic; }

.cb-out {
  border-top: 1px solid #334155;
  font-family: var(--font-mono);
  color: #F8FAFC;
}

.cb-out-label {
  display: block;
  padding: 8px 16px 0;
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #94A3B8;
}

.cb-out pre {
  color: #F8FAFC;
  padding-top: 6px;
}

/* ---------- 404 page ---------- */

.not-found {
  text-align: center;
  padding-block: var(--space-8);
}

.not-found-mascot {
  display: block;
  margin: 0 auto var(--space-5);
}

.not-found p {
  color: var(--muted);
  max-width: 40ch;
  margin-inline: auto;
  margin-bottom: var(--space-5);
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .card,
  .tile {
    transition: none;
  }

  .card:hover,
  .card:focus-within,
  .tile:hover,
  .tile:focus-within {
    transform: none;
  }
}
