/* ── Design Tokens ──────────────────────────────────── */
:root {
  --color-text: #1a1a2e;
  --color-bg: #ffffff;
  --color-code-bg: #fafbfb;
  --color-code-border: #e5e7eb;
  --color-footer: #9ca3af;
  --color-link: inherit;

  --font-serif: "PT Serif", Georgia, "Times New Roman", Times, serif;
  --font-body: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;

  --sidebar-width: 200px;
  --page-top-margin-mobile: 2rem;
  --page-top-margin-tablet: 5rem;
  --page-top-margin-desktop: 8rem;
  --content-bottom: 10rem;
  --sidebar-bottom: 5rem;

  --code-border-radius: 6px;
  --code-padding: 12px 16px;
}

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

body {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

a:hover {
  text-decoration: underline;
}

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

/* ── Layout ─────────────────────────────────────────── */
.container {
  max-width: 72rem;  /* ~1152px — matches max-w-5xl + some room */
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Desktop: sidebar + content side by side */
@media (min-width: 768px) {
  .container {
    flex-direction: row;
    padding: 0 2rem;
    margin-top: var(--page-top-margin-tablet);
  }
}

@media (min-width: 1024px) {
  .container {
    margin-top: var(--page-top-margin-desktop);
  }
}

/* ── Sidebar ────────────────────────────────────────── */
.sidebar {
  font-family: var(--font-body);
  padding-top: var(--page-top-margin-mobile);
  padding-bottom: 0;
}

@media (min-width: 768px) {
  .sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    padding-top: 0;
    padding-bottom: var(--sidebar-bottom);
  }
}

@media (min-width: 1024px) {
  .sidebar {
    position: sticky;
    top: 5rem;
    align-self: flex-start;
  }
}

.site-name {
  font-family: var(--font-body);
  font-size: 17px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

.site-name a {
  color: var(--color-text);
}

.site-name a:hover {
  text-decoration: underline;
}

/* Mobile: sidebar becomes horizontal nav */
@media (max-width: 767px) {
  .sidebar {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 1.5rem;
    padding-top: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 1.5rem;
  }

  .site-name {
    margin-bottom: 0;
    flex-shrink: 0;
  }
}

.nav {
  font-family: var(--font-body);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

@media (max-width: 767px) {
  .nav {
    flex-direction: row;
    gap: 1rem;
    overflow-x: auto;
  }
}

.nav a {
  font-size: 15px;
  color: var(--color-footer);
  transition: color 0.15s;
}

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

.nav a.active {
  color: var(--color-text);
}

/* ── Main Content ───────────────────────────────────── */
.content {
  flex: 1;
  min-width: 0;
  padding-bottom: var(--content-bottom);
}

@media (min-width: 768px) {
  .content {
    padding-left: 4rem;
  }
}

/* ── Typography ─────────────────────────────────────── */
.content h1 {
  font-family: var(--font-body);
  font-size: 32px;
  font-weight: 700;
  line-height: 1.3;
  margin: 2rem 0 1rem;
}

.content h2 {
  font-family: var(--font-body);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.3;
  margin: 2rem 0 0.75rem;
}

.content h3 {
  font-family: var(--font-body);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  margin: 1.5rem 0 0.5rem;
}

.content p {
  margin-bottom: 1.25rem;
}

.content ul,
.content ol {
  margin: 1rem 0;
  padding-left: 1.5rem;
}

.content li {
  margin-bottom: 0.25rem;
}

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

.content a:hover {
  text-decoration: none;
}

.content blockquote {
  border-left: 3px solid #d1d5db;
  padding-left: 1rem;
  margin: 1.5rem 0;
  color: #6b7280;
}

.content hr {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 2rem 0;
}

/* ── Code Blocks ────────────────────────────────────── */
.content pre {
  background: var(--color-code-bg);
  border: 1px solid var(--color-code-border);
  border-radius: var(--code-border-radius);
  padding: var(--code-padding);
  overflow-x: auto;
  margin: 1rem 0;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
}

.content code {
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

.content :not(pre) > code {
  font-size: 0.8125rem;
  background: #f3f4f6;
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
}

/* ── Blog Index ─────────────────────────────────────── */
.post-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
}

.post-list > a {
  display: block;
  color: var(--color-text);
  text-decoration: none;
  border-bottom: 1px solid #f3f4f6;
  transition: color 0.15s;
}

.post-list > a:last-child {
  border-bottom: none;
}

.post-list > a:hover {
  color: rgba(26, 26, 46, 0.7);
  text-decoration: none;
}

.post-entry {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0.75rem 0 1rem;
}

@media (min-width: 768px) {
  .post-entry {
    flex-direction: row;
    align-items: flex-start;
    padding: 0.75rem 0 0.5rem;
  }
}

.post-title-wrap {
  flex: 1 1 auto;
}

@media (min-width: 768px) {
  .post-title-wrap {
    width: 75%;
  }
}

.post-title {
  font-family: var(--font-body);
  font-size: 17px;
  font-weight: 500;
  line-height: 1.5;
}

.post-date {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 400;
  line-height: 20px;
  color: #99a1af;
}

@media (min-width: 768px) {
  .post-date {
    width: 25%;
    padding-left: 1rem;
    flex-shrink: 0;
    text-align: left;
  }
}

/* ── Annotations (Wikipedia-style tooltips) ──────── */
/* The annotation term is a <span> with a [+] superscript indicator.
   The popup is a separate <section> appended after the document content
   so it can contain block-level elements (lists, code blocks, etc.).
   All Markdown inside annotations is parsed at build time by the
   markdown-it annotation-tip plugin. */

.annotation-term {
  cursor: pointer;
  white-space: nowrap;
}

.annotation-term sup {
  vertical-align: super;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  color: #2563eb;  /* blue-600 */
  font-family: var(--font-body);
  line-height: 1;
  transition: color 0.15s;
}

.annotation-term:hover sup,
.annotation-term sup:hover {
  color: #1d4ed8;
}

/* Highlight the annotated term when its popup is open */
.annotation-term.active {
  background-color: #e2e8f5;  /* light navy blue */
  border-radius: 3px;
  padding: 0 2px;
  margin: 0 -2px;
  transition: background-color 0.15s ease;
}

.annotated-popup {
  display: none;
  position: fixed;
  z-index: 50;
  max-width: 22rem;
  width: max-content;
  padding: 0.75rem 1rem;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.5;
  color: #1f2937;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  white-space: normal;
  word-wrap: break-word;
  pointer-events: auto;
}

/* Popup visible (toggled by JS removing [hidden]) */
.annotated-popup:not([hidden]) {
  display: block;
}

/* Arrow pointing down to the reference (default: bottom, rotated 45deg) */
.annotated-popup::before {
  content: "";
  position: absolute;
  bottom: var(--arrow-bottom, -6px);
  top: var(--arrow-top, auto);
  left: var(--arrow-left, 12px);
  width: 10px;
  height: 10px;
  background: #ffffff;
  border-right: 1px solid #d1d5db;
  border-bottom: 1px solid #d1d5db;
  transform: rotate(var(--arrow-rotate, 45deg));
  transition: none;
}

/* Allow links inside popups */
.annotated-popup a {
  color: #2563eb;
  text-decoration: underline;
}

.annotated-popup a:hover {
  text-decoration: none;
}

/* Small inline code inside popup */
.annotated-popup code {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  background: #f3f4f6;
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
}

/* Lists inside popups */
.annotated-popup ul,
.annotated-popup ol {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.annotated-popup li {
  margin-bottom: 0.125rem;
}

/* Blockquotes inside popups */
.annotated-popup blockquote {
  border-left: 2px solid #d1d5db;
  padding-left: 0.75rem;
  margin: 0.5rem 0;
  color: #6b7280;
}

/* Code blocks inside popups */
.annotated-popup pre {
  margin: 0.5rem 0;
  padding: 8px 12px;
  background: #f3f4f6;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 0.8125rem;
}

.annotated-popup p {
  margin-bottom: 0.5rem;
}

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

/* ── Footer ─────────────────────────────────────────── */
.content-footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e5e7eb;
  font-size: 14px;
  color: var(--color-footer);
}

.content-footer a {
  color: var(--color-footer);
}

.content-footer a:hover {
  color: var(--color-text);
}