/* 네트워크 한 입에 — Korean networking primer styles */

:root {
  --bg: #fafaf7;
  --bg-elevated: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --border: #e5e5e0;
  --code-bg: #f4f4f0;
  --highlight: #fef3c7;
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.08);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.08);
  --max-width: 1100px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f10;
    --bg-elevated: #1a1a1c;
    --text: #e8e8e6;
    --text-muted: #a0a0a0;
    --accent: #60a5fa;
    --accent-soft: #1e2c4a;
    --border: #2a2a2c;
    --code-bg: #18181a;
    --highlight: #422f12;
    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, 0.10);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.12);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

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

a { color: var(--accent); }

/* ── Site header ─────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.7rem 1.25rem;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-header .brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.site-header nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}
.site-header nav a {
  text-decoration: none;
  color: var(--text-muted);
  padding: 0.3rem 0.55rem;
  border-radius: 0.4rem;
  font-size: 0.85rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.site-header nav a:hover {
  color: var(--accent);
  background: var(--accent-soft);
}
.site-header nav a.current {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}

/* ── Layout ──────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 2.5rem;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

.toc {
  position: sticky;
  top: 4.5rem;
  align-self: start;
  font-size: 0.85rem;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
}
.toc h3 {
  margin: 0 0 0.5rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.toc ol {
  list-style: none;
  padding: 0;
  margin: 0;
}
.toc li { margin: 0; }
.toc a {
  color: var(--text-muted);
  text-decoration: none;
  display: block;
  padding: 0.3rem 0.6rem;
  border-left: 2px solid var(--border);
  line-height: 1.4;
}
.toc a:hover {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
}

/* ── Article ─────────────────────────────────────── */
article { min-width: 0; }

article h1 {
  font-size: 2.1rem;
  margin: 0 0 2rem;
  letter-spacing: -0.025em;
  line-height: 1.25;
}
article h1 .num {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 0.5rem;
}

article h2 {
  margin-top: 3.5rem;
  margin-bottom: 1rem;
  font-size: 1.45rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  letter-spacing: -0.015em;
  scroll-margin-top: 4rem;
  line-height: 1.3;
}

article h3 {
  margin-top: 2rem;
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
  scroll-margin-top: 4rem;
  letter-spacing: -0.01em;
}

article p,
article ul,
article ol {
  margin: 1rem 0;
}

article ul,
article ol {
  padding-left: 1.4rem;
}
article li { margin: 0.3rem 0; }

article strong { font-weight: 700; color: var(--text); }
article em { font-style: italic; }

article code {
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.12em 0.4em;
  border-radius: 0.3em;
  border: 1px solid var(--border);
}

article pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 0.5em;
  padding: 1em 1.2em;
  overflow-x: auto;
  font-size: 0.85em;
  line-height: 1.6;
  margin: 1.5em 0;
}
article pre code {
  background: none;
  padding: 0;
  border: none;
  font-size: inherit;
}

article blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.5em 0;
  padding: 0.75em 1.2em;
  background: var(--accent-soft);
  border-radius: 0 0.4em 0.4em 0;
  color: var(--text);
}

/* Callouts */
article .callout {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  padding: 0.9em 1.2em;
  margin: 1.5em 0;
  border-radius: 0 0.4em 0.4em 0;
}
article .callout .label {
  font-weight: 700;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  display: block;
  margin-bottom: 0.35rem;
}
article .callout p:first-of-type { margin-top: 0; }
article .callout p:last-of-type { margin-bottom: 0; }
article .callout.warn {
  border-left-color: var(--danger);
  background: var(--danger-soft);
}
article .callout.warn .label { color: var(--danger); }
article .callout.tip {
  border-left-color: var(--success);
  background: var(--success-soft);
}
article .callout.tip .label { color: var(--success); }

/* Tables */
article table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.75em 0;
  font-size: 0.92em;
}
article th,
article td {
  padding: 0.55em 0.85em;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
article th {
  background: var(--code-bg);
  font-weight: 600;
}
article tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--code-bg) 50%, transparent);
}

/* ASCII diagrams */
article .ascii-diagram {
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  white-space: pre;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 0.5em;
  padding: 1.1em 1.2em;
  overflow-x: auto;
  font-size: 0.78em;
  line-height: 1.45;
  margin: 1.75em 0;
  color: var(--text);
}

article figure {
  margin: 1.5em 0;
  text-align: center;
}
article figcaption {
  font-size: 0.85em;
  color: var(--text-muted);
  margin-top: 0.5em;
}

/* Chapter prev/next */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin: 4rem 0 0;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
  flex-wrap: wrap;
}
.chapter-nav a {
  text-decoration: none;
  color: var(--text);
  padding: 1rem 1.2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  flex: 1;
  min-width: 0;
  max-width: 320px;
  transition: border-color 0.15s, transform 0.15s;
}
.chapter-nav a:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.chapter-nav a.next {
  text-align: right;
  margin-left: auto;
}
.chapter-nav .label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.chapter-nav .title {
  display: block;
  font-weight: 600;
  margin-top: 0.35rem;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

/* ── Index page ──────────────────────────────────── */
.hero {
  text-align: center;
  padding: 4rem 1.5rem 3rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}
.hero h1 {
  font-size: 2.8rem;
  margin: 0 0 0.6rem;
  letter-spacing: -0.035em;
  line-height: 1.15;
}
.hero p {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin: 0 auto;
  max-width: 580px;
}
.hero .meta {
  margin-top: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}
.chapter-card {
  text-decoration: none;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  padding: 1.5rem 1.6rem 1.6rem;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chapter-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 8px 24px -16px color-mix(in srgb, var(--accent) 60%, transparent);
}
.chapter-card .num {
  font-size: 0.7rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
}
.chapter-card h2 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: -0.015em;
  line-height: 1.3;
}
.chapter-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.55;
}
.chapter-card .tags {
  margin-top: 0.6rem;
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}
.chapter-card .tags span {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  background: var(--code-bg);
  border-radius: 99px;
  color: var(--text-muted);
}

footer.site-footer {
  text-align: center;
  padding: 2rem 1rem 3rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* ── Mobile ──────────────────────────────────────── */
@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 1.5rem 1rem 3rem;
  }
  .toc {
    position: static;
    max-height: none;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
  }
  .site-header {
    flex-wrap: wrap;
    padding: 0.6rem 0.9rem;
  }
  .site-header nav { font-size: 0.8rem; }
  .hero h1 { font-size: 2rem; }
  article h1 { font-size: 1.7rem; }
  article h2 { font-size: 1.25rem; }
}

/* Print */
@media print {
  .site-header,
  .toc,
  .chapter-nav,
  footer.site-footer { display: none; }
  .layout { grid-template-columns: 1fr; padding: 0; }
}
