/* ==========================================================================
   Design Tokens — Editorial Minimalism
   ========================================================================== */

:root {
  --bg: #ffffff;
  --bg-subtle: #f8f8f7;
  --bg-code: #f3f3f2;

  --fg: #282828;
  --fg1: #3c3836;
  --fg2: #504945;
  --fg3: #6b6866;
  --fg4: #676767;
  --fg5: #969696;

  --rule: rgba(103, 103, 103, 0.14);
  --rule-strong: rgba(103, 103, 103, 0.35);
  --link-underline: rgba(103, 103, 103, 0.3);
  --link-underline-hover: rgba(40, 40, 40, 0.55);

  --red: #ad2111;
  --mark-bg: rgba(255, 206, 82, 0.28);

  --font-serif: "Iowan Old Style", "Iowan Old Style BT", "Newsreader", Georgia, serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Chakra Petch", var(--font-sans);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;

  --content-width: 660px;
  --content-pad: 1.3rem;
  --content-max: calc(var(--content-width) + 2 * var(--content-pad));
  --left-col: 7.5rem;
  --col-gap: 1.5rem;
  --site-header-height: 50px;
}

@media (min-width: 769px) {
  :root {
    --site-header-height: 54px;
  }
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

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

html {
  overflow-y: scroll;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--fg4) var(--bg);
  scroll-padding-top: calc(var(--site-header-height) + 1rem);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.6;
  background-color: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  overflow-x: clip;
  font-variant-numeric: proportional-nums lining-nums;
}

body.menu-open {
  overflow: hidden;
}

::selection {
  background-color: rgba(0, 0, 0, 0.12);
}

a {
  color: var(--fg4);
  text-decoration: none;
  transition: color 0.25s ease-in-out, opacity 0.25s ease-in-out, text-decoration-color 0.25s ease-in-out;
}

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

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 4px;
  border-radius: 2px;
}

hr {
  border: 0;
  height: 1px;
  background-color: var(--rule);
  margin: 2rem 0;
}

img {
  max-width: 100%;
  height: auto;
}

/* ==========================================================================
   Page Shell
   ========================================================================== */

.wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: var(--bg);
  overflow-wrap: break-word;
  padding: var(--site-header-height) 1rem 0;
}

@media (max-width: 768px) {
  .wrapper {
    padding-left: 0.33rem;
    padding-right: 0.33rem;
  }
}

/* ==========================================================================
   Site Header & Navigation
   ========================================================================== */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1002;
  height: var(--site-header-height);
  background-color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.6rem 0 1rem;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.site-header.is-hidden {
  pointer-events: none;
  transform: translateY(-100%);
}

.site-header:has(:focus-visible) {
  pointer-events: auto;
  transform: none;
  transition: none;
}

@media (min-width: 641px) {
  .site-header {
    padding-right: 1rem;
  }
}

@media (min-width: 769px) {
  .site-header {
    left: 1rem;
    right: 1rem;
    padding-inline: 0.33rem;
  }
}

.navbar-logo {
  flex-shrink: 0;
}

.navbar-logo a {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
  line-height: 25px;
  letter-spacing: 1.7px;
  text-transform: uppercase;
  color: var(--fg4);
  text-decoration: none;
  transition: opacity 0.25s ease-in-out;
}

.navbar-logo a:hover {
  color: var(--fg4);
  opacity: 0.78;
}

@media (min-width: 641px) {
  .navbar-logo a {
    font-size: 17px;
  }
}

.nav-group {
  display: flex;
  align-items: center;
}

.top-nav {
  display: none;
  align-items: center;
  gap: 1.5rem;
  font-family: var(--font-sans);
}

.top-nav a {
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--fg1);
  text-decoration: none;
  text-underline-offset: 3px;
}

.top-nav a:hover,
.top-nav a[aria-current="page"] {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: rgba(40, 40, 40, 0.24);
}

@media (min-width: 641px) {
  .top-nav {
    display: flex;
  }
}

@media (min-width: 769px) {
  .top-nav {
    gap: 1.75rem;
  }
}

/* Mobile Hamburger */

.hamburger {
  position: relative;
  z-index: 1003;
  display: inline-block;
  width: 40px;
  height: 40px;
  margin-left: 0.5rem;
  padding: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hamburger span {
  position: absolute;
  left: 9px;
  right: 9px;
  height: 2px;
  background: var(--fg3);
  border-radius: 2px;
  transition: transform 0.25s ease, opacity 0.2s ease, top 0.25s ease, bottom 0.25s ease;
}

.hamburger span:nth-child(1) {
  top: 12px;
}

.hamburger span:nth-child(2) {
  top: 19px;
}

.hamburger span:nth-child(3) {
  bottom: 12px;
}

.hamburger.is-active span:nth-child(1) {
  top: 19px;
  transform: rotate(45deg);
}

.hamburger.is-active span:nth-child(2) {
  opacity: 0;
}

.hamburger.is-active span:nth-child(3) {
  top: 19px;
  bottom: auto;
  transform: rotate(-45deg);
}

@media (min-width: 641px) {
  .hamburger {
    display: none;
  }
}

.mobile-menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.mobile-menu-overlay[hidden] {
  display: none;
}

.mobile-menu-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.mobile-menu-nav {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  text-align: center;
}

.mobile-menu-nav a {
  font-family: var(--font-sans);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--fg);
}

/* ==========================================================================
   Main Content Container
   ========================================================================== */

main {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 2.5rem var(--content-pad) 1rem;
  animation: fadeIn 0.55s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  main,
  .site-header,
  .hamburger span,
  .mobile-menu-overlay {
    animation: none;
    transition: none;
  }
}

/* ==========================================================================
   Home & Index Sections
   ========================================================================== */

.page-title {
  font-family: var(--font-sans);
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: -0.015em;
  line-height: 1.15;
  color: var(--fg);
  margin-bottom: 0.6rem;
}

.page-subtitle {
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--fg4);
  margin-bottom: 2rem;
}

.section-heading {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg4);
  margin-top: 3rem;
  margin-bottom: 0.5rem;
}

.intro {
  margin-top: 1.25rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 768px) {
  .intro {
    grid-template-columns: var(--left-col) 1fr;
    align-items: start;
    gap: var(--col-gap);
  }
}

.intro-avatar {
  width: 108px;
  height: 108px;
  object-fit: cover;
  display: block;
}

@media (min-width: 768px) {
  .intro-avatar {
    width: var(--left-col);
    height: var(--left-col);
  }
}

.intro-body {
  min-width: 0;
}

.intro p {
  margin-bottom: 1.15rem;
}

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

/* Post List (Thinking Machines grid) */

.post-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}

.post-list li {
  position: relative;
  padding-bottom: 0.4rem;
}

.post-list li + li {
  padding-top: 0.4rem;
}

.post-list li + li::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  border-top: 1px solid var(--rule);
  pointer-events: none;
}

.post-item-link {
  display: block;
  color: inherit;
  text-decoration: none;
  line-height: 1.4;
  border-radius: 8px;
  margin: 0 -1rem;
  padding: 1rem;
  transition: background-color 0.2s ease;
}

@media (min-width: 768px) {
  .post-item-link {
    display: grid;
    grid-template-columns: var(--left-col) 1fr;
    align-items: baseline;
    gap: var(--col-gap);
    margin: 0 -1.5rem;
    padding: 1.15rem 1.5rem;
  }
}

.post-item-link time {
  display: block;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--fg4);
  white-space: nowrap;
  margin-bottom: 0.25rem;
  transition: color 0.2s ease;
}

@media (min-width: 768px) {
  .post-item-link time {
    grid-area: 1 / 1;
    margin-bottom: 0;
  }
}

.post-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
}

@media (min-width: 768px) {
  .post-info {
    grid-area: 1 / 2;
  }
}

.post-item-title {
  display: inline-block;
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 500;
  color: var(--fg);
  text-wrap: balance;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 2px;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

.post-item-subtitle {
  font-size: 0.95em;
  line-height: 1.45;
  color: var(--fg3);
  transition: color 0.2s ease;
}

@media (hover: hover) {
  .post-item-link:hover .post-item-title {
    color: var(--fg);
    text-decoration-color: rgba(80, 73, 69, 0.3);
  }

  .post-item-link:hover .post-item-subtitle {
    color: var(--fg1);
  }

  .post-item-link:hover time {
    color: var(--fg2);
  }
}

/* ==========================================================================
   Article & Prose Typography
   ========================================================================== */

.post-header {
  margin-top: 1.5rem;
  margin-bottom: 2.25rem;
}

.post-header .post-title {
  font-family: var(--font-serif);
  font-size: clamp(1.75rem, 3.2vw, 2.05rem);
  font-weight: 600;
  line-height: 1.3;
  color: var(--fg);
  margin: 0;
  text-wrap: balance;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--fg4);
}

.post-meta .meta-sep {
  opacity: 0.5;
}

.prose {
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.65;
  color: var(--fg);
}

.prose > :last-child {
  margin-bottom: 0;
}

.prose p,
.prose blockquote,
.prose pre,
.prose ul,
.prose ol,
.prose figure,
.prose table {
  margin-top: 0;
  margin-bottom: 1.35rem;
}

.prose a {
  color: var(--fg1);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-underline-offset: 2px;
}

.prose a:hover {
  color: var(--fg);
  text-decoration-color: var(--link-underline-hover);
}

.prose h2 {
  font-family: var(--font-serif);
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--fg);
  margin: 2.25rem 0 0.75rem;
}

.prose h3 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 400;
  font-style: italic;
  line-height: 1.4;
  color: var(--fg);
  margin: 1.75rem 0 0.6rem;
}

.prose h4 {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--fg2);
  margin: 1.5rem 0 0.5rem;
}

.prose ul {
  list-style: square;
  margin-left: 1.5rem;
}

.prose ol {
  list-style: decimal;
  margin-left: 1.75rem;
}

.prose li {
  margin-bottom: 0.35rem;
}

.prose blockquote {
  border-left: 2px solid var(--rule-strong);
  color: var(--fg2);
  margin: 1.6rem 0 1.6rem 0.5rem;
  padding: 0.15rem 0 0.15rem 1.25rem;
}

.prose blockquote p:last-child {
  margin-bottom: 0;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  color: var(--red);
}

.prose pre {
  background-color: var(--bg-code);
  border-radius: 0.45rem;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--fg2);
}

.prose pre code {
  color: inherit;
  font-size: inherit;
}

.prose figure {
  margin: 1.75rem 0;
  text-align: center;
}

.prose figure img {
  display: block;
  margin: 0 auto;
  border-radius: 4px;
}

.prose figcaption {
  margin-top: 0.65rem;
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  color: var(--fg4);
}

.prose .embed-frame {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background-color: var(--bg-subtle);
  margin: 1.5rem 0;
}

/* ==========================================================================
   Embedded Jupyter Notebook Viewer
   ========================================================================== */

.notebook-embed {
  margin: 1.75rem 0;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background-color: var(--bg);
  overflow: hidden;
}

.nb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1rem;
  background-color: var(--bg-subtle);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-sans);
  font-size: 13px;
}

.nb-filename {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--fg2);
}

.nb-download {
  color: var(--fg4);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-underline-offset: 2px;
}

.nb-download:hover {
  color: var(--fg);
}

.nb-cells {
  max-height: 620px;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.nb-cell-md h2,
.nb-cell-md h3,
.nb-cell-md h4 {
  margin: 0.5rem 0 0.25rem;
  font-family: var(--font-serif);
  font-style: normal;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--fg);
}

.nb-cell-code {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nb-prompt {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--fg5);
  user-select: none;
}

.nb-cell-body {
  min-width: 0;
}

.notebook-embed pre.nb-code {
  margin: 0;
  padding: 0.8rem 1rem;
  background-color: var(--bg-code);
  border-radius: 6px;
  font-size: 12.5px;
  line-height: 1.45;
  overflow-x: auto;
}

.nb-outputs {
  margin-top: 0.5rem;
  padding-left: 0.75rem;
  border-left: 2px solid var(--rule);
}

.notebook-embed pre.nb-output-text {
  margin: 0;
  padding: 0.5rem 0.75rem;
  background-color: transparent;
  color: var(--fg2);
  font-size: 12.5px;
  line-height: 1.45;
  overflow-x: auto;
}

.nb-output-html {
  overflow-x: auto;
  padding: 0.35rem 0;
}

.nb-output-html table {
  border-collapse: collapse;
  margin: 0;
}

.nb-output-html td {
  width: 24px;
  height: 24px;
  text-align: center;
  vertical-align: middle;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.45);
  padding: 0;
}

.nb-error {
  padding: 1rem;
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--fg4);
}

/* ==========================================================================
   Playable Open Flood Widget
   ========================================================================== */

.open-flood-widget {
  margin: 1.75rem 0;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background-color: var(--bg);
  overflow: hidden;
}

.of-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  background-color: var(--bg-subtle);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-sans);
}

.of-title-group {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.of-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
}

.of-stats {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg4);
}

.of-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.of-btn {
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: var(--fg2);
  background-color: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.of-btn:hover:not(:disabled) {
  color: var(--fg);
  border-color: var(--rule-strong);
  background-color: var(--bg-subtle);
}

.of-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.of-body {
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.of-board {
  display: grid;
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--rule);
}

.of-cell {
  border: none;
  padding: 0;
  cursor: pointer;
  transition: background-color 0.18s ease;
}

.of-cell:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: -2px;
  z-index: 1;
}

.of-palette {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
}

.of-swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.of-swatch:hover:not(:disabled) {
  transform: scale(1.08);
}

.of-swatch.is-current {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--fg);
  cursor: default;
}

.of-swatch:disabled:not(.is-current) {
  opacity: 0.4;
  cursor: default;
}

.of-status {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--fg4);
  text-align: center;
}

.of-status.is-solved {
  color: var(--fg);
  font-weight: 500;
}

.prose mark {
  background-color: var(--mark-bg);
  color: var(--fg);
  padding: 0 0.15em;
}

.prose .katex {
  font-size: 1.02em;
}

.prose .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.25rem 0;
}

.draft-note {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--fg4);
}

.back-link {
  display: inline-block;
  margin-top: 2.5rem;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--fg4);
  text-decoration: none;
}

.back-link:hover {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--link-underline-hover);
  text-underline-offset: 3px;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  width: 100%;
  margin-top: 6rem;
  padding: 0 0 2.25rem;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--fg4);
}

.footer-inner {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 1.75rem var(--content-pad) 0;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.25rem;
  list-style: none;
}

.footer-links a {
  color: var(--fg2);
  text-decoration: none;
  text-underline-offset: 2px;
}

.footer-links a:hover {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: rgba(40, 40, 40, 0.24);
}

.footer-copy {
  color: var(--fg4);
  font-size: 13px;
}

/* ==========================================================================
   404 Page
   ========================================================================== */

.not-found {
  padding-top: 4rem;
}

.not-found h1 {
  font-family: var(--font-serif);
  font-size: 2.25rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.not-found p {
  color: var(--fg3);
  margin-bottom: 1.5rem;
}
