/* ============================================================
   THE INSANE MATHEMATICS OF MYSTIC — page styles
   Sits on the shared ivory/gold theme (style.css); only
   page-specific layout, charts, calculator and recommendation
   cards live here. Outcome palette:
     kill (attacker destroys)  -> gold-deep
     retreat                   -> gold
     tie (undefined rule)      -> parchment
     repelled                  -> mismatch tint
     death (attacker dies)     -> mismatch
   ============================================================ */

/* defined in cards.css on the landing page; restated so the borrowed
   .hexmap__cell tiles render their gold ring on this page too */
:root { --gold-bright: #e8cf8f; }

/* ---------- header ---------- */
.mhero {
  position: relative;
  padding: clamp(5rem, 10vw, 8rem) 1.5rem clamp(3.5rem, 7vw, 5.5rem);
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 1.4rem;
  background:
    radial-gradient(ellipse 70% 55% at 50% 30%, rgba(201,162,75,0.12) 0%, rgba(201,162,75,0) 70%),
    var(--bg);
  border-bottom: 1px solid var(--gold-faint);
}
.mhero__back {
  position: absolute; top: 1.4rem; left: 1.6rem;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--muted);
  transition: color 0.3s;
}
.mhero__back:hover { color: var(--gold-deep); }
.mhero__eyebrow {
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.42em; text-transform: uppercase;
  color: var(--gold-deep);
}
.mhero__title {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(2.1rem, 6vw, 4.6rem);
  line-height: 1.08; letter-spacing: 0.02em;
  max-width: 16ch;
  text-wrap: balance;
  background: linear-gradient(175deg, #b08a2e 15%, var(--gold-deep) 55%, #5f4712 95%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.mhero__lede {
  max-width: 62ch; color: var(--muted);
  font-size: clamp(0.98rem, 1.6vw, 1.12rem);
  text-wrap: balance;
}
.mhero__chips {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem;
  margin-top: 0.4rem;
}
.mhero__chips li {
  font-size: 0.78rem; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink);
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
  padding: 0.55rem 1.15rem;
  background: var(--surface);
}
.mhero__chips li span { color: var(--gold-deep); }

.maths-page code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.86em;
  background: var(--gold-faint);
  border: 1px solid var(--gold-soft);
  border-radius: 6px;
  padding: 0.05em 0.4em;
  color: var(--gold-deep);
}

/* ---------- sections ---------- */
.msection { position: relative; padding: clamp(4.5rem, 9vw, 7.5rem) 1.5rem; }
.msection + .msection { border-top: 1px solid var(--gold-faint); }
.msection__head { max-width: 860px; margin: 0 auto clamp(2.5rem, 5vw, 4rem); text-align: center; }
.msection__eyebrow {
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.42em; text-transform: uppercase;
  color: var(--gold-deep); margin-bottom: 1rem;
}
.msection__title {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(1.9rem, 5vw, 3.6rem);
  line-height: 1.12; letter-spacing: 0.02em;
  color: var(--ink); text-wrap: balance;
}
.msection__lede {
  margin-top: 1.3rem; color: var(--muted);
  font-size: clamp(0.98rem, 1.6vw, 1.12rem);
  text-wrap: balance;
}
.msection__lede strong, .mpanel__text strong, .mnote strong { color: var(--gold-deep); font-weight: 600; }

/* ---------- panels & grids ---------- */
.mgrid { max-width: 1100px; margin: 0 auto; display: grid; gap: 1.4rem; }
.mgrid--2 { grid-template-columns: 1fr 1fr; }
.mpanel {
  background: var(--surface);
  border: 1px solid var(--gold-faint);
  border-radius: 16px;
  padding: clamp(1.5rem, 3vw, 2.4rem);
  box-shadow: 0 18px 44px -28px rgba(34,29,18,0.18);
}
.mpanel--wide { max-width: 1100px; margin: 1.4rem auto 0; }
.mgrid + .mpanel--wide, .mpanel--wide + .mgrid { margin-top: 1.4rem; }
.mpanel__title {
  font-family: var(--font-display); font-size: 1.25rem; font-weight: 700;
  color: var(--gold-deep); margin-bottom: 0.9rem; letter-spacing: 0.04em;
}
.mpanel__text { color: var(--ink); font-size: 0.95rem; margin-bottom: 1.2rem; max-width: 72ch; }
.mpanel__text:last-child { margin-bottom: 0; }

.mnote {
  max-width: 760px; margin: clamp(2rem, 4vw, 3rem) auto 0; text-align: center;
  color: var(--muted); font-size: 0.95rem; line-height: 1.7;
}

/* ---------- charts ---------- */
.mchart { width: 100%; }
.mchart svg { display: block; width: 100%; height: auto; }
.mchart--matrix { max-width: 460px; margin: 0 auto; }
.mchart--matrix-sm { max-width: 340px; }
.mchart__half { min-width: 0; }
.mchart[data-chart="buffpower"] {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem 1.6rem;
}
.mchart__sub {
  font-family: var(--font-display); font-weight: 700; font-size: 0.85rem;
  letter-spacing: 0.08em; color: var(--muted); margin-bottom: 0.4rem;
}
.mchart[data-chart="buffpower"] .mchart__sub:nth-of-type(2) { grid-column: 2; grid-row: 1; }
.mchart[data-chart="buffpower"] .mchart__half:first-of-type { grid-column: 1; grid-row: 2; }
.mchart[data-chart="buffpower"] .mchart__half:last-of-type { grid-column: 2; grid-row: 2; }

/* SVG text + guides */
.mchart text { font-family: var(--font-display); }
.svg-label { font-size: 11.5px; font-weight: 600; fill: var(--muted); letter-spacing: 0.02em; }
.svg-value { font-size: 12px; font-weight: 700; fill: var(--ink); }
.svg-note { font-size: 10.5px; font-weight: 600; fill: var(--muted); letter-spacing: 0.04em; }
.grid-line { stroke: rgba(34,29,18,0.09); stroke-width: 1; }
.mean-line { stroke: var(--mismatch); stroke-width: 1.4; stroke-dasharray: 5 4; }

/* outcome palette (cells, segments, swatches, calculator fills).
   fill paints SVG elements; background paints HTML spans (legends, cbar). */
.mx-kill     { fill: var(--gold-deep); background: var(--gold-deep); }
.mx-retreat  { fill: var(--gold); background: var(--gold); }
.mx-tie      { fill: #ece4cf; background: #ece4cf; }
.mx-repelled { fill: rgba(176,86,58,0.32); background: rgba(176,86,58,0.32); }
.mx-death    { fill: var(--mismatch); background: var(--mismatch); }
.mx-cell { stroke: rgba(34,29,18,0.12); stroke-width: 1; }
.mx-num { font-size: 13px; font-weight: 700; fill: var(--ink); }
.mx-num--kill, .mx-num--death { fill: #f6ecc9; }
.mx-pct { font-size: 11px; font-weight: 700; fill: var(--ink); }
.mx-pct--kill, .mx-pct--death { fill: #f6ecc9; }

/* legends */
.mlegend {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 0.5rem 1.4rem; margin-top: 1.2rem;
}
.mlegend li { display: flex; align-items: center; gap: 0.5rem; font-size: 0.82rem; color: var(--muted); }
.mlegend strong { color: var(--ink); font-weight: 600; }
.mlegend__swatch {
  width: 14px; height: 14px; border-radius: 4px; flex: 0 0 auto;
  border: 1px solid rgba(34,29,18,0.12);
}

/* fact callouts */
.mfacts { display: flex; flex-direction: column; gap: 1.1rem; margin-top: 0.4rem; }
.mfacts li { display: grid; grid-template-columns: 92px 1fr; gap: 1rem; align-items: baseline; }
.mfacts strong {
  font-family: var(--font-display); font-weight: 700; font-size: 1.5rem;
  color: var(--gold-deep); line-height: 1;
}
.mfacts span { color: var(--muted); font-size: 0.92rem; line-height: 1.55; }
.mfacts span strong, .mfacts li > span > strong { font-size: inherit; }
.mfacts--row {
  flex-direction: row; flex-wrap: wrap; gap: 1rem;
}
.mfacts--row li {
  grid-template-columns: none; grid-auto-rows: auto; gap: 0.3rem;
  flex: 1 1 200px;
  border: 1px solid var(--gold-faint); border-radius: 12px;
  padding: 1rem 1.2rem;
  background: rgba(201,162,75,0.05);
}
.mfacts--row strong { font-size: 1.15rem; }

/* ---------- biome table ---------- */
.mtable-wrap { max-width: 1100px; margin: 1.4rem auto 0; overflow-x: auto; }
.mtable {
  width: 100%; border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--gold-faint); border-radius: 16px;
  font-size: 0.86rem;
}
.mtable th, .mtable td { padding: 0.85rem 1rem; text-align: left; vertical-align: top; }
.mtable thead th {
  font-family: var(--font-display); font-size: 0.7rem; font-weight: 700;
  letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold-deep);
  border-bottom: 1px solid var(--gold-soft);
}
.mtable tbody tr + tr { border-top: 1px solid var(--gold-faint); }
.mtable tbody tr:hover { background: rgba(201,162,75,0.05); }
.mtable td { color: var(--muted); line-height: 1.5; }
.mtable td:nth-child(3), .mtable td:nth-child(5) { color: var(--ink); font-weight: 500; }
.mtable__biome { display: inline-flex; align-items: center; gap: 0.55rem; font-weight: 700; color: var(--ink); white-space: nowrap; }
.mtable__biome .bicon { width: 26px; height: 26px; }
.mtable__fx--match { color: var(--gold-deep); }
.mtable__fx--mismatch { color: var(--mismatch); }
.mtable-note {
  max-width: 760px; margin: 1.2rem auto 0; text-align: center;
  color: var(--muted); font-size: 0.88rem;
}
.mtable-note em { color: var(--ink); }

/* ---------- polyhex strip ---------- */
.polyrow { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.8rem; }
.polyrow + .polyrow { margin-top: 1.4rem; }
.polyrow__cap { color: var(--muted); font-size: 0.9rem; }
.polyrow__cap strong { color: var(--gold-deep); }
.polyrow__strip { display: flex; flex-wrap: wrap; gap: 1.2rem 1.5rem; align-items: flex-end; }
/* each shape is a cluster of landing-page hero-map tiles (hexmap__cell) */
.polyshape { position: relative; display: inline-block; flex: 0 0 auto; }
.polyshape .hexmap__cell { will-change: auto; } /* static diagram — no scroll animation */

/* ---------- calculator ---------- */
.calc {
  max-width: 1100px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--gold-faint);
  border-radius: 18px;
  box-shadow: 0 24px 54px -34px rgba(34,29,18,0.25);
  padding: clamp(1.4rem, 3vw, 2.2rem);
}
.calc__controls {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 1.2rem;
  align-items: start;
}
.calc__heading {
  font-family: var(--font-display); font-weight: 700; font-size: 1.05rem;
  color: var(--gold-deep); letter-spacing: 0.06em; margin-bottom: 0.8rem;
  text-transform: uppercase;
}
.calc__label {
  display: flex; flex-direction: column; gap: 0.35rem;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 0.7rem;
}
.calc select {
  font-family: var(--font-body); font-size: 0.92rem; font-weight: 500;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--gold-soft); border-radius: 10px;
  padding: 0.6rem 0.7rem;
  width: 100%;
  cursor: pointer;
  transition: border-color 0.3s;
}
.calc select:hover, .calc select:focus { border-color: var(--gold); outline: none; }
.calc__custom {
  border: 1px dashed var(--gold-soft); border-radius: 12px;
  padding: 0.8rem 0.9rem 0.2rem; margin-bottom: 0.7rem;
}
.calc__stat { font-size: 0.85rem; color: var(--muted); line-height: 1.55; min-height: 3em; }
.calc__stat strong { color: var(--gold-deep); }
.calc__tile {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  padding-top: 0.4rem; min-width: 190px;
}
.calc__vs {
  font-family: var(--font-display); font-style: italic; font-weight: 700;
  color: var(--gold); font-size: 1.3rem;
}
.calc__hint { font-size: 0.75rem; color: var(--muted); text-align: center; max-width: 26ch; line-height: 1.5; }
.calc__results {
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 1.6rem;
  margin-top: 1.6rem; padding-top: 1.4rem;
  border-top: 1px dashed var(--gold-soft);
  align-items: center;
}
.calc__bars { display: flex; flex-direction: column; gap: 0.65rem; }
.calc__matrixwrap { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; }

.cbar { display: grid; grid-template-columns: 128px 1fr 92px; gap: 0.8rem; align-items: center; }
.cbar__label { display: flex; flex-direction: column; line-height: 1.25; }
.cbar__label strong { font-size: 0.85rem; color: var(--ink); font-weight: 700; }
.cbar__label span { font-size: 0.68rem; color: var(--muted); letter-spacing: 0.03em; }
.cbar__track {
  height: 16px; border-radius: 8px;
  background: rgba(34,29,18,0.06);
  overflow: hidden;
}
.cbar__fill {
  display: block; height: 100%; border-radius: 8px;
  transition: width 0.7s var(--ease-out);
}
.cbar__val { font-size: 0.85rem; font-weight: 700; color: var(--ink); white-space: nowrap; }
.cbar__val em { font-style: normal; font-weight: 500; color: var(--muted); font-size: 0.75rem; }

/* ---------- recommendations ---------- */
.recs {
  max-width: 900px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 1.3rem;
}
.rec {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--gold-faint);
  border-left: 3px solid var(--gold);
  border-radius: 0 16px 16px 0;
  padding: clamp(1.5rem, 3vw, 2.2rem) clamp(1.5rem, 3vw, 2.4rem) clamp(1.5rem, 3vw, 2.2rem) clamp(4.2rem, 6vw, 5rem);
  box-shadow: 0 18px 44px -30px rgba(34,29,18,0.2);
}
.rec__num {
  position: absolute; left: 1.3rem; top: 1.5rem;
  font-family: var(--font-display); font-weight: 700; font-size: 1.15rem;
  color: var(--gold); letter-spacing: 0.04em;
}
.rec__title {
  font-family: var(--font-display); font-weight: 700; font-size: 1.25rem;
  color: var(--ink); letter-spacing: 0.03em; margin-bottom: 0.8rem;
}
.rec p { color: var(--muted); font-size: 0.95rem; line-height: 1.7; }
.rec p + p { margin-top: 0.8rem; }
.rec p strong { color: var(--gold-deep); font-weight: 600; }
.rec__action {
  padding-top: 0.9rem;
  border-top: 1px dashed var(--gold-soft);
  color: var(--ink) !important;
}
.rec__action::before {
  content: "Action — ";
  font-weight: 700; color: var(--gold-deep);
  letter-spacing: 0.04em;
}

/* ---------- reveal (JS-gated so no-JS users see everything) ---------- */
.maths-js [data-mreveal] {
  opacity: 0; transform: translateY(26px);
  transition: opacity 0.8s var(--ease-out), transform 0.8s var(--ease-out);
}
.maths-js [data-mreveal].is-in { opacity: 1; transform: none; }

/* ---------- responsive ---------- */
@media (max-width: 1024px) {
  .mgrid--2 { grid-template-columns: 1fr; }
  .calc__results { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .calc__controls { grid-template-columns: 1fr; }
  .calc__tile { padding: 0.4rem 0; }
  .mchart[data-chart="buffpower"] { grid-template-columns: 1fr; }
  .mchart[data-chart="buffpower"] .mchart__sub:nth-of-type(2) { grid-column: 1; grid-row: auto; }
  .mchart[data-chart="buffpower"] .mchart__half:first-of-type,
  .mchart[data-chart="buffpower"] .mchart__half:last-of-type { grid-column: 1; grid-row: auto; }
  .mfacts li { grid-template-columns: 76px 1fr; }
  .cbar { grid-template-columns: 96px 1fr 84px; gap: 0.55rem; }
  .mhero__back { position: static; margin-bottom: 0.6rem; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .maths-js [data-mreveal] { opacity: 1; transform: none; transition: none; }
  .cbar__fill { transition: none; }
}
