/* ─── Algo Solutions Ghost Theme ─────────────────────────── */
/* Fonts: JetBrains Mono (mono), Inter (sans) */

/* ─── CSS Variables ──────────────────────────────────────── */
:root {
  --font-mono: var(--gh-font-heading, "JetBrains Mono"), monospace;
  --font-sans:
    var(--gh-font-body, "Inter"), -apple-system, BlinkMacSystemFont, sans-serif;
  --max-width: 64rem; /* 1024px */
  --radius: 0.375rem;
}

/* ─── Koenig Width Classes ───────────────────────────────── */
.kg-width-wide {
  max-width: min(calc(var(--max-width) + 4rem), 100vw - 2rem);
  margin-left: auto;
  margin-right: auto;
}

.kg-width-full {
  max-width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  width: 100vw;
}

.kg-width-wide img,
.kg-width-full img {
  max-width: 100%;
  height: auto;
}

/* Light mode */
html.light {
  --bg: hsl(0 0% 100%);
  --fg: hsl(220 9% 20%);
  --card: hsl(0 0% 98%);
  --card-fg: hsl(220 9% 20%);
  --primary: hsl(140 50% 40%);
  --primary-fg: hsl(0 0% 100%);
  --muted: hsl(220 14% 95%);
  --muted-fg: hsl(220 9% 46%);
  --border: hsl(220 13% 88%);
  --code-bg: hsl(220 14% 95%);
  --code-fg: hsl(220 9% 20%);
  --code-border: hsl(220 13% 88%);
  --terminal-green: hsl(140 50% 40%);
  --terminal-cyan: hsl(190 70% 50%);
  --terminal-yellow: hsl(45 90% 55%);
  --terminal-red: hsl(0 70% 55%);
  --tag-bg: hsl(220 14% 93%);
  --tag-fg: hsl(220 9% 46%);
  --toc-fg: hsl(220 9% 46%);
  --progress-bar: hsl(140 50% 40%);
}

/* Dark mode (default) */
html.dark {
  --bg: hsl(220 18% 7%);
  --fg: hsl(220 14% 85%);
  --card: hsl(220 16% 10%);
  --card-fg: hsl(220 14% 85%);
  --primary: hsl(140 55% 45%);
  --primary-fg: hsl(220 18% 7%);
  --muted: hsl(220 14% 14%);
  --muted-fg: hsl(220 9% 55%);
  --border: hsl(220 14% 18%);
  --code-bg: hsl(220 16% 12%);
  --code-fg: hsl(220 14% 85%);
  --code-border: hsl(220 14% 20%);
  --terminal-green: hsl(140 55% 50%);
  --terminal-cyan: hsl(190 75% 55%);
  --terminal-yellow: hsl(45 90% 60%);
  --terminal-red: hsl(0 70% 60%);
  --tag-bg: hsl(220 14% 14%);
  --tag-fg: hsl(220 9% 60%);
  --toc-fg: hsl(220 9% 55%);
  --progress-bar: hsl(140 55% 45%);
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.6;
}

a {
  color: inherit;
  text-decoration: none;
}

::selection {
  background: hsla(140, 55%, 45%, 0.3);
  color: var(--fg);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--muted-fg);
}

/* ─── Header ─────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 2px;
  z-index: 40;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 3.5rem;
  padding: 0 1.5rem;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--fg);
  transition: color 0.2s;
}

.site-logo:hover {
  color: var(--primary);
}

.icon-terminal {
  width: 1.25rem;
  height: 1.25rem;
  color: var(--primary);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.site-nav ul {
  display: flex;
  align-items: center;
  list-style: none;
  gap: 1.5rem;
  margin: 0;
  padding: 0;
}

.site-nav li {
  margin: 0;
  padding: 0;
}

.site-nav a {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted-fg);
  transition: color 0.2s;
}

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

/* Theme toggle */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  color: var(--muted-fg);
  transition: color 0.2s;
  display: flex;
  align-items: center;
}

.theme-toggle:hover {
  color: var(--fg);
}

.theme-toggle svg {
  width: 1rem;
  height: 1rem;
}

html.dark .icon-sun {
  display: block;
}
html.dark .icon-moon {
  display: none;
}
html.light .icon-sun {
  display: none;
}
html.light .icon-moon {
  display: block;
}

/* ─── Site Main ──────────────────────────────────────────── */
.site-main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 3rem 1.5rem;
}

/* ─── Hero ───────────────────────────────────────────────── */
.hero {
  margin-bottom: 3rem;
}

.hero-path {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted-fg);
}

.hero-path .icon-terminal {
  width: 1rem;
  height: 1rem;
}

.hero-title {
  font-family: var(--font-mono);
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--fg);
  margin-bottom: 0.5rem;
  line-height: 1.2;
}

.hero-description {
  color: var(--muted-fg);
  max-width: 32rem;
  line-height: 1.6;
}

/* ─── Section Labels ─────────────────────────────────────── */
.section-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted-fg);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.label-dim {
  opacity: 0.4;
}

/* ─── Tags ───────────────────────────────────────────────── */
.tags-section {
  margin-bottom: 2rem;
}

.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.algo-tag {
  display: inline-flex;
  align-items: center;
  border-radius: 2px;
  background: var(--tag-bg);
  padding: 0.125rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--tag-fg);
  transition: color 0.2s;
  cursor: pointer;
}

.algo-tag:hover {
  color: var(--fg);
}

/* ─── Post Card ──────────────────────────────────────────── */
.posts-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.post-card {
  display: block;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  padding: 1.25rem;
  transition: border-color 0.2s;
}

.post-card:hover {
  border-color: hsla(140, 55%, 45%, 0.4);
}

.post-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.post-card-title {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--fg);
  transition: color 0.2s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.post-card:hover .post-card-title {
  color: var(--primary);
}

.post-card-excerpt {
  font-size: 0.875rem;
  color: var(--muted-fg);
  margin-bottom: 0.75rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.post-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.post-card-date {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--muted-fg);
  opacity: 0.6;
  flex-shrink: 0;
}

/* ─── Difficulty Badge ───────────────────────────────────── */
.difficulty-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.difficulty-easy {
  color: var(--terminal-green);
}
.difficulty-medium {
  color: var(--terminal-yellow);
}
.difficulty-hard {
  color: var(--terminal-red);
}

/* ─── Reading Progress ───────────────────────────────────── */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: var(--progress-bar);
  z-index: 50;
  transition: width 0.1s linear;
}

/* ─── Post Layout ────────────────────────────────────────── */
.post-layout {
  display: flex;
  gap: 3rem;
}

.post-content {
  flex: 1;
  min-width: 0;
}

.page-content {
  max-width: 48rem;
}

/* Back link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted-fg);
  transition: color 0.2s;
  margin-bottom: 2rem;
}

.back-link:hover {
  color: var(--fg);
}

.icon-sm {
  width: 0.75rem;
  height: 0.75rem;
}

/* ─── Post Header ────────────────────────────────────────── */
.post-header {
  margin-bottom: 2.5rem;
}

.post-meta-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.post-title {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--fg);
  line-height: 1.3;
  margin-bottom: 1rem;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.post-reading-time {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--muted-fg);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.post-date {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted-fg);
  opacity: 0.6;
}

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

/* ─── Post Body (Ghost Content) ──────────────────────────── */
.post-body {
  border-top: 1px solid var(--border);
  padding-top: 2rem;
}

.post-body h2 {
  font-family: var(--font-mono);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--fg);
  margin: 2.5rem 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  scroll-margin-top: 5rem;
}

.post-body h2:first-child {
  margin-top: 0;
}

.post-body h2::before {
  content: "#";
  color: var(--primary);
}

.post-body h3 {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--fg);
  margin: 2rem 0 0.75rem;
  scroll-margin-top: 5rem;
}

.post-body p {
  color: color-mix(in srgb, var(--fg) 90%, transparent);
  line-height: 1.75;
  margin-bottom: 1rem;
}

.post-body ul,
.post-body ol {
  color: color-mix(in srgb, var(--fg) 90%, transparent);
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}

.post-body li {
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

.post-body strong {
  font-weight: 600;
  color: var(--fg);
}

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

.post-body a:hover {
  opacity: 0.8;
}

/* Inline code */
.post-body code {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--code-bg);
  color: var(--primary);
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
}

/* Code blocks */
.post-body pre {
  overflow-x: auto;
  border: 0;
  border-radius: var(--radius);
}

.post-body pre code {
  background: none;
  padding: 0;
}

/* ─── Prism.js Styles ────────────────────────────────────── */
/* Override Prism.js styles to match our theme */

.code-block-wrapper > pre[class*="language-"] {
  margin: 0;
  border: none;
}

.dark .code-block-wrapper pre[class*="language-"],
.dark .code-block-wrapper code[class*="language-"] {
  font-size: 0.925rem;
}

.light .code-block-wrapper > pre[class*="language-"] {
  background: none;
}

/* Code block wrapper (injected by JS) */

.code-block-wrapper {
  position: relative;
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 1.5rem 0;
}

.code-block-wrapper pre {
  margin: 0;
  border: none;
  border-radius: 0;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--code-border);
  padding: 0.5rem 1rem;
  background: var(--code-bg);
}

.code-block-labels {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.code-block-filename {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted-fg);
}

.code-block-lang {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-fg);
  opacity: 0.6;
}

.copy-btn {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--muted-fg);
  padding: 0.25rem 0.5rem;
  border-radius: 3px;
  transition: color 0.2s;
}

.copy-btn:hover {
  color: var(--fg);
}
.copy-btn.copied {
  color: var(--terminal-green);
}

/* Blockquotes */
.post-body blockquote {
  border-left: 2px solid var(--primary);
  padding-left: 1rem;
  margin: 1.5rem 0;
  color: var(--muted-fg);
  font-style: italic;
}

/* Tables */
.post-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.875rem;
}

.post-body th,
.post-body td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.post-body th {
  background: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-fg);
}

/* Images */
.post-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 1.5rem 0;
}

.post-body figure {
  margin: 1.5rem 0;
}

.post-body figcaption {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted-fg);
  text-align: center;
  margin-top: 0.5rem;
}

/* Horizontal rule */
.post-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* ─── Complexity Cards ────────────────────────────────────── */
.complexity-card {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
}

.complexity-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted-fg);
  margin-bottom: 0.25rem;
}

.complexity-value {
  font-family: var(--font-mono);
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.complexity-time {
  color: var(--terminal-green);
}
.complexity-space {
  color: var(--terminal-cyan);
}

.complexity-note {
  font-size: 0.75rem;
  color: var(--muted-fg);
}

@media (max-width: 768px) {
  .post-body div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
}

/* KG cards (Ghost-specific content blocks) */
.post-body .kg-card {
  margin: 1.5rem 0;
}

.post-body .kg-code-card pre {
  margin: 0;
}

.post-body .kg-bookmark-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.post-body .kg-bookmark-container {
  display: flex;
  text-decoration: none;
  color: var(--fg);
}

.post-body .kg-bookmark-content {
  flex: 1;
  padding: 1rem;
}

.post-body .kg-bookmark-title {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 600;
}

.post-body .kg-bookmark-description {
  font-size: 0.75rem;
  color: var(--muted-fg);
  margin-top: 0.25rem;
}

/* ─── Table of Contents Sidebar ──────────────────────────── */
.toc-sidebar {
  display: none;
  position: sticky;
  top: 5rem;
  width: 14rem;
  flex-shrink: 0;
  align-self: flex-start;
}

@media (min-width: 1280px) {
  .toc-sidebar {
    display: block;
  }
}

.toc-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted-fg);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.toc-list {
  list-style: none;
  border-left: 1px solid var(--border);
}

.toc-link {
  display: block;
  padding: 0.25rem 0 0.25rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--toc-fg);
  border-left: 1px solid transparent;
  margin-left: -1px;
  transition:
    color 0.2s,
    border-color 0.2s;
}

.toc-link:hover {
  color: var(--fg);
  border-left-color: var(--muted-fg);
}

.toc-link.active {
  color: var(--primary);
  border-left-color: var(--primary);
}

.toc-link-nested {
  padding-left: 2rem;
  font-size: 0.6875rem;
}

/* ─── Pagination ─────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.pagination-link {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--primary);
  transition: opacity 0.2s;
}

.pagination-link:hover {
  opacity: 0.8;
}

.pagination-info {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted-fg);
}

/* ─── Footer ─────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 4rem;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted-fg);
  opacity: 0.6;
}

.footer-inner a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ─── Error Page ─────────────────────────────────────────── */
.error-page {
  text-align: center;
  padding: 6rem 0;
}

.error-code {
  font-family: var(--font-mono);
  font-size: 4rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.error-message {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--muted-fg);
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .hero-title {
    font-size: 1.5rem;
  }

  .post-title {
    font-size: 1.25rem;
  }

  .post-layout {
    flex-direction: column;
  }

  .header-inner {
    padding: 0 1rem;
  }

  .site-main {
    padding: 2rem 1rem;
  }

  .site-nav {
    gap: 1rem;
  }
}
