// Direction B — SANCTUARY
// Nature-inspired. Asymmetric two-column. Ridge motif as ornament.
// Sage accent on numerals. Slightly more distinctive than Field Notes.

const scStyles = {
  hero: {
    paddingBottom: 18, borderBottom: "0.5px solid var(--sr-sage-haze)",
    marginBottom: 14,
  },
  pageTitle: {
    fontFamily: "var(--sr-serif)", fontWeight: 300, fontStyle: "italic",
    fontSize: 56, lineHeight: 1.0, letterSpacing: "-0.01em",
    color: "var(--sr-sage-mid)", margin: "10px 0 0",
  },
  deck: {
    fontFamily: "var(--sr-serif)", fontWeight: 400,
    fontSize: 14, lineHeight: 1.55, color: "var(--sr-ink)",
    margin: "8px 0 0", maxWidth: "60ch",
  },
  bigInitial: {
    fontFamily: "var(--sr-serif)", fontWeight: 300,
    fontSize: 64, lineHeight: 0.8, color: "var(--sr-sage)",
    letterSpacing: "0.02em",
  },
  numTick: {
    fontFamily: "var(--sr-sans)", fontSize: 9, fontWeight: 600,
    letterSpacing: "0.12em", color: "var(--sr-sage)",
  },
};

const RidgeRule = ({ color = "var(--sr-sage-mid)", opacity = 0.6, margin = "20px 0" }) => (
  <div style={{ display: "flex", alignItems: "center", gap: 10, margin }}>
    <div style={{ flex: 1, height: 0, borderTop: "0.5px solid var(--sr-sage-haze)" }} />
    <svg viewBox="0 0 40 12" width="32" height="10" style={{ opacity }}>
      <path d="M 1 11 L 10 4 L 16 8 L 23 2 L 30 7 L 39 11" stroke={color}
        strokeWidth="1.2" fill="none" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
    <div style={{ flex: 1, height: 0, borderTop: "0.5px solid var(--sr-sage-haze)" }} />
  </div>
);

// ─────────────────────────────────────────────────────────────────────
function EmotionsSC() {
  const c = window.SR_CONTENT.emotions;
  return (
    <SRPage pageNumber={1} pageOf={1} doc="emotions" padding="60px 72px 56px">
      <div style={scStyles.hero}>
        <Eyebrow>{c.eyebrow}</Eyebrow>
        <div style={{ display: "flex", alignItems: "center", gap: 12, margin: "10px 0 4px" }}>
          <div style={{ flex: 1, height: 0, borderTop: "0.5px solid var(--sr-sage-haze)" }} />
          <RidgeMark width={48} style={{ opacity: 0.75 }} />
          <div style={{ flex: 1, height: 0, borderTop: "0.5px solid var(--sr-sage-haze)" }} />
        </div>
        <h1 style={{ ...scStyles.pageTitle, fontSize: 50 }}>{c.title}</h1>
        <p style={scStyles.deck}>{c.deck}</p>
      </div>

      <p style={{
        fontFamily: "var(--sr-serif)", fontStyle: "italic",
        fontSize: 13, lineHeight: 1.55, color: "var(--sr-sage-mid)",
        margin: "16px 0 0", maxWidth: "56ch",
      }}>{c.intro}</p>

      <div style={{ display: "flex", justifyContent: "center", margin: "8px 0 12px" }}>
        <FeelingWheel size={660} mode="color" />
      </div>

      <RidgeRule margin="6px 0 14px" />

      <div style={{ display: "grid", gridTemplateColumns: "160px 1fr", gap: 24 }}>
        <Caps>A Note from the Practice</Caps>
        <div>
          <p style={{
            fontFamily: "var(--sr-serif)", fontStyle: "italic",
            fontSize: 12.5, lineHeight: 1.55, color: "var(--sr-ink)", margin: 0,
          }}>{c.note}</p>
          <p style={{
            fontFamily: "var(--sr-sans)", fontSize: 8.5, letterSpacing: "0.18em",
            textTransform: "uppercase", color: "var(--sr-sage-pale)", marginTop: 8,
          }}>{c.attribution}</p>
        </div>
      </div>
    </SRPage>
  );
}

// ─────────────────────────────────────────────────────────────────────
function GroundingSC() {
  const c = window.SR_CONTENT.grounding;
  const startNumbers = {
    "The Five Senses": 1, "Breath": 13,
    "Mind & Naming": 39, "Imagery": 47,
    "Self-Compassion": 53, "With Your Hands": 61,
  };
  const colLeft  = [c.groups[0], c.groups[3], c.groups[4]];
  const colRight = [c.groups[1], c.groups[5], c.groups[6]];

  const renderGroup = (g) => {
    let n = startNumbers[g.name];
    return (
      <section key={g.name} style={{ breakInside: "avoid", marginBottom: 16 }}>
        <div style={{
          display: "flex", alignItems: "center", gap: 10,
          margin: "0 0 8px",
        }}>
          <svg viewBox="0 0 24 12" width="14" height="7"><path d="M 1 11 L 8 3 L 12 7 L 16 2 L 23 11" stroke="var(--sr-sage)" strokeWidth="1.4" fill="none" strokeLinecap="round" strokeLinejoin="round" /></svg>
          <span style={{
            fontFamily: "var(--sr-sans)", fontSize: 10, letterSpacing: "0.22em",
            textTransform: "uppercase", fontWeight: 500, color: "var(--sr-sage-mid)",
          }}>{g.name}</span>
        </div>
        <ol style={{ margin: 0, padding: 0, listStyle: "none" }}>
          {g.items.map(item => {
            const num = n; n += 1;
            return (
              <li key={item} style={{
                display: "grid", gridTemplateColumns: "22px 1fr", gap: 4,
                fontFamily: "var(--sr-serif)", fontSize: 10.5, lineHeight: 1.5,
                color: "var(--sr-ink)", padding: "2px 0",
              }}>
                <span style={scStyles.numTick}>{String(num).padStart(2, "0")}</span>
                <span>{item}</span>
              </li>
            );
          })}
        </ol>
      </section>
    );
  };

  return (
    <SRPage pageNumber={1} pageOf={2} doc="grounding" padding="60px 72px 56px">
      <div style={scStyles.hero}>
        <Eyebrow>{c.eyebrow}</Eyebrow>
        <div style={{ display: "flex", alignItems: "center", gap: 12, margin: "10px 0 4px" }}>
          <div style={{ flex: 1, height: 0, borderTop: "0.5px solid var(--sr-sage-haze)" }} />
          <RidgeMark width={48} style={{ opacity: 0.75 }} />
          <div style={{ flex: 1, height: 0, borderTop: "0.5px solid var(--sr-sage-haze)" }} />
        </div>
        <h1 style={{ ...scStyles.pageTitle, fontSize: 50 }}>{c.title}</h1>
        <p style={scStyles.deck}>{c.deck}</p>
      </div>

      <p style={{
        fontFamily: "var(--sr-serif)", fontStyle: "italic",
        fontSize: 13, lineHeight: 1.55, color: "var(--sr-sage-mid)",
        margin: "16px 0 0", maxWidth: "56ch",
      }}>{c.intro}</p>

      <RidgeRule margin="14px 0 12px" />

      <div style={{
        display: "grid", gridTemplateColumns: "1fr 1fr", columnGap: 36,
        alignItems: "start",
      }}>
        <div>{colLeft.map(renderGroup)}</div>
        <div>{colRight.map(renderGroup)}</div>
      </div>
    </SRPage>
  );
}

// ─────────────────────────────────────────────────────────────────────
function RosenbergSC() {
  const c = window.SR_CONTENT.rosenberg;
  return (
    <SRPage pageNumber={1} pageOf={1} doc="rosenberg">
      <div style={scStyles.hero}>
        <Eyebrow>{c.eyebrow}</Eyebrow>
        <div style={{ display: "flex", alignItems: "center", gap: 12, margin: "10px 0 4px" }}>
          <div style={{ flex: 1, height: 0, borderTop: "0.5px solid var(--sr-sage-haze)" }} />
          <RidgeMark width={48} style={{ opacity: 0.75 }} />
          <div style={{ flex: 1, height: 0, borderTop: "0.5px solid var(--sr-sage-haze)" }} />
        </div>
        <h1 style={{ ...scStyles.pageTitle, fontSize: 46 }}>{c.title}</h1>
        <p style={scStyles.deck}>{c.deck}</p>
      </div>

      <p style={{
        fontFamily: "var(--sr-serif)", fontStyle: "italic",
        fontSize: 13, lineHeight: 1.55, color: "var(--sr-sage-mid)",
        margin: "18px 0 16px", maxWidth: "60ch",
      }}>{c.intro}</p>

      {/* Legend */}
      <div style={{
        display: "flex", gap: 28, alignItems: "center",
        padding: "10px 16px", background: "var(--sr-cream-soft)",
        borderTop: "0.5px solid var(--sr-sage-haze)",
        borderBottom: "0.5px solid var(--sr-sage-haze)",
        marginBottom: 4,
      }}>
        {c.legend.map(([k, v]) => (
          <span key={k} style={{ display: "flex", alignItems: "baseline", gap: 8 }}>
            <strong style={{
              fontFamily: "var(--sr-sans)", fontSize: 10.5, letterSpacing: "0.2em",
              color: "var(--sr-sage)", fontWeight: 600,
            }}>{k}</strong>
            <span style={{
              fontFamily: "var(--sr-serif)", fontSize: 12, fontStyle: "italic",
              color: "var(--sr-ink)",
            }}>{v}</span>
          </span>
        ))}
      </div>

      {/* Items */}
      <ol style={{ margin: 0, padding: 0, listStyle: "none" }}>
        {c.items.map((item, i) => (
          <li key={i} style={{
            display: "grid", gridTemplateColumns: "34px 1fr 36px 36px 36px 36px",
            alignItems: "center",
            padding: "9px 8px",
            background: i % 2 === 0 ? "transparent" : "var(--sr-cream-soft)",
          }}>
            <span style={{
              fontFamily: "var(--sr-sans)", fontSize: 10, letterSpacing: "0.14em",
              color: "var(--sr-sage)", fontWeight: 600,
            }}>{String(i + 1).padStart(2, "0")}</span>
            <span style={{
              fontFamily: "var(--sr-serif)", fontSize: 13, lineHeight: 1.35,
              color: "var(--sr-ink)",
            }}>{item}</span>
            {[0,1,2,3].map(k => (
              <span key={k} style={{ display: "flex", justifyContent: "center" }}>
                <span style={{
                  width: 16, height: 16, border: "0.75px solid var(--sr-sage)", borderRadius: 9,
                }} />
              </span>
            ))}
          </li>
        ))}
      </ol>

      <p style={{
        marginTop: 12, fontFamily: "var(--sr-serif)", fontStyle: "italic",
        fontSize: 11, color: "var(--sr-sage-pale)",
      }}>Public domain. Reproduced from Rosenberg, M. (1965).</p>

      {/* Scoring & Interpretation */}
      <div style={{
        marginTop: 18,
        display: "grid", gridTemplateColumns: "1fr 1fr", columnGap: 28,
      }}>
        <div>
          <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 8 }}>
            <svg viewBox="0 0 24 12" width="14" height="7"><path d="M 1 11 L 8 3 L 12 7 L 16 2 L 23 11" stroke="var(--sr-sage)" strokeWidth="1.4" fill="none" strokeLinecap="round" strokeLinejoin="round" /></svg>
            <span style={{
              fontFamily: "var(--sr-sans)", fontSize: 10, letterSpacing: "0.22em",
              textTransform: "uppercase", fontWeight: 500, color: "var(--sr-sage-mid)",
            }}>Scoring</span>
          </div>
          <p style={{
            fontFamily: "var(--sr-serif)", fontStyle: "italic", fontSize: 11,
            color: "var(--sr-sage-mid)", margin: "0 0 6px",
          }}>Items 1, 3, 4, 7, 10</p>
          <div style={{
            display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 0,
            border: "0.5px solid var(--sr-sage-haze)", background: "var(--sr-sage-haze)",
            marginBottom: 12,
          }}>
            {c.scoringStandard.map(([label, val]) => (
              <div key={label} style={{ background: "var(--sr-cream-soft)", padding: "6px 4px", textAlign: "center" }}>
                <div style={{ fontFamily: "var(--sr-sans)", fontSize: 8, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--sr-sage-mid)" }}>{label.split(' ').map(w => w[0]).join('')}</div>
                <div style={{ fontFamily: "var(--sr-serif)", fontSize: 18, color: "var(--sr-sage)", fontWeight: 500 }}>{val}</div>
              </div>
            ))}
          </div>
          <p style={{
            fontFamily: "var(--sr-serif)", fontStyle: "italic", fontSize: 11,
            color: "var(--sr-sage-mid)", margin: "0 0 6px",
          }}>Items 2, 5, 6, 8, 9 — reverse-scored</p>
          <div style={{
            display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 0,
            border: "0.5px solid var(--sr-sage-haze)", background: "var(--sr-sage-haze)",
          }}>
            {c.scoringReverse.map(([label, val]) => (
              <div key={label} style={{ background: "var(--sr-cream-soft)", padding: "6px 4px", textAlign: "center" }}>
                <div style={{ fontFamily: "var(--sr-sans)", fontSize: 8, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--sr-sage-mid)" }}>{label.split(' ').map(w => w[0]).join('')}</div>
                <div style={{ fontFamily: "var(--sr-serif)", fontSize: 18, color: "var(--sr-sage)", fontWeight: 500 }}>{val}</div>
              </div>
            ))}
          </div>
        </div>
        <div>
          <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 8 }}>
            <svg viewBox="0 0 24 12" width="14" height="7"><path d="M 1 11 L 8 3 L 12 7 L 16 2 L 23 11" stroke="var(--sr-sage)" strokeWidth="1.4" fill="none" strokeLinecap="round" strokeLinejoin="round" /></svg>
            <span style={{
              fontFamily: "var(--sr-sans)", fontSize: 10, letterSpacing: "0.22em",
              textTransform: "uppercase", fontWeight: 500, color: "var(--sr-sage-mid)",
            }}>Interpretation</span>
          </div>
          <ul style={{ margin: 0, padding: 0, listStyle: "none" }}>
            {c.bands.map(([range, label, desc]) => (
              <li key={range} style={{
                padding: "8px 0",
                borderBottom: "0.5px solid var(--sr-sage-haze)",
              }}>
                <div style={{ display: "flex", alignItems: "baseline", gap: 10 }}>
                  <span style={{
                    fontFamily: "var(--sr-sans)", fontSize: 10.5, letterSpacing: "0.1em",
                    color: "var(--sr-sage)", fontWeight: 600, fontVariantNumeric: "tabular-nums",
                  }}>{range}</span>
                  <span style={{
                    fontFamily: "var(--sr-serif)", fontSize: 13, fontStyle: "italic",
                    color: "var(--sr-ink)",
                  }}>{label}</span>
                </div>
                <p style={{
                  fontFamily: "var(--sr-serif)", fontSize: 11, lineHeight: 1.5,
                  color: "var(--sr-sage-mid)", margin: "2px 0 0",
                }}>{desc}</p>
              </li>
            ))}
          </ul>
          <p style={{
            fontFamily: "var(--sr-serif)", fontStyle: "italic", fontSize: 11,
            color: "var(--sr-ink)", lineHeight: 1.55, marginTop: 10,
          }}>{c.note}</p>
        </div>
      </div>
    </SRPage>
  );
}

// ─────────────────────────────────────────────────────────────────────
// GROUNDING — SANCTUARY — Page 2
// The Body (20) + Movement (6) + When the Body Is Activated (6)
function GroundingSC2() {
  const c = window.SR_CONTENT.grounding;
  const groupByName = Object.fromEntries(c.groups.map(g => [g.name, g]));

  const renderGroup = (name, startNum) => {
    const g = groupByName[name];
    let n = startNum;
    return (
      <section key={name} style={{ breakInside: "avoid", marginBottom: 16 }}>
        <div style={{
          display: "flex", alignItems: "center", gap: 10,
          margin: "0 0 8px",
        }}>
          <svg viewBox="0 0 24 12" width="14" height="7"><path d="M 1 11 L 8 3 L 12 7 L 16 2 L 23 11" stroke="var(--sr-sage)" strokeWidth="1.4" fill="none" strokeLinecap="round" strokeLinejoin="round" /></svg>
          <span style={{
            fontFamily: "var(--sr-sans)", fontSize: 10, letterSpacing: "0.22em",
            textTransform: "uppercase", fontWeight: 500, color: "var(--sr-sage-mid)",
          }}>{name}</span>
        </div>
        <ol style={{ margin: 0, padding: 0, listStyle: "none" }}>
          {g.items.map(item => {
            const num = n; n += 1;
            return (
              <li key={item} style={{
                display: "grid", gridTemplateColumns: "22px 1fr", gap: 4,
                fontFamily: "var(--sr-serif)", fontSize: 10.5, lineHeight: 1.5,
                color: "var(--sr-ink)", padding: "2px 0",
              }}>
                <span style={scStyles.numTick}>{String(num).padStart(2, "0")}</span>
                <span>{item}</span>
              </li>
            );
          })}
        </ol>
      </section>
    );
  };

  return (
    <SRPage pageNumber={2} pageOf={2} doc="grounding" padding="60px 72px 56px">
      <div style={scStyles.hero}>
        <Eyebrow>Grounding Reference · Continued</Eyebrow>
        <div style={{ display: "flex", alignItems: "center", gap: 12, margin: "10px 0 4px" }}>
          <div style={{ flex: 1, height: 0, borderTop: "0.5px solid var(--sr-sage-haze)" }} />
          <RidgeMark width={48} style={{ opacity: 0.75 }} />
          <div style={{ flex: 1, height: 0, borderTop: "0.5px solid var(--sr-sage-haze)" }} />
        </div>
        <h1 style={{ ...scStyles.pageTitle, fontSize: 44 }}>{c.title}</h1>
        <p style={scStyles.deck}>For when the body needs more than thought.</p>
      </div>

      <div style={{
        display: "grid", gridTemplateColumns: "1fr 1fr", columnGap: 36,
        alignItems: "start",
      }}>
        <div>{renderGroup("The Body", 19)}</div>
        <div>
          {renderGroup("Movement", 75)}
          {renderGroup("When the Body Is Activated", 81)}
        </div>
      </div>

      <div style={{
        marginTop: 18, paddingTop: 14,
        borderTop: "0.5px solid var(--sr-sage-haze)",
        display: "grid", gridTemplateColumns: "160px 1fr", gap: 24,
      }}>
        <Caps>A Note from the Practice</Caps>
        <p style={{
          fontFamily: "var(--sr-serif)", fontStyle: "italic", fontSize: 12.5,
          lineHeight: 1.6, color: "var(--sr-ink)", margin: 0, maxWidth: "62ch",
        }}>{c.note}</p>
      </div>
    </SRPage>
  );
}

Object.assign(window, { EmotionsSC, GroundingSC, GroundingSC2, RosenbergSC });
