/* === Engineering a Compiler — 한국어판 === */

:root {
  --bg: #fafafa;
  --bg-elev: #ffffff;
  --bg-code: #f4f4f7;
  --text: #1f1f23;
  --text-muted: #6b6b76;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --border: #e4e4ec;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
  --code-keyword: #b45309;
  --code-string: #047857;
  --code-comment: #6b6b76;
  --warn-bg: #fef3c7;
  --warn-border: #fbbf24;
  --note-bg: #ecfdf5;
  --note-border: #34d399;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --bg-elev: #1e1f25;
    --bg-code: #1a1b20;
    --text: #e9e9f1;
    --text-muted: #9b9bab;
    --accent: #818cf8;
    --accent-soft: #2a2745;
    --border: #2c2d36;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.25);
    --code-keyword: #fbbf24;
    --code-string: #6ee7b7;
    --code-comment: #8b8b9b;
    --warn-bg: #3a2c08;
    --warn-border: #b45309;
    --note-bg: #0d2f24;
    --note-border: #047857;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

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

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static !important; height: auto !important; border-right: none !important; border-bottom: 1px solid var(--border); }
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
}

.sidebar h1 {
  font-size: 1.1rem;
  margin: 0 0 0.25rem 0;
  letter-spacing: -0.02em;
}

.sidebar .subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.sidebar nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar nav li {
  margin: 0.15rem 0;
}

.sidebar nav a {
  display: block;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.9rem;
  transition: background 0.12s ease, color 0.12s ease;
}

.sidebar nav a:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sidebar .nav-section {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 1.25rem 0 0.5rem 0.75rem;
  font-weight: 600;
}

.content {
  padding: 3rem 4rem;
  max-width: 880px;
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 700px) {
  .content { padding: 2rem 1.25rem; }
}

.content h1 {
  font-size: 2.2rem;
  letter-spacing: -0.025em;
  margin: 0 0 0.5rem;
  line-height: 1.25;
}

.content h2 {
  font-size: 1.6rem;
  margin: 3rem 0 1rem;
  letter-spacing: -0.02em;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.content h3 {
  font-size: 1.25rem;
  margin: 2rem 0 0.75rem;
  letter-spacing: -0.015em;
}

.content h4 {
  font-size: 1.05rem;
  margin: 1.5rem 0 0.5rem;
  color: var(--text-muted);
  font-weight: 600;
}

.content p {
  margin: 0.75rem 0;
}

.content a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dashed var(--accent);
}

.content a:hover { border-bottom-style: solid; }

.content ul, .content ol {
  padding-left: 1.5rem;
}

.content li { margin: 0.35rem 0; }

.lead {
  font-size: 1.15rem;
  color: var(--text-muted);
  margin: 0.5rem 0 2rem;
}

.chapter-meta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
  padding: 0.75rem 1rem;
  background: var(--bg-elev);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.chapter-meta strong { color: var(--text); }

code {
  font-family: "SF Mono", Menlo, Monaco, "Cascadia Code", monospace;
  font-size: 0.9em;
  background: var(--bg-code);
  padding: 0.12em 0.4em;
  border-radius: 4px;
  border: 1px solid var(--border);
}

pre {
  background: var(--bg-code);
  padding: 1rem 1.25rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.55;
}

pre code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: inherit;
}

.kw  { color: var(--code-keyword); font-weight: 600; }
.str { color: var(--code-string); }
.cm  { color: var(--code-comment); font-style: italic; }

.callout {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
}

.callout.note {
  border-left-color: var(--note-border);
  background: var(--note-bg);
}

.callout.warn {
  border-left-color: var(--warn-border);
  background: var(--warn-bg);
}

.callout-title {
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.term-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  font-size: 0.92rem;
}

.term-box .term {
  font-weight: 700;
  color: var(--accent);
}

.term-box .en {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--bg-elev);
  font-weight: 600;
}

.figure {
  margin: 1.5rem 0;
  text-align: center;
}

.figure pre, .figure .ascii {
  display: inline-block;
  text-align: left;
}

.figure-caption {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin: 4rem 0 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
}

.chapter-nav a {
  flex: 1;
  padding: 1rem 1.25rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text) !important;
  border-bottom: 1px solid var(--border) !important;
  transition: border-color 0.15s, transform 0.15s;
}

.chapter-nav a:hover {
  border-color: var(--accent) !important;
  transform: translateY(-2px);
}

.chapter-nav .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
  margin-bottom: 0.25rem;
}

.chapter-nav .next-link { text-align: right; }

/* === Index page hero === */
.hero {
  padding: 4rem 4rem 2rem;
  max-width: 1100px;
  margin: 0 auto;
}
@media (max-width: 700px) { .hero { padding: 2rem 1.25rem; } }

.hero h1 {
  font-size: 3rem;
  margin: 0;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.hero .tagline {
  font-size: 1.2rem;
  color: var(--text-muted);
  margin: 0.5rem 0 0.25rem;
}

.hero .author {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 2rem;
}

.toc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  padding: 0 4rem 4rem;
  max-width: 1100px;
  margin: 0 auto;
}
@media (max-width: 700px) { .toc-grid { padding: 0 1.25rem 3rem; } }

.toc-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.4rem;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  display: block;
}

.toc-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.toc-card .num {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
}

.toc-card .title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0.25rem 0 0.5rem;
  letter-spacing: -0.015em;
}

.toc-card .summary {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.toc-card.section-divider {
  background: transparent;
  border: none;
  padding: 1rem 0 0;
  grid-column: 1 / -1;
}

.toc-card.section-divider:hover {
  transform: none;
  box-shadow: none;
}

.toc-card.section-divider .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
}

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