/* ── Fonts ──────────────────────────────── */

@font-face {
  font-family: 'Inter';
  src: url('fonts/Inter.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Lora';
  src: url('fonts/Lora.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Lora';
  src: url('fonts/Lora-Italic.woff2') format('woff2');
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #050506;
  --surface-raised: #111116;
  --border: #1e1e24;
  --text: #dddde5;
  --text-bright: #f0f0f6;
  --text-muted: #606070;
  --accent: #4f86f7;
  --accent-hover: #74a3f9;
  --accent-glow: rgba(79, 134, 247, 0.1);
  --code-bg: #080809;
  --code-border: #1a1a20;
  --code-text: #93c5fd;
  --header-bg: rgba(5, 5, 6, 0.88);
  --link-underline: rgba(79, 134, 247, 0.35);
  --pre-code-color: #c8c8d8;
  --sidebar-width: 280px;
  --header-height: 60px;
  --content-width: 800px;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-serif: 'Lora', Georgia, serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Mono', 'Courier New', monospace;
}

body {
  font-family: var(--font-serif);
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  font-size: 17px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Light theme vars — shared between OS preference and manual toggle */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ffffff;
      --surface-raised: #f3f3f3;
    --border: #e0e0e0;
    --text: #1a1a1a;
    --text-bright: #000000;
    --text-muted: #909090;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-glow: rgba(37, 99, 235, 0.07);
    --code-bg: #f5f5f5;
    --code-border: #e0e0e0;
    --code-text: #1e40af;
    --header-bg: rgba(255, 255, 255, 0.88);
    --link-underline: rgba(37, 99, 235, 0.35);
    --pre-code-color: #2d2d3a;
  }
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --surface-raised: #f3f3f3;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-bright: #000000;
  --text-muted: #909090;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-glow: rgba(37, 99, 235, 0.07);
  --code-bg: #f5f5f5;
  --code-border: #e0e0e0;
  --code-text: #1e40af;
  --header-bg: rgba(255, 255, 255, 0.88);
  --link-underline: rgba(37, 99, 235, 0.35);
  --pre-code-color: #2d2d3a;
}

:root[data-theme="dark"] {
  --bg: #050506;
  --surface-raised: #111116;
  --border: #1e1e24;
  --text: #dddde5;
  --text-bright: #f0f0f6;
  --text-muted: #606070;
  --accent: #4f86f7;
  --accent-hover: #74a3f9;
  --accent-glow: rgba(79, 134, 247, 0.1);
  --code-bg: #080809;
  --code-border: #1a1a20;
  --code-text: #93c5fd;
  --header-bg: rgba(5, 5, 6, 0.88);
  --link-underline: rgba(79, 134, 247, 0.35);
  --pre-code-color: #c8c8d8;
}

/* ── App shell ──────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────── */

header {
  height: var(--header-height);
  background: var(--header-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 2.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

#blog-title {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-bright);
  text-decoration: none;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

#blog-title:hover {
  color: var(--accent-hover);
}

#github-link {
  margin-left: auto;
  display: flex;
  align-items: center;
  color: var(--text-muted);
  transition: color 0.12s;
  margin-right: 0.75rem;
}

#github-link:hover {
  color: var(--text);
}

#github-link svg {
  width: 1.125rem;
  height: 1.125rem;
  fill: currentColor;
}

#theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  line-height: 1;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

#theme-toggle:hover {
  background: var(--surface-raised);
  color: var(--text);
  border-color: var(--text-muted);
}

/* ── Layout ─────────────────────────────── */

#layout {
  display: flex;
  flex: 1;
  width: 100%;
  padding: 3rem 2.5rem;
  gap: 4rem;
}

/* ── Content area ───────────────────────── */

#content {
  flex: 1;
  min-width: 0;
}

/* ── Sidebar ────────────────────────────── */

#sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: calc(var(--header-height) + 3rem);
  height: fit-content;
  max-height: calc(100vh - var(--header-height) - 6rem);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#sidebar::-webkit-scrollbar { width: 3px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#sidebar h2 {
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

#post-list {
  display: flex;
  flex-direction: column;
}

.post-link {
  display: block;
  padding: 0.875rem 1rem;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  border-left: 2px solid transparent;
  transition: background 0.12s, border-color 0.12s;
  margin-bottom: 2px;
}

.post-link:hover {
  background: var(--surface-raised);
  border-left-color: var(--border);
}

.post-link.active {
  background: var(--accent-glow);
  border-left-color: var(--accent);
}

.post-link.active .post-link-title {
  color: var(--accent-hover);
}

.post-link-title {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text);
}

.post-date {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ── Article ────────────────────────────── */

#content article {
  max-width: var(--content-width);
  margin: 0 auto;
}

.post-header {
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.post-header h1 {
  font-family: var(--font-sans);
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 0.875rem;
}

.post-meta {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.post-meta::before {
  content: '';
  display: inline-block;
  width: 1rem;
  height: 1px;
  background: var(--text-muted);
}

/* ── Post body ──────────────────────────── */

.post-body {
  font-size: 1.0625rem;
  line-height: 1.8;
}

.post-body h1,
.post-body h2,
.post-body h3,
.post-body h4,
.post-body h5,
.post-body h6 {
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
  color: var(--text);
  margin-top: 2.5rem;
  margin-bottom: 0.875rem;
}

.post-body h1 { font-size: 1.75rem; }
.post-body h2 { font-size: 1.375rem; }
.post-body h3 { font-size: 1.125rem; }
.post-body h4 { font-size: 0.875rem; }
.post-body h5 { font-size: 0.8125rem; }
.post-body h6 { font-size: 0.75rem; }

.post-body p {
  margin-bottom: 1.5rem;
}

.post-body a {
  color: var(--accent-hover);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s, color 0.15s;
}

.post-body a:hover {
  color: var(--text-bright);
  text-decoration-color: var(--accent-hover);
}

.post-body strong {
  font-weight: 700;
  color: var(--text-bright);
}

.post-body em {
  font-style: italic;
}

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

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

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

.post-body blockquote {
  border-left: 2px solid var(--accent);
  padding: 0.625rem 1.5rem;
  margin: 2rem 0;
  background: var(--accent-glow);
  border-radius: 0 8px 8px 0;
}

.post-body blockquote p {
  margin-bottom: 0;
  color: var(--text-muted);
  font-style: italic;
}

.post-body code {
  font-family: var(--font-mono);
  font-size: 0.84em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 0.15em 0.4em;
  color: var(--code-text);
}

.post-body pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 10px;
  padding: 1.5rem;
  overflow-x: auto;
  margin: 2rem 0;
}

.post-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--pre-code-color);
}

.post-body hr {
  border: none;
  margin: 3rem 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 1.125rem;
  letter-spacing: 0.5em;
}

.post-body hr::before {
  content: '···';
}

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

/* ── Giscus comments ────────────────────── */

#giscus-container {
  max-width: var(--content-width);
  margin: 3rem auto 0;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

/* ── Error ──────────────────────────────── */

#error {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  color: #f87171;
  background: rgba(248, 113, 113, 0.07);
  border: 1px solid rgba(248, 113, 113, 0.2);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  max-width: var(--content-width);
  margin: 0 auto;
}

/* ── Responsive ─────────────────────────── */

@media (max-width: 768px) {
  header { padding: 0 1.25rem; }

  #layout {
    flex-direction: column-reverse;
    padding: 1.5rem 1.25rem;
    gap: 2rem;
  }

  #sidebar {
    width: 100%;
    position: static;
    max-height: none;
  }

  #post-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .post-link {
    border: 1px solid var(--border);
    border-left: 2px solid transparent;
    padding: 0.625rem 0.875rem;
  }

  .post-link.active {
    border-color: var(--accent);
  }

  .post-date { display: none; }

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