:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f5;
  --surface: #ffffff;
  --text: #1f1e1d;
  --text-muted: #6b6a66;
  --text-faint: #9b9a96;
  --border: #e8e7e3;
  --accent: #2f6fde;
  --accent-soft: #eaf1fd;
  --code-bg: #f1f0ec;
  --code-text: #c4432b;
  --figure-bg: #ffffff;
  --topbar-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #191918;
    --bg-soft: #202020;
    --surface: #222221;
    --text: #e9e8e4;
    --text-muted: #a3a29e;
    --text-faint: #75746f;
    --border: #2f2f2d;
    --accent: #6ea1f5;
    --accent-soft: #1f2a3d;
    --code-bg: #2a2a28;
    --code-text: #f08a72;
    --figure-bg: #fbfbfa;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #191918;
  --bg-soft: #202020;
  --surface: #222221;
  --text: #e9e8e4;
  --text-muted: #a3a29e;
  --text-faint: #75746f;
  --border: #2f2f2d;
  --accent: #6ea1f5;
  --accent-soft: #1f2a3d;
  --code-bg: #2a2a28;
  --code-text: #f08a72;
  --figure-bg: #fbfbfa;
  color-scheme: dark;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 16px);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 16px;
  line-height: 1.75;
  word-break: keep-all;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
img { max-width: 100%; height: auto; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.12em 0.4em;
  border-radius: 4px;
  word-break: break-all;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1120px;
  height: 100%;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand { font-weight: 700; text-decoration: none; font-size: 17px; }
.topnav { display: flex; gap: 20px; margin-left: auto; }
.topnav a {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
}
.topnav a:hover { color: var(--text); }

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text); background: var(--bg-soft); }
.theme-toggle svg {
  width: 17px; height: 17px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; }
}

/* ---------- Layout ---------- */
.layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 220px minmax(0, 760px);
  gap: 56px;
  justify-content: center;
}

.toc {
  position: sticky;
  top: calc(var(--topbar-h) + 32px);
  align-self: start;
  max-height: calc(100vh - var(--topbar-h) - 64px);
  overflow-y: auto;
  padding-top: 48px;
  font-size: 13.5px;
}
.toc-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc ol ol { margin: 4px 0 6px; padding-left: 12px; border-left: 1px solid var(--border); }
.toc li { margin: 2px 0; }
.toc a {
  display: block;
  padding: 3px 8px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-muted);
  line-height: 1.45;
}
.toc a:hover { color: var(--text); background: var(--bg-soft); }
.toc a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.content { min-width: 0; padding-bottom: 64px; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 760px); }
  .toc { display: none; }
}
@media (max-width: 520px) {
  .topnav { gap: 14px; }
  .topnav a { font-size: 13px; }
  .brand { display: none; }
  .topnav { margin-left: 0; }
  .theme-toggle { margin-left: auto; }
}

/* ---------- Sections ---------- */
.section { padding-top: 56px; }
.section-title {
  margin: 0 0 8px;
  font-size: 28px;
  letter-spacing: -0.01em;
}
.sub { font-size: 18px; margin: 32px 0 12px; }

.intro-heading { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.intro h1 { margin: 0; font-size: 36px; line-height: 1.3; }
.intro-role { margin: 0; font-size: 13px; font-weight: 600; color: var(--accent); }
.intro-lead { margin: 20px 0 24px; font-size: 19px; line-height: 1.7; }
caption { text-align: left; color: var(--text-muted); padding-bottom: 8px; font-size: 13px; }

.project {
  padding: 40px 0 48px;
  border-bottom: 1px solid var(--border);
}
.project:last-child { border-bottom: 0; }
.project-num {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}
.project h3 {
  margin: 0;
  font-size: clamp(22px, 4vw, 26px);
  line-height: 1.35;
  letter-spacing: -0.01em;
}
.project h3 .org { font-weight: 500; color: var(--text-muted); font-size: 0.75em; }

.facts { margin: 18px 0 14px; display: grid; gap: 4px; font-size: 15px; }
.facts div { display: grid; grid-template-columns: 80px 1fr; gap: 12px; }
.facts dt { color: var(--text-faint); }
.facts dd { margin: 0; }

.stack { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.stack li {
  font-size: 12.5px;
  font-weight: 500;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.project h4 {
  margin: 36px 0 10px;
  font-size: 17px;
  line-height: 1.5;
}
.project ul { padding-left: 1.25em; margin: 0; }
.project li { margin: 4px 0; }
.project li::marker { color: var(--text-faint); }



/* ---------- Problem-solving case ---------- */
.case {
  margin-top: 36px;
  padding: 24px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.case h4 { margin: 0 0 16px; }
.case-no {
  display: inline-block;
  margin-right: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  vertical-align: 1px;
}
@media (max-width: 520px) {
  .case { padding: 18px 16px; margin-left: -4px; margin-right: -4px; }
  .case-no { display: block; margin-bottom: 2px; }
}

.steps { margin: 0; }
.steps dt {
  margin-top: 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}
.steps dt:first-child { margin-top: 0; }
.steps dd { margin: 2px 0 0; }

figure { margin: 20px 0; }
figure img {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--figure-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: zoom-in;
}
.case > figure:first-of-type { margin-top: 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 16px 0 4px; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
  background: var(--surface);
  border: 1px solid var(--border);
}
th, td {
  padding: 9px 12px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  line-height: 1.55;
}
thead th { background: var(--bg-soft); font-weight: 600; color: var(--text-muted); }
.metrics tbody th { white-space: nowrap; font-weight: 400; }
.metrics tbody th.group { vertical-align: middle; text-align: center; background: var(--bg-soft); color: var(--text-muted); font-weight: 600; }

.retro li { margin: 6px 0; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 14px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.tl-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 16px; }
.tl-head .date { color: var(--text-faint); font-size: 14px; font-variant-numeric: tabular-nums; }
.timeline p { margin: 4px 0 0; color: var(--text-muted); }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 15, 14, 0.82);
  cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: min(1400px, 100%);
  max-height: 100%;
  width: auto;
  background: #fff;
  border-radius: 10px;
  padding: 16px;
}
.lightbox-close {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

/* ---------- Print ---------- */
@media print {
  .topbar, .toc, .lightbox, .theme-toggle { display: none !important; }
  .layout { display: block; max-width: none; padding: 0; }
  body { font-size: 11pt; background: #fff; color: #000; }
  .case { break-inside: avoid-page; background: none; }
  figure { break-inside: avoid; }
  a { text-decoration: none; }
}
