:root {
  color-scheme: light;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: #282b28;
  background: #f8f7f4;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body { margin: 0; }

main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: min(100%, 848px);
  margin: 0 auto;
  padding: 112px 32px 80px;
}

#kernel-view, #section-view { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.page-footer { margin-top: auto; padding-top: 48px; }
.page-footer .back { margin: 0; }
#section-view .page-footer { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 24px; }
.next-sections { display: flex; flex: 1 1 420px; flex-wrap: wrap; justify-content: flex-end; gap: 10px; min-width: 0; }
.chapter-next {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 44px;
  max-width: 100%;
  padding: 12px 16px;
  border: 1px solid #d7dbd0;
  border-radius: 6px;
  color: #454a41;
  background: #fdfdfa;
  font-size: 14px;
  line-height: 1.45;
  text-decoration: none;
}
.chapter-next.main-next { color: #30382b; background: #eff1e9; border-color: #b9c2ac; font-weight: 500; }
.chapter-next svg { flex: 0 0 18px; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

h1 {
  margin: 0 0 40px;
  font-size: 32px;
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -1px;
}

h1:focus { outline: none; }

.directions {
  display: grid;
  gap: 20px;
}

.direction {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 104px;
  padding: 26px 32px;
  border: 1px solid #dedfd8;
  border-radius: 8px;
  color: inherit;
  background: #fdfdfa;
  text-decoration: none;
  font-size: 23px;
  font-weight: 400;
  line-height: 1.4;
  transition: background-color 160ms, border-color 160ms;
}

.direction svg, .back svg {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.direction svg { color: #70776b; }

.back {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: -12px 0 32px;
  color: #62685f;
  text-decoration: none;
  font-size: 14px;
}

.back svg { width: 18px; height: 18px; }

a:focus-visible {
  outline: 2px solid #59694c;
  outline-offset: 5px;
}

body[data-view="map"] main { width: min(100%, 1240px); padding-top: 64px; }
#kernel-title { margin-bottom: 32px; }
.map-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: #bdc3b5 transparent;
  border-radius: 8px;
}
.map-scroll:focus-visible { outline: 2px solid #59694c; outline-offset: 5px; }
.learning-map { position: relative; min-width: 1040px; }
.map-nodes {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 272px minmax(180px, 1fr) minmax(180px, 1fr);
  grid-template-rows: repeat(5, 88px);
  column-gap: 40px;
  row-gap: 48px;
  padding: 16px 24px 28px;
}
.map-node {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 16px 20px;
  color: #454a41;
  background: #fdfdfa;
  border: 1px solid #d7dbd0;
  border-radius: 8px;
  text-decoration: none;
  text-align: center;
  font-size: 16px;
  line-height: 1.45;
  text-wrap: balance;
  transition: background-color 160ms, border-color 160ms;
}
.main-node {
  color: #30382b;
  background: #eff1e9;
  border-color: #b9c2ac;
  font-size: 18px;
  font-weight: 500;
}
.connections { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.connections .main-line { fill: none; stroke: #69775b; stroke-width: 3.5; }
.connections .line-clearance { fill: none; stroke: #f8f7f4; stroke-width: 8; }
.connections .branch-line { fill: none; stroke: #a7ada1; stroke-width: 1.4; }
.section-article h1 { max-width: 680px; margin-bottom: 40px; line-height: 1.35; }
.math-result { scroll-margin-top: 24px; }
.math-result + .math-result { margin-top: 24px; padding-top: 20px; border-top: 1px solid #e0e2da; }
.result-header { display: flex; align-items: center; gap: 16px; min-height: 44px; }
.math-result.is-reference-target > .result-header {
  background: #eef1e8;
  outline: 1px solid #b9c2ac;
  outline-offset: 8px;
  border-radius: 3px;
}
.result-reference {
  color: #536746;
  text-decoration: underline;
  text-decoration-color: #a0ad92;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.math-result h2 { flex: 1; min-width: 0; margin: 0; font-size: 17px; line-height: 1.5; font-weight: 600; }
.result-toggle {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 8px 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.result-body { padding-top: 12px; }
.optional-info { position: relative; flex: 0 0 auto; }
.optional-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 11px;
  color: #5b6750;
  font-size: 12px;
  line-height: 1.4;
  list-style: none;
  cursor: pointer;
  position: relative;
  isolation: isolate;
}
.optional-badge::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 9px 0;
  border: 1px solid #cbd3bf;
  border-radius: 20px;
  background: #eff2e9;
}
.optional-badge::-webkit-details-marker { display: none; }
.math-result .optional-note {
  position: absolute;
  z-index: 3;
  top: calc(100% + 4px);
  right: 0;
  width: 224px;
  max-width: calc(100vw - 48px);
  padding: 12px 14px;
  border: 1px solid #d7dbd0;
  border-radius: 8px;
  background: #fdfdfa;
  box-shadow: 0 5px 18px #282b2810;
  font-size: 13px;
  line-height: 1.6;
}
.result-toggle:focus-visible, .optional-badge:focus-visible {
  outline: 2px solid #59694c;
  outline-offset: 4px;
  border-radius: 4px;
}
.math-result p, .definition-conditions { margin: 0; font-size: 17px; line-height: 1.85; color: #454a41; }
.result-body > p + p, .definition-conditions + p { margin-top: 16px; }
.definition-conditions { margin-top: 16px; padding-left: 28px; }
.definition-conditions li + li { margin-top: 12px; }
.result-comments { margin-top: 16px; }
.math-result .result-comments p { color: #73786f; font-size: 14px; font-style: italic; line-height: 1.65; }
.result-comments p + p { margin-top: 8px; }
.result-body .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.equation { overflow-x: auto; overflow-y: hidden; margin-top: 20px; padding: 8px 4px; }
.equation .katex-display { margin: 0.5em 0; }
.equation .katex-display > .katex { white-space: nowrap; }
.katex { font-size: 1.1em; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (hover: hover) {
  .direction:hover { background: #eef0e8; border-color: #b8c0ad; }
  .back:hover { color: #282b28; }
  .map-node:hover { background: #e9eee0; border-color: #93a381; }
  .result-toggle:hover { color: #59694c; }
  .optional-badge:hover::before { border-color: #93a381; }
  .chapter-next:hover { background: #e9eee0; border-color: #93a381; }
  .result-reference:hover { color: #303e25; text-decoration-color: currentColor; }
}

@media (max-width: 600px) {
  main { padding: 64px 24px; }
  h1 { margin-bottom: 32px; font-size: 28px; }
  .direction { min-height: 92px; padding: 24px; font-size: 21px; }
  body[data-view="map"] main { padding-top: 48px; }
  .map-scroll { margin-inline: -24px; border-radius: 0; }
  .section-article h1 { font-size: 27px; }
  .next-sections { flex-basis: 100%; justify-content: flex-start; }
  .chapter-next { width: 100%; }
  .math-result p, .definition-conditions { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .direction, .map-node { transition: none; }
}
