:root {
  color-scheme: light;
  --page: #ffffff;
  --bg: #f4f5f7;
  --ink: #17212b;
  --muted: #5d6b78;
  --line: #d9dee5;
  --line-strong: #c5ccd6;
  --field: #f1f3f6;
  --accent: #285f9f;
  --accent-soft: #e8f1fb;
  --max: 1040px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
}

.site-top {
  background: var(--page);
  border-bottom: 1px solid var(--line);
  margin-bottom: 1rem;
}

.site-top-inner {
  width: min(var(--max), 94vw);
  margin: 0 auto;
  padding: 0.7rem 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.site-mark {
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.site-path {
  color: var(--muted);
  font-size: 0.85rem;
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 1rem;
  width: min(var(--max), 94vw);
  margin: 0 auto;
  align-items: start;
}

.toc-drawer {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 0.8rem;
  background: var(--page);
  border: 1px solid var(--line);
}

.toc-drawer h2 {
  margin: 0 0 0.65rem;
  color: var(--ink);
  font-size: 0.95rem;
}

.toc-section {
  margin: 1rem 0 0.35rem;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.toc-link {
  display: block;
  padding: 0.28rem 0;
  color: var(--ink);
  font-size: 0.86rem;
  line-height: 1.35;
  text-decoration: none;
}

.toc-link.is-active {
  color: var(--accent);
  font-weight: 800;
}

.sheet {
  margin-bottom: 3rem;
  padding: clamp(1rem, 3vw, 2rem);
  border: 1px solid var(--line);
  background: var(--page);
}

.sheet-head {
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--line-strong);
}

.kicker {
  margin: 0 0 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.7rem, 4vw, 2.55rem);
  line-height: 1.1;
}

.lede {
  max-width: 760px;
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
}

section {
  padding: 1.2rem 0;
  border-bottom: 1px solid var(--line);
}

section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

h2 {
  margin: 0 0 0.65rem;
  color: var(--accent);
  font-size: 1.15rem;
  line-height: 1.3;
}

p { line-height: 1.6; }

.fact-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
  background: var(--page);
}

.fact-table th,
.fact-table td {
  padding: 0.72rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.5;
}

.fact-table th {
  background: var(--field);
  color: #314253;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.fact-table td { font-size: 0.92rem; }

.formula-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.box {
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
}

.box strong {
  display: block;
  margin-bottom: 0.35rem;
  color: #314253;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.math-field {
  width: fit-content;
  max-width: 100%;
  margin: 0.55rem auto;
  padding: 0.62rem 0.8rem;
  border-radius: 6px;
  background: var(--field);
  overflow-x: auto;
  text-align: center;
}

.note {
  margin-top: 0.8rem;
  padding: 0.8rem;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  color: #26394d;
  line-height: 1.6;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
}

.home-card {
  display: grid;
  align-content: start;
  gap: 0.45rem;
  min-height: 100%;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--page);
}

.home-card h3 {
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.3;
}

.home-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.home-card a,
.topic-list a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.topic-list {
  display: grid;
  gap: 0.55rem;
}

.topic-list a {
  display: grid;
  grid-template-columns: minmax(150px, 0.45fr) minmax(0, 1fr);
  gap: 0.8rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--page);
}

.topic-list strong {
  color: var(--ink);
}

.topic-list span {
  color: var(--muted);
  font-weight: 400;
  line-height: 1.45;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.35rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  line-height: 1.2;
  text-decoration: none;
}

.link-btn.secondary {
  background: var(--page);
  color: var(--accent);
}

.examples {
  display: grid;
  gap: 0.85rem;
}

.example {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(0, 1.2fr);
  gap: 0.85rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.example h3 {
  margin: 0 0 0.35rem;
  color: var(--ink);
  font-size: 1rem;
}

.example p {
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.strategy {
  margin-top: 0.7rem;
  padding: 0.65rem 0.7rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: #26394d;
  font-size: 0.9rem;
  line-height: 1.55;
}

.strategy strong {
  display: block;
  margin-bottom: 0.15rem;
  color: #314253;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.steps {
  display: grid;
  gap: 0.38rem;
  align-content: start;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
}

.steps span {
  display: block;
  width: calc(100% - 2rem);
  max-width: 100%;
  margin-left: 1.25rem;
  padding: 0.16rem 0;
  overflow-x: auto;
}

.steps mjx-container[display="true"] {
  margin: 0;
  text-align: left !important;
}

.solve-flow {
  display: grid;
  gap: 0.6rem;
}

.switch-note {
  margin: 0.15rem 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.triangle-diagram {
  min-height: 180px;
  justify-content: center;
}

@media (max-width: 760px) {
  .layout,
  .formula-row,
  .home-grid,
  .example {
    grid-template-columns: 1fr;
  }

  .topic-list a {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  .toc-drawer {
    position: static;
    max-height: none;
  }

  .steps span {
    width: calc(100% - 1rem);
    margin-left: 0.5rem;
  }

  .fact-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}
