/*
 * Subpage chapters — a shared visual system for lessons, resources and utility pages.
 * It deliberately uses native document flow and HTML interactions: no scroll hijacking.
 */

body:not(.home) {
  --sai-chapter-accent: #087f72;
  --sai-chapter-dark: #102c2d;
  --sai-chapter-pale: #dff3ec;
  --sai-chapter-warm: #f3e7da;
  --sai-chapter-canvas: #f7f5ee;
  --sai-chapter-max: 80rem;
}

body.sai-pillar-modele {
  --sai-chapter-accent: #ba432e;
  --sai-chapter-pale: #f5ded4;
  --sai-chapter-warm: #ead7cc;
}

body:not(.home) .sai-main {
  background: var(--sai-chapter-canvas);
}

body:not(.home) .sai-main > .sai-breadcrumbs {
  width: min(calc(100% - 2 * var(--sai-gutter)), var(--sai-chapter-max));
  max-width: none;
  margin-inline: auto;
  padding-block: 1.15rem;
  border-bottom: 1px solid var(--sai-line);
}

body:not(.home) .sai-breadcrumbs a {
  text-decoration-thickness: 1px;
  text-underline-offset: .25em;
}

body:not(.home) .sai-main > .wp-block-post-content {
  background: transparent;
}

/* Chapter opener: a broad editorial panel instead of an anonymous centered heading. */
body:not(.home) .sai-hero:not(.sai-hero--human) {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 2.25fr) minmax(13rem, .75fr);
  align-content: center;
  width: min(calc(100% - 2 * var(--sai-gutter)), var(--sai-chapter-max));
  min-height: clamp(25rem, 48vw, 34rem);
  margin: clamp(1.25rem, 3vw, 2.5rem) auto 0;
  padding: clamp(2.5rem, 6vw, 5.25rem);
  overflow: hidden;
  border: 1px solid var(--sai-line);
  border-bottom: 1px solid var(--sai-line);
  border-radius: 1.5rem .35rem 1.5rem .35rem;
  background:
    linear-gradient(112deg, rgba(255,255,255,.96) 0 65%, rgba(255,255,255,.3) 65%),
    var(--sai-paper);
  box-shadow: 0 1.8rem 4rem rgba(16,44,45,.09);
}

body:not(.home) .sai-hero:not(.sai-hero--human)::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 0 0 auto;
  width: 34%;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  background:
    linear-gradient(150deg, transparent 0 44%, rgba(255,255,255,.45) 44% 45%, transparent 45% 100%),
    repeating-linear-gradient(90deg, transparent 0 2.75rem, rgba(16,44,45,.09) 2.75rem calc(2.75rem + 1px)),
    var(--sai-chapter-pale);
  clip-path: polygon(17% 0, 100% 0, 100% 100%, 0 88%);
  transform: none;
}

body:not(.home) .sai-hero:not(.sai-hero--human)::after {
  content: "ROZDZIAŁ / PRAKTYKA";
  position: absolute;
  z-index: 1;
  top: clamp(3rem, 6vw, 5rem);
  right: clamp(1.5rem, 4vw, 3.5rem);
  bottom: clamp(2rem, 4vw, 3.5rem);
  width: clamp(9rem, 15vw, 12rem);
  height: auto;
  max-width: 12rem;
  padding-top: .65rem;
  border-top: 3px solid var(--sai-chapter-accent);
  color: var(--sai-chapter-dark);
  font-family: var(--wp--preset--font-family--mono);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .12em;
  background-image: url("../graphics/hero-dual-path.svg");
  background-repeat: no-repeat;
  background-position: center 72%;
  background-size: 100% auto;
  filter: drop-shadow(0 1rem 1.5rem rgba(16,44,45,.08));
  transform: none;
}

body.sai-type-resource .sai-hero:not(.sai-hero--human)::after { content: "ZASÓB / DO UŻYCIA"; }
body.sai-type-faq .sai-hero:not(.sai-hero--human)::after { content: "PYTANIA / ODPOWIEDZI"; }
body.sai-type-program .sai-hero:not(.sai-hero--human)::after { content: "MAPA / DWIE ŚCIEŻKI"; }
body.sai-type-trust .sai-hero:not(.sai-hero--human)::after { content: "METODA / ZASADY"; }

body:not(.home) .sai-hero:not(.sai-hero--human) > :is(h1, p, .wp-block-buttons) {
  grid-column: 1;
  width: min(100%, 45rem);
  max-width: none;
  margin-inline: 0;
}

body:not(.home) .sai-hero:not(.sai-hero--human) .sai-kicker {
  align-self: end;
  width: fit-content;
  margin: 0 0 clamp(1.5rem, 3vw, 2.4rem);
  padding: .55rem .75rem;
  border: 1px solid color-mix(in srgb, var(--sai-chapter-accent) 34%, transparent);
  background: var(--sai-chapter-pale);
  color: var(--sai-chapter-dark);
  line-height: 1;
}

body:not(.home) .sai-hero:not(.sai-hero--human) .sai-kicker::before { display: none; }

body:not(.home) .sai-hero:not(.sai-hero--human) h1 {
  margin-block: 0 1.5rem;
  font-size: clamp(2.65rem, 5.5vw, 5.75rem);
  line-height: .98;
  letter-spacing: -.06em;
  text-wrap: balance;
}

body:not(.home) .sai-hero:not(.sai-hero--human) > .has-large-font-size {
  margin-bottom: 0;
  color: var(--sai-soft-ink);
  font-size: clamp(1.1rem, 1.65vw, 1.45rem) !important;
  line-height: 1.6;
  text-wrap: pretty;
}

/* Reading rhythm: each direct section is a full-width chapter band. */
body:not(.home) .wp-block-post-content > .sai-section {
  position: relative;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: clamp(3.5rem, 7vw, 6.5rem) var(--sai-gutter);
  border-top: 1px solid var(--sai-line);
  background: var(--sai-paper);
}

body:not(.home) .wp-block-post-content > .sai-hero + .sai-section,
body:not(.home) .wp-block-post-content > .sai-contents + .sai-section {
  margin-top: clamp(2rem, 5vw, 4.5rem);
}

body:not(.home) .wp-block-post-content > .sai-section:nth-of-type(even) {
  background: #f0f2e9;
}

body.sai-pillar-modele .wp-block-post-content > .sai-section:nth-of-type(even) {
  background: #f6ede6;
}

body:not(.home) .wp-block-post-content > .sai-section::before {
  content: "";
  position: absolute;
  top: 0;
  left: max(var(--sai-gutter), calc((100% - var(--sai-reading)) / 2));
  width: 4.5rem;
  height: 4px;
  background: var(--sai-chapter-accent);
}

body:not(.home) .sai-section > :is(h2, h3, p, ul, ol, blockquote, figure, table, .wp-block-buttons, .wp-block-group, .wp-block-columns, .wp-block-details),
body:not(.home) .sai-section > .wp-block-list {
  width: min(100%, var(--sai-reading));
  max-width: var(--sai-reading);
  margin-inline: auto;
}

body:not(.home) .sai-section > h2 {
  padding-top: 0;
  font-size: clamp(2rem, 4vw, 3.9rem);
  line-height: 1.02;
  letter-spacing: -.045em;
  text-wrap: balance;
}

body:not(.home) .sai-section > h2::before { content: none; }

body:not(.home) .sai-section > h2 + p {
  max-width: min(100%, 42rem);
  color: var(--sai-soft-ink);
  font-size: clamp(1.1rem, 1.6vw, 1.3rem);
  line-height: 1.7;
}

/* The contents rail is visually separate from both the hero and lesson body. */
body:not(.home) .sai-contents {
  width: min(calc(100% - 2 * var(--sai-gutter)), var(--sai-chapter-max));
  margin: 1rem auto 0;
  padding: 1rem 1.25rem;
  border: 0;
  border-left: 4px solid var(--sai-chapter-accent);
  border-radius: 0 .75rem .75rem 0;
  background: var(--sai-chapter-dark);
  color: #fff;
  box-shadow: 0 .75rem 2rem rgba(16,44,45,.12);
}

body:not(.home) .sai-contents summary { color: #fff; }
body:not(.home) .sai-contents a { color: #c8f4e7; text-decoration-color: rgba(200,244,231,.45); }
body.sai-pillar-modele .sai-contents a { color: #ffd9c9; text-decoration-color: rgba(255,217,201,.5); }

/* Exercises should feel like real worksheets, not another paragraph container. */
body:not(.home) .sai-work-card,
body:not(.home) .is-style-workshop-panel {
  position: relative;
  padding: clamp(1.5rem, 4vw, 2.5rem);
  overflow: hidden;
  border: 1px solid var(--sai-line);
  border-top: 5px solid var(--sai-chapter-accent);
  border-radius: 0 0 1rem 1rem;
  background:
    repeating-linear-gradient(0deg, transparent 0 2.15rem, rgba(16,44,45,.045) 2.15rem calc(2.15rem + 1px)),
    #fffefa;
  box-shadow: 0 1.2rem 2.8rem rgba(16,44,45,.08);
}

body:not(.home) .sai-work-card::after,
body:not(.home) .is-style-workshop-panel::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  border-style: solid;
  border-width: 0 2.5rem 2.5rem 0;
  border-color: transparent var(--sai-chapter-pale) transparent transparent;
}

body:not(.home) .wp-block-details,
body.sai-type-faq .sai-faq-items > details {
  overflow: hidden;
  margin-block: 1rem;
  border: 1px solid var(--sai-line);
  border-radius: .85rem;
  background: #fffefa;
  box-shadow: 0 .5rem 1.5rem rgba(16,44,45,.055);
}

body:not(.home) .wp-block-details > summary,
body.sai-type-faq .sai-faq-items > details > summary {
  position: relative;
  padding: 1.25rem 3.75rem 1.25rem 1.35rem;
  cursor: pointer;
  color: var(--sai-chapter-dark);
  font-family: var(--wp--preset--font-family--display);
  font-size: clamp(1.05rem, 1.5vw, 1.25rem);
  font-weight: 650;
  line-height: 1.35;
  list-style: none;
}

body:not(.home) .wp-block-details > summary::-webkit-details-marker,
body.sai-type-faq .sai-faq-items > details > summary::-webkit-details-marker { display: none; }

body:not(.home) .wp-block-details > summary::after,
body.sai-type-faq .sai-faq-items > details > summary::after {
  content: "+";
  position: absolute;
  top: 50%;
  right: 1.2rem;
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--sai-chapter-pale);
  color: var(--sai-chapter-dark);
  font-family: var(--wp--preset--font-family--mono);
  transform: translateY(-50%);
}

body:not(.home) .wp-block-details[open] > summary::after,
body.sai-type-faq .sai-faq-items > details[open] > summary::after { content: "−"; }

body:not(.home) .wp-block-details > :not(summary) {
  margin-inline: 1.35rem;
}

body:not(.home) .wp-block-details > :last-child { margin-bottom: 1.35rem; }

body:not(.home) .wp-block-details[open] > summary {
  border-bottom: 1px solid var(--sai-line);
  background: color-mix(in srgb, var(--sai-chapter-pale) 44%, white);
}

/* Program: one intentional visual number, no browser marker plus a second badge. */
body.sai-page-foundation-program .sai-section > :is(h2, p, .sai-program),
body.sai-page-foundation-method .sai-section > :is(h2, p, .sai-program) {
  width: min(100%, 70rem);
  max-width: 70rem;
}

body.sai-page-foundation-program ol.sai-program,
body.sai-page-foundation-method ol.sai-program {
  counter-reset: sai-program;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  padding: 0;
  list-style: none;
}

body.sai-page-foundation-program .sai-program > li,
body.sai-page-foundation-method .sai-program > li {
  counter-increment: sai-program;
  position: relative;
  min-height: 10rem;
  margin: 0;
  padding: 1.5rem 1.5rem 1.5rem 4.5rem;
  border: 1px solid var(--sai-line);
  border-radius: .9rem;
  background: #fffefa;
  box-shadow: 0 .6rem 1.8rem rgba(16,44,45,.05);
}

body.sai-page-foundation-program .sai-program > li::before,
body.sai-page-foundation-method .sai-program > li::before {
  content: counter(sai-program, decimal-leading-zero);
  position: absolute;
  top: 1.4rem;
  left: 1.35rem;
  color: var(--sai-chapter-accent);
  font-family: var(--wp--preset--font-family--mono);
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .06em;
}

body.sai-page-foundation-program .sai-program > li::marker,
body.sai-page-foundation-method .sai-program > li::marker { content: ""; }

body.sai-page-foundation-program .sai-program a,
body.sai-page-foundation-method .sai-program a {
  display: inline;
  font-family: var(--wp--preset--font-family--display);
  font-size: 1.15rem;
  font-weight: 650;
  line-height: 1.35;
}

/* Resource hub: turn the bare list into a usable library index. */
body.sai-page-resources-hub .sai-module-list {
  counter-reset: sai-resource;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  width: min(100%, 70rem);
  max-width: 70rem;
  padding: 0;
  list-style: none;
}

body.sai-page-resources-hub .sai-module-list > li {
  counter-increment: sai-resource;
  position: relative;
  min-height: 8rem;
  margin: 0;
  padding: 1.5rem 1.5rem 1.5rem 4.5rem;
  border: 1px solid var(--sai-line);
  border-radius: .9rem;
  background: #fffefa;
  box-shadow: 0 .6rem 1.8rem rgba(16,44,45,.05);
}

body.sai-page-resources-hub .sai-module-list > li::before {
  content: counter(sai-resource, decimal-leading-zero);
  position: absolute;
  left: 1.35rem;
  color: var(--sai-chapter-accent);
  font-family: var(--wp--preset--font-family--mono);
  font-size: .82rem;
  font-weight: 700;
}

body.sai-page-resources-hub .sai-module-list > li::marker { content: ""; }

/* FAQ is an actual interactive index, with native details/summary controls. */
body.sai-type-faq .wp-block-post-content { counter-reset: sai-faq; }

body.sai-type-faq .sai-faq-items > details {
  counter-increment: sai-faq;
  width: min(100%, 54rem);
  max-width: 54rem;
  margin-inline: auto;
}

body.sai-type-faq .sai-faq-items > details > summary {
  padding-left: 4.25rem;
}

body.sai-type-faq .sai-faq-items > details > summary::before {
  content: counter(sai-faq, decimal-leading-zero);
  position: absolute;
  top: 1.35rem;
  left: 1.35rem;
  color: var(--sai-chapter-accent);
  font-family: var(--wp--preset--font-family--mono);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .08em;
}

body.sai-type-faq .sai-faq-items > details > p {
  max-width: 44rem;
  color: var(--sai-soft-ink);
  line-height: 1.75;
}

/* Endings and next-module navigation should close the chapter decisively. */
body:not(.home) .wp-block-post-content > .sai-note {
  position: relative;
  width: min(calc(100% - 2 * var(--sai-gutter)), var(--sai-chapter-max));
  max-width: var(--sai-chapter-max);
  margin: clamp(2.5rem, 6vw, 5rem) auto;
  padding: clamp(1.75rem, 4vw, 3rem);
  overflow: hidden;
  border: 0;
  border-left: .45rem solid var(--sai-chapter-accent);
  border-radius: 0 1rem 1rem 0;
  background: var(--sai-chapter-dark);
  color: #fff;
  box-shadow: 0 1.5rem 3.5rem rgba(16,44,45,.14);
}

body:not(.home) .sai-note :is(h2, h3, p) { color: inherit; }
body:not(.home) .sai-note a { color: #c8f4e7; }
body.sai-pillar-modele .sai-note a { color: #ffd9c9; }

body:not(.home) .sai-module-nav {
  width: min(calc(100% - 2 * var(--sai-gutter)), var(--sai-chapter-max));
  max-width: var(--sai-chapter-max);
  margin: clamp(2.5rem, 6vw, 5rem) auto;
  gap: 1rem;
}

body:not(.home) .sai-module-nav__link {
  min-height: 8rem;
  padding: 1.5rem;
  border: 1px solid var(--sai-line);
  border-radius: .9rem;
  background: #fffefa;
  box-shadow: 0 .65rem 1.8rem rgba(16,44,45,.055);
}

body:not(.home) .sai-module-nav__link:is(:hover, :focus-visible) {
  border-color: var(--sai-chapter-accent);
  transform: translateY(-3px);
}

body:not(.home) .sai-module-nav__link--program {
  min-height: 3.75rem;
  padding: 1rem 1.25rem;
  border: 0;
  border-radius: .6rem;
  background: var(--sai-chapter-pale);
  box-shadow: none;
}

body:not(.home) :is(a, summary):focus-visible {
  outline: 3px solid var(--sai-chapter-accent);
  outline-offset: 4px;
}

body:not(.home) section[id] { scroll-margin-top: 7rem; }

@media (max-width: 900px) {
  body:not(.home) .sai-hero:not(.sai-hero--human) {
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
    padding-bottom: 5rem;
  }

  body:not(.home) .sai-hero:not(.sai-hero--human)::before {
    inset: auto 0 0 auto;
    width: 48%;
    height: 6rem;
    clip-path: polygon(25% 0, 100% 0, 100% 100%, 0 100%);
  }

  body:not(.home) .sai-hero:not(.sai-hero--human)::after {
    top: auto;
    right: 1.5rem;
    bottom: 1.5rem;
    height: auto;
    background-image: none;
    filter: none;
  }
}

@media (max-width: 720px) {
  body:not(.home) .sai-main > .sai-breadcrumbs,
  body:not(.home) .sai-hero:not(.sai-hero--human),
  body:not(.home) .sai-contents,
  body:not(.home) .wp-block-post-content > .sai-note,
  body:not(.home) .sai-module-nav {
    width: min(calc(100% - 2rem), var(--sai-chapter-max));
  }

  body:not(.home) .sai-hero:not(.sai-hero--human) {
    margin-top: 1rem;
    padding: 2rem 1.5rem 5rem;
    border-radius: 1rem .25rem 1rem .25rem;
  }

  body:not(.home) .sai-hero:not(.sai-hero--human) h1 {
    font-size: clamp(2.45rem, 13vw, 4.25rem);
  }

  body:not(.home) .wp-block-post-content > .sai-section {
    padding: 3.25rem 1rem;
  }

  body:not(.home) .wp-block-post-content > .sai-section::before { left: 1rem; }

  body.sai-page-foundation-program ol.sai-program,
  body.sai-page-foundation-method ol.sai-program,
  body.sai-page-resources-hub .sai-module-list {
    grid-template-columns: minmax(0, 1fr);
  }

  body.sai-page-foundation-program .sai-program > li,
  body.sai-page-foundation-method .sai-program > li,
  body.sai-page-resources-hub .sai-module-list > li {
    min-height: 0;
  }

  body.sai-type-faq .sai-faq-items > details > summary {
    padding-left: 3.6rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  body:not(.home) *, body:not(.home) *::before, body:not(.home) *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
