/* ─────────────────────────────────────────────────────────────────────────────
   Circuits DIY

   Every colour, font and dimension the Customizer offers arrives as a CSS
   custom property — --bh-accent, --bh-font-body, --bh-content-width and so on.
   The fallback after each var() is what the theme looks like before anything
   has been customised, and each matches the default declared in theme.json.

   That is the whole contract: the theme never reads a setting in PHP in order
   to style itself, so a change in the Customizer lands without a reload.
   ───────────────────────────────────────────────────────────────────────────── */

:root {
    --cd-accent:     var(--bh-accent, #e63329);
    --cd-accent-dk:  var(--bh-accent-dark, #b8241b);
    --cd-header-bg:  var(--bh-header-bg, #ffffff);
    --cd-utility-bg: var(--bh-utility-bg, #1e2430);
    --cd-footer-bg:  var(--bh-footer-bg, #1e2430);

    --cd-font:       var(--bh-font-body, Inter, system-ui, -apple-system, sans-serif);
    --cd-font-head:  var(--bh-font-heading, Inter, system-ui, -apple-system, sans-serif);
    --cd-size:       var(--bh-font-size, 16px);
    --cd-width:      var(--bh-content-width, 1240px);

    --cd-ink:        #16202e;
    --cd-ink-soft:   #5a6473;
    --cd-line:       #e4e8ee;
    --cd-surface:    #ffffff;
    --cd-page:       #f6f7f9;

    --cd-radius:     10px;
    --cd-shadow:     0 1px 2px rgba(22,32,46,.06), 0 8px 24px rgba(22,32,46,.06);
    --cd-shadow-lift:0 2px 4px rgba(22,32,46,.08), 0 16px 40px rgba(22,32,46,.10);
}

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

.cd-body {
    margin: 0;
    font-family: var(--cd-font);
    font-size: var(--cd-size);
    line-height: 1.65;
    color: var(--cd-ink);
    background: var(--cd-page);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--cd-font-head); line-height: 1.25; margin: 0; }
a { color: inherit; }
img { max-width: 100%; height: auto; display: block; }

.cd-wrap { width: 100%; max-width: var(--cd-width); margin: 0 auto; padding: 0 20px; }
.cd-ico { width: 1.15em; height: 1.15em; display: inline-block; vertical-align: -.18em; flex-shrink: 0; }

.sr-only, .cd-skip:not(:focus) {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.cd-skip:focus {
    position: fixed; z-index: 200; top: 12px; left: 12px;
    background: var(--cd-accent); color: #fff;
    padding: 10px 16px; border-radius: var(--cd-radius); font-weight: 600;
}

/* ── utility bar ─────────────────────────────────────────────────────────── */

.cd-utility { background: var(--cd-utility-bg); font-size: .78rem; }
.cd-utility__list {
    display: flex; flex-wrap: wrap; gap: 0 1.35rem;
    list-style: none; margin: 0; padding: .5rem 0;
}
.cd-utility a { color: rgba(255,255,255,.72); text-decoration: none; transition: color .15s; }
.cd-utility a:hover { color: #fff; }

/* Below 900px this is the first thing to go: every one of these pages is also
   in the footer, and the space is worth more than the links. */
@media (max-width: 900px) { .cd-utility { display: none; } }

/* ── masthead ────────────────────────────────────────────────────────────── */

.cd-masthead { background: var(--cd-header-bg); border-bottom: 1px solid var(--cd-line); }
.cd-masthead__inner {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1.5rem; padding-top: 1.15rem; padding-bottom: 1.15rem;
}
.cd-logo { display: block; text-decoration: none; flex-shrink: 0; }
.cd-logo img { max-height: 58px; width: auto; }
.cd-logo__text { display: block; font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; }
.cd-logo__tag { display: block; font-size: .78rem; color: var(--cd-ink-soft); margin-top: .1rem; }

.cd-search { position: relative; display: flex; max-width: 340px; flex: 1; }
.cd-search input {
    width: 100%;
    padding: .6rem 2.6rem .6rem .9rem;
    border: 1px solid var(--cd-line);
    border-radius: 999px;
    font: inherit; font-size: .875rem;
    background: var(--cd-page);
    color: inherit;
}
.cd-search input:focus {
    outline: none; background: #fff;
    border-color: var(--cd-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--cd-accent) 16%, transparent);
}
.cd-search button {
    position: absolute; right: .3rem; top: 50%; transform: translateY(-50%);
    width: 34px; height: 34px;
    display: grid; place-items: center;
    border: 0; border-radius: 50%;
    background: none; color: var(--cd-ink-soft); cursor: pointer;
}
.cd-search button:hover { color: var(--cd-accent); }
.cd-search--page { max-width: 520px; margin: 0 auto 2rem; }

@media (max-width: 720px) {
    .cd-masthead__inner { flex-wrap: wrap; gap: .9rem; }
    .cd-search { max-width: none; order: 3; }
}

/* ── navigation ──────────────────────────────────────────────────────────── */

.cd-nav { background: var(--cd-header-bg); border-bottom: 2px solid var(--cd-accent); }
.cd-nav.is-sticky { position: sticky; top: 0; z-index: 60; box-shadow: 0 2px 12px rgba(22,32,46,.07); }
.cd-nav__inner { display: flex; align-items: center; }

.cd-nav__toggle {
    display: none; align-items: center; gap: .5rem;
    padding: .7rem 0; border: 0; background: none;
    font: inherit; font-weight: 600; color: inherit; cursor: pointer;
}

/* Core's menu_html() supplies the markup and the open/close behaviour. This
   restyles it into a horizontal bar with a mega panel. */
.cd-menu { gap: 0; }
.cd-menu > .bh-menu__item > .bh-menu__link {
    padding: .85rem 1rem;
    font-size: .875rem; font-weight: 600; letter-spacing: .01em;
    text-transform: uppercase;
    position: relative;
}
.cd-menu > .bh-menu__item > .bh-menu__link::after {
    content: ''; position: absolute; left: 1rem; right: 1rem; bottom: 0;
    height: 3px; background: var(--cd-accent);
    transform: scaleX(0); transform-origin: left;
    transition: transform .18s ease;
}
.cd-menu > .bh-menu__item:hover > .bh-menu__link::after,
.cd-menu > .bh-menu__item.is-open > .bh-menu__link::after { transform: scaleX(1); }

/* The mega panel.
   A parent whose children have children becomes a multi-column layout rather
   than a stack of nested dropdowns — a category tree three levels deep as
   cascading menus is close to unusable with a mouse. */
.cd-menu > .bh-menu__item--parent > .bh-submenu {
    display: flex; gap: 2.5rem;
    min-width: min(880px, calc(100vw - 40px));
    padding: 1.6rem 1.8rem;
    border-radius: 0 0 var(--cd-radius) var(--cd-radius);
    box-shadow: var(--cd-shadow-lift);
}
.cd-menu > .bh-menu__item--parent > .bh-submenu > .bh-menu__item { flex: 1; min-width: 0; }
.cd-menu > .bh-menu__item--parent > .bh-submenu > .bh-menu__item > .bh-menu__link {
    font-size: .72rem; font-weight: 700; letter-spacing: .08em;
    text-transform: uppercase; color: var(--cd-accent);
    padding: 0 0 .5rem; margin-bottom: .4rem;
    border-bottom: 1px solid var(--cd-line);
    pointer-events: none;               /* a column heading is a label, not a link */
}
.cd-menu > .bh-menu__item--parent > .bh-submenu > .bh-menu__item > .bh-menu__link .bh-menu__caret { display: none; }

/* Third level: a plain list inside its column, not another floating panel. */
.cd-menu .bh-submenu .bh-submenu {
    position: static; opacity: 1; visibility: visible; transform: none;
    display: block; min-width: 0; padding: 0;
    border: 0; box-shadow: none; background: none;
}
.cd-menu .bh-submenu .bh-submenu .bh-menu__link {
    padding: .3rem 0; font-size: .84rem; color: var(--cd-ink-soft);
}
.cd-menu .bh-submenu .bh-submenu .bh-menu__link:hover { color: var(--cd-accent); background: none; }

@media (max-width: 900px) {
    .cd-nav__inner { flex-wrap: wrap; }
    .cd-nav__toggle { display: inline-flex; }
    .cd-nav__menu { display: none; width: 100%; padding-bottom: .75rem; }
    .cd-nav__menu.is-open { display: block; }
    .cd-menu { display: block; }
    .cd-menu > .bh-menu__item > .bh-menu__link { padding: .6rem 0; }
    .cd-menu > .bh-menu__item > .bh-menu__link::after { display: none; }
    .cd-menu > .bh-menu__item--parent > .bh-submenu {
        display: block; min-width: 0; padding: 0 0 0 1rem;
        position: static; opacity: 1; visibility: visible; transform: none;
        box-shadow: none; border: 0;
    }
}

/* ── the grid ────────────────────────────────────────────────────────────── */

.cd-main { padding: 2rem 0 3.5rem; }

.cd-pagehead { margin-bottom: 1.75rem; }
.cd-pagehead h1 { font-size: clamp(1.6rem, 3vw, 2.15rem); font-weight: 800; letter-spacing: -.02em; }
.cd-pagehead p { color: var(--cd-ink-soft); margin: .5rem 0 0; max-width: 62ch; }

.cd-grid { display: grid; gap: 1.4rem; grid-template-columns: repeat(3, 1fr); }
[data-columns="2"] .cd-grid { grid-template-columns: repeat(2, 1fr); }
[data-columns="4"] .cd-grid { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1080px) { .cd-grid, [data-columns="4"] .cd-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) {
    .cd-grid, [data-columns="2"] .cd-grid, [data-columns="4"] .cd-grid { grid-template-columns: 1fr; }
}

.cd-card {
    background: var(--cd-surface);
    border-radius: var(--cd-radius);
    overflow: hidden;
    display: flex; flex-direction: column;
    transition: transform .18s ease, box-shadow .18s ease;
}
.cd-cards--raised   .cd-card { box-shadow: var(--cd-shadow); }
.cd-cards--outlined .cd-card { border: 1px solid var(--cd-line); }
.cd-cards--plain    .cd-card { background: none; }
.cd-cards--raised .cd-card:hover { transform: translateY(-3px); box-shadow: var(--cd-shadow-lift); }

.cd-card__media { display: block; aspect-ratio: 16 / 10; background: var(--cd-page); overflow: hidden; }
.cd-card__media img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; }
.cd-card:hover .cd-card__media img { transform: scale(1.04); }

.cd-card__body { padding: 1rem 1.05rem 1.1rem; display: flex; flex-direction: column; gap: .5rem; flex: 1; }
.cd-card__title { font-size: 1.02rem; font-weight: 700; line-height: 1.35; letter-spacing: -.01em; }
.cd-card__title a { text-decoration: none; }
.cd-card__title a:hover { color: var(--cd-accent); }
.cd-card__excerpt {
    margin: 0; font-size: .875rem; color: var(--cd-ink-soft); line-height: 1.6;
    /* Three lines, so one long excerpt cannot make a card taller than its row. */
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.cd-card__meta {
    margin-top: auto; padding-top: .55rem;
    display: flex; flex-wrap: wrap; gap: .75rem;
    font-size: .78rem; color: var(--cd-ink-soft);
    border-top: 1px solid var(--cd-line);
}
.cd-cards--plain .cd-card__meta { border-top-color: transparent; }
.cd-card__author { font-weight: 600; color: var(--cd-ink); }

/* ── article ─────────────────────────────────────────────────────────────── */

.cd-single { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 2.5rem; align-items: start; }
.cd-single--page { grid-template-columns: minmax(0, 1fr); max-width: 820px; }
@media (max-width: 1000px) { .cd-single { grid-template-columns: minmax(0, 1fr); } }

.cd-article {
    background: var(--cd-surface);
    border-radius: var(--cd-radius);
    padding: clamp(1.4rem, 4vw, 2.6rem);
    box-shadow: var(--cd-shadow);
}
.cd-article__terms { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .9rem; }
.cd-article__terms a {
    font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
    color: var(--cd-accent); text-decoration: none;
    padding: .22rem .6rem; border-radius: 999px;
    background: color-mix(in srgb, var(--cd-accent) 10%, transparent);
}
.cd-article__title {
    font-size: clamp(1.6rem, 3.6vw, 2.4rem); font-weight: 800;
    letter-spacing: -.025em; margin-bottom: .8rem;
}
.cd-article__meta {
    display: flex; flex-wrap: wrap; gap: .35rem 1.1rem;
    font-size: .82rem; color: var(--cd-ink-soft);
    padding-bottom: 1.25rem; border-bottom: 1px solid var(--cd-line);
}
.cd-article__hero { margin: 1.5rem 0; border-radius: var(--cd-radius); overflow: hidden; }
.cd-article__after { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--cd-line); }

/* ── prose ───────────────────────────────────────────────────────────────── */

.cd-prose { font-size: 1.02rem; line-height: 1.75; }
.cd-prose > * + * { margin-top: 1.15em; }
.cd-prose h2 { font-size: 1.5rem; font-weight: 700; margin-top: 2em; letter-spacing: -.015em; }
.cd-prose h3 { font-size: 1.2rem; font-weight: 700; margin-top: 1.6em; }
.cd-prose a { color: var(--cd-accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.cd-prose a:hover { color: var(--cd-accent-dk); }
.cd-prose img, .cd-prose figure { border-radius: var(--cd-radius); }
.cd-prose ul, .cd-prose ol { padding-left: 1.35em; }
.cd-prose li + li { margin-top: .35em; }
.cd-prose blockquote {
    margin-left: 0; padding: .2rem 0 .2rem 1.15rem;
    border-left: 3px solid var(--cd-accent);
    color: var(--cd-ink-soft); font-style: italic;
}
/* Code is the substance of this site, so it gets real attention. */
.cd-prose pre {
    background: #10151d; color: #e6edf3;
    padding: 1.1rem 1.25rem; border-radius: var(--cd-radius);
    overflow-x: auto; font-size: .84rem; line-height: 1.65;
    /* Tabs default to eight columns, which wrecks an Arduino sketch. */
    tab-size: 4;
}
.cd-prose :not(pre) > code {
    background: color-mix(in srgb, var(--cd-accent) 9%, transparent);
    color: var(--cd-accent-dk);
    padding: .12em .38em; border-radius: 4px;
    font-size: .88em;
}
.cd-prose table { width: 100%; border-collapse: collapse; font-size: .9rem; display: block; overflow-x: auto; }
.cd-prose th, .cd-prose td { padding: .55rem .75rem; border: 1px solid var(--cd-line); text-align: left; }
.cd-prose th { background: var(--cd-page); font-weight: 600; }

.cd-sidebar { position: sticky; top: 5rem; display: flex; flex-direction: column; gap: 1.25rem; }
@media (max-width: 1000px) { .cd-sidebar { position: static; } }

.cd-related { margin-top: 3rem; }
.cd-related__title { font-size: 1.3rem; font-weight: 700; margin-bottom: 1.2rem; letter-spacing: -.015em; }

/* ── pagination ──────────────────────────────────────────────────────────── */

.cd-pager {
    display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
    gap: .4rem; margin-top: 2.75rem;
}
.cd-pager__list { display: flex; align-items: center; gap: .3rem; list-style: none; margin: 0; padding: 0; }
.cd-pager__num, .cd-pager__step {
    display: inline-flex; align-items: center; gap: .3rem;
    min-width: 38px; height: 38px; padding: 0 .75rem;
    justify-content: center;
    border-radius: 8px; border: 1px solid var(--cd-line);
    background: var(--cd-surface); color: inherit;
    font-size: .875rem; font-weight: 600; text-decoration: none;
}
.cd-pager__num:hover, .cd-pager__step:hover { border-color: var(--cd-accent); color: var(--cd-accent); }
.cd-pager__num.is-current { background: var(--cd-accent); border-color: var(--cd-accent); color: #fff; }
.cd-pager__gap { padding: 0 .3rem; color: var(--cd-ink-soft); }
@media (max-width: 560px) { .cd-pager__step span { display: none; } }

/* ── footer ──────────────────────────────────────────────────────────────── */

.cd-footer { background: var(--cd-footer-bg); color: rgba(255,255,255,.72); padding: 3rem 0 1.5rem; }
.cd-footer__grid { display: grid; gap: 2.25rem; grid-template-columns: repeat(3, 1fr) 1.4fr; }
@media (max-width: 1000px) { .cd-footer__grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .cd-footer__grid { grid-template-columns: 1fr; } }

.cd-footer__heading {
    font-size: .78rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
    color: var(--cd-accent); margin-bottom: .85rem;
}
.cd-footer__col ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.cd-footer a { color: rgba(255,255,255,.72); text-decoration: none; font-size: .9rem; }
.cd-footer a:hover { color: #fff; }

.cd-footer__logo { max-height: 46px; width: auto; margin-bottom: .9rem; }
.cd-footer__logotext { font-size: 1.25rem; font-weight: 800; color: #fff; margin-bottom: .6rem; }
.cd-footer__tagline { font-size: .875rem; line-height: 1.6; margin: 0 0 1.1rem; max-width: 34ch; }

.cd-social { display: flex; flex-wrap: wrap; gap: .5rem; list-style: none; margin: 0; padding: 0; }
.cd-social a {
    display: grid; place-items: center; width: 36px; height: 36px;
    border-radius: 50%; background: rgba(255,255,255,.08); color: rgba(255,255,255,.8);
    transition: background .15s, color .15s;
}
.cd-social a:hover { background: var(--cd-accent); color: #fff; }

.cd-footer__base {
    margin-top: 2.5rem; padding-top: 1.25rem;
    border-top: 1px solid rgba(255,255,255,.1);
    font-size: .82rem; text-align: center;
}
.cd-footer__base p { margin: 0; }

/* ── odds and ends ───────────────────────────────────────────────────────── */

.cd-empty {
    background: var(--cd-surface); border-radius: var(--cd-radius);
    padding: 3rem 1.5rem; text-align: center; color: var(--cd-ink-soft);
    box-shadow: var(--cd-shadow);
}
.cd-empty--404 h1 { font-size: 1.8rem; font-weight: 800; color: var(--cd-ink); margin-bottom: .6rem; }

.cd-btn {
    display: inline-block; padding: .65rem 1.4rem;
    background: var(--cd-accent); color: #fff;
    border-radius: 999px; font-weight: 600; font-size: .9rem; text-decoration: none;
}
.cd-btn:hover { background: var(--cd-accent-dk); }

.cd-totop {
    position: fixed; right: 1.1rem; bottom: 1.1rem; z-index: 70;
    width: 42px; height: 42px; display: grid; place-items: center;
    border: 0; border-radius: 50%;
    background: var(--cd-accent); color: #fff;
    box-shadow: var(--cd-shadow-lift); cursor: pointer;
}
.cd-totop[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
    .cd-card:hover { transform: none; }
    .cd-card:hover .cd-card__media img { transform: none; }
}

@media print {
    .cd-utility, .cd-nav, .cd-footer, .cd-totop, .cd-search, .cd-sidebar { display: none !important; }
    .cd-article { box-shadow: none; padding: 0; }
}
