/* ==========================================================================
   Custom styles for celso.is — Inspired by AkitaOnRails
   ========================================================================== */

/* ---------- Article shell ---------- */
.post-shell {
  width: 100%;
  max-width: calc(68ch + 16rem + 2.5rem);
  margin-inline: auto;
  padding: 2.5rem 1rem;
  display: grid;
  grid-template-columns: minmax(0, 68ch);
  justify-content: center;
}

.post-main {
  min-width: 0;
}

.post-article,
.post-footer {
  width: 100%;
  max-width: 68ch;
  margin-inline: auto;
}

/* ---------- Base typography ---------- */
.post-content {
  font-family: "Source Serif 4", Charter, "Bitstream Charter", Georgia, Cambria, "Times New Roman", serif;
  font-size: 19px;
  line-height: 1.7;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
  hyphens: auto;
  color: #2a2622;
}

/* ---------- Headings ---------- */
.post-content :where(h1, h2, h3, h4, h5, h6) {
  font-family: "Source Sans 3", "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  font-weight: 700;
  letter-spacing: -0.012em;
  line-height: 1.15;
  color: #111827;
  scroll-margin-top: 5rem;
}

.post-content h1 {
  font-size: 2.25rem;
  margin-bottom: 1rem;
  margin-top: 0;
}

.post-content h2 {
  font-size: 1.75rem;
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid #e5e7eb;
}

.post-content h3 {
  font-size: 1.375rem;
  margin-top: 2rem;
  margin-bottom: 0.5rem;
}

.post-content h4 {
  font-size: 1.125rem;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

/* ---------- Paragraphs & lists ---------- */
.post-content :where(p, li) {
  text-wrap: pretty;
}

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

.post-content ul,
.post-content ol {
  margin-bottom: 1.25rem;
  padding-left: 1.5rem;
}

.post-content ul {
  list-style-type: disc;
}

.post-content ol {
  list-style-type: decimal;
}

.post-content li {
  margin-bottom: 0.4rem;
}

.post-content li > ul,
.post-content li > ol {
  margin-top: 0.4rem;
  margin-bottom: 0;
}

/* ---------- Links ---------- */
.post-content :where(a) {
  color: #2563eb;
  text-decoration: underline;
  text-decoration-thickness: from-font;
  text-underline-offset: 0.12em;
  text-decoration-skip-ink: auto;
  transition: color 0.15s ease;
}

.post-content a:hover {
  color: #1d4ed8;
}

/* ---------- Blockquotes ---------- */
.post-content blockquote {
  border-left: 3px solid #d1d5db;
  padding-left: 1.25rem;
  margin: 1.75rem 0;
  font-style: italic;
  color: #4b5563;
}

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

/* ---------- Inline code ---------- */
.post-content :where(code):not(pre code) {
  font-size: 0.85em;
  padding: 0.15em 0.35em;
  background-color: #f1ece0;
  border-radius: 0.25rem;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  hyphens: none;
}

/* ---------- Code blocks ---------- */
.post-content pre {
  font-size: 0.9em;
  line-height: 1.65;
  background: #f1ece0;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 0.5rem;
  padding: 1rem 1.25rem;
  margin: 1.75rem 0;
  overflow-x: auto;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}

/* Commonmarker syntax-highlighted blocks override */
.post-content pre[style*="background-color"] {
  border-color: rgba(0, 0, 0, 0.06);
}

.post-content pre code {
  background-color: transparent;
  padding: 0;
  color: inherit;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-ligatures: none;
  font-size: inherit;
}

/* Custom scrollbar for code blocks */
.post-content pre::-webkit-scrollbar {
  height: 10px;
}

.post-content pre::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.18);
  border-radius: 999px;
}

.post-content pre::-webkit-scrollbar-track {
  background: transparent;
}

/* ---------- Images ---------- */
.post-content img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  margin: 1.5rem 0;
}

.post-content figure {
  margin: 1.75rem 0;
}

.post-content figcaption {
  font-size: 0.875rem;
  color: #6b7280;
  text-align: center;
  margin-top: 0.5rem;
}

/* ---------- Horizontal rule ---------- */
.post-content hr {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 2.5rem 0;
}

/* ---------- Tables ---------- */
.post-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.75rem 0;
  font-size: 0.925em;
}

.post-content th,
.post-content td {
  border: 1px solid #d1d5db;
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.post-content th {
  background-color: #f3f4f6;
  font-family: "Source Sans 3", "Helvetica Neue", sans-serif;
  font-weight: 600;
}

/* ==========================================================================
   Table of Contents sidebar
   ========================================================================== */

.toc-sidebar {
  display: none;
  font-family: "Source Sans 3", "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  font-size: 0.8125rem;
  line-height: 1.4;
  width: 14rem;
  max-height: calc(100vh - 6rem);
  padding-right: 0.5rem;
  overflow-y: auto;
  position: sticky;
  top: 5rem;
}

.toc-sidebar .toc-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7280;
  margin-bottom: 0.75rem;
  padding-left: 0.5rem;
}

.toc-sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  position: relative;
}

/* Vertical line on the left */
.toc-sidebar > ul {
  padding-left: 0;
}

.toc-sidebar > ul::before {
  content: "";
  position: absolute;
  top: 0.25rem;
  bottom: 0.25rem;
  left: 0;
  width: 1px;
  background-color: #e5e7eb;
}

.toc-sidebar .toc-link {
  display: flex;
  align-items: baseline;
  gap: 0.375rem;
  padding: 0.375rem 0.5rem;
  border-radius: 0.25rem;
  color: #6b7280;
  text-decoration: none;
  transition: all 0.15s ease;
  word-break: break-word;
  position: relative;
}

.toc-sidebar .toc-link::before {
  content: "#";
  opacity: 0.3;
  flex-shrink: 0;
  font-weight: 600;
}

.toc-sidebar .toc-link:hover {
  background-color: #f3f4f6;
  color: #111827;
}

/* Active TOC link */
.toc-sidebar .toc-link.active {
  background-color: #eff6ff;
  color: #1d4ed8;
  font-weight: 600;
}

.toc-sidebar .toc-link.active::before {
  opacity: 0.6;
  color: #1d4ed8;
}

/* TOC nesting indentation */
.toc-sidebar .toc-level-2 {
  padding-left: 0.75rem;
}

.toc-sidebar .toc-level-3 {
  padding-left: 1.5rem;
}

/* ---------- Article header ---------- */
.post-header {
  width: 100%;
}

.post-header h1 {
  font-family: "Source Sans 3", "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: #111827;
}

/* ---------- Back navigation ---------- */
.post-footer {
  width: 100%;
}

/* ---------- Responsive article layout ---------- */
@media (min-width: 1024px) {
  .post-shell--with-toc {
    grid-template-columns: 14rem minmax(0, 68ch);
    column-gap: 2.5rem;
    align-items: start;
    padding-inline: 1.5rem;
  }

  .post-shell--with-toc .post-article,
  .post-shell--with-toc .post-footer {
    margin-inline: 0;
  }

  .toc-sidebar {
    display: block;
  }
}

@media (max-width: 640px) {
  .post-shell {
    padding-block: 2rem;
  }

  .post-content {
    font-size: 18px;
  }
}

/* ---------- Line clamp utility ---------- */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
