/* eg.css - styles for the reworked Embedded Garage pages.
   The idea: the page is a datasheet, and set into it is one working
   instrument. Paper background, ink text, a single red "markup" ink for
   emphasis, and a dark oscilloscope whose traces are the only bright colour.
   Every page of the site uses this one stylesheet. */

/* ---- Fonts: served from this site, not from Google ---------------------------
   Each rule names one font file. "swap" shows text at once in a fallback font
   and switches when the file arrives, so text is never invisible while loading.
   The files are the Latin subset; the unicode-range tells the browser to fetch
   a file only if the page uses characters from it. Licence: assets/fonts/LICENSE.txt. */
@font-face {
    font-family: "IBM Plex Sans";              /* Body text, regular weight. */
    font-style: normal;                        /* Upright. */
    font-weight: 400;                          /* Regular. */
    font-display: swap;                        /* Fallback first, then swap. */
    src: url("/assets/fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "IBM Plex Sans";              /* Greek letters in body text, such as the delta in equations. */
    font-style: normal;                        /* Upright. */
    font-weight: 400;                          /* Regular. */
    font-display: swap;                        /* Fallback first, then swap. */
    src: url("/assets/fonts/ibm-plex-sans-greek-400-normal.woff2") format("woff2");
    unicode-range: U+0370-03FF;                /* Only fetched on pages that contain Greek letters. */
}

@font-face {
    font-family: "IBM Plex Sans";              /* Medium weight: buttons and status lines. */
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("/assets/fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "IBM Plex Sans";              /* Semi-bold: entry headings and table headers. */
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("/assets/fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "IBM Plex Sans Condensed";    /* Page and section headings. */
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("/assets/fonts/ibm-plex-sans-condensed-latin-600-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "IBM Plex Sans Condensed";    /* Bold: the headline on the home page only. */
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("/assets/fonts/ibm-plex-sans-condensed-latin-700-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "IBM Plex Mono";              /* Readouts, code and table values. */
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("/assets/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "IBM Plex Mono";              /* Medium weight: dates and the slider value. */
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("/assets/fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---- Design tokens: every colour and font is named once here ------------ */
:root {
    --paper: #F4F1E8;        /* Page background: warm paper, like a printed application note. */
    --panel: #FFFFFF;        /* Raised surfaces: form fields. */
    --ink: #16181B;          /* Main text: near-black ink (about 15.8:1 on the paper). */
    --dim: #5A5F66;          /* Secondary text (about 5.7:1 on the paper). */
    --rule: #CFC9B8;         /* Hairlines between sections. */
    --field: #8A8578;        /* Borders of controls, dark enough to see the edge of a field. */
    --accent: #B83A14;       /* Redline: the red pen used for revisions on drawings (about 5.1:1 on paper). */
    --accent-deep: #9C2F0E;  /* Darker redline for hover states. */
    --error: #A1121F;        /* Form error text; a different red from the accent so errors are not mistaken for links. */
    --ok: #1E6B3A;           /* Form success text. */
    --bezel: #1B1E22;        /* Body of the oscilloscope. */
    --screen: #0D0F11;       /* The scope screen, darker than its body so traces glow against it. */
    --ch1: #F2C230;          /* Channel 1 trace: the conventional yellow of a bench scope. */
    --ch2: #4FB8C9;          /* Channel 2 trace. */
    --text: "IBM Plex Sans", "Segoe UI", Arial, sans-serif;                       /* Body text. */
    --head: "IBM Plex Sans Condensed", "Arial Narrow", Arial, sans-serif;         /* Headings. */
    --mono: "IBM Plex Mono", Consolas, monospace;                                 /* Instrument readouts and drawing labels. */
    --edge: clamp(1.25rem, 4vw, 3.5rem);   /* Left/right page margin; grows with the window. */
}

/* ---- Dark mode: the same tokens with dark values ----------------------------
   theme.js puts data-theme="dark" on the <html> element when the visitor has
   chosen dark mode. Only the colours change; every rule below reads the tokens. */
:root { color-scheme: light; }                 /* Tell the browser to draw light scrollbars and form controls by default. */

:root[data-theme="dark"] {
    color-scheme: dark;      /* Dark scrollbars and form controls. */
    --paper: #141517;        /* Page background: graphite, not pure black. */
    --panel: #1E2023;        /* Form fields, slightly lighter than the page. */
    --ink: #ECE8DF;          /* Main text: warm off-white (about 14.9:1 on the page). */
    --dim: #9A978F;          /* Secondary text (about 6.3:1 on the page). */
    --rule: #34383E;         /* Hairlines between sections. */
    --field: #6A6F78;        /* Borders of controls. */
    --accent: #F0704A;       /* The redline, lightened so it stays readable on graphite (about 6:1). */
    --accent-deep: #FF8F6B;  /* Hover state: lighter still, since darker would fade into the page. */
    --error: #F2857A;        /* Form error text. */
    --ok: #6FCF97;           /* Form success text. */
}

/* ---- Base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }   /* Padding never makes an element wider than its stated width. */

html {
    scroll-behavior: smooth;                              /* Menu links glide to their section. */
    font-size: clamp(16px, calc(8.6px + 0.54vw), 19px);   /* Type grows gently on large screens (16 px up to a 1366 px window, 19 px at 1920 px), so the page fills a laptop instead of sitting small in one corner. */
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }                   /* Jump instead, for people who asked for less motion. */
}

body {
    margin: 0;                         /* Remove the browser's default page margin. */
    background: var(--paper);            /* Paper page. */
    color: var(--ink);               /* Ink text. */
    font-family: var(--text);          /* Plex Sans everywhere unless overridden. */
    font-size: 1.125rem;               /* 18 px body: comfortable for long technical sentences. */
    line-height: 1.55;                 /* Open line spacing for long technical sentences. */
}

a {
    color: inherit;                            /* Links take the surrounding text colour... */
    text-decoration-color: var(--accent);       /* ...and are marked by a redline underline. */
    text-decoration-thickness: 2px;            /* Thick enough to notice. */
    text-underline-offset: 0.2em;              /* Keep the underline clear of descenders. */
}

a:hover { color: var(--accent); }               /* Hover turns the whole link red. */

:focus-visible {
    outline: 2px solid var(--accent);           /* Clear keyboard focus ring on every control. */
    outline-offset: 3px;                       /* A small gap so the ring does not touch the element. */
}

.skip-link {
    position: absolute;                        /* Out of the layout flow. */
    left: -999rem;                             /* Hidden off-screen until focused. */
    top: 0.5rem;                               /* Where it appears when focused. */
    background: var(--accent);                  /* High-visibility chip. */
    color: var(--paper);                         /* Paper-coloured text on red. */
    padding: 0.5rem 0.75rem;                   /* Comfortable target size. */
}

.skip-link:focus { left: 0.5rem; }             /* Bring it on-screen for keyboard users. */

/* ---- The sheet: every block shares one centred width ----------------------- */
.topbar, .hero, .page-head, .band, .footer, .article-wrap {
    max-width: calc(80rem + 2 * var(--edge));  /* Content is at most 80rem wide, plus the side margins. */
    margin-inline: auto;                       /* On a wider window the spare space is split evenly left and right. */
}

/* ---- Top bar ------------------------------------------------------------- */
.topbar {
    display: flex;                             /* Brand and menu on one line. */
    flex-wrap: wrap;                           /* The menu drops below the brand on narrow phones. */
    align-items: center;                       /* Vertically centre both. */
    justify-content: space-between;            /* Brand left, menu right. */
    gap: 0.75rem 2rem;                         /* Space between them, and between wrapped rows. */
    padding: 1.25rem var(--edge);              /* Same side margin as the rest of the page. */
}

.brand {
    display: inline-flex;                      /* Mark and name side by side. */
    align-items: center;                       /* Centre the mark against the text. */
    gap: 0.6rem;                               /* Space between mark and name. */
    text-decoration: none;                     /* The brand is not underlined. */
}

.brand-mark {
    width: 1.9rem;                             /* Logo size in the bar. */
    height: 1.9rem;                            /* Square. */
    color: var(--ink);                         /* The hexagon is drawn in ink; the die inside overrides this below. */
}

.brand-mark .die { stroke: var(--accent); }   /* The chip die and its pins are drawn in redline. */

.brand-name {
    font-family: var(--head);                  /* Condensed heading face. */
    font-size: 1.45rem;                        /* Slightly larger than body text. */
    letter-spacing: 0.01em;                    /* A touch of air for the condensed letters. */
}

.nav-list {
    display: flex;                             /* Links in a row. */
    flex-wrap: wrap;                           /* Wrap rather than overflow on small screens. */
    gap: 0.25rem 1.5rem;                       /* Space between links. */
    margin: 0;                                 /* Remove list defaults. */
    padding: 0;                                /* Remove list defaults. */
    list-style: none;                          /* No bullets. */
}

.nav-list a {
    display: inline-block;                     /* So padding enlarges the tap target. */
    padding: 0.4rem 0;                         /* Taller target without changing the look. */
    text-decoration: none;                     /* Menu links are plain until hovered. */
    color: var(--dim);                         /* Quieter than the page text. */
}

.nav-list a:hover { color: var(--ink); }     /* Darken to full ink on hover. */

.theme-toggle {
    padding: 0.25rem 0.6rem;                   /* A small key, in keeping with the other buttons. */
    border: 1px solid var(--field);            /* Outlined, like a secondary button. */
    border-radius: 3px;                        /* Same corner as the other buttons. */
    background: transparent;                   /* No fill. */
    color: var(--dim);                         /* As quiet as the menu links. */
    font: 400 0.9rem var(--text);              /* Slightly smaller than the menu text. */
    cursor: pointer;                           /* Hand cursor. */
}

.theme-toggle:hover {
    color: var(--ink);                         /* Brighten the label on hover... */
    border-color: var(--ink);                  /* ...and the outline with it. */
}

.nav-list { align-items: center; }             /* Keep the links and the toggle on one centre line. */

/* ---- Hero ---------------------------------------------------------------- */
.hero {
    display: grid;                             /* Statement and scope share a grid. */
    gap: 2.5rem;                               /* Space between them when stacked. */
    padding: clamp(1rem, 2vw, 2rem) var(--edge) clamp(3rem, 7vw, 6rem);     /* A small gap under the top bar, so the instrument starts high on the screen; generous space below before the first section. */
    align-items: start;                        /* The headline starts on the same line as the top of the scope, so the two columns share one top edge. */
}

@media (min-width: 62rem) {
    .hero {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);   /* Text and scope get equal widths, so each half of the headline fits on one line. */
        gap: 4rem;                                              /* Wider gap on desktop. */
    }
}

h1 {
    margin: 0 0 1.5rem;                        /* Space under the headline only. */
    font-family: var(--head);                  /* Condensed face lets a long sentence be set large. */
    font-weight: 600;                          /* The only weight loaded for this face. */
    font-size: clamp(2.6rem, 5.4vw, 4.6rem);   /* Scales with the window between sensible limits. */
    line-height: 1.02;                         /* Tight, as large condensed type needs. */
    letter-spacing: -0.005em;                  /* Slightly tighter at display size. */
    text-wrap: balance;                        /* Even line lengths instead of one short last line. */
}

.hero h1 .phrase { display: inline-block; }  /* Each half of the headline is kept together, so on a laptop it reads as two lines: "From the power stage" and "to the bytes on the bus." On a phone each half wraps inside itself. */

.hero h1 {
    font-size: min(2.4rem, calc((100vw - 3rem) / 10));   /* On phones and tablets: as large as possible while "to the bytes on the bus." still fits on one line (that half is about ten times the font size wide; 3rem covers the page margins). */
    font-weight: 700;                          /* Bold, a step heavier than the other headings, so the smaller headline still reads as the title of the site. */
}

@media (min-width: 62rem) {
    .hero h1 {
        font-size: clamp(2.4rem, 4.2vw, 3.6rem);   /* Beside the oscilloscope: scales with the window, two lines from 1024 px to 1920 px. */
    }
}

.lede {
    margin: 0 0 2rem;                          /* Space before the buttons. */
    max-width: 34rem;                          /* Keeps lines to a readable length. */
    color: var(--dim);                         /* Supports the headline without competing with it. */
}

.hero .lede { margin-bottom: 1rem; }         /* In the hero, two short paragraphs sit close together... */

.hero .actions { margin-top: 2rem; }          /* ...and the buttons keep their larger gap below the last one. */

.actions {
    display: flex;                             /* Buttons in a row. */
    flex-wrap: wrap;                           /* Stack on very narrow screens. */
    gap: 0.75rem;                              /* Space between buttons. */
}

/* ---- Buttons: shaped like instrument front-panel keys --------------------- */
.button {
    display: inline-block;                     /* Works for both links and buttons. */
    padding: 0.7rem 1.15rem;                   /* Large enough to tap. */
    border: 1px solid var(--field);            /* Outlined by default. */
    border-radius: 3px;                        /* Nearly square, like a panel key. */
    background: transparent;                   /* Secondary buttons have no fill. */
    color: var(--ink);                       /* Ink label. */
    font: 500 1rem var(--text);                /* Medium weight label in the body face. */
    text-decoration: none;                     /* Buttons are not underlined. */
    cursor: pointer;                           /* Hand cursor for real buttons too. */
}

.button:hover {
    border-color: var(--accent);                /* Outline lights up on hover. */
    color: var(--accent);                       /* Label follows. */
}

.button-primary {
    background: var(--accent);                  /* The one filled button per group. */
    border-color: var(--accent);                /* Border matches the fill. */
    color: var(--paper);                         /* Paper label: strong contrast on red. */
}

.button-primary:hover {
    background: var(--accent-deep);            /* A darker red on hover. */
    border-color: var(--accent-deep);                     /* Border follows the fill. */
    color: var(--paper);                         /* Label stays paper-coloured. */
}

.button[disabled] { opacity: 0.6; cursor: default; }   /* While the form is sending. */

/* ---- The scope ------------------------------------------------------------ */
.scope {
    --ink: #ECE8DF;                            /* Inside the instrument, text is light... */
    --paper: #1B1E22;                          /* ...on the dark body, so these tokens are redefined locally. */
    --dim: #A9A69D;                            /* Lighter secondary text for the dark body. */
    --rule: #34383E;                           /* Darker hairlines inside the instrument. */
    --field: #4A4F57;                          /* Key outlines inside the instrument. */
    --accent: var(--ch1);                      /* Controls on the instrument light up in the trace colour, not red. */
    margin: 0;                                 /* Remove the default figure margin. */
    padding: 1rem;                             /* The instrument's bezel. */
    background: var(--bezel);                  /* Instrument body. */
    color: var(--ink);                         /* Light text for everything inside. */
    border: 1px solid var(--rule);             /* Edge of the body. */
    border-radius: 6px;                        /* Slightly rounded case. */
}

.scope-screen {
    aspect-ratio: 10 / 7;                      /* Screen proportions on phones and tablets, close to a bench scope. */
    background: var(--screen);                 /* Darker than the body so the traces stand out. */
    border: 1px solid var(--rule);             /* Screen edge. */
    border-radius: 3px;                        /* Small radius inside the bezel. */
    overflow: hidden;                          /* Keep the trace glow inside the screen. */
}

@media (min-width: 62rem) {
    .scope-screen {
        aspect-ratio: auto;                    /* Beside the headline the screen is full width, so its height is set directly instead. */
        height: clamp(11rem, 36vh, 26rem);     /* About a third of the window height: the controls and readouts under it stay visible on a laptop without scrolling. */
    }
}

.scope-screen canvas {
    display: block;                            /* Remove the inline gap under the canvas. */
    width: 100%;                               /* Fill the screen box... */
    height: 100%;                              /* ...in both directions; scope.js sets the pixel size. */
}

.scope-legend {
    display: flex;                             /* Both channels on one line where there is room. */
    flex-wrap: wrap;                           /* Wrap on narrow screens. */
    gap: 0.25rem 1.5rem;                       /* Space between the two entries. */
    margin: 0.75rem 0 0;                       /* Space above only. */
    padding: 0;                                /* Remove list defaults. */
    list-style: none;                          /* No bullets. */
    font-size: 0.9rem;                         /* Smaller than body text. */
    color: var(--dim);                         /* Quiet. */
}

.swatch {
    display: inline-block;                     /* A small coloured bar before each label. */
    width: 1.1rem;                             /* Bar length. */
    height: 3px;                               /* Bar thickness, like a trace. */
    margin-right: 0.5rem;                      /* Space before the label. */
    vertical-align: middle;                    /* Centre on the text line. */
}

.swatch-ch1 { background: var(--ch1); }        /* Matches channel 1. */
.swatch-ch2 { background: var(--ch2); }        /* Matches channel 2. */

.scope-controls {
    display: flex;                             /* Slider and key side by side. */
    align-items: flex-end;                     /* Align the key with the slider track. */
    gap: 1rem;                                 /* Space between them. */
    margin-top: 1rem;                          /* Space above the controls. */
}

.knob {
    flex: 1;                                   /* The slider takes all remaining width. */
    display: grid;                             /* Label above the slider. */
    gap: 0.35rem;                              /* Space between label and slider. */
    font-size: 0.9rem;                         /* Small label. */
    color: var(--dim);                         /* Quiet label. */
}

.knob input {
    width: 100%;                               /* Full-width track. */
    accent-color: var(--accent);                /* Trace-coloured thumb and track, using the browser's own slider. */
    height: 1.75rem;                           /* Taller hit area for touch. */
    margin: 0;                                 /* Remove default margins. */
}

.button-key {
    min-width: 4.5rem;                         /* Same width whether it says Run or Stop, so nothing shifts. */
    text-align: center;                        /* Centre the label. */
}

.readouts {
    display: grid;                             /* Four values in a row... */
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;                              /* Space between values. */
    margin: 1rem 0 0;                          /* Space above only. */
    padding-top: 1rem;                         /* Room under the dividing line. */
    border-top: 1px solid var(--rule);         /* Separates readouts from controls. */
}

@media (max-width: 30rem) {
    .readouts { grid-template-columns: repeat(2, minmax(0, 1fr)); }   /* ...two by two on small phones. */
}

.readouts dt {
    font-size: 0.85rem;                        /* Small label. */
    color: var(--dim);                         /* Quiet label. */
}

.readouts dd {
    margin: 0;                                 /* Remove the default indent. */
    font-family: var(--mono);                  /* Fixed-width digits, so values do not jitter as they change. */
    font-size: 1.2rem;                         /* Readable at a glance. */
    font-variant-numeric: tabular-nums;        /* Every digit the same width. */
}

.scope figcaption {
    margin-top: 1rem;                          /* Space above the caption. */
    font-size: 0.9rem;                         /* Smaller than body text. */
    color: var(--dim);                         /* Quiet. */
}

/* ---- Content bands: heading in the margin, content beside it -------------- */
.band {
    display: grid;                             /* Heading and body share a grid. */
    gap: 1rem;                                 /* Space between them when stacked. */
    padding: clamp(2rem, 5vw, 3.5rem) var(--edge);   /* Vertical rhythm between sections. */
    border-top: 1px solid var(--rule);         /* One hairline between sections. */
}

@media (min-width: 52rem) {
    .band {
        grid-template-columns: 15rem minmax(0, 1fr);   /* Fixed margin column, flexible content column. */
        gap: 2rem;                                     /* Space between the columns. */
    }
}

h2 {
    margin: 0;                                 /* The grid handles spacing. */
    font-family: var(--head);                  /* Condensed heading face. */
    font-weight: 600;                          /* The loaded weight. */
    font-size: 1.9rem;                         /* Clearly a section heading. */
    line-height: 1.1;                          /* Tight for a short heading. */
    color: var(--accent);                       /* Redline marks the section names down the left edge. */
}

.band-body {
    display: grid;                             /* Entries sit in as many columns as fit... */
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 24rem), 1fr));   /* ...each at least 24rem wide: one column on a phone, two on a laptop. */
    gap: 2.25rem 3rem;                         /* Space between rows and between columns. */
    align-content: start;                      /* Rows keep their natural height. */
}

.entry h3 {
    margin: 0 0 0.4rem;                        /* Small gap before the paragraph. */
    font: 600 1.3rem/1.25 var(--text);         /* Semi-bold body face, a step above body size. */
}

.entry p { margin: 0 0 0.75rem; }              /* Paragraph spacing inside an entry. */

.entry p:last-child { margin-bottom: 0; }      /* No trailing gap after the last paragraph. */

.entry .status {
    color: var(--accent);                       /* Status lines stand out from descriptions. */
    font-weight: 500;                          /* Slightly stronger than body text. */
}

.entry .repo {
    font: 400 0.9rem var(--mono);              /* Small drawing-style lettering for the repository line. */
    color: var(--dim);                         /* Quiet until there is a real link to show. */
}

.entry .button { margin-top: 0.25rem; }        /* A little air above a button that follows text. */

/* ---- Contact --------------------------------------------------------------- */
.contact-line { margin: 0; }                   /* The grid gap handles spacing. */

.links {
    display: flex;                             /* Links in a row. */
    flex-wrap: wrap;                           /* They wrap onto a second line on a phone instead of widening the page. */
    gap: 0.5rem 1.5rem;                        /* Space between wrapped rows, and between links. */
    margin: 0;                                 /* Remove list defaults. */
    padding: 0;                                /* Remove list defaults. */
    list-style: none;                          /* No bullets. */
}

.contact-form {
    display: grid;                             /* Fields stack. */
    gap: 1.1rem;                               /* Space between fields. */
    max-width: 32rem;                          /* A form wider than this is harder to scan. */
}

.honeypot {
    position: absolute;                        /* Out of the layout. */
    left: -999rem;                             /* Off-screen: people never see it, bots still fill it. */
}

.form-group {
    display: grid;                             /* Label, field and error stack. */
    gap: 0.35rem;                              /* Small gap between them. */
}

.form-group label {
    font-size: 0.95rem;                        /* Slightly smaller than body text. */
    color: var(--dim);                         /* Quiet label. */
}

.form-group input,
.form-group textarea {
    width: 100%;                               /* Fill the form width. */
    padding: 0.65rem 0.75rem;                  /* Comfortable typing area. */
    background: var(--panel);                  /* White field on the paper page. */
    border: 1px solid var(--field);            /* Field edge. */
    border-radius: 3px;                        /* Matches the buttons. */
    color: var(--ink);                       /* Typed text colour. */
    font: inherit;                             /* Same face and size as the page, not the browser default. */
}

.form-group textarea { resize: vertical; }     /* Let people make the box taller, not wider. */

.form-group .invalid { border-color: var(--error); }   /* main.js adds this class to a field that failed validation. */

.field-error {
    display: none;                             /* Hidden until main.js marks it visible. */
    font-size: 0.9rem;                         /* Small helper text. */
    color: var(--error);                       /* Error colour. */
}

.field-error.visible { display: block; }       /* Shown next to the field that needs fixing. */

.contact-form .submit-btn { justify-self: start; }   /* Button keeps its natural width at the left. */

.form-status { display: none; }                /* Nothing to say until the form is sent. */

.form-status.visible {
    display: block;                            /* Show the result message. */
    font-weight: 500;                          /* Slightly stronger than body text. */
}

.form-status.error { color: var(--error); }    /* Sending failed. */
.form-status.success { color: var(--ok); }     /* Sent. */

/* ---- Footer: one plain line under a rule -------------------------------------- */
.footer {
    display: flex;                             /* One line: copyright, then the links. */
    flex-wrap: wrap;                           /* They stack on a phone. */
    justify-content: center;                   /* The single footer line sits in the middle of the page. */
    text-align: center;                        /* If it wraps on a phone, each line is centred too. */
    align-items: baseline;                     /* Line the text up on its baseline. */
    gap: 0.5rem 2rem;                          /* Space between them, and between wrapped rows. */
    padding: 1.25rem var(--edge) 3rem;         /* Room above, and at the very bottom of the page. */
    border-top: 1px solid var(--ink);          /* An ink rule closes the page. */
    font-size: 0.95rem;                        /* Slightly smaller than body text. */
    color: var(--dim);                         /* Quiet. */
}

.footer p { margin: 0; }                       /* The flex gap handles spacing. */

/* ==== Inner pages ========================================================== */

/* ---- Current page in the menu --------------------------------------------- */
.nav-list a[aria-current="page"] {
    color: var(--ink);                         /* The page you are on is shown in full ink... */
    text-decoration: underline;                /* ...and underlined... */
    text-decoration-color: var(--accent);      /* ...in redline, like a marked-up drawing. */
    text-decoration-thickness: 2px;            /* Same weight as text links. */
    text-underline-offset: 0.35em;             /* Clear of the letters. */
}

/* ---- Page title area -------------------------------------------------------- */
.page-head {
    padding: clamp(2rem, 5vw, 4rem) var(--edge) clamp(2rem, 4vw, 3rem);   /* Space around the title. */
}

.page-head h1 { margin-bottom: 1rem; }         /* Tighter gap than the homepage headline. */

.page-head .lede {
    margin: 0;                                 /* No buttons follow, so no bottom gap is needed. */
    max-width: 44rem;                          /* Readable line length. */
    font-size: 1.25rem;                        /* A step above body text. */
}

/* ---- Running text inside bands and articles --------------------------------- */
.band-body > * { min-width: 0; }               /* Let wide items (tables, the frame listing) shrink and scroll inside the column instead of widening the page. */

.band-body > :not(.entry) { grid-column: 1 / -1; }   /* Anything that is not an entry (text, lists, tables, instruments) spans the full width. */

.band-body > p,
.band-body > .prose-list {
    margin-top: 0;                             /* The grid gap spaces loose paragraphs and lists. */
    margin-bottom: 0;                          /* Same below. */
    max-width: 46rem;                          /* Running text keeps a readable line length even in a wide column. */
}

.prose-list {
    margin: 0;                                 /* The grid gap handles outer spacing. */
    padding-left: 1.25rem;                     /* Room for the bullets or numbers. */
    display: grid;                             /* Even gaps between items. */
    gap: 0.6rem;                               /* Space between items. */
}

.prose-list li::marker { color: var(--accent); }   /* Bullets and step numbers in redline. */

/* ---- Tables: ruled like a datasheet parameter table -------------------------- */
.table-wrap { overflow-x: auto; }              /* A wide table scrolls inside its box instead of breaking the page. */

table {
    width: 100%;                               /* Use the full content width. */
    border-collapse: collapse;                 /* Single lines between cells. */
    font-size: 1rem;                           /* Slightly smaller than body text. */
}

th, td {
    padding: 0.55rem 0.75rem 0.55rem 0;        /* Row height, and a gap between columns. */
    border-bottom: 1px solid var(--rule);      /* Hairline under every row. */
    text-align: left;                          /* Datasheet tables are left-aligned. */
    vertical-align: top;                       /* Multi-line cells start at the top. */
}

thead th {
    border-bottom: 1px solid var(--ink);       /* A stronger line under the header row. */
    font-weight: 600;                          /* Header labels in semi-bold. */
}

tbody th { font-weight: 500; }                 /* Row labels are a little stronger than values. */

td.num, code {
    font-family: var(--mono);                  /* Numbers, identifiers and code in the fixed-width face. */
    font-size: 0.95em;                         /* Mono looks larger than Plex Sans at the same size. */
}

/* ---- Timeline (About page) --------------------------------------------------- */
.timeline {
    display: grid;                             /* One row per period. */
    gap: 2rem;                                 /* Space between periods. */
    margin: 0;                                 /* Remove list defaults. */
}

.timeline dt {
    font: 500 0.95rem var(--mono);             /* The years, in drawing lettering. */
    color: var(--accent);                      /* Redline, so the eye can run down the dates. */
    margin-bottom: 0.25rem;                    /* Small gap before the role. */
}

.timeline dd { margin: 0; }                    /* Remove the default indent. */

.timeline dd h3 {
    margin: 0 0 0.4rem;                        /* Small gap before the description. */
    font: 600 1.3rem/1.25 var(--text);         /* Same style as entry headings. */
}

.timeline dd p { margin: 0; }                  /* One paragraph per period. */

/* ---- Articles (notes) --------------------------------------------------------- */
.article-wrap {
    display: grid;                             /* Article, and beside it the contents list. */
    grid-template-columns: minmax(0, 1fr);     /* One column on small screens; the zero minimum lets code blocks scroll instead of widening the page. */
    gap: 3rem;                                 /* Space between the two when stacked or side by side. */
    padding: 0 var(--edge) clamp(3rem, 6vw, 5rem);   /* Side margins, and space before the footer. */
}

.article {
    max-width: 46rem;                          /* The reading column. */
    min-width: 0;                              /* Allow it to shrink below the width of its widest code block. */
}

.toc { display: none; }                        /* The contents list is only shown where there is room beside the text. */

@media (min-width: 70rem) {
    .article-wrap {
        grid-template-columns: minmax(0, 46rem) minmax(14rem, 1fr);   /* Reading column, then the contents list in the remaining width. */
        gap: 5rem;                                                    /* Clear space between text and list. */
    }

    .toc {
        display: block;                        /* Show the list. */
        position: sticky;                      /* It stays in view while the article scrolls. */
        top: 2rem;                             /* Distance from the top of the window when stuck. */
        align-self: start;                     /* Needed for sticky to work inside a grid. */
        padding-left: 1.5rem;                  /* Space between its rule and its text. */
        border-left: 1px solid var(--rule);    /* A hairline separating it from the article. */
        font-size: 0.95rem;                    /* Slightly smaller than body text. */
    }

    .toc-title {
        margin: 0 0 0.75rem;                   /* Space under the small heading. */
        font: 500 0.85rem var(--mono);         /* Drawing lettering. */
        color: var(--dim);                     /* Quiet. */
    }

    .toc ol {
        margin: 0;                             /* Remove list defaults. */
        padding: 0;                            /* Remove list defaults. */
        list-style: none;                      /* No numbers; the order is clear from the layout. */
        display: grid;                         /* Even gaps between links. */
        gap: 0.5rem;                           /* Space between links. */
    }

    .toc a { text-decoration: none; }          /* Plain until hovered, like the menu. */
}

.article h2 {
    margin: 2.5rem 0 0.75rem;                  /* Space above each section of the article. */
    font-size: 1.6rem;                         /* Smaller than a band heading. */
    color: var(--ink);                         /* Article headings are ink; red is kept for the margin headings. */
}

.article p, .article ul, .article table { margin: 0 0 1.1rem; }   /* Paragraph rhythm. */

.article li { margin-bottom: 0.4rem; }         /* A little air between list items. */

.article .meta {
    font: 400 0.9rem var(--mono);              /* Author line in drawing lettering. */
    color: var(--dim);                         /* Quiet. */
}

pre {
    margin: 0 0 1.1rem;                        /* Same rhythm as paragraphs. */
    padding: 1rem;                             /* Space around the code. */
    background: var(--bezel);                  /* Code sits on the same dark surface as the instruments. */
    color: #ECE8DF;                            /* Light code text. */
    border-radius: 3px;                        /* Matches the buttons. */
    overflow-x: auto;                          /* Long lines scroll instead of breaking the layout. */
    font: 400 0.9rem/1.5 var(--mono);          /* Fixed-width code. */
}

pre code { font-size: inherit; }               /* Do not shrink code twice inside a pre block. */

/* ---- ISO-TP instrument (Firmware page) ---------------------------------------- */
.scope .field-row {
    display: flex;                             /* Label, slider and value on one line. */
    align-items: center;                       /* Vertically centred. */
    gap: 1rem;                                 /* Space between them. */
}

.scope .field-row output {
    min-width: 5.5rem;                         /* Fixed width so the slider does not shift as digits change. */
    font: 500 1.1rem var(--mono);              /* Readout style. */
    text-align: right;                         /* Numbers line up on the right. */
}

.frame-list {
    margin: 1rem 0 0;                          /* Space above the frame listing. */
    padding: 0.75rem;                          /* Space inside the screen. */
    list-style: none;                          /* No bullets. */
    background: var(--screen);                 /* The same dark screen as the oscilloscope. */
    border: 1px solid var(--rule);             /* Screen edge. */
    border-radius: 3px;                        /* Small radius inside the bezel. */
    max-height: 22rem;                         /* Long transfers scroll inside the screen... */
    overflow: auto;                            /* ...in both directions if needed. */
    font: 400 0.9rem/1.7 var(--mono);          /* Fixed-width bytes. */
    white-space: nowrap;                       /* One frame per line, never wrapped. */
}

.frame-list .tx { color: var(--ch1); }         /* Frames from the sender, in the channel 1 colour. */
.frame-list .rx { color: var(--ch2); }         /* Frames from the receiver, in the channel 2 colour. */
.frame-list .kind {
    display: inline-block;                     /* So it can have a fixed width. */
    width: 10.5rem;                            /* Frame names line up in a column. */
    color: var(--dim);                         /* Quieter than the bytes. */
}
