/* Cena 3D e controlos sobrepostos (barra superior, filtro ativo, legenda, pesquisa) */
.graph { position: fixed; inset: 0; z-index: 1; outline: none; }
.graph canvas { display: block; }

/* tooltip do 3d-force-graph (float-tooltip): o contentor fica transparente — a folha é o .tt.
   Sem isto herda texto claro (#eee) do contentor e, no modo claro, desaparece sobre o papel. */
.float-tooltip-kap, .scene-tooltip {
  padding: 0 !important; border-radius: 0 !important; background: none !important;
  color: var(--ink) !important; font-family: var(--mono) !important; font-size: inherit !important;
  pointer-events: none;
}
.tt {
  display: grid; gap: .2em;
  max-width: 28em;
  padding: .7em .9em;
  /* claro: folha creme, texto escuro e aresta vermelha (como as folhas do cartaz) */
  background: var(--edge-cream); color: var(--ink);
  border: 1px solid var(--rule);
  box-shadow: .45em .45em 0 var(--edge-red);
  text-align: left;
}
:root[data-theme="dark"] .tt { background: var(--paper); box-shadow: .5em .5em 0 var(--edge-cream); }
.tt-type, .tt-count { font-size: var(--s-2); text-transform: lowercase; color: var(--muted); }
.tt-title { font-family: var(--serif); font-size: var(--s1); text-transform: uppercase; letter-spacing: .06em; line-height: 1.15; }
.tt-sub { font-size: var(--s-1); text-transform: lowercase; }
.tt-name { font-family: var(--serif); font-size: var(--s1); }

/* ─────────── barra superior ─────────── */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 10;
  display: flex; align-items: center; gap: calc(var(--gap) * 1.5);
  flex-wrap: wrap;
  padding: calc(var(--gap) * .9) calc(var(--gap) * 1.4);
  pointer-events: none;
  transition: opacity .6s var(--ease), transform .6s var(--ease);
}
.topbar > * { pointer-events: auto; }
body.panel-open .topbar { padding-right: calc(var(--panel-w) + var(--gap)); }

.brand { display: flex; align-items: center; gap: .45em; min-height: var(--touch); }
.brand-hand { width: clamp(18px, 1.5vw, 52px); }
.brand-title { font-family: var(--serif); font-size: var(--s1); text-transform: uppercase; letter-spacing: .2em; }
.brand:hover .brand-title { color: var(--accent); }

/* 1.ª linha: marca + ferramentas · 2.ª linha: centro de gravidade (12 modos em 3 grupos) */
.gravity { order: 3; width: 100%; display: flex; align-items: center; gap: .7em; flex-wrap: wrap; margin-top: calc(var(--gap) * -.6); }
.control-label { font-size: var(--s-2); color: var(--muted); }

.gravity-groups { display: flex; flex-wrap: wrap; gap: .35em; }
.segmented {
  display: inline-flex; flex-wrap: wrap;
  background: var(--veil);
  border: 1px solid var(--rule);
  backdrop-filter: blur(4px);
}
.seg {
  min-height: var(--touch); padding: 0 .85em;
  font-size: var(--s-1);
  border-right: 1px dotted var(--rule);
  transition: color .2s, background-color .2s;
}
.seg:last-child { border-right: 0; }
.seg:hover { color: var(--accent); }
.seg[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

.tools { margin-left: auto; display: flex; align-items: center; gap: .5em; flex-wrap: wrap; }
.tool {
  min-height: var(--touch); min-width: var(--touch); padding: 0 .8em;
  font-size: var(--s-1);
  background: var(--veil); border: 1px solid var(--rule); backdrop-filter: blur(4px);
}
.tool:hover { color: var(--accent); border-color: var(--accent); }
.tool--icon { font-size: var(--s0); padding: 0; }

/* pesquisa */
.search { position: relative; }
.search input {
  width: clamp(150px, 14vw, 520px);
  min-height: var(--touch); padding: 0 .9em;
  font-size: var(--s-1);
  background: var(--veil); border: 1px solid var(--rule); border-radius: 0;
  backdrop-filter: blur(4px);
  -webkit-appearance: none;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--accent); }
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: auto;
  width: max(100%, 22em);
  margin: 0; padding: .3em 0; list-style: none;
  background: var(--paper); border: 1px solid var(--rule); box-shadow: .5em .5em 0 var(--edge-cream);
  max-height: 60vh; overflow: auto;
}
.search-results button {
  width: 100%; min-height: var(--touch); padding: .35em .9em;
  display: grid; grid-template-columns: 7.5em 1fr; gap: .6em; align-items: baseline; text-align: left;
}
.search-results button:hover, .search-results button:focus-visible { background: var(--ink); color: var(--paper); }
/* lupa: só no telemóvel (ver o fim deste ficheiro) */
.search-toggle { display: none; }
.search-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.sr-type { font-size: var(--s-2); color: var(--muted); }
.sr-label { font-size: var(--s-1); text-transform: lowercase; }
.sr-empty { padding: .6em .9em; color: var(--muted); font-size: var(--s-1); }

/* ─────────── filtro ativo ─────────── */
.filter-chip {
  position: fixed; left: 50%; bottom: calc(var(--gap) * 1.4); z-index: 10;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: .8em; flex-wrap: wrap; justify-content: center;
  max-width: calc(100vw - 2 * var(--gap));
  padding: .4em .5em .4em 1em;
  background: var(--paper);
  border: 1px solid var(--accent);
  box-shadow: .45em .45em 0 var(--edge-cream);
  font-size: var(--s-1);
}
body.panel-open .filter-chip { left: calc((100vw - var(--panel-w)) / 2); }
.chip-tokens { display: flex; flex-wrap: wrap; gap: .3em .9em; margin: 0; padding: 0; list-style: none; }
.chip-token { display: inline-flex; align-items: baseline; gap: .45em; }
.filter-chip .chip-remove { min-height: 0; padding: 0 .3em; border: 0; color: var(--muted); font-size: var(--s0); line-height: 1; }
.filter-chip .chip-remove:hover { background: none; color: var(--accent); }
.chip-type { color: var(--muted); font-size: var(--s-2); }
.chip-label { color: var(--accent); font-family: var(--serif); font-size: var(--s1); text-transform: none; }
.chip-count { color: var(--muted); font-size: var(--s-2); }
.filter-chip button { min-height: calc(var(--touch) * .85); padding: 0 .8em; border: 1px solid var(--rule); }
.filter-chip button:hover { background: var(--accent); color: var(--paper); border-color: var(--accent); }

/* ─────────── legenda ─────────── */
.legend {
  position: fixed; left: calc(var(--gap) * 1.4); bottom: calc(var(--gap) * 1.4); z-index: 9;
  font-size: var(--s-2);
}
.legend-toggle { min-height: var(--touch); padding: 0 .9em; background: var(--veil); border: 1px solid var(--rule); font-size: var(--s-1); }
.legend-body {
  display: none;
  margin-bottom: .5em;
  padding: .9em 1.1em;
  background: var(--veil); border: 1px solid var(--rule); backdrop-filter: blur(4px);
}
.legend.is-open .legend-body { display: grid; gap: .8em; }
.legend { display: flex; flex-direction: column-reverse; align-items: flex-start; }
.legend ul { margin: 0; padding: 0; list-style: none; display: grid; gap: .45em; }
.legend li { display: flex; align-items: center; gap: .7em; }
.lg-mark { width: .9em; height: .9em; display: inline-block; background: var(--ink); }
.lg-project { width: .8em; height: 1.05em; background: var(--paper); border: 1px solid var(--ink); box-shadow: .18em -.18em 0 var(--edge-cream); }
.lg-student, .lg-typology, .lg-year { border-radius: 50%; }
.lg-student { width: .6em; height: .6em; }
.lg-group { background: none; border: 2px solid var(--ink); border-radius: 50%; }
.lg-teacher { transform: rotate(45deg) scale(.75); }
.lg-uc { transform: scale(.8); }
.lg-format { background: none; border: 1.5px solid var(--ink); width: .7em; height: 1em; }
.lg-tag { transform: scale(.5); }
/* arquivo material */
.lg-paper { width: .8em; height: 1em; clip-path: polygon(0 0, 62% 0, 100% 30%, 100% 100%, 0 100%); }
.lg-weight { width: 1em; height: .8em; background: repeating-linear-gradient(to bottom, var(--ink) 0 .14em, transparent .14em .3em); }
.lg-typeface, .lg-reference, .lg-work { width: auto; height: auto; background: none; font-family: var(--serif); line-height: 1; font-size: 1.25em; text-transform: none; }
.lg-typeface::before { content: "Aa"; }
.lg-reference::before { content: "“"; font-size: 1.4em; line-height: .6; }
.lg-work::before { content: "¶"; }
.lg-producer { width: 1em; height: 1em; background:
  linear-gradient(var(--ink), var(--ink)) center / 1.5px 100% no-repeat,
  linear-gradient(var(--ink), var(--ink)) center / 100% 1.5px no-repeat;
  border-radius: 50%; box-shadow: inset 0 0 0 .2em var(--veil), inset 0 0 0 .3em var(--ink); }
.legend-nodes { grid-template-columns: repeat(2, auto); column-gap: 1.6em; }
.legend svg { width: 2.4em; height: .5em; overflow: visible; }
.lg-line { stroke: var(--ink); stroke-width: 1.5; }
.lg-line--category { opacity: .45; }

/* ─────────── modo atrator ─────────── */
.attract-hint {
  position: fixed; left: 50%; bottom: 6vh; z-index: 8; margin: 0;
  transform: translateX(-50%);
  font-family: var(--serif); font-size: var(--s2); font-variant-caps: all-small-caps; letter-spacing: .2em;
  color: var(--ink);
  opacity: 0; pointer-events: none;
  transition: opacity 1.2s var(--ease);
}
body.is-attract .attract-hint { opacity: .85; animation: breathe 4s ease-in-out infinite; }
body.is-attract .topbar, body.is-attract .legend { opacity: .25; }
@keyframes breathe { 50% { opacity: .35; } }

/* modo leve (telemóveis): aviso se o dispositivo ficar sem memória gráfica (ver graph.js) */
.webgl-lost {
  position: fixed; left: 50%; top: 50%; z-index: 20;
  transform: translate(-50%, -50%);
  width: min(22em, calc(100vw - 2 * var(--gap)));
  display: grid; gap: .9em;
  padding: 1em 1.2em;
  background: var(--paper); border: 1px solid var(--accent); box-shadow: .45em .45em 0 var(--edge-cream);
  font-size: var(--s-1);
}
.webgl-lost[hidden] { display: none; }
.webgl-lost p { margin: 0; }
.webgl-lost button { justify-self: start; min-height: var(--touch); padding: 0 .9em; border: 1px solid var(--rule); }
.webgl-lost button:hover { background: var(--accent); color: var(--paper); border-color: var(--accent); }

@media (max-width: 900px) {
  .gravity .control-label { display: none; }
  .tools { margin-left: 0; }
  .search input { width: 44vw; }
}
.filter-chip[hidden], .search-results[hidden] { display: none; }

/* telemóvel: barra compacta, segmentos deslizáveis */
@media (max-width: 720px) {
  .topbar { gap: 6px; padding: 8px 10px; }
  /* sem o título: a mão (que continua a levar à página de entrada) abre a linha das ferramentas, e as duas
     linhas do menu sobem */
  .brand { flex: none; min-height: 40px; min-width: 30px; justify-content: center; }
  .brand-hand { width: 26px; }
  .brand-title { display: none; }
  .gravity { order: 3; width: 100%; margin-top: 0; }
  #gravity-bar { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  #gravity-bar .segmented { flex-wrap: nowrap; flex: none; }
  #gravity-bar::-webkit-scrollbar { display: none; }
  .seg { min-height: 40px; padding: 0 .7em; white-space: nowrap; }
  /* ferramentas numa linha que desliza como a dos modos; pesquisa e tema em ícones */
  .tools { flex: 1 1 0; min-width: 0; flex-wrap: nowrap; gap: 6px; overflow-x: auto; scrollbar-width: none; }
  .tools::-webkit-scrollbar { display: none; }
  .tools > * { flex: none; }
  .tool { min-height: 40px; min-width: 40px; }
  /* pesquisa: lupa que se estende ao tocar, ocupando a linha; os resultados abrem por baixo da barra
     (.search sem posição → ficam presos à barra e não ao deslizador, que os cortaria) */
  .search { position: static; display: flex; gap: 6px; }
  .search-toggle { display: inline-grid; place-items: center; }
  .search input { display: none; width: auto; min-width: 0; min-height: 40px; }
  .search.is-open { flex: 0 0 100%; }
  .search.is-open input { display: block; flex: 1; }
  .search.is-open .search-toggle { color: var(--accent); border-color: var(--accent); }
  .search-results { top: 100%; left: 10px; right: 10px; width: auto; max-height: 55vh; }
  /* língua: um só botão, com a outra língua (em português mostra «en», em inglês «pt») */
  .segmented--lang .seg[aria-pressed="true"] { display: none; }
  .segmented--lang .seg { border-right: 0; min-width: 40px; }
  /* tema: meio círculo em vez da palavra (a palavra fica para os leitores de ecrã) */
  #theme-toggle { position: relative; font-size: 0; padding: 0; }
  #theme-toggle::before {
    content: ""; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: 16px; height: 16px; box-sizing: border-box;
    border: 1.5px solid currentColor; border-radius: 50%;
    background: linear-gradient(90deg, currentColor 50%, transparent 50%);
  }
  .filter-chip { bottom: 64px; }
}

/* ─────────── telemóvel: modo leve (html.leve, ver assets/js/movel.js) ─────────── */
/* sem desfoque por trás dos controlos e do «sobre»: sobre a cena 3D em movimento, o desfoque é refeito a cada
   quadro e gasta memória gráfica. No telemóvel, fundos de papel opacos. */
.leve .segmented, .leve .tool, .leve .search input, .leve .legend-toggle, .leve .legend-body {
  backdrop-filter: none; background: var(--paper);
}
.leve .about { backdrop-filter: none; }
/* recomendação no modo «arquivo» */
.movel-aviso {
  position: fixed; left: 10px; right: 10px; z-index: 9;
  display: flex; align-items: flex-start; gap: .5em;
  padding: .55em .45em .55em .9em;
  background: var(--paper); border: 1px solid var(--rule); box-shadow: .35em .35em 0 var(--edge-cream);
  font-size: var(--s-2); line-height: 1.4;
}
.movel-aviso[hidden] { display: none; }
.movel-aviso div { flex: 1; display: grid; gap: .35em; }
.movel-aviso p { margin: 0; }
.movel-aviso button { flex: none; min-width: 32px; min-height: 32px; font-size: var(--s0); line-height: 1; color: var(--muted); }
/* painel de diagnóstico dos ensaios (?diag=1, teste-movel.html) */
.diag {
  position: fixed; right: 6px; bottom: 6px; z-index: 30;
  max-width: calc(100vw - 12px);
  padding: .5em .65em;
  background: rgba(20, 20, 18, .88); color: #eeede6;
  font: 9.5px/1.4 var(--mono);
}
.diag pre { margin: 0; white-space: pre-wrap; font: inherit; }
.diag p { margin: .45em 0 0; display: flex; gap: 1.2em; align-items: center; }
.diag button { padding: .25em .6em; border: 1px solid #eeede6; }
.diag a { color: inherit; }
