:root {
  color-scheme: light;
  --ink: #19212b;
  --muted: #667085;
  --paper: #f6f3ec;
  --card: #fffdf8;
  --line: #d9d4c8;
  --green: #287a55;
  --green-soft: #e5f2e9;
  --blue: #2767a8;
  --blue-soft: #e6eff9;
  --amber: #a35f08;
  --amber-soft: #fff1d6;
  --red: #a23932;
  --shadow: 0 12px 32px rgba(36, 30, 20, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(255, 255, 255, 0.32), rgba(255, 255, 255, 0.32)),
    repeating-linear-gradient(0deg, transparent, transparent 31px, rgba(76, 64, 43, 0.035) 32px),
    var(--paper);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  line-height: 1.68;
}

main {
  width: min(940px, calc(100% - 32px));
  margin: 40px auto 80px;
}

header {
  padding: 32px 36px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
  box-shadow: var(--shadow);
}

h1, h2, h3 {
  line-height: 1.25;
}

h1 {
  margin: 8px 0 10px;
  font-size: clamp(2rem, 5vw, 3.5rem);
  letter-spacing: -0.04em;
}

h2 {
  margin: 0 0 18px;
  font-size: 1.45rem;
}

h3 {
  margin: 0 0 8px;
}

p {
  margin: 0.55rem 0;
}

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

.eyebrow {
  color: var(--amber);
  font-size: 0.83rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.lead {
  max-width: 720px;
  color: #3e4955;
  font-size: 1.08rem;
}

section {
  margin-top: 24px;
  padding: 28px 32px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 253, 248, 0.9);
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.role {
  min-height: 180px;
  padding: 22px;
  border-radius: 14px;
}

.role.interface {
  border: 1px solid #b9ddc8;
  background: var(--green-soft);
}

.role.class {
  border: 1px solid #bed3eb;
  background: var(--blue-soft);
}

.icon {
  display: inline-grid;
  width: 34px;
  height: 34px;
  margin-right: 8px;
  place-items: center;
  border: 2px solid currentColor;
  border-radius: 50%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 800;
}

.interface .icon {
  color: var(--green);
}

.class .icon {
  color: var(--blue);
}

code, pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

code {
  padding: 0.12em 0.35em;
  border-radius: 5px;
  background: #ece8df;
  font-size: 0.92em;
}

pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}

pre {
  overflow-x: auto;
  margin: 16px 0 0;
  padding: 18px 20px;
  border-radius: 12px;
  color: #eaf1f8;
  background: #202a34;
  font-size: 0.9rem;
  line-height: 1.6;
}

.flow {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  gap: 10px;
  align-items: center;
}

.node {
  min-height: 112px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: white;
}

.arrow {
  color: var(--amber);
  font-size: 1.6rem;
}

.callout {
  border-left: 5px solid var(--amber);
  background: var(--amber-soft);
}

.small {
  color: var(--muted);
  font-size: 0.88rem;
}

.steps {
  margin: 0;
  padding: 0;
  counter-reset: lesson-step;
  list-style: none;
}

.steps > li {
  position: relative;
  min-height: 74px;
  margin: 0 0 18px;
  padding: 2px 0 18px 58px;
  border-bottom: 1px dashed var(--line);
  counter-increment: lesson-step;
}

.steps > li:last-child {
  margin-bottom: 0;
  border-bottom: 0;
}

.steps > li::before {
  content: counter(lesson-step);
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--blue);
  font-weight: 800;
}

.key {
  display: inline-block;
  min-width: 1.7em;
  padding: 0.05em 0.38em;
  border: 1px solid #b8b1a4;
  border-bottom-width: 2px;
  border-radius: 5px;
  color: #344054;
  background: white;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.84em;
  text-align: center;
  white-space: nowrap;
}

.signal-grid {
  display: grid;
  grid-template-columns: 140px 1fr 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.signal-grid > div {
  padding: 13px 15px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: white;
}

.signal-grid > div:nth-child(3n) {
  border-right: 0;
}

.signal-grid > div:nth-last-child(-n + 3) {
  border-bottom: 0;
}

/* 非三列时用 .cols2 / .cols4 修正边框 */
.signal-grid.cols2 > div:nth-child(3n) { border-right: 1px solid var(--line); }
.signal-grid.cols2 > div:nth-child(2n) { border-right: 0; }
.signal-grid.cols2 > div:nth-last-child(-n + 3) { border-bottom: 1px solid var(--line); }
.signal-grid.cols2 > div:nth-last-child(-n + 2) { border-bottom: 0; }
.signal-grid.cols4 { grid-template-columns: minmax(0, .45fr) minmax(0, 1.3fr) minmax(0, .7fr) minmax(0, 1.5fr); }
.signal-grid > div { min-width: 0; overflow-wrap: anywhere; }
.signal-grid.cols4 > div:nth-child(3n) { border-right: 1px solid var(--line); }
.signal-grid.cols4 > div:nth-child(4n) { border-right: 0; }
.signal-grid.cols4 > div:nth-last-child(-n + 4) { border-bottom: 0; }

.signal-grid .head {
  color: white;
  background: #344054;
  font-weight: 750;
}

.path {
  padding: 14px 16px;
  border: 1px dashed #9aa4b2;
  border-radius: 10px;
  color: #344054;
  background: #f8fafc;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

.quiz-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

button {
  padding: 13px 16px;
  border: 1px solid #b7afa0;
  border-radius: 10px;
  color: var(--ink);
  background: white;
  font: inherit;
  cursor: pointer;
}

button:hover {
  border-color: var(--blue);
  transform: translateY(-1px);
}

.feedback {
  min-height: 2rem;
  margin-top: 12px;
  font-weight: 650;
}

.feedback.correct {
  color: var(--green);
}

.feedback.wrong {
  color: var(--red);
}

footer {
  margin-top: 24px;
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
}

@media (max-width: 700px) {
  .two-col, .quiz-options {
    grid-template-columns: 1fr;
  }

  .flow {
    grid-template-columns: 1fr;
  }

  .signal-grid,
  .signal-grid.cols4 {
    grid-template-columns: 1fr;
  }

  .signal-grid > div {
    border-right: 0;
  }

  .signal-grid .head {
    display: none;
  }

  .signal-grid > div:nth-last-child(-n + 3) {
    border-bottom: 1px solid var(--line);
  }

  .signal-grid > div:last-child {
    border-bottom: 0;
  }

  .arrow {
    transform: rotate(90deg);
    text-align: center;
  }

  header, section {
    padding: 24px 20px;
  }
}

@media print {
  body {
    background: white;
  }

  main {
    width: 100%;
    margin: 0;
  }

  header, section {
    break-inside: avoid;
    box-shadow: none;
  }
}

/* 术语表：dt 是术语，dd 是一句话定位 */
.terms {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 18px;
  margin-top: 14px;
  align-items: baseline;
}

.terms dt {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  color: var(--blue);
  white-space: nowrap;
}

.terms dd {
  margin: 0;
}

@media (max-width: 640px) {
  .terms {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .terms dd {
    margin-bottom: 10px;
  }
}
