:root {
  --color-bg: #ffffff;
  --color-text: #191f28;
  --color-text-sub: #6b7684;
  --color-text-mute: #8b95a1;
  --color-border: #eaecef;
  --color-border-faint: #f0f2f4;
  --color-hover: #f4f2fe;
  --color-accent: #5b3df5;
  --color-accent-weak: rgba(91, 61, 245, 0.35);
  --color-selection: rgba(91, 61, 245, 0.18);
  --color-code-bg: #f3f1fb;

  --font-sans: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, Monaco, Consolas, monospace;

  --header-h: 64px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-padding-top: calc(var(--header-h) + 24px);
  scroll-behavior: smooth;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 16.5px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: var(--color-selection);
  color: var(--color-text);
}

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

a:focus-visible,
.post-card:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 24px;
}

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

/* ============================================
   Header
   ============================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

.site-header.is-scrolled {
  border-bottom-color: var(--color-border);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  height: var(--header-h);
}

.site-label {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--color-text);
  transition: color 0.15s;
}

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

.gh-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--color-text-mute);
  transition: color 0.15s;
}

.gh-link:hover {
  color: var(--color-text);
}

.gh-icon {
  opacity: 0.7;
  transition: opacity 0.15s;
}

.gh-link:hover .gh-icon {
  opacity: 1;
}

/* ============================================
   Entry stack (home)
   ============================================ */
.post-list {
  padding: 72px 0 120px;
  display: flex;
  flex-direction: column;
}

.entry {
  padding: 72px 0 64px;
  border-bottom: 1px solid var(--color-border-faint);
}

.entry:first-child { padding-top: 0; }
.entry:last-child { border-bottom: none; }

.entry-link {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 32px;
  color: inherit;
  position: relative;
}

.entry-link:focus-visible {
  outline: none;
  box-shadow: inset 3px 0 0 var(--color-accent);
  border-radius: 0;
}

.entry-date {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--color-text-mute);
  margin: 0;
  padding-top: 10px;
}

.entry-body { min-width: 0; }

.entry-title {
  font-size: clamp(28px, 3.6vw, 38px);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.25;
  margin: 0 0 18px;
  color: var(--color-text);
  transition: color 0.18s;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.entry-lead {
  font-size: 16.5px;
  line-height: 1.75;
  color: var(--color-text-sub);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.entry-more {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--color-accent);
  margin-top: 16px;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.2s, transform 0.2s;
}

.entry-link:hover .entry-title { color: var(--color-accent); }
.entry-link:hover .entry-more { opacity: 1; transform: translateY(0); }

/* ============================================
   States
   ============================================ */
.loading,
.error {
  padding: 60px 0;
  text-align: center;
  color: var(--color-text-mute);
  font-size: 14px;
}

/* ============================================
   Post layout (with TOC)
   ============================================ */
.post-layout {
  margin: 0 auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 280px minmax(0, 680px) 280px;
  gap: 48px;
  justify-content: center;
}

.post-main {
  grid-column: 2;
  min-width: 0;
}

.toc {
  grid-column: 3;
}

@media (max-width: 1380px) {
  .post-layout {
    grid-template-columns: minmax(0, 680px);
    gap: 0;
  }
  .post-main { grid-column: 1; }
  .toc { display: none; }
}

/* ============================================
   Post detail
   ============================================ */
.post {
  padding: 64px 0 40px;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.post-header {
  margin-bottom: 56px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--color-border);
}

.post-meta {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--color-text-mute);
  margin: 0 0 16px;
}

.post-title {
  font-size: clamp(28px, 3.8vw, 38px);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.25;
  margin: 0;
}

.post-body {
  font-size: 17px;
  line-height: 1.85;
  color: var(--color-text);
  word-break: keep-all;
  overflow-wrap: break-word;
}

.post-body h1,
.post-body h2,
.post-body h3 {
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.35;
  scroll-margin-top: calc(var(--header-h) + 24px);
}

.post-body h1 {
  font-size: 28px;
  margin-top: 2.6em;
  margin-bottom: 0.6em;
}

.post-body h2 {
  font-size: 22px;
  margin-top: 2.6em;
  margin-bottom: 0.6em;
}

.post-body h3 {
  font-size: 18px;
  margin-top: 2em;
  margin-bottom: 0.5em;
}

.post-body p { margin: 1.3em 0; }

.post-body a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--color-accent-weak);
  transition: text-decoration-color 0.15s;
}

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

.post-body a[target="_blank"]::after {
  content: " ↗";
  font-size: 0.82em;
  color: var(--color-text-mute);
  margin-left: 1px;
}

.post-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 1.8em auto;
  display: block;
}

.post-body figure {
  margin: 1.8em 0;
}

.post-body figcaption {
  font-size: 13px;
  color: var(--color-text-mute);
  text-align: center;
  margin-top: 8px;
  line-height: 1.5;
}

.post-body ul,
.post-body ol {
  padding-left: 1.4em;
  margin: 1.3em 0;
}

.post-body li { margin: 0.4em 0; }

.post-body blockquote {
  border-left: 2px solid var(--color-border);
  padding: 0.1em 0 0.1em 1.25em;
  margin: 2em 0;
  color: var(--color-text-sub);
  font-size: 1.02em;
  line-height: 1.75;
}

.post-body blockquote p { margin: 0.6em 0; }

.post-body blockquote em,
.post-body blockquote strong {
  color: var(--color-text);
}

.post-body blockquote code {
  color: var(--color-accent);
}

.post-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--color-code-bg);
  padding: 0.14em 0.4em;
  border-radius: 3px;
  color: var(--color-accent);
  font-weight: 500;
}

.post-body pre {
  position: relative;
  background: #0d1117;
  color: #e6edf3;
  border-radius: 8px;
  padding: 32px 22px 20px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.65;
  margin: 1.8em 0;
}

.post-body pre code,
.post-body pre code.hljs {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
  font-weight: 400;
}

.post-body pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 10px;
  right: 14px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: rgba(230, 237, 243, 0.4);
  text-transform: uppercase;
  pointer-events: none;
}

.post-body hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 2.8em 0;
}

.post-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.6em 0;
  font-size: 15px;
}

.post-body th,
.post-body td {
  border-bottom: 1px solid var(--color-border);
  padding: 10px 14px;
  text-align: left;
}

.post-body th { font-weight: 600; }

/* ============================================
   Prev/Next navigation
   ============================================ */
.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 80px;
  padding-top: 32px;
  border-top: 1px solid var(--color-border);
}

.post-nav:empty { display: none; }

.post-nav-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 0;
  color: inherit;
  transition: color 0.15s;
}

.post-nav-item--prev { text-align: left; }
.post-nav-item--next { text-align: right; grid-column: 2; }

.post-nav-label {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  color: var(--color-text-mute);
  text-transform: uppercase;
}

.post-nav-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--color-text);
  line-height: 1.4;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.post-nav-item:hover .post-nav-title { color: var(--color-accent); }

/* ============================================
   Post back
   ============================================ */
.post-back {
  padding: 40px 0 120px;
  font-size: 14px;
  color: var(--color-text-sub);
}

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

/* ============================================
   TOC (right sidebar)
   ============================================ */
.toc {
  position: sticky;
  top: calc(var(--header-h) + 56px);
  align-self: start;
  max-height: calc(100vh - var(--header-h) - 80px);
  overflow-y: auto;
  padding: 8px 0;
  border-left: 1px solid var(--color-border-faint);
  padding-left: 20px;
}

.toc:empty { display: none; }

.toc-title {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--color-text-mute);
  text-transform: uppercase;
  margin: 0 0 14px;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toc-item {
  line-height: 1.5;
}

.toc-item a {
  display: block;
  padding: 5px 0;
  font-size: 13px;
  color: var(--color-text-mute);
  letter-spacing: -0.005em;
  transition: color 0.15s;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.toc-item--h2 a { padding-left: 12px; }
.toc-item--h3 a { padding-left: 24px; font-size: 12.5px; }

.toc-item a:hover {
  color: var(--color-text);
}

.toc-item a.is-active {
  color: var(--color-accent);
  font-weight: 500;
}

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

.site-footer .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  flex-wrap: wrap;
}

.footer-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.footer-row {
  display: grid;
  grid-template-columns: 92px auto;
  gap: 16px;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.01em;
  transition: color 0.15s;
}

.footer-label {
  color: var(--color-text-mute);
}

.footer-value {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text-sub);
  transition: color 0.15s;
}

.footer-row:hover .footer-value {
  color: var(--color-text);
}

.footer-row svg {
  opacity: 0.7;
  transition: opacity 0.15s;
}

.footer-row:hover svg {
  opacity: 1;
}

.footer-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--color-text-mute);
  margin: 0;
}

/* ============================================
   Animations (subtle)
   ============================================ */
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.entry {
  opacity: 0;
  animation: fade-up 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: calc(var(--i, 0) * 60ms);
}

.post-header,
.post-body,
.post-nav,
.post-back {
  opacity: 0;
  animation: fade-up 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.post-header { animation-delay: 0ms; }
.post-body { animation-delay: 80ms; }
.post-nav { animation-delay: 160ms; }
.post-back { animation-delay: 200ms; }

.toc {
  opacity: 0;
  animation: fade-in 0.6s ease forwards;
  animation-delay: 240ms;
}

.post-body img {
  transition: opacity 0.4s ease;
}

.post-body img:not([src]) {
  opacity: 0;
}

.toc-item a.is-active {
  animation: fade-in 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001s !important;
    animation-delay: 0s !important;
    transition-duration: 0.001s !important;
  }
}

/* ============================================
   Mobile
   ============================================ */
@media (max-width: 640px) {
  body { font-size: 16px; }
  .container { padding: 0 20px; }
  .post-layout { padding: 0 20px; }
  .site-header .container { height: 56px; }
  :root { --header-h: 56px; }

  .post-list { padding: 48px 0 80px; }

  .entry { padding: 48px 0 40px; }
  .entry-link {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .entry-date { padding-top: 0; }
  .entry-title { font-size: 24px; margin-bottom: 12px; }
  .entry-lead { font-size: 16px; -webkit-line-clamp: 3; }
  .entry-more { opacity: 1; transform: none; }

  .post { padding: 40px 0 24px; }
  .post-body { font-size: 16.5px; line-height: 1.8; }
  .post-body h1 { font-size: 24px; }
  .post-body h2 { font-size: 20px; }
  .post-body h3 { font-size: 17px; }
  .post-body pre { font-size: 13px; padding: 16px; }

  .post-nav {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .post-nav-item--next { text-align: left; grid-column: 1; }
}
