.cgrl-library {
  margin: 2rem 0;
  padding: clamp(1.5rem, 3vw, 2.5rem) 0;
  border-top: 5px solid #a33131;
  border-bottom: 1px solid #d7dde3;
  color: #18212b;
  background: #ffffff;
  scroll-margin-top: 1.25rem;
}

.cgrl-library [hidden] {
  display: none !important;
}

.cgrl-heading {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(340px, 1.1fr);
  gap: clamp(1.25rem, 3vw, 3rem);
  align-items: end;
  padding: 0 clamp(1rem, 2.5vw, 2rem);
}

.cgrl-heading h2 {
  margin-top: 0.45rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.9rem, 3.5vw, 3rem);
  font-weight: 700;
  line-height: 1.12;
}

.cgrl-heading > p {
  max-width: 75ch;
  color: #52606d;
  font-size: 1.06rem;
  line-height: 1.72;
}

.cgrl-introductions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 1.5rem;
  border-top: 1px solid #d7dde3;
  border-bottom: 1px solid #d7dde3;
}

.cgrl-introduction {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 1rem;
  padding: clamp(1.2rem, 2.5vw, 1.8rem);
  scroll-margin-top: 1.25rem;
}

.cgrl-introduction + .cgrl-introduction {
  border-left: 1px solid #d7dde3;
}

.cgrl-introductions svg {
  width: 1.65rem;
  height: 1.65rem;
  color: #a33131;
}

.cgrl-introductions h3 {
  font-size: 1.16rem;
  font-weight: 850;
}

.cgrl-introductions p {
  max-width: 75ch;
  margin-top: 0.45rem;
  color: #52606d;
  font-size: 1rem;
  line-height: 1.68;
}

.cgrl-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: #18212b;
  color: #ffffff;
}

.cgrl-metrics > div {
  min-height: 104px;
  padding: 1.15rem clamp(1rem, 2vw, 1.5rem);
  border-right: 1px solid rgb(255 255 255 / 18%);
}

.cgrl-metrics > div:last-child {
  border-right: 0;
}

.cgrl-metrics dt {
  color: #cbd5df;
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.cgrl-metrics dd {
  margin-top: 0.25rem;
  color: #f2c14e;
  font-size: clamp(1.7rem, 3vw, 2.35rem);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}

.cgrl-reading-guide {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid #d7dde3;
  background: #f4f7f7;
}

.cgrl-reading-guide > div {
  padding: 1.25rem clamp(1rem, 2vw, 1.5rem);
  border-right: 1px solid #d7dde3;
}

.cgrl-reading-guide > div:last-child {
  border-right: 0;
}

.cgrl-reading-guide strong {
  color: #115e59;
  font-size: 1rem;
}

.cgrl-reading-guide p {
  margin-top: 0.4rem;
  color: #52606d;
  font-size: 0.96rem;
  line-height: 1.62;
}

.cgrl-workspace {
  padding: clamp(1.2rem, 2.5vw, 2rem);
}

.cgrl-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid #bac5ce;
  background: #eef2f4;
}

.cgrl-tabs button {
  display: inline-flex;
  min-height: 50px;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.75rem 1rem;
  border-right: 1px solid #bac5ce;
  color: #394754;
  font-size: 0.98rem;
  font-weight: 800;
}

.cgrl-tabs button:last-child {
  border-right: 0;
}

.cgrl-tabs button[aria-selected="true"] {
  color: #ffffff;
  background: #115e59;
  box-shadow: inset 0 -4px 0 #f2c14e;
}

.cgrl-tabs button:focus-visible,
.cgrl-controls input:focus-visible,
.cgrl-controls select:focus-visible,
.cgrl-more:focus-visible,
.cgrl-chapter-chip:focus-visible,
.cgrl-chapter-link:focus-visible {
  outline: 3px solid #2563a6;
  outline-offset: 2px;
}

.cgrl-tabs svg {
  width: 1.2rem;
  height: 1.2rem;
}

.cgrl-controls {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(250px, 0.6fr);
  gap: 1rem;
  align-items: end;
  margin-top: 1.1rem;
}

.cgrl-search-field,
.cgrl-chapter-field {
  display: grid;
  gap: 0.4rem;
  color: #394754;
  font-size: 0.88rem;
  font-weight: 800;
}

.cgrl-input-wrap {
  position: relative;
  display: block;
}

.cgrl-input-wrap > svg {
  position: absolute;
  top: 50%;
  left: 0.85rem;
  width: 1.15rem;
  height: 1.15rem;
  color: #637382;
  pointer-events: none;
  transform: translateY(-50%);
}

.cgrl-controls input,
.cgrl-controls select {
  width: 100%;
  min-height: 48px;
  border: 1px solid #aebbc5;
  border-radius: 4px;
  color: #18212b;
  background: #ffffff;
  font-size: 1rem;
}

.cgrl-controls input {
  padding: 0.7rem 3.15rem 0.7rem 2.65rem;
}

.cgrl-controls select {
  padding: 0.7rem 2.2rem 0.7rem 0.8rem;
}

.cgrl-input-wrap button {
  position: absolute;
  top: 4px;
  right: 4px;
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  color: #52606d;
  border-radius: 3px;
}

.cgrl-input-wrap button:hover {
  color: #8e2929;
  background: #f8ecec;
}

.cgrl-input-wrap button svg {
  width: 1.15rem;
  height: 1.15rem;
}

.cgrl-result-head {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid #18212b;
}

.cgrl-result-head h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.35rem, 2.3vw, 1.85rem);
  font-weight: 700;
}

.cgrl-result-head p {
  color: #52606d;
  font-size: 0.94rem;
  font-variant-numeric: tabular-nums;
}

.cgrl-entry {
  padding: 1.35rem 0;
  border-bottom: 1px solid #d7dde3;
}

.cgrl-entry-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: baseline;
}

.cgrl-entry-header h3 {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.2rem, 2vw, 1.55rem);
  font-weight: 700;
}

.cgrl-entry-meta {
  grid-column: 2;
  grid-row: 1;
  color: #637382;
  font-size: 0.88rem;
  font-weight: 750;
}

.cgrl-entry-header > .bitigci-save-row {
  grid-column: 1 / -1;
  grid-row: 2;
  margin: 0.2rem 0 0;
}

.cgrl-definition {
  max-width: 100ch;
  margin-top: 0.6rem;
  color: #2d3944;
  font-size: 1.03rem;
  line-height: 1.72;
}

.cgrl-sense-list {
  margin: 0.8rem 0 0 1.45rem;
  list-style: decimal;
}

.cgrl-sense-list > li {
  padding: 0.15rem 0 0.95rem 0.4rem;
}

.cgrl-sense-list > li::marker {
  color: #a33131;
  font-size: 1rem;
  font-weight: 900;
}

.cgrl-chapter-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.7rem;
}

.cgrl-chapter-chip,
.cgrl-chapter-link {
  color: #115e59;
  text-decoration: underline;
  text-decoration-color: #96bcb6;
  text-underline-offset: 3px;
}

.cgrl-chapter-chip {
  padding: 0.25rem 0.45rem;
  border-left: 3px solid #96bcb6;
  background: #f0f7f5;
  font-size: 0.84rem;
  font-weight: 750;
}

.cgrl-chapter-link {
  display: inline-block;
  margin-top: 0.45rem;
  font-size: 0.92rem;
  font-weight: 800;
}

.cgrl-formula-label {
  display: block;
  margin-top: 1rem;
  color: #52606d;
  font-size: 0.82rem;
  text-transform: uppercase;
}

.cgrl-math {
  max-width: 100%;
  margin-top: 0.45rem;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  border-left: 5px solid #2563a6;
  background: #f2f6fa;
  font-size: 1.06rem;
}

.cgrl-narrative {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.4rem;
  margin-top: 1rem;
}

.cgrl-explanation {
  min-width: 0;
  padding-left: 0.9rem;
  border-left: 3px solid #d7dde3;
}

.cgrl-explanation strong,
.cgrl-formula-uses > strong {
  color: #8e2929;
  font-size: 0.94rem;
}

.cgrl-explanation p {
  margin-top: 0.35rem;
  color: #394754;
  font-size: 0.98rem;
  line-height: 1.68;
  overflow-wrap: anywhere;
}

.cgrl-formula-uses {
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px dashed #aebbc5;
}

.cgrl-use-count {
  margin-left: 0.55rem;
  color: #637382;
  font-size: 0.88rem;
}

.cgrl-formula-uses ul {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.65rem;
}

.cgrl-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: #52606d;
}

.cgrl-empty svg {
  width: 2rem;
  height: 2rem;
  margin: 0 auto 0.6rem;
  color: #a33131;
}

.cgrl-empty strong {
  display: block;
  color: #18212b;
  font-size: 1.05rem;
}

.cgrl-empty p {
  margin-top: 0.35rem;
  font-size: 0.96rem;
}

.cgrl-more {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  margin: 1.2rem auto 0;
  padding: 0.65rem 1.1rem;
  border: 1px solid #115e59;
  border-radius: 4px;
  color: #115e59;
  background: #ffffff;
  font-size: 0.96rem;
  font-weight: 850;
}

.cgrl-more:hover {
  color: #ffffff;
  background: #115e59;
}

.cgrl-more svg {
  width: 1.1rem;
  height: 1.1rem;
}

.cgrl-noscript {
  margin: 1rem;
  padding: 1rem;
  border-left: 4px solid #a33131;
  background: #f8ecec;
  font-size: 1rem;
}

@media (max-width: 900px) {
  .cgrl-heading,
  .cgrl-controls {
    grid-template-columns: 1fr;
  }

  .cgrl-introductions,
  .cgrl-reading-guide {
    grid-template-columns: 1fr;
  }

  .cgrl-introduction + .cgrl-introduction,
  .cgrl-reading-guide > div + div {
    border-top: 1px solid #d7dde3;
    border-left: 0;
  }

  .cgrl-reading-guide > div {
    border-right: 0;
  }

  .cgrl-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cgrl-metrics > div:nth-child(2n) {
    border-right: 0;
  }

  .cgrl-metrics > div:nth-child(-n + 2) {
    border-bottom: 1px solid rgb(255 255 255 / 18%);
  }
}

@media (max-width: 640px) {
  .cgrl-library {
    margin: 1.35rem 0;
  }

  .cgrl-heading,
  .cgrl-workspace {
    padding-right: 0.8rem;
    padding-left: 0.8rem;
  }

  .cgrl-introduction {
    grid-template-columns: 30px minmax(0, 1fr);
    padding: 1rem 0.8rem;
  }

  .cgrl-tabs {
    grid-template-columns: 1fr;
  }

  .cgrl-tabs button {
    justify-content: flex-start;
    border-right: 0;
    border-bottom: 1px solid #bac5ce;
  }

  .cgrl-tabs button:last-child {
    border-bottom: 0;
  }

  .cgrl-result-head,
  .cgrl-entry-header {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.3rem;
  }

  .cgrl-entry-meta {
    grid-column: 1;
    grid-row: auto;
    white-space: normal;
  }

  .cgrl-entry-header > .bitigci-save-row {
    grid-column: 1;
    grid-row: auto;
  }

  .cgrl-narrative {
    grid-template-columns: 1fr;
  }

  .cgrl-math {
    font-size: 0.98rem;
  }
}
