/* ---------- Tokens ---------- */
:root {
  --bg: #ffffff;
  --text: #171717;
  --muted: #6f6f6f;
  --faint: #a3a3a3;
  --rule: #e7e7e7;
  --hover: #f6f6f6;
  --link: #1d4ed8;
  --ok: #1f9d55;
  --focus: #1d4ed8;

  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --page: 960px;
  --label: 176px;
  --gap: 3rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --text: #ededed;
    --muted: #9a9a9a;
    --faint: #666666;
    --rule: #2a2a2a;
    --hover: #1b1b1b;
    --link: #8fb0ff;
    --ok: #3ecf7a;
    --focus: #8fb0ff;
  }
}

:root[data-theme="dark"] {
  --bg: #121212;
  --text: #ededed;
  --muted: #9a9a9a;
  --faint: #666666;
  --rule: #2a2a2a;
  --hover: #1b1b1b;
  --link: #8fb0ff;
  --ok: #3ecf7a;
  --focus: #8fb0ff;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 80px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; display: block; }
[hidden] { display: none !important; }

a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-decoration-thickness: 1px;
  text-underline-offset: .25em;
  transition: text-decoration-color .15s, color .15s;
}
a:hover { color: var(--link); text-decoration-color: currentColor; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
  border-radius: 3px;
}

h1, h2, h3 { margin: 0; font-weight: 500; line-height: 1.25; }
p { margin: 0 0 1em; }

.page { width: min(100% - 2.5rem, var(--page)); margin-inline: auto; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 1rem; top: -4rem;
  background: var(--text);
  color: var(--bg);
  padding: .5rem .9rem;
  border-radius: 4px;
  z-index: 100;
  text-decoration: none;
}
.skip-link:focus { top: 1rem; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
}
.header-inner { display: flex; align-items: center; gap: 1rem; min-height: 64px; }

.brand { font-weight: 500; text-decoration: none; }
.brand:hover { color: var(--text); }

nav { margin-left: auto; }
.nav-list { display: flex; gap: .25rem; list-style: none; margin: 0; padding: 0; }
.nav-list a {
  display: inline-block;
  padding: .4rem .65rem;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: .9375rem;
}
.nav-list a:hover { color: var(--text); background: var(--hover); }

.theme-toggle {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0; border-radius: 6px;
  background: transparent; color: var(--muted);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text); background: var(--hover); }

/* ---------- Grelha das secções ----------
   Nome da secção numa coluna estreita à esquerda, conteúdo à direita. */
.intro,
.block {
  display: grid;
  grid-template-columns: var(--label) minmax(0, 1fr);
  gap: 1.25rem var(--gap);
}

.block {
  padding: 2.5rem 0;
  border-top: 1px solid var(--rule);
}

.block-title {
  font-size: .9375rem;
  color: var(--muted);
  padding-top: .1rem;
}

/* ---------- Apresentação ---------- */
.intro {
  padding: clamp(3rem, 10vw, 6.5rem) 0 clamp(3rem, 8vw, 5rem);
  align-items: end;
}

.portrait {
  margin: 0;
  position: relative;
  aspect-ratio: 4 / 5;
  border-radius: 6px;
  overflow: hidden;
  background: var(--hover);
}
.portrait img {
  width: 100%; height: 100%;
  object-fit: cover;
  filter: grayscale(1) contrast(1.05);
  transition: filter .4s ease;
}
.portrait:hover img { filter: none; }
.portrait-fallback {
  position: absolute; inset: 0;
  display: none; place-items: center;
  color: var(--faint);
  font-size: 1.5rem;
  letter-spacing: .04em;
}
.portrait.is-missing img { display: none; }
.portrait.is-missing .portrait-fallback { display: grid; }

.intro h1 {
  font-size: clamp(2rem, 5vw, 2.75rem);
  letter-spacing: -.025em;
  line-height: 1.1;
}
.role {
  font-size: clamp(1.125rem, 2.5vw, 1.375rem);
  color: var(--muted);
  letter-spacing: -.01em;
  margin: .2rem 0 1.5rem;
}
.intro-lead { max-width: 34em; font-size: 1.0625rem; }

.status {
  display: inline-flex; align-items: center; gap: .55rem;
  margin: .5rem 0 0;
  font-size: .9375rem;
  color: var(--muted);
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent);
}

/* ---------- Trabalho ---------- */
.work { list-style: none; margin: -.6rem 0 0; padding: 0; }
.work > li + li { border-top: 1px solid var(--rule); }

.project summary {
  display: grid;
  grid-template-columns: minmax(0, 12rem) minmax(0, 1fr) auto 1rem;
  align-items: baseline;
  gap: 1.25rem;
  padding: .85rem .6rem;
  margin: 0 -.6rem;
  border-radius: 6px;
  cursor: pointer;
  list-style: none;
}
.project summary::-webkit-details-marker { display: none; }
.project summary:hover { background: var(--hover); }

.project-name { font-weight: 500; }
.project-summary { color: var(--muted); }
.project-kind { color: var(--faint); font-size: .875rem; white-space: nowrap; }

/* Sinal de mais que vira menos quando o projecto abre */
.toggle { position: relative; width: 11px; height: 11px; align-self: center; color: var(--muted); }
.toggle::before, .toggle::after {
  content: "";
  position: absolute; left: 0; top: 5px;
  width: 11px; height: 1.5px;
  background: currentColor;
  transition: transform .2s ease;
}
.toggle::after { transform: rotate(90deg); }
.project[open] .toggle::after { transform: rotate(0deg); }

.project-detail {
  padding: .5rem 0 2rem;
  max-width: 38rem;
}
.project-detail > p { max-width: 36em; }

/* Abertura suave onde o navegador suporta */
@supports (interpolate-size: allow-keywords) {
  :root { interpolate-size: allow-keywords; }
  .project::details-content {
    height: 0;
    overflow: clip;
    transition: height .3s ease, content-visibility .3s allow-discrete;
  }
  .project[open]::details-content { height: auto; }
}

.shot {
  margin: .25rem 0 1.5rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
}
.shot img { width: 100%; }
.shot.is-missing { display: none; }
/* Montagens com fundo transparente dispensam a moldura */
.shot-plain { border: 0; border-radius: 0; }

/* Imagens que abrem em tamanho grande */
.thumb { display: block; cursor: zoom-in; }
.thumb img { transition: opacity .15s; }
.thumb:hover img { opacity: .88; }

/* Grelha de miniaturas por baixo da imagem principal */
.thumbs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .5rem;
  margin: -.75rem 0 1.5rem;
}
.thumbs .thumb {
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
}

/* Ecrãs de telemóvel numa faixa que desliza na horizontal */
.phones {
  display: flex;
  gap: .75rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  margin: .25rem 0 1.5rem;
  padding-bottom: .75rem;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}
.phones .thumb {
  flex: 0 0 150px;
  scroll-snap-align: start;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
}
.phones img { width: 100%; height: auto; }

/* Janela da imagem ampliada */
.lightbox {
  width: 100vw; height: 100vh;
  max-width: none; max-height: none;
  margin: 0; padding: clamp(1rem, 4vw, 3rem);
  border: 0;
  background: transparent;
}
.lightbox[open] { display: grid; place-items: center; }
.lightbox::backdrop { background: rgba(0, 0, 0, .85); }
.lightbox img {
  max-width: 100%;
  max-height: calc(100vh - 6rem);
  width: auto; height: auto;
  border-radius: 6px;
}
.lightbox-close {
  position: fixed; top: 1rem; right: 1rem;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, .22); }

.meta { margin: 0 0 1.25rem; font-size: .9375rem; }
.meta div {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr);
  gap: 1rem;
  padding: .35rem 0;
}
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

.detail-link { margin: 0; font-size: .9375rem; }

/* ---------- Percurso ---------- */
.path { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }
.path li { display: grid; gap: .05rem; }
.path-role { font-weight: 500; }
.path-org { color: var(--muted); }

/* ---------- Sobre ---------- */
.prose p { max-width: 36em; }

.gallery {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .75rem;
  margin-top: 2rem;
}
.gallery figure {
  margin: 0;
  aspect-ratio: 4 / 5;
  border-radius: 6px;
  overflow: hidden;
  background: var(--hover);
}
.gallery img {
  width: 100%; height: 100%;
  object-fit: cover;
  filter: grayscale(1) contrast(1.05);
  transition: filter .4s ease;
}
.gallery figure:hover img { filter: none; }
.gallery figure.is-missing { display: none; }
.gallery.is-empty { display: none; }

/* ---------- Ferramentas ---------- */
.tools { margin: 0; display: grid; gap: .75rem; }
.tools div {
  display: grid;
  grid-template-columns: 9rem minmax(0, 1fr);
  gap: 1rem;
}
.tools dt { color: var(--muted); }
.tools dd { margin: 0; }

/* ---------- Contacto ---------- */
.contact-lead { font-size: 1.0625rem; }
.contact-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.contact-list li {
  display: grid;
  grid-template-columns: 9rem minmax(0, 1fr);
  gap: 1rem;
}
.contact-list span { color: var(--muted); }

/* ---------- Rodapé ---------- */
.site-footer { padding: 2.5rem 0 3rem; color: var(--faint); font-size: .875rem; }
.site-footer .page { border-top: 1px solid var(--rule); padding-top: 1.5rem; }
.site-footer p { margin: 0; }

/* ---------- Ecrãs pequenos ---------- */
@media (max-width: 720px) {
  .intro, .block { grid-template-columns: minmax(0, 1fr); }
  .block { gap: 1rem; padding: 2rem 0; }

  .intro { padding-top: 2rem; }
  .portrait { width: 112px; }

  .project summary {
    grid-template-columns: minmax(0, 1fr) 1rem;
    gap: .15rem 1rem;
  }
  .project-name { grid-column: 1; grid-row: 1; }
  .toggle { grid-column: 2; grid-row: 1; }
  .project-summary { grid-column: 1 / -1; font-size: .9375rem; }
  .project-kind { display: none; }

  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
  .brand { display: none; }
  nav { margin-left: -.65rem; }
  .theme-toggle { margin-left: auto; }
  .meta div, .tools div, .contact-list li { grid-template-columns: minmax(0, 1fr); gap: 0; }
}

/* ---------- Movimento reduzido ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
