*, *::before, *::after {
  box-sizing: border-box;
}

/* Mesmos tokens das fórmulas, para as páginas avulsas parecerem uma família.
   As oito cores de família são a paleta categórica validada (contraste e
   daltonismo) contra este fundo, nos dois temas. A cor nunca anda sozinha:
   a família também está na posição e no nome da coluna ou da faixa. */
:root {
  color-scheme: dark;
  --bg: #1c1c1c;
  --surface: #242424;
  --border: #333;
  --text: #a8a8a8;
  --text-strong: #e6e6e6;
  --text-muted: #7c7c7c;

  --fam-1: #3987e5;
  --fam-2: #199e70;
  --fam-3: #d95926;
  --fam-4: #9085e9;
  --fam-5: #d55181;
  --fam-6: #c98500;
  --fam-7: #e66767;
  --fam-8: #008300;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #fafaf8;
    --surface: #ffffff;
    --border: #e2e2de;
    --text: #4a4a4a;
    --text-strong: #1c1c1c;
    --text-muted: #6e6e6e;

    --fam-1: #2a78d6;
    --fam-2: #1baf7a;
    --fam-3: #eb6834;
    --fam-4: #4a3aa7;
    --fam-5: #e87ba4;
    --fam-6: #eda100;
    --fam-7: #e34948;
    --fam-8: #008300;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fafaf8;
  --surface: #ffffff;
  --border: #e2e2de;
  --text: #4a4a4a;
  --text-strong: #1c1c1c;
  --text-muted: #6e6e6e;

  --fam-1: #2a78d6;
  --fam-2: #1baf7a;
  --fam-3: #eb6834;
  --fam-4: #4a3aa7;
  --fam-5: #e87ba4;
  --fam-6: #eda100;
  --fam-7: #e34948;
  --fam-8: #008300;
}

[data-cor="1"] { --c: var(--fam-1); }
[data-cor="2"] { --c: var(--fam-2); }
[data-cor="3"] { --c: var(--fam-3); }
[data-cor="4"] { --c: var(--fam-4); }
[data-cor="5"] { --c: var(--fam-5); }
[data-cor="6"] { --c: var(--fam-6); }
[data-cor="7"] { --c: var(--fam-7); }
[data-cor="8"] { --c: var(--fam-8); }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  padding: 4.5rem 16px 3rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--text-strong);
  outline-offset: 2px;
}

.back-link {
  position: absolute;
  top: 18px;
  left: 18px;
  display: inline-flex;
  padding: 6px;
  border-radius: 8px;
  color: var(--text-muted);
}

.back-link:hover {
  color: var(--text-strong);
}

a {
  color: var(--text-strong);
  text-underline-offset: 3px;
}

/* ---------------------------------------------------------------- cabeçalho */

.pt {
  max-width: 1280px;
  margin: 0 auto;
}

.pt-head {
  max-width: 760px;
  margin: 0 auto 2rem;
  text-align: center;
}

.pt-head h1 {
  margin: 0 0 .75rem;
  font-size: clamp(1.6rem, 4.5vw, 2.5rem);
  color: var(--text-strong);
}

.pt-lede {
  margin: 0 0 1.25rem;
  line-height: 1.6;
}

.pt-search input {
  width: 100%;
  max-width: 420px;
  padding: .7rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-strong);
  font: inherit;
}

.pt-count {
  min-height: 1.2em;
  margin: .5rem 0 0;
  font-size: .85rem;
  color: var(--text-muted);
}

/* ---------------------------------------------------------------- tabela */

.pt-scroll {
  overflow-x: auto;
  padding-bottom: .5rem;
}

/* Coluna 1: rótulos das linhas. Colunas 2–5: bloco principal. Colunas 6–7,
   linhas 1–7: a ficha, no vão ao lado do bloco principal. As
   faixas de baixo ocupam as colunas 2–7. */
.pt-grid {
  display: grid;
  grid-template-columns: minmax(7.5rem, .9fr) repeat(6, minmax(6.4rem, 1fr));
  gap: 6px;
  min-width: 860px;
}

.pt-colhead,
.pt-rowhead,
.pt-striphead {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 4px 6px;
  font-size: .75rem;
  line-height: 1.3;
  color: var(--text-muted);
  transition: color .15s ease;
}

.pt-colhead {
  border-bottom: 3px solid var(--c);
}

.pt-colhead strong,
.pt-striphead strong {
  font-size: .8rem;
  color: var(--text-strong);
}

.pt-rowhead {
  justify-content: center;
  text-align: right;
}

.pt-striphead {
  justify-content: center;
  text-align: right;
  border-right: 3px solid var(--c);
}

.pt-colhead.is-hot,
.pt-rowhead.is-hot {
  color: var(--text-strong);
}

.pt-gap {
  height: 1.25rem;
}

.el {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-height: 6.4rem;
  padding: 6px 8px 7px;
  border: 1px solid color-mix(in srgb, var(--c) 55%, transparent);
  border-radius: 6px;
  background: color-mix(in srgb, var(--c) 14%, var(--surface));
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform .15s ease, opacity .2s ease, box-shadow .15s ease;
}

.el:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}

.el[aria-pressed="true"] {
  border: 2px solid var(--c);
  padding: 5px 7px 6px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 25%, transparent);
}

.el.is-dim {
  opacity: .18;
}

.el-n {
  font-size: .7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.el-sym {
  margin: 2px 0 1px;
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.05;
  color: var(--text-strong);
}

.el-name {
  font-size: .72rem;
  line-height: 1.25;
  color: var(--text-strong);
}

.el-dist {
  margin-top: auto;
  padding-top: 3px;
  font-size: .66rem;
  color: var(--text-muted);
}

/* ---------------------------------------------------------------- ficha */

.pt-detail {
  grid-column: 6 / 8;
  grid-row: 1 / 8;
  align-self: stretch;
  overflow: auto;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: .88rem;
  line-height: 1.5;
}

.pt-detail h2 {
  margin: 0 0 .5rem;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}

.legend {
  margin: .75rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: .35rem;
}

.legend li {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.legend li::before {
  content: "";
  flex: none;
  width: .8rem;
  height: .8rem;
  border-radius: 3px;
  border: 1px solid var(--c);
  background: color-mix(in srgb, var(--c) 30%, var(--surface));
}

.fd-top {
  display: flex;
  gap: .8rem;
  align-items: flex-start;
}

.fd-badge {
  flex: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 4.2rem;
  height: 4.2rem;
  padding: 4px 6px;
  border: 2px solid var(--c);
  border-radius: 6px;
  background: color-mix(in srgb, var(--c) 18%, var(--surface));
}

.fd-badge span {
  font-size: .65rem;
  color: var(--text-muted);
}

.fd-badge strong {
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-strong);
}

.pt-detail .fd-name {
  margin: 0;
  text-transform: none;
  letter-spacing: normal;
  font-size: 1.1rem;
  line-height: 1.3;
  color: var(--text-strong);
}

.fd-fam {
  margin: .2rem 0 0;
  font-size: .78rem;
  color: var(--text-muted);
}

.fd-sec {
  margin: .9rem 0 .25rem;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}

.fd p {
  margin: 0;
}

.fd ul {
  margin: 0;
  padding-left: 1.1rem;
}

.fd-tex {
  overflow-x: auto;
  overflow-y: hidden;
  padding: .3rem 0;
  color: var(--text-strong);
}

.fd-tex .katex {
  font-size: 1.1em;
}

.fd-ref {
  font: inherit;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-strong);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.fd-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  margin-top: 1rem;
  padding-top: .8rem;
  border-top: 1px solid var(--border);
  font-size: .82rem;
}

.fd-close {
  display: none;
}

/* ---------------------------------------------------------------- notas */

.pt-notes {
  max-width: 760px;
  margin: 2.5rem auto 0;
  line-height: 1.6;
}

.pt-notes h2 {
  margin: 0 0 .6rem;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}

.pt-notes ul {
  padding-left: 1.2rem;
}

/* ---------------------------------------------------------------- telas estreitas */

/* A tabela rola na horizontal e a ficha vira uma folha que sobe de baixo. */
@media (max-width: 900px) {
  .pt-grid {
    grid-template-columns: 6.5rem repeat(6, 6.2rem);
    min-width: 0;
  }

  .pt-detail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    max-height: 70vh;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, .35);
    transform: translateY(105%);
    transition: transform .25s ease;
  }

  .pt-detail.is-open {
    transform: none;
  }

  .fd-close {
    display: inline;
  }
}

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