/* ============================================================
   Boolean Algebra & Logic — A-level CS study site
   Plain CSS, light/dark aware, print friendly.
   ============================================================ */

:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --text: #1b2430;
  --muted: #5b6776;
  --border: #d9e1ec;
  --accent: #3a5bd9;
  --accent-2: #6a3ad9;
  --accent-soft: #e7ecfd;
  --ok: #1f8a52;
  --code-bg: #f1f4fa;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 8px 24px rgba(20, 30, 50, .06);
  --radius: 14px;
  --maxw: 1000px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #161d27;
    --surface-2: #1d2733;
    --text: #e7edf5;
    --muted: #9fb0c3;
    --border: #29333f;
    --accent: #7c97ff;
    --accent-2: #b18cff;
    --accent-soft: #1d2740;
    --ok: #4cc98a;
    --code-bg: #121925;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Header / nav ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.nav {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand {
  font-weight: 800;
  letter-spacing: -.02em;
  text-decoration: none;
  color: var(--text);
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.brand .logic-dot {
  width: 1.4rem; height: 1.4rem; border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: inline-block;
}
.nav-links {
  display: flex;
  gap: .25rem;
  flex-wrap: wrap;
  margin-left: auto;
}
.nav-links a {
  text-decoration: none;
  color: var(--muted);
  padding: .35rem .6rem;
  border-radius: 8px;
  font-size: .92rem;
  font-weight: 600;
}
.nav-links a:hover { background: var(--surface-2); color: var(--text); }
.nav-links a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

/* ---------- Board toggle ---------- */
.board-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
}
.board-toggle button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: .82rem;
  padding: .35rem .8rem;
  cursor: pointer;
}
.board-toggle button[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}

/* ---------- Layout ---------- */
main { max-width: var(--maxw); margin: 0 auto; padding: 1.5rem 1rem 4rem; }
section { margin: 2.2rem 0; }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); letter-spacing: -.02em; margin: .2rem 0 .4rem; }
h2 { font-size: 1.4rem; letter-spacing: -.01em; margin-top: 2rem; padding-top: .4rem; }
h3 { font-size: 1.1rem; margin: 1.4rem 0 .4rem; }
.lead { font-size: 1.1rem; color: var(--muted); max-width: 65ch; }
.muted { color: var(--muted); }

.tagline { color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; }

/* ---------- Cards ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .step { font-size: .75rem; font-weight: 800; color: var(--accent); letter-spacing: .06em; }
.card h3 { margin: .3rem 0 .3rem; }
.card p { margin: 0; color: var(--muted); font-size: .95rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  box-shadow: var(--shadow);
}

.callout {
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 10px;
  padding: .8rem 1rem;
  margin: 1rem 0;
  font-size: .95rem;
}
.callout.board-note { border-left-color: var(--accent-2); }
.callout strong { color: var(--text); }

/* ---------- Tables ---------- */
table {
  border-collapse: collapse;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
caption { text-align: left; color: var(--muted); font-size: .9rem; padding: .3rem 0; }
th, td { padding: .5rem .7rem; text-align: center; border-bottom: 1px solid var(--border); }
thead th { background: var(--surface-2); font-size: .9rem; }
tbody tr:last-child td { border-bottom: 0; }
td.t { color: var(--ok); font-weight: 700; }   /* a 1 / true */
td.f { color: var(--muted); }                   /* a 0 / false */
.table-scroll { overflow-x: auto; }

.truth { max-width: 460px; }
.truth th, .truth td { min-width: 2.6rem; }

/* ---------- Boolean expressions ---------- */
.expr, var, .bool {
  font-family: "SFMono-Regular", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
  font-style: normal;
}
.expr { font-size: 1.02em; }
.expr var { color: var(--accent); font-weight: 600; }
.expr .op { color: var(--muted); }
.expr .ovl, .ovl { text-decoration: overline; text-decoration-thickness: .08em; }
.expr-block {
  display: block;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .7rem .9rem;
  margin: .5rem 0;
  font-size: 1.05rem;
  overflow-x: auto;
}
.expr-block.center { text-align: center; }

/* law list */
.laws { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: .8rem; }
.law { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .8rem 1rem; }
.law h4 { margin: 0 0 .35rem; font-size: .98rem; }
.law .forms { display: flex; flex-direction: column; gap: .25rem; }

/* ---------- SVG diagrams & gates ---------- */
svg.gate, svg.diagram {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  color: var(--text);
}
svg.gate { width: 86px; height: 52px; color: var(--accent); }
svg.diagram { width: 100%; max-width: 560px; height: auto; display: block; margin: .5rem 0; }
svg.diagram text, svg.gate text { fill: currentColor; stroke: none; font-family: inherit; font-size: 14px; font-weight: 600; }
svg .dot { fill: currentColor; stroke: none; }
svg .wire { stroke: var(--muted); }
svg .blk { fill: var(--surface-2); stroke: var(--border); }

.gate-table td { vertical-align: middle; }
.gate-table td.sym { width: 110px; }

/* Karnaugh map */
.kmap { border-collapse: collapse; margin: .6rem 0; width: auto; }
.kmap th, .kmap td { border: 1px solid var(--border); min-width: 2.8rem; height: 2.8rem; }
.kmap .corner { background: var(--surface-2); font-size: .85rem; color: var(--muted); }
.kmap td.one { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.kmap .grp1 { box-shadow: inset 0 0 0 3px var(--accent); }
.kmap .grp2 { box-shadow: inset 0 0 0 3px var(--accent-2); }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: .88rem;
}
.site-footer .inner { max-width: var(--maxw); margin: 0 auto; padding: 1.4rem 1rem; }
.site-footer a { color: var(--accent); }

/* ---------- Misc ---------- */
.pill { display:inline-block; background: var(--surface-2); border:1px solid var(--border); border-radius:999px; padding:.1rem .6rem; font-size:.78rem; font-weight:700; color: var(--muted); }
.pill.ocr { color: var(--accent); border-color: var(--accent); }
.pill.aqa { color: var(--accent-2); border-color: var(--accent-2); }
ul.tight { margin: .4rem 0; padding-left: 1.2rem; }
ul.tight li { margin: .2rem 0; }
.cols { display:grid; grid-template-columns: 1fr 1fr; gap:1.2rem; }
@media (max-width: 640px){ .cols { grid-template-columns: 1fr; } }

/* show/hide by board (used for prose differences) */
[data-board="aqa"] .only-ocr { display: none; }
[data-board="ocr"] .only-aqa { display: none; }

/* ---------- Practice activity ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .8rem; }
.tabs button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font: inherit; font-weight: 700; font-size: .85rem;
  padding: .35rem .7rem; border-radius: 8px; cursor: pointer;
}
.tabs button:hover { border-color: var(--accent); color: var(--text); }
.tabs button[aria-current="true"] {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent;
}
.tabs button.solved::after { content: " ✓"; color: var(--ok); }
.tabs button[aria-current="true"].solved::after { color: #fff; }

.practice .question {
  font-size: 1.6rem; text-align: center; padding: 1.2rem .8rem; margin: .2rem 0 1.2rem;
}
.qexpr { font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace; }
.qexpr var { color: var(--accent); font-weight: 600; font-style: normal; }
.qexpr .op { color: var(--muted); }

.answer-label { font-weight: 700; display: block; margin-bottom: .4rem; }
.answer-input {
  width: 100%; font-size: 1.3rem; padding: .6rem .8rem;
  font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
}
.answer-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.keypad { display: flex; flex-direction: column; align-items: center; gap: .5rem; margin: 1rem 0; }
.keypad .krow { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
.keypad button {
  min-width: 3.2rem; height: 3.2rem; font-size: 1.25rem; font-weight: 700;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
  font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
}
.keypad button:hover { border-color: var(--accent); }
.keypad button:active { transform: translateY(1px); }
.keypad button.util { font-size: .8rem; background: var(--surface); color: var(--muted); font-family: inherit; }

.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .4rem; }
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 700; padding: .5rem 1rem; border-radius: 10px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }

.feedback { margin-top: 1rem; padding: .75rem 1rem; border-radius: 10px; font-weight: 600; min-height: 1.2rem; display: none; }
.feedback.show { display: block; }
.feedback.correct { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent); }
.feedback.partial { background: #fff4e0; color: #9a6700; border: 1px solid #f0c674; }
.feedback.wrong   { background: #fdeaea; color: #b42318; border: 1px solid #f3b4ae; }
.feedback.info    { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
@media (prefers-color-scheme: dark) {
  .feedback.partial { background: #3a2e12; color: #f0c674; border-color: #6b551f; }
  .feedback.wrong   { background: #3a1c18; color: #f3b4ae; border-color: #6e2b22; }
}

/* ---------- Interactive K-map ---------- */
.kmap-wrap { display: grid; grid-template-columns: auto 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 640px) { .kmap-wrap { grid-template-columns: 1fr; } }
.kmap-live td { transition: box-shadow .08s ease; }
.kmap-live td.one { cursor: pointer; }
.kmap-live td.one:hover { box-shadow: inset 0 0 0 2px var(--accent); }
.kmap-live td.zero { color: var(--muted); }
.kmap-live td.one.sel { box-shadow: inset 0 0 0 3px var(--accent); }
.kmap-live td.covered { position: relative; }
.kmap-live td.covered::after {
  content: ""; position: absolute; top: 3px; right: 3px;
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
}
.kmap-side { min-width: 0; }
.gchips { display: flex; flex-wrap: wrap; gap: .4rem; min-height: 1.5rem; }
.gchip {
  background: var(--surface); border: 2px solid var(--border); border-radius: 999px;
  padding: .25rem .7rem; font: inherit; font-weight: 700; cursor: pointer;
}
.gchip:hover { filter: brightness(1.05); }
hr.rule { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }

@media print {
  .site-header, .site-footer, .board-toggle { display: none; }
  body { background: #fff; }
  .card, .panel, table, .law { box-shadow: none; }
}
