/* NewCMMath @font-face lives in kern/kern-newcm.css now. */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:     #FFFAFF;
  --muted:  #9194B5;
  --accent: #6B6E9D;
  --dark:   #4B4E6D;
}

html {
  background: var(--bg);
  color: var(--dark);
  font-family: "neue-haas-grotesk-display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-weight: 400;
  font-style: normal;
  font-size: 16px;
  line-height: 1.65;
}

body {
  max-width: 680px;
  margin: 0 auto;
  padding: 80px 32px 120px;
}

/* Header */

header {
  margin-bottom: 56px;
}

.wordmark {
  font-family: "freight-text-pro", Georgia, serif;
  font-weight: 600;
  font-style: italic;
  font-size: 52px;
  color: var(--dark);
  letter-spacing: -0.01em;
  line-height: 1;
  display: block;
  margin-bottom: 10px;
  text-decoration: none;
}

.tagline {
  font-size: 15px;
  color: var(--muted);
  font-weight: 400;
  margin-bottom: 18px;
}

nav {
  display: flex;
  gap: 20px;
  align-items: baseline;
}

nav a {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.02em;
  padding-bottom: 2px;
}

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

nav a.active {
  color: var(--accent);
  border-bottom: 1px solid var(--accent);
}

/* Typography */

h2 {
  font-family: "freight-text-pro", Georgia, serif;
  font-weight: 600;
  font-style: italic;
  font-size: 22px;
  color: var(--accent);
  margin: 48px 0 14px;
}

h2:first-of-type {
  margin-top: 0;
}

h3 {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 30px 0 10px;
}

section {
  margin-bottom: 48px;
}

p {
  font-size: 15.5px;
  color: var(--dark);
  margin-bottom: 14px;
}

p:last-child {
  margin-bottom: 0;
}

ul {
  padding-left: 20px;
  margin-bottom: 14px;
}

li {
  font-size: 15.5px;
  margin-bottom: 4px;
}

/* Links */

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

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

/* Code */

code {
  font-family: "calling-code", "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 13.5px;
  background: rgba(75, 78, 109, 0.08);
  color: var(--dark);
  padding: 1px 5px;
  border-radius: 3px;
}

pre {
  background: #2D2F45;
  color: var(--bg);
  padding: 20px 24px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 12px 0 20px;
  font-family: "calling-code", "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 13px;
  line-height: 1.7;
}

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

/* Math font: New Computer Modern Math (Typst's default) */
math {
  font-family: "NewCMMath-Regular", "New Computer Modern Math", "Latin Modern Math",
    "STIX Two Math", "Times New Roman", serif;
}

/* Math demo on landing page */

.math-demo {
  font-size: 1.5rem;
  text-align: center;
  padding: 20px 0 4px;
}

.demo-label {
  font-family: "calling-code", "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 36px !important;
}

/* Table */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin: 20px 0;
}

th {
  text-align: left;
  font-weight: 700;
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid rgba(75, 78, 109, 0.2);
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

td {
  padding: 9px 12px 9px 0;
  border-bottom: 1px solid rgba(75, 78, 109, 0.1);
  vertical-align: top;
}

tr:last-child td {
  border-bottom: none;
}

/* Docs: on-this-page TOC box */

.toc-box {
  border: 1px solid rgba(75, 78, 109, 0.18);
  border-radius: 6px;
  padding: 16px 20px 20px;
  margin-bottom: 48px;
}

.toc-header {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}

.toc-list {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 24px;
  margin-bottom: 0;
}

.toc-list li {
  margin-bottom: 0;
  font-size: 15.5px;
}

.toc-list a {
  font-size: 14px;
  color: var(--accent);
  text-decoration: none;
}

.toc-list a:hover {
  color: var(--dark);
}

/* Syntax cheat sheet */

.cheat-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(75, 78, 109, 0.08);
  font-size: 14.5px;
}

.cheat-src {
  font-family: "calling-code", "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 12.5px;
  background: rgba(75, 78, 109, 0.07);
  padding: 2px 6px;
  border-radius: 3px;
  min-width: 180px;
  flex-shrink: 0;
  color: var(--dark);
}

.cheat-arrow {
  color: var(--muted);
}

.cheat-out {
  font-size: 1.1rem;
}

/* Examples page: editor */

.editor-wrap {
  margin: 24px 0;
  border: 1px solid rgba(75, 78, 109, 0.2);
  border-radius: 6px;
  overflow: hidden;
  display: grid;
  /* minmax(0, 1fr) instead of plain 1fr so a wide math output doesn't
     expand the column to its intrinsic width; the column stays half the
     wrap and the #editor-output's overflow-x: auto can actually scroll. */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

/* On wide viewports, let the editor escape the 680px body column so the
   side-by-side panes have room to breathe. The negative margins scale
   smoothly with viewport width and cap so very large screens don't make
   the panes unwieldy. Narrower screens hit the @media block lower in
   the file and fall back to the in-column layout. */
@media (min-width: 880px) {
  .editor-wrap {
    margin-inline: calc(-1 * min((100vw - 680px) / 2, 220px));
  }
}

.editor-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.editor-col + .editor-col {
  border-left: 1px solid rgba(75, 78, 109, 0.2);
}

.pane-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-family: "calling-code", "SF Mono", "Menlo", "Consolas", monospace;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(75, 78, 109, 0.15);
}

#editor-textarea {
  flex: 1;
  min-height: 260px;
  padding: 16px;
  font-family: "calling-code", "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 14px;
  line-height: 1.55;
  background: transparent;
  color: var(--dark);
  border: none;
  resize: none;
  outline: none;
}

#editor-output {
  flex: 1;
  min-width: 0;
  min-height: 260px;
  padding: 16px;
  display: flex;
  align-items: center;
  font-size: 1.6rem;
  overflow-x: auto;
  overflow-y: hidden;
}

/* On narrow screens the textarea typically needs less height; mobile
   users mostly use the gallery rather than the live editor. */
@media (max-width: 540px) {
  #editor-textarea, #editor-output { min-height: 160px; }
  #editor-output { font-size: 1.35rem; }
}

/* margin: auto on a flex child centers it when there's room and collapses
   to 0 when the child is wider than the container, which lets overflow-x
   actually scroll instead of clipping the left edge under justify-content. */
#editor-output > math,
#editor-output > span {
  margin: auto;
  flex-shrink: 0;
}

.editor-toolbar {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-top: 10px;
  font-size: 13.5px;
}

.editor-toolbar label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--dark);
}

.btn {
  font-size: 13px;
  padding: 4px 12px;
  border: 1px solid var(--muted);
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  display: inline-block;
}

.btn:hover {
  background: var(--muted);
  color: var(--bg);
  text-decoration: none;
}

/* Gallery */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1px;
  margin-top: 16px;
  background: rgba(75, 78, 109, 0.12);
  border: 1px solid rgba(75, 78, 109, 0.12);
  border-radius: 6px;
  overflow: hidden;
}

.gallery-card {
  padding: 14px 16px;
  cursor: pointer;
  background: var(--bg);
  transition: background 0.1s;
}

.gallery-card:hover {
  background: rgba(75, 78, 109, 0.05);
}

.gallery-card-src {
  font-family: "calling-code", "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 10px;
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-card-out {
  font-size: 1.1rem;
  text-align: center;
  padding: 4px 0;
}

/* Footer */

footer {
  margin-top: 80px;
  padding-top: 24px;
  border-top: 1px solid rgba(75, 78, 109, 0.15);
  font-size: 13px;
  color: var(--muted);
  display: flex;
  gap: 20px;
}

footer a {
  color: var(--muted);
  text-decoration: none;
}

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

/* Responsive */

@media (max-width: 540px) {
  body {
    padding: 48px 20px 80px;
  }

  .wordmark {
    font-size: 40px;
  }

  pre {
    padding: 16px;
  }

  .editor-wrap {
    grid-template-columns: 1fr;
  }

  .editor-col + .editor-col {
    border-left: none;
    border-top: 1px solid rgba(75, 78, 109, 0.2);
  }

  .toc-list {
    grid-template-columns: 1fr;
  }
}
