@import url('https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Geist:wght@100;200;300;400;500;600;700;800;900&display=swap');

/* Reset and base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Geist", Helvetica, Arial, sans-serif;
  font-size: 16px;
  font-weight: 300;
  line-height: 1.6;
  color: #333;
  background-color: #fff;
}

/* Scroll progress bar (blog posts) */
.scroll-progress-wrap {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(0, 0, 0, 0.08);
  z-index: 9999;
}

.scroll-progress-bar {
  height: 100%;
  width: 0%;
  background: #1a3a3a;
  transition: width 0.08s ease-out;
}

strong {
  font-family: "Geist", Helvetica, Arial, sans-serif;
  font-weight: 600;
}

/* Header */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background-color: #1a3a3a;
  color: #e8e8e8;
}

.site-title {
  margin: 0;
  font-family: "Crimson Pro", serif;
  font-size: 1.2rem;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.site-title[href] {
  text-decoration: none;
  color: inherit;
}

.site-nav {
  display: flex;
  gap: 2rem;
}

.site-nav a {
  color: #e8e8e8;
  text-decoration: none;
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
}

.site-nav a:hover {
  opacity: 0.85;
}

/* Main content */
.main-content {
  max-width: 880px;
  margin: 0 auto;
  padding: 3rem 2rem;
}

/* Blog posts */
.blog-post {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2rem;
  margin-bottom: 4rem;
}

.blog-post:last-child {
  margin-bottom: 0;
}

.post-content {
  flex: 1;
  min-width: 0;
}

.post-date {
  display: block;
  font-size: 0.85rem;
  color: #888;
  margin-bottom: 0.5rem;
}

.post-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 300;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background-color: #1a3a3a;
  color: #fff;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}

.post-badge--editorial {
  background-color: #e0e0e0;
  color: #555;
}

.post-title {
  margin: 0 0 0.5rem;
  font-family: "Crimson Pro", serif;
  font-size: 1.8rem;
  font-weight: 300;
  color: #000;
  line-height: 1.3;
}

.post-title a {
  color: inherit;
  text-decoration: none;
}

.post-title a:hover {
  color: #1a3a3a;
}

.post-title-hover {
  position: relative;
  cursor: default;
}

.post-title-hover-gif {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 20;
  pointer-events: none;
}

.post-title-hover:hover .post-title-hover-gif {
  opacity: 1;
  visibility: visible;
}

.post-title-hover-gif img {
  width: 100px;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.post-authors {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: #333;
}

.post-description {
  margin: 0;
  font-size: 0.95rem;
  color: #444;
}

.post-image {
  flex-shrink: 0;
}

.post-image img {
  width: 400px;
  height: 240px;
  object-fit: cover;
  border-radius: 4px;
}

/* About page */
.about-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 2rem;
}

.about-title {
  font-family: "Crimson Pro", serif;
  font-size: 2.25rem;
  font-weight: 300;
  color: #000;
  margin: 0 0 2rem;
}

.about-body p {
  margin: 0 0 1rem;
  line-height: 1.7;
  color: #333;
}

.about-body p:last-child {
  margin-bottom: 0;
}

/* Footer */
.site-footer {
  margin-top: 4rem;
  padding: 2rem;
  border-top: 1px solid #ddd;
  text-align: center;
  font-size: 0.85rem;
  color: #666;
}

.site-footer p {
  margin: 0;
}

/* Blog article template */
.blog-article {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0 2rem;
  width: 100%;
  padding: 3rem 2rem 3rem 1.5rem;
}

.article-figure-group {
  display: flex;
  gap: 1.5rem;
  margin: 1rem 0;
  align-items: flex-start;
}

.article-figure-group .article-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.article-figure-group .article-figure img {
  width: 100%;
  max-height: 320px;
  min-height: 200px;
  object-fit: contain;
}

.article-figure-group .article-figure--primary {
  flex: 1.6;
  min-width: 0;
}

.article-figure-group .article-figure--secondary {
  flex: 0.6;
  min-width: 200px;
}

.article-header .article-figure {
  margin: 1rem 0;
  text-align: center;
}

.article-header .article-figure img {
  max-width: 480px;
  width: 100%;
  height: auto;
}

.post-flappy-bird .article-header .article-figure img {
  max-width: 320px;
  aspect-ratio: 3/4;
  object-fit: cover;
  object-position: center center;
}

.article-header {
  grid-column: 2;
  text-align: left;
  margin: 0 0 2rem;
  margin-left: calc(50vw - 696px);
  margin-right: auto;
  max-width: 720px;
}

.article-title {
  margin: 0 0 0.5rem;
  font-family: "Crimson Pro", serif;
  font-size: 2.25rem;
  font-weight: 300;
  color: #000;
  line-height: 1.2;
}

.article-subtitle {
  margin: 0 0 1.5rem;
  font-size: 1.15rem;
  color: #555;
  font-weight: 400;
}

.article-meta {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem 2rem;
  padding: 1.25rem 0;
  max-width: 720px;
}

.article-meta::before,
.article-meta::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 100vw;
  border-top: 1px solid #ddd;
}

.article-meta::before {
  top: 0;
}

.article-meta::after {
  bottom: 0;
}

.meta-column {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.meta-label {
  font-size: 0.7rem;
  font-weight: 300;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #888;
}

.meta-value {
  font-size: 0.9rem;
  color: #333;
}

.article-body {
  display: contents;
}

.article-toc {
  grid-column: 1;
  grid-row: 2;
}

.article-content {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  max-width: 720px;
  margin: 0;
  margin-left: calc(50vw - 696px);
  margin-right: auto;
}

.article-toc {
  position: sticky;
  top: 2rem;
  align-self: start;
}

.toc-title {
  margin: 0 0 1rem;
  padding-left: 24px;
  font-family: "Crimson Pro", serif;
  font-size: 0.85rem;
  font-weight: 300;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #444;
}

.toc-nav {
  font-size: 0.9rem;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0 0 0 24px;
}

.toc-list li {
  margin-bottom: 0.5rem;
}

.toc-list a {
  color: #555;
  text-decoration: none;
}

.toc-list a:hover {
  color: #1a3a3a;
  font-weight: 600;
}

.toc-list a.toc-active,
.toc-list ul a.toc-active {
  font-weight: 600;
  color: #1a3a3a;
}

.toc-list ul {
  list-style: none;
  margin: 0.5rem 0 0.75rem 1rem;
  padding: 0;
}

.toc-list ul li {
  margin-bottom: 0.35rem;
}

.toc-list ul a {
  font-size: 0.85rem;
  color: #666;
}

.article-content h2 {
  margin: 2.5rem 0 1rem;
  font-family: "Crimson Pro", serif;
  font-size: 1.8rem;
  font-weight: 300;
  color: #000;
}

.article-content h2:first-child {
  margin-top: 0;
}

.article-content h3 {
  margin: 1.5rem 0 0.75rem;
  font-family: "Crimson Pro", serif;
  font-size: 1.5rem;
  font-weight: 300;
  color: #222;
}

.article-content p {
  margin: 0 0 1rem;
  line-height: 1.7;
  color: #333;
}

.article-content p.text-center {
  text-align: center;
}

.article-content blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.5rem;
  border-left: 4px solid #1a3a3a;
  background: #f8f9fa;
}

.article-content blockquote p {
  margin: 0;
}

.article-content pre {
  margin: 1rem 0;
  padding: 1rem 1.25rem;
  background: #f5f5f5;
  border-radius: 4px;
  overflow-x: auto;
}

.article-content pre code {
  font-family: "Consolas", "Monaco", "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* Code block copy button */
.article-content .code-block-wrap {
  position: relative;
}

.article-content .code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 32px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: #555;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.article-content .code-copy-btn:hover {
  background: #1a3a3a;
}

.article-content .code-copy-btn:focus {
  outline: 2px solid #1a3a3a;
  outline-offset: 2px;
}

.article-content .code-copy-btn.copied {
  background: #2e7d32;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}

.results-table th,
.results-table td {
  padding: 0.65rem 1rem;
  text-align: left;
  border-bottom: 1px solid #e0e0e0;
}

.results-table thead th {
  background: #f5f5f5;
  font-weight: 600;
  color: #333;
}

.results-table tbody tr:hover {
  background: #fafafa;
}

.results-table td:first-child {
  font-weight: 500;
  color: #555;
  white-space: nowrap;
}

.article-content figure.article-figure {
  margin: 1.5rem 0;
  text-align: center;
}

.article-content figure.article-figure img {
  max-width: 100%;
  height: auto;
}

.article-content figure.article-figure figcaption {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: #666;
  text-align: left;
}

.text-red {
  color: #c00;
}

.article-content a {
  color: #1a3a3a;
  text-decoration: underline;
}

.article-content a:hover {
  opacity: 0.85;
}

/* Footnotes */
.article-content a.footnote-ref,
a.footnote-ref {
  font-size: 0.85em;
  text-decoration: none;
  color: #0066cc !important;
  font-weight: 400;
}

.article-content a.footnote-ref:hover,
a.footnote-ref:hover {
  text-decoration: underline;
}

.references {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid #ddd;
}

.references h2 {
  margin: 0 0 1rem;
  font-family: "Crimson Pro", serif;
  font-size: 1.5rem;
  font-weight: 300;
  color: #000;
}

.references ol {
  margin: 0;
  padding-left: 1.5rem;
  list-style: none;
  counter-reset: ref;
}

.references li {
  counter-increment: ref;
  margin-bottom: 0.75rem;
  padding-left: 0.5rem;
  position: relative;
}

.references li::before {
  content: "[" counter(ref) "] ";
  position: absolute;
  left: -1.5rem;
  font-size: 0.9rem;
  color: #1a3a3a;
}

.references li a {
  color: #0066cc;
  word-break: break-all;
}

/* Margin notes (right margin of article content) */
.code-with-note {
  position: relative;
}

.article-content .margin-note {
  position: absolute;
  left: 100%;
  margin-left: 1.5rem;
  width: 220px;
  /* Align with the `yield` line: ~21st line in the neighbors() snippet; pre padding 1rem + (20 * 0.9rem * 1.5) */
  top: calc(1rem + 20 * 0.9rem * 1.5);
  font-size: 0.85rem;
  line-height: 1.5;
  color: #555;
}

.article-content .margin-note strong {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #333;
}

.article-content .margin-note code {
  font-size: 0.8em;
  padding: 0.1em 0.3em;
  background: #f0f0f0;
  border-radius: 3px;
}

/* Valid states interactive demo */
.valid-states-demo {
  margin: 1.5rem 0 2rem;
  padding: 1.25rem 1.5rem;
  background: #f9f9f9;
  border: 1px solid #e8e8e8;
  border-radius: 6px;
}

.valid-states-intro {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  color: #555;
}

.valid-states-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1.25rem;
  margin-bottom: 1rem;
}

.valid-states-controls label {
  font-size: 0.9rem;
  color: #333;
}

.valid-states-controls select {
  padding: 0.35rem 2.5rem 0.35rem 0.5rem;
  font-size: 0.9rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  margin-left: 0.25rem;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
}

.valid-states-controls button {
  padding: 0.4rem 1rem;
  font-size: 0.9rem;
  background: #1a3a3a;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.valid-states-controls button:hover {
  background: #244a4a;
}

.valid-states-output {
  margin-top: 0.5rem;
}

.valid-states-summary {
  margin: 0 0 0.75rem;
  font-weight: 600;
  color: #222;
}

.valid-states-list-caption {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: #666;
}

.valid-states-grids {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  max-height: 420px;
  overflow-y: auto;
}

.valid-state-grid {
  display: grid;
  gap: 1px;
  background: #bbb;
  padding: 1px;
  border-radius: 4px;
  flex-shrink: 0;
}

.valid-state-cell {
  background: #eee;
  min-width: 26px;
  min-height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.valid-state-cell.valid-state-body {
  background: #66bb6a;
}

.valid-state-cell.valid-state-head {
  background: #2e7d32;
  color: #fff;
  font-size: 18px;
  font-weight: bold;
}

.valid-state-head-arrow {
  display: block;
  line-height: 1;
  font-size: 1.1em;
}

/* Responsive - blog article */
@media (max-width: 900px) {
  .blog-article {
    grid-template-columns: 1fr;
  }

  .article-header {
    grid-column: 1;
    margin-left: auto;
    margin-right: auto;
  }

  .article-toc {
    grid-column: 1;
    grid-row: 2;
    position: static;
    border-bottom: 1px solid #eee;
    padding-bottom: 1.5rem;
    margin-bottom: 1.5rem;
  }

  .article-content {
    grid-column: 1;
    grid-row: 3;
    margin-left: auto;
    margin-right: auto;
  }

  .article-content .margin-note {
    position: static;
    width: 100%;
    margin-left: 0;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: #f8f8f8;
    border-left: 3px solid #1a3a3a;
    border-radius: 0 4px 4px 0;
  }
}

/* Responsive */
@media (max-width: 640px) {
  .site-header {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }

  .main-content {
    padding: 2rem 1rem;
  }

  .blog-post {
    flex-direction: column;
    margin-bottom: 3rem;
  }

  .post-image {
    align-self: center;
  }

  .post-image img {
    width: 240px;
    height: 150px;
  }
}