/* ABOUTME: Stylesheet for the Introduction to Sankhya GitHub Pages site.
   ABOUTME: Night-manuscript theme: indigo ink ground, manuscript gold, palm-leaf text. */

:root {
  --ink: #eff6fb;        /* akasha — barely-visible sky blue ground */
  --ink-raised: #ffffff;  /* raised panels */
  --ink-line: #cfdfea;    /* hairlines */
  --palm: #1c2a3a;       /* manuscript ink — primary text */
  --palm-dim: #48586a;   /* dimmer ink */
  --gold: #b26910;       /* kesari deepened to ochre for light ground */
  --vermilion: #bf2e1c;  /* sindoor deepened for light ground */
  --faded: #5f7284;      /* vibhuti ash — secondary text */
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --display: "Marcellus", "Cormorant Garamond", Georgia, serif;
  --body: "Alegreya Sans", "Gill Sans", "Segoe UI", sans-serif;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--ink);
  color: var(--palm);
  font-family: var(--body);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 62rem; margin: 0 auto; padding: 0 1.5rem; }

a { color: var(--gold); text-decoration: none; border-bottom: 1px solid rgba(178, 105, 16, 0.4); }
a:hover { color: var(--palm); border-bottom-color: var(--palm); }
a:focus-visible, summary:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 2px; }

/* ---------- Hero ---------- */

.hero {
  position: relative;
  padding: 7rem 0 5rem;
  overflow: hidden;
  border-bottom: 1px solid var(--ink-line);
}

.hero-glyph {
  position: absolute;
  top: 50%; right: -2rem;
  transform: translateY(-50%);
  font-family: "Noto Serif Devanagari", serif;
  font-size: clamp(14rem, 30vw, 24rem);
  line-height: 1;
  color: rgba(178, 105, 16, 0.1);
  user-select: none;
  pointer-events: none;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--vermilion);
  margin-bottom: 1.25rem;
}

.hero h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(3rem, 8vw, 5.5rem);
  letter-spacing: 0.04em;
  color: var(--palm);
}

.hero .translit {
  font-family: var(--display);
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  color: var(--gold);
  letter-spacing: 0.12em;
  margin: 0.25rem 0 1.75rem;
}

.hero .thesis { max-width: 34rem; color: var(--palm-dim); font-size: 1.125rem; }

.master {
  margin-top: 3rem;
  display: inline-block;
  border: 1px solid var(--ink-line);
  border-left: 3px solid var(--gold);
  background: var(--ink-raised);
  padding: 1.25rem 1.75rem;
}
.master .eq { font-family: var(--mono); font-size: 1.35rem; color: var(--palm); }
.master .eq b { color: var(--gold); font-weight: 600; }
.master .note { font-size: 0.85rem; color: var(--faded); margin-top: 0.4rem; }

@media (prefers-reduced-motion: no-preference) {
  .hero > .wrap > * { animation: rise 0.7s ease both; }
  .hero > .wrap > *:nth-child(2) { animation-delay: 0.08s; }
  .hero > .wrap > *:nth-child(3) { animation-delay: 0.16s; }
  .hero > .wrap > *:nth-child(4) { animation-delay: 0.24s; }
  .hero > .wrap > *:nth-child(5) { animation-delay: 0.32s; }
  @keyframes rise { from { opacity: 0; transform: translateY(0.75rem); } to { opacity: 1; transform: none; } }
}

/* ---------- Sections ---------- */

section { padding: 4.5rem 0; border-bottom: 1px solid var(--ink-line); }
section:last-of-type { border-bottom: none; }

.sec-label {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--vermilion);
  margin-bottom: 0.75rem;
}

h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  letter-spacing: 0.03em;
  color: var(--palm);
  margin-bottom: 1.5rem;
}

h3 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.25rem;
  color: var(--gold);
  margin: 2rem 0 0.75rem;
}

p + p { margin-top: 1rem; }
.lede { font-size: 1.2rem; color: var(--palm); max-width: 40rem; }
.muted { color: var(--faded); }
.small { font-size: 0.9rem; }

em.skt { font-style: normal; color: var(--gold); }

/* ---------- Principle triad ---------- */

.triad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--ink-line); border: 1px solid var(--ink-line); margin-top: 2rem; }
.triad > div { background: var(--ink-raised); padding: 1.5rem; }
.triad .skt-head { font-family: var(--display); font-size: 1.2rem; color: var(--gold); }
.triad .gloss { font-family: var(--mono); font-size: 0.75rem; color: var(--faded); letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 0.6rem; }

/* ---------- Axiom cards ---------- */

.ax-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 1.25rem; margin-top: 2rem; }

.ax-cat { border: 1px solid var(--ink-line); background: var(--ink-raised); padding: 1.5rem; }
.ax-cat h3 { margin-top: 0; }
.ax-cat ul { list-style: none; }
.ax-cat li { padding: 0.6rem 0; border-top: 1px dashed var(--ink-line); display: grid; grid-template-columns: 2.6rem 1fr; gap: 0.6rem; align-items: baseline; }
.ax-cat li:first-child { border-top: none; }
.ax-id { font-family: var(--mono); font-size: 0.8rem; color: var(--vermilion); }
.ax-form { display: block; font-family: var(--mono); font-size: 0.82rem; color: var(--gold); margin-top: 0.2rem; }

/* ---------- Cascade (signature) ---------- */

.cascade { margin-top: 2.5rem; position: relative; max-width: 44rem; }
.cascade::before {
  content: "";
  position: absolute; left: 1.1rem; top: 1.5rem; bottom: 1.5rem;
  width: 1px; background: linear-gradient(var(--gold), var(--vermilion));
  opacity: 0.5;
}
.cnode { position: relative; padding: 0 0 2.25rem 3.25rem; }
.cnode:last-child { padding-bottom: 0; }
.cnode::before {
  content: "";
  position: absolute; left: 0.7rem; top: 0.45rem;
  width: 0.85rem; height: 0.85rem;
  border: 1px solid var(--gold);
  background: var(--ink);
  transform: rotate(45deg);
}
.cnode .cval { font-family: var(--mono); font-size: 1.05rem; color: var(--palm); }
.cnode .cval b { color: var(--gold); font-weight: 600; }
.cnode .cwhy { color: var(--palm-dim); margin-top: 0.35rem; max-width: 36rem; }
.cnode .csrc { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.14em; color: var(--vermilion); text-transform: uppercase; margin-top: 0.4rem; }

/* ---------- Octant figure ---------- */

.octants { display: grid; grid-template-columns: repeat(4, minmax(3.5rem, 5.5rem)); gap: 0.5rem; margin: 2rem 0 1rem; }
.octants div {
  aspect-ratio: 1;
  border: 1px solid var(--ink-line);
  background: var(--ink-raised);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 0.75rem; color: var(--faded);
}
.octants .lit {
  background: linear-gradient(135deg, rgba(178,105,16,0.28), rgba(191,46,28,0.2));
  border-color: var(--gold);
  color: var(--palm);
}
.fig-cap { font-size: 0.85rem; color: var(--faded); max-width: 30rem; }

/* ---------- Tables ---------- */

table { width: 100%; border-collapse: collapse; margin-top: 2rem; font-size: 0.95rem; }
th { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--vermilion); text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--ink-line); }
td { padding: 0.7rem 0.75rem; border-bottom: 1px dashed var(--ink-line); vertical-align: top; }
td.mono { font-family: var(--mono); font-size: 0.85rem; color: var(--gold); }
.table-scroll { overflow-x: auto; }

/* ---------- Reading list ---------- */

.readings { list-style: none; margin-top: 1.5rem; }
.readings li { padding: 0.75rem 0; border-bottom: 1px dashed var(--ink-line); display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: baseline; }
.readings .tag { font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--vermilion); min-width: 6.5rem; }

/* ---------- Footer ---------- */

footer { padding: 3rem 0 4rem; color: var(--faded); font-size: 0.9rem; border-top: 1px solid var(--ink-line); }
footer p + p { margin-top: 0.5rem; }

/* ---------- Derivation theater ---------- */

.theater { border: 1px solid var(--ink-line); background: var(--ink-raised); padding: 1.5rem; margin-top: 2rem; max-width: 44rem; }
.dw-btn {
  font-family: var(--mono); font-size: 0.8rem; letter-spacing: 0.08em;
  color: var(--ink-raised); background: var(--gold); border: 1px solid var(--gold);
  padding: 0.55rem 1rem; cursor: pointer;
}
.dw-btn:hover:not(:disabled) { background: var(--vermilion); border-color: var(--vermilion); }
.dw-btn:focus-visible { outline: 2px solid var(--palm); outline-offset: 2px; }
.th-grid { display: grid; grid-template-columns: 15rem 1fr; gap: 1.5rem; align-items: center; }
.th-stage { display: grid; place-items: center; }
.th-sym { font-family: var(--display); font-size: 2rem; color: var(--vermilion); line-height: 1; }
.th-eq { font-family: var(--mono); font-size: 0.9rem; color: var(--palm); margin-top: 0.5rem; }
.th-val { font-family: var(--mono); font-size: 1.35rem; font-weight: 600; color: var(--gold); min-height: 1.8rem; margin-top: 0.35rem; overflow-wrap: anywhere; }
.th-note { font-size: 0.9rem; color: var(--faded); margin-top: 0.5rem; min-height: 3.4rem; }
.th-controls { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: center; margin-top: 1.25rem; }
.th-dots { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.th-dot {
  font-family: var(--mono); font-size: 0.75rem; color: var(--palm-dim);
  background: transparent; border: 1px solid var(--ink-line);
  min-width: 2.2rem; padding: 0.35rem 0.4rem; cursor: pointer;
}
.th-dot:hover { color: var(--vermilion); border-color: var(--vermilion); }
.th-dot:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.th-dot-active { color: var(--ink-raised); background: var(--gold); border-color: var(--gold); }
.theater .fig-cap { margin-top: 1rem; }

/* Theater scenes: each constant gets its geometric move */
.th-seven .oct {
  transform: translate3d(calc(var(--sx) * 40px), calc(var(--sy) * 40px), calc(var(--sz) * 40px));
}
.th-seven .oct:not(.oct-observed) { opacity: 0.3; }

@media (prefers-reduced-motion: no-preference) {
  .th-x .cube-asm { animation: th-shrink 2.4s ease-in-out infinite; }
  .th-phi .cube-asm { animation: th-grow 2.4s ease-in-out infinite; }
  .th-k .cube-asm { animation: th-double 2.4s ease-in-out infinite; }
  .th-pho .cube-asm { animation: th-breathe 1.05s ease-in-out infinite; }
  .th-c .cube-asm { animation: th-spin 1.4s linear infinite; }
  .th-atomic .cube-asm { animation: th-recede 2s ease-in forwards; }
  @keyframes th-shrink {
    0%, 100% { transform: rotateX(-24deg) rotateY(-38deg) scale3d(1, 1, 1); }
    50% { transform: rotateX(-24deg) rotateY(-38deg) scale3d(0.618, 0.618, 0.618); }
  }
  @keyframes th-grow {
    0%, 100% { transform: rotateX(-24deg) rotateY(-38deg) scale3d(0.75, 0.75, 0.75); }
    50% { transform: rotateX(-24deg) rotateY(-38deg) scale3d(1.214, 1.214, 1.214); }
  }
  @keyframes th-double {
    0%, 100% { transform: rotateX(-24deg) rotateY(-38deg) scale3d(1, 1, 1); }
    45%, 55% { transform: rotateX(-24deg) rotateY(-38deg) scale3d(1.2599, 1.2599, 1.2599); }
  }
  @keyframes th-breathe {
    0%, 100% { transform: rotateX(-24deg) rotateY(-38deg) scale3d(1.05, 1.05, 1.05); }
    50% { transform: rotateX(-24deg) rotateY(-38deg) scale3d(0.94, 0.94, 0.94); }
  }
  @keyframes th-spin {
    from { transform: rotateX(-24deg) rotateY(-38deg); }
    to { transform: rotateX(-24deg) rotateY(322deg); }
  }
  @keyframes th-recede {
    from { transform: rotateX(-24deg) rotateY(-38deg) scale3d(1, 1, 1); }
    to { transform: rotateX(-24deg) rotateY(-38deg) scale3d(0.08, 0.08, 0.08); }
  }
}

/* ---------- Interactive 1→8 cube ---------- */

.cube-stage { margin: 2.5rem 0 1rem; cursor: pointer; user-select: none; width: fit-content; }
.cube-stage:focus-visible { outline: 2px solid var(--gold); outline-offset: 6px; }
.cube-scene { width: 14rem; height: 14rem; perspective: 900px; display: grid; place-items: center; }
.cube-asm {
  position: relative; width: 0; height: 0;
  transform-style: preserve-3d;
  transform: rotateX(-24deg) rotateY(-38deg);
  transition: transform 0.6s ease;
}
.cube-stage:hover .cube-asm { transform: rotateX(-20deg) rotateY(-24deg); }
.oct {
  position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  transform-style: preserve-3d;
  transform: translate3d(calc(var(--sx) * 22px), calc(var(--sy) * 22px), calc(var(--sz) * 22px));
  transition: transform 0.6s ease, opacity 0.6s ease;
}
.cube-stage.split .oct {
  transform: translate3d(calc(var(--sx) * 40px), calc(var(--sy) * 40px), calc(var(--sz) * 40px));
}
.cube-stage.split .oct:not(.oct-observed) { opacity: 0.3; }
.face {
  position: absolute; width: 44px; height: 44px;
  background: var(--ink-raised); border: 1px solid var(--ink-line);
}
.oct-observed .face { border-color: var(--gold); background: linear-gradient(135deg, rgba(178,105,16,0.3), rgba(191,46,28,0.22)); }
.face-front  { transform: translateZ(22px); }
.face-back   { transform: rotateY(180deg) translateZ(22px); }
.face-right  { transform: rotateY(90deg) translateZ(22px); }
.face-left   { transform: rotateY(-90deg) translateZ(22px); }
.face-top    { transform: rotateX(90deg) translateZ(22px); }
.face-bottom { transform: rotateX(-90deg) translateZ(22px); }
.cube-hint { font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.08em; color: var(--faded); max-width: 16rem; }

/* ---------- Scroll reveals & progress ---------- */

@media (prefers-reduced-motion: no-preference) {
  html.js main section .wrap { opacity: 0; transform: translateY(1.25rem); transition: opacity 0.7s ease, transform 0.7s ease; }
  html.js main section .wrap.revealed { opacity: 1; transform: none; }
}

@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    body::before {
      content: ""; position: fixed; top: 0; left: 0; z-index: 99;
      width: 100%; height: 3px;
      background: linear-gradient(90deg, var(--gold), var(--vermilion));
      transform-origin: left; transform: scaleX(0);
      animation: page-progress linear both;
      animation-timeline: scroll(root);
    }
    @keyframes page-progress { from { transform: scaleX(0); } to { transform: scaleX(1); } }
  }
}

/* ---------- Theory figures ---------- */

.fig-anim { margin: 2.25rem 0 0; max-width: 44rem; }
.fig-anim canvas { display: block; width: 100%; border: 1px solid var(--ink-line); background: var(--ink-raised); }
.fig-anim .fig-cap { margin-top: 0.6rem; }

.fig-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; margin-top: 2rem; }
.fig-strip figure { margin: 0; border: 1px solid var(--ink-line); background: var(--ink-raised); padding: 1rem; }
.fig-strip svg { display: block; width: 100%; height: auto; }
.fig-strip .fig-cap { margin-top: 0.5rem; }
.fig-svg-text { font-family: var(--mono); font-size: 10px; fill: var(--faded); }

/* ---------- Responsive ---------- */

@media (max-width: 44rem) {
  .hero { padding: 4.5rem 0 3.5rem; }
  .master .eq { font-size: 1.05rem; }
  .th-grid { grid-template-columns: 1fr; }
  .th-stage { order: -1; }
  .fig-strip { grid-template-columns: 1fr; }
  .triad { grid-template-columns: 1fr; }
  .octants { grid-template-columns: repeat(4, 1fr); }
  section { padding: 3.25rem 0; }
}
