/* ========================================
   Design System & Variables
   ======================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Colors — Dark (default) */
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2233;
  --bg-card-hover: #1f2b3f;
  --bg-code: #151d2b;
  --bg-nav: rgba(10, 14, 23, 0.85);

  --text-primary: #e4e8f1;
  --text-secondary: #8892a6;
  --text-muted: #5a6478;

  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --accent-gradient: linear-gradient(135deg, #3b82f6, #06b6d4);

  --border: #1e293b;
  --border-hover: #334155;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Spacing */
  --container-max: 1100px;
  --container-narrow: 780px;
  --nav-height: 72px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px var(--accent-glow);

  /* Border radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

/* ========================================
   Light Theme
   ======================================== */
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-card: #f1f5f9;
  --bg-card-hover: #e8eef4;
  --bg-code: #f1f5f9;
  --bg-nav: rgba(255, 255, 255, 0.85);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-glow: rgba(37, 99, 235, 0.1);
  --accent-gradient: linear-gradient(135deg, #2563eb, #0891b2);

  --border: #e2e8f0;
  --border-hover: #cbd5e1;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
  --shadow-glow: 0 0 30px var(--accent-glow);
}

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-base), color var(--transition-base);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

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

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

/* ========================================
   Container
   ======================================== */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 24px;
}

.container--narrow {
  max-width: var(--container-narrow);
}

/* ========================================
   Navigation
   ======================================== */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-nav);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid transparent;
  z-index: 1000;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.nav.scrolled {
  border-bottom-color: var(--border);
  box-shadow: var(--shadow-md);
}

.nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.nav__logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  transition: color var(--transition-fast);
}

.nav__logo:hover {
  color: var(--accent);
}

.nav__logo span {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav__links {
  display: flex;
  align-items: center;
  gap: 32px;
  list-style: none;
}

.nav__link {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color var(--transition-fast);
  position: relative;
}

.nav__link::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--accent-gradient);
  border-radius: 1px;
  transition: width var(--transition-base);
}

.nav__link:hover,
.nav__link.active {
  color: var(--text-primary);
}

.nav__link:hover::after,
.nav__link.active::after {
  width: 100%;
}

.nav__social {
  display: flex;
  align-items: center;
  gap: 16px;
}

.nav__social a {
  color: var(--text-muted);
  transition: color var(--transition-fast), transform var(--transition-fast);
  display: flex;
  align-items: center;
}

.nav__social a:hover {
  color: var(--text-primary);
  transform: translateY(-1px);
}

.nav__social svg {
  width: 20px;
  height: 20px;
}

/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
  width: 36px;
  height: 36px;
}

.theme-toggle:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
  background: var(--bg-card);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.theme-toggle .icon-sun {
  display: none;
}

.theme-toggle .icon-moon {
  display: block;
}

[data-theme="light"] .theme-toggle .icon-sun {
  display: block;
}

[data-theme="light"] .theme-toggle .icon-moon {
  display: none;
}

/* Mobile menu toggle */
.nav__toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.nav__toggle span {
  width: 22px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: transform var(--transition-base), opacity var(--transition-fast);
}

.nav__toggle.open span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.nav__toggle.open span:nth-child(2) {
  opacity: 0;
}

.nav__toggle.open span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* ========================================
   Hero Section
   ======================================== */
.hero {
  padding: calc(var(--nav-height) + 80px) 0 80px;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: -200px;
  right: -200px;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  pointer-events: none;
}

.hero__content {
  max-width: 640px;
}

.hero__greeting {
  font-size: 1rem;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.hero__name {
  font-size: clamp(2.5rem, 5vw, 3.5rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin-bottom: 16px;
}

.hero__name span {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero__title {
  font-size: 1.35rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.hero__description {
  font-size: 1.05rem;
  color: var(--text-secondary);
  line-height: 1.8;
  max-width: 540px;
}

/* ========================================
   Section Styles
   ======================================== */
.section {
  padding: 80px 0;
}

.section__header {
  margin-bottom: 48px;
}

.section__title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.section__subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
}

/* ========================================
   Post Cards
   ======================================== */
.posts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}

.post-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 32px;
  transition: transform var(--transition-base), border-color var(--transition-base),
    box-shadow var(--transition-base), background var(--transition-base);
  display: flex;
  flex-direction: column;
}

.post-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.post-card__meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.post-card__date {
  color: var(--text-muted);
}

.post-card__reading-time {
  color: var(--text-muted);
}

.post-card__reading-time::before {
  content: '·';
  margin-right: 12px;
}

.post-card__title {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  line-height: 1.4;
  letter-spacing: -0.01em;
  transition: color var(--transition-fast);
}

.post-card:hover .post-card__title {
  color: var(--accent);
}

.post-card__excerpt {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.7;
  margin-bottom: 20px;
  flex-grow: 1;
}

.post-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  display: inline-block;
  padding: 4px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-glow);
  border-radius: 20px;
  letter-spacing: 0.02em;
}

/* ========================================
   Blog Page
   ======================================== */
.page-header {
  padding: calc(var(--nav-height) + 60px) 0 40px;
}

.page-header__title {
  font-size: clamp(2rem, 4vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.page-header__description {
  color: var(--text-secondary);
  font-size: 1.05rem;
  margin-top: 8px;
}

/* ========================================
   Article Page
   ======================================== */
.article-header {
  padding: calc(var(--nav-height) + 60px) 0 40px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 48px;
}

.article-header__back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 24px;
  transition: color var(--transition-fast);
}

.article-header__back:hover {
  color: var(--accent);
}

.article-header__title {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.03em;
  margin-bottom: 16px;
}

.article-header__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.article-header__tags {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* Article Body */
.article-body {
  padding-bottom: 80px;
}

.article-body h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 48px;
  margin-bottom: 16px;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.article-body h3 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-top: 36px;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.article-body p {
  margin-bottom: 20px;
  color: var(--text-secondary);
  font-size: 1.05rem;
  line-height: 1.8;
}

.article-body ul,
.article-body ol {
  margin-bottom: 20px;
  padding-left: 24px;
  color: var(--text-secondary);
}

.article-body li {
  margin-bottom: 8px;
  line-height: 1.7;
}

.article-body strong {
  color: var(--text-primary);
  font-weight: 600;
}

.article-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 12px 24px;
  margin: 24px 0;
  background: var(--accent-glow);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-style: italic;
}

.article-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.article-body a:hover {
  color: var(--accent-hover);
}

/* Code — inline */
.article-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  padding: 2px 6px;
  background: var(--bg-code);
  border-radius: 4px;
  color: var(--accent-hover);
}

/* ========================================
   Code Block Component
   ======================================== */
.code-block {
  margin: 24px 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}

/* Header bar */
.code-block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  min-height: 40px;
}

.code-block__lang {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Copy button */
.code-block__copy {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

.code-block__copy:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
  background: var(--bg-card);
}

.code-block__copy-check {
  display: none;
}

.code-block__copy.copied {
  color: #22c55e;
  border-color: rgba(34, 197, 94, 0.3);
}

.code-block__copy.copied .code-block__copy-icon {
  display: none;
}

.code-block__copy.copied .code-block__copy-check {
  display: inline-flex;
}

/* Code body */
.code-block__body {
  position: relative;
  overflow: hidden;
  transition: max-height 0.35s ease;
}

/* Specificity hack to override Prism loaded later */
body .code-block__body pre[class*="language-"],
body .code-block__body pre {
  margin: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  background: var(--bg-code) !important;
  /* Top/Bottom 12px, Right 16px, Left 3.8em (gutter for line numbers) */
  padding: 12px 16px 12px 3.8em !important;
  position: relative;
}

body .code-block__body pre[class*="language-"] code,
body .code-block__body pre code {
  display: block;
  padding: 0 !important;
  background: transparent !important;
  font-size: 0.875rem;
  line-height: 1.65;
  color: var(--text-primary);
  text-shadow: none !important;
  /* Ensure relative positioning for line-numbers-rows if it's a child */
  position: relative;
}

/* Force line numbers to sit inside the padding area */
body .code-block__body .line-numbers-rows {
  left: -3.8em !important;
}

/* Horizontal scroll hint gradient */
.code-block__body.has-overflow::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 40px;
  background: linear-gradient(to right, transparent, var(--bg-code));
  pointer-events: none;
  z-index: 2;
}

/* Collapsed state */
.code-block--collapsed .code-block__body {
  max-height: 300px;
}

/* Fade overlay when collapsed */
.code-block--collapsed .code-block__body::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: linear-gradient(to bottom, transparent, var(--bg-code));
  z-index: 3;
  pointer-events: none;
}

/* Expand / collapse button */
.code-block__expand {
  display: none;
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: color var(--transition-fast), background var(--transition-fast);
}

.code-block__expand:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

/* Show expand button when block is collapsible */
.code-block--collapsed .code-block__expand,
.code-block--expanded .code-block__expand {
  display: flex;
}

/* Rotate chevron when expanded */
.code-block--expanded .code-block__expand svg {
  transform: rotate(180deg);
}

/* Old pre/code selectors kept as fallback for unmatched blocks */
.article-body pre {
  margin: 24px 0;
  border-radius: var(--radius-md);
  overflow-x: auto;
  border: 1px solid var(--border);
}

.article-body pre code {
  display: block;
  padding: 24px;
  background: var(--bg-code);
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-primary);
}

/* ========================================
   Footer
   ======================================== */
.footer {
  margin-top: auto;
  padding: 40px 0;
  border-top: 1px solid var(--border);
}

.footer__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.footer__copyright {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.footer__social {
  display: flex;
  gap: 16px;
}

.footer__social a {
  color: var(--text-muted);
  transition: color var(--transition-fast);
  display: flex;
  align-items: center;
}

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

.footer__social svg {
  width: 18px;
  height: 18px;
}

/* ========================================
   Animations
   ======================================== */
.fade-in {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--transition-slow), transform var(--transition-slow);
}

.fade-in.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger children */
.stagger>.fade-in:nth-child(1) {
  transition-delay: 0ms;
}

.stagger>.fade-in:nth-child(2) {
  transition-delay: 100ms;
}

.stagger>.fade-in:nth-child(3) {
  transition-delay: 200ms;
}

.stagger>.fade-in:nth-child(4) {
  transition-delay: 300ms;
}

.stagger>.fade-in:nth-child(5) {
  transition-delay: 400ms;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 768px) {
  .nav__links {
    position: fixed;
    top: var(--nav-height);
    left: 0;
    width: 100%;
    height: calc(100dvh - var(--nav-height));
    background: var(--bg-primary);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
    z-index: 999;
    padding: 0 24px;
  }

  .nav__links.open {
    opacity: 1;
    visibility: visible;
  }

  .nav__link {
    font-size: 1.2rem;
  }

  .nav__social--desktop {
    display: none;
  }

  .nav__social--mobile {
    display: flex !important;
  }

  .nav__toggle {
    display: flex;
    margin-left: 12px;
  }

  .theme-toggle {
    margin-left: auto;
  }

  .hero {
    padding: calc(var(--nav-height) + 48px) 0 48px;
  }

  .hero__name {
    font-size: 2.25rem;
  }

  .section {
    padding: 48px 0;
  }

  .footer__inner {
    flex-direction: column;
    gap: 16px;
    text-align: center;
  }

  /* Code blocks on mobile */
  .code-block {
    margin-left: -24px;
    margin-right: -24px;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  /* Restore padding for line numbers */
  .code-block__body pre.line-numbers {
    padding-left: 3.8em;
  }

  .article-body pre.line-numbers {
    padding-left: 3.8em;
  }

  .code-block__body pre code {
    padding: 16px 16px;
    font-size: 0.8rem;
    /* Prevent code element from clipping line numbers */
    overflow: visible;
  }

  .code-block__body pre {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .article-body pre {
    margin-left: -24px;
    margin-right: -24px;
    border-radius: 0;
    border-left: none;
    border-right: none;
    overflow-x: auto;
  }

  .article-body pre code {
    padding: 16px 20px;
    font-size: 0.8rem;
    overflow: visible;
  }
}

@media (min-width: 769px) {
  .nav__social--mobile {
    display: none !important;
  }

  .posts-grid {
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  }
}

/* ========================================
   Prism.js Theme Overrides
   ======================================== */
pre[class*="language-"],
code[class*="language-"] {
  font-family: var(--font-mono) !important;
  font-size: 0.875rem !important;
}

/* Line numbers styling */
.line-numbers .line-numbers-rows {
  border-right: 1px solid var(--border) !important;
  padding-right: 4px;
}

.line-numbers .line-numbers-rows>span::before {
  color: var(--text-muted) !important;
}

/* Light mode: override Prism theme for readability */
[data-theme="light"] pre[class*="language-"],
[data-theme="light"] code[class*="language-"] {
  background: var(--bg-code) !important;
  color: #334155 !important;
}

[data-theme="light"] .code-block__body pre code {
  color: #334155 !important;
}

[data-theme="light"] .article-body pre code {
  color: #334155 !important;
}

/* Light mode syntax colors */
[data-theme="light"] .token.comment,
[data-theme="light"] .token.prolog,
[data-theme="light"] .token.doctype,
[data-theme="light"] .token.cdata {
  color: #6b7280 !important;
}

[data-theme="light"] .token.punctuation {
  color: #475569 !important;
}

[data-theme="light"] .token.property,
[data-theme="light"] .token.tag,
[data-theme="light"] .token.boolean,
[data-theme="light"] .token.number,
[data-theme="light"] .token.constant,
[data-theme="light"] .token.symbol {
  color: #b45309 !important;
}

[data-theme="light"] .token.selector,
[data-theme="light"] .token.attr-name,
[data-theme="light"] .token.string,
[data-theme="light"] .token.char,
[data-theme="light"] .token.builtin {
  color: #047857 !important;
}

[data-theme="light"] .token.operator,
[data-theme="light"] .token.entity,
[data-theme="light"] .token.url {
  color: #92400e !important;
}

[data-theme="light"] .token.atrule,
[data-theme="light"] .token.attr-value,
[data-theme="light"] .token.keyword {
  color: #7c3aed !important;
}

[data-theme="light"] .token.function,
[data-theme="light"] .token.class-name {
  color: #2563eb !important;
}

[data-theme="light"] .token.regex,
[data-theme="light"] .token.important,
[data-theme="light"] .token.variable {
  color: #b91c1c !important;
}

/* Light mode line numbers */
[data-theme="light"] .line-numbers .line-numbers-rows {
  border-right-color: var(--border) !important;
}

[data-theme="light"] .line-numbers .line-numbers-rows>span::before {
  color: #94a3b8 !important;
}