/* code-history — 程序是怎么来的
   No web fonts, no CDN: everything same-origin so the strict CSP holds
   and the pages keep working offline. */

:root {
  --paper: #fdf8ee;
  --paper-2: #fffdf8;
  --ink: #23262f;
  --ink-soft: #5b6070;
  --line: #e4dbc9;
  --accent: #d9601f;
  --accent-soft: #fdf0e4;
  --teal: #14736b;
  --teal-soft: #e6f3f1;
  --violet: #5b4bb7;
  --violet-soft: #eeebfb;
  --shadow: 0 2px 0 var(--line), 0 10px 24px -18px rgba(35, 38, 47, 0.55);
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.75;
  letter-spacing: 0.01em;
}

a {
  color: var(--teal);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

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

/* ---------- header / nav ---------- */

.site-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(16px, 4vw, 40px);
  background: var(--paper-2);
  border-bottom: 2px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-family: var(--mono);
  font-size: 15px;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.site-nav a {
  padding: 5px 10px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 14.5px;
  border: 1px solid transparent;
}

.site-nav a:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.site-nav a[aria-current="page"] {
  background: var(--ink);
  color: #fff;
}

/* ---------- layout ---------- */

.wrap {
  max-width: 880px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 44px) clamp(16px, 4vw, 40px) 64px;
}

.wrap--wide {
  max-width: 1120px;
}

h1 {
  font-size: clamp(26px, 5vw, 38px);
  line-height: 1.3;
  margin: 0 0 10px;
  letter-spacing: -0.01em;
}

h2 {
  font-size: clamp(20px, 3.4vw, 25px);
  margin: 44px 0 12px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}

h3 {
  font-size: 18.5px;
  margin: 26px 0 8px;
}

p {
  margin: 0 0 14px;
}

.lede {
  font-size: clamp(17px, 2.6vw, 19.5px);
  color: var(--ink-soft);
  margin-bottom: 22px;
}

.chapter-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 12px;
  margin-bottom: 12px;
}

.chapter-tag b {
  font-size: 15px;
}

ul,
ol {
  margin: 0 0 16px;
  padding-left: 22px;
}

li {
  margin-bottom: 7px;
}

strong {
  font-weight: 700;
}

code,
kbd {
  font-family: var(--mono);
  font-size: 0.92em;
  background: #f2ece0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 5px;
  overflow-wrap: anywhere;
}

hr {
  border: 0;
  border-top: 1px dashed var(--line);
  margin: 32px 0;
}

/* ---------- boxes ---------- */

.box {
  border: 2px solid var(--line);
  border-left-width: 6px;
  border-radius: var(--radius);
  background: var(--paper-2);
  padding: 16px 20px;
  margin: 22px 0;
  box-shadow: var(--shadow);
}

.box > :last-child {
  margin-bottom: 0;
}

.box-title {
  font-weight: 700;
  display: block;
  margin-bottom: 6px;
  font-size: 16px;
}

.box--key {
  border-left-color: var(--accent);
  background: var(--accent-soft);
}

.box--key .box-title {
  color: var(--accent);
}

.box--think {
  border-left-color: var(--violet);
  background: var(--violet-soft);
}

.box--think .box-title {
  color: var(--violet);
}

.box--fact {
  border-left-color: var(--teal);
  background: var(--teal-soft);
}

.box--fact .box-title {
  color: var(--teal);
}

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

.toc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr));
  gap: 14px;
  margin: 22px 0 8px;
  padding: 0;
  list-style: none;
}

.toc-card {
  display: block;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  padding: 16px 18px;
  text-decoration: none;
  color: var(--ink);
  box-shadow: var(--shadow);
  height: 100%;
}

.toc-card:hover {
  border-color: var(--accent);
  color: var(--ink);
  transform: translateY(-2px);
}

.toc-no {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
}

.toc-card h3 {
  margin: 4px 0 6px;
  font-size: 18px;
}

.toc-card p {
  margin: 0;
  font-size: 15px;
  color: var(--ink-soft);
  line-height: 1.6;
}

/* ---------- figures / diagrams ---------- */

figure {
  margin: 24px 0;
  padding: 16px;
  background: var(--paper-2);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
}

figure svg {
  display: block;
  width: 100%;
  height: auto;
  min-width: 460px;
}

figcaption {
  font-size: 14.5px;
  color: var(--ink-soft);
  margin-top: 10px;
}

/* ---------- pager ---------- */

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  margin-top: 46px;
  padding-top: 18px;
  border-top: 2px solid var(--line);
}

.pager a {
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 8px 16px;
  background: var(--paper-2);
  text-decoration: none;
  color: var(--ink);
  font-size: 15px;
}

.pager a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- footer ---------- */

.site-foot {
  border-top: 2px solid var(--line);
  background: var(--paper-2);
  padding: 22px clamp(16px, 4vw, 40px) 30px;
  font-size: 14.5px;
  color: var(--ink-soft);
}

.site-foot .wrap {
  padding-top: 0;
  padding-bottom: 0;
}

/* ---------- timeline ---------- */

.timeline {
  list-style: none;
  margin: 26px 0 0;
  padding: 0 0 0 26px;
  border-left: 3px solid var(--line);
}

.timeline li {
  position: relative;
  margin-bottom: 22px;
}

.timeline li::before {
  content: "";
  position: absolute;
  left: -34px;
  top: 9px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--paper);
}

.timeline .year {
  display: inline-block;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--accent);
  margin-right: 8px;
}

.timeline .era {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  font-family: var(--mono);
  margin-bottom: 2px;
}

/* ---------- glossary ---------- */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 18px 0 22px;
}

.filter-bar input {
  flex: 1 1 240px;
  font: inherit;
  font-size: 16px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink);
}

.filter-bar input:focus {
  outline: 3px solid var(--accent-soft);
  border-color: var(--accent);
}

.count-note {
  font-size: 14.5px;
  color: var(--ink-soft);
  font-family: var(--mono);
}

.term {
  border-bottom: 1px dashed var(--line);
  padding: 14px 0;
}

.term:last-child {
  border-bottom: 0;
}

.term h3 {
  margin: 0 0 4px;
  font-size: 17.5px;
}

.term .en {
  font-family: var(--mono);
  font-size: 13.5px;
  color: var(--teal);
  margin-left: 8px;
  font-weight: 400;
}

.term p {
  margin: 0;
  font-size: 15.5px;
  color: var(--ink-soft);
}

.term[hidden] {
  display: none;
}

/* ---------- bootstrap stepper ---------- */

.stepper {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin: 24px 0;
}

.stepper-stages {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 0;
  list-style: none;
}

.stepper-stages button {
  font: inherit;
  font-size: 14.5px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
}

.stepper-stages button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.stepper-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.stepper-body h3 {
  margin: 0;
  font-size: 18px;
}

.stepper-body p {
  margin: 0;
  font-size: 15.5px;
  color: var(--ink-soft);
}

.stepper-nav {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

.btn {
  font: inherit;
  font-size: 15px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.btn--primary:hover:not(:disabled) {
  background: #bf5117;
  border-color: #bf5117;
  color: #fff;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- simulator ---------- */

.sim-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
  gap: 16px;
  align-items: start;
}

.panel {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
  min-width: 0;
}

.panel h2,
.panel h3 {
  margin: 0 0 10px;
  padding: 0;
  border: 0;
  font-size: 17px;
}

.panel .hint {
  font-size: 14px;
  color: var(--ink-soft);
  margin: 0 0 10px;
}

textarea {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 14.5px;
  line-height: 1.55;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fffefa;
  color: var(--ink);
  tab-size: 2;
}

textarea:focus {
  outline: 3px solid var(--accent-soft);
  border-color: var(--accent);
}

.mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  padding: 0;
  list-style: none;
}

.mode-tabs button {
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
}

.mode-tabs button[aria-pressed="true"] {
  border-color: var(--teal);
  background: var(--teal-soft);
  color: var(--teal);
  font-weight: 700;
}

.mode-pane[hidden] {
  display: none;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 12px 0 0;
}

.keystrokes {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--violet);
  margin-left: auto;
}

.mono-out {
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.7;
  background: #23262f;
  color: #f7f3e8;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 62px;
}

.mono-out .dim {
  color: #9aa0b2;
}

table.state {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
}

table.state th,
table.state td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

table.state th {
  color: var(--ink-soft);
  font-weight: 600;
  width: 42%;
}

.reg {
  font-family: var(--mono);
  font-weight: 700;
}

.mem-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
  margin-top: 10px;
}

.mem-cell {
  font-family: var(--mono);
  font-size: 12.5px;
  text-align: center;
  padding: 5px 0;
  border-radius: 6px;
  background: #f4efe4;
  color: var(--ink-soft);
}

.mem-cell.used {
  background: var(--accent-soft);
  color: var(--accent);
}

.mem-cell.hl {
  background: var(--teal);
  color: #fff;
}

.out-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  min-height: 30px;
}

.out-list li {
  font-family: var(--mono);
  font-size: 14px;
  background: var(--teal-soft);
  color: var(--teal);
  border: 1px solid var(--teal);
  border-radius: 8px;
  padding: 2px 9px;
  margin: 0;
}

.err {
  color: #b3261e;
  font-size: 14.5px;
  margin: 8px 0 0;
  white-space: pre-wrap;
}

.err:empty {
  display: none;
}

.switch-board {
  display: grid;
  gap: 6px;
}

.switch-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 62px;
  gap: 8px;
  align-items: center;
}

.switch-row .addr {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--ink-soft);
}

.switch-row .val {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  text-align: right;
}

.bits {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 3px;
}

.bits input {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  aspect-ratio: 1 / 1.35;
  margin: 0;
  border: 2px solid var(--line);
  border-radius: 5px;
  background: #f4efe4;
  cursor: pointer;
}

.bits input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.bits input:focus-visible {
  outline: 3px solid var(--teal-soft);
}

table.isa {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
  margin: 14px 0 6px;
}

table.isa th,
table.isa td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

table.isa th {
  color: var(--ink-soft);
  font-weight: 600;
}

table.isa code {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-weight: 700;
}

.example-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0;
  list-style: none;
  margin: 0 0 12px;
}

.example-list button {
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
}

.example-list button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: 10px;
  margin-top: 8px;
  padding: 0;
  list-style: none;
}

.scoreboard li {
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  margin: 0;
  background: var(--paper);
}

.scoreboard b {
  display: block;
  font-family: var(--mono);
  font-size: 20px;
  color: var(--accent);
}

/* ---------- print ---------- */

@media print {
  .site-head,
  .site-foot,
  .pager,
  .toolbar,
  .mode-tabs {
    display: none;
  }

  body {
    background: #fff;
    font-size: 12pt;
  }

  .box,
  .panel,
  figure,
  .photo-row {
    box-shadow: none;
    break-inside: avoid;
  }

  .photo-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    overflow: visible;
  }
}

/* ---------- 历史照片 ---------- */

figure.photo {
  padding: 0;
  background: none;
  border: 0;
  overflow: visible;
}

figure.photo img,
.photo-row img {
  display: block;
  width: 100%;
  height: auto;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
}

figure.photo img {
  margin: 0;
}

figure.photo.narrow {
  max-width: 460px;
}

figure.photo.hero {
  margin-top: 8px;
}

/* 横排照片：手机上是一条可左右滑的带子（每张 78% 宽），宽屏变两列 */
.photo-row {
  display: flex;
  gap: 12px;
  margin: 24px 0 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  align-items: flex-start;   /* 否则 flex 会把两张图拉到同高，比例被压扁 */
}

.photo-row img {
  flex: 0 0 78%;
  width: 78%;
  scroll-snap-align: center;
}

@media (min-width: 620px) {
  .photo-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    overflow: visible;
  }

  .photo-row img {
    flex: none;
    width: 100%;
  }
}

.photo-note {
  margin: 0 0 26px;
  font-size: 14.5px;
  color: var(--ink-soft);
}

.credit {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  color: var(--ink-soft);
}

.credit a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- 图片来源页 ---------- */

.credit-list {
  list-style: none;
  padding: 0;
  margin: 24px 0;
  display: grid;
  gap: 18px;
}

.credit-list li {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 14px;
  align-items: start;
  padding: 12px;
  background: var(--paper-2);
  border: 2px solid var(--line);
  border-radius: var(--radius);
}

.credit-thumb img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.credit-list p {
  margin: 0 0 4px;
  font-size: 14.5px;
}

.credit-cap {
  color: var(--ink);
}

.credit-meta,
.credit-src {
  font-size: 13px;
  color: var(--ink-soft);
}

.credit-src {
  font-family: var(--mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

@media (max-width: 520px) {
  .credit-list li {
    grid-template-columns: 1fr;
  }

  .credit-thumb {
    max-width: 200px;
  }
}

/* ---------- 点图放大 ---------- */

.zoomable { cursor: zoom-in; }
.zoomable:active { opacity: .88; }

.lb {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  background: rgba(6, 14, 20, .95);
  touch-action: pinch-zoom;
  overscroll-behavior: contain;
}

.lb[hidden] { display: none; }

.lb-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 6px;
  color: #fff;
  font-size: 13px;
}

.lb-count { font-variant-numeric: tabular-nums; opacity: .85; }

.lb-close {
  appearance: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.lb-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* 关键：contain + 不给固定宽高 → 不裁切、不拉伸 */
.lb-stage img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  background: rgba(255, 255, 255, .04);
}

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 64px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.lb-nav[hidden] { display: none; }
.lb-prev { left: 4px; }
.lb-next { right: 4px; }

.lb-caption {
  margin: 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
  color: #fff;
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
  opacity: .82;
}

.lb-close:focus-visible,
.lb-nav:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

body.lb-open { overflow: hidden; }

/* ---------- 插线游戏（复古插线板） ---------- */

.plug-app {
  --panel-cream: #f7f0e2;
  --panel-edge: #c9b795;
  --bakelite: #33383f;
  --bakelite-2: #23272d;
  --bakelite-edge: #14171b;
  --engrave: #ece6d8;
  --engrave-soft: #a7b0bb;
  --brass-dark: #8a6c26;
  --steel: #98a1ac;
  --steel-dark: #5a626d;
  --amber: #ffb43a;
  margin: 20px 0;
}

/* ---------- 顶栏（手机上吸顶：任务和结果一直看得见） ---------- */

.plug-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 2px solid var(--panel-edge);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #f8f2e5, #e9dcc4);
  box-shadow: inset 0 1px 0 #fff, 0 8px 18px -14px rgba(35, 38, 47, .75);
}

@media (min-width: 760px) {
  .plug-bar {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }
}

.plug-bar-main {
  min-width: 0;
}

.mission {
  margin: 0;
  font-size: 16.5px;
  font-weight: 700;
}

/* 接线公式：像机器上的读数窗 */
.formula {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 7px;
  margin: 7px 0 0;
  padding: 4px 10px;
  border: 1px solid #cfc0a0;
  border-radius: 8px;
  background: linear-gradient(180deg, #14171b, #23272d);
  overflow-wrap: anywhere;
}

.formula-tag {
  font-size: 11.5px;
  letter-spacing: .06em;
  color: var(--engrave-soft, #a7b0bb);
}

/* 全局给 code 加了浅色底（正文里的行内代码用），读数窗里的算式要去掉它，
   否则浅色字落在浅色底上就看不见了 */
.formula-expr,
.formula-value {
  font-family: var(--mono);
  font-size: 16px;
  background: none;
  border: 0;
  padding: 0;
}

.formula-expr {
  color: #f2ece0;
}

.formula-value {
  font-weight: 700;
  color: var(--amber, #ffb43a);
  text-shadow: 0 0 8px rgba(255, 180, 58, .5);
}

.bar-status {
  margin: 2px 0 0;
  font-size: 13.5px;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.bar-status[data-kind="win"] {
  color: #b4500f;
  font-weight: 700;
}

.bar-status[data-kind="warn"] {
  color: #a03a12;
}

.plug-bar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.plug-bar-actions .btn {
  padding: 6px 13px;
  font-size: 14.5px;
  touch-action: manipulation;
}

.btn--ghost {
  background: transparent;
  border-style: dashed;
}

.bar-value {
  font-family: var(--mono);
  font-size: 15px;
  padding: 3px 10px;
  border: 2px solid var(--bakelite-edge);
  border-radius: 999px;
  background: linear-gradient(180deg, #14171b, #23272d);
  color: var(--amber);
  text-shadow: 0 0 7px rgba(255, 180, 58, .6);
}

/* ---------- 面板与机箱 ---------- */

.plug-body {
  display: grid;
  gap: 16px;
  align-items: start;
}

@media (min-width: 900px) {
  .plug-body {
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  }
}

.plug-board {
  position: relative;
  padding: 24px 14px 16px;
  border: 2px solid var(--panel-edge);
  border-radius: 18px;
  background: linear-gradient(180deg, var(--panel-cream) 0%, #eadfc8 58%, #e0d2b6 100%);
  box-shadow:
    inset 0 1px 0 #fffdf7,
    inset 0 -3px 8px rgba(120, 100, 70, .16),
    0 14px 30px -22px rgba(35, 38, 47, .7);
  overflow: visible;
}

.screw {
  position: absolute;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e8dfca, #b6a582 70%, #8f7f5d);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, .75), 0 1px 1px rgba(0, 0, 0, .25);
  z-index: 5;
}

.screw::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 2px;
  border-radius: 1px;
  background: #6f6146;
  transform: translate(-50%, -50%) rotate(35deg);
}

.screw--tl { left: 8px; top: 8px; }
.screw--tr { right: 8px; top: 8px; }
.screw--bl { left: 8px; bottom: 8px; }
.screw--br { right: 8px; bottom: 8px; }

.rack {
  margin: 0 0 16px;
}

.rack:last-of-type {
  margin-bottom: 0;
}

.rack-title {
  display: inline-block;
  margin: 0 0 9px;
  padding: 3px 12px;
  border: 1px solid #cbb894;
  border-radius: 6px;
  background: linear-gradient(180deg, #f2e8d4, #ddceb0);
  color: #6d5c3d;
  font-size: 12.5px;
  letter-spacing: .08em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8);
}

.units {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(146px, 1fr));
}

/* 模块 = 深色电木机箱，上面刻着字 */
.unit {
  position: relative;
  z-index: 3;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 10px 8px 12px;
  border: 2px solid var(--bakelite-edge);
  border-radius: 12px;
  background: linear-gradient(180deg, #3b4149 0%, #2b3037 62%, var(--bakelite-2) 100%);
  color: var(--engrave);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .16), 0 5px 12px -10px rgba(0, 0, 0, .95);
}

.unit-name {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .02em;
}

.unit-note {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--engrave-soft);
}

/* 拨轮：金属按键 + 计数器窗 + 指针 */
.dial {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dial-key {
  width: 34px;
  height: 30px;
  padding: 0;
  font: inherit;
  font-size: 17px;
  line-height: 1;
  color: #2b2118;
  border: 2px solid #6b5c3d;
  border-radius: 8px;
  background: linear-gradient(180deg, #eadab6, #c9b489);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .85), 0 2px 0 #7d6b48;
  cursor: pointer;
  touch-action: manipulation;
}

.dial-key:active {
  transform: translateY(1px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6);
}

.drum {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 5.4ch;
  height: 34px;
  padding: 0 8px 0 18px;
  border: 2px solid var(--bakelite-edge);
  border-radius: 6px;
  background: linear-gradient(180deg, #14171b, #1f2429);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .9);
}

.needle {
  position: absolute;
  left: 3px;
  top: 50%;
  width: 12px;
  height: 12px;
  margin-top: -6px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #d9c48a, #8a7440);
  transform: rotate(var(--turn, 0deg));
}

.needle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -3px;
  width: 2px;
  height: 6px;
  border-radius: 1px;
  background: var(--amber);
  transform: translateX(-50%);
}

.dial-value {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--amber);
  text-shadow: 0 0 7px rgba(255, 180, 58, .55);
}

/* 插孔：金属环 + 黑洞 */
.socket-wrap {
  display: grid;
  justify-items: center;
  gap: 3px;
}

.socket-label {
  font-size: 11px;
  color: var(--engrave-soft);
}

.sockets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  justify-content: center;
}

.socket {
  position: relative;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 3px solid var(--steel-dark);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #6d7681 0%, #343a42 46%, var(--bakelite-edge) 100%);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, .85), 0 1px 0 rgba(255, 255, 255, .25);
  cursor: pointer;
  touch-action: manipulation;
}

.socket--in {
  border-color: var(--brass-dark);
}

.socket--out {
  border-color: var(--steel);
}

.socket[data-used="true"] {
  border-color: #2f9c86;
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, .85), 0 0 0 3px rgba(47, 156, 134, .25);
}

.socket[data-active="true"] {
  border-color: var(--amber);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, .85), 0 0 0 4px rgba(255, 180, 58, .4);
}

/* 选了起点以后，能接的插孔会呼吸式闪动 */
.socket[data-target="true"] {
  border-color: #7fd4c2;
  animation: socket-pulse 1.15s ease-in-out infinite;
}

@keyframes socket-pulse {
  0%, 100% { box-shadow: inset 0 3px 6px rgba(0, 0, 0, .85), 0 0 0 0 rgba(127, 212, 194, 0); }
  50% { box-shadow: inset 0 3px 6px rgba(0, 0, 0, .85), 0 0 0 6px rgba(127, 212, 194, .35); }
}

.socket:focus-visible,
.dial-key:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

/* 触屏设备把插孔做大一点，手指点得准。
   窄屏一律放大（视口宽度是确定的）；宽屏的触屏设备靠 hover/pointer 判断。 */
@media (max-width: 620px), (hover: none) and (pointer: coarse) {
  .socket {
    width: 46px;
    height: 46px;
  }

  .dial-key {
    width: 42px;
    height: 40px;
  }

  /* 窄屏上拨轮竖着排：计数窗一行，加减键一行。
     横向塞不下时这就是最省宽度、也最好按的排法。 */
  .dial {
    flex-wrap: wrap;
    gap: 6px 8px;
    justify-content: space-between;
  }

  .drum {
    flex: 1 1 100%;
    order: -1;
    min-width: 0;
  }

  .socket-label {
    font-size: 11.5px;
  }
}

/* 输出灯：玻璃灯泡 + 机械计数器窗 */
.lamp {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bulb {
  position: relative;
  width: 30px;
  height: 30px;
  border: 2px solid var(--bakelite-edge);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #7b838d, #3a4048 60%, #20242a);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .8);
}

/* 玻璃高光：一小块亮的反光，灯泡才像玻璃 */
.bulb::after {
  content: "";
  position: absolute;
  left: 22%;
  top: 18%;
  width: 32%;
  height: 26%;
  border-radius: 50%;
  background: rgba(255, 255, 255, .45);
  filter: blur(1px);
}

.lamp[data-on="true"] .bulb::after {
  background: rgba(255, 255, 255, .9);
}

.lamp[data-on="true"] .bulb {
  background: radial-gradient(circle at 38% 32%, #fff5d6, var(--amber) 55%, #b4500f);
  box-shadow: 0 0 16px 5px rgba(255, 180, 58, .55), inset 0 1px 3px rgba(255, 255, 255, .75);
}

.counter {
  min-width: 3.4ch;
  padding: 2px 9px;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  color: var(--amber);
  border: 2px solid var(--bakelite-edge);
  border-radius: 6px;
  background: linear-gradient(180deg, #14171b, #1f2429);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .9);
}

.counter output {
  font: inherit;
  color: inherit;
}

.lamp[data-on="true"] .counter {
  text-shadow: 0 0 9px rgba(255, 180, 58, .75);
}

/* ---------- 线（三层：外皮 / 芯线 / 高光）+ 插头 ---------- */

/* 可见的线画在机箱上面：插头正好落在插孔里，看起来是“插进去”的 */
.cables {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 4;
  pointer-events: none;
  overflow: visible;
}

/* 命中层在机箱下面：点线拔线只在机器之间的空隙里生效，
   这样它永远不会挡住插孔的手指落点 */
.cables--hit {
  z-index: 2;
}

.cable-skin {
  fill: none;
  stroke: #2a1c12;
  stroke-opacity: .5;
  stroke-width: 8;
  stroke-linecap: round;
}

.cable-core {
  fill: none;
  stroke-width: 4.6;
  stroke-linecap: round;
}

.cable-shine {
  fill: none;
  stroke: rgba(255, 255, 255, .5);
  stroke-width: 1.4;
  stroke-linecap: round;
  transform: translateY(-1.2px);
}

.plug {
  stroke: var(--bakelite-edge);
  stroke-width: 2;
}

.plug-shine {
  fill: rgba(255, 255, 255, .55);
}

.cable-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 26;
  pointer-events: stroke;
  cursor: pointer;
}

/* ---------- 全屏 / 专注模式 ---------- */

body.plug-focus {
  overflow: hidden;
}

.plug-app[data-fs="true"],
.plug-app:fullscreen,
.plug-app:-webkit-full-screen {
  position: fixed;
  inset: 0;
  z-index: 90;
  margin: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px calc(env(safe-area-inset-bottom, 0px) + 10px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #1b1f24;
  overflow: hidden;
}

.plug-app[data-fs="true"] .plug-bar,
.plug-app:fullscreen .plug-bar {
  position: static;
  margin-bottom: 0;
}

.plug-app[data-fs="true"] .plug-body,
.plug-app:fullscreen .plug-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
}

.plug-app[data-fs="true"] .plug-side,
.plug-app:fullscreen .plug-side {
  display: none;
}

.plug-app[data-fs="true"] .plug-board,
.plug-app:fullscreen .plug-board {
  margin: 0;
}

.plug-app[data-fs="true"] .mission,
.plug-app:fullscreen .mission {
  font-size: 15px;
}

.plug-app[data-fs="true"] .bar-status,
.plug-app:fullscreen .bar-status {
  display: -webkit-box;
  overflow: hidden;
  font-size: 12.5px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* 全屏时顶栏要省地方：按钮缩小、退出全屏排到最前面（手机上一眼就能找到） */
.plug-app[data-fs="true"] .formula,
.plug-app:fullscreen .formula {
  margin-top: 5px;
  padding: 3px 8px;
}

.plug-app[data-fs="true"] .formula-expr,
.plug-app[data-fs="true"] .formula-value,
.plug-app:fullscreen .formula-expr,
.plug-app:fullscreen .formula-value {
  font-size: 15px;
}

.plug-app[data-fs="true"] .plug-bar-actions,
.plug-app:fullscreen .plug-bar-actions {
  gap: 5px;
}

.plug-app[data-fs="true"] .plug-bar-actions .btn,
.plug-app:fullscreen .plug-bar-actions .btn {
  padding: 5px 10px;
  font-size: 13.5px;
}

.plug-app[data-fs="true"] #fs-toggle,
.plug-app:fullscreen #fs-toggle {
  order: -1;
}

@media (max-width: 520px) {
  .rack {
    margin-bottom: 13px;
  }

  .units {
    gap: 8px;
    /* 窄屏上拨轮竖排，模块最小宽度约 102px，所以两列在 320px 的手机上也放得下 */
    grid-template-columns: repeat(auto-fit, minmax(122px, 1fr));
  }

  .socket-label {
    font-size: 10.5px;
  }

  .unit-name {
    font-size: 13px;
  }

  .unit {
    padding: 8px 6px 10px;
  }

  .plug-board {
    padding: 22px 10px 14px;
  }
}

@media print {
  .plug-app {
    break-inside: avoid;
  }

  .cables {
    display: none;
  }
}
