:root {
  color-scheme: dark;
  --bg: #07090f;
  --bg-soft: rgba(11, 15, 25, 0.86);
  --bg-card: rgba(10, 13, 21, 0.8);
  --text: #ffffff;
  --muted: #a1a1aa;
  --subtle: #71717a;
  --border: rgba(63, 63, 70, 0.9);
  --border-soft: rgba(82, 82, 91, 0.45);
  --primary: #e4e4e7;
  --primary-text: #09090b;
  --accent: #b884ff;
  --accent-soft: rgba(184, 132, 255, 0.18);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.24);
  --shadow-soft: 0 10px 40px rgba(0, 0, 0, 0.2);
  --grid: rgba(255, 255, 255, 0.06);
  --btn-secondary-bg: rgba(24, 24, 27, 0.9);
  --btn-secondary-border: rgba(113, 113, 122, 0.7);
  --equation-bg: rgba(0, 0, 0, 0.32);
  --equation-text: #ffffff;
  --node-bg: rgba(10, 14, 24, 0.98);
  --line: rgba(196, 181, 253, 0.55);
}

body.theme-light {
  color-scheme: light;
  --bg: #f6f8fc;
  --bg-soft: rgba(255, 255, 255, 0.88);
  --bg-card: rgba(255, 255, 255, 0.82);
  --text: #0f172a;
  --muted: #475569;
  --subtle: #64748b;
  --border: rgba(226, 232, 240, 0.95);
  --border-soft: rgba(203, 213, 225, 0.7);
  --primary: #111827;
  --primary-text: #ffffff;
  --accent: #7c3aed;
  --accent-soft: rgba(124, 58, 237, 0.12);
  --shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 10px 40px rgba(15, 23, 42, 0.06);
  --grid: rgba(15, 23, 42, 0.06);
  --btn-secondary-bg: rgba(255, 255, 255, 0.9);
  --btn-secondary-border: rgba(203, 213, 225, 1);
  --equation-bg: rgba(248, 250, 252, 0.95);
  --equation-text: #0f172a;
  --node-bg: rgba(255, 255, 255, 0.97);
  --line: rgba(99, 102, 241, 0.42);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
a { font: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }

.bg-layer,
.grid-layer,
.glow-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.bg-layer { background: var(--bg); z-index: -3; }
.grid-layer {
  z-index: -2;
  background-image:
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: 40px 40px;
}
.glow-layer {
  z-index: -1;
  background:
    radial-gradient(circle at top left, rgba(77, 91, 179, 0.24), transparent 30%),
    radial-gradient(circle at 80% 20%, rgba(135, 53, 150, 0.22), transparent 24%),
    radial-gradient(circle at 60% 80%, rgba(70, 133, 165, 0.14), transparent 26%);
}

.glass {
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.topbar-shell {
  position: sticky;
  top: 16px;
  z-index: 30;
  padding: 16px 16px 0;
}

.topbar {
  max-width: 1400px;
  margin: 0 auto;
  border-radius: 28px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  background: var(--node-bg);
  flex: 0 0 auto;
}
.brand-mark img { width: 100%; height: 100%; }
.brand-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}
.topnav button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 14px;
  border-radius: 999px;
  transition: 180ms ease;
}
.topnav button:hover,
.topnav button.is-active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}
body.theme-light .topnav button:hover,
body.theme-light .topnav button.is-active {
  background: rgba(15, 23, 42, 0.08);
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.lang-switch {
  display: flex;
  align-items: center;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.06);
}
body.theme-light .lang-switch { background: rgba(255, 255, 255, 0.8); }
.lang-switch button,
.theme-toggle {
  border: 0;
  background: transparent;
  color: var(--muted);
}
.lang-switch button {
  width: 42px;
  height: 32px;
  border-radius: 999px;
  transition: 180ms ease;
}
.lang-switch button.is-active {
  background: var(--primary);
  color: var(--primary-text);
}
.theme-toggle {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.06);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
body.theme-light .theme-toggle { background: rgba(255, 255, 255, 0.8); }
.theme-icon-light { display: none; }
body.theme-light .theme-icon-dark { display: none; }
body.theme-light .theme-icon-light { display: inline; }

.page-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 16px 80px;
  display: grid;
  gap: 24px;
}

.hero,
.panel {
  border-radius: 36px;
}
.hero {
  padding: 34px;
}
.panel {
  padding: 34px;
}

.eyebrow-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.95rem;
}
body.theme-light .eyebrow-badge { background: rgba(255, 255, 255, 0.75); }
.eyebrow-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent);
}

.hero-title {
  margin: 22px 0 0;
  font-size: clamp(2.6rem, 7vw, 5.2rem);
  line-height: 0.95;
  letter-spacing: -0.06em;
}
.hero-canonical {
  margin: 20px 0 0;
  color: var(--accent);
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}
.hero-text {
  margin: 22px 0 0;
  max-width: 960px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.9;
}
.hero-note {
  margin: 18px 0 0;
  max-width: 960px;
  color: var(--subtle);
  font-size: 0.98rem;
  line-height: 1.8;
}
.hero-actions {
  margin-top: 28px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.btn {
  border-radius: 999px;
  padding: 14px 18px;
  transition: transform 180ms ease, opacity 180ms ease, background 180ms ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
  border: 0;
  background: var(--primary);
  color: var(--primary-text);
}
.btn-secondary {
  border: 1px solid var(--btn-secondary-border);
  background: var(--btn-secondary-bg);
  color: var(--text);
}

.section-header { max-width: 900px; }
.section-eyebrow {
  margin: 0;
  color: var(--subtle);
  text-transform: uppercase;
  letter-spacing: 0.28em;
  font-size: 0.77rem;
}
.section-title {
  margin: 14px 0 0;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.03;
  letter-spacing: -0.05em;
}
.section-text {
  margin: 18px 0 0;
  color: var(--muted);
  line-height: 1.9;
  font-size: 1rem;
}

.card-grid,
.equation-grid,
.mini-card-grid,
.network-layout,
.two-col-list {
  margin-top: 26px;
}
.card-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.cards-intro { margin-top: 0; }
.equation-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.mini-card-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.two-col-list {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.appendix-layout {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  margin-top: 26px;
}
.network-layout {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
}

.card,
.equation-card,
.mini-card,
.subpanel {
  border-radius: 28px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  box-shadow: var(--shadow-soft);
}
body.theme-light .card,
body.theme-light .equation-card,
body.theme-light .mini-card,
body.theme-light .subpanel {
  background: rgba(255, 255, 255, 0.72);
}
.card {
  padding: 24px;
}
.card-icon {
  width: 46px;
  height: 46px;
  border-radius: 18px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
body.theme-light .card-icon { background: rgba(15, 23, 42, 0.04); }
.card-icon svg { width: 20px; height: 20px; }
.card h3,
.equation-card h3,
.subpanel h3,
.footer-panel h2 {
  margin: 16px 0 0;
  font-size: 1.2rem;
  letter-spacing: -0.03em;
}
.card p,
.mini-card p,
.subpanel-text,
.footer-panel p {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.8;
}

.equation-card {
  padding: 22px;
}
.equation-title {
  font-size: 1rem;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.equation-box {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--equation-bg);
  padding: 18px 18px;
  overflow-x: auto;
  color: var(--equation-text);
}
.equation-box .katex-display {
  margin: 0;
  padding: 2px 0;
}
.equation-box .katex {
  color: inherit;
  font-size: 1.08rem;
}
.equation-box .katex-display > .katex {
  white-space: nowrap;
}
.equation-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.7;
}

.mini-card {
  padding: 18px;
}
.mini-card strong {
  color: var(--text);
}
.why-panel h3,
.subpanel h3 { margin-top: 0; }
.subpanel {
  padding: 22px;
}
.subpanel ul {
  margin: 14px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.85;
}
.subpanel li + li { margin-top: 6px; }

.appendix-mini-grid {
  grid-template-columns: 1fr;
}

.appendix-visual {
  margin-top: 18px;
  display: grid;
  gap: 14px;
}

.appendix-flow {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
}

.appendix-step {
  position: relative;
  overflow: hidden;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  padding: 18px;
  box-shadow: var(--shadow-soft);
}

body.theme-light .appendix-step {
  background: rgba(255, 255, 255, 0.78);
}

.appendix-step::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  opacity: 0.98;
}

.appendix-step.is-good {
  border-color: rgba(16, 185, 129, 0.28);
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.08) 0%, rgba(255, 255, 255, 0.05) 40%);
}

.appendix-step.is-good::before {
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.98), rgba(16, 185, 129, 0.32));
}

.appendix-step.is-mid {
  border-color: rgba(245, 158, 11, 0.28);
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.08) 0%, rgba(255, 255, 255, 0.05) 40%);
}

.appendix-step.is-mid::before {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.98), rgba(245, 158, 11, 0.32));
}

.appendix-step.is-bad {
  border-color: rgba(244, 63, 94, 0.30);
  background: linear-gradient(180deg, rgba(244, 63, 94, 0.09) 0%, rgba(255, 255, 255, 0.05) 40%);
}

.appendix-step.is-bad::before {
  background: linear-gradient(90deg, rgba(244, 63, 94, 0.98), rgba(244, 63, 94, 0.34));
}

body.theme-light .appendix-step.is-good {
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.10) 0%, rgba(255, 255, 255, 0.92) 45%);
}

body.theme-light .appendix-step.is-mid {
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.10) 0%, rgba(255, 255, 255, 0.92) 45%);
}

body.theme-light .appendix-step.is-bad {
  background: linear-gradient(180deg, rgba(244, 63, 94, 0.10) 0%, rgba(255, 255, 255, 0.92) 45%);
}

.appendix-step-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: rgba(6, 10, 18, 0.34);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

body.theme-light .appendix-step-state {
  background: rgba(255, 255, 255, 0.76);
}

.appendix-step-label {
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.appendix-step-title {
  margin-top: 10px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.appendix-step-text {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.75;
  font-size: 0.95rem;
}

.appendix-metric {
  margin-top: 14px;
  border-radius: 20px;
  border: 1px solid var(--border-soft);
  background: var(--equation-bg);
  padding: 14px;
  color: var(--equation-text);
  font-size: 0.95rem;
  overflow-x: auto;
}

.appendix-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 1.4rem;
  font-weight: 700;
}

.appendix-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.appendix-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.88rem;
}

body.theme-light .appendix-pill {
  background: rgba(255, 255, 255, 0.82);
}

.appendix-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.appendix-dot.is-good { background: #10b981; box-shadow: 0 0 12px rgba(16, 185, 129, 0.45); }
.appendix-dot.is-mid { background: #f59e0b; box-shadow: 0 0 12px rgba(245, 158, 11, 0.35); }
.appendix-dot.is-bad { background: #f43f5e; box-shadow: 0 0 12px rgba(244, 63, 94, 0.38); }

.signature-badge {
  margin-top: 18px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(168, 85, 247, 0.24);
  background: rgba(168, 85, 247, 0.10);
  border-radius: 999px;
  padding: 10px 14px;
}

.signature-label {
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.signature-name {
  font-size: 0.92rem;
  letter-spacing: 0.18em;
  font-weight: 700;
  color: var(--text);
}

.network-wrap {
  position: relative;
  height: 280px;
  margin-top: 18px;
}
.network-svg {
  width: 100%;
  height: 100%;
}
.network-line {
  stroke: var(--line);
  stroke-width: 2;
}
.arrow-head { fill: var(--line); }
.network-label {
  fill: var(--accent);
  font-size: 12px;
  text-anchor: middle;
}
.network-node {
  position: absolute;
  width: 64px;
  height: 64px;
  margin-left: -32px;
  margin-top: -32px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--node-bg);
  box-shadow: var(--shadow-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
}
.node-a { left: 50%; top: 18%; }
.node-b { left: 23%; top: 72%; }
.node-c { left: 77%; top: 72%; }

.footer-panel h2 { font-size: 1.1rem; }
.footer-panel p { max-width: 980px; }

@media (max-width: 1200px) {
  .topnav { display: none; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mini-card-grid { grid-template-columns: 1fr; }
  .network-layout { grid-template-columns: 1fr; }
  .appendix-layout { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .equation-grid,
  .two-col-list,
  .card-grid,
  .appendix-flow {
    grid-template-columns: 1fr;
  }
  .appendix-arrow {
    transform: rotate(90deg);
    min-height: 24px;
  }
  .hero,
  .panel { padding: 24px; border-radius: 28px; }
  .topbar { border-radius: 22px; }
}

@media (max-width: 640px) {
  .topbar-shell { top: 10px; padding: 10px 10px 0; }
  .topbar {
    padding: 10px 12px;
    align-items: flex-start;
    flex-direction: column;
  }
  .controls { width: 100%; justify-content: space-between; }
  .page-shell { padding: 18px 10px 56px; gap: 18px; }
  .hero-title { line-height: 1.02; }
  .hero-actions { flex-direction: column; }
  .btn { width: 100%; text-align: center; }
}
