/* ---------- tokens ---------- */
:root {
  --bg: #f8f0e0;
  --bg-elevated: #fffbf2;
  --fg: #1c1b19;
  --fg-muted: #6b6660;
  --border: #e8dcc4;
  --accent: #a8542f;
  --accent-fg: #ffffff;
  --code-bg: #1e1e1e;
  --code-fg: #d4d4d4;
  --shadow: 0 1px 2px rgba(28, 27, 25, 0.06), 0 4px 16px rgba(28, 27, 25, 0.06);
  --radius: 10px;
  --content-width: 60rem;
  --content-width-wide: 76rem;
  --font-sans: "Noto Sans KR", -apple-system, "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
  --font-mono: Consolas, "SF Mono", "Cascadia Code", "D2Coding", monospace;
}

/* Noto Sans KR (loaded from Google Fonts in base.html) covers both scripts,
   so `body`'s font-family below just applies to both languages now. */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171614;
    --bg-elevated: #1f1e1b;
    --fg: #ece8e1;
    --fg-muted: #a39c92;
    --border: #322f2a;
    --accent: #e08a5b;
    --accent-fg: #171614;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 20px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #171614;
  --bg-elevated: #1f1e1b;
  --fg: #ece8e1;
  --fg-muted: #a39c92;
  --border: #322f2a;
  --accent: #e08a5b;
  --accent-fg: #171614;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 20px rgba(0, 0, 0, 0.35);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { color-scheme: light dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: var(--content-width); margin: 0 auto; padding: 0 1.5rem; }
.wrap-wide { max-width: var(--content-width-wide); margin: 0 auto; padding: 0 1.5rem; }
a { color: inherit; }
img { max-width: 100%; border-radius: 6px; }
.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--accent); color: var(--accent-fg); padding: .5rem 1rem; z-index: 100;
}
.skip-link:focus { left: 1rem; top: 1rem; }

/* ---------- header ---------- */
.site-header {
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  z-index: 10;
}
.header-inner {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .9rem 1.5rem;
}
.brand { font-weight: 700; text-decoration: none; letter-spacing: -.01em; flex-shrink: 0; }
.main-nav { display: flex; gap: 1.1rem; flex: 1; }
.main-nav a { text-decoration: none; color: var(--fg-muted); font-size: .93rem; }
.main-nav a:hover, .main-nav a.active { color: var(--fg); }
.header-controls { display: flex; align-items: center; gap: .9rem; flex-shrink: 0; }
.lang-switch { display: flex; gap: .5rem; font-size: .85rem; }
.lang-switch a { text-decoration: none; color: var(--fg-muted); }
.lang-switch a:hover { color: var(--fg); }
.lang-current { color: var(--fg); font-weight: 600; }
#theme-toggle {
  background: none; border: 1px solid var(--border); color: var(--fg);
  border-radius: 999px; width: 2rem; height: 2rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
#theme-toggle:hover { border-color: var(--accent); }
/* An actual icon, not a "◐" text glyph - that glyph isn't reliably covered
   by any font, so the browser falls back to a *locale-appropriate* font
   for it based on html[lang], rendering it at a different apparent size
   per language. A masked icon sidesteps font coverage entirely.

   Two icons stacked in the same slot, toggled by the *effective* theme -
   showing what you'd switch TO (sun while dark, moon while light) is the
   standard convention. Same "effectively dark" logic as the color tokens
   above: explicit data-theme="dark", or no override while the system
   prefers dark. */
.icon-theme {
  display: none; width: 1.05rem; height: 1.05rem; flex: none;
  background-color: currentColor;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-size: contain; mask-size: contain;
}
.icon-sun { -webkit-mask-image: url("/images/icon-sun.svg"); mask-image: url("/images/icon-sun.svg"); }
.icon-moon { -webkit-mask-image: url("/images/icon-moon.svg"); mask-image: url("/images/icon-moon.svg"); display: block; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }

/* ---------- hero / home ---------- */
#content { padding-top: 2.5rem; padding-bottom: 4rem; min-height: 60vh; }
.hero { text-align: center; padding: 2rem 0 3rem; }
.hero .avatar {
  width: 88px; height: 88px; border-radius: 50%; object-fit: cover;
  box-shadow: var(--shadow); margin-bottom: 1rem;
}
.hero h1 { margin: 0 0 .3rem; font-size: 1.7rem; }
.hero .tagline { color: var(--fg-muted); margin: 0; }
.hero-links { display: flex; flex-wrap: wrap; justify-content: center; gap: .6rem; margin-top: 1.4rem; }
.hero-link {
  display: inline-block; text-decoration: none; color: var(--fg);
  border: 1px solid var(--border); border-radius: 999px; padding: .45rem 1.1rem;
  font-size: .88rem; background: var(--bg-elevated);
  transition: border-color .15s ease, color .15s ease;
}
.hero-link:hover { border-color: var(--accent); color: var(--accent); }
.hero-link { display: inline-flex; align-items: center; gap: .45rem; }

/* Monochrome icons via mask instead of <img>, so they inherit currentColor -
   matching text color in both themes and on hover, with one asset each. */
.hero-link-icon {
  display: inline-block; width: 1rem; height: 1rem; flex: none;
  background-color: currentColor;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-size: contain; mask-size: contain;
}
.icon-github { -webkit-mask-image: url("/images/icon-github.svg"); mask-image: url("/images/icon-github.svg"); }
.icon-youtube { -webkit-mask-image: url("/images/icon-youtube.svg"); mask-image: url("/images/icon-youtube.svg"); }
.icon-x { -webkit-mask-image: url("/images/icon-x.svg"); mask-image: url("/images/icon-x.svg"); }
.icon-linkedin { -webkit-mask-image: url("/images/icon-linkedin.svg"); mask-image: url("/images/icon-linkedin.svg"); }

/* Same mask trick, sized in em so it scales with surrounding text - for
   icon+link lines inside post bodies (e.g. the {{< icon >}} shortcode). */
.icon-inline {
  display: inline-block; width: 1em; height: 1em; flex: none;
  background-color: currentColor;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-size: contain; mask-size: contain;
  vertical-align: -0.15em; margin-right: .35em;
}
.list-header h1, .tags-index h1 { font-size: 1.25rem; margin-bottom: 1.2rem; }

.category-group { margin-bottom: 2.4rem; }
.category-group:last-child { margin-bottom: 0; }
.category-heading {
  font-size: 1.02rem; font-weight: 600; margin: 0 0 1rem;
  padding-bottom: .5rem; border-bottom: 1px solid var(--border);
  color: var(--fg-muted);
}

/* ---------- cards ---------- */
.card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.1rem; }
.card {
  display: block; text-decoration: none; color: inherit;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card-cover { position: relative; aspect-ratio: 16/9; overflow: hidden; background: var(--border); }
.card-cover img { width: 100%; height: 100%; object-fit: cover; border-radius: 0; display: block; }
.card-cover img.card-badge {
  position: absolute; top: .5rem; left: .5rem; z-index: 1;
  width: 3.0rem; height: 3.0rem; padding: .1rem; box-sizing: border-box;
  background: #fff; border-radius: 50%;
  box-shadow: 2px 2px 6px rgba(0, 0, 0, .45), 0 1px 2px rgba(0, 0, 0, .25);
  object-fit: contain;
}
.card-body { padding: 1rem 1.1rem 1.2rem; }
.card-body h3 { margin: 0 0 .3rem; font-size: 1.02rem; }
.card-date { color: var(--fg-muted); font-size: .78rem; }
.card-desc { color: var(--fg-muted); font-size: .88rem; margin: .5rem 0 0; }
.card-tags { margin-top: .6rem; display: flex; flex-wrap: wrap; gap: .35rem; }

.tag-pill {
  display: inline-block; font-size: .74rem; padding: .18rem .55rem;
  border-radius: 999px; background: var(--border); color: var(--fg-muted);
  text-decoration: none;
}
.tag-pill:hover { color: var(--fg); }
.tag-pill-lg { font-size: .9rem; padding: .4rem .8rem; margin: .3rem .3rem 0 0; }
.tag-count { opacity: .6; }
.tag-cloud { display: flex; flex-wrap: wrap; }

.empty { color: var(--fg-muted); }

/* -- wide, one-per-row layout (posts list): cover left, content right -- */
.card-grid--list { grid-template-columns: 1fr; gap: 1rem; }
.card-grid--list .card { display: flex; flex-direction: row; align-items: center; }
.card-grid--list .card-cover { width: 16rem; flex: none; aspect-ratio: 16/9; }
.card-grid--list .card-body {
  flex: 1; min-width: 0; padding: 1.2rem 1.4rem;
  display: flex; flex-direction: column; justify-content: center;
}
.card-grid--list .card-body h3 { font-size: 1.15rem; }
.card-grid--list .card-desc {
  font-size: .92rem; margin-top: .4rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
@media (max-width: 640px) {
  .card-grid--list .card { flex-direction: column; }
  .card-grid--list .card-cover { width: 100%; }
}

/* ---------- article ---------- */
.post-header h1 { font-size: 1.9rem; margin-bottom: .5rem; line-height: 1.25; }
.post-meta { color: var(--fg-muted); font-size: .88rem; display: flex; gap: .8rem; align-items: center; }
.status-pill { text-transform: capitalize; background: var(--border); border-radius: 999px; padding: .1rem .6rem; }
.post-tags { margin: .8rem 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.post-cover { margin: 1.5rem 0; }
.post-cover img { width: 100%; }
.repo-link { color: var(--accent); }

.toc {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.3rem; margin: 1.5rem 0; background: var(--bg-elevated); font-size: .9rem;
}
.toc-title { margin: 0 0 .4rem; font-weight: 600; color: var(--fg-muted); text-transform: uppercase; font-size: .74rem; letter-spacing: .04em; }
.toc ul { margin: 0; padding-left: 1.1rem; }
.toc a { text-decoration: none; color: var(--fg-muted); }
.toc a:hover { color: var(--accent); }

/* ---------- series ---------- */
.series-nav {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.3rem; margin: 1.2rem 0; background: var(--bg-elevated); font-size: .88rem;
}
.series-nav-title { margin: 0 0 .5rem; font-weight: 600; }
.series-nav-title a { text-decoration: none; color: var(--fg); }
.series-nav-title a:hover { color: var(--accent); }
.series-nav ol { margin: 0; padding-left: 1.2rem; color: var(--fg-muted); }
.series-nav li { margin: .15rem 0; }
.series-nav li.current { font-weight: 600; color: var(--fg); }
.series-nav a { color: var(--fg-muted); text-decoration: none; }
.series-nav a:hover { color: var(--accent); }

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

.series-adjacent {
  display: flex; justify-content: space-between; gap: 1rem;
  margin-top: 2.2rem; padding-top: 1.2rem; border-top: 1px solid var(--border);
  font-size: .9rem;
}
.series-adjacent a { text-decoration: none; color: var(--fg); max-width: 48%; }
.series-adjacent a:hover .label, .series-adjacent a:hover { color: var(--accent); }
.series-adjacent .label {
  display: block; font-size: .74rem; text-transform: uppercase;
  letter-spacing: .04em; color: var(--fg-muted); margin-bottom: .2rem;
}

.post-body { margin-top: 1.8rem; }
.post-body h1, .post-body h2, .post-body h3 {
  font-weight: 700; letter-spacing: -.01em; scroll-margin-top: 1.5rem;
}
.post-body h1 { font-size: 1.55rem; margin-top: 2.6rem; padding-bottom: .6rem; border-bottom: 1px solid var(--border); }
.post-body h2 { font-size: 1.3rem; margin-top: 2.2rem; }
.post-body h3 { font-size: 1.08rem; margin-top: 1.8rem; }
.post-body .heading-anchor {
  margin-left: .5rem; font-size: .78em; font-weight: 400; color: var(--accent);
  text-decoration: none; opacity: 0; transition: opacity .12s ease;
}
.post-body h1:hover .heading-anchor,
.post-body h2:hover .heading-anchor,
.post-body h3:hover .heading-anchor { opacity: 1; }
.post-body p { margin: 1em 0; }
.post-body ul, .post-body ol { margin: 1em 0; padding-left: 1.4rem; }
.post-body li { margin: .35rem 0; }
.post-body li::marker { color: var(--accent); }
.post-body li > ul, .post-body li > ol { margin: .35rem 0; }
.post-body blockquote {
  margin: 1.2em 0; padding: .6rem 1.1rem; border-left: 3px solid var(--accent);
  color: var(--fg-muted); background: var(--bg-elevated); border-radius: 0 6px 6px 0;
  font-style: italic;
}
.post-body blockquote p { margin: .4em 0; }
.post-body code {
  font-family: var(--font-mono); font-size: .87em;
  background: var(--border); padding: .12em .38em; border-radius: 4px;
}
.post-body .highlight { background: none; margin: 1.2em 0; }
.post-body pre {
  background: var(--code-bg); color: var(--code-fg); border-radius: var(--radius);
  padding: 1rem 1.2rem; overflow-x: auto; font-size: .85rem; line-height: 1.55;
  margin: 0; font-family: var(--font-mono);
}
.post-body pre code { background: none; padding: 0; color: inherit; }
.post-body .mermaid {
  background: var(--code-bg); border-radius: var(--radius);
  padding: 1.2rem; margin: 1.2em 0; overflow-x: auto; text-align: center;
}
.post-body .mermaid svg { max-width: 100%; }
.post-body table {
  border-collapse: collapse; width: 100%; margin: 1.2em 0; font-size: .92rem;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.post-body th, .post-body td { border-bottom: 1px solid var(--border); padding: .55rem .8rem; text-align: left; }
.post-body th {
  background: var(--bg-elevated); font-weight: 600; font-size: .82rem;
  text-transform: uppercase; letter-spacing: .03em; color: var(--fg-muted);
}
.post-body tbody tr:nth-child(even) { background: color-mix(in srgb, var(--border) 35%, transparent); }
.post-body tbody tr:last-child td { border-bottom: none; }
.post-body img { display: block; margin: 1.2em auto; }
.post-body a { color: var(--accent); }
.post-body hr { border: none; border-top: 1px solid var(--border); margin: 2.2em 0; }
.post-body ::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--fg); }

.post-body .md-figure { margin: 1.4em auto; text-align: center; }
.post-body .md-figure img { display: block; margin: 0 auto; }
.post-body .md-figure figcaption { margin-top: .5rem; font-size: .82rem; color: var(--fg-muted); }

.post-body .embed-responsive {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  margin: 1.4em 0; border-radius: var(--radius); overflow: hidden; background: #000;
}
.post-body .embed-responsive iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.post-body details {
  margin: 1.2em 0; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0 1.1rem; background: var(--bg-elevated);
}
.post-body details summary {
  cursor: pointer; font-weight: 600; padding: .8rem 0; list-style: revert;
}
.post-body details[open] summary { border-bottom: 1px solid var(--border); margin-bottom: .8rem; }
.post-body details > *:last-child { margin-bottom: 1rem; }
.post-body .md-tabs details.md-tab { margin: .7rem 0; }

/* ---------- shader embeds ---------- */
.shader-embed, .mesh-shader-embed {
  margin: 1.6em 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
  box-shadow: var(--shadow);
}
.shader-embed canvas, .mesh-shader-embed canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 0;
  touch-action: none;
}
.shader-canvas-wrap { position: relative; }
.shader-canvas-wrap:fullscreen {
  background: #000;
  display: flex; align-items: center; justify-content: center;
}
.shader-canvas-wrap:fullscreen canvas { width: 100%; height: 100%; aspect-ratio: auto; }

.shader-toolbar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; flex-wrap: wrap; align-items: center; gap: .35rem;
  padding: .35rem .5rem;
  background: linear-gradient(to top, rgba(0,0,0,.72), rgba(0,0,0,0));
}
.shader-btn {
  background: rgba(255,255,255,.14); border: none; color: #fff;
  min-width: 1.7rem; height: 1.7rem; border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: .82rem; line-height: 1; padding: 0 .4rem;
}
.shader-btn:hover { background: rgba(255,255,255,.28); }
.shader-btn:active { background: rgba(255,255,255,.36); }
.shader-btn-toggle.shader-btn-active { background: var(--accent); color: var(--accent-fg); }
.shader-time {
  margin-left: auto;
  color: rgba(255,255,255,.85);
  font-family: var(--font-mono);
  font-size: .7rem;
  letter-spacing: .02em;
  user-select: none;
}

/* -- mesh-embed parameter / code panels -- */
.shader-panel {
  border-top: 1px solid #232323;
  background: #111214;
  padding: .8rem .9rem;
}
.shader-panel-empty { margin: 0; color: rgba(255,255,255,.5); font-size: .82rem; }

.shader-param-row {
  display: flex; align-items: center; gap: .6rem;
  padding: .32rem 0; font-size: .82rem; color: rgba(255,255,255,.85);
}
.shader-param-name {
  font-family: var(--font-mono); width: 8rem; flex: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.shader-param-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.shader-param-value {
  font-family: var(--font-mono); width: 3.4rem; text-align: right; flex: none;
  color: rgba(255,255,255,.6);
}
.shader-param-row input[type="color"] {
  width: 2rem; height: 1.4rem; border: none; background: none; padding: 0; cursor: pointer;
}
.shader-param-row input[type="checkbox"] { accent-color: var(--accent); width: 1rem; height: 1rem; }

.shader-editor {
  display: block; width: 100%; min-height: 14rem; resize: vertical;
  background: #0d0d0d; color: #d4d4d4; border: 1px solid #2a2a2a; border-radius: 6px;
  font-family: var(--font-mono); font-size: .8rem; line-height: 1.5;
  padding: .7rem .8rem; tab-size: 2; white-space: pre; overflow: auto;
}
.shader-editor-row { display: flex; justify-content: flex-end; margin-top: .5rem; }
.shader-run-btn {
  background: var(--accent); color: var(--accent-fg); border: none;
  padding: .4rem .9rem; border-radius: 6px; font-size: .8rem; cursor: pointer; font-weight: 600;
}
.shader-run-btn:hover { filter: brightness(1.08); }
.shader-editor-error {
  margin: .6rem 0 0; padding: .6rem .8rem;
  background: #1a0000; color: #ff8a80; border-radius: 6px;
  font-family: var(--font-mono); font-size: .78rem; white-space: pre-wrap;
}

.shader-caption {
  margin: 0;
  padding: .55rem .9rem;
  font-size: .8rem;
  color: var(--fg-muted);
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}
.shader-error {
  color: #ff8a80;
  background: #1a0000;
  padding: 1rem 1.1rem;
  font-family: var(--font-mono);
  font-size: .8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  margin: 0;
}

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--border); margin-top: 3rem; }
.footer-inner {
  padding: 1.6rem 1.5rem; display: flex; justify-content: space-between; flex-wrap: wrap; gap: .8rem;
  color: var(--fg-muted); font-size: .85rem;
}
.footer-social { display: flex; gap: 1rem; }
.footer-social a { text-decoration: none; }
.footer-social a:hover { color: var(--fg); }

@media (max-width: 640px) {
  .header-inner { flex-wrap: wrap; }
  .main-nav { order: 3; width: 100%; }
  .card-grid:not(.card-grid--list) { grid-template-columns: 1fr; }
}
@media (min-width: 641px) and (max-width: 900px) {
  .card-grid:not(.card-grid--list) { grid-template-columns: repeat(2, 1fr); }
}
