:root {
  --bg: #0e1014;
  --bg-elev: #161a21;
  --bg-soft: #1c222c;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8e6e1;
  --muted: #9a958c;
  --accent: #c9a66b;
  --accent-dim: rgba(201, 166, 107, 0.15);
  --pos: #6ecf8e;
  --neg: #e07a6a;
  --radius: 14px;
  --font: "Outfit", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(201, 166, 107, 0.07), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(90, 140, 180, 0.06), transparent 50%),
    var(--bg);
  color: var(--text);
  line-height: 1.45;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem clamp(1rem, 3vw, 2.5rem);
  background: rgba(14, 16, 20, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  width: 100%;
}

.brand {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.brand-bodhi {
  color: var(--accent);
}

.lang {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}

.lang-btn {
  min-width: 2.5rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
}

.lang-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  width: 100%;
  max-width: none;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 3.5rem) 3rem;
}

.cats {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 1rem 0 0.75rem;
  margin: 0 -0.25rem;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-dim) transparent;
  -webkit-overflow-scrolling: touch;
}

.cat-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  transition: border-color 0.2s, color 0.2s, background 0.2s, transform 0.15s;
}

.cat-btn:hover {
  color: var(--text);
  border-color: rgba(201, 166, 107, 0.35);
}

.cat-btn.active {
  color: var(--text);
  background: var(--accent-dim);
  border-color: rgba(201, 166, 107, 0.45);
}

.cat-icon {
  font-size: 1rem;
  opacity: 0.9;
}

.stage {
  min-width: 0;
}

.stage-head {
  padding: 0.5rem 0 1.25rem;
  animation: fadeUp 0.35s ease both;
}

.eyebrow {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.4rem;
}

.stage-head h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.lede {
  margin-top: 0.4rem;
  color: var(--muted);
  font-size: 0.98rem;
  max-width: 40rem;
}

.panels {
  display: grid;
  gap: 1rem;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1rem, 2.5vw, 1.5rem);
  animation: fadeUp 0.4s ease both;
}

.card:nth-child(2) { animation-delay: 0.04s; }
.card:nth-child(3) { animation-delay: 0.08s; }
.card:nth-child(4) { animation-delay: 0.12s; }
.card:nth-child(5) { animation-delay: 0.16s; }

.card h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.85rem;
  color: var(--text);
}

.card h2 .hint {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--muted);
}

.note {
  color: var(--muted);
  font-size: 0.92rem;
  margin-bottom: 0.75rem;
}

.formula {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.65rem 1rem;
  padding: 1rem 0.75rem;
  background: var(--bg-soft);
  border-radius: calc(var(--radius) - 4px);
  overflow-x: auto;
  font-size: clamp(1.05rem, 2.4vw, 1.35rem);
}

.formula + .formula,
.formula + .note,
.note + .formula,
.formula + .examples,
.examples + .formula {
  margin-top: 0.85rem;
}

.formula.left {
  justify-content: flex-start;
}

.formula .katex {
  font-size: 1.15em;
}

.examples {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.65rem;
  margin-top: 0.85rem;
}

.ex {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.65rem;
  width: fit-content;
  max-width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line);
  font-size: 0.95rem;
}

.side-op {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: 0.35rem;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.92em;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
}

.side-op-sep {
  color: var(--accent);
  font-size: 1.05em;
  line-height: 1;
}

.step {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line);
}

.ex-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sign-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-top: 0.5rem;
}

@media (max-width: 520px) {
  .sign-grid {
    grid-template-columns: 1fr;
  }
}

.sign-box {
  padding: 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  text-align: center;
}

.sign-box.pos {
  border-color: rgba(110, 207, 142, 0.35);
}

.sign-box.neg {
  border-color: rgba(224, 122, 106, 0.35);
}

.sign-box .tag {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.55rem;
}

.sign-box.pos .tag { color: var(--pos); }
.sign-box.neg .tag { color: var(--neg); }

.metric {
  display: grid;
  gap: 1rem;
}

.metric-block h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.metric-sub {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  margin: 1.1rem 0 0.3rem;
}

.metric-tip {
  font-size: 0.92rem;
  color: var(--muted);
  margin: 0 0 0.55rem;
  line-height: 1.35;
}

.ladder {
  display: grid;
  grid-template-columns: repeat(10, minmax(3.75rem, 1fr));
  align-items: stretch;
  gap: 0;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  min-width: 0;
}

.ladder-liquid {
  grid-template-columns: repeat(4, minmax(4.5rem, 1fr));
  max-width: 28rem;
}

.rung {
  min-width: 0;
  text-align: center;
  padding: 0.65rem 0.2rem;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  position: relative;
}

.rung:not(:first-child) {
  border-left: none;
}

.rung:first-child {
  border-radius: 10px 0 0 10px;
}

.rung:last-child {
  border-radius: 0 10px 10px 0;
}

.rung.base {
  background: var(--accent-dim);
  border: 1px solid rgba(201, 166, 107, 0.4);
  z-index: 1;
}

.rung.empty {
  background: transparent;
  opacity: 0.45;
}

.rung.empty .sym {
  color: var(--muted);
}

.rung .sym {
  display: block;
  font-family: var(--mono);
  font-weight: 500;
  font-size: clamp(0.92rem, 1.35vw, 1.12rem);
  color: var(--text);
  line-height: 1.2;
}

.rung .name {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.rung .alias {
  display: block;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text);
  margin-top: 0.15rem;
  opacity: 0.9;
}

.rung .factor {
  display: block;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
  margin-top: 0.35rem;
  opacity: 0.95;
  line-height: 1.25;
  white-space: nowrap;
}

.rung .factor .unit {
  font-size: 0.85em;
  opacity: 0.85;
}

.arrow-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
  padding: 0 0.25rem;
}

.frac-parts {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 1rem 0;
}

.frac-big {
  font-size: 1.65rem;
  line-height: 1;
}

.frac-big .katex {
  font-size: 2.1em;
}

.frac-labels {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.35rem;
  font-size: 0.95rem;
  padding-top: 0.15rem;
}

.frac-labels span {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
}

.frac-labels .arrow {
  color: var(--accent);
  font-family: var(--mono);
}

.grid-2 {
  display: grid;
  gap: 0.85rem;
}

@media (min-width: 640px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.shape-grid {
  display: grid;
  gap: 0.85rem;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  align-items: stretch;
}

.shape-card {
  padding: 1rem;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  display: grid;
  grid-template-rows: 120px auto auto 1fr;
  gap: 0.55rem;
  justify-items: center;
  text-align: center;
  overflow: visible;
  align-content: start;
}

.shape-card .shape-viz {
  width: 100%;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shape-card .shape-viz svg,
.shape-card > svg {
  width: 100%;
  max-width: 150px;
  height: 110px;
  overflow: visible;
}

.shape-card .name {
  font-weight: 600;
  font-size: 1.08rem;
  line-height: 1.25;
  min-height: 1.25em;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shape-card .desc {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.3;
  min-height: 2.6em;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  margin: 0;
}

.shape-card .forms {
  width: 100%;
  font-size: 1.05rem;
  display: grid;
  gap: 0.55rem;
  align-content: start;
}

.shape-card .forms .row {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 2.6rem;
  padding: 0.55rem 0.5rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
  overflow-x: auto;
}

.shape-card .forms .row .katex {
  font-size: 1.12em;
}

.rule-box {
  margin: 0.85rem 0;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(201, 166, 107, 0.45);
  border-radius: 10px;
  background: var(--accent-dim);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.45;
}

.rule-box strong {
  display: block;
  color: var(--accent);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.rule-box p {
  margin: 0;
}

.scale-grid {
  display: grid;
  gap: 0.85rem;
  margin-top: 0.75rem;
}

@media (min-width: 800px) {
  .scale-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.scale-step {
  padding: 0.75rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
}

.balance-viz {
  width: 100%;
  overflow-x: auto;
}

.balance-viz svg {
  display: block;
  width: 100%;
  max-width: 420px;
  height: auto;
  margin: 0 auto;
}

.cross-demo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0 0.25rem;
}

.cross-box {
  position: relative;
  padding: 1.25rem 1.5rem;
  background: var(--bg-soft);
  border-radius: 12px;
  border: 1px solid var(--line);
}

.cross-eq {
  font-size: 1.35rem;
}

.cross-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.steps {
  display: grid;
  gap: 0.5rem;
  width: 100%;
  max-width: 28rem;
}

.step-n {
  flex: 0 0 auto;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--accent-dim);
  color: var(--accent);
}

.prop-viz {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem;
  background: var(--bg-soft);
  border-radius: 12px;
  margin-bottom: 0.75rem;
}

.prop-col {
  text-align: center;
}

.prop-col .bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.35rem;
  height: 64px;
  margin-bottom: 0.4rem;
}

.bar {
  width: 14px;
  border-radius: 4px 4px 0 0;
  background: var(--accent);
  opacity: 0.85;
}

.prop-mid {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 1.1rem;
}

.prop-graph {
  width: 100%;
  max-width: 420px;
  margin: 0.25rem auto 0.85rem;
  background: var(--bg-soft);
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 0.5rem 0.75rem 0.35rem;
}

.prop-graph svg {
  display: block;
  width: 100%;
  height: auto;
}

.data-table {
  width: 100%;
  max-width: 420px;
  margin: 0.65rem auto;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.data-table th,
.data-table td {
  border: 1px solid var(--line);
  padding: 0.55rem 0.75rem;
  text-align: center;
}

.data-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.8rem;
  border-bottom-color: rgba(201, 166, 107, 0.45);
}

.obs {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0.5rem;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  vertical-align: middle;
}

.answer {
  margin-top: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: var(--accent-dim);
  border: 1px solid rgba(201, 166, 107, 0.3);
  color: var(--text);
  font-size: 0.95rem;
}

.scale-viz {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem;
  background: var(--bg-soft);
  border-radius: 12px;
  margin-bottom: 0.75rem;
}

.scale-map,
.scale-real {
  padding: 0.75rem 1rem;
  border: 1px dashed var(--line);
  border-radius: 10px;
  text-align: center;
  min-width: 7rem;
}

.scale-map {
  font-size: 0.85rem;
}

.scale-real {
  font-size: 1.05rem;
  border-style: solid;
  border-color: rgba(201, 166, 107, 0.35);
}

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 0.5rem 1.5rem;
  padding: 1.25rem clamp(1rem, 4vw, 3.5rem) calc(1.25rem + var(--safe-b));
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  max-width: none;
  margin: 0 auto;
  width: 100%;
}

.foot a {
  color: var(--muted);
}

.foot a:hover {
  color: var(--accent);
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Desktop: side category rail */
@media (min-width: 900px) {
  .shell {
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 2rem;
    padding-top: 1.25rem;
    align-items: start;
  }

  .cats {
    flex-direction: column;
    position: sticky;
    top: 4.5rem;
    overflow: visible;
    padding: 0;
    margin: 0;
    max-height: calc(100dvh - 5.5rem);
    overflow-y: auto;
  }

  .cat-btn {
    width: 100%;
    justify-content: flex-start;
    border-radius: 10px;
    white-space: normal;
    text-align: left;
  }
}

@media (min-width: 1400px) {
  .shell {
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 2.5rem;
    padding-left: clamp(1.5rem, 4vw, 3rem);
    padding-right: clamp(1.5rem, 4vw, 3rem);
  }

  .stage-head h1 {
    font-size: 2.45rem;
  }

  .formula {
    font-size: 1.45rem;
    padding: 1.25rem 1rem;
  }

  .formula .katex {
    font-size: 1.22em;
  }

  .card {
    padding: 1.65rem 1.75rem;
  }

  .shape-grid {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  }
}

@media (min-width: 1700px) {
  .shell {
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 3rem;
  }

  body {
    font-size: 1.06rem;
  }

  .formula {
    font-size: 1.55rem;
  }
}

/* KaTeX on dark */
.katex {
  color: var(--text);
}

.muted-math {
  color: var(--muted);
  font-size: 0.9rem;
}
