:root {
  color-scheme: dark;
  --bg: #0b0a09;
  --surface: rgba(24, 21, 19, 0.74);
  --surface-solid: #161412;
  --text: #f5f0e9;
  --muted: #a69d93;
  --line: rgba(245, 240, 233, 0.13);
  --accent: #ff5a36;
  --accent-soft: rgba(255, 90, 54, 0.14);
  --on-accent: #190703;
  --code-bg: #141210;
  --gpu-a: #ff4a24;
  --gpu-b: #ffc27a;
  --hl-keyword: #ff8a6b;
  --hl-string: #ffc27a;
  --hl-title: #f5d9a8;
  --hl-comment: #7c746b;
  --font-sans: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --wide: 1120px;
  --narrow: 720px;
  --gutter: clamp(16px, 4vw, 32px);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8f4ee;
  --surface: rgba(255, 253, 250, 0.82);
  --surface-solid: #fffdfa;
  --text: #1c1815;
  --muted: #6a6158;
  --line: rgba(28, 24, 21, 0.14);
  --accent: #c93210;
  --accent-soft: rgba(201, 50, 16, 0.1);
  --on-accent: #fff8f4;
  --code-bg: #f1ebe2;
  --gpu-a: #d6391a;
  --gpu-b: #e08a1e;
  --hl-keyword: #b42c0e;
  --hl-string: #8a5a00;
  --hl-title: #6e3b12;
  --hl-comment: #8b8176;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 96px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.7;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; display: block; }
h1, h2, h3 { line-height: 1.25; letter-spacing: -0.02em; margin: 0; }
p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

#gpu-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

#reading-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 30;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
}

.container { width: 100%; max-width: calc(var(--wide) + var(--gutter) * 2); margin: 0 auto; padding: 0 var(--gutter); }
.container.narrow { max-width: calc(var(--narrow) + var(--gutter) * 2); }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--accent);
}
.muted { color: var(--muted); }

/* 머리글 */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid transparent;
  border-bottom-color: var(--line);
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
}
.brand { font-family: var(--font-mono); font-weight: 600; letter-spacing: -0.02em; }
.site-nav { display: flex; align-items: center; gap: clamp(12px, 3vw, 28px); font-size: 15px; }
.site-nav a { color: var(--muted); transition: color 0.2s; }
.site-nav a:hover, .site-nav a.is-active { color: var(--text); }
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.3s var(--ease);
}
.icon-button:hover { border-color: var(--accent); transform: rotate(20deg); }
.icon-button::before { content: "☾"; font-size: 15px; line-height: 1; }
[data-theme="light"] .icon-button::before { content: "☀"; }

main { flex: 1; }

/* 첫 화면 */
.hero {
  min-height: calc(100vh - 65px);
  min-height: calc(100svh - 65px);
  display: flex;
  align-items: center;
  padding: 64px 0;
}
.hero-copy { max-width: 620px; }
.hero h1 {
  margin: 20px 0 24px;
  font-size: clamp(2.6rem, 6.6vw, 4.8rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.12;
}
.hero-lead { color: var(--muted); font-size: clamp(1.05rem, 2vw, 1.2rem); max-width: 25em; }
.pre-line { white-space: pre-line; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 36px; }
.hero-stats {
  display: flex;
  gap: 32px;
  margin: 48px 0 0;
  padding: 0;
  font-family: var(--font-mono);
}
.hero-stats div { display: flex; flex-direction: column; }
.hero-stats dt { order: 2; color: var(--muted); font-size: 13px; }
.hero-stats dd { order: 1; margin: 0; font-size: 26px; font-weight: 600; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.25s var(--ease), border-color 0.2s, background 0.2s;
}
.button:hover { transform: translateY(-2px); border-color: var(--accent); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.button.small { min-height: 36px; padding: 0 14px; font-size: 14px; }
.button.danger { color: var(--accent); }

/* 구역 */
.section { padding: clamp(72px, 12vh, 140px) 0; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
}
.section-head h2 { font-size: clamp(1.7rem, 3.6vw, 2.4rem); font-weight: 750; }
.text-link { color: var(--muted); font-size: 15px; white-space: nowrap; transition: color 0.2s; }
.text-link:hover { color: var(--accent); }

.post-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.post-row { border-bottom: 1px solid var(--line); }
.post-row a {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 8px 24px;
  align-items: baseline;
  padding: 26px 0;
  transition: padding 0.35s var(--ease);
}
.post-row a:hover { padding-left: 12px; }
.post-row time { font-family: var(--font-mono); font-size: 13px; color: var(--muted); }
.post-row h3 { font-size: clamp(1.15rem, 2.4vw, 1.45rem); font-weight: 700; transition: color 0.2s; }
.post-row a:hover h3 { color: var(--accent); }
.post-row p { grid-column: 2; color: var(--muted); font-size: 15.5px; }
.post-row .reading { grid-column: 3; grid-row: 1; font-family: var(--font-mono); font-size: 13px; color: var(--muted); }
.tag-line { grid-column: 2; display: flex; flex-wrap: wrap; gap: 6px 10px; font-family: var(--font-mono); font-size: 13px; color: var(--muted); }
.tag-line span::before { content: "#"; color: var(--accent); }

.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 20px; }
.project-card {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform 0.35s var(--ease), border-color 0.25s;
}
.project-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  background: radial-gradient(280px circle at var(--spot-x, 50%) var(--spot-y, 50%), var(--accent-soft), transparent 70%);
}
.project-card:hover { transform: translateY(-4px); border-color: var(--accent); }
.project-card:hover::after { opacity: 1; }
.project-cover {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, var(--accent-soft), transparent 70%), var(--surface-solid);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 44px;
  font-weight: 600;
  color: var(--accent);
}
.project-cover img { width: 100%; height: 100%; object-fit: cover; }
.project-body { display: flex; flex-direction: column; gap: 10px; padding: 22px; }
.project-body h3 { font-size: 1.25rem; font-weight: 700; }
.project-body p { color: var(--muted); font-size: 15.5px; }
.stack { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 0; padding: 0; list-style: none; }
.stack li {
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--muted);
}

.empty { padding: 56px 0; text-align: center; color: var(--muted); }

/* 스크롤 등장 효과. 스크립트가 없으면 처음부터 보인다. */
.js .reveal { opacity: 0; transform: translateY(20px); transition: opacity 0.7s var(--ease), transform 0.7s var(--ease); }
.js .reveal.is-visible { opacity: 1; transform: none; }

/* 내부 페이지 */
.page { padding: clamp(40px, 8vh, 80px) 0 96px; }
.page-title { margin-bottom: 32px; }
.page-title h1 { margin-top: 12px; font-size: clamp(2.1rem, 5vw, 3.2rem); font-weight: 800; }
.page-title p { margin-top: 12px; color: var(--muted); }

.filters { display: flex; flex-direction: column; gap: 16px; margin-bottom: 32px; }
.search { display: flex; gap: 8px; max-width: 460px; }
.search input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}
.search input:focus { outline: none; border-color: var(--accent); }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-chip {
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  transition: color 0.2s, border-color 0.2s;
}
.tag-chip:hover, .tag-chip.is-active { color: var(--accent); border-color: var(--accent); }

.pagination { display: flex; align-items: center; justify-content: center; gap: 20px; margin-top: 40px; font-family: var(--font-mono); font-size: 14px; }

/* 글 본문 */
.article-layout { display: grid; grid-template-columns: minmax(0, var(--narrow)) 220px; gap: 56px; justify-content: center; }
.article-card {
  min-width: 0;
  padding: clamp(24px, 4vw, 48px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.article-head h1 { margin: 12px 0 16px; font-size: clamp(1.9rem, 4.6vw, 2.8rem); font-weight: 800; }
.article-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-family: var(--font-mono); font-size: 13px; color: var(--muted); }
.article-head { padding-bottom: 28px; margin-bottom: 32px; border-bottom: 1px solid var(--line); }

.toc { position: sticky; top: 96px; align-self: start; font-size: 14px; }
.toc[hidden] { display: none; }
.toc strong { font-family: var(--font-mono); font-size: 12px; color: var(--muted); font-weight: 500; }
.toc ol { list-style: none; margin: 10px 0 0; padding: 0; border-left: 1px solid var(--line); }
.toc li a { display: block; padding: 4px 0 4px 14px; margin-left: -1px; border-left: 1px solid transparent; color: var(--muted); transition: color 0.2s; }
.toc li.toc-h3 a { padding-left: 26px; font-size: 13px; }
.toc a:hover, .toc a.is-active { color: var(--text); }
.toc a.is-active { border-left-color: var(--accent); }

.prose { font-size: 17px; line-height: 1.85; }
.prose > * + * { margin-top: 1.1em; }
.prose h2 { margin-top: 2.2em; font-size: 1.55rem; font-weight: 750; }
.prose h3 { margin-top: 1.8em; font-size: 1.22rem; font-weight: 700; }
.prose a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: 0.3em; }
.prose img { border-radius: 10px; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.4em 0; }
.prose blockquote { margin-left: 0; margin-right: 0; padding-left: 18px; border-left: 3px solid var(--accent); color: var(--muted); }
.prose code { font-family: var(--font-mono); font-size: 0.88em; padding: 0.12em 0.36em; border-radius: 5px; background: var(--accent-soft); }
.prose pre {
  position: relative;
  overflow-x: auto;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--code-bg);
  line-height: 1.6;
}
.prose pre code { padding: 0; background: none; font-size: 14px; }
.prose table { display: block; overflow-x: auto; width: 100%; border-collapse: collapse; font-size: 15px; }
.prose th, .prose td { padding: 9px 14px; border: 1px solid var(--line); text-align: left; }
.prose th { background: var(--accent-soft); }

.code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-solid);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}
.prose pre:hover .code-copy, .code-copy:focus-visible { opacity: 1; }

.hljs-keyword, .hljs-built_in, .hljs-literal, .hljs-type { color: var(--hl-keyword); }
.hljs-string, .hljs-number, .hljs-attr { color: var(--hl-string); }
.hljs-title, .hljs-section { color: var(--hl-title); }
.hljs-comment, .hljs-meta { color: var(--hl-comment); }

.post-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 40px; }
.post-nav a {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  transition: border-color 0.2s;
}
.post-nav a:hover { border-color: var(--accent); }
.post-nav small { display: block; font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.post-nav .next { grid-column: 2; text-align: right; }

.project-links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.project-hero { margin-bottom: 32px; overflow: hidden; border-radius: 12px; border: 1px solid var(--line); }

.about-links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }

/* 바닥글 */
.site-footer { border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 70%, transparent); }
.site-footer .container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  padding-top: 24px;
  padding-bottom: 24px;
  font-size: 13.5px;
  color: var(--muted);
}
#gpu-status { font-family: var(--font-mono); font-size: 12.5px; }

/* 오류 */
.error-page { min-height: 60vh; display: grid; place-content: center; text-align: center; gap: 12px; padding: 64px 0; }
.error-page strong { font-family: var(--font-mono); font-size: clamp(4rem, 14vw, 7rem); color: var(--accent); line-height: 1; }
.error-page .button { justify-self: center; margin-top: 16px; }

/* 관리자 */
.admin-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.admin-head h2 { font-size: 1.3rem; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-section + .admin-section { margin-top: 56px; }
.admin-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.admin-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.admin-item { min-width: 0; flex: 1 1 280px; }
.admin-item small { display: block; font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); }
.badge { display: inline-block; margin-right: 6px; padding: 0 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.badge.draft { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.flash { margin-bottom: 20px; padding: 10px 16px; border-radius: 10px; background: var(--accent-soft); font-size: 15px; }

.form-grid { display: grid; gap: 20px; }
.field { display: grid; align-content: start; gap: 6px; min-width: 0; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; }
.field label, .field .label { font-size: 14px; font-weight: 600; }
.field small { color: var(--muted); font-size: 13px; }
.field input[type="text"], .field input[type="url"], .field input[type="number"], .field input[type="password"], .field textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-solid);
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field textarea { min-height: 520px; resize: vertical; font-family: var(--font-mono); font-size: 14px; line-height: 1.7; }
.field textarea.short { min-height: 96px; font-family: inherit; font-size: 15px; }
.field-error { color: var(--accent); font-size: 13.5px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; }
.checks { display: flex; flex-wrap: wrap; gap: 20px; }
.editor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.editor-tools { display: grid; gap: 8px; min-width: 0; }
.editor-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-solid); }
.editor-toolbar button {
  min-width: 32px;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.editor-toolbar button:hover { background: var(--accent-soft); color: var(--text); }
.toolbar-gap { width: 1px; height: 18px; margin: 0 4px; background: var(--line); }
.draft-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
.draft-banner[hidden] { display: none; }
.draft-banner > span { flex: 1 1 200px; }
.field textarea.is-dragging { border-color: var(--accent); background: var(--accent-soft); }
.preview-pane { max-height: 620px; overflow: auto; padding: 18px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-solid); }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.login-box { max-width: 380px; margin: 0 auto; }

@media (max-width: 960px) {
  .article-layout { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
  .editor-grid { grid-template-columns: minmax(0, 1fr); }
  .field textarea { min-height: 360px; }
}

@media (max-width: 640px) {
  .post-row a { grid-template-columns: 1fr auto; }
  .post-row h3, .post-row p, .tag-line { grid-column: 1 / -1; }
  .post-row .reading { grid-column: 2; grid-row: 1; }
  .hero { min-height: auto; padding: 72px 0 56px; }
  .hero-stats { gap: 24px; }
  .post-nav { grid-template-columns: 1fr; }
  .post-nav .next { grid-column: 1; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .js .reveal { opacity: 1; transform: none; }
}
