/* Gates: a green circuit board with copper traces and a paper datasheet */
@font-face { font-family: "Young Serif"; font-display: swap; src: url(../fonts/young-serif-latin-400-normal.woff2) format("woff2"); }

:root {
  --bg: #173B2C;          /* solder mask */
  --bg2: #1D4736;
  --dot: #2A5A45;
  --silk: #EEF1E7;        /* silkscreen white */
  --muted: #A9C2B3;
  --copper: #B97A3C;
  --lit: #FFD25A;
  --paper: #F3F5EF;
  --ink: #12261C;
  --ink-muted: #5B6F62;
  --rule: #D5DDD3;
  --ok: #3E9B5A;
  --bad: #D9473C;
  --display: "Young Serif", Georgia, serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--silk); font-family: var(--ui); line-height: 1.45; min-height: 100vh; }
a { color: inherit; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--lit); outline-offset: 2px; }

.wrap { max-width: 560px; margin: 0 auto; padding: 0 14px; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 0 0; }
.back { text-decoration: none; color: var(--muted); font-size: 0.95rem; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; }
.icon-btn:hover { background: var(--bg2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.title-row { display: flex; align-items: baseline; justify-content: space-between; padding: 4px 0 10px; }
h1 { font-family: var(--display); font-weight: 400; font-size: 2.2rem; margin: 0; line-height: 1; }
.sub { margin: 0; color: var(--muted); font-size: 0.95rem; }

.layout { display: grid; gap: 12px; grid-template-areas: "steps" "sheet" "board" "build"; }
.steps { grid-area: steps; }
.sheet { grid-area: sheet; }
.boardwrap { grid-area: board; }
.build { grid-area: build; }
@media (min-width: 900px) {
  .wrap { max-width: 1060px; }
  .layout { grid-template-columns: 400px 1fr; grid-template-areas: "steps steps" "sheet board" "build board"; align-items: start; column-gap: 22px; }
  .boardwrap { position: sticky; top: 14px; }
}

/* datasheet */
.sheet { background: var(--paper); color: var(--ink); border-radius: 6px; padding: 10px 10px 8px; box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.allowed { margin: 0 0 10px; font-weight: 700; }
.allowed span { font-family: var(--mono); font-weight: 600; }

/* board */
.boardwrap { overflow-x: auto; border-radius: 10px; background-color: var(--bg2); background-image: radial-gradient(var(--dot) 1.2px, transparent 1.3px); background-size: 16px 16px; border: 1.5px solid #2E6049; padding: 6px; }
.board { width: 100%; display: block; max-height: 70vh; }
.board .trace { fill: none; stroke: var(--copper); stroke-width: 3; stroke-linecap: round; }
.board .trace.lit { stroke: var(--lit); }
.board .trace.open { stroke-dasharray: 3 3; }
.board .open-pad { fill: none; stroke: var(--copper); stroke-width: 2; }
.board .faded { opacity: .35; }
.board .pad { fill: var(--bg); stroke: var(--copper); stroke-width: 3; }
.board .pad.lit { fill: var(--lit); stroke: var(--lit); }
.board .pad.out.ok { stroke: #8FE3A2; }
.board .pad.out.bad { stroke: #FF7A6E; stroke-dasharray: 4 3; }
.board .pad-label { fill: var(--silk); font: 700 13px var(--ui); text-anchor: middle; }
.board .pad.lit + .pad-label { fill: var(--ink); }
.board .bit { fill: var(--muted); font: 600 11px var(--mono); text-anchor: middle; }
.board .stub { stroke: var(--silk); stroke-width: 2; }
.board .body { fill: var(--bg); stroke: var(--silk); stroke-width: 2; stroke-linejoin: round; }
.board .body.on { fill: #3B4A22; }
.board .body-line { fill: none; stroke: var(--silk); stroke-width: 2; }
.board .bubble { fill: var(--bg); stroke: var(--silk); stroke-width: 2; }
.board .glabel, .board .bit { paint-order: stroke; stroke: var(--bg2); stroke-width: 4px; stroke-linejoin: round; }
.board .glabel { fill: var(--muted); font: 600 11px var(--mono); text-anchor: middle; }
.board .gop { fill: var(--silk); font: 700 8.5px var(--ui); text-anchor: middle; letter-spacing: .02em; }
.viewing { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 4px 2px; color: var(--lit); font-weight: 700; }

/* builder */
.hud { display: flex; justify-content: space-between; align-items: center; margin: 12px 0 0; }
.hud p { margin: 0; color: var(--muted); }
.hud b { color: var(--silk); font-family: var(--display); font-weight: 400; font-size: 1.4rem; margin-left: 4px; font-variant-numeric: tabular-nums; }
.palette { display: flex; gap: 8px; flex-wrap: wrap; }
.add { flex: 1 1 0; min-width: 70px; border: 0; border-radius: 10px; padding: 11px 8px; background: var(--copper); color: #1A1208; font-weight: 800; cursor: pointer; box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); display: flex; justify-content: center; gap: 4px; }
.add .plus { opacity: .7; }
.add:disabled { opacity: .4; cursor: default; }
.tool { border: 1.5px solid #3D7059; background: transparent; border-radius: 12px; padding: 9px 14px; font-weight: 700; cursor: pointer; }
.tool:disabled { opacity: .4; cursor: default; }
.tool.wide { width: 100%; margin-bottom: 12px; border-color: var(--rule); color: var(--ink); }
.go { width: 100%; border: 0; border-radius: 12px; padding: 13px; background: var(--lit); color: var(--ink); font-weight: 800; font-size: 1.05rem; cursor: pointer; }
.go:disabled { background: #2E6049; color: var(--muted); cursor: default; }

.card { background: var(--paper); color: var(--ink); border-radius: 6px; padding: 18px; }
.done { margin-top: 14px; }
.done .go { background: var(--ink); color: var(--paper); }
.kicker { margin: 0; color: var(--ink-muted); font-weight: 600; }
.big { font-family: var(--display); font-size: 2.3rem; line-height: 1.1; margin: 6px 0 6px; }
.res-line { margin: 0 0 14px; }
.fine { color: var(--ink-muted); font-size: 0.85rem; text-align: center; margin: 10px 0 0; }

/* ads */
.ad-inline { margin-top: 26px; }
.ad-slot { display: block; margin: 0 auto; overflow: hidden; }
.ad-banner { width: 100%; max-width: 728px; min-height: 100px; }
.ad-slot.placeholder { border: 1.5px dashed #3D7059; border-radius: 12px; display: grid; place-items: center; color: var(--muted); font-size: 0.85rem; }
.ad-slot.placeholder::before { content: "Ad space " attr(data-size); }
.ad-slot.collapsed { min-height: 0; }
.ad-slot ins[data-ad-status="unfilled"] { display: none !important; }
.ad-label { font-size: 11px; color: var(--muted); text-align: center; margin: 0 0 4px; }

.foot { display: flex; justify-content: center; gap: 22px; padding: 26px 0 40px; color: var(--muted); font-size: 0.9rem; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--paper); color: var(--ink); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.dlg { border: 0; border-radius: 12px; padding: 22px; width: min(440px, calc(100vw - 32px)); background: var(--paper); color: var(--ink); }
.dlg::backdrop { background: rgba(5, 15, 10, .6); }
.dlg h2 { font-family: var(--display); font-weight: 400; margin: 0 0 10px; font-size: 1.6rem; }
.dlg p, .dlg li { color: var(--ink-muted); }
.dlg b { color: var(--ink); }
.gate-help { padding-left: 18px; margin: 0 0 12px; }
.dlg .x { position: absolute; right: 10px; top: 8px; border: 0; background: transparent; font-size: 26px; cursor: pointer; color: var(--ink-muted); width: 40px; height: 40px; }
.dlg .go { background: var(--ink); color: var(--paper); }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 0; }
.stats div { display: flex; flex-direction: column-reverse; background: #E2E9E0; border-radius: 10px; padding: 10px; }
.stats dt { color: var(--ink-muted); font-size: 0.85rem; }
.stats dd { margin: 0; font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* steps */
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.step { border: 1.5px solid #2E6049; background: var(--bg2); border-radius: 10px; padding: 7px 6px; text-align: center; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.step .sname { font-weight: 800; font-size: .92rem; }
.step .smeta { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.step.cur { border-color: var(--lit); background: #24543F; }
.step.solved .smeta { color: #8FE3A2; }
.step:disabled { opacity: .45; cursor: default; }

/* truth table, one column per row */
.sheet-top { display: flex; justify-content: space-between; align-items: baseline; margin: 0 2px 6px; }
.allowed { font-weight: 700; font-size: .9rem; }
.allowed span { font-family: var(--mono); }
.score { font-weight: 800; font-size: .9rem; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.score.full { color: var(--ok); }
.ttwrap { overflow-x: auto; }
.tt { width: 100%; border-collapse: collapse; font-family: var(--mono); text-align: center; font-variant-numeric: tabular-nums; table-layout: fixed; }
.tt th { font-family: var(--ui); font-size: .72rem; color: var(--ink-muted); font-weight: 700; text-align: right; padding: 0 8px 0 0; width: 52px; white-space: nowrap; }
.tt td { padding: 3px 0; font-size: .95rem; cursor: pointer; }
.tt tr.in td { color: var(--ink-muted); }
.tt tr.in.last td, .tt tr.in.last th { border-bottom: 1.5px solid var(--ink); padding-bottom: 5px; }
.tt tr.want td { font-weight: 800; color: var(--ink); padding-top: 5px; }
.tt tr.got td { font-weight: 800; }
.tt td.probe { background: #FFF1C2; }
.tt tr.in.last td.probe { box-shadow: none; }
.tt td.ok { color: #fff; background: var(--ok); }
.tt td.bad { color: #fff; background: var(--bad); }
.tt td.unk { color: #A3B0A7; }
.tt td.ok.probe, .tt td.bad.probe { box-shadow: inset 0 0 0 3px #FFD25A; }

/* board interaction */
.board .hit { fill: transparent; stroke: none; }
.board .gate, .board .src, .board .outg { cursor: pointer; }
.board .selbox { fill: rgba(255, 210, 90, .12); stroke: var(--lit); stroke-width: 1.5; stroke-dasharray: 4 3; }
.board .can .pad, .board .can .body { stroke: var(--lit); stroke-width: 3; }
.board .can .hit { fill: rgba(255, 210, 90, .16); }
.board .can { animation: pulse 1.2s ease-in-out infinite; }
.board .trace.hot, .board .open-pad.hot { stroke: var(--lit); }
.board.solved .pad.out { stroke: #8FE3A2; stroke-width: 4; }
.boardwrap { transition: box-shadow .3s; }
.board.flash { animation: flash .9s ease-out; }
@keyframes pulse { 50% { opacity: .65; } }
@keyframes flash { 0% { filter: brightness(1.8) saturate(1.4); } 100% { filter: none; } }

/* editor */
.editor { background: var(--bg2); border: 1.5px solid #2E6049; border-radius: 10px; padding: 8px; margin-bottom: 10px; min-height: 52px; display: grid; gap: 8px; align-content: center; }
.erow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ename { font-family: var(--mono); font-weight: 800; color: var(--lit); margin-right: 2px; }
.ehint { margin: 0; color: var(--muted); font-size: .9rem; }
.chip { border: 1.5px solid var(--silk); background: transparent; border-radius: 8px; min-width: 44px; min-height: 38px; padding: 6px 10px; font-family: var(--mono); font-weight: 700; cursor: pointer; }
.chip.op { font-family: var(--ui); }
.chip.op.cur { background: var(--silk); color: var(--ink); }
.chip.fixed { cursor: default; display: inline-flex; align-items: center; }
.chip.pin.cur, .chip.src.cur { background: var(--lit); color: var(--ink); border-color: var(--lit); }
.chip.empty { border-style: dashed; color: var(--lit); border-color: var(--lit); }
.chip.empty.cur { color: var(--ink); }
.chip.src.input { border-color: var(--copper); }
.chip.del { margin-left: auto; border-color: #FF7A6E; color: #FF9A90; font-family: var(--ui); }

/* banner + result */
.banner { margin-top: 12px; background: #24543F; border: 1.5px solid #8FE3A2; border-radius: 10px; padding: 12px; }
.btitle { margin: 0; font-weight: 800; }
.bsub { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }
.brow { margin-top: 10px; }
.res-rows { display: grid; gap: 6px; margin: 0 0 14px; }
.rrow { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; }
.rrow .tool { color: var(--ink); border-color: var(--rule); padding: 5px 10px; font-size: .85rem; }
