:root {
  --bg: #0b0e14;
  --surface: #11151c;
  --surface-2: #171c25;
  --border: #232a35;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #7aa2f7;
  --topbar-h: 58px;
  --panel-w: min(580px, 100vw);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

code, kbd { font-family: ui-monospace, 'JetBrains Mono', 'Fira Code', monospace; }

/* ------------------------------ topbar ------------------------------ */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 14, 20, 0.92);
  backdrop-filter: blur(8px);
  position: relative;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand strong { display: block; font-size: 15px; letter-spacing: 0.2px; }
.brand small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; }
.logo {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 9px;
  font: italic 600 22px/1 'Latin Modern Math', 'STIX Two Math', Georgia, serif;
  background: linear-gradient(135deg, #7aa2f7, #bb9af7);
  color: #0b0e14;
}

.disc {
  margin-left: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.disc:hover, .disc:focus { border-color: var(--accent); outline: none; }

.search { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.search input {
  width: 100%;
  padding: 9px 36px 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
}
.search input:focus { border-color: var(--accent); }
.search kbd {
  position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  font-size: 11px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px;
  pointer-events: none;
}
#search-results {
  display: none;
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
#search-results.open { display: block; }
#search-results li {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 14px;
}
#search-results li small { margin-left: auto; color: var(--muted); font-size: 11px; }
#search-results li.cur, #search-results li:hover { background: var(--surface-2); }

.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--c); flex: none; display: inline-block;
}

.progress { display: flex; flex-direction: column; gap: 4px; width: 150px; }
.progress .bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress .bar span {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, #9ece6a, #73daca);
  transition: width 0.3s;
}
.progress small { color: var(--muted); font-size: 11px; }

.actions { display: flex; gap: 6px; }
.actions button {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 16px;
}
.actions button:hover { border-color: var(--accent); }

/* ------------------------------ palco ------------------------------ */

#stage {
  position: relative;
  height: calc(100% - var(--topbar-h));
  overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(circle, #1c2230 1.2px, transparent 1.3px);
  background-size: 24px 24px;
}

#graph {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
#graph.dragging { cursor: grabbing; }

/* arestas */
.edge {
  fill: none;
  stroke: #2d3542;
  stroke-width: 1.6;
  marker-end: url(#arrow);
  transition: opacity 0.2s, stroke 0.2s;
}
.edge.anc, .edge.desc {
  stroke: #e6edf3;
  stroke-width: 2.2;
  marker-end: url(#arrow-hl);
}
.edge.desc {
  stroke-dasharray: 6 5;
  animation: flow 0.9s linear infinite;
}
.edge.dim { opacity: 0.12; }
@keyframes flow { to { stroke-dashoffset: -11; } }

/* nós */
.node { cursor: pointer; outline: none; transition: opacity 0.2s; }
.node-bg {
  fill: color-mix(in srgb, var(--c) 10%, #10141b);
  stroke: color-mix(in srgb, var(--c) 55%, transparent);
  stroke-width: 1.4;
  transition: fill 0.2s, stroke 0.2s, stroke-width 0.2s;
}
.node-label {
  fill: var(--text);
  font-size: 13px;
  font-weight: 600;
  dominant-baseline: middle;
  pointer-events: none;
}
.node-check { opacity: 0.18; pointer-events: none; }
.node-check circle { fill: none; stroke: var(--c); stroke-width: 1.4; }
.node-check path { fill: none; stroke: transparent; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.node:hover .node-bg, .node:focus-visible .node-bg { stroke: var(--c); stroke-width: 2; }
.node.ready .node-bg { stroke: var(--c); stroke-dasharray: 5 3; }
.node.done .node-bg { fill: color-mix(in srgb, var(--c) 32%, #10141b); stroke: var(--c); stroke-dasharray: none; }
.node.done .node-check { opacity: 1; }
.node.done .node-check circle { fill: var(--c); }
.node.done .node-check path { stroke: #0b0e14; }

.node.active .node-bg {
  stroke: var(--c);
  stroke-width: 3;
  filter: drop-shadow(0 0 10px color-mix(in srgb, var(--c) 70%, transparent));
}
.node.anc .node-bg, .node.desc .node-bg { stroke: var(--c); stroke-width: 2; }
.node.match .node-bg { stroke: #fff; stroke-width: 2.4; }
.node.dim { opacity: 0.18; }

/* trilha guiada no mapa */
.node-step { display: none; pointer-events: none; }
.node.route .node-step { display: inline; }
.node-step circle { fill: var(--c); stroke: #0b0e14; stroke-width: 2; }
.node-step text {
  fill: #0b0e14; font-size: 10px; font-weight: 800;
  text-anchor: middle; dominant-baseline: middle;
}
.node.route.done .node-step circle { fill: #3b4453; }
.node.route.done .node-step text { fill: #e6edf3; }
.node.current .node-bg {
  stroke: #fff;
  stroke-width: 3;
  stroke-dasharray: none;
  filter: drop-shadow(0 0 12px color-mix(in srgb, var(--c) 80%, transparent));
}

/* legenda / dica */
#legend {
  position: absolute; left: 14px; bottom: 14px;
  display: flex; flex-wrap: wrap; gap: 6px;
  max-width: calc(100% - 28px);
}
#legend button {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(17, 21, 28, 0.9);
  font-size: 12px;
}
#legend button small { color: var(--muted); }
#legend button.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, var(--surface)); }

#hint {
  position: absolute; left: 14px; top: 12px;
  font-size: 12px; color: var(--muted); line-height: 1.7;
  pointer-events: none;
}
#hint .line { display: inline-block; width: 22px; vertical-align: middle; border-top: 2px solid #e6edf3; }
#hint .line.dashed { border-top-style: dashed; }

#loading {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  text-align: center; line-height: 1.6;
  color: var(--muted);
  background: var(--bg);
}
#loading.error { color: #f7768e; }
#loading code { color: var(--text); background: var(--surface-2); padding: 2px 6px; border-radius: 5px; }

/* ------------------------------ painel ------------------------------ */

#panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: var(--panel-w);
  padding: 18px 26px 60px;
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -18px 0 40px rgba(0, 0, 0, 0.35);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 10;
}
#panel.open { transform: none; }
#panel::before {
  content: '';
  position: absolute; left: 0; right: 0; top: 0; height: 3px;
  background: var(--c);
}

.panel-head { display: flex; align-items: center; justify-content: space-between; }
.badge {
  font-size: 11px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, transparent);
  padding: 4px 9px; border-radius: 6px;
}
#panel-close {
  background: none; border: 1px solid transparent; border-radius: 7px;
  width: 32px; height: 32px; color: var(--muted);
}
#panel-close:hover { border-color: var(--border); color: var(--text); }

#panel h1 { font-size: 26px; margin: 14px 0 10px; line-height: 1.25; }

.done-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); cursor: pointer;
}
.done-toggle input { accent-color: #9ece6a; width: 16px; height: 16px; }

.relations {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  margin: 18px 0 12px; padding: 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
}
.relations h3 {
  margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 4px 9px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--c) 50%, transparent);
  background: color-mix(in srgb, var(--c) 10%, transparent);
}
.chip:hover { background: color-mix(in srgb, var(--c) 25%, transparent); }
.chip.done::after { content: ' ✓'; color: #9ece6a; }
.muted { color: var(--muted); font-size: 13px; }

.path { margin-bottom: 8px; font-size: 13px; }
.path summary { cursor: pointer; color: var(--muted); padding: 4px 0; }
.path ol { margin: 6px 0 0; padding-left: 22px; columns: 2; column-gap: 20px; }
.path li { margin: 2px 0; break-inside: avoid; }
.path li::marker { color: var(--c); }
.path a { color: var(--text); text-decoration: none; }
.path a:hover { text-decoration: underline; }
.path li.done a { color: var(--muted); text-decoration: line-through; }

/* trilha guiada no painel */
.route {
  margin: 16px 0 4px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--c) 45%, var(--border));
  background: color-mix(in srgb, var(--c) 7%, var(--surface-2));
  border-radius: 10px;
}
.route-head { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
.route-head a { color: var(--c); font-weight: 700; text-decoration: none; }
.route-head a:hover { text-decoration: underline; }
.route-head button {
  background: none; border: 0; color: var(--muted); width: 26px; height: 26px; border-radius: 6px;
}
.route-head button:hover { color: var(--text); background: var(--surface); }
#route-count { color: var(--muted); font-size: 12px; }
.route-steps {
  display: flex; flex-wrap: wrap; gap: 6px;
  list-style: none; padding: 0; margin: 10px 0 12px;
}
.route-steps button {
  min-width: 28px; height: 28px; padding: 0 6px;
  border-radius: 999px;
  font-size: 12px; font-weight: 700;
  border: 1.5px solid var(--c);
  background: transparent;
}
.route-steps button.done { background: color-mix(in srgb, var(--c) 30%, transparent); }
.route-steps button.cur { background: var(--c); color: #0b0e14; box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 30%, transparent); }
.route-steps button.goal { border-style: dashed; }
.route-steps button.goal::after { content: ' ★'; }
.route-nav { display: flex; gap: 8px; }
.route-nav button {
  padding: 7px 12px; border-radius: 8px; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface);
}
.route-nav button:hover:not(:disabled) { border-color: var(--c); }
.route-nav button:disabled { opacity: 0.45; cursor: default; }
.route-nav .primary {
  margin-left: auto;
  background: var(--c); color: #0b0e14; border-color: var(--c); font-weight: 700;
}
.path.in-route { display: none; }
.route-nav .primary.locked {
  background: transparent; color: var(--text); border-color: var(--border); font-weight: 600;
}
.route-steps button:disabled { opacity: 0.35; cursor: not-allowed; }

/* status e exercícios */
.ex-summary { font-size: 13px; color: var(--muted); }
.ex-summary a { color: var(--c); }
.ex-summary.done { color: #9ece6a; font-weight: 600; }

.exercise {
  margin: 16px 0;
  padding: 12px 14px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--c);
  border-radius: 8px;
  background: var(--surface-2);
}
.exercise.solved { border-left-color: #9ece6a; }
.exercise.shake { animation: shake 0.35s; }
@keyframes shake {
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}
.ex-head {
  display: flex; justify-content: space-between;
  font-size: 11px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase; color: var(--muted);
}
.ex-status { color: #9ece6a; }
.ex-question p { margin: 6px 0 10px; }
.ex-form { display: flex; gap: 8px; }
.ex-form input {
  flex: 1; min-width: 0;
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: 14px ui-monospace, 'JetBrains Mono', monospace;
  outline: none;
}
.ex-form input:focus { border-color: var(--c); }
.exercise.solved .ex-form input { border-color: #9ece6a55; color: #9ece6a; }
.ex-form button, .ex-options button, .complete button {
  padding: 7px 14px; border-radius: 7px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--c);
  background: color-mix(in srgb, var(--c) 18%, transparent);
}
.exercise.solved .ex-form button { display: none; }
.ex-options { display: flex; flex-wrap: wrap; gap: 8px; }
.ex-options button { font-weight: 500; border-color: var(--border); background: var(--surface); }
.ex-options button:hover { border-color: var(--c); }
.ex-options button.wrong { border-color: #f7768e; color: #f7768e; text-decoration: line-through; }
.ex-options button.right { border-color: #9ece6a; background: #9ece6a22; color: #9ece6a; }
.exercise.solved .ex-options button:not(.right) { opacity: 0.4; }
.ex-preview { min-height: 0; margin-top: 6px; font-size: 13px; }
.ex-preview:empty { display: none; }
.ex-feedback { font-size: 13px; margin-top: 6px; }
.ex-feedback:empty { display: none; }
.ex-feedback.ok { color: #9ece6a; font-weight: 600; }
.ex-feedback.err { color: #f7768e; }
.ex-hint { color: var(--muted); margin-top: 4px; }

.complete {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 18px; padding: 14px;
  border: 1px solid #9ece6a66; border-radius: 10px;
  background: #9ece6a14; color: #9ece6a;
}
.complete[hidden] { display: none; }
.complete button { border-color: #9ece6a; background: #9ece6a; color: #0b0e14; }

/* ------------------------------ markdown ------------------------------ */

.markdown {
  border-top: 1px solid var(--border);
  margin-top: 10px;
  padding-top: 6px;
  font-size: 15px;
  line-height: 1.7;
  color: #d4dae1;
}
.markdown h2 { font-size: 19px; margin: 26px 0 8px; color: var(--text); }
.markdown h2::before { content: '§ '; color: var(--c); }
.markdown h3 { font-size: 16px; margin: 20px 0 6px; color: var(--text); }
.markdown p { margin: 10px 0; }
.markdown a { color: var(--accent); }
.markdown a.wikilink {
  color: var(--c);
  text-decoration: none;
  border-bottom: 1px dashed var(--c);
}
.markdown .wikilink.broken { color: #f7768e; text-decoration: line-through; }
.markdown ul, .markdown ol { padding-left: 22px; }
.markdown li { margin: 4px 0; }
.markdown blockquote {
  margin: 14px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--c);
  background: color-mix(in srgb, var(--c) 7%, transparent);
  border-radius: 0 8px 8px 0;
}
.markdown blockquote p { margin: 4px 0; }
.markdown code {
  font-size: 0.88em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 5px;
}
.markdown pre {
  background: #0d1117; border: 1px solid var(--border);
  padding: 12px 14px; border-radius: 8px; overflow-x: auto;
}
.markdown pre code { background: none; border: 0; padding: 0; }
.markdown table { border-collapse: collapse; margin: 12px 0; font-size: 14px; width: 100%; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.markdown th { background: var(--surface-2); }
.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
.markdown details { margin: 10px 0; padding: 8px 12px; background: var(--surface-2); border-radius: 8px; }
.markdown summary { cursor: pointer; color: var(--muted); }

.math-block, .markdown .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.markdown .katex { font-size: 1.08em; }

/* ------------------------------ responsivo ------------------------------ */

@media (max-width: 820px) {
  .topbar { gap: 10px; padding: 0 10px; }
  .brand small, .brand strong, .progress, .search kbd, #hint { display: none; }
  .disc { margin-left: 0; max-width: 130px; }
  #panel { padding: 16px 18px 60px; }
  .relations { grid-template-columns: 1fr; }
  .path ol { columns: 1; }
}
