:root {
  --paper: #f6f3ec;
  --paper-2: #fffdf8;
  --ink: #1c1e22;
  --muted: #6a6e75;
  --line: #e1dbcf;
  --accent: #0f6e63;
  --accent-soft: #dcefeb;
  --amber: #a86a12;
  --amber-soft: #fbf0db;
  --red: #b42318;
  --red-soft: #fde8e6;
  --green: #2c7a36;
  --green-soft: #e4f3e5;
  --code-bg: #1b1f2b;
  --code-ink: #e6e6e3;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --side: 270px;
  --top: 56px;
}
* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--top) + 16px); }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15.5px/1.65 var(--sans); }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: .88em; background: #ece6da; padding: .08em .35em; border-radius: 4px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 2.1rem; margin: .2em 0 .5em; }
h2 { font-size: 1.45rem; margin: 2.2em 0 .6em; padding-top: .2em; border-top: 1px solid var(--line); }
h3 { font-size: 1.1rem; margin: 0 0 .4em; }
.lead { font-size: 1.08rem; color: #3a3d43; max-width: 72ch; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .74rem; color: var(--amber); font-weight: 700; margin: 0; }
.eyebrow a { color: inherit; }
kbd { font-family: var(--mono); font-size: .72em; opacity: .75; border: 1px solid currentColor; border-radius: 3px; padding: 0 .3em; margin-left: .4em; }

/* ---------- layout ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--top); z-index: 20;
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: var(--ink); color: #fff;
}
.brand { color: #fff; text-decoration: none; font-family: var(--serif); font-size: 1.25rem; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.brand-mark { font-family: var(--mono); font-size: .8rem; background: var(--accent); padding: 3px 7px; border-radius: 4px; letter-spacing: .05em; }
.brand-sub { font-family: var(--sans); font-size: .8rem; font-weight: 400; opacity: .6; margin-left: 6px; }
.progress { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: .82rem; opacity: .9; }
.progress-track { width: 140px; height: 6px; background: #3a3d45; border-radius: 3px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: #4fd1b5; transition: width .4s; }
.menu-btn { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }

.sidebar {
  position: fixed; top: var(--top); bottom: 0; left: 0; width: var(--side); overflow-y: auto;
  padding: 18px 12px 40px; border-right: 1px solid var(--line); background: var(--paper-2);
}
.sidebar a { display: block; padding: 6px 12px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: .9rem; line-height: 1.35; }
.sidebar a:hover { background: #f0ebe0; }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-group { margin: 18px 12px 6px; font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 700; }

main { margin-left: var(--side); padding: calc(var(--top) + 28px) 48px 80px; max-width: calc(var(--side) + 1060px); }
.loading { padding: 40px; color: var(--muted); }

/* ---------- botões ---------- */
.btn {
  font: 600 .86rem var(--sans); padding: 7px 14px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line); background: var(--paper-2); color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 4px;
}
.btn:hover { border-color: #c9c1b1; background: #fff; }
.btn-run { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-run:hover { background: #0c5d53; border-color: #0c5d53; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--red); }
.btn-danger[data-armed] { background: var(--red); color: #fff; border-color: var(--red); }
.btn-lg { padding: 11px 18px; font-size: .95rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.spacer { flex: 1; }
select.btn { font-weight: 500; max-width: 260px; }

/* ---------- código ---------- */
pre.code {
  margin: 0; background: var(--code-bg); color: var(--code-ink); padding: 14px 16px; border-radius: 8px;
  overflow-x: auto; font: 13.5px/1.55 var(--mono);
}
pre.code code { background: none; padding: 0; font-size: inherit; color: inherit; }
.tk-kw { color: #7cc4ff; font-weight: 600; }
.tk-fn { color: #e7b86a; }
.tk-str { color: #a5d68a; }
.tk-num { color: #f39a8d; }
.tk-com { color: #7d8597; font-style: italic; }
.tk-id { color: #d9b8ff; }
.tk-op { color: #c9ccd4; }

.ex { margin: 16px 0 22px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper-2); overflow: hidden; }
.ex-title { padding: 8px 14px; font-size: .82rem; font-weight: 700; color: #4a4e55; border-bottom: 1px solid var(--line); }
.ex pre.code { border-radius: 0; }
.ex-static { background: transparent; }
.ex-bar { display: flex; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); }
.ex-out:not(:empty) { padding: 4px 12px 12px; border-top: 1px dashed var(--line); }

/* ---------- editor ---------- */
.editor { position: relative; border-radius: 10px; background: var(--code-bg); height: calc(var(--rows) * 21.7px + 28px); min-height: 120px; resize: vertical; overflow: hidden; border: 1px solid #000; }
.editor pre, .editor textarea {
  position: absolute; inset: 0; margin: 0; padding: 14px 16px; border: 0;
  font: 14px/1.55 var(--mono); white-space: pre; overflow: auto; tab-size: 2; letter-spacing: 0;
}
.editor pre { color: var(--code-ink); pointer-events: none; scrollbar-width: none; }
.editor pre::-webkit-scrollbar { display: none; }
.editor pre code { background: none; padding: 0; font-size: inherit; }
.editor textarea { background: transparent; color: transparent; caret-color: #fff; resize: none; outline: none; }
.editor textarea::placeholder { color: #6c7385; }
.editor textarea::selection { background: rgba(124, 196, 255, .3); color: transparent; }
.editor:focus-within { box-shadow: 0 0 0 3px rgba(15, 110, 99, .35); }

/* ---------- resultados ---------- */
.out:not(:empty) { margin-top: 12px; }
.res-table-wrap { overflow: auto; max-height: 460px; border: 1px solid var(--line); border-radius: 8px; background: #fff; margin-top: 8px; }
.res-table { border-collapse: collapse; width: 100%; font: 13px/1.4 var(--mono); }
.res-table th { position: sticky; top: 0; background: #efe9dd; text-align: left; padding: 7px 12px; font-weight: 700; border-bottom: 1px solid var(--line); white-space: nowrap; }
.res-table td { padding: 5px 12px; border-bottom: 1px solid #f1ede5; white-space: nowrap; }
.res-table tr:nth-child(even) td { background: #fcfaf5; }
.res-table .null { color: #a39d91; font-style: italic; }
.res-table .num { color: #1f4f8a; }
.res-table .empty { color: var(--muted); font-style: italic; text-align: center; }
.res-meta, .res-time { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.res-label { font-size: .8rem; font-weight: 700; color: #4a4e55; margin-top: 12px; }
.msg { padding: 9px 12px; border-radius: 8px; margin-top: 8px; font-size: .9rem; background: #efe9dd; }
.msg-ok { background: var(--green-soft); color: #1d5a25; }
.msg-err { background: var(--red-soft); color: #7a1a12; font-family: var(--mono); font-size: .84rem; }
.msg-err .tip { font-family: var(--sans); margin-top: 6px; color: #5a2a24; font-size: .88rem; }

/* ---------- tabelas de conteúdo ---------- */
.tbl-wrap { overflow-x: auto; margin: 14px 0; }
.tbl { border-collapse: collapse; width: 100%; font-size: .9rem; background: var(--paper-2); }
.tbl th { text-align: left; background: #ece6da; padding: 8px 12px; border: 1px solid var(--line); }
.tbl td { padding: 7px 12px; border: 1px solid var(--line); vertical-align: top; }

/* ---------- notas ---------- */
.note { border-left: 4px solid; border-radius: 0 8px 8px 0; padding: 10px 16px; margin: 18px 0; background: var(--paper-2); }
.note p { margin: .3em 0; }
.note ul { margin: .3em 0; padding-left: 1.2em; }
.note-title { font-weight: 700; font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 2px; }
.note-info { border-color: var(--accent); background: #eef6f4; }
.note-info .note-title { color: var(--accent); }
.note-tip { border-color: var(--amber); background: var(--amber-soft); }
.note-tip .note-title { color: var(--amber); }
.note-warn { border-color: #c98a1a; background: #fdf3e1; }
.note-warn .note-title { color: #8a5a0b; }
.note-danger { border-color: var(--red); background: var(--red-soft); }
.note-danger .note-title { color: var(--red); }
.note .res-table-wrap { margin-top: 6px; }

/* ---------- aula ---------- */
.lesson { max-width: 900px; }
.cards3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 14px 0; }
.card { background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.card p { margin: .4em 0; font-size: .92rem; }
.pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 48px; padding-top: 18px; border-top: 1px solid var(--line); }
.pager a { text-decoration: none; font-weight: 600; }
.steps { counter-reset: s; list-style: none; padding: 0; }
.steps li { counter-increment: s; padding: 6px 0 6px 40px; position: relative; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 5px; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; font-size: .8rem; display: grid; place-items: center; font-weight: 700; }

/* venn */
.join-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 18px 0; }
.venn { margin: 0; text-align: center; background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 6px 8px; }
.venn svg { width: 150px; height: auto; }
.venn figcaption { font: 600 .74rem var(--mono); color: #4a4e55; }
.v-on { fill: var(--accent); fill-opacity: .75; }
.v-off { fill: none; }
.v-cut { fill: var(--paper-2); }
.v-line { fill: none; stroke: var(--ink); stroke-width: 1.4; }
.v-txt { font: 700 14px var(--sans); fill: var(--ink); }

/* ---------- home ---------- */
.hero { padding: 28px 0 10px; max-width: 820px; }
.hero h1 { font-size: 2.6rem; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.roadmap { columns: 2; column-gap: 32px; padding-left: 1.4em; }
.roadmap li { break-inside: avoid; padding: 3px 0; }
.roadmap li span { color: var(--muted); font-size: .78rem; margin-left: 8px; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.topic-card { display: block; text-decoration: none; color: var(--ink); background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.topic-card:hover { border-color: var(--accent); }
.topic-name { font-weight: 700; margin-bottom: 8px; }
.bar { height: 6px; background: #ebe5d8; border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
.bar div { height: 100%; background: var(--accent); }

/* ---------- exercícios ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: .85rem; background: var(--paper-2); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.ex-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 8px; }
.ex-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-2); text-decoration: none; color: var(--ink); }
.ex-item:hover { border-color: var(--accent); }
.ex-item .check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: .75rem; color: #fff; flex: none; }
.ex-item.done .check { background: var(--green); border-color: var(--green); }
.ex-name { flex: 1; font-weight: 600; font-size: .92rem; }
.lvl { font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .05em; }
.lvl-1 { background: var(--green-soft); color: var(--green); }
.lvl-2 { background: var(--amber-soft); color: var(--amber); }
.lvl-3 { background: var(--red-soft); color: var(--red); }
.tag { font-size: .7rem; background: #e9e3d6; color: #4a4e55; padding: 2px 8px; border-radius: 999px; text-transform: none; letter-spacing: 0; }
.exercise { max-width: 980px; }
.statement { font-size: 1.05rem; background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; margin-bottom: 14px; }
.solved-mark { color: var(--green); }
.feedback { padding: 11px 14px; border-radius: 8px; margin: 8px 0; }
.feedback.ok { background: var(--green-soft); color: #1d5a25; }
.feedback.bad { background: var(--red-soft); color: #7a1a12; }

/* ---------- playground ---------- */
.pg-layout { display: grid; grid-template-columns: 250px 1fr; gap: 18px; align-items: start; }
.pg-head h1 { margin-bottom: .1em; }
.pg-schema { background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; position: sticky; top: calc(var(--top) + 16px); max-height: calc(100vh - var(--top) - 40px); overflow: auto; }
.pg-schema-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; color: var(--muted); margin: 2px 4px 8px; }
.pg-schema details { border-bottom: 1px solid #f0ebe0; }
.pg-schema summary { cursor: pointer; padding: 5px 4px; font: 600 .84rem var(--mono); display: flex; align-items: center; gap: 6px; }
.pg-schema summary .t-name:hover { color: var(--accent); text-decoration: underline; }
.t-count { margin-left: auto; font: 500 .7rem var(--sans); color: var(--muted); }
.pg-schema ul { list-style: none; margin: 0 0 6px; padding: 0 0 0 14px; }
.pg-schema li { display: flex; justify-content: space-between; gap: 6px; font: .78rem var(--mono); padding: 1px 4px; border-radius: 4px; cursor: pointer; }
.pg-schema li:hover { background: var(--accent-soft); }
.pg-schema li em { color: var(--muted); font-style: normal; font-size: .72rem; }
.k { font: 700 .58rem var(--sans); padding: 1px 4px; border-radius: 3px; margin-right: 4px; vertical-align: 1px; }
.k.pk { background: #f6d77a; color: #5b4200; }
.k.fk { background: #bfdcf7; color: #0f3f6b; }

/* ---------- modelo ---------- */
.er-figure { margin: 20px 0; background: var(--paper-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.er-svg { width: 100%; max-width: 820px; display: block; margin: 0 auto; }
.er-line { stroke: #8c8578; stroke-width: 1.4; }
.er-card-txt { font: 700 10px var(--mono); fill: var(--amber); }
.er-node { cursor: pointer; }
.er-node rect { fill: #fff; stroke: var(--ink); stroke-width: 1.4; }
.er-node.assoc rect { fill: var(--accent-soft); }
.er-node.weak rect.inner { fill: none; }
.er-node:hover rect { stroke: var(--accent); stroke-width: 2; }
.er-node text { font: 600 12.5px var(--mono); text-anchor: middle; fill: var(--ink); }
.er-figure figcaption { font-size: .8rem; color: var(--muted); text-align: center; margin-top: 6px; }
.lg { display: inline-block; width: 14px; height: 10px; border: 1.4px solid var(--ink); border-radius: 2px; vertical-align: -1px; margin-left: 6px; }
.lg.assoc { background: var(--accent-soft); }
.lg.weak { outline: 1.4px solid var(--ink); outline-offset: 1px; }
.er-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.er-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; transition: box-shadow .3s; }
.er-card.flash { box-shadow: 0 0 0 3px var(--accent); }
.er-head { background: var(--ink); color: #fff; padding: 8px 12px; font: 700 .9rem var(--mono); display: flex; }
.er-head .t-count { color: #b9bcc4; }
.er-card ul { list-style: none; margin: 0; padding: 6px 0; }
.er-card li { display: grid; grid-template-columns: 62px 1fr auto; gap: 6px; padding: 3px 12px; font: .8rem var(--mono); align-items: center; }
.er-card li.is-pk .c { font-weight: 700; }
.er-card li .ty { color: var(--muted); font-size: .74rem; }
.er-card li .ty i { color: #b0a796; }
.er-card li .ref { grid-column: 2 / -1; font-size: .74rem; text-decoration: none; margin-top: -2px; }

/* ---------- responsivo ---------- */
@media (max-width: 980px) {
  .menu-btn { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; z-index: 15; box-shadow: 4px 0 20px rgba(0,0,0,.1); }
  body.nav-open .sidebar { transform: none; }
  main { margin-left: 0; padding: calc(var(--top) + 20px) 18px 60px; }
  .pg-layout { grid-template-columns: 1fr; }
  .pg-schema { position: static; max-height: 260px; }
  .cards3 { grid-template-columns: 1fr; }
  .roadmap { columns: 1; }
  .brand-sub, .progress span { display: none; }
}

/* ---------- glossário ---------- */
.top-search { margin-left: auto; }
.top-search input {
  width: 260px; background: #2b2e35; border: 1px solid #40444d; color: #fff; border-radius: 7px;
  padding: 6px 12px; font: .85rem var(--sans); outline: none;
}
.top-search input::placeholder { color: #9a9ea8; }
.top-search input:focus { border-color: #4fd1b5; background: #33363e; }
.top-search + .progress { margin-left: 18px; }
.glossary { max-width: 940px; }
.g-search { position: sticky; top: calc(var(--top) + 10px); z-index: 5; display: flex; align-items: center; gap: 10px;
  background: var(--paper-2); border: 2px solid var(--ink); border-radius: 12px; padding: 4px 14px; box-shadow: 0 6px 18px rgba(28,30,34,.08); margin-top: 18px; }
.g-search:focus-within { border-color: var(--accent); }
.g-icon { font-size: 1.4rem; color: var(--muted); line-height: 1; }
.g-search input { flex: 1; border: 0; outline: none; background: transparent; font: 1.05rem var(--sans); padding: 10px 0; color: var(--ink); }
.g-count { font-size: .8rem; color: var(--muted); white-space: nowrap; }
#g-cats .chip { cursor: pointer; font: inherit; font-size: .85rem; }
.g-letters { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 10px; }
.g-letters a { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 6px; text-decoration: none; font-weight: 700; font-size: .85rem; color: var(--ink); border: 1px solid var(--line); background: var(--paper-2); }
.g-letters a:hover { background: var(--ink); color: #fff; }
.g-letter { font: 600 1.6rem var(--serif); color: var(--amber); margin: 26px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--line); scroll-margin-top: calc(var(--top) + 90px); }
.g-item { background: var(--paper-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; margin: 10px 0; scroll-margin-top: calc(var(--top) + 90px); }
.g-item header { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.g-item h3 { margin: 0; font-size: 1.2rem; }
.g-alias { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.g-def { margin: 8px 0; }
.g-ex { margin: 10px 0 6px; }
.g-item footer { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.g-rel { font-size: .78rem; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; color: var(--ink); background: #fff; }
.g-rel:hover { border-color: var(--accent); color: var(--accent); }
.g-lesson { margin-left: auto; font-size: .82rem; font-weight: 600; text-decoration: none; }
.g-empty { padding: 30px; text-align: center; color: var(--muted); background: var(--paper-2); border: 1px dashed var(--line); border-radius: 10px; margin-top: 16px; }
mark { background: #fde68a; color: inherit; border-radius: 2px; padding: 0 1px; }
@media (max-width: 980px) { .top-search input { width: 150px; } .g-lesson { margin-left: 0; } }
