/* Português do Brasil — handbook
   Three text colours carry three information layers:
   teal = Portuguese, warm grey mono = respelling, ink = English. */

:root {
  --paper:   #F5F6F2;
  --surface: #EBECE6;
  --ink:     #1B2127;
  --ink-mid: #4A545C;
  --pt:      #0B6E5F;
  --pt-soft: #E4EFEB;
  --sound:   #8A7A62;
  --rule:    #DBDCD3;
  --rule-hi: #C3C5B9;

  --serif: "Newsreader", Georgia, "Iowan Old Style", serif;
  --sans:  "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono:  "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --bar: 17.5rem;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  font-feature-settings: "kern", "liga";
}

/* ---------- layout ---------- */

.shell { display: flex; align-items: flex-start; }

.rail {
  width: var(--bar);
  flex: 0 0 var(--bar);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-right: 1px solid var(--rule);
  padding: 2rem 1.25rem 3rem 1.75rem;
}

.page {
  flex: 1 1 auto;
  min-width: 0;
  padding: 3.5rem 3rem 6rem;
}

.col { max-width: 40rem; }

/* Tables and pre may exceed the reading column. */
.col > table,
.col > .scroll,
.col > pre { max-width: 52rem; }

/* ---------- masthead ---------- */

.brand { display: block; text-decoration: none; color: inherit; margin-bottom: 2rem; }

.brand b {
  display: block;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.4rem;
  line-height: 1.1;
  color: var(--pt);
  letter-spacing: -0.01em;
}

.brand span {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-mid);
  margin-top: 0.3rem;
}

.brand:hover b { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- table of contents ---------- */

.toc-group {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--ink-mid);
  margin: 1.5rem 0 0.5rem;
}

.toc { list-style: none; margin: 0; padding: 0; }

.toc li { margin: 0; }

.toc a {
  display: grid;
  grid-template-columns: 1.9rem 1fr;
  gap: 0.35rem;
  padding: 0.24rem 0.5rem 0.24rem 0;
  text-decoration: none;
  color: var(--ink);
  font-size: 0.875rem;
  line-height: 1.35;
  border-radius: 2px;
}

.toc a .n {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--sound);
  padding-top: 0.1em;
}

.toc a:hover { background: var(--pt-soft); }
.toc a:hover .n { color: var(--pt); }

.toc a[aria-current="page"] {
  color: var(--pt);
  font-weight: 600;
  background: var(--pt-soft);
  box-shadow: -0.45rem 0 0 0 var(--pt-soft), inset 2px 0 0 0 var(--pt);
}
.toc a[aria-current="page"] .n { color: var(--pt); }

/* ---------- pronunciation key in the rail ---------- */

.key {
  margin-top: 2.25rem;
  border-top: 1px solid var(--rule-hi);
  padding-top: 1rem;
}

.key > summary {
  cursor: pointer;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--ink-mid);
  list-style: none;
}
.key > summary::-webkit-details-marker { display: none; }
.key > summary::before { content: "▸ "; font-style: normal; color: var(--sound); }
.key[open] > summary::before { content: "▾ "; }

.key dl {
  margin: 0.75rem 0 0;
  display: grid;
  grid-template-columns: 3.1rem 1fr;
  gap: 0.3rem 0.5rem;
  font-size: 0.78rem;
  line-height: 1.3;
}
.key dt { font-family: var(--mono); color: var(--sound); }
.key dd { margin: 0; color: var(--ink-mid); }
.key dd b { color: var(--pt); font-weight: 600; }

/* ---------- chapter head ---------- */

.head { margin-bottom: 2.75rem; }

.head .num {
  font-family: var(--mono);
  font-size: 3.25rem;
  line-height: 1;
  color: var(--rule-hi);
  display: block;
  margin-bottom: 0.35rem;
}

.head h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 2.35rem;
  line-height: 1.12;
  letter-spacing: -0.018em;
  margin: 0;
  max-width: 22ch;
}

.head hr {
  border: 0;
  border-top: 2px solid var(--pt);
  width: 3rem;
  margin: 1.4rem 0 0;
}

/* ---------- prose ---------- */

.col h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.55rem;
  letter-spacing: -0.012em;
  margin: 3.25rem 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--rule);
}

.col h3 {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 1.02rem;
  letter-spacing: 0.005em;
  margin: 2.35rem 0 0.7rem;
}

.col h4 {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.93rem;
  margin: 1.6rem 0 0.5rem;
  color: var(--ink-mid);
}

.col p { margin: 0 0 1rem; }

.col ul, .col ol { margin: 0 0 1.15rem; padding-left: 1.3rem; }
.col li { margin-bottom: 0.35rem; }
.col li::marker { color: var(--sound); }

.col a { color: var(--pt); text-underline-offset: 2px; }

.col hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 2.75rem 0;
}

.col strong { font-weight: 600; }
.col em { font-style: italic; }

.col blockquote {
  margin: 1.5rem 0;
  padding: 0.9rem 1.15rem;
  background: var(--pt-soft);
  border-left: 2px solid var(--pt);
}
.col blockquote p:last-child { margin-bottom: 0; }
.col blockquote strong { color: var(--pt); }

/* ---------- inline Portuguese ---------- */

/* Portuguese appears in backticks throughout the source. */
.col code {
  font-family: var(--serif);
  font-size: 1.02em;
  font-weight: 500;
  color: var(--pt);
  background: none;
  padding: 0;
}

.col blockquote code { font-size: 1.06em; }

/* ---------- tables ---------- */

.scroll { overflow-x: auto; margin: 1.35rem 0 1.6rem; }

.col table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
  line-height: 1.45;
}

.col th, .col td {
  text-align: left;
  vertical-align: top;
  padding: 0.5rem 1rem 0.5rem 0;
  border-bottom: 1px solid var(--rule);
}

.col th {
  font-weight: 600;
  font-size: 0.76rem;
  color: var(--ink-mid);
  border-bottom: 1px solid var(--rule-hi);
  padding-bottom: 0.4rem;
  white-space: nowrap;
}

.col tbody tr:hover { background: #EFF0EB; }

.col td:last-child, .col th:last-child { padding-right: 0; }

/* Language columns, tagged at build time from the header row. */
table[data-pt] td.pt,
.col td.pt {
  font-family: var(--serif);
  font-size: 1.02rem;
  font-weight: 500;
  color: var(--pt);
}
.col td.pt code { font-size: 1em; }

.col td.sound {
  font-family: var(--mono);
  font-size: 0.775rem;
  letter-spacing: 0.005em;
  color: var(--sound);
  white-space: nowrap;
}

/* ---------- foot navigation ---------- */

.foot {
  display: flex;
  gap: 1rem;
  margin-top: 4.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  max-width: 52rem;
}

.foot a {
  flex: 1 1 0;
  min-width: 0;
  text-decoration: none;
  color: var(--ink);
  padding: 0.85rem 1rem;
  border: 1px solid var(--rule-hi);
  background: transparent;
}
.foot a:hover { border-color: var(--pt); background: var(--pt-soft); }
.foot a.next { text-align: right; }
.foot a.spacer { visibility: hidden; }

.foot em {
  display: block;
  font-family: var(--mono);
  font-style: normal;
  font-size: 0.72rem;
  color: var(--sound);
  margin-bottom: 0.2rem;
}
.foot b {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.02rem;
  line-height: 1.25;
}

/* ---------- home ---------- */

.lede {
  font-family: var(--serif);
  font-size: 1.22rem;
  line-height: 1.55;
  color: var(--ink-mid);
  max-width: 34rem;
  margin: 0 0 2.5rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0;
  max-width: 52rem;
  border-top: 1px solid var(--rule);
  margin: 1.25rem 0 2rem;
}

.grid a {
  display: grid;
  grid-template-columns: 2.1rem 1fr;
  gap: 0.5rem;
  padding: 0.7rem 1rem 0.7rem 0;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
  color: var(--ink);
  font-size: 0.9rem;
}
.grid a:hover { background: var(--pt-soft); color: var(--pt); }
.grid a .n { font-family: var(--mono); font-size: 0.76rem; color: var(--sound); }

/* ---------- mobile ---------- */

.railtoggle { display: none; }
.railbtn { display: none; }

@media (max-width: 940px) {
  body { font-size: 15.5px; }

  .shell { display: block; }

  .railbtn {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface);
    border-bottom: 1px solid var(--rule-hi);
    padding: 0.7rem 1.25rem;
    font-family: var(--serif);
    font-size: 1rem;
    color: var(--pt);
    cursor: pointer;
  }
  .railbtn::before { content: "☰"; font-family: var(--sans); font-size: 0.95rem; }

  .rail {
    display: none;
    width: auto;
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--rule-hi);
    padding: 1.25rem 1.5rem 2rem;
  }
  .railtoggle:checked ~ .shell .rail { display: block; }
  .rail .brand { display: none; }

  .page { padding: 2rem 1.25rem 4rem; }
  .head .num { font-size: 2.4rem; }
  .head h1 { font-size: 1.85rem; }
  .col h2 { font-size: 1.35rem; margin-top: 2.5rem; }
  .foot { display: block; }
  .foot a { display: block; margin-bottom: 0.6rem; text-align: left !important; }
  .col table { font-size: 0.85rem; }
  .col th, .col td { padding-right: 0.7rem; }
}

/* ---------- accessibility & print ---------- */

a:focus-visible, summary:focus-visible, .railbtn:focus-visible {
  outline: 2px solid var(--pt);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media print {
  .rail, .foot, .railbtn { display: none; }
  body { background: #fff; font-size: 10.5pt; }
  .page { padding: 0; }
  .col, .col > table, .foot { max-width: none; }
  .col h2 { break-after: avoid; }
  .col table { break-inside: auto; }
  tr { break-inside: avoid; }
}
