:root {
  --bg: #0f1419;
  --surface: #171d26;
  --surface-2: #1f2733;
  --border: #2b3543;
  --text: #e6edf3;
  --text-dim: #8b98a9;
  --accent: #4ea1ff;
  --inside: #46d39a;
  --outside: #ff6b6b;
  --pi-line: #f0b429;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 32px 24px 64px;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Malgun Gothic", -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.6;
}

/* ---------- header ---------- */

.site-header {
  max-width: 1060px;
  margin: 0 auto 24px;
}

.site-header h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 15px;
}

/* ---------- tabs ---------- */

.tabs {
  max-width: 1060px;
  margin: 0 auto 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}

.tab-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-group-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--pi-line);
  margin-right: 2px;
  min-width: 14px;
}

.tab {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}

.tab:hover { color: var(--text); border-color: #3c4a5c; }

.tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #06121f;
  font-weight: 600;
}

/* ---------- layout ---------- */

.layout {
  max-width: 1060px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 28px;
  align-items: start;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- stage ---------- */

.stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}

#stage-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.stage-caption {
  margin: 14px 2px 0;
  color: var(--text-dim);
  font-size: 13px;
  min-height: 40px;
}

/* ---------- panel ---------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.readout {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
}

.readout-label {
  font-size: 13px;
  color: var(--text-dim);
}

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
}

.badge.is-done {
  background: rgba(70, 211, 154, 0.12);
  border-color: rgba(70, 211, 154, 0.4);
  color: var(--inside);
}

/* 파라미터가 없는 알고리즘에서는 슬라이더 한 줄을 숨긴다 */
.slider.is-hidden { display: none; }

.readout-value {
  font-size: 40px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.readout-error {
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* ---------- stats ---------- */

.stats {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 20px;
  display: grid;
  grid-template-columns: auto auto;
  gap: 6px 12px;
}

.stats dt {
  color: var(--text-dim);
  font-size: 13px;
}

.stats dd {
  margin: 0;
  text-align: right;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* ---------- controls ---------- */

.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.button-row { display: flex; gap: 8px; }

.btn {
  flex: 1;
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.btn:hover { background: #2a3441; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06121f;
  font-weight: 600;
}

.btn-primary:hover { background: #6bb2ff; }

.slider { display: block; }

.slider-label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.slider-label b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.slider input {
  width: 100%;
  accent-color: var(--accent);
}

/* ---------- chart ---------- */

.chart-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 20px 12px;
}

.chart-title {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
}

#chart-canvas {
  display: block;
  width: 100%;
  height: auto;
}

.chart-legend {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin: 0 5px 0 12px;
  vertical-align: -1px;
}

.chart-legend .swatch:first-child { margin-left: 0; }
.swatch-est { background: var(--accent); }
.swatch-pi { background: var(--pi-line); }

/* ---------- pseudo code ---------- */

.code-section {
  max-width: 1060px;
  margin: 28px auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 22px 20px;
}

.code-title {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
}

.code-method {
  margin-left: 8px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-dim);
}

.code {
  margin: 0;
  padding: 0;
  font-family: "D2Coding", "Consolas", "Menlo", monospace;
  font-size: 13.5px;
  line-height: 1.75;
  overflow-x: auto;
}

.code-line {
  display: flex;
  gap: 16px;
  white-space: pre;
  border-left: 2px solid transparent;
  padding-left: 10px;
}

.code-line .ln {
  flex: none;
  width: 22px;
  text-align: right;
  color: #4a5766;
  user-select: none;
}

.code-line.is-key {
  background: rgba(240, 180, 41, 0.09);
  border-left-color: var(--pi-line);
}

.code-line.is-key .src { color: var(--pi-line); font-weight: 600; }

.code .cmt { color: #5f7a63; }

.code .kw { color: #7fb3ff; }

.code-note {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

/* ---------- explain ---------- */

.explain {
  margin: 0;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 13px;
  color: var(--text-dim);
}

.explain b { color: var(--text); font-weight: 600; }
