:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-alt: #f4f1ea;
  --ink: #18181b;
  --ink-muted: #52525b;
  --ink-subtle: #71717a;
  --border: #e4e0d8;
  --grid-line: rgba(24, 24, 27, 0.08);
  --accent: #c2410c;
  --accent-soft: #fff7ed;
  --teal: #0f766e;
  --teal-soft: #f0fdfa;
  --indigo: #3730a3;
  --indigo-soft: #eef2ff;
  --radius: 12px;
  --font-sans: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-serif: 'Noto Serif KR', Georgia, serif;
  --font-mono: 'JetBrains Mono', monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #141413;
  --surface: #1c1c1a;
  --surface-alt: #252420;
  --ink: #ecebe6;
  --ink-muted: #a8a69e;
  --ink-subtle: #828078;
  --border: #33312b;
  --grid-line: rgba(236, 235, 230, 0.09);
  --accent: #fb923c;
  --accent-soft: rgba(251, 146, 60, 0.14);
  --teal: #2dd4bf;
  --teal-soft: rgba(45, 212, 191, 0.12);
  --indigo: #a5b4fc;
  --indigo-soft: rgba(165, 180, 252, 0.12);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 84px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  line-height: 1.88;
  font-size: 16.5px;
  word-break: keep-all;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

/* Progress Bar & Header */
#progress-bar {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--teal));
  z-index: 1000;
  transition: width 0.08s linear;
}
header {
  position: sticky;
  top: 0;
  z-index: 900;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.brand {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  white-space: nowrap;
}
.brand-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}
header nav {
  display: flex;
  align-items: center;
  gap: 1.35rem;
  font-size: 0.86rem;
  font-weight: 500;
}
header nav > a {
  color: var(--ink-muted);
  text-decoration: none;
  transition: color 0.15s;
}
header nav > a:hover { color: var(--accent); }
.theme-btn {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  padding: 0.32rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.theme-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Hero Section */
.hero {
  max-width: 1180px;
  margin: 0 auto;
  padding: 4rem 2rem 3rem;
  border-bottom: 1px solid var(--border);
}
.eyebrow {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.28rem 0.72rem;
  border-radius: 999px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 1rem;
}
.hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 4vw, 3.1rem);
  line-height: 1.24;
  letter-spacing: -0.025em;
  margin: 0 0 1.25rem;
  font-weight: 700;
  max-width: 900px;
}
.hero h1 span {
  display: block;
  font-family: var(--font-sans);
  font-size: clamp(1.12rem, 2.1vw, 1.48rem);
  color: var(--ink-muted);
  font-weight: 500;
  margin-top: 0.5rem;
  letter-spacing: -0.015em;
}
.hero-desc {
  max-width: 780px;
  color: var(--ink-muted);
  font-size: 1.06rem;
  line-height: 1.82;
  margin: 0 0 1.6rem;
}
.meta-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 2rem;
}
.meta-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.3rem 0.78rem;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--ink-muted);
}
.hero-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 0.9rem;
  max-width: 960px;
}
.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  text-decoration: none;
  color: var(--ink);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.hero-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.05);
}
.hero-card small {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 0.3rem;
}
.hero-card b {
  font-size: 0.94rem;
  line-height: 1.4;
  display: block;
}

/* Layout Grid */
.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2.75rem 2rem 6rem;
  display: grid;
  grid-template-columns: 250px minmax(0, 760px);
  gap: 3.5rem;
  align-items: start;
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; gap: 2rem; }
  aside { position: static !important; }
}

/* Sidebar TOC */
aside {
  position: sticky;
  top: 4.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  font-size: 0.84rem;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
}
.toc-title {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--ink-subtle);
  margin: 0 0 0.75rem;
}
.toc-group {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--teal);
  letter-spacing: 0.04em;
  margin: 1rem 0 0.35rem;
}
aside a {
  display: block;
  color: var(--ink-muted);
  text-decoration: none;
  padding: 0.32rem 0.55rem;
  border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
  line-height: 1.45;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
aside a:hover {
  background: var(--surface-alt);
  color: var(--ink);
}
aside a.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* Main Essay Content */
main { min-width: 0; }
.lead-para {
  font-size: 1.12rem;
  line-height: 1.9;
  color: var(--ink);
  font-weight: 500;
  padding-bottom: 1.5rem;
  margin-bottom: 1.75rem;
  border-bottom: 1px solid var(--border);
}
.part-label {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--teal);
  background: var(--teal-soft);
  border: 1px solid color-mix(in srgb, var(--teal) 22%, transparent);
  display: inline-block;
  padding: 0.25rem 0.72rem;
  border-radius: 6px;
  margin-top: 3.5rem;
  margin-bottom: 0.55rem;
  text-transform: uppercase;
}
h2 {
  font-family: var(--font-serif);
  font-size: 1.65rem;
  margin: 0.35rem 0 1.25rem;
  line-height: 1.38;
  letter-spacing: -0.02em;
  scroll-margin-top: 5.2rem;
}
h3 {
  font-size: 1.14rem;
  font-weight: 700;
  margin: 2rem 0 0.7rem;
  line-height: 1.45;
  letter-spacing: -0.01em;
}
p { margin: 0 0 1.25rem; }
ul, ol {
  margin: 0 0 1.4rem;
  padding-left: 1.35rem;
}
li { margin-bottom: 0.55rem; }
code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--surface-alt);
  padding: 0.12rem 0.38rem;
  border-radius: 5px;
  border: 1px solid var(--border);
}
blockquote {
  margin: 1.75rem 0;
  padding: 1.15rem 1.4rem;
  background: var(--surface-alt);
  border-left: 4px solid var(--accent);
  border-radius: 0 10px 10px 0;
  color: var(--ink);
  font-size: 0.98rem;
  line-height: 1.8;
}
blockquote cite {
  display: block;
  margin-top: 0.55rem;
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 0.77rem;
  color: var(--ink-subtle);
}
.callout {
  margin: 1.75rem 0;
  padding: 1.15rem 1.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--teal);
  border-radius: 10px;
  font-size: 0.94rem;
  line-height: 1.78;
}
.callout-title {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--teal);
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
  text-transform: uppercase;
}

/* Glossary Term Links */
.term {
  border-bottom: 1.5px dashed var(--accent);
  color: var(--ink);
  cursor: pointer;
  font-weight: 500;
  padding: 0 1px;
  transition: background 0.15s, color 0.15s;
}
.term:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Figures & Diagrams */
figure {
  margin: 2rem 0 2.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
figure svg {
  display: block;
  width: 100%;
  height: auto;
}
figcaption {
  margin-top: 0.9rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
  line-height: 1.65;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  margin: 1.5rem 0 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.89rem;
  line-height: 1.65;
}
th, td {
  padding: 0.82rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  background: var(--surface-alt);
  font-weight: 700;
  font-size: 0.82rem;
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }

/* Interactive Lab Panels */
.lab-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 2rem 0 2.25rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.03);
}
.lab-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.85rem;
  margin-bottom: 1rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--border);
}
.lab-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--indigo);
  background: var(--indigo-soft);
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  letter-spacing: 0.05em;
}
.lab-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.filter-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.filter-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink-muted);
  font-family: var(--font-sans);
  font-size: 0.79rem;
  font-weight: 500;
  padding: 0.34rem 0.78rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.filter-btn:hover {
  border-color: var(--ink-muted);
  color: var(--ink);
}
.filter-btn.active {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.scale-btn.active {
  background: var(--teal);
  color: #ffffff;
  border-color: var(--teal);
}

/* Elo Bar Chart with Axis, Gridlines & Tick Labels */
.elo-scale-note {
  font-size: 0.82rem;
  color: var(--ink-muted);
  background: var(--surface-alt);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 1.1rem;
  line-height: 1.6;
}
.elo-chart-wrap {
  position: relative;
}
.elo-row {
  display: grid;
  grid-template-columns: 165px 1fr 74px;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.58rem;
  font-size: 0.84rem;
}
@media (max-width: 600px) {
  .elo-row { grid-template-columns: 120px 1fr 58px; gap: 0.5rem; }
  .elo-axis-row { grid-template-columns: 120px 1fr 58px !important; gap: 0.5rem !important; }
}
.elo-name {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.elo-cat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.elo-track {
  background: var(--surface-alt);
  height: 24px;
  border-radius: 6px;
  overflow: visible;
  position: relative;
}
.elo-gridline {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 1px;
  background: var(--grid-line);
  pointer-events: none;
  z-index: 1;
}
.elo-baseline {
  position: absolute;
  top: -5px;
  bottom: -5px;
  width: 1.5px;
  border-left: 1.5px dashed var(--accent);
  pointer-events: none;
  z-index: 3;
  opacity: 0.75;
}
.elo-fill {
  position: relative;
  z-index: 2;
  height: 100%;
  border-radius: 6px;
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.elo-val {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  text-align: right;
  font-weight: 600;
  white-space: nowrap;
}
.elo-val small {
  display: block;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--ink-subtle);
  line-height: 1.1;
}
.elo-axis-row {
  display: grid;
  grid-template-columns: 165px 1fr 74px;
  align-items: start;
  gap: 0.8rem;
  margin-top: 0.5rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}
.elo-axis-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-subtle);
  text-align: right;
  padding-right: 0.25rem;
}
.elo-ticks {
  position: relative;
  height: 36px;
}
.elo-tick {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-muted);
  white-space: nowrap;
}
.elo-tick::before {
  content: "";
  display: block;
  width: 1px;
  height: 6px;
  background: var(--ink-subtle);
  margin: -9px auto 3px;
}
.elo-tick.is-baseline {
  color: var(--accent);
  font-weight: 600;
}
.elo-tick.is-baseline::before {
  background: var(--accent);
  height: 8px;
}
.elo-tick-sub {
  display: block;
  font-size: 0.63rem;
  color: var(--accent);
  text-align: center;
  margin-top: 1px;
}
.elo-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.75rem;
  font-size: 0.78rem;
  color: var(--ink-muted);
}
.elo-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

/* Simulator Sliders */
.sim-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.35rem;
}
@media (max-width: 680px) {
  .sim-grid { grid-template-columns: 1fr; }
}
.slider-group { margin-bottom: 1rem; }
.slider-group label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}
.slider-group input[type=range] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}
.sim-result {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.15rem;
  font-size: 0.88rem;
  line-height: 1.72;
}

/* Debate Video & Pro/Con Layout */
.video-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1.75rem 0 2rem;
}
.video-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}
.video-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: 8px;
  background: #000;
  display: block;
}
.chapter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.9rem;
}
.chapter-btn {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  padding: 0.34rem 0.72rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.chapter-btn:hover, .chapter-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.video-note {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--ink-subtle);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.video-note a {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  text-decoration: none;
  font-weight: 600;
}
.video-note a:hover { text-decoration: underline; }
.debate-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.5rem 0 1.85rem;
}
@media (max-width: 720px) {
  .debate-grid { grid-template-columns: 1fr; }
}
.debate-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  font-size: 0.9rem;
  line-height: 1.72;
}
.debate-col.pro { border-top: 3px solid var(--teal); }
.debate-col.con { border-top: 3px solid var(--accent); }
.debate-col h4 {
  margin: 0 0 0.75rem;
  font-size: 0.96rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.debate-col ul {
  margin: 0;
  padding-left: 1.15rem;
}
.debate-col li { margin-bottom: 0.6rem; }

/* Resource Cards */
.resource-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 1rem;
  margin-top: 1.15rem;
}
.res-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.8rem;
  transition: border-color 0.15s;
}
.res-card:hover { border-color: var(--ink-subtle); }
.res-tag {
  font-family: var(--font-mono);
  font-size: 0.69rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.res-card h4 {
  margin: 0.25rem 0 0.45rem;
  font-size: 0.97rem;
  line-height: 1.45;
}
.res-card p {
  font-size: 0.84rem;
  color: var(--ink-muted);
  margin: 0;
  line-height: 1.62;
}
.res-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
}
.res-link {
  font-family: var(--font-mono);
  font-size: 0.73rem;
  text-decoration: none;
  padding: 0.26rem 0.58rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--ink);
  background: var(--bg);
  transition: border-color 0.15s, color 0.15s;
}
.res-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.res-link.yt {
  background: color-mix(in srgb, #ef4444 10%, var(--bg));
  border-color: color-mix(in srgb, #ef4444 35%, var(--border));
  color: #dc2626;
}
:root[data-theme="dark"] .res-link.yt {
  color: #fca5a5;
}

/* Glossary Popover Modal */
#glossary-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  max-width: 390px;
  background: var(--ink);
  color: var(--bg);
  padding: 1.05rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.26);
  z-index: 1200;
  display: none;
  font-size: 0.86rem;
  line-height: 1.62;
}
#glossary-toast button {
  background: none;
  border: none;
  color: var(--ink-subtle);
  font-size: 1.15rem;
  cursor: pointer;
  line-height: 1;
}

footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--ink-subtle);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.language-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.32rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  white-space: nowrap;
  font-size: 0.74rem;
}
.language-switch [aria-current] {
  color: var(--ink);
  font-weight: 700;
}
.language-switch a {
  color: var(--ink-muted);
  text-decoration: none;
}
.language-switch a:hover,
.language-switch a:focus-visible {
  color: var(--accent);
  text-decoration: underline;
}
.language-divider {
  color: var(--ink-subtle);
}
@media (max-width: 1150px) {
  header nav > a { display: none; }
  header nav { gap: 0.5rem; }
}
@media (max-width: 540px) {
  header { padding: 0.65rem 0.8rem; gap: 0.65rem; }
  .brand { font-size: 0.7rem; white-space: normal; }
  .brand-dot { flex: 0 0 8px; }
}
