:root {
  --bg: #f6f4ef;
  --panel: #fffdf8;
  --panel-strong: #ffffff;
  --text: #1f2933;
  --muted: #61707d;
  --cyan: #276f86;
  --red: #8b2f3c;
  --orange: #a76528;
  --line: #d9d3c8;
  --shadow: 0 14px 34px rgba(45, 54, 65, 0.08);
  --paper: #fbfaf7;
  --code-bg: #18212b;
}

body.light {
  --bg: #11161c;
  --panel: #171d24;
  --panel-strong: #1d252e;
  --text: #edf1f5;
  --muted: #a6b2bd;
  --cyan: #79aebb;
  --red: #cf7580;
  --orange: #d0a06f;
  --line: #33404b;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  --paper: #151b21;
  --code-bg: #0d1218;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(rgba(31, 41, 51, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 41, 51, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 48px 48px, 48px 48px, auto;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  letter-spacing: 0;
}

#particles {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.22;
}

.progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: var(--cyan);
  z-index: 10;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 8;
  width: 292px;
  padding: 22px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(10px);
  transition: transform 0.25s ease;
}

body.light .sidebar { background: color-mix(in srgb, var(--panel) 92%, transparent); }

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 46%, var(--cyan) 47% 53%, transparent 54%),
    linear-gradient(45deg, transparent 46%, var(--red) 47% 53%, transparent 54%),
    var(--paper);
  border: 1px solid var(--line);
}

.brand small, .search span, .eyebrow { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; }
.search { display: grid; gap: 8px; margin: 22px 0; }
.search input {
  width: 100%;
  padding: 12px 13px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

nav { display: grid; gap: 6px; }
nav a, .mode-toggle, .button, .code-head button, .sim-head button, .segmented button {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

nav a:hover, .button:hover, button:hover {
  transform: translateY(-1px);
  border-color: var(--cyan);
  background: color-mix(in srgb, var(--cyan) 8%, var(--paper));
}

.mode-toggle { width: 100%; margin-top: 20px; }
.nav-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 11;
  width: 44px;
  height: 44px;
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
}

main {
  position: relative;
  z-index: 1;
  margin-left: 292px;
  padding: 24px;
}

.section-panel {
  min-height: auto;
  padding: 56px;
  margin: 0 0 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hero {
  min-height: 78vh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.8fr);
  align-items: center;
  gap: 34px;
  overflow: hidden;
  position: relative;
}

.hero-grid {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0 74%, color-mix(in srgb, var(--cyan) 9%, transparent) 75%, transparent 76%),
    linear-gradient(var(--line) 1px, transparent 1px);
  background-size: 100% 100%, 100% 52px;
  opacity: 0.42;
  animation: none;
}

@keyframes scan { from { transform: translateX(-80%); } to { transform: translateX(80%); } }

.hero-copy { position: relative; z-index: 1; }
h1, h2, h3, p { margin-top: 0; }
h1 {
  max-width: 920px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.35rem, 5vw, 4.9rem);
  font-weight: 700;
  line-height: 1.05;
  margin-bottom: 20px;
}
h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.65rem, 2.4vw, 2.6rem);
  margin-bottom: 14px;
}
h3 { font-size: 1.02rem; }
.subtitle { max-width: 780px; color: var(--muted); font-size: 1.15rem; line-height: 1.7; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }
.button.primary { color: #fff; background: var(--cyan); border-color: var(--cyan); }
.button.secondary { background: var(--paper); }

.radar-card {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
}

.radar-card canvas, .sim-panel canvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.section-heading { max-width: 980px; margin-bottom: 24px; }
.section-heading p { color: var(--muted); line-height: 1.75; }

.metric-grid, .analysis-grid, .comparison, .sim-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.formula-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  counter-reset: formula;
}

.metric-grid article, .glass, .formula-card, .comparison article, .sim-panel, .code-card {
  padding: 20px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric-grid article {
  display: grid;
  gap: 8px;
}

.metric-grid span, li, .glass p, .comparison p, .formula-card p { color: var(--muted); line-height: 1.65; }
li { margin: 7px 0; }

.code-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.code-card { margin-top: 16px; overflow: hidden; }
.code-head, .sim-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.code-head h3, .sim-head h3 { margin: 0; }
.code-head button, .sim-head button, .segmented button { padding: 8px 10px; }
pre {
  max-height: 240px;
  overflow: auto;
  margin: 0;
  padding: 16px;
  color: #e7edf3;
  background: var(--code-bg);
  border-radius: 8px;
  border: 1px solid var(--line);
}
.code-card.expanded pre { max-height: 680px; }
code { font-family: "Cascadia Code", Consolas, monospace; font-size: 0.9rem; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 780px; background: var(--panel-strong); }
th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--cyan); }
td { color: var(--muted); }

.formula-card {
  position: relative;
  padding: 24px 24px 20px 28px;
  border-left: 4px solid color-mix(in srgb, var(--cyan) 65%, var(--line));
}
.formula-card strong {
  color: var(--text);
  display: block;
  margin-bottom: 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.18rem;
}
.formula-code {
  color: var(--muted);
  margin-bottom: 12px;
  font-size: 0.92rem;
}
.formula-code b { color: var(--orange); }
.formula-card .math {
  color: var(--cyan);
  padding: 10px;
  margin: 12px 0;
  border-left: 3px solid var(--red);
  background: color-mix(in srgb, var(--cyan) 8%, var(--paper));
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.55;
  overflow-x: auto;
}
.formula-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.formula-control input { width: 100%; accent-color: var(--cyan); }
.formula-control output { color: var(--cyan); font-family: "Cascadia Code", Consolas, monospace; }
.formula-bar {
  grid-column: 1 / -1;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 60%, transparent);
}
.formula-bar span {
  display: block;
  width: 45%;
  height: 100%;
  background: var(--cyan);
}
.tok-key { color: #d7a45f; }
.tok-num { color: #8fc0cf; }
.tok-comment { color: #95a2ad; }

.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented .active { color: #fff; background: var(--cyan); border-color: var(--cyan); }

.flowchart {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 10px;
  align-items: center;
  margin-top: 18px;
  overflow-x: auto;
}
.flowchart div {
  min-height: 58px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 10px;
  border-radius: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
}
.flowchart span {
  height: 2px;
  background: var(--line);
}
.flowchart span::after { content: ">"; color: var(--orange); margin-left: calc(100% - 6px); position: relative; top: -10px; }

.conclusion p { max-width: 1100px; color: var(--muted); line-height: 1.85; font-size: 1.05rem; }
.hidden-by-search { display: none; }

@media (max-width: 980px) {
  .nav-toggle { display: grid; place-items: center; }
  .sidebar { transform: translateX(-102%); }
  .sidebar.open { transform: translateX(0); }
  main { margin-left: 0; padding: 12px; }
  .section-panel { padding: 28px 18px; }
  .hero { grid-template-columns: 1fr; padding-top: 72px; }
  .metric-grid, .analysis-grid, .formula-grid, .comparison, .sim-grid, .code-layout { grid-template-columns: 1fr; }
  .flowchart { grid-template-columns: repeat(7, 140px); }
}
