* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  --bg: #efe6d6;        /* papel */
  --bg-soft: #e7dcc8;   /* blocos de código, árvore */
  --bg-hover: #e0d3bc;
  --border: #d8cab1;
  --text: #2a2723;
  --muted: #675f52;
  --link: #0b5cad;
  --active-bg: #dccfb6;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  max-width: 740px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

header { margin-bottom: 2rem; border-bottom: 1px solid var(--border); padding-bottom: 1rem; }
header h1 a { color: var(--text); }
header p { color: var(--muted); font-size: 0.9rem; margin-top: 0.25rem; }
header nav { font-size: 0.9rem; margin-top: 0.5rem; color: var(--muted); }

/* Post list */
.post-list { list-style: none; }
.post-list li { margin-bottom: 1.25rem; }
.post-list .date { color: var(--muted); font-size: 0.85rem; font-family: monospace; margin-right: 0.5rem; }

/* Post content */
.post-meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 1.5rem; }
.post-content h1 { font-size: 1.8rem; margin: 1.5rem 0 0.75rem; }
.post-content h2 { font-size: 1.4rem; margin: 1.5rem 0 0.75rem; }
.post-content h3 { font-size: 1.15rem; margin: 1.25rem 0 0.5rem; }
.post-content p { margin-bottom: 1rem; }
.post-content ul, .post-content ol { margin: 0 0 1rem 1.5rem; }
.post-content blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  color: var(--muted);
  margin: 1rem 0;
}
/* Os desenhos são tinta preta em fundo branco: multiply faz o branco virar a cor do papel */
.post-content img { max-width: 100%; height: auto; mix-blend-mode: multiply; }
.post-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
}
.post-content th, .post-content td {
  border: 1px solid var(--border);
  padding: 0.5rem;
  text-align: left;
}
.post-content th { background: var(--bg-soft); }

/* Code */
.post-content code {
  background: var(--bg-soft);
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
  font-size: 0.9em;
}
.post-content pre {
  background: var(--bg-soft);
  padding: 1rem;
  border-radius: 4px;
  overflow-x: auto;
  margin: 1rem 0;
}
.post-content pre code, .hljs {
  background: none;
  padding: 0;
}

/* Mermaid */
.mermaid { margin: 1rem 0; text-align: center; }

/* Function Plot */
.function-plot { margin: 1rem 0; }
.function-plot svg { max-width: 100%; height: auto; }

/* KaTeX overrides */
.katex-display { margin: 1rem 0; overflow-x: auto; }

/* Tabs (Artigo | Código) */
.tabs { display: flex; gap: 1.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
.tabs a { color: var(--muted); padding: 0.4rem 0; margin-bottom: -1px; border-bottom: 2px solid transparent; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--text); }

/* Code view: file tree + read-only file */
.code-view {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  font-size: 0.85rem;
}
.code-tree { border-right: 1px solid var(--border); background: var(--bg-soft); padding: 0.5rem 0; }
.code-tree ul { list-style: none; }
.code-tree ul ul { padding-left: 0.9rem; }
.code-tree a, .code-tree summary {
  display: block;
  padding: 0.15rem 0.75rem;
  font-family: monospace;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.code-tree a:hover { background: var(--bg-hover); text-decoration: none; }
.code-tree a.active { background: var(--active-bg); color: var(--link); }
.code-tree-toggle { display: none; }

.code-file { min-width: 0; }
.code-file-header {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-family: monospace;
  color: var(--muted);
}
.code-lines {
  margin: 0;
  padding: 0.75rem 0;
  overflow-x: auto;
  line-height: 1.5;
  counter-reset: line;
}
.code-lines code { font-size: 0.8rem; }
.code-lines .line { display: inline; }
.code-lines .line::before {
  counter-increment: line;
  content: counter(line);
  display: inline-block;
  width: 2.5rem;
  margin-right: 1rem;
  text-align: right;
  color: var(--muted);
  opacity: 0.6;
  user-select: none;
}

@media (max-width: 640px) {
  .code-view { grid-template-columns: minmax(0, 1fr); }
  .code-tree { border-right: none; border-bottom: 1px solid var(--border); padding: 0; }
  .code-tree-toggle {
    display: block;
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: none;
    border: none;
    font: inherit;
    font-family: monospace;
    text-align: left;
    color: var(--text);
    cursor: pointer;
  }
  .code-tree-toggle::after { content: " ▾"; color: var(--muted); }
  .tree-open .code-tree-toggle::after { content: " ▴"; }
  .code-tree-list { display: none; padding-bottom: 0.5rem; }
  .tree-open .code-tree-list { display: block; }
  .code-file-header { display: none; }
}

footer { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.8rem; }
