:root {
  --bg: #f4f6f9;
  --paper: #ffffff;
  --ink: #1a2332;
  --muted: #5a6578;
  --line: #d1d9e6;
  --primary: #1e3a5f;
  --accent: #2563eb;
  --max: 52rem;
  --toc-width: 17rem;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--primary);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 1px 3px rgba(26, 35, 50, 0.12);
}

.site-header-inner {
  max-width: calc(var(--max) + var(--toc-width) + 4rem);
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-header-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.site-logo {
  flex-shrink: 0;
  display: block;
  line-height: 0;
}

.site-logo img {
  display: block;
  height: 2.75rem;
  width: auto;
}

.site-header-text {
  min-width: 0;
}

.site-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.site-header p {
  margin: 0.35rem 0 0;
  font-size: 0.92rem;
  color: rgba(255, 255, 255, 0.78);
}

.btn-download-md {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-download-md:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.4);
  text-decoration: none;
  color: #fff;
}

.btn-download-ai {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  border: 2px solid #2563eb;
  background: #2563eb;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  animation: download-border-pulse 2s ease-in-out infinite;
  transition: background 0.15s ease;
}

.btn-download-ai:hover {
  background: #1d4ed8;
  text-decoration: none;
  color: #fff;
}

@keyframes download-border-pulse {
  0%, 100% {
    border-color: #2563eb;
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.45);
  }
  50% {
    border-color: #93c5fd;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2);
  }
}

@media (max-width: 640px) {
  .site-header-inner {
    flex-wrap: wrap;
  }

  .btn-download-md,
  .btn-download-ai {
    width: 100%;
    justify-content: center;
  }
}

.layout {
  max-width: calc(var(--max) + var(--toc-width) + 4rem);
  margin: 0 auto;
  padding: 1.25rem;
  display: grid;
  gap: 1.5rem;
}

@media (min-width: 1024px) {
  .layout {
    grid-template-columns: var(--toc-width) minmax(0, 1fr);
    align-items: start;
  }
}

#TOC {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  box-shadow: 0 1px 3px rgba(26, 35, 50, 0.06);
}

@media (min-width: 1024px) {
  #TOC {
    position: sticky;
    top: 5.5rem;
    max-height: calc(100vh - 6.5rem);
    overflow: auto;
  }
}

#TOC::before {
  content: "Indice";
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

#TOC ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

#TOC ul ul {
  padding-left: 0.9rem;
  margin-top: 0.2rem;
}

#TOC li {
  margin: 0.2rem 0;
  font-size: 0.88rem;
  line-height: 1.35;
}

#TOC a {
  color: var(--ink);
}

#TOC a:hover {
  color: var(--accent);
}

.content {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.5rem 1.4rem 2.5rem;
  box-shadow: 0 1px 3px rgba(26, 35, 50, 0.06);
}

@media (min-width: 768px) {
  .content {
    padding: 2rem 2.2rem 3rem;
  }
}

.content > h1:first-child {
  display: none;
}

.content h1,
.content h2,
.content h3,
.content h4 {
  scroll-margin-top: 5.5rem;
  color: var(--ink);
  line-height: 1.25;
}

.content h2 {
  margin: 2.2rem 0 0.9rem;
  padding-top: 0.2rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--line);
  font-size: 1.45rem;
}

.content h3 {
  margin: 1.5rem 0 0.6rem;
  font-size: 1.15rem;
}

.content h4 {
  margin: 1.2rem 0 0.5rem;
  font-size: 1rem;
}

.content p,
.content ul,
.content ol {
  margin: 0.65rem 0 1rem;
}

.content ul,
.content ol {
  padding-left: 1.35rem;
}

.content hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 2rem 0;
}

.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0 1.4rem;
  font-size: 0.92rem;
  display: block;
  overflow-x: auto;
}

.content th,
.content td {
  border: 1px solid var(--line);
  padding: 0.55rem 0.7rem;
  vertical-align: top;
  text-align: left;
}

.content th {
  background: #f1f5f9;
  font-weight: 600;
}

.content tr:nth-child(even) td {
  background: #f8fafc;
}

.content code {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 0.88em;
  background: #f1f5f9;
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

.content pre {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  font-size: 0.85rem;
}

.content pre code {
  background: none;
  padding: 0;
}

.mermaid-wrap {
  margin: 1.2rem 0 1.6rem;
  padding: 1rem;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
}

.mermaid {
  min-width: min(100%, 320px);
}

.site-footer {
  max-width: calc(var(--max) + var(--toc-width) + 4rem);
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.site-footer a {
  color: var(--primary);
  font-weight: 600;
}

.site-footer a:hover {
  color: var(--accent);
}
