/* ─────────────────────────────────────────
   The 3TC — blog stylesheet
   Same structure as the parent site (The Constant Factor):
   fixed top bar, narrow centred column, dark mode.
   Kept from the3tc.ai: Roboto and the grey page background.
───────────────────────────────────────── */

/* ─────────────────────────────────────────
   Tokens — Light Mode
───────────────────────────────────────── */
:root {
  --bg:   #fafafa;
  --bg_s: #f3f3f3;
  --bg_code: #ececec;
  --fg:   #282828;
  --fg1:  #3c3836;
  --fg2:  #504945;
  --fg3:  #6b6866;
  --fg4:  #676767;
  --fg5:  #969696;
  --hover-bg: rgba(128,128,128,0.10);
  --accent: #2563eb;

  --font-sans: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;

  --site-header-height: 54px;
  --max-width: 680px;
}

/* ─────────────────────────────────────────
   Dark Mode
───────────────────────────────────────── */
body.darkmode {
  --bg:   #0d0d0d;
  --bg_s: #1a1a1a;
  --bg_code: #1a1a1a;
  --fg:   #f0f0f0;
  --fg1:  #e0e0e0;
  --fg2:  #c8c8c8;
  --fg3:  #aaaaaa;
  --fg4:  #888888;
  --fg5:  #666666;
  --accent: #60a5fa;
  --hover-bg: rgba(128,128,128,0.20);
}

/* ─────────────────────────────────────────
   Reset
───────────────────────────────────────── */
*, *::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-scrollbar { width: 8px; height: 8px; background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--fg4); }
::-webkit-scrollbar-thumb:hover { background: var(--fg1); }

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.625;
  background: var(--bg);
  /* Subtle engineering grid background */
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--fg) 2%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--fg) 2%, transparent) 1px, transparent 1px);
  background-size: 20px 20px;
  color: var(--fg);
  min-height: 100vh;
  overflow-x: clip;
  transition: background 0.2s ease, color 0.2s ease;
}

::selection { background: rgba(0,0,0,0.12); }
body.darkmode ::selection { background: rgba(240,240,240,0.18); color: var(--fg); }

a {
  text-decoration: none;
  transition: color 0.2s ease, opacity 0.2s ease;
  color: var(--accent);
}
a:link, a:visited { color: var(--accent); }
a:hover { opacity: 0.8; }

time { color: var(--fg4); }

hr { border: none; border-top: 1px solid var(--fg4); margin: 1rem 0; }

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

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

/* ─────────────────────────────────────────
   Layout Wrapper
───────────────────────────────────────── */
#wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  font-family: var(--font-sans);
  overflow-wrap: break-word;
  padding: var(--site-header-height) 1rem 0;
}

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

/* ─────────────────────────────────────────
   Header
───────────────────────────────────────── */
#header {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg);
}

#header .site-header {
  position: fixed;
  top: 0;
  left: 1rem;
  right: 1rem;
  z-index: 1002;
  height: var(--site-header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  padding: 0 0.33rem;
  box-sizing: border-box;
  transition: background 0.2s ease;
}

@media (max-width: 768px) {
  #header .site-header { left: 0; right: 0; padding: 0 1rem; }
}

/* Wordmark */
.navbar-logo { flex-shrink: 0; }

#header .navbar-logo a {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg4) !important;
  text-decoration: none !important;
  transition: opacity 0.2s ease;
}
#header .navbar-logo a:hover { opacity: 0.75; }

/* Sticky post header on single pages */
#header .sticky-post-header {
  width: 100%;
  background-color: var(--bg);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid color-mix(in srgb, var(--fg4) 15%, transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-in-out;
}

#header .sticky-post-header.is-visible {
  opacity: 1;
  pointer-events: auto;
}

#header .sticky-post-header .post-title-sticky {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 19px;
  color: var(--fg);
  margin: 0;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Desktop nav */
.nav-group { display: flex; align-items: center; gap: 0; }

.top-nav {
  display: flex;
  gap: 1.75rem;
  align-items: center;
  font-family: var(--font-sans);
}
.top-nav a {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--fg1) !important;
  text-decoration: none;
  transition: opacity 0.2s ease;
}
.top-nav a:hover {
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--fg) 20%, transparent);
  text-underline-offset: 2px;
}

/* Dark-mode toggle */
.dark-mode-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-left: 1.25rem;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  color: var(--fg);
  flex-shrink: 0;
  transition: background 0.2s ease;
}
.dark-mode-toggle:hover { background: var(--hover-bg); }
.dark-mode-toggle svg { width: 18px; height: 18px; fill: currentColor; }
body:not(.darkmode) .icon-sun { display: none; }
body.darkmode .icon-moon { display: none; }

/* Hamburger */
.hamburger {
  display: none;
  position: relative;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 8px;
  margin-left: 0.5rem;
  -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) { bottom: auto; top: 19px; transform: rotate(-45deg); }

/* Mobile overlay */
.mobile-menu-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}
.mobile-menu-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.mobile-menu-nav {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  text-align: center;
}
.mobile-menu-nav a {
  font-family: var(--font-sans);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--fg) !important;
  text-decoration: none;
}
body.menu-open { overflow: hidden; }

/* ─────────────────────────────────────────
   Main Content
───────────────────────────────────────── */
#main {
  align-self: center;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  width: 100%;
  max-width: var(--max-width);
  margin: auto;
  padding: 1rem;
  animation: fadeIn 0.5s ease-in-out;
}

.content { padding-top: 0.5rem; }

#main.content > article.content {
  max-width: 660px;
  margin-left: auto;
  margin-right: auto;
}

.content :last-child { margin-bottom: 0px; }

/* List page is slightly wider to account for padding */
#main.index.list { max-width: calc(var(--max-width) + 3.2rem); }
#main.index.list .blog-page-title,
#main.index.list .content,
#main.index.list .page-content,
#main.index.list .post-group { max-width: var(--max-width); }
#main.index.list .page-content { margin: 0 auto; width: 100%; }

#main.index.content p { margin-bottom: 1.8rem; }

@media (max-width: 768px) {
  #main { width: 100%; }
}
@media (max-width: 1170px) {
  #main.index { padding-left: 1.3rem; padding-right: 1.3rem; }
}

/* ─────────────────────────────────────────
   Blog List — Post Items
───────────────────────────────────────── */
.blog-page-title {
  font-family: var(--font-sans);
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: -0.015em;
  color: var(--fg);
  margin: 0;
  padding-top: 1rem;
  line-height: 1.15;
}

#main.index .post-group ul {
  list-style: none;
  padding-top: 1.6rem;
}

#main.index .post-group ul li {
  margin-bottom: 0;
  position: relative;
  padding-bottom: 0.4rem;
}

#main.index .post-group ul li + li { padding-top: 0.4rem; }

#main.index .post-group ul li + li::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  border-top: 1px solid color-mix(in srgb, var(--fg4) 15%, transparent);
  pointer-events: none;
}

/* Full-row clickable link */
#main.index .post-group .post-item-link {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 1.5rem;
  align-items: baseline;
  line-height: 1.4;
  padding: 1.2rem 1.5rem;
  margin: 0 -1.5rem;
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s ease;
}
#main.index .post-group .post-item-link:hover { background: var(--hover-bg); }

.desktop-time {
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--fg4);
  white-space: nowrap;
  text-align: left;
  transition: opacity 0.2s ease;
}
.mobile-time { display: none; }

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

.post-info .post-title {
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 500;
  color: var(--fg);
  transition: opacity 0.2s ease;
}

.post-info .post-subtitle {
  font-size: 0.95em;
  color: var(--fg2);
  line-height: 1.4;
}

.post-info .author {
  display: block;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--fg4);
  padding-top: 6px;
}

/* Hover effects on list items */
#main.index .post-group .post-item-link:hover .post-title {
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--fg2) 25%, transparent);
  text-underline-offset: 2px;
}
#main.index .post-group .post-item-link:hover .post-subtitle { color: var(--fg1); }
#main.index .post-group .post-item-link:hover .author,
#main.index .post-group .post-item-link:hover .desktop-time,
#main.index .post-group .post-item-link:hover .mobile-time { color: var(--fg3); }

@media (max-width: 767px) {
  #main.index .post-group .post-item-link {
    display: block;
    padding: 1rem 1.6rem;
    margin: 0 -1.6rem;
  }
  .desktop-time { display: none; }
  .mobile-time {
    display: block;
    font-family: var(--font-sans);
    font-size: 15px;
    color: var(--fg4);
    margin-bottom: 0.3rem;
  }
}

/* ─────────────────────────────────────────
   Single Post
───────────────────────────────────────── */
.post-single { padding-bottom: 4rem; }

.post-header {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid color-mix(in srgb, var(--fg4) 20%, transparent);
}

.post-header .post-title {
  font-family: var(--font-sans);
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--fg);
  margin-bottom: 0.75rem;
}

.post-byline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--fg4);
}
.post-sep { color: color-mix(in srgb, var(--fg4) 40%, transparent); }

.post-body { font-size: 16px; line-height: 1.7; color: var(--fg); }
.post-body p, .post-body blockquote, .post-body pre, .post-body ul, .post-body ol, .post-body dl, .post-body table {
  margin-top: 0;
  margin-bottom: 1.333rem;
}
.post-body h2, .post-body h3, .post-body h4 {
  font-family: var(--font-sans);
  font-weight: 700;
  line-height: 1.25;
  margin-top: 2rem;
  margin-bottom: 1.333rem;
  color: var(--fg);
}
.post-body h2 { font-size: 1.35rem; }
.post-body h3 { font-size: 1.15rem; }
.post-body h4 { font-size: 0.95rem; }
.post-body ul, .post-body ol { padding-left: 1.5em; margin-bottom: 1.4em; }
.post-body li { margin-bottom: 0.3em; }
.post-body blockquote {
  border-left: 2px solid var(--fg4);
  padding-left: 1.25rem;
  margin: 1.5em 0;
  color: var(--fg3);
  font-style: italic;
}
.post-body a {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: color-mix(in srgb, var(--fg) 30%, transparent);
}
.post-body a:hover { color: var(--fg2); }
.post-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg_code);
  color: var(--fg2);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}
.post-body pre {
  background: var(--bg_code);
  padding: 1.25rem;
  overflow-x: auto;
  border-radius: 6px;
  margin: 1.5em 0;
}
.post-body pre code { background: none; padding: 0; font-size: 14px; }
.post-body hr { margin: 2rem 0; }

.post-body figure { margin: 2rem 0; }
.post-body figcaption { font-size: 0.85rem; color: var(--fg3); margin-top: 0.6rem; }

.post-body table {
  display: block;
  width: max-content;
  max-width: 100%;
  overflow: auto;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.post-body th, .post-body td {
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid color-mix(in srgb, var(--fg4) 20%, transparent);
  text-align: left;
}
.post-body th { font-weight: 500; }

.post-body .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

/* Tags */
.post-footer {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid color-mix(in srgb, var(--fg4) 20%, transparent);
}
.post-tags { display: flex; flex-wrap: wrap; gap: 0.75rem; }
a.tag {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--fg4);
  text-decoration: none;
}
a.tag:hover { color: var(--fg); }

/* ─────────────────────────────────────────
   Footer
───────────────────────────────────────── */
#footer {
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--fg4);
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 5rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
}

#footer > div {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
}

#footer > div > span > a {
  color: var(--fg4);
  text-decoration: none;
  position: relative;
  transition: color 0.2s ease;
}
#footer > div > span > a::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 0.5px;
  background: var(--fg4);
  bottom: 0; left: 0;
  transform: scaleX(0);
  transform-origin: bottom right;
  transition: transform 0.2s ease-out;
}
#footer > div > span > a:hover { color: var(--fg3); }
#footer > div > span > a:hover::after {
  transform: scaleX(1);
  transform-origin: bottom left;
}

/* Mobile footer */
@media (max-width: 640px) {
  #footer { align-items: flex-start; padding: 0 1rem 2rem; }
  #footer > div {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  .footer-separator { display: none; }
}

/* ─────────────────────────────────────────
   Mobile breakpoints
───────────────────────────────────────── */
@media (max-width: 640px) {
  :root { --site-header-height: 50px; }
  .top-nav { display: none; }
  .hamburger { display: inline-flex; }
}

/* ─────────────────────────────────────────
   Homepage wordmark
───────────────────────────────────────── */
.logo-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1rem 1rem 1.35rem;
  text-align: center;
  animation: fadeIn 0.6s ease-in-out;
}

.logo {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: clamp(3em, 8vw, 3.4em);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.3;
  text-wrap: stable;
  color: var(--fg) !important;
  text-decoration: none !important;
}

.main-logo-title {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 1.05rem;
  letter-spacing: normal;
  text-transform: none;
  margin-top: 0.5rem;
  color: var(--fg4);
  text-wrap: balance;
}

/* ─────────────────────────────────────────
   Lightbox (figure images open full screen)
───────────────────────────────────────── */
.post-body figure img.is-zoomable { cursor: zoom-in; transition: box-shadow 0.15s ease; }
.post-body figure img.is-zoomable:hover,
.post-body figure img.is-zoomable:focus-visible { box-shadow: 0 0 0 2px var(--fg); outline: none; }

.lightbox {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.75rem; padding: 3rem 1rem 1.5rem;
  background: color-mix(in srgb, var(--bg) 97%, transparent);
  cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 100%; max-height: calc(100vh - 8rem);
  width: auto; height: auto; object-fit: contain;
  cursor: default; background: #fff;
  box-shadow: 0 2px 24px rgba(0, 0, 0, 0.12);
}
.lightbox__caption {
  max-width: 60rem; font-size: 0.85rem; color: var(--fg3); text-align: center; cursor: default;
}
.lightbox__close {
  position: absolute; top: 0.75rem; right: 1rem;
  width: 2.5rem; height: 2.5rem; border-radius: 50%;
  border: 1px solid var(--fg); background: transparent; color: var(--fg);
  font-size: 1.5rem; line-height: 1; cursor: pointer;
}
.lightbox__close:hover { background: var(--fg); color: var(--bg); }
body.lightbox-open { overflow: hidden; }
