/* ── 1. Tokens ─────────────────────────────────────────────── */
:root {
  color-scheme: dark;

  /* Cores */
  --bg: light-dark(#f0f0f0, #0f0f0f);
  --surface: light-dark(#ebebeb, #161616);
  --border: light-dark(#d4d4d4, #252525);
  --text: light-dark(#2d2d2d, #fff);
  --muted: light-dark(#888, #999);
  --muted2: light-dark(#777, #454545);
  --muted3: light-dark(#666, #bbb);
  --accent: light-dark(#8e55dc, #b59ef4);
  --accent2: light-dark(#cc88c0, #d5aacd);
  --accent3: light-dark(#72af00, #a6bf5b);
  --accent4: light-dark(#1589d1, #73bfef);

  /* Tipografia */
  --font-mono: "JetBrains Mono", Consolas, monospace;
  --font-sans: "Oswald", Roboto, sans-serif;

  /* Espaçamento (escala 4px) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Raio */
  --radius-sm: 3px;
  --radius-md: 4px;
  --radius-lg: 8px;

  /* Transições */
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Layout */
  --sidebar-w: 278px;

  /* Breakpoints (referência — usados em @media literais) */
  /* mobile: 829px (desktop a partir de 830px) */
}
:root.light {
  color-scheme: light;
}

/* ── 2. Reset & utilitários ────────────────────────────────── */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

::selection {
  background: var(--accent);
  color: var(--bg);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── 3. Tipografia base ────────────────────────────────────── */
body {
  display: grid;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.7;
}

h2 {
  font-family: var(--font-sans);
  font-size: 32px;
  font-weight: 500;
  padding: var(--space-4) 0;
}
h3 {
  font-family: var(--font-sans);
  font-size: 22px;
  font-weight: 700;
  color: var(--muted3);
  margin: var(--space-5) 0 10px;
}
p {
  color: var(--muted3);
  margin-bottom: var(--space-3);
}
a {
  display: contents;
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border);
  transition:
    color var(--transition-fast),
    text-decoration-color var(--transition-fast);
}
a:hover {
  color: var(--accent3);
}
ul {
  list-style: none;
  padding: 0;
}
code {
  background: light-dark(#efefef, #1e1e1e);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--accent2);
}
strong {
  color: var(--text);
}
blockquote {
  max-width: 572px;
  border-left: 2px solid var(--accent4);
  padding: 0 var(--space-5);
  margin-bottom: var(--space-5);
}
mark {
  background: light-dark(rgba(107, 72, 212, 0.12), rgba(200, 241, 53, 0.2));
  color: var(--accent);
  border-radius: 2px;
  padding: 0 2px;
}

/* ── 4. Layout ─────────────────────────────────────────────── */
.container {
  display: flex;
  height: 100vh;
  width: 100%;
  max-width: 1800px;
  justify-self: center;
  overflow: hidden;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── 5. Componentes ────────────────────────────────────────── */

/* 5.1 Sidebar / TOC ----------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}
.sidebar__header {
  padding: var(--space-5) 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.sidebar__logo {
  width: 120px;
  margin-bottom: 10px;
  transform: rotate(-3deg);
  transform-origin: 50% 15%;
  transition: transform var(--transition-slow);
  will-change: transform;
  cursor: pointer;
}
.sidebar__glasses {
  position: absolute;
  opacity: 0%;
  width: 62px;
  left: 114px;
  top: -30px;
  z-index: 1;
  transition:
    top 0.3s ease-in-out,
    opacity 0.3s ease-in-out;
}
.sidebar__glasses.visible,
.logo-link:hover .sidebar__glasses {
  opacity: 100%;
  top: 32px;
  transform: rotate(-3deg);
  transition: top 0.3s ease-in-out;
  animation: glassesSway 0.7s linear infinite alternate;
}
.sidebar__stats {
  padding: var(--space-3) 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.sidebar__stats span {
  color: var(--accent3);
}
.sidebar__stats span#stat-sections {
  color: var(--accent4);
}
.sidebar__backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 199;
}
.sidebar__backdrop.visible {
  display: block;
}

.toc {
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  padding-bottom: 180px;
}
.toc__item {
  display: block;
  padding: 6px 20px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  border-left: 5px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
}
.toc__item:hover {
  color: var(--text);
  border-left-color: var(--muted2);
}
.toc__item.active {
  color: var(--text);
  border-left-color: var(--accent4);
  background: light-dark(rgba(42, 123, 181, 0.08), rgba(115, 203, 255, 0.06));
  font-weight: 500;
}
.toc__item--sub {
  font-size: 13px;
  padding-left: 40px;
  text-transform: none;
}

/* 5.2 Topbar ------------------------------------------------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-4) 40px;
  display: flex;
  align-items: center;
  gap: var(--space-5);
  transition: padding 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.topbar--compact .topbar {
  padding: 10px 40px;
}
.topbar__links {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-shrink: 0;
}

.search {
  flex: 1;
  position: relative;
}
.search::before {
  content: "⌕";
  position: absolute;
  left: var(--space-5);
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 34px;
  pointer-events: none;
  z-index: 1;
  transition:
    font-size var(--transition-base),
    left var(--transition-base);
}
.topbar--compact .search::before {
  font-size: 22px;
  left: 28px;
}
.search__input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 15px;
  padding: var(--space-3) 100px var(--space-3) 60px;
  border-radius: var(--radius-md);
  outline: none;
  transition:
    filter 0.2s,
    border-color 0.2s,
    font-size var(--transition-base),
    padding var(--transition-base);
}
.topbar--compact .search__input {
  font-size: 12px;
  padding: var(--space-2) 100px var(--space-2) 60px;
}
.search__input:focus {
  border-color: var(--accent3);
  filter: drop-shadow(0 0 10px #ffc1e522);
  transition: filter 0.3s ease-out;
}
.search__input:hover {
  filter: drop-shadow(0 0 5px #ffc1e530);
  transition: filter 0.2s ease-out;
}
.search__input::placeholder {
  color: var(--muted);
}
.search__count {
  position: absolute;
  right: var(--space-5);
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
}
.search__count .num {
  color: var(--accent2);
}

.icon-button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}
.icon-button:hover {
  color: var(--text);
}
.icon-button--menu {
  display: none;
  font-size: 24px;
  line-height: 1;
  user-select: none;
}
.icon-button--theme {
  display: flex;
  align-items: center;
}

/* 5.3 Hero --------------------------------------------------- */
.hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-7);
  align-items: start;
  margin-bottom: var(--space-7);
}
.hero__right {
  padding: var(--space-4) var(--space-4) 20px 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  position: relative;
}
.hero__tagline {
  font-family: var(--font-sans);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.hero h2 {
  display: block;
  max-width: 380px;
  text-transform: uppercase;
  color: var(--text);
  line-height: 1.1;
  font-size: 58px;
  margin-bottom: var(--space-3);
}
.hero__badges {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding-top: 20px;
  margin-top: 20px;
  border-top: 1px solid var(--border);
  text-decoration: none;
}
.hero__badges a:hover {
  text-decoration: none;
}

.animated-text {
  background: linear-gradient(to right, #fc9272 20%, #fd76a8 30%, #f87be6 70%, #ab8ff7 80%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  background-size: 300% auto;
  animation: textShine 1.3s linear infinite alternate;
}
.animated-text--br {
  filter: brightness(1.2) hue-rotate(150deg);
}
:root.light .animated-text {
  filter: brightness(0.85) hue-rotate(-30deg);
}
:root.light .animated-text--br {
  filter: brightness(1) hue-rotate(150deg);
}

.confetti-trigger {
  align-self: end;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 0;
  opacity: 0.8;
  transition:
    opacity var(--transition-fast),
    transform var(--transition-fast);
  line-height: 1;
  margin-left: var(--space-1);
}
.confetti-trigger:hover {
  opacity: 1;
  transform: scale(1.15);
}

/* 5.4 Conteúdo (rendered, entry, results) ------------------- */
.content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 40px var(--space-7);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.rendered h2 {
  color: var(--accent2);
  margin: 40px 0 var(--space-4);
  padding-top: 40px;
  scroll-margin-top: 60px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.rendered ul li {
  display: flex;
  align-items: flex-start;
  justify-content: left;
  gap: var(--space-3);
  color: var(--muted3);
  position: relative;
}
.rendered ul li:hover {
  background-color: var(--surface);
}
.rendered ul li::before {
  content: "🔗";
  position: absolute;
  left: var(--space-2);
  top: calc(50% - 12px);
  font-size: 16px;
  color: var(--muted2);
}
.rendered ul li > a {
  display: block;
  flex: 1;
  text-decoration: none;
  cursor: pointer;
  padding: var(--space-3) var(--space-2) var(--space-3) 44px;
  border-bottom: 0.5px solid var(--border);
}
.rendered ul li:hover > a .entry__title {
  color: var(--accent4);
  text-decoration-color: var(--accent);
}

.entry__title {
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border);
  transition:
    color var(--transition-fast),
    text-decoration-color var(--transition-fast);
}
.entry__desc {
  color: var(--muted3);
  font-weight: 200;
}

.anchor-copy {
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 400;
  color: var(--muted2);
  padding: 0 2px;
  opacity: 0;
  transition:
    opacity var(--transition-fast),
    color var(--transition-fast);
  line-height: 1;
  flex-shrink: 0;
  text-transform: none;
  letter-spacing: 0;
}
.rendered h2:hover .anchor-copy {
  opacity: 1;
}
.anchor-copy:hover {
  color: var(--text);
}
.anchor-copy.copied {
  color: var(--accent3);
  opacity: 1;
}

.reference-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--accent);
  border: 0.5px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0 5px;
  font-weight: 800;
  white-space: nowrap;
  vertical-align: text-bottom;
}

.results {
  display: none;
}
.results.active {
  display: block;
}
.result__item {
  position: relative;
  animation: fadeIn 0.2s ease;
}
.result__item::before {
  content: "🔗";
  position: absolute;
  left: var(--space-2);
  top: calc(50% - 12px);
  font-size: 16px;
  color: var(--muted2);
  pointer-events: none;
}
.result__item:hover {
  background-color: var(--surface);
}
.result__item:hover .result__link .entry__title {
  color: var(--text);
  text-decoration-color: var(--accent);
}
.result__link {
  display: block;
  text-decoration: none;
  padding: var(--space-3) var(--space-2) var(--space-3) 44px;
  border-bottom: 0.5px solid var(--border);
  cursor: pointer;
}
.result__section {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 2px;
}

.no-results {
  text-align: center;
  color: var(--muted);
  padding: 60px 0;
  font-size: 13px;
}
.no-results .big {
  font-family: var(--font-sans);
  font-size: var(--space-7);
  display: block;
  margin-bottom: var(--space-3);
}

/* 5.5 Contributors ------------------------------------------ */
.contributors {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.contributors:empty {
  display: none;
}
.contributors__label {
  font-family: var(--font-sans);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--space-4);
}
.contributors__avatar img {
  border-radius: 50%;
  display: block;
  opacity: 0.8;
  transition:
    opacity var(--transition-fast),
    transform var(--transition-fast);
}
.contributors__avatar:hover img {
  opacity: 1;
  transform: scale(1.15);
}

/* 5.6 Footer ------------------------------------------------- */
.footer {
  text-align: center;
  padding-top: 200px;
  color: var(--muted2);
  font-size: 12px;
}
.footer a {
  color: var(--muted2);
  text-decoration: none;
}
.footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* 5.7 Loading, error ---------------------------------------- */
.loading {
  text-align: center;
  color: var(--muted);
  padding: 80px 0;
  font-size: 13px;
}

.error {
  text-align: center;
  color: #ff6b6b;
  padding: 80px 40px;
  font-size: 13px;
  display: none;
}
.error .big {
  font-family: var(--font-sans);
  font-size: 40px;
  display: block;
  margin-bottom: var(--space-3);
}

/* 5.8 Confetti ---------------------------------------------- */
.confetti__canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 10;
}
.confetti__particle {
  position: absolute;
  pointer-events: none;
  animation: confetti-burst ease-out forwards;
}

/* 5.9 Languages --------------------------------------------- */
.languages,
.languages--en {
  margin: 0;
  font-size: 13px;
}
.languages a,
.languages--en a {
  text-decoration: none;
}
.languages a:hover {
  color: var(--accent3);
}
.languages--en a:hover {
  color: var(--accent4);
}
.languages--mobile {
  display: none;
}

/* ── 6. Estados ────────────────────────────────────────────── */
.hidden {
  display: none;
}

/* ── 7. Animações ──────────────────────────────────────────── */
@keyframes glassesSway {
  0% {
    transform: rotate(-5deg);
  }
  100% {
    transform: rotate(5deg);
  }
}
@keyframes textShine {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 100% 50%;
  }
}
@keyframes confetti-burst {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(var(--dx), var(--dy)) rotate(var(--rotate));
    opacity: 0;
  }
}

#back-to-top {
  position: fixed;
  right: 20px;
  bottom: 28px;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease,
    color 0.15s ease,
    background 0.15s ease;
}

#back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(-150%);
}

#back-to-top:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

#footer {
  text-align: center;
  padding-top: 200px;
  color: var(--muted2);
  font-size: 12px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── 8. Responsivo ─────────────────────────────────────────── */

/* Mobile (≤829px): hero em uma coluna, sidebar overlay, topbar compacta */
@media (max-width: 829px) {
  .hero {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .icon-button--menu {
    display: block;
  }
  .content {
    padding: var(--space-5) 20px;
  }
  .topbar {
    padding: var(--space-3) var(--space-4);
  }
  .topbar--compact .topbar {
    padding: 10px var(--space-4);
  }
  .topbar__links {
    display: none;
  }
  .languages--mobile {
    display: block;
  }
}
