/* logic-gates/style.css */
:root {
  color-scheme: dark;
  --bg: #101a14;
  --panel: #182319;
  --panel-2: #1d2b21;
  --ink: #eff5e9;
  --muted: #9faa9c;
  --line: rgba(213, 225, 207, 0.14);
  --lime: #aede6b;
  --cyan: #61d5c4;
  --red: #df6452;
  --gold: #d9ab52;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 85% 6%, rgba(97, 213, 196, 0.08), transparent 30rem),
    radial-gradient(circle at 10% 28%, rgba(185, 239, 108, 0.055), transparent 26rem),
    var(--bg);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.wrap { width: min(1160px, calc(100% - 36px)); margin: 0 auto; }
.skip-link {
  position: fixed; top: 10px; left: 10px; z-index: 10000; padding: 10px 14px;
  color: var(--bg); background: var(--lime); border-radius: 9px; transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

.lab-hero { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); }
.hero-grid {
  position: absolute; inset: 0; pointer-events: none; opacity: .32;
  background-image:
    linear-gradient(rgba(97, 213, 196, .08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(97, 213, 196, .08) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(90deg, transparent, black 45%, black 75%, transparent);
}
.hero-inner { position: relative; padding: 34px 0 64px; }
.hero-kicker { display: flex; align-items: center; gap: 10px; color: var(--cyan); font-size: 12px; font-weight: 800; letter-spacing: .15em; }
.signal-dot { width: 8px; height: 8px; background: var(--lime); border-radius: 50%; box-shadow: 0 0 0 6px rgba(185,239,108,.08), 0 0 18px var(--lime); }
.hero-copy { display: grid; grid-template-columns: minmax(0,1.35fr) minmax(260px,.65fr); gap: 64px; align-items: end; margin-top: 54px; }
.chapter { margin: 0 0 16px; color: var(--muted); font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 12px; letter-spacing: .14em; }
h1 { margin: 0; font-size: clamp(50px, 8vw, 96px); line-height: .95; letter-spacing: -.045em; }
h1 em { display: block; margin-top: 15px; color: var(--lime); font-size: .36em; font-style: normal; font-weight: 600; letter-spacing: .03em; }
.hero-intro { max-width: 700px; margin: 28px 0 0; color: var(--muted); font-size: 17px; line-height: 1.9; }
.hero-readout { display: grid; background: rgba(21,31,24,.78); border: 1px solid var(--line); border-radius: 22px 22px 22px 6px; backdrop-filter: blur(12px); }
.hero-readout div { display: flex; align-items: center; gap: 18px; padding: 19px 22px; border-top: 1px solid var(--line); }
.hero-readout div:first-child { border-top: 0; }
.hero-readout span { min-width: 50px; color: var(--lime); font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 28px; font-weight: 800; }
.hero-readout small { color: var(--muted); font-size: 13px; letter-spacing: .08em; }

.course-nav { position: sticky; top: 0; z-index: 50; background: rgba(13,21,16,.88); border-bottom: 1px solid var(--line); backdrop-filter: blur(16px); }
.nav-inner { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.nav-inner::-webkit-scrollbar { display: none; }
.course-nav button { min-height: 56px; padding: 0 18px; color: var(--muted); white-space: nowrap; background: transparent; border: 0; border-bottom: 2px solid transparent; cursor: pointer; font-size: 13px; font-weight: 700; }
.course-nav button:hover { color: var(--ink); }
.course-nav button.on { color: var(--lime); border-bottom-color: var(--lime); }

main { padding: 64px 0 70px; }
.tab-panel { animation: panel-in .25s ease; }
@keyframes panel-in { from { opacity: 0; transform: translateY(8px); } }
.section-heading { display: grid; grid-template-columns: 1fr minmax(280px,.65fr); gap: 50px; align-items: end; margin-bottom: 30px; }
.section-index { margin: 0 0 10px; color: var(--cyan); font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 12px; font-weight: 800; letter-spacing: .1em; }
.section-heading h2 { margin: 0; font-size: clamp(30px,5vw,48px); line-height: 1.15; letter-spacing: -.025em; }
.section-heading > p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.8; }

.binary-bridge { display: grid; grid-template-columns: auto 1fr auto; gap: 20px; align-items: center; margin: 36px 0 20px; padding: 20px; background: linear-gradient(110deg, rgba(97,213,196,.08), rgba(185,239,108,.04)); border: 1px solid var(--line); border-radius: 18px; }
.bridge-bit { display: grid; width: 54px; height: 54px; place-items: center; color: var(--muted); background: #0c130e; border: 1px solid var(--line); border-radius: 14px; font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 25px; font-weight: 800; }
.bridge-bit.active { color: var(--bg); background: var(--lime); box-shadow: 0 0 30px rgba(185,239,108,.18); }
.bridge-copy strong, .bridge-copy span { display: block; }
.bridge-copy strong { margin-bottom: 5px; }
.bridge-copy span { color: var(--muted); font-size: 13px; line-height: 1.65; }

.gate-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; }
.gate-card { display: flex; min-height: 285px; flex-direction: column; padding: 22px; background: rgba(21,31,24,.82); border: 1px solid var(--line); border-radius: 20px 20px 20px 5px; transition: border-color .18s, transform .18s, background .18s; }
.gate-card:hover { background: var(--panel-2); border-color: rgba(185,239,108,.35); transform: translateY(-3px); }
.gate-card-top { display: flex; align-items: center; justify-content: space-between; }
.gate-symbol { display: grid; min-width: 52px; height: 52px; padding: 0 8px; place-items: center; color: var(--bg); background: var(--lime); border-radius: 13px 13px 13px 4px; font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 20px; font-weight: 900; }
.gate-code { color: var(--cyan); font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 11px; letter-spacing: .12em; }
.gate-card h3 { margin: 20px 0 7px; font-size: 20px; }
.gate-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.mini-truth { display: flex; gap: 6px; margin: 17px 0; }
.mini-truth span { flex: 1; padding: 8px; color: var(--muted); text-align: center; background: #0d1510; border-radius: 8px; font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 11px; }
.mini-truth b { color: var(--lime); }
.try-gate { min-height: 38px; margin-top: auto; color: var(--cyan); background: transparent; border: 1px solid rgba(97,213,196,.26); border-radius: 10px; cursor: pointer; font-size: 12px; font-weight: 800; }
.try-gate:hover { color: var(--bg); background: var(--cyan); }

.gate-picker, .adder-mode { display: flex; gap: 8px; margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.gate-picker button, .adder-mode button { min-height: 44px; padding: 0 15px; color: var(--muted); white-space: nowrap; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; cursor: pointer; font-size: 12px; font-weight: 800; }
.gate-picker button:hover, .adder-mode button:hover { color: var(--ink); }
.gate-picker button.active, .adder-mode button.active { color: var(--bg); background: var(--lime); border-color: var(--lime); }

.logic-workbench { display: grid; grid-template-columns: 150px minmax(380px,1fr) 260px; gap: 18px; min-height: 360px; padding: 24px; background: linear-gradient(145deg, rgba(26,39,30,.95), rgba(16,24,19,.95)); border: 1px solid var(--line); border-radius: 24px 24px 24px 6px; box-shadow: 0 26px 70px rgba(0,0,0,.22); }
.input-bank { display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.bit-switch { display: grid; min-height: 116px; padding: 14px; place-items: center; color: var(--muted); background: #0b120d; border: 1px solid var(--line); border-radius: 16px; cursor: pointer; }
.bit-switch strong { color: var(--muted); font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 34px; }
.bit-switch small { font-size: 11px; font-weight: 800; letter-spacing: .1em; }
.bit-switch span { font-size: 10px; }
.bit-switch[aria-checked="true"] { color: var(--lime); border-color: rgba(185,239,108,.45); box-shadow: inset 0 0 30px rgba(185,239,108,.06); }
.bit-switch[aria-checked="true"] strong { color: var(--lime); text-shadow: 0 0 16px rgba(185,239,108,.45); }
.circuit { position: relative; min-height: 310px; overflow: hidden; background: #0a110c; border: 1px solid var(--line); border-radius: 18px; }
.circuit::before { position: absolute; inset: 0; content: ""; opacity: .45; background-image: radial-gradient(rgba(97,213,196,.17) 1px,transparent 1px); background-size: 16px 16px; }
.wire { position: absolute; z-index: 1; height: 3px; background: #3e5143; }
.wire.on { background: var(--lime); box-shadow: 0 0 12px rgba(185,239,108,.55); }
.wire-a { top: 112px; left: 8%; width: 30%; }
.wire-b { top: 196px; left: 8%; width: 30%; }
.wire-out { top: 154px; right: 10%; width: 25%; }
.gate-body { position: absolute; top: 91px; left: 37%; z-index: 2; display: grid; width: 120px; height: 126px; place-items: center; align-content: center; color: var(--ink); background: #1a271e; border: 2px solid var(--cyan); border-radius: 18px 56px 56px 18px; box-shadow: 0 0 32px rgba(97,213,196,.08); }
.gate-body span { color: var(--cyan); font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 21px; font-weight: 900; }
.gate-body small { margin-top: 7px; color: var(--muted); }
.output-lamp { position: absolute; top: 112px; right: 3%; z-index: 2; display: grid; place-items: center; }
.output-lamp > span { width: 40px; height: 40px; background: #26342a; border: 2px solid #506052; border-radius: 50%; }
.output-lamp.on > span { background: var(--lime); border-color: #e8ffc6; box-shadow: 0 0 12px var(--lime), 0 0 34px rgba(185,239,108,.55); }
.output-lamp small { margin-top: 8px; color: var(--muted); font-size: 10px; }
.output-lamp strong { margin-top: 2px; font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 22px; }
.rule-panel { display: flex; flex-direction: column; justify-content: center; padding: 20px; background: rgba(10,17,12,.55); border: 1px solid var(--line); border-radius: 17px; }
.rule-panel p { margin: 0 0 9px; color: var(--cyan); font-size: 11px; font-weight: 800; letter-spacing: .12em; }
.rule-panel strong { font-size: 17px; line-height: 1.5; }
.rule-panel code { display: block; margin: 18px 0; padding: 12px; color: var(--lime); background: #070d09; border-radius: 8px; font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; text-align: center; }
.rule-panel span { color: var(--muted); font-size: 12px; line-height: 1.7; }

.truth-block { margin-top: 18px; padding: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; }
.truth-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.truth-heading h3 { margin: 0; font-size: 17px; }
.truth-heading span { color: var(--muted); font-size: 11px; }
.truth-table { display: grid; gap: 5px; }
.truth-row { display: grid; grid-template-columns: repeat(3,1fr); gap: 5px; }
.truth-cell { display: grid; min-height: 38px; place-items: center; color: var(--muted); background: #0d1510; border: 1px solid transparent; border-radius: 8px; font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 13px; }
.truth-row.header .truth-cell { color: var(--cyan); background: transparent; font-size: 11px; font-weight: 800; letter-spacing: .1em; }
.truth-row.current .truth-cell { color: var(--bg); background: var(--lime); border-color: var(--lime); font-weight: 900; }
.truth-table.single .truth-row { grid-template-columns: repeat(2,1fr); }

.adder-board { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 16px; align-items: stretch; padding: 25px; background: linear-gradient(145deg, rgba(26,39,30,.95), rgba(16,24,19,.95)); border: 1px solid var(--line); border-radius: 24px 24px 24px 6px; }
.adder-inputs { display: flex; align-items: center; justify-content: center; gap: 10px; }
.bit-switch.compact { width: 84px; min-height: 104px; }
.plus { color: var(--muted); font-size: 24px; }
.adder-equation { display: grid; place-items: center; align-content: center; padding: 18px; background: #09100b; border: 1px solid var(--line); border-radius: 17px; }
.adder-equation span { color: var(--muted); font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; }
.adder-equation strong { margin: 10px 0 6px; color: var(--lime); font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 45px; letter-spacing: .12em; text-shadow: 0 0 22px rgba(185,239,108,.25); }
.adder-equation small { color: var(--muted); font-size: 10px; }
.adder-outputs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.adder-outputs div { display: grid; place-items: center; align-content: center; background: #0d1510; border: 1px solid var(--line); border-radius: 15px; }
.adder-outputs span { color: var(--muted); font-size: 11px; }
.adder-outputs strong { margin: 8px 0; color: var(--cyan); font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 36px; }
.adder-outputs small { color: var(--muted); font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 9px; text-align: center; }
.formula-strip { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.formula-strip > div { display: flex; gap: 12px; align-items: center; padding: 15px 18px; overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 13px; }
.formula-strip small { min-width: 48px; color: var(--cyan); font-weight: 800; }
.formula-strip code { padding: 6px 9px; color: var(--lime); white-space: nowrap; background: #0b120d; border-radius: 7px; font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 11px; }
.adder-table .truth-row { grid-template-columns: repeat(4,1fr); }
.adder-table.full .truth-row { grid-template-columns: repeat(5,1fr); }

.quiz-shell { max-width: 820px; margin: 0 auto; }
.quiz-status { margin-bottom: 14px; }
.quiz-status > div:first-child { display: flex; justify-content: space-between; gap: 18px; color: var(--muted); font-size: 12px; }
.quiz-status strong { color: var(--lime); }
.progress-track { height: 5px; margin-top: 12px; overflow: hidden; background: #1d2b20; border-radius: 999px; }
.progress-track span { display: block; width: 0; height: 100%; background: linear-gradient(90deg,var(--cyan),var(--lime)); transition: width .25s; }
.quiz-card, .quiz-finish { min-height: 430px; padding: clamp(25px,5vw,48px); background: linear-gradient(145deg, rgba(26,39,30,.98), rgba(15,23,17,.98)); border: 1px solid var(--line); border-radius: 26px 26px 26px 7px; box-shadow: 0 24px 70px rgba(0,0,0,.22); }
.quiz-level { margin: 0 0 16px; color: var(--cyan); font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 11px; font-weight: 800; letter-spacing: .12em; }
.quiz-card h3 { max-width: 650px; margin: 0 0 28px; font-size: clamp(25px,4vw,36px); line-height: 1.4; }
.quiz-options { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; }
.quiz-options button { min-height: 62px; padding: 12px 18px; color: var(--ink); background: #0d1510; border: 1px solid var(--line); border-radius: 13px; cursor: pointer; font-size: 17px; font-weight: 800; }
.quiz-options button:hover:not(:disabled) { border-color: var(--cyan); }
.quiz-options button.correct { color: var(--bg); background: var(--lime); border-color: var(--lime); }
.quiz-options button.wrong { color: white; background: var(--red); border-color: var(--red); }
.quiz-feedback { margin-top: 18px; padding: 15px 17px; color: var(--muted); background: #0b120d; border-left: 3px solid var(--cyan); border-radius: 4px 10px 10px 4px; font-size: 13px; line-height: 1.75; }
.quiz-feedback strong { color: var(--ink); }
.next-question, .quiz-finish button { min-height: 46px; margin-top: 18px; padding: 0 20px; color: var(--bg); background: var(--lime); border: 0; border-radius: 11px; cursor: pointer; font-weight: 900; }
.quiz-finish { display: grid; place-items: center; align-content: center; text-align: center; }
.finish-seal { display: grid; width: 62px; height: 62px; place-items: center; color: white; background: var(--red); border-radius: 16px 16px 16px 5px; font-size: 28px; font-weight: 900; }
.quiz-finish h3 { margin: 20px 0 8px; font-size: 28px; }
.quiz-finish p { margin: 0; color: var(--muted); }

.page-footer { display: flex; justify-content: space-between; gap: 20px; padding: 28px 0 80px; color: var(--muted); border-top: 1px solid var(--line); font-size: 12px; }
.page-footer p { margin: 0; }
.noscript { margin: 20px; padding: 16px; color: white; background: var(--red); text-align: center; }
[hidden] { display: none !important; }
:where(a,button):focus-visible { outline: 3px solid rgba(185,239,108,.5); outline-offset: 3px; }

@media (max-width: 900px) {
  .hero-copy, .section-heading { grid-template-columns: 1fr; gap: 28px; }
  .hero-readout { grid-template-columns: repeat(3,1fr); }
  .hero-readout div { flex-direction: column; gap: 4px; align-items: start; border-top: 0; border-left: 1px solid var(--line); }
  .hero-readout div:first-child { border-left: 0; }
  .gate-grid { grid-template-columns: repeat(2,1fr); }
  .logic-workbench { grid-template-columns: 130px 1fr; }
  .rule-panel { grid-column: 1 / -1; }
  .adder-board { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .wrap { width: min(100% - 24px,1160px); }
  .hero-inner { padding-top: 24px; padding-bottom: 44px; }
  .hero-copy { margin-top: 38px; }
  .hero-intro { font-size: 15px; }
  .hero-readout div { padding: 13px; }
  .hero-readout span { font-size: 22px; }
  .hero-readout small { font-size: 10px; }
  main { padding-top: 42px; }
  .gate-grid { grid-template-columns: 1fr; }
  .binary-bridge { grid-template-columns: auto 1fr; }
  .binary-bridge .bridge-bit:last-child { display: none; }
  .logic-workbench { grid-template-columns: 1fr; padding: 14px; }
  .input-bank { flex-direction: row; }
  .bit-switch { min-height: 88px; }
  .circuit { min-height: 290px; }
  .gate-body { left: 34%; width: 105px; }
  .wire-out { right: 8%; width: 22%; }
  .truth-heading { align-items: start; flex-direction: column; gap: 4px; }
  .adder-inputs { flex-wrap: wrap; }
  .adder-outputs { min-height: 130px; }
  .formula-strip { grid-template-columns: 1fr; }
  .quiz-options { grid-template-columns: 1fr; }
  .page-footer { flex-direction: column; gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* assets/site-shell.css */
/* The shared dock is independent of each subject's colors and navigation styles. */
body[data-knowledge-theme] { min-width: 0; }

body .site-knowledge-dock {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 5px;
  max-width: calc(100vw - 24px);
  margin: 0;
  padding: 5px;
  color: #f9f8f2;
  background: #173c32;
  border: 1px solid #386053;
  border-radius: 15px;
  box-shadow: 0 8px 28px rgba(19, 43, 34, .19);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  line-height: 1.4;
}
body .site-knowledge-dock a {
  position: static;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 12px;
  color: #f9f8f2;
  background: transparent;
  border: 0;
  border-radius: 10px;
  text-decoration: none;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0;
  box-shadow: none;
  transition: background-color 160ms ease;
}
body .site-knowledge-dock .site-review-link { color: #e2eee5; background: rgba(255, 255, 255, .08); }
body .site-knowledge-dock a:hover,
body .site-knowledge-dock a[aria-current="page"] { color: #fff; background: rgba(255, 255, 255, .17); }
body .site-knowledge-dock .site-dock-icon { display: inline-block; font-size: 18px; line-height: 1; }
body .site-knowledge-dock a:focus-visible { outline: 2px solid #fff3c7; outline-offset: -2px; }
body .site-dock-spacer {
  display: block;
  clear: both;
  height: calc(88px + env(safe-area-inset-bottom));
  flex: 0 0 calc(88px + env(safe-area-inset-bottom));
  pointer-events: none;
}
@media (max-width: 560px) {
  body .site-knowledge-dock { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); border-radius: 13px; }
  body .site-knowledge-dock a { gap: 5px; padding: 0 10px; font-size: 12px; }
}
@media print { body .site-knowledge-dock, body .site-dock-spacer { display: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
