:root {
  --paper: #fbf8ed;
  --paper-hover: #f3eedf;
  --paper-raised: #fffdf5;
  --bar: #eee9dc;
  --ink: #111111;
  --muted-ink: #555047;
  --control-edge: #c9c3b6;
  --scroll-thumb: #aaa394;
  --scroll-track: #eee9dc;
  --scroll-edge-light: #fdfbf4;
  --scroll-edge-dark: #6f6a5d;
  --font-scale: 1;
  font-size: calc(16px * var(--font-scale));
  scrollbar-width: auto;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

:root[data-theme="bright"] {
  --paper: #ffffff;
  --paper-hover: #ededed;
  --paper-raised: #ffffff;
  --bar: #f3f3f3;
  --ink: #090909;
  --muted-ink: #4a4a4a;
  --control-edge: #c8c8c8;
  --scroll-thumb: #b5b5b5;
  --scroll-track: #f3f3f3;
  --scroll-edge-light: #ffffff;
  --scroll-edge-dark: #707070;
}

:root[data-theme="night"] {
  --paper: #151515;
  --paper-hover: #303030;
  --paper-raised: #202020;
  --bar: #282828;
  --ink: #f2f2ee;
  --muted-ink: #c8c8c2;
  --control-edge: #777777;
  --scroll-thumb: #686868;
  --scroll-track: #252525;
  --scroll-edge-light: #8b8b8b;
  --scroll-edge-dark: #050505;
  color-scheme: dark;
}

html {
  background: var(--paper);
}

html::-webkit-scrollbar {
  width: 14px;
  height: 14px;
}

html::-webkit-scrollbar-track {
  background: var(--scroll-track);
  border-left: 1px solid var(--scroll-edge-dark);
  box-shadow: inset 1px 0 var(--scroll-edge-light);
}

html::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border: 2px outset var(--control-edge);
  border-radius: 0;
}

html::-webkit-scrollbar-button {
  display: block;
  width: 14px;
  height: 14px;
  background: var(--bar);
  border: 2px outset var(--control-edge);
}

html::-webkit-scrollbar-corner {
  background: var(--scroll-track);
}

body {
  box-sizing: border-box;
  max-width: 960px;
  margin: 20px auto;
  padding: 18px;
  background: var(--paper);
  color: var(--ink);
  font-family: "Times New Roman", "宋体", SimSun, serif;
  font-size: 1rem;
  line-height: 1.8;
}

.article-loading,
.article-error {
  margin: 32px auto;
  padding: 12px 14px;
  border: 1px solid var(--ink);
  background: var(--paper-hover);
}

.article-error {
  border-left: 5px double var(--ink);
}

h1 {
  margin: 0 0 16px;
  font-size: 1.5rem;
  line-height: 1.3;
}

p {
  margin: 0 0 14px;
}

ul, ol {
    padding-left: 20px;
}

.author {
    text-align: right;
    line-height: 1.8;
    color: var(--muted-ink);
}

img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 14px 0;
  border: 2px solid var(--ink);
}

a {
  color: var(--ink);
}

.playground-launch {
  display: inline-block;
  margin: 4px 0 18px;
  padding: 4px 10px;
  border: 2px outset var(--control-edge);
  background: var(--bar);
  color: var(--ink);
  text-decoration: none;
  line-height: 1.4;
}

.playground-launch:active {
  border-style: inset;
}

body.playground-page {
  width: 100vw;
  max-width: none;
  height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.playground-shell {
  --editor-height: 44vh;
  display: grid;
  grid-template-rows: minmax(90px, var(--editor-height)) 10px minmax(90px, 1fr);
  width: 100%;
  height: 100%;
  background: var(--paper);
}

.playground-pane {
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.playground-pane-title {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-bottom: 1px solid var(--ink);
  background: var(--bar);
  font-size: 0.8125rem;
  line-height: 1.4;
}

.playground-editor {
  box-sizing: border-box;
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  resize: none;
  border: 0;
  outline: 0;
  padding: 12px 14px;
  background: var(--paper-raised);
  color: var(--ink);
  font: 0.9375rem/1.55 "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  tab-size: 2;
}

.playground-splitter {
  position: relative;
  cursor: row-resize;
  border-top: 2px outset var(--control-edge);
  border-bottom: 2px outset var(--control-edge);
  background: var(--bar);
  touch-action: none;
}

.playground-splitter::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 54px;
  border-top: 1px dotted var(--ink);
  transform: translate(-50%, -50%);
}

.playground-splitter:focus-visible {
  outline: 2px dotted var(--ink);
  outline-offset: -2px;
}

.playground-preview {
  box-sizing: border-box;
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  padding: 14px 18px;
  background: var(--paper);
}

.playground-preview .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
}

.playground-error {
  color: #9f1d1d;
  font-family: "SFMono-Regular", Consolas, monospace;
  white-space: pre-wrap;
}

:root[data-theme="night"] .playground-error {
  color: #ff9d9d;
}

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

code {
  padding: 0.08em 0.28em;
  border: 1px solid var(--control-edge);
  background: var(--paper-hover);
  font-size: 0.9em;
  overflow-wrap: anywhere;
}

pre {
  margin: 12px 0 18px;
  padding: 11px 13px;
  overflow-x: auto;
  border: 1px solid var(--ink);
  background: var(--paper-raised);
  line-height: 1.55;
  white-space: pre;
}

pre code {
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 0.875rem;
  overflow-wrap: normal;
}

kbd {
  padding: 1px 5px;
  border: 1px solid var(--scroll-edge-dark);
  border-bottom-width: 2px;
  background: var(--bar);
  font-size: 0.82em;
}

.lead,
.note,
.warning,
.summary {
  background: var(--paper-hover) !important;
}

.example,
.diagram {
  background: var(--paper-raised) !important;
}

table th {
  background: var(--bar) !important;
}

.author {
  color: var(--muted-ink);
}

h2 {
  margin: 30px 0 12px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--ink);
  font-size: 1.25rem;
}

h3 {
  margin: 22px 0 8px;
  font-size: 1.0625rem;
}

.lead,
.note,
.warning,
.formula,
.summary,
.example {
  border: 1px solid var(--ink);
  padding: 10px 12px;
  background: var(--paper-hover);
}

.lead { margin-bottom: 20px; }
.note, .warning, .example { margin: 14px 0; }
.warning { border-left: 5px double var(--ink); }
.example { background: var(--paper-raised); }
.example > strong:first-child { display: block; margin-bottom: 8px; }

.formula {
  margin: 14px 0 18px;
  padding: 13px 16px;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--control-edge);
  border-left: 4px double var(--ink);
  background: var(--paper-raised) !important;
  box-shadow: inset 0 1px var(--scroll-edge-light);
  text-align: center;
  font-family: "STIX Two Math", "Cambria Math", "Latin Modern Math", "Times New Roman", "宋体", serif;
  font-size: 1.1875rem;
  font-variant-numeric: lining-nums;
  line-height: 2.05;
  letter-spacing: 0.01em;
  word-spacing: 0.08em;
  white-space: normal;
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}

.formula i {
  font-family: inherit;
}

.formula sub,
.formula sup {
  position: relative;
  font-size: 0.7em;
  line-height: 0;
  vertical-align: baseline;
}

.formula sub { bottom: -0.28em; }
.formula sup { top: -0.62em; }

.formula::-webkit-scrollbar {
  height: 8px;
}

.formula::-webkit-scrollbar-track {
  background: transparent;
}

.formula::-webkit-scrollbar-thumb {
  border: 2px solid var(--paper-raised);
  border-radius: 0;
  background: var(--scroll-thumb);
}

.formula + .formula { margin-top: -4px; }

.math-limits {
  display: inline-grid;
  grid-template-areas:
    "upper"
    "operator"
    "lower";
  grid-template-rows: 0.75em 1.05em 0.75em;
  min-width: 1.65em;
  margin: 0 0.12em;
  align-items: center;
  justify-items: center;
  vertical-align: middle;
  line-height: 1;
  white-space: nowrap;
}

.math-limit-upper,
.math-limit-lower {
  font-size: 0.52em;
  line-height: 1;
  letter-spacing: 0;
  word-spacing: 0;
}

.math-limit-upper { grid-area: upper; align-self: end; }
.math-limit-lower { grid-area: lower; align-self: start; }

.math-limit-operator {
  grid-area: operator;
  font-size: 1.45em;
  line-height: 0.75;
}

.math-limits[data-operator="lim"] {
  min-width: 2em;
}

.math-limits[data-operator="lim"] .math-limit-operator {
  font-size: 0.82em;
  font-style: normal;
}

.math-fraction {
  display: inline-grid;
  grid-template-rows: auto auto;
  min-width: 1.2em;
  margin: 0 0.12em;
  vertical-align: middle;
  align-items: center;
  justify-items: stretch;
  line-height: 1.08;
  text-align: center;
  white-space: nowrap;
}

.math-numerator,
.math-denominator {
  display: block;
  padding: 0.08em 0.2em;
  text-align: center;
}

.math-numerator {
  border-bottom: 1px solid currentColor;
}

.math-root {
  display: inline-flex;
  margin: 0 0.1em;
  align-items: flex-start;
  vertical-align: middle;
  line-height: 1.15;
  white-space: nowrap;
}

.math-root-sign {
  display: inline-block;
  margin-right: -0.05em;
  font-size: 1.38em;
  line-height: 1;
  transform: translateY(0.03em);
}

.math-radicand {
  display: inline-block;
  min-width: 0.55em;
  padding: 0.08em 0.12em 0 0.08em;
  border-top: 1px solid currentColor;
  line-height: 1.2;
  text-align: center;
}

.math-group {
  white-space: nowrap;
}

.contents {
  margin: 14px 0 22px;
  padding: 10px 12px 10px 40px;
  border: 1px dashed var(--ink);
  columns: 2;
}

.contents li { break-inside: avoid; margin-bottom: 4px; }
.contents a { color: var(--ink); }

.formula-table {
  width: 100%;
  margin: 12px 0 18px;
  border-collapse: collapse;
}

.formula-table th,
.formula-table td {
  border: 1px solid var(--ink);
  padding: 7px 9px;
  text-align: left;
  vertical-align: top;
}

.formula-table th { background: var(--bar); }

.diagram {
  margin: 16px 0 22px;
  padding: 10px;
  border: 2px solid var(--ink);
  background: var(--paper-raised);
}

.diagram svg { display: block; width: 100%; height: auto; }
.diagram figcaption { margin-top: 8px; text-align: center; font-size: 0.875rem; }
.diagram text { fill: var(--ink); font-family: "Times New Roman", "宋体", serif; font-size: 14px; }
.diagram line, .diagram path, .diagram rect, .diagram circle { vector-effect: non-scaling-stroke; }
.diagram .axis { fill: none; stroke: var(--muted-ink); stroke-width: 1.2; }
.diagram .main { fill: none; stroke: var(--ink); stroke-width: 2.5; }
.diagram .secondary { fill: none; stroke: var(--muted-ink); stroke-width: 2; stroke-dasharray: 7 5; }
.diagram .box { fill: var(--bar); stroke: var(--ink); stroke-width: 1.5; }
.diagram .arrow { fill: none; stroke: var(--ink); stroke-width: 2; }
.diagram marker path,
.diagram g[fill="#111"] { fill: var(--ink); }

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

.summary {
  margin-top: 26px;
  padding: 10px 12px 10px 40px;
}

.summary li { margin-bottom: 8px; }
.external-link { font-weight: bold; }

@media (max-width: 620px) {
  .contents { columns: 1; }
  .two-column { grid-template-columns: 1fr; }
  .formula {
    padding: 11px 12px;
    text-align: center;
    font-size: 1.0625rem;
    line-height: 2.1;
  }
  .formula-table { display: block; overflow-x: auto; }
  body { margin: 10px auto; padding: 12px; }
}
