:root {
  --math-teal: #167c73;
  --math-teal-soft: #e8f6f3;
  --math-blue: #3178b8;
  --math-blue-soft: #edf5fb;
  --math-violet: #7654a8;
  --math-violet-soft: #f3eef9;
  --math-gold: #a76812;
  --math-gold-soft: #fff6df;
}

.math-page main {
  overflow: clip;
}

.math-hub-hero,
.math-subpage-hero {
  position: relative;
  padding: clamp(34px, 6vw, 82px) 24px 34px;
  background:
    linear-gradient(135deg, rgba(255, 247, 245, 0.96), rgba(234, 247, 246, 0.9)),
    url("../images/teacher.webp") center 32% / cover;
  border-bottom: 1px solid rgba(226, 107, 96, 0.18);
}

.math-hub-hero__inner,
.math-subpage-hero__inner,
.math-library__inner,
.math-tool-section__inner {
  width: min(1180px, 100%);
  margin: 0 auto;
}

.math-hub-hero__grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr);
  gap: 18px;
  align-items: stretch;
}

.math-hub-hero__copy,
.math-hub-hero__aside,
.math-subpage-hero__copy {
  padding: clamp(24px, 4vw, 48px);
  border: 1px solid rgba(226, 107, 96, 0.23);
  border-radius: 8px;
}

.math-hub-hero h1,
.math-subpage-hero h1 {
  max-width: 780px;
  margin: 8px 0 14px;
  font-size: clamp(2.25rem, 5vw, 4.8rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.math-hub-hero__copy > p:not(.eyebrow),
.math-subpage-hero__copy > p:not(.eyebrow) {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1.04rem, 1.6vw, 1.24rem);
  font-weight: 650;
  line-height: 1.62;
}

.math-hub-hero .button--secondary,
.math-subpage-hero .button--secondary,
.math-library .button--secondary {
  border-color: rgba(32, 38, 45, 0.18);
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
}

.math-hub-hero .button--secondary:hover,
.math-subpage-hero .button--secondary:hover,
.math-library .button--secondary:hover {
  border-color: var(--math-teal);
  color: var(--math-teal);
}

.math-hub-hero__aside {
  display: grid;
  align-content: space-between;
  gap: 24px;
  background: rgba(255, 255, 255, 0.79);
}

.math-hub-hero__formula {
  color: var(--math-teal);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3rem, 7vw, 6.2rem);
  font-weight: 700;
  line-height: 1;
}

.math-hub-hero__aside strong {
  display: block;
  margin-bottom: 7px;
  color: var(--ink);
  font-size: 1.18rem;
}

.math-hub-hero__aside p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.55;
}

.math-library {
  padding: clamp(44px, 7vw, 86px) 24px;
  background: #f7fafc;
}

.math-library + .math-library {
  padding-top: 0;
}

.math-library__head {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(260px, 0.55fr);
  gap: 28px;
  align-items: end;
  margin-bottom: 24px;
}

.math-library__head h2 {
  margin: 5px 0 0;
  font-size: clamp(1.8rem, 3.2vw, 3.05rem);
  line-height: 1.05;
}

.math-library__head > p:last-child {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.6;
}

.math-catalog-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.math-catalog-grid--four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.math-resource-card {
  min-height: 230px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
  padding: 22px;
  color: inherit;
  text-decoration: none;
  border: 1px solid rgba(49, 120, 184, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 14px 34px rgba(31, 43, 54, 0.08);
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.math-resource-card:hover,
.math-resource-card:focus-visible {
  transform: translateY(-4px);
  border-color: var(--math-teal);
  box-shadow: 0 18px 42px rgba(31, 43, 54, 0.13);
}

.math-resource-card__mark {
  width: max-content;
  min-width: 54px;
  padding: 8px 11px;
  border-radius: 6px;
  background: var(--math-blue-soft);
  color: var(--math-blue);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.12rem;
  font-weight: 800;
  line-height: 1;
}

.math-resource-card:nth-child(4n + 2) .math-resource-card__mark {
  color: var(--math-violet);
  background: var(--math-violet-soft);
}

.math-resource-card:nth-child(4n + 3) .math-resource-card__mark {
  color: var(--math-gold);
  background: var(--math-gold-soft);
}

.math-resource-card:nth-child(4n + 4) .math-resource-card__mark {
  color: var(--math-teal);
  background: var(--math-teal-soft);
}

.math-resource-card h3 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.2rem, 1.8vw, 1.5rem);
  line-height: 1.15;
}

.math-resource-card p {
  margin: 0;
  color: var(--muted);
  font-weight: 650;
  line-height: 1.55;
}

.math-resource-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  color: var(--math-teal);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.math-subpage-hero {
  padding-bottom: 38px;
}

.math-subpage-hero__copy {
  max-width: 970px;
  background: rgba(255, 255, 255, 0.84);
}

.math-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.math-breadcrumb a {
  color: var(--coral-dark);
}

.math-breadcrumb span::before {
  content: "/";
  margin-right: 8px;
  color: rgba(42, 49, 58, 0.35);
}

.math-subpage-hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.math-tool-section {
  padding: 28px 24px clamp(54px, 7vw, 86px);
  background:
    linear-gradient(180deg, #f7fafc 0%, #edf7f5 100%);
}

.math-tool-intro {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: end;
  margin-bottom: 16px;
}

.math-tool-intro h2 {
  margin: 4px 0 0;
  font-size: clamp(1.55rem, 2.8vw, 2.45rem);
}

.math-tool-intro p {
  max-width: 560px;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.55;
}

.math-frame-shell {
  position: relative;
  min-height: 560px;
  overflow: hidden;
  border: 1px solid rgba(226, 107, 96, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 22px 48px rgba(31, 43, 54, 0.1);
}

.math-frame-shell::before {
  content: "Ładowanie narzędzia…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
}

.math-frame-shell.is-ready::before {
  display: none;
}

.math-app-frame {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  min-height: 560px;
  border: 0;
  background: transparent;
}

.math-related {
  padding: 0 24px 72px;
  background: #edf7f5;
}

.math-related .math-library__inner {
  padding-top: 28px;
  border-top: 1px solid rgba(42, 49, 58, 0.1);
}

.math-related h2 {
  margin: 0 0 18px;
  font-size: clamp(1.45rem, 2.5vw, 2.1rem);
}

.math-related__links {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.math-related__links a {
  display: grid;
  gap: 5px;
  min-height: 110px;
  padding: 18px;
  border: 1px solid rgba(22, 124, 115, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: inherit;
  text-decoration: none;
}

.math-related__links strong {
  color: var(--ink);
}

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

@media (max-width: 900px) {
  .math-hub-hero__grid,
  .math-library__head {
    grid-template-columns: 1fr;
  }

  .math-hub-hero__aside {
    grid-template-columns: auto 1fr;
    align-items: center;
  }

  .math-hub-hero__formula {
    font-size: 3.4rem;
  }

  .math-catalog-grid,
  .math-catalog-grid--four,
  .math-related__links {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .math-hub-hero,
  .math-subpage-hero,
  .math-library,
  .math-tool-section,
  .math-related {
    padding-left: 16px;
    padding-right: 16px;
  }

  .math-hub-hero__copy,
  .math-hub-hero__aside,
  .math-subpage-hero__copy {
    padding: 22px;
  }

  .math-hub-hero h1,
  .math-subpage-hero h1 {
    font-size: clamp(2.15rem, 12vw, 3.25rem);
  }

  .math-hub-hero__aside {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .math-catalog-grid,
  .math-catalog-grid--four,
  .math-related__links {
    grid-template-columns: 1fr;
  }

  .math-resource-card {
    min-height: 0;
  }

  .math-tool-intro {
    display: grid;
    align-items: start;
  }

  .math-frame-shell,
  .math-app-frame {
    min-height: 620px;
  }

  .math-frame-shell {
    margin-inline: -8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .math-resource-card {
    transition: none;
  }
}
