/* =========================================================
   main.css — Minimal sans-serif blog
   Fonts: Inter (UI + body) · JetBrains Mono (code)
   Theme: Catppuccin Mocha (dark) / Catppuccin Latte (light)
   ========================================================= */

/* --- Custom properties: Catppuccin Mocha (dark) --- */
:root,
[data-theme="dark"] {
  --bg: #1e1e2e;
  --bg-alt: #181825;
  --surface: #313244;
  --surface-hi: #45475a;
  --overlay: #585b70;
  --text: #cdd6f4;
  --subtext: #a6adc8;
  --muted: #6c7086;
  --accent: #89b4fa;
  --accent-alt: #cba6f7;
  --green: #a6e3a1;
  --red: #f38ba8;
  --yellow: #f9e2af;
  --border: #313244;
  --shadow: rgba(0, 0, 0, 0.35);

  /* Code block header — slightly lighter than bg */
  --code-header-bg: #2a2a3d;
  --code-body-bg: #1a1a2e;

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* --- Custom properties: Catppuccin Latte (light) --- */
[data-theme="light"] {
  --bg: #eff1f5;
  --bg-alt: #e6e9ef;
  --surface: #dce0e8;
  --surface-hi: #ccd0da;
  --overlay: #bcc0cc;
  --text: #4c4f69;
  --subtext: #6c6f85;
  --muted: #9ca0b0;
  --accent: #1e66f5;
  --accent-alt: #8839ef;
  --green: #40a02b;
  --red: #d20f39;
  --yellow: #df8e1d;
  --border: #ccd0da;
  --shadow: rgba(76, 79, 105, 0.1);

  --code-header-bg: #dce0e8;
  --code-body-bg: #e6e9ef;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

/* --- Masthead --- */
.masthead {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.masthead__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.masthead__logo {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}

.masthead__logo:hover {
  color: var(--accent);
  text-decoration: none;
}

.masthead__tagline {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.masthead__nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  font-size: 0.875rem;
}

.nav-link {
  color: var(--subtext);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  transition: color 0.15s;
  font-weight: 450;
}

.nav-link:hover {
  color: var(--text);
  text-decoration: none;
}

.nav-link--feed svg {
  opacity: 0.7;
}

/* --- Layout container --- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
  flex: 1;
}

.container--narrow {
  max-width: 720px;
}

/* --- Newspaper layout (main + sidebar) --- */
.newspaper-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 3rem;
  margin-top: 2.5rem;
}

@media (max-width: 920px) {
  .newspaper-layout {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .sidebar {
    border-top: 1px solid var(--border);
    padding-top: 2rem;
  }
}

/* --- Hero section --- */
.hero {
  padding-bottom: 2.5rem;
  border-bottom: 1px solid var(--border);
}

.hero__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.hero__title {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 0.875rem;
  color: var(--text);
}

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

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

.hero__desc {
  font-size: 1.0625rem;
  color: var(--subtext);
  margin-bottom: 1.5rem;
  max-width: 560px;
  line-height: 1.65;
}

/* --- Article grid --- */
.article-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

/* --- Post card --- */
.post-card {
  background-color: var(--bg);
  padding: 1.375rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: background-color 0.15s;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.post-card:hover {
  background-color: var(--surface);
}

.post-card__meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.post-card__title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
}

.post-card__title a {
  color: var(--text);
  text-decoration: none;
}

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

.post-card__desc {
  font-size: 0.85rem;
  color: var(--subtext);
  line-height: 1.55;
  flex: 1;
}

.post-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.25rem;
}

.post-card--small .post-card__title {
  font-size: 0.9375rem;
}

/* --- Sidebar --- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.sidebar-widget__title {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.875rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.sidebar-list__item {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.sidebar-list__item a {
  font-size: 0.875rem;
  color: var(--text);
  text-decoration: none;
  line-height: 1.3;
}

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

.sidebar-list__item time {
  font-size: 0.7rem;
  color: var(--muted);
}

/* --- Tags --- */
.tag {
  display: inline-block;
  padding: 0.15em 0.6em;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  background-color: var(--surface);
  color: var(--subtext);
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}

.tag:hover {
  background-color: var(--accent);
  color: var(--bg);
  text-decoration: none;
}

.tag--hero {
  background-color: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
}

.tag--large {
  font-size: 0.875rem;
  padding: 0.3em 0.8em;
}

.tag--active {
  background-color: var(--accent);
  color: var(--bg);
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55em 1.1em;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: opacity 0.15s;
}

.btn--primary {
  background-color: var(--accent);
  color: var(--bg);
}

.btn--primary:hover {
  opacity: 0.88;
  text-decoration: none;
}

/* --- Reading time --- */
.reading-time {
  font-size: 0.75rem;
  color: var(--muted);
}

/* --- Article page --- */
.article {
  padding: 2.5rem 0;
}

.article__header {
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.article__meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--subtext);
  margin-bottom: 1rem;
}

.article__title {
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.12;
  color: var(--text);
  margin-bottom: 0.875rem;
}

.article__lead {
  font-size: 1.1rem;
  color: var(--subtext);
  line-height: 1.65;
  margin-bottom: 1rem;
}

.article__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.article__footer {
  margin-top: 1.5rem;
  padding-top: 0.875rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

/* --- Prose body --- */
.prose {
  line-height: 1.75;
  font-size: 1.0625rem;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  color: var(--text);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin-top: 2.25em;
  margin-bottom: 0.6em;
}

.prose h1 {
  font-size: 1.875rem;
}

.prose h2 {
  font-size: 1.375rem;
}

.prose h3 {
  font-size: 1.125rem;
}

.prose h4 {
  font-size: 1rem;
}

.prose h2+p,
.prose h3+p {
  margin-top: 0;
}

.prose p {
  margin-bottom: 1.35em;
}

.prose a {
  color: var(--accent);
}

.prose a:hover {
  text-decoration: underline;
}

.prose ul,
.prose ol {
  margin: 0.5em 0 1.35em 1.4em;
}

.prose li {
  margin-bottom: 0.3em;
}

.prose li>ul,
.prose li>ol {
  margin-bottom: 0;
}

.prose blockquote {
  border-left: 2px solid var(--accent);
  margin: 1.5em 0;
  padding: 0.75em 1.25em;
  color: var(--subtext);
  font-style: italic;
}

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

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5em 0;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5em;
  font-size: 0.9rem;
}

.prose th,
.prose td {
  padding: 0.6em 0.875em;
  border: 1px solid var(--border);
  text-align: left;
}

.prose th {
  background-color: var(--surface);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--subtext);
}

.prose tr:nth-child(even) td {
  background-color: var(--bg-alt);
}

/* Inline code */
.prose code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  padding: 0.15em 0.4em;
  border-radius: 4px;
  background-color: var(--surface);
  color: var(--accent-alt);
}

/* ── Code blocks ─────────────────────────────────────────────────────────── */

.code-block {
  border-radius: 10px;
  overflow: hidden;
  margin: 1.75em 0;
  border: 1px solid var(--border);
  font-size: 0.875rem;
}

/* Header bar: dots + optional filename + language badge */
.code-block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 1rem;
  background-color: var(--code-header-bg);
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
}

.code-block__dots {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.code-block__dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.code-block__dot--red {
  background: #ff5f57;
}

.code-block__dot--yellow {
  background: #febc2e;
}

.code-block__dot--green {
  background: #28c840;
}

.code-block__filename {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--subtext);
  flex: 1;
  /* truncate long names */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-block__lang {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--muted);
  text-transform: lowercase;
  flex-shrink: 0;
  border: 1px solid var(--border);
  padding: 0.1em 0.45em;
  border-radius: 3px;
}

/* Copy button */
.code-block__copy {
  margin-left: auto;
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.2em 0.3em;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
  line-height: 1;
}

.code-block__copy:hover {
  color: var(--subtext);
  border-color: var(--border);
}

.code-block__copy--copied {
  color: var(--green) !important;
}

/* Shell / terminal blocks */
.code-block--shell {
  border-color: var(--surface-hi);
}

.code-block--shell .code-block__header {
  background-color: #1a1a2a;
  border-bottom-color: var(--surface-hi);
}

[data-theme="light"] .code-block--shell .code-block__header {
  background-color: #2a2d3e;
}

.code-block__terminal-icon {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--green);
  letter-spacing: -0.05em;
  flex-shrink: 0;
}

.code-block--shell .chroma,
.prose .code-block--shell .chroma {
  background-color: #1e1e2a !important;
}

[data-theme="light"] .code-block--shell .chroma,
[data-theme="light"] .prose .code-block--shell .chroma {
  background-color: #282a36 !important;
}

[data-theme="light"] .prose .code-block--shell .chroma code {
  background-color: #282a36 !important;
}

/* The chroma <pre> sits directly in the code-block, no extra border/radius */
.code-block .chroma,
.prose .code-block .chroma {
  margin: 0 !important;
  border-radius: 0 !important;
  border: none !important;
  padding: 1.125em 1.25em;
  background-color: var(--code-body-bg);
  overflow-x: auto;
  line-height: 1.6;
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

.prose .code-block .chroma code {
  background-color: var(--code-body-bg);
  padding: 0em;
}

/* ── Figure / Image (Medium-style) ──────────────────────────────────────── */

.figure {
  margin: 2.5em 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.625rem;
}

/* Shimmer wrapper — isolates the loading animation from the figcaption */
.figure__media {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-radius: 6px;
  background-color: var(--surface);
  /* line-height: 0 removes the inline gap below the img element */
  line-height: 0;
}

/* Animated shimmer sweep shown while the image is loading */
.figure__media::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent         0%,
    var(--surface-hi)  50%,
    transparent       100%
  );
  background-size: 200% 100%;
  animation: img-shimmer 1.8s ease-in-out infinite;
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.35s ease;
}

/* Hide shimmer once the image has loaded */
.figure__media.media--loaded::before {
  opacity: 0;
  animation: none;
}

@keyframes img-shimmer {
  0%   { background-position:  100% 0; }
  100% { background-position: -100% 0; }
}

.figure__media img {
  display: block;
  width: 100%;
  height: auto; /* combined with width+height attrs → browser reserves space */
  max-width: 100%;
  border-radius: inherit;
  position: relative;
  z-index: 2;
  /* Start invisible; fade in on load */
  opacity: 0;
  transition: opacity 0.5s ease;
}

.figure__media img.img--loaded {
  opacity: 1;
}

.figure figcaption {
  font-size: 0.8125rem;
  color: var(--muted);
  text-align: center;
  max-width: 480px;
  line-height: 1.5;
}

/* Wide: breaks slightly out of column */
.figure--wide {
  margin-left: -2.5rem;
  margin-right: -2.5rem;
}

.figure--wide .figure__media {
  border-radius: 4px;
}

/* Full-bleed: viewport width */
.figure--full {
  margin-left: calc(-50vw + 50%);
  margin-right: calc(-50vw + 50%);
  width: 100vw;
  max-width: 100vw;
}

.figure--full .figure__media {
  border-radius: 0;
}

.figure--full .figure__media img {
  width: 100%;
  max-width: 100%;
}

/* --- Giscus comments --- */
.giscus-wrap {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.giscus-wrap .giscus {
  margin: 0;
}

/* --- Suggested posts --- */
.suggested {
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.suggested__title {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.suggested__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

@media (max-width: 640px) {
  .suggested__grid {
    grid-template-columns: 1fr;
  }
}

/* --- Breadcrumb --- */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.breadcrumb a {
  color: var(--subtext);
}

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

/* --- Page header --- */
.page-header {
  margin-bottom: 0.5rem;
}

.page-header__count {
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

/* --- Theme toggle (icon-only) --- */
theme-toggle button,
.theme-toggle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3em 0.4em;
  cursor: pointer;
  color: var(--subtext);
  display: flex;
  align-items: center;
  transition: border-color 0.15s, color 0.15s;
  line-height: 1;
}

theme-toggle button:hover,
.theme-toggle-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

theme-toggle button svg,
.theme-toggle-btn svg {
  display: block;
}

/* --- Feed widget --- */
feed-widget .feed-widget {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.125rem;
}

feed-widget .feed-widget__title {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

feed-widget .feed-widget__links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

feed-widget .feed-widget__link {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8125rem;
  color: var(--subtext);
  text-decoration: none;
}

feed-widget .feed-widget__link:hover {
  color: var(--accent);
}

/* --- Footer --- */
.site-footer {
  background-color: var(--bg-alt);
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.site-footer__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.site-footer__right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.site-footer__right a {
  color: var(--subtext);
}

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

/* --- Responsive --- */
@media (max-width: 600px) {
  .masthead__inner {
    padding: 0.625rem 1rem;
    gap: 0.5rem;
  }

  .masthead__tagline {
    display: none;
  }

  .masthead__nav {
    gap: 0.75rem;
    font-size: 0.8125rem;
  }

  .nav-link--feed span:not(.sr-only) {
    display: none;
  }

  .container {
    padding: 2rem 1rem 3rem;
  }

  .hero__title {
    font-size: 1.625rem;
  }

  .article__title {
    font-size: 1.625rem;
  }

  .article-grid {
    grid-template-columns: 1fr;
  }

  .figure--wide {
    margin-left: -1rem;
    margin-right: -1rem;
  }

  .figure--wide .figure__media {
    border-radius: 4px;
  }

  .site-footer__inner {
    flex-direction: column;
    align-items: flex-start;
  }
}
