/* minterms.com — one stylesheet. Light, clean, one accent; logic gates and bits as the motif. */

:root {
  --page: #faf9f6;
  --surface: #ffffff;
  --tint: #f2f0ea;
  --ink: #1b1d22;
  --muted: #5c6370;
  --line: #dcdad3;
  --accent: #1f4fd8;
  --accent-soft: #e8edfc;
  --one: #e3ebff;          /* cells and rows that hold a 1 */
  --zero: transparent;     /* cells that hold a 0 */

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "Courier New", monospace;

  --radius: 8px;
  --gutter: 1.25rem;
}

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

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

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

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

a { color: var(--accent); text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }

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

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.6em; }
h1 { font-family: var(--serif); font-size: clamp(2rem, 5vw, 3rem); letter-spacing: -0.01em; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }

code, .expr, .bits, .truth { font-family: var(--mono); }
.expr { font-size: 1.08em; white-space: nowrap; }

.wrap { max-width: 68rem; margin: 0 auto; padding-inline: var(--gutter); }
.muted { color: var(--muted); font-size: 0.95rem; }
.scroll-x { overflow-x: auto; }

/* A complemented literal. Adjacent overbars must not merge into one long bar. */
.ov { text-decoration: overline; text-decoration-thickness: 0.08em; margin-right: 0.08em; }

.skip-link {
  position: absolute; left: var(--gutter); top: -4rem;
  padding: 0.5rem 1rem; background: var(--ink); color: #fff; border-radius: var(--radius); z-index: 10;
}
.skip-link:focus { top: 0.5rem; }

/* ---------- header and footer ---------- */

.site-header { border-bottom: 1px solid var(--line); background: var(--page); }
.site-header-inner, .site-footer-inner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1.5rem;
}
.site-header-inner { padding-block: 0.9rem; }

.wordmark { font-family: var(--serif); font-weight: bold; font-size: 1.3rem; color: var(--ink); text-decoration: none; }
.wordmark span { color: var(--accent); }
.wordmark-small { font-size: 1rem; }

.nav { display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; margin: 0; padding: 0; list-style: none; }
.nav a { color: var(--ink); text-decoration: none; padding-block: 0.25rem; border-bottom: 2px solid transparent; }
.nav a:hover, .nav a[aria-current="page"] { border-bottom-color: var(--accent); }

.site-footer { margin-top: 4rem; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.92rem; }
.site-footer-inner { padding-block: 1.75rem 2.5rem; }
.site-footer p { margin: 0; }
.site-footer .nav a { color: var(--muted); }

/* ---------- hero ---------- */

.hero { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); }

.bits {
  margin: 0; color: var(--line); letter-spacing: 0.55em; white-space: nowrap; overflow: hidden; user-select: none;
}
.hero > .bits { position: absolute; inset: 1rem 0 auto 0; padding-left: var(--gutter); font-size: 0.95rem; }
.bits-inline { margin-bottom: 1rem; }

.hero-inner {
  position: relative;
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 2.5rem; align-items: center;
  padding-block: 4.5rem 3.5rem;
}
.lead { font-size: 1.2rem; color: var(--muted); max-width: 34em; }

.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 1.75rem 0 0; }
.btn {
  display: inline-block; padding: 0.75rem 1.4rem; border-radius: var(--radius);
  background: var(--ink); color: #fff; border: 2px solid var(--ink);
  font-weight: 600; text-decoration: none;
}
.btn:hover { background: var(--accent); border-color: var(--accent); }
.btn-quiet { background: transparent; color: var(--ink); }
.btn-quiet:hover { background: var(--accent-soft); color: var(--ink); border-color: var(--ink); }

.hero-figure { margin: 0; padding: 1.25rem 1.25rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.hero-figure svg { display: block; width: 100%; height: auto; color: var(--ink); }
.hero-figure .gate-body { fill: var(--accent-soft); stroke: var(--accent); }
.hero-figure .labels { font-family: var(--mono); font-size: 12px; }
.hero-figure figcaption { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 0.92rem; text-align: center; overflow-x: auto; white-space: nowrap; }

/* ---------- sections ---------- */

.page-head { border-bottom: 1px solid var(--line); padding-block: 3rem 2rem; }
.section { padding-block: 3.25rem 1rem; }
.section-tint { background: var(--tint); border-block: 1px solid var(--line); padding-bottom: 3rem; margin-top: 2.25rem; }
.section-lead { color: var(--muted); max-width: 40em; margin-bottom: 1.75rem; }

.prose > * { max-width: 44rem; }
.prose h2 { margin-top: 2rem; font-size: 1.3rem; }

/* ---------- "what minimizing means" ---------- */

.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 1.25rem; margin: 0; padding: 0; list-style: none; }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem; }
.step h3 { display: flex; align-items: center; gap: 0.6rem; }
.step-number {
  display: inline-grid; place-items: center; flex: none; width: 1.7rem; height: 1.7rem;
  border-radius: 50%; background: var(--ink); color: #fff; font-family: var(--mono); font-size: 0.9rem;
}

.truth { border-collapse: collapse; font-size: 0.95rem; }
.truth th, .truth td { padding: 0.12rem 0.8rem; text-align: center; border-bottom: 1px solid var(--line); }
.truth thead th { border-bottom: 2px solid var(--ink); }
.truth tbody th { color: var(--muted); font-weight: normal; }
.truth .f { font-weight: bold; border-left: 1px solid var(--line); }
.truth .is-one { background: var(--one); }

.implicants { margin: 0; padding: 0; list-style: none; }
.implicants li { display: grid; grid-template-columns: 3.2rem 1fr auto; gap: 0.5rem; align-items: baseline; padding: 0.45rem 0; border-bottom: 1px solid var(--line); }
.implicants code { font-weight: bold; }
.implicants li > span { color: var(--muted); font-size: 0.95rem; }
.implicants li > .expr { color: var(--ink); font-size: 1rem; }

.result { margin-top: 1.25rem; padding: 0.8rem 1rem; background: var(--one); border-left: 4px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0; font-size: 1.15rem; overflow-x: auto; white-space: nowrap; }

/* ---------- cards ---------- */

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1.25rem; margin: 0 0 1.5rem; padding: 0; list-style: none; }
.card { position: relative; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem; }
.card p { color: var(--muted); font-size: 0.97rem; }
.card-gate { width: 4rem; height: auto; margin-bottom: 0.9rem; color: var(--muted); }
.card-status { margin: auto 0 0; padding-top: 0.5rem; font-size: 0.9rem; font-weight: 600; }

.card-live { border-color: var(--accent); box-shadow: 0 1px 0 var(--accent); }
.card-live .card-gate { color: var(--accent); }
.card-live .card-gate .gate-body { fill: var(--accent-soft); }
.card-live .card-status { color: var(--accent); }
.card-live:hover { background: var(--accent-soft); }
.card-link { color: var(--ink); text-decoration: none; }
.card-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }   /* whole card is the link */

/* ---------- lessons ---------- */

.lessons { margin: 0 0 1.5rem; padding: 0; list-style: none; counter-reset: lesson; max-width: 46rem; }
.lessons li { counter-increment: lesson; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem 0.75rem; padding: 0.8rem 0; border-bottom: 1px solid var(--line); }
.lessons li::before { content: counter(lesson, decimal-leading-zero); font-family: var(--mono); color: var(--accent); font-size: 0.9rem; }
.tag { font-size: 0.78rem; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 0.05rem 0.6rem; white-space: nowrap; }

/* ---------- lessons ---------- */

.eyebrow { margin-bottom: 0.75rem; font-size: 0.9rem; color: var(--muted); }
.eyebrow a { color: var(--muted); }

.lessons li > p { flex-basis: 100%; margin: 0 0 0 2.1rem; color: var(--muted); font-size: 0.95rem; }

.prose h2 { padding-top: 0.5rem; }
.prose h3 { margin-top: 1.75rem; }
.prose ul, .prose ol { padding-left: 1.4rem; margin: 0 0 1.2em; }
.prose li { margin-bottom: 0.45em; }
.prose code { background: var(--tint); border-radius: 4px; padding: 0.05em 0.35em; font-size: 0.95em; }

.expr-block { font-family: var(--mono); padding-left: 1rem; border-left: 3px solid var(--line); overflow-x: auto; white-space: nowrap; }

.note { background: var(--accent-soft); border-radius: var(--radius); padding: 1rem 1.2rem; margin: 1.5rem 0; }
.note p:last-child { margin-bottom: 0; }

.data { border-collapse: collapse; margin: 0 0 1.4rem; font-size: 0.97rem; }
.data th, .data td { padding: 0.4rem 0.9rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: baseline; }
.data thead th { border-bottom: 2px solid var(--ink); font-size: 0.9rem; white-space: nowrap; }
.data tbody th { font-weight: normal; white-space: nowrap; }

.qm td:nth-child(2), .qm td:nth-child(3) { font-family: var(--mono); }
.qm .group-start td { border-top: 2px solid var(--line); }
.qm .prime { color: var(--accent); font-weight: 600; }

.chart th, .chart td { text-align: center; }
.chart tbody th { text-align: left; }
.chart td { font-family: var(--mono); min-width: 2.4rem; }
.chart .done { background: var(--tint); color: var(--muted); }
.chart .only { display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border: 2px solid var(--accent); border-radius: 50%; line-height: 1; }
.chart .essential th, .chart .essential .chart-note { color: var(--accent); font-weight: 600; }
.chart .essential td, .chart .essential th { background: var(--one); }
.chart .selected td, .chart .selected th { background: #fdf6dc; }
.chart .dominated th, .chart .dominated td { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.chart .chart-note { font-family: var(--sans); font-size: 0.85rem; text-align: left; white-space: nowrap; text-decoration: none !important; }

.truth .is-dc { background: var(--tint); }

.kmap-figure { margin: 1.5rem 0; }
.kmap { display: block; height: auto; font-family: var(--mono); }
.kmap-head text { font-size: 13px; fill: var(--muted); }
.kmap-head .kmap-title { font-size: 14px; font-weight: bold; fill: var(--ink); }
.kmap-head line { stroke: var(--line); stroke-width: 1; }
.kmap .cell { fill: var(--surface); stroke: var(--ink); stroke-width: 1; }
.kmap .cell-1 { fill: var(--one); }
.kmap .cell-dc { fill: var(--tint); }
.kmap .value { font-size: 17px; fill: var(--ink); }
.kmap .value-1 { font-weight: bold; }
.kmap .value-0 { fill: #9aa0ab; }
.kmap .value-dc { fill: var(--muted); }
.kmap .number { font-size: 10px; fill: #4b5160; paint-order: stroke; stroke: #fff; stroke-width: 3px; stroke-linejoin: round; }
.kmap-group rect, .kmap-group path { fill-opacity: 0.1; stroke-width: 2.5; }
.kmap-group .fill-only { stroke: none; }
.kmap-group .stroke-only { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.kmap-legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.5rem; margin: 0.6rem 0 0; padding: 0 !important; list-style: none; font-size: 0.95rem; }
.kmap-legend li { display: flex; align-items: baseline; gap: 0.45rem; margin: 0; }
.swatch { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 3px; align-self: center; }

.node { margin: 1.25rem 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.node-title { margin: 0; padding: 0.6rem 1rem; background: var(--tint); border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 0.95rem; }
.node-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }
.node-col { padding: 0.8rem 1rem; border-right: 1px solid var(--line); }
.node-col:last-child { border-right: 0; background: var(--accent-soft); }
.node-col h4 { margin: 0 0 0.5rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
.node-col h4 span { text-transform: none; letter-spacing: 0; font-weight: normal; color: var(--muted); }
.node-col ul { margin: 0 !important; padding: 0 !important; list-style: none; }
.node-col li { margin: 0 0 0.3rem; font-size: 0.97rem; }
.val { font-family: var(--mono); font-weight: bold; }
sub.tag, .prose sub.tag { font-family: var(--mono); font-size: 0.72em; color: var(--accent); border: 0; padding: 0; }
.was { color: var(--muted); font-size: 0.82rem; }
.tick { color: #15803d; font-weight: bold; }

.tree-outline, .tree-outline ul { list-style: none; margin: 0; padding-left: 0 !important; }
.tree-outline { margin-bottom: 1.5rem; }
.tree-outline ul { margin: 0.4rem 0 0 0.6rem; border-left: 2px solid var(--line); }
.tree-outline ul > li { position: relative; padding-left: 1.4rem; margin-bottom: 0.4rem; }
.tree-outline ul > li::before { content: ""; position: absolute; left: 0; top: 0.85em; width: 1rem; border-top: 2px solid var(--line); }
.branch { display: inline-block; min-width: 3.6rem; font-family: var(--mono); font-size: 0.85rem; font-weight: bold; color: var(--accent); }
.tree-outline .tag { color: var(--accent); border-color: var(--accent); }

.expr-block.small { font-size: 0.85rem; white-space: normal; }
.chart .group-edge { border-left: 2px solid var(--ink); }

.node-next { margin: 0; padding: 0.5rem 1rem; border-top: 1px solid var(--line); font-size: 0.9rem; }
.collect { color: var(--accent); white-space: nowrap; }
.node:target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.tool-form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.5rem 1.5rem; margin-bottom: 2rem; }
.tool-form fieldset { border: 0; margin: 0 0 1.1rem; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; }
.tool-form legend { padding: 0; margin-bottom: 0.4rem; font-weight: 600; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }

/* One row of controls: every label is a single short line, every control has the same height and
   starts on the same line, and help text sits under its control - so nothing pushes a neighbour down. */
.fields { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1rem 1.25rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; flex: 1 1 13rem; min-width: 0; }
.field-small { flex: 0 0 7.5rem; }
.field-wide { flex-basis: 100%; }
.field:has(textarea) { flex-grow: 2; flex-basis: 18rem; }
.field .label { font-weight: 600; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); white-space: nowrap; }
.field .hint { font-size: 0.82rem; font-weight: normal; color: var(--muted); line-height: 1.35; }
.field input, .field select, .field textarea {
  font: inherit; font-weight: normal; font-size: 1rem; line-height: 1.5;
  box-sizing: border-box; width: 100%; min-height: 2.75rem; padding: 0.55rem 0.75rem;
  border: 1px solid #b9b6ad; border-radius: 6px; background: #fff; color: var(--ink);
}
.field input, .field textarea { font-family: var(--mono); font-size: 0.97rem; }
.field textarea { resize: vertical; min-height: 5.5rem; }
.field select { appearance: none; -webkit-appearance: none; padding-right: 2.2rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%231b1d22' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.8rem center; background-size: 0.7rem; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: #8d897e; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input::placeholder, .field textarea::placeholder { color: #a3a09a; }
.tool-form .actions { margin-top: 1.25rem; align-items: center; }
.tool-form .btn { padding: 0.6rem 1.3rem; }
.tool-form .error-box { margin: 1rem 0 0; }
.tool-form input[type="radio"] { accent-color: var(--accent); margin-right: 0.3rem; }
button.btn { font: inherit; font-weight: 600; cursor: pointer; }
.hidden { display: none !important; }
.error-box { padding: 0.8rem 1rem; border-left: 4px solid #b91c1c; background: #fdecec; border-radius: 0 var(--radius) var(--radius) 0; }
.tree-output.prose > * { max-width: none; }
.tree-output > h2 { margin-top: 2.25rem; }
.tree-output[aria-busy="true"] { opacity: 0.6; }

/* ---------- interactive tools ---------- */

.kmap-live .cell { cursor: pointer; }
.kmap-live .cell:hover { fill: var(--accent-soft); }
.kmap-live .cell:focus { outline: none; }
.kmap-live .cell:focus-visible { stroke: var(--accent); stroke-width: 3.5; }
.kmap-live text, .kmap-live .kmap-group { pointer-events: none; }
.kmap-live .value { user-select: none; }

.kmap-tool { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2rem 3rem; align-items: start; margin-bottom: 2rem; }
.kmap-answer h2 { font-size: 1.2rem; }
.kmap-help { margin-top: 0.5rem; }
kbd { font-family: var(--mono); font-size: 0.85em; padding: 0.05em 0.4em; border: 1px solid #b9b6ad; border-bottom-width: 2px; border-radius: 4px; background: #fff; }
.chip { font: inherit; font-size: 0.85rem; padding: 0.15rem 0.7rem; border: 1px solid #b9b6ad; border-radius: 99px; background: #fff; color: var(--ink); cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip-on { background: var(--ink); border-color: var(--ink); color: #fff; }
.alternatives { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; font-size: 0.95rem; }

.pla-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; }
.pla-grid pre { margin: 0; padding: 0.8rem 1rem; background: var(--tint); border-radius: var(--radius); font-size: 0.85rem; line-height: 1.35; max-height: 22rem; overflow: auto; }
.pla-grid h3 { margin: 0.75rem 0 0.4rem; font-size: 0.95rem; }

.circuit-frame { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin: 1rem 0; }
.circuit { display: block; height: auto; max-width: none; font-family: var(--mono); font-size: 14px; }
.circuit .wires path { fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linejoin: round; }
.circuit .wires .shared-wire { stroke: var(--accent); stroke-width: 2; }
.circuit .gate-body { fill: var(--surface); stroke: var(--ink); stroke-width: 1.8; stroke-linejoin: round; }
.circuit .gate-body.shared { fill: #cfdcff; stroke: var(--accent); stroke-width: 2.4; }
.circuit .dots circle { fill: var(--ink); }
.circuit .labels text { fill: var(--ink); }
.tt-grid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1rem 3rem; align-items: start; }
.tt-grid h2 { font-size: 1.2rem; margin-top: 1.75rem; }
.tt-grid > div > h2:first-child { margin-top: 0; }
.tt-grid details { margin-bottom: 0.75rem; }
.tt-grid summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.wrap-ok { white-space: normal; overflow-wrap: anywhere; }
.wrap-ok .expr { white-space: normal; }
[hidden] { display: none !important; }

.checks { padding-left: 1.4rem; }
.checks > li { margin-bottom: 1.4rem; }
.check-q { margin-bottom: 0.4rem; }
.checks summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 0.95rem; width: fit-content; }
.check-a { margin-top: 0.5rem; padding: 0.8rem 1rem; background: var(--tint); border-radius: var(--radius); }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 3rem; }
.pager a { display: block; padding: 1rem 1.2rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); text-decoration: none; font-weight: 600; }
.pager a:hover { border-color: var(--accent); background: var(--accent-soft); }
.pager a span { display: block; font-size: 0.8rem; font-weight: normal; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.pager-next { text-align: right; }

/* ---------- small screens ---------- */

@media (max-width: 48rem) {
  .kmap-tool, .tt-grid { grid-template-columns: minmax(0, 1fr); }
  .pager { grid-template-columns: 1fr; }
  .pager-next { text-align: left; }
  .hero-inner { grid-template-columns: minmax(0, 1fr); padding-block: 3.5rem 2.5rem; gap: 2rem; }
  .section { padding-top: 2.5rem; }
}

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