@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,500;0,700;1,400;1,500&family=JetBrains+Mono:wght@300;400;500;700&display=swap');

/* ============================================================
   BASE RESET
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

/* ============================================================
   DESIGN TOKENS  — SignalBoard colorway
   ============================================================ */
:root {
  --bg:          #f7f5f0;
  --bg-alt:      #fff;
  --fg:          #1a1a1a;
  --muted:       #999;
  --rule:        #d4d0c8;
  --accent:      #2c5f2d;
  --accent-h:    #1a4a1b;
  --red:         #c0392b;
  --green:       #2c5f2d;

  /* Layout */
  --text-width:  748px;
  --note-width:  150px;
  --note-gap:    2rem;
  --page-width:  calc(var(--text-width) + var(--note-gap) + var(--note-width) + 6rem);

  /* Fonts */
  --font-serif: "EB Garamond", Georgia, serif;
  --font-mono:  "JetBrains Mono", monospace;
}

/* ============================================================
   DOCUMENT
   ============================================================ */
html {
  font-size: 19px;
  scroll-behavior: smooth;
  scroll-padding-top: 2rem;
}

body {
  font-family: var(--font-serif);
  font-size: 1rem;
  line-height: 1.75;
  color: var(--fg);
  background: var(--bg);
  margin: 0 auto;
  max-width: var(--page-width);
  padding: 0 3rem 0 calc(140px + 2rem);
  word-spacing: 0.03em;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   LAYOUT SHELLS
   ============================================================ */
header,
footer {
  max-width: var(--text-width);
  margin-left: auto;
  margin-right: auto;
}

main {
  margin-top: 4rem;
  margin-bottom: 4rem;
}

/* ============================================================
   SITE HEADER
   ============================================================ */
header {
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  opacity: 0;
  animation: fadeIn 1s ease forwards 0.2s;
}

header .site-title {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg);
  text-decoration: none;
  transition: opacity 0.2s;
}

header .site-title:hover {
  opacity: 0.55;
}

header nav {
  position: fixed;
  left: 0;
  top: 0;
  width: 140px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 2.5rem 1.25rem;
  background: var(--bg);
  border-right: 1px solid var(--rule);
  z-index: 100;
  gap: 0.25rem;
}

header nav a {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 300;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  margin-left: 0;
  padding: 0.35em 0.5em;
  border-left: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

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

header nav a:visited {
  color: var(--muted);
}

/* ============================================================
   SITE FOOTER
   ============================================================ */
footer {
  margin-bottom: 2.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.55rem;
  font-weight: 300;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  opacity: 0;
  animation: fadeIn 1s ease forwards 0.8s;
}

/* ============================================================
   TYPOGRAPHY — HEADINGS
   ============================================================ */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-mono);
  color: var(--fg);
  line-height: 1.3;
  font-weight: 500;
  margin-top: 2.2em;
  margin-bottom: 0.5em;
  letter-spacing: 0.04em;
}

h1 { font-size: 1.9rem; margin-top: 0; }
h2 { font-size: 1.1rem;  letter-spacing: 0.08em; text-transform: uppercase; font-weight: 500; }
h3 { font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
h4 { font-size: 0.82rem; font-style: normal; font-weight: 400; margin-top: 1.5em; }

/* Heading anchor § link */
.heading-anchor {
  opacity: 0;
  margin-left: 0.4em;
  font-size: 0.8em;
  font-style: normal;
  font-variant: normal;
  text-decoration: none;
  color: var(--muted);
  transition: opacity 0.15s;
  user-select: none;
}

h2:hover .heading-anchor,
h3:hover .heading-anchor,
h4:hover .heading-anchor {
  opacity: 1;
}

/* ============================================================
   LINKS
   ============================================================ */
a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 2px;
  transition: color 0.2s, text-decoration-color 0.2s;
}

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

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

/* ============================================================
   PARAGRAPHS & BODY TEXT
   ============================================================ */
p {
  margin-top: 0;
  margin-bottom: 1.15em;
  text-align: left;
}

/* Drop cap on the first paragraph of a post */
.post-content > p:first-of-type::first-letter {
  float: left;
  font-size: 3.4em;
  line-height: 0.82;
  padding-right: 0.08em;
  padding-top: 0.04em;
  color: var(--fg);
  font-weight: 500;
}

/* ============================================================
   ABSTRACT / EPIGRAPH
   ============================================================ */
.abstract {
  position: relative;
  background: var(--bg-alt);
  border: 1px solid rgba(212, 208, 200, 0.5);
  border-radius: 3px;
  padding: 1em 1.25em 1em 1.5em;
  margin: 0 0 2.5em;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.04),
    0 4px 12px rgba(0, 0, 0, 0.03);
}

.abstract::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  background: var(--fg);
}

.abstract p {
  font-style: italic;
  color: var(--fg);
  margin-bottom: 0;
  font-size: 0.88rem;
  line-height: 1.7;
}

.epigraph {
  margin: 1.5em 0 2em 1.5em;
  color: var(--muted);
  font-style: normal;
}

.epigraph p {
  margin-bottom: 0.2em;
}

.epigraph cite {
  display: block;
  font-style: normal;
  font-size: 0.88em;
  margin-top: 0.4em;
}

.epigraph cite::before {
  content: "— ";
}

/* ============================================================
   BLOCKQUOTES
   ============================================================ */
blockquote {
  position: relative;
  margin: 1.2em 0;
  padding: 0.8em 1.25em 0.8em 1.5em;
  border: 1px solid rgba(212, 208, 200, 0.5);
  border-radius: 3px;
  background: var(--bg-alt);
  color: var(--fg);
  font-style: normal;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.04),
    0 4px 12px rgba(0, 0, 0, 0.03);
}

blockquote::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  background: var(--rule);
}

blockquote p {
  margin-bottom: 0;
}

/* ============================================================
   TABLE OF CONTENTS
   ============================================================ */
.toc {
  background: transparent;
  border: none;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  padding: 0.85em 0;
  margin: 0 0 2.2em;
  font-size: 0.82rem;
  line-height: 1.6;
}

.toc .toc-title {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.5em;
}

.toc ol {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.toc li {
  margin-bottom: 0.15em;
}

.toc a {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  color: var(--muted);
  text-decoration: none;
  padding: 3px 0 3px 10px;
  border-left: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

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

.toc .toc-h3 {
  padding-left: 1.5em;
  font-size: 0.68rem;
}

/* ============================================================
   POST LAYOUT — WIDE GRID WITH SIDENOTES
   ============================================================ */
.post-content {
  font-size: 1rem;
  max-width: var(--text-width);
}

@media (min-width: 960px) {
  .post-content {
    display: grid;
    grid-template-columns: minmax(0, var(--text-width)) var(--note-width);
    column-gap: var(--note-gap);
    max-width: calc(var(--text-width) + var(--note-gap) + var(--note-width));
  }

  .post-content > * {
    grid-column: 1;
    min-width: 0;
  }

  .sidenote {
    grid-column: 2;
    align-self: start;
  }
}

/* ============================================================
   SIDENOTES
   ============================================================ */
.sidenote {
  font-size: 0.75rem;
  line-height: 1.55;
  color: var(--muted);
  border-left: 1px solid var(--rule);
  padding-left: 0.8rem;
  margin-top: 0.15rem;
}

.sidenote p {
  text-align: left;
  margin-bottom: 0;
  hyphens: none;
}

.sidenote-number {
  color: var(--fg);
  font-size: 0.75em;
  vertical-align: super;
  line-height: 0;
  margin-right: 0.3em;
  font-family: var(--font-mono);
  font-weight: 500;
}

/* On narrow screens, hide sidenotes (footnotes shown at bottom instead) */
@media (max-width: 959px) {
  .sidenote {
    display: none;
  }
}

/* ============================================================
   CODE
   ============================================================ */
code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  font-weight: 400;
  background: rgba(26, 26, 26, 0.04);
  padding: 0.15em 0.35em;
  border-radius: 3px;
  color: var(--fg);
  border: 1px solid rgba(212, 208, 200, 0.4);
}

pre {
  position: relative;
  background: var(--bg-alt);
  border: 1px solid rgba(212, 208, 200, 0.5);
  border-radius: 3px;
  padding: 1.1em 1.3em;
  overflow-x: auto;
  line-height: 1.55;
  margin: 1.2em 0;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.04),
    0 4px 12px rgba(0, 0, 0, 0.03);
}

pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  border: none;
  color: var(--fg);
  font-size: 0.82em;
  font-weight: 300;
}

/* ============================================================
   HORIZONTAL RULE
   ============================================================ */
hr {
  border: none;
  height: 1px;
  background: var(--rule);
  margin: 2.5em 0;
}

/* ============================================================
   LISTS
   ============================================================ */
ul, ol {
  padding-left: 1.5em;
  margin-top: 0;
  margin-bottom: 0.8em;
}

li { margin-bottom: 0.25em; }

li > ul,
li > ol {
  margin-top: 0.25em;
  margin-bottom: 0;
}

/* ============================================================
   TABLES
   ============================================================ */
table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  margin: 1.4em 0;
}

th {
  text-align: left;
  border-bottom: 1px solid var(--fg);
  padding: 5px 8px;
  color: var(--fg);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 0.6rem;
  letter-spacing: 0.05em;
}

td {
  padding: 4px 8px;
  border-bottom: 1px solid rgba(212, 208, 200, 0.3);
  color: var(--fg);
  font-weight: 300;
}

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

tr:hover td {
  background: rgba(212, 208, 200, 0.08);
}

/* ============================================================
   IMAGES & FIGURES
   ============================================================ */
img {
  max-width: 100%;
  height: auto;
  border-radius: 3px;
  display: block;
  margin: 1.4em auto;
}

figure {
  margin: 2em 0;
  text-align: center;
}

figcaption {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 0.5em;
  font-style: normal;
  letter-spacing: 0.04em;
}

/* ============================================================
   FOOTNOTES  (shown on narrow screens; replaced by sidenotes on wide)
   ============================================================ */

/* Hide the auto-generated <hr> above the footnotes section */
hr.footnotes-sep {
  display: none;
}

.footnotes {
  margin-top: 2.5em;
  padding-top: 1em;
  border-top: 1px solid var(--rule);
  font-size: 0.82em;
  color: var(--muted);
}

.footnotes ol { padding-left: 1.25em; margin: 0; }
.footnotes li { margin-bottom: 0.5em; }
.footnotes p  { text-align: left; margin: 0; }

sup a,
.footnote-ref a {
  text-decoration: none;
  font-size: 0.75em;
  vertical-align: super;
  color: var(--fg);
  font-family: var(--font-mono);
  font-weight: 500;
}

/* ============================================================
   POST HEADER
   ============================================================ */
.post-header {
  margin-bottom: 2.5em;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1em;
  max-width: var(--text-width);
  opacity: 0;
  animation: fadeIn 1s ease forwards 0.2s;
}

.post-header h1 {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: 0.02em;
  margin-bottom: 0.3em;
}

.post-subtitle {
  font-size: 0.88rem;
  color: var(--muted);
  font-style: normal;
  margin: 0 0 0.75em;
  line-height: 1.6;
}

.post-tags {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: none;
  margin: 0 0 0.5em;
}

.post-meta {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 300;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ============================================================
   HOME PAGE — POST LIST
   ============================================================ */
.home-main {
  max-width: var(--text-width);
  margin-left: auto;
  margin-right: auto;
}

.home-main h1 {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: 0.04em;
}

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

.post-list li {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  padding: 1.2rem 0.5rem;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
  transition: opacity 0.3s ease;
}

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

.post-list li:hover {
  opacity: 0.55;
}

.post-list time {
  flex-shrink: 0;
  padding-top: 0.15em;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 300;
  letter-spacing: 0.02em;
  min-width: 5.5em;
}

.post-list-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.post-list-subtitle {
  font-size: 0.78rem;
  color: var(--muted);
  font-style: normal;
  margin: 0;
  line-height: 1.6;
}

.post-list a {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--fg);
  text-decoration: none;
}

.post-list a:hover {
  color: var(--fg);
  text-decoration: none;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 700px) {
  html { font-size: 17px; }
  body { padding: 0 1.25rem; }

  header nav {
    position: static;
    width: auto;
    height: auto;
    flex-direction: row;
    padding: 0;
    border-right: none;
    background: none;
    gap: 0;
  }

  header nav a {
    margin-left: 1.25rem;
    border-left: none;
    padding: 0.35em 0;
  }

  h1 { font-size: 1.1rem; }

  .post-header h1 { font-size: 1.1rem; }

  .post-list li {
    flex-direction: column;
    gap: 0.1rem;
    padding: 1rem 0.25rem;
  }

  .post-list time {
    min-width: auto;
  }

  .post-list a {
    font-size: 0.82rem;
  }
}

/* ============================================================
   HASHTAG PANEL — fixed, right side, mirrors left nav
   ============================================================ */

/* Hidden by default; shown only on wide viewports below */
.hashtag-panel {
  display: none;
}

@keyframes hashtag-slide-in {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

@media (min-width: 1100px) {
  .hashtag-panel {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    position: fixed;
    right: 1rem;
    top: 2.5rem;
    width: 140px;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    z-index: 90;
  }

  .hashtag-item {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 300;
    letter-spacing: 0.03em;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--rule);
    border-radius: 3px;
    padding: 0.3em 0.6em;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.15s;
    text-align: left;
    animation: hashtag-slide-in 0.35s ease both;
  }

  .hashtag-item:hover {
    color: var(--fg);
    border-color: var(--fg);
    background: rgba(26, 26, 26, 0.04);
    transform: translateX(-3px);
  }

  .hashtag-item:active {
    transform: scale(0.96);
  }

  .hashtag-item.hashtag-copied {
    color: var(--green);
    border-color: var(--green);
  }
}

/* ============================================================
   FOCUS-VISIBLE
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ============================================================
   READING PROGRESS BAR
   ============================================================ */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: var(--fg);
  z-index: 300;
  transition: width 0.1s linear;
  pointer-events: none;
}

/* ============================================================
   COPY CODE BUTTON
   ============================================================ */
.copy-btn {
  position: absolute;
  top: 0.5em;
  right: 0.5em;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.2em 0.5em;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 300;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.2s, border-color 0.2s;
}

pre:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  color: var(--fg);
  border-color: var(--fg);
}

.copy-btn.copied {
  color: var(--green);
  border-color: var(--green);
}

/* ============================================================
   READ TIME
   ============================================================ */
.read-time {
  margin-left: 0.3em;
}

/* ============================================================
   TOC ACTIVE LINK
   ============================================================ */
.toc a.toc-active {
  color: var(--fg);
  border-left-color: var(--fg);
  background: rgba(26, 26, 26, 0.04);
}

/* ============================================================
   SCROLL FADE-IN ANIMATIONS
   ============================================================ */
.fade-target {
  opacity: 0;
  transition: opacity 0.5s ease;
}

.fade-target.fade-in {
  opacity: 1;
}
