:root {
  --pt-grammar-blue: #2563a8;
  --pt-grammar-green: #087b55;
  --pt-grammar-green-dark: #075a40;
  --pt-grammar-yellow: #d6a900;
  --pt-grammar-ink: #17202a;
  --pt-grammar-muted: #5f6b76;
  --pt-grammar-border: #d9e2e1;
  --pt-grammar-surface: #ffffff;
  --pt-grammar-tint: #f5f8f7;
}

body.page-grammar {
  background: var(--pt-grammar-tint);
  color: var(--pt-grammar-ink);
}

body.page-grammar main.section.container {
  box-sizing: border-box;
  max-width: 840px;
  padding-top: 8rem;
  padding-bottom: 4rem;
}

.grammar-article {
  max-width: 760px;
  color: var(--pt-grammar-ink);
  line-height: 1.72;
}

.grammar-article > p:first-child {
  margin: 0 0 0.75rem;
}

.grammar-article > p:first-child a {
  color: var(--pt-grammar-green);
  font-size: 0.9rem;
  font-weight: 700;
}

.grammar-article > p:first-child a::before {
  content: '\2190';
  margin-right: 0.4rem;
}

.grammar-topic-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0 0 1.75rem;
  padding: 0.7rem;
  border: 1px solid var(--pt-grammar-border);
  border-radius: 8px;
  background: var(--pt-grammar-surface);
}

.grammar-topic-nav a {
  padding: 0.42rem 0.72rem;
  border: 1px solid #dce4e7;
  border-radius: 6px;
  color: var(--pt-grammar-green);
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.25;
  text-decoration: none;
  white-space: nowrap;
}

.grammar-topic-nav a:hover {
  border-color: var(--pt-grammar-green);
  background: #edf8f3;
  text-decoration: none;
}

.grammar-topic-nav a.active {
  border-color: var(--pt-grammar-green);
  background: var(--pt-grammar-green);
  color: #ffffff;
  pointer-events: none;
}

.grammar-article h1 {
  margin: 0 0 0.75rem;
  color: var(--pt-grammar-blue);
  font-size: clamp(2rem, 5vw, 2.8rem);
  letter-spacing: 0;
}

.grammar-lead {
  max-width: 68ch;
  margin-bottom: 2.1rem;
  color: var(--pt-grammar-muted);
  font-size: 1.06rem;
  line-height: 1.72;
}

.grammar-section {
  margin: 0;
  padding: 1.65rem 0;
  border-top: 1px solid var(--pt-grammar-border);
}

.grammar-section:first-of-type {
  border-top: 2px solid var(--pt-grammar-green);
}

.grammar-section h2 {
  margin: 0 0 0.75rem;
  color: var(--pt-grammar-green-dark);
  font-size: 1.28rem;
  letter-spacing: 0;
}

.grammar-section p,
.grammar-section li {
  line-height: 1.72;
}

.grammar-section ul,
.grammar-section ol,
.example-list {
  margin-top: 0.75rem;
  padding-left: 1.3rem;
}

.grammar-section li + li {
  margin-top: 0.55rem;
}

.note-box {
  margin: 1rem 0;
  padding: 0.95rem 1rem;
  border: 1px solid #c8ddd5;
  border-left: 4px solid var(--pt-grammar-green);
  border-radius: 6px;
  background: #eef8f4;
}

.summary-list {
  margin-bottom: 0;
  padding: 1rem 1rem 1rem 2rem;
  border: 1px solid var(--pt-grammar-border);
  border-top: 3px solid var(--pt-grammar-yellow);
  border-radius: 6px;
  background: var(--pt-grammar-surface);
}

.grammar-article code {
  padding: 0.08rem 0.25rem;
  border-radius: 4px;
  background: #e9f2f7;
}

.pt-table-scroll {
  margin-top: 1rem;
  overflow-x: auto;
  border: 1px solid var(--pt-grammar-border);
  border-radius: 6px;
  background: var(--pt-grammar-surface);
}

.pt-grammar-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
}

.pt-grammar-table th,
.pt-grammar-table td {
  padding: 0.72rem 0.85rem;
  border-bottom: 1px solid var(--pt-grammar-border);
  text-align: left;
  vertical-align: top;
}

.pt-grammar-table th {
  background: #eef3f5;
  color: #34424d;
  font-size: 0.88rem;
}

.pt-grammar-table td {
  font-size: 0.94rem;
}

.pt-grammar-table tr:last-child td {
  border-bottom: 0;
}

.grammar-article a:focus-visible,
.grammar-topic-nav a:focus-visible,
#grammar-explorer a:focus-visible,
#grammar-explorer summary:focus-visible,
#grammarSearchPt:focus-visible {
  outline: 3px solid rgba(8, 123, 85, 0.25);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .grammar-topic-nav {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }

  .grammar-section {
    padding-block: 1.35rem;
  }
}

/* Portuguese Grammar Explorer */
#grammar-explorer {
  max-width: 1040px;
}

.pt-explorer-header {
  max-width: 900px;
  margin: 0 auto 2rem;
}

#grammar-explorer .pt-explorer-header .section-title {
  margin: 0 0 0.5rem;
  text-align: left;
  letter-spacing: 0;
}

.pt-explorer-intro {
  max-width: 70ch;
  margin: 0;
  color: var(--pt-grammar-muted);
  line-height: 1.7;
}

.pt-explorer-tools {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  align-items: end;
  gap: 1rem;
  margin-top: 1.25rem;
}

.pt-grammar-search {
  position: relative;
}

.pt-grammar-search i {
  position: absolute;
  top: 50%;
  left: 1rem;
  color: #687681;
  transform: translateY(-50%);
  pointer-events: none;
}

.pt-grammar-search input {
  box-sizing: border-box;
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 1rem 0.75rem 2.75rem;
  border: 1px solid #b9c7c4;
  border-radius: 6px;
  background: #ffffff;
  color: var(--pt-grammar-ink);
  font: inherit;
}

.pt-topic-filter {
  display: inline-flex;
  margin: 0;
  padding: 3px;
  border: 1px solid var(--pt-grammar-border);
  border-radius: 6px;
  background: #ffffff;
}

.pt-topic-filter legend {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.pt-topic-filter label {
  position: relative;
  cursor: pointer;
}

.pt-topic-filter input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pt-topic-filter span {
  display: block;
  padding: 0.55rem 0.72rem;
  border-radius: 4px;
  color: var(--pt-grammar-muted);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.pt-topic-filter input:checked + span {
  background: var(--pt-grammar-green);
  color: #ffffff;
}

.pt-topic-filter input:focus-visible + span {
  outline: 3px solid rgba(8, 123, 85, 0.25);
  outline-offset: 1px;
}

.pt-search-status {
  min-height: 1.5rem;
  margin: 0.55rem 0 0;
  color: var(--pt-grammar-muted);
  font-size: 0.9rem;
}

#grammar-explorer .grammar-accordion {
  min-width: 0;
  max-width: 900px;
}

#grammar-explorer .accordion-item {
  border: 1px solid var(--pt-grammar-border);
  border-radius: 8px;
  box-shadow: 0 2px 7px rgba(23, 32, 42, 0.04);
}

#grammar-explorer .accordion-item summary::after,
#grammar-explorer .toggle-item summary::after {
  content: '+';
  position: static;
  inset: auto;
  display: block;
  width: 1em;
  height: 1em;
  border: 0;
  background: none;
  color: var(--pt-grammar-green);
  font-family: Arial, sans-serif;
  font-size: 1.3rem;
  line-height: 1;
  text-align: center;
  transform: none !important;
}

#grammar-explorer .accordion-item[open] > summary::after,
#grammar-explorer .toggle-item[open] > summary::after {
  content: '\2212';
  transform: none !important;
}

#grammar-explorer .accordion-item summary h2 {
  border: 0;
  color: var(--pt-grammar-ink);
  letter-spacing: 0;
}

#grammar-explorer .toggle-item.live > summary {
  color: var(--pt-grammar-green-dark);
}

#grammar-explorer .toggle-item:not(.live) > summary {
  color: #697781;
}

#grammar-explorer .rule-content {
  border-left-color: #a9d6c4;
  background: #f4faf7;
}

#grammar-explorer .topic-disabled::after {
  color: #87949d;
}

.pt-topic-hidden,
.pt-group-hidden,
.pt-level-hidden {
  display: none !important;
}

@media (max-width: 700px) {
  .pt-explorer-tools {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .pt-topic-filter {
    width: 100%;
  }

  .pt-topic-filter label {
    flex: 1;
  }

  .pt-topic-filter span {
    padding-inline: 0.4rem;
    text-align: center;
  }

  #grammar-explorer .accordion-item,
  #grammar-explorer .accordion-item summary,
  #grammar-explorer .accordion-item summary h2 {
    min-width: 0;
    max-width: 100%;
  }

  #grammar-explorer .accordion-item summary h2 {
    font-size: 1.05rem;
    overflow-wrap: anywhere;
  }
}
